def test():
    G = NX.DiGraph()
    edges = [(1,2), (1,3),
             (3,1), (3,2), (3,5),
             (4,5), (4,6),
             (5,4), (5,6),
             (6,4)]
    G.add_edges_from(edges)

    M = page_rank.google_matrix(G, alpha=0.9)
    e, ev = numpy.linalg.eig(M.T)
    p = numpy.array(ev[:,0] / ev[:,0].sum())[:,0]
    print "exact  ", p

    pr = page_rank.page_rank(G,alpha=0.9,tol=1.0e-8)
    print "networkx", pr.values()

    np = page_rank.page_rank_numpy(G,alpha=0.9)
    print "numpy  ", np

    try:
        ns = page_rank.page_rank_scipy(G,alpha=0.9)
        print "scipy  ", ns
    except Error:
        print "scipy not working"
Beispiel #2
0
def test():
    G = NX.DiGraph()
    edges = [(1, 2), (1, 3), (3, 1), (3, 2), (3, 5), (4, 5), (4, 6), (5, 4),
             (5, 6), (6, 4)]
    G.add_edges_from(edges)

    M = page_rank.google_matrix(G, alpha=0.9)
    e, ev = numpy.linalg.eig(M.T)
    p = numpy.array(ev[:, 0] / ev[:, 0].sum())[:, 0]
    print "exact  ", p

    pr = page_rank.page_rank(G, alpha=0.9, tol=1.0e-8)
    print "networkx", pr.values()

    np = page_rank.page_rank_numpy(G, alpha=0.9)
    print "numpy  ", np

    try:
        ns = page_rank.page_rank_scipy(G, alpha=0.9)
        print "scipy  ", ns
    except Error:
        print "scipy not working"
print "Finished reading the dataset --> Number of nodes of dataset = %s" % len(G.nodes())

#print G.edges()

print "Do you want to run numpy.linalg.eig? (y/n) [It might be very heavy]"
answer=sys.stdin.readline()[:-1]
if answer == "y":
    import numpy
    M=NX_future_page_rank.google_matrix(G,alpha=0.9)
    e,ev=numpy.linalg.eig(M.T)
    p=numpy.array(ev[:,0]/ev[:,0].sum())[:,0]
    print "exact  ", p

print "Do you want to run page_rank? (y/n) [It might be very heavy]"
answer=sys.stdin.readline()[:-1]
if answer == "y":
    pr = NX_future_page_rank.page_rank(G,alpha=0.9,tol=1.0e-8)
    print "networkx", pr.values()

print "Do you want to run page_rank numpy? (y/n) [It might be very heavy]"
answer=sys.stdin.readline()[:-1]
if answer == "y":
    np=NX_future_page_rank.page_rank_numpy(G,alpha=0.9)
    print "numpy  ", np

print "Do you want to run page_rank scipy? (y/n) [It might be very heavy]"
answer=sys.stdin.readline()[:-1]
if answer == "y":
    ns=NX_future_page_rank.page_rank_scipy(G,alpha=0.9)
    print "scipy  ", ns
    G.nodes())

#print G.edges()

print "Do you want to run numpy.linalg.eig? (y/n) [It might be very heavy]"
answer = sys.stdin.readline()[:-1]
if answer == "y":
    import numpy
    M = NX_future_page_rank.google_matrix(G, alpha=0.9)
    e, ev = numpy.linalg.eig(M.T)
    p = numpy.array(ev[:, 0] / ev[:, 0].sum())[:, 0]
    print "exact  ", p

print "Do you want to run page_rank? (y/n) [It might be very heavy]"
answer = sys.stdin.readline()[:-1]
if answer == "y":
    pr = NX_future_page_rank.page_rank(G, alpha=0.9, tol=1.0e-8)
    print "networkx", pr.values()

print "Do you want to run page_rank numpy? (y/n) [It might be very heavy]"
answer = sys.stdin.readline()[:-1]
if answer == "y":
    np = NX_future_page_rank.page_rank_numpy(G, alpha=0.9)
    print "numpy  ", np

print "Do you want to run page_rank scipy? (y/n) [It might be very heavy]"
answer = sys.stdin.readline()[:-1]
if answer == "y":
    ns = NX_future_page_rank.page_rank_scipy(G, alpha=0.9)
    print "scipy  ", ns
Beispiel #5
0
def numpyPR(G):
    np = page_rank.page_rank_numpy(G,alpha=0.9)
    return np
Beispiel #6
0
def numpyPR(G):
    np = page_rank.page_rank_numpy(G, alpha=0.9)
    return np