This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def uncorrelated(data, steps=10): | |
N = len(data) | |
for i in range(steps*N): | |
pos = np.random.randint(N) # Select an element at random | |
data[pos] = np.random.random() # Replace the value | |
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bak_sneppen(data, steps=10): | |
N = len(data) | |
for i in range(steps*N): | |
pos = np.argmin(data) # Find the position of the minimum value | |
# Replace the minimum valuea and both it's neighbours | |
data[(pos-1) % N] = np.random.random() | |
data[pos] = np.random.random() | |
data[(pos+1) % N] = np.random.random() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compute the "Google" Matrix from the adjacency matrix, A. | |
# For illustration purposes only. *Not* efficient! | |
def Google_Matrix(A, m): | |
N = A.shape[0] | |
v = np.ones(N) | |
# Calculate the degree of each node | |
KT = np.dot(A.T, v) | |
# Normalize the columns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Perform the power method for "iter" iterations | |
def Power_Method(G, iter): | |
N = G.shape[0] | |
x0 = np.ones(N)/N | |
for i in range(iter): | |
x0 = np.dot(G, x0) | |
return x0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def BarabasiAlbert(N): | |
net = np.zeros(2*N, dtype='int') | |
# Edges represented by sequence of nodes | |
net[:6] = [0, 1, 1, 2, 2, 3] | |
# Generate the network | |
for i in xrange(3, N): | |
pos = np.random.randint(0, i) | |
net[2*i] = i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ErdosRenyi(N, m=N): | |
net = np.zeros(2*m, dtype='int') | |
for i in xrange(m): | |
while True: | |
node1, node2 = np.random.randint(0, N, 2) | |
# No self loops allowed | |
if node1 != node2: | |
break |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
OlderNewer