From: Jason H Stover Date: Thu, 8 Oct 2009 21:19:11 +0000 (-0400) Subject: New function covariance_2pass_create X-Git-Tag: fc11-i386-build17^0 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=commitdiff_plain;h=09e9433298a484353b1aac68018871553bee3d55 New function covariance_2pass_create --- diff --git a/src/math/covariance.c b/src/math/covariance.c index ba0de0b6..32cda24c 100644 --- a/src/math/covariance.c +++ b/src/math/covariance.c @@ -29,10 +29,20 @@ struct covariance { - /* The variables for which the covariance matrix is to be calculated */ + /* The variables for which the covariance matrix is to be calculated. */ size_t n_vars; const struct variable **vars; - + + /* Categorical variables. */ + size_t n_catvars; + const struct variable **catvars; + + /* Array containing number of categories per categorical variable. */ + size_t *n_categories; + + /* Dimension of the covariance matrix. */ + size_t dim; + /* The weight variable (or NULL if none) */ const struct variable *wv; @@ -65,7 +75,8 @@ covariance_moments (const struct covariance *cov, int m) -/* Create a covariance struct */ +/* Create a covariance struct. + */ struct covariance * covariance_create (size_t n_vars, const struct variable **vars, const struct variable *weight, enum mv_class exclude) @@ -76,6 +87,7 @@ covariance_create (size_t n_vars, const struct variable **vars, cov->wv = weight; cov->n_vars = n_vars; + cov->dim = n_vars; for (i = 0; i < n_vars; ++i) cov->vars[i] = vars[i]; @@ -94,6 +106,43 @@ covariance_create (size_t n_vars, const struct variable **vars, return cov; } +/* + Create a covariance struct for a two-pass algorithm. If categorical + variables are involed, the dimension cannot be know until after the + first data pass, so the actual covariances will not be allocated + until then. + */ +struct covariance * +covariance_2pass_create (size_t n_vars, const struct variable **vars, + size_t n_catvars, const struct variable **catvars, + const struct variable *weight, enum mv_class exclude) +{ + size_t i; + struct covariance *cov = xmalloc (sizeof *cov); + cov->vars = xmalloc (sizeof *cov->vars * n_vars); + cov->catvars = xnmalloc (n_catvars, sizeof (*cov->catvars)); + cov->n_categories = xnmalloc (n_catvars, sizeof (cov->n_categories)); + + cov->wv = weight; + cov->n_vars = n_vars; + cov->n_catvars = n_catvars; + + for (i = 0; i < n_vars; ++i) + cov->vars[i] = vars[i]; + + for (i = 0; i < n_catvars; i++) + { + cov->catvars[i] = catvars[i]; + cov->n_categories[i] = 0; + } + + cov->moments = xmalloc (sizeof *cov->moments * n_MOMENTS); + + cov->exclude = exclude; + + return cov; +} + /* Return an integer, which can be used to index into COV->cm, to obtain the I, J th element of the covariance matrix. If COV->cm does not diff --git a/src/math/covariance.h b/src/math/covariance.h index 8b8de88e..ee096af6 100644 --- a/src/math/covariance.h +++ b/src/math/covariance.h @@ -29,6 +29,10 @@ struct ccase ; struct covariance * covariance_create (size_t n_vars, const struct variable **vars, const struct variable *wv, enum mv_class excl); +struct covariance * +covariance_2pass_create (size_t n_vars, const struct variable **vars, + size_t n_catvars, const struct variable **catvars, + const struct variable *weight, enum mv_class excl); void covariance_accumulate (struct covariance *, const struct ccase *);