I have a small patch which perhaps you could review before I push it.

J'

On Sun, Sep 18, 2011 at 05:18:09PM -0400, Jason Stover wrote:
     I just pushed a fixe for type 3 sums of squares in the presence of
     interactions. 
     
     -Jason
     
     _______________________________________________
     pspp-dev mailing list
     [email protected]
     https://lists.gnu.org/mailman/listinfo/pspp-dev

-- 
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://pgp.mit.edu or any PGP keyserver for public key.

commit fbfe1712cba1525b841bcbb6d5bf7c5532cda0c5
Author: John Darrington <[email protected]>
Date:   Fri Sep 23 15:56:45 2011 +0200

    Move interaction subset predicates out of glm.c into interaction.c
    
    Renamed function:   is_subset --> interaction_is_proper_subset
                        drop_from_submodel --> interaction_is_subset
    and moved them into interaction.c  This seems to me to be easier
    to understand, and more efficient.

diff --git a/src/language/stats/glm.c b/src/language/stats/glm.c
index dddf391..b23832f 100644
--- a/src/language/stats/glm.c
+++ b/src/language/stats/glm.c
@@ -347,59 +347,6 @@ not_dropped (size_t j, const size_t *dropped, size_t n_dropped)
   return true;
 }
 
-/*
-  Do the variables in X->VARS constitute a proper
-  subset of the variables in Y->VARS?
- */
-static bool
-is_subset (const struct interaction *x, const struct interaction *y)
-{
-  size_t i;
-  size_t j;
-  size_t n = 0;
-
-  if (x->n_vars < y->n_vars)
-    {
-      for (i = 0; i < x->n_vars; i++)
-	{
-	  for (j = 0; j < y->n_vars; j++)
-	    {
-	      if (x->vars [i] == y->vars [j])
-		{
-		  n++;
-		}
-	    }
-	}
-    }
-  if (n >= x->n_vars)
-    return true;
-  return false;
-}
-
-static bool
-drop_from_submodel (const struct interaction *x, const struct interaction *y)
-{
-  size_t i;
-  size_t j;
-  size_t n = 0;
-
-  if (is_subset (x, y))
-    return true;
-
-  for (i = 0; i < x->n_vars; i++)
-    for (j = 0; j < y->n_vars; j++)
-      {
-	if (x->vars [i] == y->vars [j])
-	  n++;
-      }
-  if (n == x->n_vars)
-    {
-      return true;
-    }
-
-  return false;
-}
-
 static void
 fill_submatrix (gsl_matrix * cov, gsl_matrix * submatrix, size_t * dropped,
 		size_t n_dropped)
@@ -448,12 +395,12 @@ get_ssq (struct covariance *cov, gsl_vector *ssq, const struct glm_spec *cmd)
 	{
 	  const struct interaction * x = 
 	    categoricals_get_interaction_by_subscript (cats, i - cmd->n_dep_vars);
-	  if (is_subset (cmd->interactions [k], x))
+	  if (interaction_is_proper_subset (cmd->interactions [k], x))
 	    {
 	      assert (n_dropped_model < covariance_dim (cov));
 	      model_dropped[n_dropped_model++] = i;
 	    }
-	  if (drop_from_submodel (cmd->interactions [k], x))
+	  if (interaction_is_subset (cmd->interactions [k], x))
 	    {
 	      assert (n_dropped_submodel < covariance_dim (cov));
 	      submodel_dropped[n_dropped_submodel++] = i;
diff --git a/src/math/interaction.c b/src/math/interaction.c
index d24166d..d81eba5 100644
--- a/src/math/interaction.c
+++ b/src/math/interaction.c
@@ -72,6 +72,56 @@ interaction_add_variable (struct interaction *i, const struct variable *v)
 }
 
 
+/*
+  Do the variables in X->VARS constitute a proper
+  subset of the variables in Y->VARS?
+ */
+bool
+interaction_is_proper_subset (const struct interaction *x, const struct interaction *y)
+{
+  if (x->n_vars >= y->n_vars)
+    return false;
+
+  return interaction_is_subset (x, y);
+}
+
+/*
+  Do the variables in X->VARS constitute a 
+  subset (proper or otherwise) of the variables in Y->VARS?
+ */
+bool
+interaction_is_subset (const struct interaction *x, const struct interaction *y)
+{
+  size_t i;
+  size_t j;
+  size_t n = 0;
+
+  /* By definition, a subset cannot have more members than its superset */
+  if (x->n_vars > y->n_vars)
+    return false;
+
+  /* Count the number of values which are members of both sets */
+  for (i = 0; i < x->n_vars; i++)
+    {
+      for (j = 0; j < y->n_vars; j++)
+	{
+	  if (x->vars [i] == y->vars [j])
+	    {
+	      n++;
+	    }
+	}
+    }
+
+  /* If ALL the members of X were also found in Y, then this must be a subset */    
+  if (n >= x->n_vars)
+    return true;
+
+  return false;
+}
+
+
+
+
 void
 interaction_dump (const struct interaction *i)
 {
diff --git a/src/math/interaction.h b/src/math/interaction.h
index cd38ae2..0fb1f26 100644
--- a/src/math/interaction.h
+++ b/src/math/interaction.h
@@ -37,6 +37,8 @@ void interaction_destroy (struct interaction *);
 void interaction_add_variable (struct interaction *, const struct variable *);
 void interaction_dump (const struct interaction *);
 void interaction_to_string (const struct interaction *iact, struct string *str);
+bool interaction_is_proper_subset (const struct interaction *x, const struct interaction *y);
+bool interaction_is_subset (const struct interaction *x, const struct interaction *y);
 
 
 struct ccase;

Attachment: signature.asc
Description: Digital signature

_______________________________________________
pspp-dev mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/pspp-dev

Reply via email to