And the result I got when I run it on previous data is wrong, since it looks like it runs just over every entry of beast-n and repeats the calculations on it.
Yes, that's clearly what you're doing:
while (<INPUTB>) { my ($u, $superclass,$rel,$v) = (split)[0,1,2,3]; my $conteggio=&calcolo($u,$v); print OUT "$u"."\t".$rel."\t".$v."\t".$conteggio."\n"; }
Perhaps it would be better to read lines in groups, so you have similar records at the same time, then you can pass the smaller set of records into your calculation routine. Something like (untested):
my $cur_superclass; my @records; while (<INPUTB>) { my ($u, $superclass,$rel,$v) = (split)[0,1,2,3]; $cur_superclass = $superclass if !defined($cur_superclass); if ($cur_superlclass ne $superclass) { my $conteggio=calcolo(\@records); print OUT "$u"."\t".$rel."\t".$v."\t".$conteggio."\n"; @records = (); } push @records, [ $u, $superclass, $rel, $v ]; $cur_superclass = $superclass; }
This will, of course, complicate calcolo() a bit, as you'll have to iterate over the records to find what you're looking for. But at least it will ensure that you're processing all the related records at once, rather than repeating the calculation over and over:
sub calcolo { my $rRecs = shift; # Number of records my $found_recs = @{$rRecs}; for my $rRec (@$rRecs) { # compute partial values my ($u, $superclass, $rel, $v) = @$rRec; .... } # combine partials return $partials / $found_recs; # or some such... }
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re: Cycle, iterations and statistical measure got completely wrong
by roboticus
in thread Cycle, iterations and statistical measure got completely wrong
by remluvr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |