X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fts%2Finnovations.c;h=43d86ec1677c8c9bb381f59b23109da8f09940f5;hb=29e712969d0d5bc1ee20458309dee7df2c38f1ae;hp=dba4484950928648ca28f1aa24df4c64c8926bc5;hpb=0a490aaca0b5a6350d3428101b8c496f396ac26b;p=pspp-builds.git diff --git a/src/math/ts/innovations.c b/src/math/ts/innovations.c index dba44849..43d86ec1 100644 --- a/src/math/ts/innovations.c +++ b/src/math/ts/innovations.c @@ -38,9 +38,7 @@ #include #include #include -#include -#include -#define _(msgid) gettext (msgid) +#include static void get_mean_variance (size_t n_vars, const struct casefile *cf, @@ -48,13 +46,10 @@ get_mean_variance (size_t n_vars, const struct casefile *cf, { struct casereader *r; - struct ccase *c; - struct ccase *c2; + struct ccase c; size_t n; - double *x; double d; - double tmp; - double variance; + const union value *tmp; for (n = 0; n < n_vars; n++) { @@ -67,10 +62,10 @@ get_mean_variance (size_t n_vars, const struct casefile *cf, { for (n = 0; n < n_vars; n++) { - if (!mv_is_value_missing (&v->miss, val)) + tmp = case_data (&c, est[n]->variable->fv); + if (!mv_is_value_missing (&(est[n]->variable->miss), tmp)) { - tmp = case_data (&c, est[n]->variable->fv); - d = (tmp - est[n]->mean) / est[n]->n_obs; + d = (tmp->f - est[n]->mean) / est[n]->n_obs; est[n]->mean += d; est[n]->variance += est[n]->n_obs * est[n]->n_obs * d * d; est[n]->n_obs += 1.0; @@ -93,10 +88,10 @@ innovations_init_cases (struct casereader *r, struct ccase **c, size_t max_lag) bool value = true; size_t lag = 0; - while (value) + while (value && lag < max_lag) { lag++; - value = casereader_read (r, c + lag); + value = casereader_read (r, c[lag]); } return value; } @@ -114,27 +109,28 @@ innovations_update_cases (struct casereader *r, struct ccase **c, size_t max_lag { c[lag] = c[lag+1]; } - value = casereader_read (r, c + lag); + value = casereader_read (r, c[lag]); return value; } static void get_covariance (size_t n_vars, const struct casefile *cf, - struct innovations **est, size_t max_lag) + struct innovations_estimate **est, size_t max_lag) { struct casereader *r; struct ccase **c; - struct ccase *cur_case; size_t lag; - size_t n_vars; + size_t n; bool read_case = false; double d; - double tmp; + double x; + const union value *tmp; + const union value *tmp2; c = xnmalloc (max_lag, sizeof (*c)); for (lag = 0; lag < max_lag; lag++) { - c[lag] = xmalloc (sizeof *c[i]); + c[lag] = xmalloc (sizeof *c[lag]); } r = casefile_get_reader (cf); @@ -144,17 +140,17 @@ get_covariance (size_t n_vars, const struct casefile *cf, { for (n = 0; n < n_vars; n++) { - cur_case = case_data (c[0], est[n]->variable->fv); - if (!mv_is_value_missing (&est[n]->variable->miss, cur_case)) + tmp2 = case_data (c[0], est[n]->variable->fv); + if (!mv_is_value_missing (&est[n]->variable->miss, tmp2)) { - cur_case -= est[n]->mean; + x = tmp2->f - est[n]->mean; for (lag = 1; lag <= max_lag; lag++) { tmp = case_data (c[lag], est[n]->variable->fv); if (!mv_is_value_missing (&est[n]->variable->miss, tmp)) { - d = (tmp - est[n]->mean); - *(est[n]->cov + lag) += d * cur_case; + d = (tmp->f - est[n]->mean); + *(est[n]->cov + lag) += d * x; } } } @@ -179,9 +175,8 @@ struct innovations_estimate ** pspp_innovations (const struct variable **vars, s size_t lag, const struct casefile *cf) { struct innovations_estimate **est; - struct casereader *r; - struct ccase *c; size_t i; + size_t j; est = xnmalloc (*n_vars, sizeof *est); for (i = 0; i < *n_vars; i++) @@ -196,14 +191,14 @@ struct innovations_estimate ** pspp_innovations (const struct variable **vars, s est[i]->coeff = xnmalloc (lag, sizeof (*est[i]->coeff)); for (j = 0; j < lag; j++) { - est[i]->coeff + j = xmalloc (sizeof (*(est[i]->coeff + j))); + est[i]->coeff[j] = xmalloc (sizeof (*(est[i]->coeff + j))); } } else { *n_vars--; - msg (MW, _("Cannot compute autocovariance for a non-numeric variable %s"), - var_to_string (vars[i])); +/* msg (MW, _("Cannot compute autocovariance for a non-numeric variable %s"), */ +/* var_to_string (vars[i])); */ } } @@ -212,4 +207,6 @@ struct innovations_estimate ** pspp_innovations (const struct variable **vars, s */ get_mean_variance (*n_vars, cf, est); get_covariance (*n_vars, cf, est, lag); + + return est; }