MAG.adjacencyMatrix

MAG.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/parents or neighbours methods; for a MAG, the symmetric matrix of adjacents)

Returns:

adjacency matrix (as numpy.ndarray): row and column i are those of the i-th node in increasing order of the ids, i.e. of sorted(self.nodes()) (the ids themselves when they are 0..n-1).

Return type:

numpy.ndarray

Example

import pyagrum as gum

dag = gum.fastDAG("A->X;Y<-B;X<-T->Y")
mag = gum.MAG.fromDAG(dag, {4})  # T latent: A->X<->Y<-B
mag.adjacencyMatrix()
# array([[0, 1, 0, 0],
#        [1, 0, 1, 0],
#        [0, 1, 0, 1],
#        [0, 0, 1, 0]])

Class

MAG