Created
October 1, 2016 17:11
-
-
Save bmtgoncalves/f7ec3f6b267988d3d9d6c3b5afd5409c to your computer and use it in GitHub Desktop.
Calculating the Google Matrix from the Adjacenty Matrix
This file contains hidden or 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 | |
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