- /*
- We compute the centered, un-normalized covariance matrix.
- */
- tmp = entry->dot_product - entry->sum1 * entry->sum2 / entry->ssize;
- covariance_matrix_insert (result, entry->v1, entry->v2, entry->val1,
- entry->val2, tmp);
- entry = hsh_next (cov->ca, &iter);
+ sum_i = get_sum (cov, i);
+ for (j = i; j < design_matrix_get_n_cols (cov->cov); j++)
+ {
+ sum_j = get_sum (cov, j);
+ entry = hsh_first (cov->ca, &iter);
+ design_matrix_set_element (cov->sums, i, j, sum_i);
+ while (entry != NULL)
+ {
+ update_ssize (cov->ssize, i, j, entry);
+ /*
+ We compute the centered, un-normalized covariance matrix.
+ */
+ 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 = design_matrix_get_element (cov->cov, i, j);
+ tmp -= sum_i * sum_j / design_matrix_get_element (cov->ssize, i, j);
+ design_matrix_set_element (cov->cov, i, j, tmp);
+ }