in reply to Re: Correlation plots
in thread Correlation plots
Your method requires that all data to be in memory at once, but it's simple to refactor it so that's not the case.
my ($cnt, $sum, $squ); while (my ($d) = $iter->()) { $cnt++; $sum += $d; $squ += $d * $d; } my $mean = $sum / $cnt; my $var = $squ + -2*$mean*$sum + $mean*$mean*$cnt; my $std = sqrt($var/$cnt);
while (my ($d) = $iter->()) can be replaced with any loop, including a file reading loop or a database fetching loop.
Update: If you don't need $var anywhere else, the last two lines can be simplified to
my $std = sqrt($squ/$cnt - $mean*$mean);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Correlation plots
by jettero (Monsignor) on Oct 09, 2007 at 18:59 UTC | |
by ikegami (Patriarch) on Oct 09, 2007 at 19:08 UTC | |
by jettero (Monsignor) on Oct 11, 2007 at 11:20 UTC |