in reply to Re: How do I get the root mean square of a list?
in thread How do I get the root mean square of a list?
This benchmarks over twice as fast, mostly because it's not calling outside subs for summation and averaging. There's a little intermediate result optimization in there as well.sub std_dev { my ($sum, $avg, $variance, $t); $sum += $_ for @_; $avg = $sum / @_; $variance += ($t = ($avg - $_)) * $t for @_; $variance /= @_; sqrt $variance; }
I wonder, however, if there isn't a more efficient algorithm for calculating standard deviation, that doesn't require iterating twice... tilly?
MeowChow s aamecha.s a..a\u$&owag.print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 2: Answer: How do I get the root mean square of a list?
by tilly (Archbishop) on Jun 04, 2001 at 21:15 UTC | |
|
Re: Re: Answer: How do I get the root mean square of a list?
by princepawn (Parson) on Jun 04, 2001 at 21:16 UTC |