matlab 无尺度网络scale-free network模拟

这是非官方的容易理解的同样的网络模型模拟

下面的官方的模拟(但自己没有去看,只是粘过来而已):

function A = BAgraph_dir(N,mo,m)
% Generates a scale-free directed adjacency matrix using Barabasi and Albert algorithm
% Input: N - number of nodes in the network, mo - size of seed, m = average degree. Use mo=m or m<mo.
% Example: A = BAgraph(300,10,10);
% Ref: Methods for generating complex networks with selected structural properties for simulations, Pretterjohn et al, Frontiers Comp Neurosci

% Author:
% Tapan P Patel, Ph.D., tapan.p.patel@gmail.com
% University of Pennsylvania
hwait = waitbar(0,'Please wait. Generating directed scale-free adjacency matrix');
A = zeros(N);
E = 0;
for i=1:mo
    for j=i+1:mo

        A(i,j) =1;
        A(j,i) = 1;
        E = E + 2;
    end
end
% Second add remaining nodes with a preferential attachment bias - rich get
% richer
for i=mo+1:N
    waitbar(i/N,hwait,sprintf('Please wait. Generating directed scale-free adjacency matrix\n%.1f %%',(i/N)*100));
    curr_deg =0;
    while(curr_deg<m)
        sample = setdiff(1:N,[i find(A(i,:))]);
        j = datasample(sample,1);
        b = sum(A(j,:))/E;
        r = rand(1);
        if(b>r)
            r = rand(1);
            if(b>r)
            A(i,j) = 1;
            A(j,i) = 1;
            E = E +2;
            else
            A(i,j) = 1;
            E = E +1;
            end
        else
            no_connection = 1;
            while(no_connection)
                sample = setdiff(1:N,[i find(A(i,:))]);
                h = datasample(sample,1);
                b = sum(A(h,:))/E;
                r = rand(1);
                if(b>r)
                    r = rand(1);
                    if(b>r)
                    A(h,i) = 1;
                    A(i,h) = 1;
                    E = E +2;
                    else
                    A(i,h) = 1;
                    E = E+1;
                    end
                    no_connection = 0;
                end
            end
        end
        curr_deg = sum(A(i,:));
    end
end
delete(hwait);

最后若需要作图的话,就G=dirgraph(A);plot(G)即可

  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值