优先附件,Matlab中的复杂网络 [英] Preferential Attachment, Complex Networks in Matlab
问题描述
嘿,大家好!
我现在正在使用MATLAB中的优先附件模型进行工作,我在理解以下内容时遇到了一些麻烦:
I am right now working on a preferential attachment model in MATLAB and I have some troubles to understand the following:
假设我一开始有4个节点,像这样连接:
Assuming I have 4 nodes in the beginning, connected like this:
time = 0
1 <-----> 2
3 <-----> 4
在下一个步骤中,我添加一个节点和4个连接,然后添加另一个节点和4个连接.
我链接到节点i的概率的公式为:
In the next time step I add a single node and 4 connections, then another single node and 4 connections.
The formula for my linking probability to node i is:
P_link(i) = degree(i) / sum of all degrees at time-1
第一步,每个节点i = 1到4的概率为1/4,然后,将节点5连接到1、2、3和4,我将得到一个度和" "= 12,则在随后的时间步中添加节点6.
这意味着链接概率为:1/6、1/6、1/6、1/6和1/3.
This results in the probabilities of 1/4 for each of the nodes i = 1 to 4 in the first step and then, having node 5 connected to 1, 2, 3 and 4, I will have a "sum of degrees" = 12, when adding node 6 in the following time step.
That then means the linking probabilities are: 1/6, 1/6, 1/6, 1/6 and 1/3.
如何在MATLAB中进行设置?我的问题是,我通常将这些东西写在纸上以获得更好的理解,如果有随机化,我只是在纸上模拟"它以与简单的MATLAB程序进行比较.
How can I set this up in MATLAB? My problem is, I normally write these things on paper to get a better understanding, and if there is a randomisation I just "simulate" it on paper to compare it with a simple MATLAB program.
我现在要做的是:我取一个随机数,比方说0.3045.
要将其添加到节点,它必须在
What I would now do is: I take a random number, let's say 0.3045.
To add this to a node it would have to be in the range of
node1: [0.0000, 1/6],
node2: [1/6, 1/3],
node3: [1/3, 1/2],
node4: [1/2, 2/3],
node5: [2/3, 1.0000].
---> CONNECT to node2
因此,第一步我对如何做有一个想法,但是现在我有两个不同的问题,我认为它们是密切相关的:
So for the first step I have an idea of how to do it, but now I have two different problems, which are, I think, closely related:
- 我如何在MATLAB中实现这一点,范围方法是一个好主意吗?
- 假设其余每个节点只能连接一次,那么在添加其余的第一个连接后,概率如何变化? (这可能是我必须承认的一个更数学的问题……)
非常抱歉,这个问题看起来很混乱,但我希望有人能给我一些有关此实现的提示.
预先感谢!
I am very sorry, this question looks so messy, but I hope someone can give me some hints about the implementation of this.
Thanks in advance!
推荐答案
我将执行以下操作...
I would do the following...
拥有邻接矩阵
>> A = [0 1 0 0; 1 0 0 0; 0 0 0 1; 0 0 1 0]
和度矩阵
>> D = sum(A)
在每次迭代中,任意顶点i
的度为D(i)
,度的总数为
In every iteration, the degree of any vertex i
is D(i)
and total number of degrees is
>> d = sum(D)
请注意,您想要在第一次迭代之前获取d
,然后在迭代循环的末尾再次获取d
,以使其保持值为time-1
,在这种情况下,您可能希望将P
通过
Note, that you want to obtain d
prior to the first iteration, and then again at the very end of iteration loop, so that it remains with value of time-1
, in which case you might want to normalize P
by doing
>> P = P ./ max(P)
然后计算选择任何顶点的概率(即,简化了范围方法)
Probabilities of picking any vertex (ie. your range approach simplified) are then calculated
>> P = cumsum(D ./ d)
ans = [0.2500, 0.5000, 0.7500, 1.0000]
对于范围为<0,1>
的随机标量数r
,您可以选择随机选择的顶点的索引i
,
And with random scalar number r
from range <0,1>
, you choose index i
of randomly selected vertex by
>> i = find([-1 P]<r, 1, 'last')
然后要将索引为j
的新顶点推送到A
,并将其连接到旧顶点i
,您只需
And to push the new vertex with index j
to A
, connecting it to old vertex i
, you simply
>> A(i, j) = 1
>> A(j, i) = 1
现在,您只需将所有内容括在循环并解决您的问题;]
Now you simply enclose everything in loop and voilà you problem solved ;]
这篇关于优先附件,Matlab中的复杂网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!