inferlo.pairwise.junction_tree.to_junction_tree_model

inferlo.pairwise.junction_tree.to_junction_tree_model(model, algorithm) JunctionizedModel[source]

Builds equivalent model on a junction tree.

First, builds a junction tree using algorithm from NetworkX which uses Minimum Fill-in heuristic.

Then, builds a new model in which variables correspond to nodes in junction tree - we will call them “supervariables”. Values of new supervariables are encoded values of original variables. New alphabet size is original alphabet size to the power of maximaljunction size. If some supervariables have less variables than others, we just don’t use all available for encoding “address space”. We mark those impossible values as having probability 0 (i.e log probability -inf).

Fields in new model are calculated by multiplying all field and interaction factors on variables in the same supervariable. While doing this, we make sure that every factor is counted only once. If some factor was accounted for in one supervariable field, it won’t be accounted for again in other supervariables.

Interaction factors in new model contain consistency requirement. If a variable of original model appears in multiple supervariables, we allow only those states where it takes the same value in all supervariables. We achieve that by using interaction factors which are equal to 1 if values of the same original variable in different supervariables are equal, and 0 if they are not equal. We actually use values 0 and -inf, because we work with logarithms.

See https://en.wikipedia.org/wiki/Tree_decomposition.

Parameters:
  • model – original model.

  • algorithm – decomposition algorithm.

Returns:

JunctionizedModel object, which contains junction tree and the new model, which is equivalent to original model, but whose graph is a tree.