Adjacency matrix from bn model #21
Replies: 1 comment
-
Hi @kenneth-lee-ch , there is no (particularly) efficient way to build this adjacency matrix since the internal representation is not this one. It is a simple code. The trickiest part is that you cannot rely on the nodeId to give the id for column or row in the matrix. def adjacencyMatrix(bn):
n=bn.size()
am=np.zeros((n,n))
idmap={bn.topologicalOrder()[i]:i for i in range(n)}
for i,j in bn.arcs():
am[idmap[i],idmap[j]]=1
#am[idmap[j],idmap[i]]=-1
return am (here, I rely on the topological order to give the order of the columns/rows in the matrix) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, is there an efficient way to extract an adjacency matrix from a bn object where the columns of the matrix corresponds to the same order in the sample generated from the bn object?
Beta Was this translation helpful? Give feedback.
All reactions