BNLearner.addMandatoryArc

BNLearner.addMandatoryArc(*args)

Allow an arc to be added if necessary during structure learning (methods learnDAG() or learnBN()).

Usage:
  1. addMandatoryArc(tail, head)

  2. addMandatoryArc(arc)

Parameters:
  • arc (pyagrum.Arc) – an arc

  • head (int | str) – a variable’s id or name

  • tail (int | str) – a variable’s id or name

Raises:

pyagrum.InvalidDirectedCycle – If the added arc creates a directed cycle in the DAG

Return type:

BNLearner

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

BNLearner