Skip to content

Causal Model

class pyagrum.causal.CausalModel(bn, latentVarsDescriptor=None, keepArcs=False)

Section titled “class pyagrum.causal.CausalModel(bn, latentVarsDescriptor=None, keepArcs=False)”

From an observational BNs and the description of latent variables, this class represent a complet causal model obtained by adding the latent variables specified in latentVarsDescriptor to the Bayesian network bn.

  • Parameters:
    • bn (pyagrum.BayesNet) – an observational Bayesian network
    • latentVarsDescriptor (List [ (**str ,**List [**int ] ) ]) – list of couples (, <list of affected variables’ ids>).
    • keepArcs (bool) – By default, the arcs between variables affected by a common latent variable will be removed but this can be avoided by setting keepArcs to True

Add an arc x->y

  • Parameters:
    • x (int |**str) – the nodeId or the name of the first node
    • y (int |**str) – the nodeId or the name of the second node
  • Return type: None

addLatentVariable(name, lchild, keepArcs=False)

Section titled “addLatentVariable(name, lchild, keepArcs=False)”

Add a new latent variable with a name, a tuple of children and replacing (or not) correlations between children.

  • Parameters:
    • name (str) – the name of the latent variable
    • lchild (Tuple [**str ,**str ]) – the tuple of (2) children
    • keepArcs (bool) – do wee keep (or not) the arc between the children ?
  • Return type: None
  • Return type: Set[Tuple[NewType(NodeId, int), NewType(NodeId, int)]]
  • Returns: the set of arcs

Check if a backdoor exists between cause and effect

  • Parameters:
    • cause (int |**str) – the nodeId or the name of the cause
    • effect (int |**str) – the nodeId or the name of the effect
    • withNames (bool) – wether we use ids (int) or names (str)
  • Returns: None if no found backdoor. Otherwise return the found backdoors as set of ids or set of names.
  • Return type: None|Set[str]|Set[int]
  • Return type: BayesNet
  • Returns: the causal Bayesian network
  • Warning: do not infer any computations in this model. It is strictly a structural model

From a NodeId, returns its children (as a set of NodeId)

  • Parameters: x (int) – the node
  • Returns: the set of children
  • Return type: Set[int]

Return a map of connected components and their nodes.

  • Returns: thedisc of connected components
  • Return type: Dict[int,NodeSet]

Erase the arc x->y

  • Parameters:
    • x (int |**str) – the nodeId or the name of the first node
    • y (int |**str) – the nodeId or the name of the second node
  • Return type: None

Does the arc x->y exist ?

  • Parameters:
    • x (int |**str) – the nodeId or the name of the first node
    • y (int |**str) – the nodeId or the name of the second node
  • Returns: True if the arc exists.
  • Return type: bool

Check if a frontdoor exists between cause and effet

  • Parameters:
    • cause (int |**str) – the nodeId or the name of the cause
    • effect (int |**str) – the nodeId or the name of the effect
    • withNames (bool) – wether we use ids (int) or names (str)
  • Returns: None if no found frontdoot. Otherwise return the found frontdoors as set of ids or set of names.
  • Return type: None|Set[str]|Set[int]
  • Parameters: name (str) – the name of the variable
  • Returns: the id of the variable
  • Return type: int
  • Returns: the set of ids of latent variables in the causal model
  • Return type: NodeSet
  • Returns: the map NodeId,Name
  • Return type: Dict[int,str]
  • Return type: Set[NewType(NodeId, int)]
  • Returns: the set of nodes
  • Return type: BayesNet
  • Returns: the observational Bayesian network

From a NodeId, returns its parent (as a set of NodeId)

  • Parameters: x (int) – the node
  • Returns: the set of parents
  • Return type: Set[int]

Create a dot representation of the causal model

  • Return type: str
  • Returns: the dot representation in a string