X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fcategoricals.c;h=8bd6683e2c94ab5d92dbe840fef7737adf367fdf;hb=0054d7bf45fb09a455698d1a180db93055f49dba;hp=d0247f6d38a453cbbf7220e04f11f879a5140d65;hpb=3cd65292e3cc6bd6532214dcc8c8ddc65bdc2972;p=pspp diff --git a/src/math/categoricals.c b/src/math/categoricals.c index d0247f6d38..8bd6683e2c 100644 --- a/src/math/categoricals.c +++ b/src/math/categoricals.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 2009, 2010, 2011, 2012, 2014 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ #include "math/categoricals.h" #include "math/interaction.h" +#include #include #include "data/case.h" @@ -103,7 +104,7 @@ lookup_variable (const struct hmap *map, const struct variable *var, unsigned in if (vn->var == var) break; - fprintf (stderr, "Warning: Hash table collision\n"); + fprintf (stderr, "%s:%d Warning: Hash table collision\n", __FILE__, __LINE__); } return vn; @@ -115,7 +116,7 @@ struct interact_params /* A map of cases indexed by a interaction_value */ struct hmap ivmap; - struct interaction *iact; + const struct interaction *iact; int base_subscript_short; int base_subscript_long; @@ -195,6 +196,31 @@ struct categoricals const struct payload *payload; }; + +bool +categoricals_isbalanced (const struct categoricals *cat) +{ + int i; + + for (i = 0 ; i < cat->n_iap; ++i) + { + int v; + const struct interact_params *iap = &cat->iap[i]; + + double oval = -1.0; + for (v = 0; v < hmap_count (&iap->ivmap); ++v) + { + const struct interaction_value *iv = iap->reverse_interaction_value_map[v]; + if (oval == -1.0) + oval = iv->cc; + if (oval != iv->cc) + return false; + } + } + return true; +} + + static void categoricals_dump (const struct categoricals *cat) { @@ -216,7 +242,7 @@ categoricals_dump (const struct categoricals *cat) } printf ("\n"); - printf ("Number of interactions %d\n", cat->n_iap); + printf ("Number of interactions %zu\n", cat->n_iap); for (i = 0 ; i < cat->n_iap; ++i) { int v; @@ -252,7 +278,7 @@ categoricals_dump (const struct categoricals *cat) assert (vn->var == var); - printf ("%g(%d)", val->f, valn->index); + printf ("%.*g(%d)", DBL_DIG + 1, val->f, valn->index); if (vv < iact->n_vars - 1) printf (", "); } @@ -270,6 +296,7 @@ categoricals_destroy (struct categoricals *cat) int i; if (NULL == cat) return; + for (i = 0; i < cat->n_iap; ++i) { struct interaction_value *iv = NULL; @@ -284,7 +311,6 @@ categoricals_destroy (struct categoricals *cat) free (cat->iap[i].enc_sum); free (cat->iap[i].df_prod); hmap_destroy (&cat->iap[i].ivmap); - interaction_destroy (cat->iap[i].iact); } /* Interate over each variable and delete its value map */ @@ -387,6 +413,7 @@ categoricals_update (struct categoricals *cat, const struct ccase *c) return; weight = cat->wv ? case_data (c, cat->wv)->f : 1.0; + weight = var_force_valid_weight (cat->wv, weight, NULL); assert (NULL == cat->reverse_variable_map_short); assert (NULL == cat->reverse_variable_map_long); @@ -445,10 +472,8 @@ categoricals_update (struct categoricals *cat, const struct ccase *c) if (cat->payload) { - double weight = cat->wv ? case_data (c, cat->wv)->f : 1.0; cat->payload->update (cat->aux1, cat->aux2, node->user_data, c, weight); } - } }