Covariance matrix interface change.
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 14 Aug 2010 09:16:21 +0000 (11:16 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 24 Aug 2010 14:37:14 +0000 (16:37 +0200)
covariance_2pass_create now takes a pointer to a
struct categoricals which must be created by the caller,
instead of creating this object for itself.  This will
(hopefully) make the implementation of interactions and other
features easier.

src/language/stats/correlations.c
src/language/stats/glm.q
src/language/stats/oneway.c
src/math/covariance.c
src/math/covariance.h

index ea7d6909bb9844e3893ccf343920faa8477dace0..6af8ba32ffd54cc32f8e84baa8f77ee0192eee1d 100644 (file)
@@ -281,7 +281,7 @@ run_corr (struct casereader *r, const struct corr_opts *opts, const struct corr
   const gsl_matrix *cov_matrix;
   gsl_matrix *corr_matrix;
   struct covariance *cov = covariance_2pass_create (corr->n_vars_total, corr->vars,
-                                                   0, NULL,
+                                                   NULL,
                                                    opts->wv, opts->exclude);
 
   struct casereader *rc = casereader_clone (r);
index 5f20a2e3f0bf96da24b6a7214d6f0538a475ced9..13b097f3b8fce021c9004184b2427f9602e94643 100644 (file)
@@ -38,6 +38,7 @@
 #include <libpspp/compiler.h>
 #include <libpspp/message.h>
 #include <math/covariance.h>
+#include <math/categoricals.h>
 #include <math/linreg.h>
 #include <math/moments.h>
 #include <output/tab.h>
@@ -358,7 +359,13 @@ run_glm (struct casereader *input,
       k++;
     }
 
-  cov = covariance_2pass_create (n_numerics, numerics, n_categoricals, categoricals, NULL, MV_NEVER);
+  struct categoricals *cats = categoricals_create (categoricals,
+                                                  n_categoricals,
+                                                  NULL, MV_NEVER);
+
+  cov = covariance_2pass_create (n_numerics, numerics,
+                                cats,
+                                NULL, MV_NEVER);
 
   reader = casereader_clone (input);
   reader = casereader_create_filter_missing (reader, numerics, n_numerics,
index c9ae255ad7508160e59d69d1a55e23fb070b5571..da4669bcd82bbef394b9da5566a52465b631be5b 100644 (file)
@@ -325,10 +325,14 @@ run_oneway (const struct oneway_spec *cmd,
 
   ws.vws = xmalloc (cmd->n_vars * sizeof (*ws.vws));
 
+
   for (v = 0; v < cmd->n_vars; ++v)
     {
+      struct categoricals *cats = categoricals_create (&cmd->indep_var, 1,
+                                                  cmd->wv, cmd->exclude);
+
       ws.vws[v].cov = covariance_2pass_create (1, &cmd->vars[v],
-                                              1, &cmd->indep_var,
+                                              cats, 
                                               cmd->wv, cmd->exclude);
       ws.vws[v].cc = 0;
     }
index f0161a54c529c59b187d840611e3cde134d45852..aa7f41771c1ac9f3d55ff90d5a418010e5e032a8 100644 (file)
@@ -171,7 +171,7 @@ covariance_1pass_create (size_t n_vars, const struct variable *const *vars,
  */
 struct covariance *
 covariance_2pass_create (size_t n_vars, const struct variable *const *vars,
-                        size_t n_catvars, const struct variable *const *catvars, 
+                        struct categoricals *cats,
                         const struct variable *wv, enum mv_class exclude)
 {
   size_t i;
@@ -197,7 +197,7 @@ covariance_2pass_create (size_t n_vars, const struct variable *const *vars,
   cov->n_cm = -1;
   cov->cm = NULL;
 
-  cov->categoricals = categoricals_create (catvars, n_catvars, wv, exclude);
+  cov->categoricals = cats;
 
   return cov;
 }
@@ -296,7 +296,8 @@ covariance_accumulate_pass1 (struct covariance *cov, const struct ccase *c)
       cov->state = 1;
     }
 
-  categoricals_update (cov->categoricals, c);
+  if (cov->categoricals)
+    categoricals_update (cov->categoricals, c);
 
   for (i = 0 ; i < cov->dim; ++i)
     {
@@ -342,8 +343,11 @@ covariance_accumulate_pass2 (struct covariance *cov, const struct ccase *c)
       assert (cov->state == 1);
       cov->state = 2;
 
-      cov->dim = cov->n_vars +
-       categoricals_total (cov->categoricals) - categoricals_get_n_variables (cov->categoricals);
+      cov->dim = cov->n_vars;
+      
+      if (cov->categoricals)
+       cov->dim += categoricals_total (cov->categoricals) 
+         - categoricals_get_n_variables (cov->categoricals);
 
       cov->n_cm = (cov->dim * (cov->dim - 1)  ) / 2;
       cov->cm = xcalloc (sizeof *cov->cm, cov->n_cm);
@@ -355,7 +359,8 @@ covariance_accumulate_pass2 (struct covariance *cov, const struct ccase *c)
          cov->moments[i] = resize_matrix (cov->moments[i], cov->dim);
        }
 
-      categoricals_done (cov->categoricals);
+      if (cov->categoricals)
+       categoricals_done (cov->categoricals);
 
       /* Populate the moments matrices with the categorical value elements */
       for (i = cov->n_vars; i < cov->dim; ++i)
index fb59535718a5af952a8bd21a904a3213508f1203..cb83e151409224d1bf1d982a259179b9e79f5f49 100644 (file)
 struct covariance;
 struct variable;
 struct ccase ;
+struct categoricals;
 
 struct covariance * covariance_1pass_create (size_t n_vars, const struct variable *const *vars, 
                                             const struct variable *wv, enum mv_class excl);
 
 struct covariance *
 covariance_2pass_create (size_t n_vars, const struct variable *const *vars,
-                        size_t n_catvars, const struct variable *const *catvars, 
+                        struct categoricals *cats,
                         const struct variable *wv, enum mv_class excl);
 
 void covariance_accumulate (struct covariance *, const struct ccase *);