I can't extract a question from your post?
Neither can I relate anything in your post -- which seems to be concerned with overlapping 2-dimension regions -- and the wikipedia link you (almost) gave which relates to finacial instruments in overlapping time periods.
You're much, much more likely to get useful responses, if you add some details about what format your data is in when you get it; and what information you hope to extract from it.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
| [reply] |
I still can't see the question. Presumably you wish to take one or more of these opinions for a given strata and use them to categorise or rate or bracket the period(s) that strata is most likely to be a part of, but without you telling us what form those opinions are expressed in, suggesting anything is pretty much impossible.
This link might help others grasp a little of what you are talking about.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
Not sure if this is what you're looking for, but here's a "best range" calculator. The first part calculates all unique, valid range combinations (this part should probably be worked on a bit further if you have many ranges), the second chooses the best range. If you just want a simple 1:1 match and aren't worried about combinations of multiple ranges, you can eliminate that part of the code.
use strict;
use warnings;
my (@r1, %r1, @r2, $i, $j, $inp, $start, $end, $choice);
@r1 = (
{ 'name' => 'b', 'start' => 70, 'end' => 110 },
{ 'name' => 'c', 'start' => 40, 'end' => 80 },
{ 'name' => 'd', 'start' => 80, 'end' => 140 },
{ 'name' => 'e', 'start' => 30, 'end' => 100 },
);
for (@r1) {
$r1{$_->{'name'}}++;
$_->{'stages'} = 1;
}
### Generate combinations of overlapping ranges
do {
@r2 = ();
for $i (0..$#r1) {
for $j (0..$#r1) {
### Ranges are same, skip
next if $i == $j;
### One range is completely inside other, skip
next if $r1[$i]{'start'} <= $r1[$j]{'start'} &&
$r1[$i]{'end'} >= $r1[$j]{'end'} ||
$r1[$j]{'start'} <= $r1[$i]{'start'} &&
$r1[$j]{'end'} >= $r1[$i]{'end'};
### i is not earlier range, skip
next if $r1[$j]{'start'} < $r1[$i]{'start'};
### Ranges do not overlap at all, skip
next if $r1[$i]{'end'} < $r1[$j]{'start'};
### Combined range already exists, skip
next if $r1{"$r1[$i]{'name'}-$r1[$j]{'name'}"}++;
### Combine and add
push @r2, {
name => "$r1[$i]{'name'}-$r1[$j]{'name'}",
start => $r1[$i]{'start'},
end => $r1[$j]{'end'},
stages => $r1[$i]{'stages'} + $r1[$j]{'stages'}
};
}
}
push @r1, @r2;
}
while ($#r2 != -1);
while (1) {
print "\n";
exit if !getInputYes('Do you want to match a range?');
$start = int getInput('Enter a start value');
$end = int getInput('Enter an end value');
@r2 = ();
for (@r1) {
$_->{'diff'} = $start - $_->{'start'} + $_->{'end'} - $end;
push @r2, $_
if $start >= $_->{'start'} &&
$end <= $_->{'end'};
}
if ($#r2 == -1) {
print "No matches found.\n";
next;
}
for (sort {
$a->{'diff'} <=> $b->{'diff'} ||
$a->{'stages'} <=> $b->{'stages'}
} @r2) {
print "$_->{'name'} [$_->{'start'}-$_->{'end'}] is best match,
+ with $_->{'diff'} difference and $_->{'stages'} stages.\n";
last;
}
}
sub getInput {
my $inp;
while (1) {
print "$_[0] : ";
chomp($inp = <STDIN>);
return $inp if $inp;
}
}
sub getInputYes {
my $inp;
while (1) {
$inp = uc substr(getInput("$_[0] (Y/N)"), 0, 1);
return 1 if $inp eq 'Y';
return 0 if $inp eq 'N';
};
}
| [reply] [d/l] |
Still no idea what you're talking about. Give us input data and tell us what you want it to come out looking like. Supplying your SQL queries might be helpful as well. Are you modeling date ranges? Or taking logical rules about what starts or ends within what or lies within what and graphing the relationships? | [reply] |
Sorry, don't have ready access to my sql queries as I am in a cafe for the next several hours. But, the way we store the data are as "periods" which have starting age and ending age. Once again, the following may describe the dataset well -- 'a' lies completely within 'b'. However, 'b' started sometime during 'c' and ended sometime during 'd'. 'c', in turn, lies completely within 'e'... and so on.
I am looking for alternative ways to store such data, and then use Perl to query it so that given a "period", I can find the most nearest period that completely contains it.
If the above is not enough to convey the question clearly, I will submit more information, probably toward the end of the day, or tomorrow, with hopefully some of the sql queries.
when small people start casting long shadows, it is time to go to bed
| [reply] |
A range (aLo..aHi) overlaps the range (bLo,bHi) when (aLo <= bHi) && (bLo <= aHi). (I think...)
This can be put into an SQL query that would return to you all of the potentially-overlapping ranges. The “distance” between the two could then be calculated e.g. max(0, (aLo-bLo)) + min(0, (aHi-bHi)) (maybe...) and the minimum taken.
You might even be able to conjure up a way to do this using a nested SQL query, i.e. select from (subquery). Choose the shortest “distance” from the overlapping-ranges returned by the inner query. An INNER JOIN could be used to map “soft” phrases like Jurassic to “hard” numbers like 14 billions-and-billions.™ (Sigh... RIP, Carl Sagan.)
You describe the ranges in a hierarchy, but I don’t know whether or not that hierarchy is strictly necessary for results. Can a range be decided to overlap based strictly on its upper- and lower-range values? Or must the decision be made by navigating a tree? If the latter, might an SQL query nevertheless be able to at least weed-out candidates for further consideration?
Food for thought, and nothing more.
| |