Skip Menu |

This queue is for tickets about the Statistics-Descriptive CPAN distribution.

Report information
The Basics
Id: 101422
Status: resolved
Priority: 0/
Queue: Statistics-Descriptive

People
Owner: Nobody in particular
Requestors: SLAFFAN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: [Patch] Speed up skewness calculations
Hello Shlomi, The attached patch does some minor refactoring on the skewness calculation to avoid needless variable creation. Kurtosis already uses this approach so it also makes the code more consistent. Benchmarking indicates it is typically 30-35% faster. Regards, Shawn.
Subject: skewness.patch
diff -r 002168f13d13 Statistics-Descriptive/lib/Statistics/Descriptive.pm --- a/Statistics-Descriptive/lib/Statistics/Descriptive.pm Sat Feb 01 10:42:25 2014 +0200 +++ b/Statistics-Descriptive/lib/Statistics/Descriptive.pm Fri Jan 09 15:41:31 2015 +1100 @@ -823,11 +823,10 @@ my $mean = $self->mean(); my $sum_pow3; + foreach my $rec ( $self->get_data ) { + $sum_pow3 += (($rec - $mean) / $sd) ** 3; + } - foreach my $rec ( $self->get_data ) { - my $value = (($rec - $mean) / $sd); - $sum_pow3 += $value ** 3; - } my $correction = $n / ( ($n-1) * ($n-2) ); @@ -848,7 +847,7 @@ my $kurt; my $n = $self->count(); - my $sd = $self->standard_deviation(); + my $sd = $self->standard_deviation(); if ( $sd && $n > 3) {
On Thu Jan 08 23:48:21 2015, SLAFFAN wrote: Show quoted text
> Hello Shlomi, > > The attached patch does some minor refactoring on the skewness > calculation to avoid needless variable creation. Kurtosis already > uses this approach so it also makes the code more consistent. >
Thanks for the patch - I applied it and released it as version 3.0608. Regards, -- Shlomi Fish Show quoted text
> Benchmarking indicates it is typically 30-35% faster. > > Regards, > Shawn.