Closed Ejaz125 closed 6 years ago
We used Snap.py (https://snap.stanford.edu/snappy/) to plot the betweenness centrality. The following code will convert an adjacency matrix into a network and then measure the betweenness centrality of each node:
from snap import *
import numpy as np
tol = 1e-5
fileName = XX_FileName_Here_XX
adj = np.loadtxt(fileName,delimiter=',')
m,n = adj.shape
edgeFile = "temp.txt"
with open(edgeFile, 'a') as file:
for i in range(m):
for j in range(n):
if((adj[i,j] > tol or adj[i,j] < -1*tol)):
file.write(str(i)+'\t'+str(j)+'\n')
file.close()
G5 = LoadEdgeList(PUNGraph, edgeFile, 0, 1)
Nodes = TIntFltH()
Edges = TIntPrFltH()
GetBetweennessCentr(G5, Nodes, Edges, 1.0)
for node in Nodes:
if (Nodes[node] > 0):
print "node: %d, %d, centrality: %f" % (node, node%7, Nodes[node])
Thank you for the snippet!
What did you use as the criteria for constructing the adjacency matrix (e.g inverse covariance matrix) between the different sensor signals?
The adjacency matrix is just the cluster_MRF parameters (the second output that TICC.solve returns)
It seems that the output of TICC.fit is a dictionary with the cluster numbers as keys and [nw,nw] inverse covariance matrices as values, where n is number of features and w is the window size. Should we run the above code on the inverse covariance matrix for each cluster?
Hello! Thank you for sharing the code above. Regarding the example for car trajectories in the paper, w is set to 10 observations (also according to car.py), my question is how to get from the above code [a cluster's MRF in the paper is a matrix of 70*70] to a single value for betweeness centrality for each cluster and feature. From above code, length of Nodes is 70 so we have 10 betweeness centrality values for each feature whereas we want a single value (i.e., the cell values in table 3 in paper). Was there any in-between step like averaging? Thank you for your help @davidhallac
Hi,
Is it possible to upload the code where the betweenness centrality for each car sensor is computed? Thanks in advance!