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;
-/* 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)
cov->wv = weight;
cov->n_vars = n_vars;
+ cov->dim = n_vars;
for (i = 0; i < n_vars; ++i)
cov->vars[i] = vars[i];
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
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 *);