Created
February 28, 2009 01:40
-
-
Save smly/71822 to your computer and use it in GitHub Desktop.
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
#!/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