Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Now using a numpy array to represent P
  • Loading branch information
sib12004 committed Apr 20, 2016
1 parent a4bc8f4 commit 2df6bab
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions pagerank.py
Expand Up @@ -4,6 +4,7 @@

import csv
import operator
import numpy as np

with open("hollins.dat", "r") as data:
reader = csv.reader(data, delimiter = ' ', skipinitialspace=True)
Expand Down Expand Up @@ -55,19 +56,28 @@ with open("hollins.dat", "r") as data:
# if i in destinations[j] : #if i is in the list of destinations
# P[(i,j)] = 1/N[j] #add 1/n_j to the matrix at (i,j)

#Make vector (list) N to store all n_j values
N = []
#Initialize an array/matrix P
P = np.zeros(V,V)

#populate the matrix
for j in range(0,V) :
if j in destinations : #need to check if it's in the dict
N.append(len(destinations[j]))
else :
N.append(0)
for i in range(0,V) :
if i in destinations[j] :
P[j][i] = 1/len(destinations[j])

P = P*damp + (1-damp) #modify P w/ dampening factor

#Make vector (list) N to store all n_j values
#N = []
#for j in range(0,V) :
# if j in destinations : #need to check if it's in the dict
# N.append(len(destinations[j]))
# else :
# N.append(0)

#Time to rank the pages!
#PR(V, initialVector, N, damp)
def PageRank(verts, initVec, outgoing, damp) :

#P[(i,j)] = P[(i,j)]*damp + (1-damp) #modify P w/ dampening factor

nextVector = initVec
for a in range(0,verts) :
Expand Down

0 comments on commit 2df6bab

Please sign in to comment.