Created
April 10, 2018 06:52
-
-
Save musou1500/97da29d6a2705b7acd8c44d3ebe52005 to your computer and use it in GitHub Desktop.
calc Authority and Hub by HITS algorithm
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
import numpy as np | |
graph = np.array([[0, 1, 0, 0], [1, 0, 1, 0], [1, 0, 0, 1], [0, 1, 0, 0]]) | |
size = len(graph) | |
a = np.full((size, 1), 1.0 / size) | |
h = np.full((size, 1), 1.0 / size) | |
iter_cnt = 3 | |
for i in range(iter_cnt): | |
prev_a = a | |
prev_h = h | |
a = np.dot(graph, prev_h) | |
a = a * (1 / np.sum(a)) | |
h = np.dot(graph.T, prev_a) | |
h = h * (1 / np.sum(h)) | |
print('iter {}\n---'.format(i)) | |
print('a: {}\nh: {}\n'.format(a, h)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment