if (value_equal (&vn->val, val, width))
break;
}
-
+
return vn;
}
{
if (vn->var == var)
break;
-
+
fprintf (stderr, "%s:%d Warning: Hash table collision\n", __FILE__, __LINE__);
}
-
+
return vn;
}
int n_cats;
/* An array of integers df_n * df_{n-1} * df_{n-2} ...
- These are the products of the degrees of freedom for the current
+ These are the products of the degrees of freedom for the current
variable and all preceeding variables */
- int *df_prod;
+ int *df_prod;
double *enc_sum;
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)
{
}
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;
return iv;
}
-bool
+bool
categoricals_sane (const struct categoricals *cat)
{
return cat->sane;
{
size_t i;
struct categoricals *cat = xmalloc (sizeof *cat);
-
+
cat->n_iap = n_inter;
cat->wv = wv;
cat->n_cats_total = 0;
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);
if (valn == NULL)
{
valn = pool_malloc (cat->pool, sizeof *valn);
- valn->index = -1;
+ valn->index = -1;
vn->n_vals++;
value_init (&valn->val, width);
value_copy (&valn->val, val, width);
hmap_insert (&vn->valmap, &valn->node, hash);
}
}
-
+
for (i = 0 ; i < cat->n_iap; ++i)
{
const struct interaction *iact = cat->iap[i].iact;
hmap_insert (&cat->iap[i].ivmap, &node->node, hash);
- if (cat->payload)
+ if (cat->payload)
{
node->user_data = cat->payload->create (cat->aux1, cat->aux2);
}
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);
}
-
}
}
cat->iap[i].df_prod = iact->n_vars ? xcalloc (iact->n_vars, sizeof (int)) : NULL;
cat->iap[i].n_cats = 1;
-
+
for (v = 0 ; v < iact->n_vars; ++v)
{
int x;
x = 0;
HMAP_FOR_EACH (valnd, struct value_node, node, &vn->valmap)
{
- /* Note: This loop is probably superfluous, it could be done in the
+ /* Note: This loop is probably superfluous, it could be done in the
update stage (at the expense of a realloc) */
array[x++] = valnd;
}
- sort (array, vn->n_vals, sizeof (*array),
+ sort (array, vn->n_vals, sizeof (*array),
compare_value_node_3way, vn);
for (x = 0; x < vn->n_vals; ++x)
bin = -1.0;
else if ( valn->index != index )
bin = 0;
-
+
result *= bin;
}
}
/* Returns unity if the value in case C at SUBSCRIPT is equal to the category
- for that subscript.
+ for that subscript.
Else if it is the last category, return -1.
Otherwise return 0.
*/
}
-/* Return a case containing the set of values corresponding to
+/* Return a case containing the set of values corresponding to
the Nth Category of the IACTth interaction */
const struct ccase *
categoricals_get_case_by_category_real (const struct categoricals *cat, int iact, int n)