Skip to content

Instantly share code, notes, and snippets.

@musou1500
Created April 10, 2018 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save musou1500/97da29d6a2705b7acd8c44d3ebe52005 to your computer and use it in GitHub Desktop.
Save musou1500/97da29d6a2705b7acd8c44d3ebe52005 to your computer and use it in GitHub Desktop.
calc Authority and Hub by HITS algorithm
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