+
+ cat->reverse_variable_map_short = pool_calloc (cat->pool,
+ cat->df_sum,
+ sizeof *cat->reverse_variable_map_short);
+
+ cat->reverse_variable_map_long = pool_calloc (cat->pool,
+ cat->n_cats_total,
+ sizeof *cat->reverse_variable_map_long);
+
+ for (i = 0 ; i < cat->n_iap; ++i)
+ {
+ struct interaction_value *ivn = NULL;
+ int x = 0;
+ int ii;
+ struct interact_params *iap = &cat->iap[i];
+
+ iap->base_subscript_short = idx_short;
+ iap->base_subscript_long = idx_long;
+
+ iap->reverse_interaction_value_map = pool_calloc (cat->pool, iap->n_cats,
+ sizeof *iap->reverse_interaction_value_map);
+
+ HMAP_FOR_EACH (ivn, struct interaction_value, node, &iap->ivmap)
+ {
+ iap->reverse_interaction_value_map[x++] = ivn;
+ }
+
+ assert (x <= iap->n_cats);
+
+ /* For some purposes (eg CONTRASTS in ONEWAY) the values need to be sorted */
+ sort (iap->reverse_interaction_value_map, x, sizeof (*iap->reverse_interaction_value_map),
+ compare_interaction_value_3way, iap);
+
+ /* Fill the remaining values with null */
+ for (ii = x ; ii < iap->n_cats; ++ii)
+ iap->reverse_interaction_value_map[ii] = NULL;
+
+ /* Populate the reverse variable maps. */
+ if (iap->df_prod)
+ {
+ for (ii = 0; ii < iap->df_prod [iap->iact->n_vars - 1]; ++ii)
+ cat->reverse_variable_map_short[idx_short++] = i;
+ }
+
+ for (ii = 0; ii < iap->n_cats; ++ii)
+ cat->reverse_variable_map_long[idx_long++] = i;
+ }
+
+ assert (cat->n_vars <= cat->n_iap);
+
+ categoricals_dump (cat);
+
+ /* Tally up the sums for all the encodings */
+ for (i = 0 ; i < cat->n_iap; ++i)
+ {
+ int x, y;
+ struct interact_params *iap = &cat->iap[i];
+ const struct interaction *iact = iap->iact;
+
+ const int df = iap->df_prod ? iap->df_prod [iact->n_vars - 1] : 0;
+
+ iap->enc_sum = xcalloc (df, sizeof (*(iap->enc_sum)));
+
+ for (y = 0; y < hmap_count (&iap->ivmap); ++y)
+ {
+ struct interaction_value *iv = iap->reverse_interaction_value_map[y];
+ for (x = iap->base_subscript_short; x < iap->base_subscript_short + df ;++x)
+ {
+ const double bin = categoricals_get_effects_code_for_case (cat, x, iv->ccase);
+ iap->enc_sum [x - iap->base_subscript_short] += bin * iv->cc;
+ }
+ if (cat->payload && cat->payload->calculate)
+ cat->payload->calculate (cat->aux1, cat->aux2, iv->user_data);
+ }
+ }
+
+ cat->sane = true;