def add_rewards_to_nodes_using_pagerank(cls, g, interactions, pagerank_func=nx.pagerank, **pr_kwargs): hig = construct_hig_from_interactions(interactions) pr = nx.pagerank(hig, **pr_kwargs) reward_func = lambda n: pr.get(n, 0.0) return cls.add_rewards_to_nodes(g, reward_func)
def test_pagerank_on_hig(self): pr = nx.pagerank( construct_hig_from_interactions(self.interactions) ) assert_true(pr['A'] < pr['F']) assert_true(pr['A'] < pr['B']) assert_true(pr['A'] < pr['C']) assert_true(pr['A'] < pr['D'])
def test_construct_hig(self): hig = construct_hig_from_interactions(self.interactions) a, b, c, d, e, f = ('A', 'B', 'C', 'D', 'E', 'F') assert_equal(sorted(range(1, 7) + [a, b, c, d, e, f, 'XXX']), sorted(hig.nodes())) print hig.edges() assert_equal( sorted([(a, 1), (1, b), (1, c), (1, d), (a, 2), (2, f), (d, 3), (3, e), (a, 4), (4, b), (d, 5), (5, f), (6, u'XXX'), (u'XXX', 6)]), sorted(hig.edges()))
def test_construct_hig(self): hig = construct_hig_from_interactions( self.interactions ) a, b, c, d, e, f = ('A', 'B', 'C', 'D', 'E', 'F') assert_equal( sorted( range(1, 7) + [a, b, c, d, e, f, 'XXX'] ), sorted(hig.nodes())) print hig.edges() assert_equal( sorted( [(a, 1), (1, b), (1, c), (1, d), (a, 2), (2, f), (d, 3), (3, e), (a, 4), (4, b), (d, 5), (5, f), (6, u'XXX'), (u'XXX', 6) ]), sorted(hig.edges()) )
def test_pagerank_on_hig(self): pr = nx.pagerank(construct_hig_from_interactions(self.interactions)) assert_true(pr['A'] < pr['F']) assert_true(pr['A'] < pr['B']) assert_true(pr['A'] < pr['C']) assert_true(pr['A'] < pr['D'])