我尝试在matlab中搜索一个函数,该函数给出了图的平均邻域度。
在network包中的python中有一个相同的函数。所以我想知道matlab中是否有类似的函数。
***********Edit****************
我不能把它转换成邻接矩阵。这实际上会占用太多的空间。
我有以下的边缘列表(实际上这只是一个测试矩阵..。例如,在节点2到节点1之间有一个边缘,等等。是的,这是一个无向图。
2 1
3 1
4 1
5 1
[经]1 2
3 2
4 2
1 3
2 3
5 3
[1]1 4
2 4
5 4
1 5
3 5
4 5
现在,我需要一个函数来计算这个图的平均邻域度(平均近邻度)。
发布于 2014-09-07 06:16:22
即使对于大的边缘列表,您也可以使用Matlab创建一个邻接矩阵,使用sparse矩阵将其放入内存中:
el = [2 1; 3 1; ... ]; %// edge list, I put only a tiny sample here...
n = max( el(:) ); %// number of nodes in the graph
A = sparse( el(:,1), el(:,2), 1, n, n ); % //sparse adjacency matrix每个节点的邻域度是相邻节点的数目。
nd = sum( A, 2 ); %// degree of each node要计算平均邻域度,可以用存储在每个条目中的邻域度来构造另一个稀疏矩阵。
ndM = sparse( el(:,1), el(:,2), nd( el(:,2) ), n, n ); 现在可以从新的矩阵计算平均近邻度。
av = full( sum( ndM, 2 ) ./ nd );https://stackoverflow.com/questions/25707419
复制相似问题