BNLearner.addMandatoryArc
- BNLearner.addMandatoryArc(*args)
Allow an arc to be added if necessary during structure learning (methods
learnDAG()orlearnBN()).- Usage:
addMandatoryArc(tail, head)
addMandatoryArc(arc)
- Parameters:
arc (
pyagrum.Arc) – an archead (
int | str) – a variable’s id or nametail (
int | str) – a variable’s id or name
- Raises:
pyagrum.InvalidDirectedCycle – If the added arc creates a directed cycle in the DAG
- 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.addMandatoryArc("A", "B") # not supported by the data, but mandatory
bn = learner.learnBN()
bn.existsArc("A", "B")
# True
Class