Skip to content

Instantly share code, notes, and snippets.

@bmtgoncalves
Created October 1, 2016 17:11
Show Gist options
  • Save bmtgoncalves/f7ec3f6b267988d3d9d6c3b5afd5409c to your computer and use it in GitHub Desktop.
Save bmtgoncalves/f7ec3f6b267988d3d9d6c3b5afd5409c to your computer and use it in GitHub Desktop.
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
for i in range(N):
A.T[i] = A.T[i]/KT[i]
# Add random links
S = np.ones((N, N))/N
G = (1-m)*A+m*S
return G
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment