CausalModel.connectedComponents

CausalModel.connectedComponents()

Return the weakly connected components of the causal DAG (treating arcs as undirected).

Each node is mapped to the index of its component: 0, 1, …, (number of components - 1), numbered in the order in which the components are found.

Returns:

mapping node id → index of its component

Return type:

dict[int, int]

See also

connectedComponentsList

returns a dict[int, set[int]] grouping nodes by component

connectedComponentsCount

returns the number of components

Example

import pyagrum as gum

bn = gum.fastBN("A->B;C->D")
cm = gum.CausalModel(bn)
cc = cm.connectedComponents()
cc[cm.idFromName("A")] == cc[cm.idFromName("B")]
# True
cc[cm.idFromName("A")] == cc[cm.idFromName("C")]
# False

Class

CausalModel