BNLearner.setTotalOrder
- BNLearner.setTotalOrder(l)
Sets a total order on a set of nodes (not necessarily all the nodes). In the case where only a proper subset of all the nodes is passed in argument, then the constraint applies only on the arcs for which both extremal nodes belong to the set.
- Parameters:
l (
Iterable[int | str]) – the ids or names of the variables, in order (any iterable but a string)- Return type:
Example
import pyagrum as gum
with open("data.csv", "w") as f: # C is mostly "A or B"
f.write("A,B,C\n" + "0,0,0\n0,1,1\n1,0,1\n1,1,1\n" * 40 + "0,0,1\n0,1,0\n1,0,0\n1,1,0\n" * 5)
learner = gum.BNLearner("data.csv")
learner.useGreedyHillClimbing()
learner.setTotalOrder(["A", "B", "C"]) # arcs only from left to right
bn = learner.learnBN()
sorted(bn.parents("C")), bn.children("C")
# ([0, 1], set())
Class