Skip to content

Instantly share code, notes, and snippets.

@smly
Created February 28, 2009 01:40
Show Gist options
  • Save smly/71823 to your computer and use it in GitHub Desktop.
Save smly/71823 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# HITS (on memory)
# using co-citation matrix
from numpy import *
from numpy.linalg import *
class HITS():
def __init__(self, adj_matrix):
self._adj = adj_matrix
def calc(self):
cit_matrix = dot(self._adj.T, self._adj)
bib_matrix = dot(self._adj, self._adj.T)
e_val,e_vec = eig( cit_matrix )
auth = sorted( zip( e_val, e_vec.T ), reverse=True )
e_val,e_vec = eig( bib_matrix )
hub = sorted( zip( e_val, e_vec.T ), reverse=True )
return (auth[0][1] / sum(auth[0][1]),
hub[0][1] / sum(hub[0][1]))
Adj = array( ((0, 0, 1, 1),
(0, 0, 1, 1),
(1, 1, 0, 0),
(0, 1, 1, 0)) )
hits = HITS(Adj)
(auth,hub) = hits.calc()
print "auth:", auth
print "hub:", hub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment