From: Jason Stover Date: Sun, 29 Mar 2009 15:04:31 +0000 (-0400) Subject: covariance-matrix.c (covariance_accumulator_to_matrix): Use sum_i and X-Git-Tag: v0.7.3~185^2~1 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5282b76bcbd0501c1227b36e4d451f340388eca5;p=pspp-builds.git covariance-matrix.c (covariance_accumulator_to_matrix): Use sum_i and sum_j to compute products of means. Store the sums of variables in cov->sums, rather than storing the means. --- diff --git a/src/math/covariance-matrix.c b/src/math/covariance-matrix.c index 82f4b447..2ab5f406 100644 --- a/src/math/covariance-matrix.c +++ b/src/math/covariance-matrix.c @@ -57,7 +57,7 @@ struct covariance_matrix { struct design_matrix *cov; struct design_matrix *ssize; - struct design_matrix *means; + struct design_matrix *sums; struct hsh_table *ca; struct moments1 **m1; struct moments **m; @@ -182,7 +182,7 @@ covariance_matrix_destroy (struct covariance_matrix *cov) assert (cov != NULL); design_matrix_destroy (cov->cov); design_matrix_destroy (cov->ssize); - design_matrix_destroy (cov->means); + design_matrix_destroy (cov->sums); hsh_destroy (cov->ca); if (cov->n_pass == ONE_PASS) { @@ -872,7 +872,7 @@ covariance_accumulator_to_matrix (struct covariance_matrix *cov) cov->cov = covariance_matrix_create (cov->n_variables, cov->v_variables); cov->ssize = covariance_matrix_create (cov->n_variables, cov->v_variables); - cov->means = covariance_matrix_create (cov->n_variables, cov->v_variables); + cov->sums = covariance_matrix_create (cov->n_variables, cov->v_variables); for (i = 0; i < design_matrix_get_n_cols (cov->cov); i++) { sum_i = get_sum (cov, i); @@ -880,7 +880,7 @@ covariance_accumulator_to_matrix (struct covariance_matrix *cov) { sum_j = get_sum (cov, j); entry = hsh_first (cov->ca, &iter); - + gsl_matrix_set (cov->sums->m, i, j, sum_i); while (entry != NULL) { update_ssize (cov->ssize, i, j, entry); @@ -889,16 +889,14 @@ covariance_accumulator_to_matrix (struct covariance_matrix *cov) */ if (is_covariance_contributor (entry, cov->cov, i, j)) { - covariance_matrix_insert (cov->cov, entry->v1, entry->v2, entry->val1, entry->val2, entry->dot_product); } entry = hsh_next (cov->ca, &iter); } tmp = gsl_matrix_get (cov->cov->m, i, j); - tmp -= gsl_matrix_get (cov->means->m, i, j) / gsl_matrix_get (cov->ssize->m, i, j); + tmp -= sum_i * sum_j / gsl_matrix_get (cov->ssize->m, i, j); gsl_matrix_set (cov->cov->m, i, j, tmp); - } } }