?? 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 + -