Matlab函数来计算平均邻近度 [英] Matlab function to compute average neighbor degree

查看:443
本文介绍了Matlab函数来计算平均邻近度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试搜索一个给matlab的函数,它给出了图的平均相邻度



python在network-X软件包中。所以我想知道在matlab中是否有类似的功能。



***********编辑******** ********



我无法将其转换为邻接矩阵。这实际上会占用太多空间。



我有下面的边界列表(实际上这只是一个测试矩阵,实际的矩阵非常大),就像节点2到节点1之间有一条边,等等..是的这是一个无向图
$ b $ 2 1 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创建一个邻接矩阵,它适合我们的内存 稀疏 matrix:

  el = [2 1; 3 1; ...]; %//边缘列表,我只在这里放了一个小样本... 
n = max(el(:)); %//图中节点的数量
A =稀疏(el(:,1),el(:,2),1,n,n); %//稀疏邻接矩阵

每个节点的邻居度是邻居的数量

  nd = sum(A,2); %//每个节点的度数

为了计算平均邻近度,可以构造另一个稀疏矩阵存储在每个条目中的邻居度bb
$ b $ ndM = sparse(el(:,1),el(:,2),nd (el(:,2)),n,n);

现在可以从新矩阵计算平均相邻程度

  av = full(sum(ndM,2)./ nd); 


I tried searching a function for matlab that gives the average neighbor degree of a graph.

There is a function for the same in python in network-X package. So i was wondering if there's a similar function in matlab.

***********Edit****************

I cannot convert it to an adjacency matrix.. this will occupy too much of space actually.

What i have is the following edge list(Actually this is just a test matrix.. the actual one is pretty large ) as in there's an edge between node 2 to node 1 and so on.. and yes this is an un-directed graph

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

Now, what i need is a function that will compute the average neighbor degree(mean neighbor degree) for this graph.

解决方案

Even for large edge list, you can use Matlab to create an adjacency matrix that fits into memory using sparse matrix:

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

The neighbor degree of each node is the number of neighbors

nd = sum( A, 2 ); %// degree of each node

To compute the average neighbor degree, one can construct another sparse matrix with the neighbor degree stored in each entry

ndM = sparse( el(:,1), el(:,2), nd( el(:,2) ), n, n ); 

The average neighbor degree can now be computed from the new matrix

av = full( sum( ndM, 2 ) ./ nd );

这篇关于Matlab函数来计算平均邻近度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆