X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fmoments.c;h=17040e9f699335fe91021cb5331ce1f257574ef5;hb=a7fb79e81f6e2a0dfddc61e91f207609e31a4632;hp=e73efad101ae3128c1a47d954ba92dfa62b95aa5;hpb=a19b858e0ac3c69e4a28c0ca6d8674427268a863;p=pspp diff --git a/src/math/moments.c b/src/math/moments.c index e73efad101..17040e9f69 100644 --- a/src/math/moments.c +++ b/src/math/moments.c @@ -1,6 +1,5 @@ /* PSPP - computes sample statistics. Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. - Written by Ben Pfaff . This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -44,11 +43,7 @@ calc_moments (enum moment max_moment, if (max_moment >= MOMENT_VARIANCE && w > 1.) { - double s2; - - /* From _Numerical Recipes in C_, 2nd ed., 0-521-43108-5, - section 14.1. */ - s2 = (d2 - pow2 (d1) / w) / (w - 1.); + double s2 = (d2 - pow2 (d1) / w) / (w - 1.); if (variance != NULL) *variance = s2; @@ -156,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) @@ -169,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; } }