Skip to content

Instantly share code, notes, and snippets.

View bmtgoncalves's full-sized avatar
💭
Hacking Away!

Bruno Gonçalves bmtgoncalves

💭
Hacking Away!
View GitHub Profile
@bmtgoncalves
bmtgoncalves / uncorr_min.py
Last active September 11, 2016 16:09
Uncorrelated and Minimum functions
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
@bmtgoncalves
bmtgoncalves / Bak_Sneppen.py
Created September 11, 2016 16:12
Bak_Sneppen model
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()
@bmtgoncalves
bmtgoncalves / GoogleMatrix.py
Created October 1, 2016 17:11
Calculating the Google Matrix from the Adjacenty Matrix
# 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
# 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
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
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.
@bmtgoncalves
bmtgoncalves / Timeseries Map.ipynb
Last active July 4, 2021 12:34
Timeseries Map.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bmtgoncalves
bmtgoncalves / 3D Plot.ipynb
Created July 11, 2021 14:41
3D Plot.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bmtgoncalves
bmtgoncalves / Color Blindness.ipynb
Last active September 11, 2022 22:03
Color Blindness.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.