Skip to content

Instantly share code, notes, and snippets.

@smly
Created February 28, 2009 03:43
Show Gist options
  • Save smly/71856 to your computer and use it in GitHub Desktop.
Save smly/71856 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# HITS (on memory)
# using von Neumann kernel
from numpy import *
from numpy import ones
from numpy.linalg import *
STEP = 500
class HITS():
def __init__(self, adj_matrix):
self._adj = adj_matrix
def calc_vnk(self):
cit_matrix = dot(self._adj.T, self._adj)
sz = size(cit_matrix[0])
beta = 1. / sorted( eigvals( cit_matrix ), reverse=True )[0] -0.001
mul_tmp = beta * cit_matrix
tmp = mul_tmp
ret = ones( (sz,sz) ) + mul_tmp
for i in range(STEP):
tmp = dot(tmp, mul_tmp)
ret += tmp
return dot(cit_matrix, ret)
adj = array( ((0, 0, 1, 1),
(0, 0, 1, 1),
(1, 1, 0, 0),
(0, 1, 1, 0)) )
hits = HITS(adj)
matrix = hits.calc_vnk()
print "matrix:"
print matrix
print "auth:", matrix[0,:]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment