⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ba.m

📁 这是用matlab编写的无标度网路模型的生成
💻 M
字号:
%   At first there are only m nodes and no edge, then the m+1st node is%   connected with the above m nodes%   usage: Nodes = BA(N,m)%   the parameter:N----network size%                 m----a new node with m new edges%   can randomly initialize the N and the m by yourself%   the  diagonal elements of the matrix also equal to -degree%   Nodes----the final coupling matrix%   The following message(s) may not be displayed correctly for they contain Chinese charactors.%   list----生成的一个辅助向量,该向量中的元素为每条边端点的节点。for example, 假设网络中节点4的度为7,则在list向量中会存在7个4,而这7个4的位置不一定是连续在一起的。%   preferential attachment体现在随机的从list向量中选取元素,选中哪个元素,该元素表示的节点即被选中。由于list向量中每个节点的个数与它的度有关,因此,度越大的点被选中的概率越大。function [Nodes,Cii]=BA(N,m)% N=10,m=3;Nodes=zeros(N);Cii=zeros(1,N);t=zeros(1,N);%Nodes=sparse(N);for i=1:m    Nodes(i,m+1)=1;    Nodes(m+1,i)=1;    list(i)=i;endfor i=m+1:2*m    list(i)=m+1;endfor n=m+2:N                  % start from m+2 to grow the network    t=2*m*(n-m-1) ;           % for list, every time t increases 2m    % t=m*(n-m-1);    for i=1:m        list(t+i)=n;          % in the list, every time the above m is n, it represents that the nth nodes is connected to other m nodes    end    k=1;     while k<m+1               % grow other m nodes        p(k)=round((t+1)*rand(1));         %    random choose an integer from 1~N        if p(k)>0&p(k)<(t+1)            if Nodes(n,list(p(k)))==0               list(t+m+k)=list(p(k));                Nodes(n,list(p(k)))=1;                Nodes(list(p(k)),n)=1;                k=k+1;            end   %end for j         end    %end for k    end %end for nend%Write_Sparse_Matrix(Nodes,['BA',num2str(N),'.txt']);%Write_into_Pajek(Nodes,['BA',num2str(N),'.net']);% for i=1:N%     Nodes(i,i)=sum(Nodes(:,i));%     Cii(i)=Nodes(i,i);% endfor i=1:N     Cii(i)=sum(Nodes(:,i));  t(i)=list(i)end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -