BayesNetFragment.adjacencyMatrix
- BayesNetFragment.adjacencyMatrix()
adjacency matrix from a graph/graphical models
Compute the adjacency matrix of a pyAgrum’s graph or graphical models (more generally an object that has
nodes,children/parentsorneighboursmethods; for a MAG, the symmetric matrix ofadjacents)- Returns:
adjacency matrix (as numpy.ndarray): row and column
iare those of thei-th node in increasing order of the ids, i.e. ofsorted(self.nodes())(the ids themselves when they are0..n-1).- Return type:
numpy.ndarray
Example
import pyagrum as gum
bn = gum.fastBN("A->B->C<-D;C->E")
fragment = gum.BayesNetFragment(bn)
fragment.installAscendants("C") # A, B, C, D
print(fragment.adjacencyMatrix())
# [[0 1 0 0]
# [0 0 1 0]
# [0 0 0 0]
# [0 0 1 0]]
Class