handunsir的个人博客分享 http://blog.sciencenet.cn/u/handunsir

博文

无向网络全局以及局部效率matlab程序

已有 6014 次阅读 2014-8-5 19:29 |系统分类:科研笔记

在网络规模不是太大时(网络节点小于1000为最佳),用matlab里graphallshortestpaths函数求解网络的效率是比较简单地,下面是求解无向网络效率程序

%全局效率

A=zeros(5,5);

A(1,2)=1;A(2,1)=1;A(2,3)=1;A(3,2)=1;A(1,3)=1;A(3,1)=1;A(4,2)=1;

A(2,4)=1;A(3,4)=1;A(4,3)=1;A(5,2)=1;A(2,5)=1;A(3,5)=1;A(5,3)=1;

% %%%%%%%%%%%%%%%%%%%%%%%只需把连接矩阵换成对应的矩阵即可

A=sparse(A);

ShortPath=1./graphallshortestpaths(A);

ShortPath(ShortPath==inf)=0;

Eglob=(1/(length(A)*(length(A)-1)))*sum(sum(ShortPath))


%局部效率

A=zeros(5,5);

A(2,3)=1;A(3,2)=1;A(5,2)=1;A(2,5)=1;A(3,5)=1;A(5,3)=1;

%%%%%%%%%%%%%%%%%%%只需把连接矩阵换成对应的矩阵即可

Eloca=0;

for i=1:length(A)

   Neigh=find(A(i,:)==1);

   if numel(Neigh)>1

       NeighPath=A(Neigh,Neigh);

        NeighPath=sparse(NeighPath);

       ShortPath=1./graphallshortestpaths(NeighPath);

      ShortPath(ShortPath==inf)=0;

       Eloca=Eloca+(1/(length(NeighPath)*(length(NeighPath)-1)))*sum(sum(ShortPath));

  end

end

Eloca=1./(length(A))*Eloca




https://blog.sciencenet.cn/blog-1668270-817316.html

上一篇:网络中一条边的两个端点度分别为D1和D2的统计程序
收藏 IP: 221.6.159.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-24 09:30

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部