📄 smallworldnetwork.m
字号:
% function [adj_matr, nd_coord,clusterCof]=smallWorldNetwork(npoints,prob,degree)
% 生成beta-小世界网络
% inputs:
% npoints - 节点数
% beta - 概率
% degree - 网络的度
% Authors: LuoNa, ECUST
% v1.0 Created 30-May-2007
% number of points, npoints
clear;clc;
% if (nargin<3)
npoints =10;
beta=0.1;
degree=4
% end
%driven the number of points, nodes are uniformly distributed
for i=1:npoints
nd_coord(i, 1) = 1*cos(2*pi/npoints*i);
nd_coord(i, 2) = 1*sin(2*pi/npoints*i);
end
dist_matr=zeros(npoints,npoints);
% generate the adjacency matrix
for i=1:npoints
if i-1<1
a1=i-1+npoints;
else
a1=i-1;
end
if i-2<1
a2=i-2+npoints;
else
a2=i-2;
end
if i+1>npoints
a3=i+1-npoints;
else
a3=i+1;
end
if i+2>npoints
a4=i+2-npoints;
else
a4=i+2;
end
dist_matr(i,a1) =1;
dist_matr(i,a2) =1;
dist_matr(i,a3) =1;
dist_matr(i,a4) =1;
end
for i=1:npoints
if i == npoints
j=1;
else
j=i+1;
end
gama=rand;
if gama < beta
dist_matr(i,j)=0;
dist_matr(j,i)=0;
k=floor(rand*npoints)+1;
while dist_matr(i,k)==1
k=floor(rand*npoints)+1;
end
dist_matr(i,k)=1;
dist_matr(k,i)=1;
end
end
for i=1:npoints
if i == npoints
j=2;
elseif i== npoints-1
j=1;
else
j=i+2;
end
gama=rand;
if gama < beta
dist_matr(i,j)=0;
dist_matr(j,i)=0;
k=floor(rand*npoints)+1;
while dist_matr(i,k)==1
k=floor(rand*npoints)+1;
end
dist_matr(i,k)=1;
dist_matr(k,i)=1;
end
end
adj_matr = sparse(dist_matr);
% plot the network
% figure(1);
% clf;
hold on;
plot(nd_coord(:, 1), nd_coord(:, 2), '.');
for i=1:npoints
text(nd_coord(i, 1), nd_coord(i, 2),int2str(i),'FontSize',18);
end
gplot(adj_matr, nd_coord);
hold off;
% 特征路径长度(L):将每个定点v连接到所有其他定点的最短路径长度的均值的中位数,将L定义这些值的中位数
L=
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -