From: Ben Pfaff Date: Mon, 5 Feb 2007 23:43:23 +0000 (+0000) Subject: Reduce number of multiplications for higher moments. X-Git-Tag: v0.6.0~566 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53f0c2ceb683a6a279fb6b4b46b225265ab1e6a5;p=pspp-builds.git Reduce number of multiplications for higher moments. --- diff --git a/src/math/ChangeLog b/src/math/ChangeLog index d3db1d0d..e351fbbb 100644 --- a/src/math/ChangeLog +++ b/src/math/ChangeLog @@ -1,3 +1,7 @@ +Mon Feb 5 15:42:14 2007 Ben Pfaff + + * moments.c (moments_pass_two): Reduce number of multiplications. + Thu Dec 7 15:27:49 WST 2006 John Darrington * factor-stats.c factor-stats.h: Changed independent values to diff --git a/src/math/moments.c b/src/math/moments.c index 9c40016c..17040e9f 100644 --- a/src/math/moments.c +++ b/src/math/moments.c @@ -151,8 +151,6 @@ moments_pass_one (struct moments *m, double value, double weight) void moments_pass_two (struct moments *m, double value, double weight) { - double d, d_power; - assert (m != NULL); if (m->pass == 1) @@ -164,28 +162,25 @@ moments_pass_two (struct moments *m, double value, double weight) if (value != SYSMIS && weight >= 0.) { - m->w2 += weight; - - d = d_power = value - m->mean; - m->d1 += d_power * weight; - + double d = value - m->mean; + double d1_delta = d * weight; + m->d1 += d1_delta; if (m->max_moment >= MOMENT_VARIANCE) { - d_power *= d; - m->d2 += d_power * weight; - + double d2_delta = d1_delta * d; + m->d2 += d2_delta; if (m->max_moment >= MOMENT_SKEWNESS) { - d_power *= d; - m->d3 += d_power * weight; - + double d3_delta = d2_delta * d; + m->d3 += d3_delta; if (m->max_moment >= MOMENT_KURTOSIS) { - d_power *= d; - m->d4 += d_power * weight; + double d4_delta = d3_delta * d; + m->d4 += d4_delta; } } } + m->w2 += weight; } }