JunctionTreeGenerator.eliminationOrder

JunctionTreeGenerator.eliminationOrder(*args)

Computes an elimination order for its parameters. The order is chosen by heuristics that take the domain sizes into account and, if given, the partial order.

Parameters:
  • g (pyagrum.UndiGraph) – an undirected graph: all the nodes are given the same domain size (2)

  • dag (pyagrum.DAG) – a DAG, triangulated through its moral graph: all the nodes are given the same domain size (2)

  • bn (pyagrum.BayesNet) – a Bayesian network, triangulated through its moral graph, with the domain sizes of its variables

  • mrf (pyagrum.MarkovRandomField) – a Markov random field, triangulated through its graph, with the domain sizes of its variables

  • partial_order (list[set[int | str]], optional) – a partition of all the nodes into an ordered list of sets: the nodes of the first set are eliminated first, then those of the second set, and so on. The nodes are given by their ids, or by their names for a Bayesian network or a Markov random field.

Raises:
  • pyagrum.NotFound – If the partial order does not contain all the nodes, or if a name is not the name of a variable.

  • pyagrum.InvalidArgument – If the partial order is not a sequence of sets of nodes.

Returns:

the node ids, in their order of elimination.

Return type:

list[int]

Example

import pyagrum as gum

bn = gum.fastBN("A->B->C<-D;A->D")
order = gum.JunctionTreeGenerator().eliminationOrder(bn)
sorted(order) == sorted(bn.nodes())
# True

# a partial order (ids or names of the variables): C is eliminated first
order = gum.JunctionTreeGenerator().eliminationOrder(bn, [["C"], ["A", "B", "D"]])
bn.variable(order[0]).name()
# 'C'

# a Markov random field is triangulated through its graph
mrf = gum.fastMRF("A--B--C;C--D;D--A")
sorted(gum.JunctionTreeGenerator().eliminationOrder(mrf)) == sorted(mrf.nodes())
# True

Class

JunctionTreeGenerator