X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fcategoricals.c;h=b621d982931c72c0eadbb04e420d943e10a5cded;hb=2dd71d2858a845fe8b10d7b279cb7c7e43c9ca16;hp=71ffe20ad7ee66ec646f1684bd524e44f5c043ca;hpb=bb0e1c1f8b1a87a0ccd9bb4ffb22466475a47b7f;p=pspp diff --git a/src/math/categoricals.c b/src/math/categoricals.c index 71ffe20ad7..b621d98293 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" @@ -76,15 +77,6 @@ struct variable_node struct hmap valmap; /* A map of value nodes */ int n_vals; /* Number of values for this variable */ - - int *indirection; /* An array (of size n_vals) of integers, which serve to - permute the index members of the values in valmap. - - Doing this, means that categories are considered in the order - of their values. Mathematically the order is irrelevant. - However certain procedures (eg logistic regression) want to report - statisitics for particular categories */ - }; @@ -112,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; @@ -124,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; @@ -225,7 +217,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; @@ -261,7 +253,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 (", "); } @@ -279,6 +271,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; @@ -293,7 +286,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 */ @@ -412,7 +404,8 @@ categoricals_update (struct categoricals *cat, const struct ccase *c) if (valn == NULL) { valn = pool_malloc (cat->pool, sizeof *valn); - valn->index = vn->n_vals++; + valn->index = -1; + vn->n_vals++; value_init (&valn->val, width); value_copy (&valn->val, val, width); hmap_insert (&vn->valmap, &valn->node, hash); @@ -553,15 +546,14 @@ categoricals_done (const struct categoricals *cat_) return; } - vn->indirection = pool_calloc (cat->pool, vn->n_vals, sizeof *vn->indirection); - /* Sort the VALMAP here */ array = xcalloc (sizeof *array, vn->n_vals); + x = 0; HMAP_FOR_EACH (valnd, struct value_node, node, &vn->valmap) { /* Note: This loop is probably superfluous, it could be done in the update stage (at the expense of a realloc) */ - array[valnd->index] = valnd; + array[x++] = valnd; } sort (array, vn->n_vals, sizeof (*array), @@ -570,7 +562,7 @@ categoricals_done (const struct categoricals *cat_) for (x = 0; x < vn->n_vals; ++x) { struct value_node *vvv = array[x]; - vn->indirection[vn->n_vals - x - 1] = vvv->index; + vvv->index = x; } free (array); @@ -753,9 +745,9 @@ categoricals_get_code_for_case (const struct categoricals *cat, int subscript, const int index = ((subscript - base_index) % iap->df_prod[v] ) / dfp; dfp = iap->df_prod [v]; - if (effects_coding && vn->indirection [valn->index] == df ) + if (effects_coding && valn->index == df ) bin = -1.0; - else if ( vn->indirection [valn->index] != index ) + else if ( valn->index != index ) bin = 0; result *= bin;