I have an adjacency matrix A with 2 initial connections in the upper left corner of the matrix (100*100).
I am trying to implement a preferential attachment algorithm, i.e. the nodes in the network with higher connectivity has a higher chance of getting connected to when a new node arrives. For that I'm looking at the following loop:
for j in range(3,N):
D=np.sum(A, axis=1)
d = np.sum(D)
P = np.cumsum(D / d) # is okay because interval between 1 and 1 is 0
r = np.random.uniform(0,1)
i = find([-1 P]<r, 1, 'last') # from matlab
if i<N and j<N: # stop before going out of bounds
A[i,j]=1
A[j,i]=1
I need an equivalent of this specific type of matlab find function in python.
The [-1 P] gives
-1.0000 0.2500 0.5000 0.7500 1.0000 1.0000 1.0000 ... up til 100 times. This will change as new nodes arrive, such that these new nodes also have some connectivity and the weight of that is represented by the size of the interval.
As such the idea is to find what interval the random number lies within, and spit out the the index i corresponding to the node within that interval. So for example a node with 2 connections has a larger interval than a node with 1 connection. "j" is given by the loop.
I've taken my main code from this answer: Preferential Attachment, Complex Networks in Matlab
That might give some more insight into what I'm trying to do if I'm being unclear.
Thanks in advance for any help :-)!