我尝试搜索 matlab 的函数,该函数给出图的平均邻度。
python 中的 network-X 包中有一个相同的函数。所以我想知道matlab中是否有类似的函数。
************编辑****************
我无法将其转换为邻接矩阵。这实际上会占用太多空间。
我所拥有的是以下边列表(实际上这只是一个测试矩阵..实际的矩阵相当大),因为节点 2 到节点 1 之间有一条边等等..是的,这是一个 un有向图
2 1
3 1
4 1
5 1
1 2
3 2
4 2
1 3
2 3
5 3
1 4
2 4
5 4
1 5
3 5
4 5
现在,我需要一个函数来计算该图的平均邻近度(平均邻近度)。
最佳答案
即使对于大型边列表,您也可以使用 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 );
关于Matlab函数计算平均邻度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25707419/