Skip to content

Commit

Permalink
Trying to optimize the code to run in a reasonable amount of time
Browse files Browse the repository at this point in the history
  • Loading branch information
sib12004 committed Apr 21, 2016
1 parent bcc02ca commit 9e5c5f6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pagerank2.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@

#PR(P, initialVector, damp)
def PageRank(trans, initVec, damp, n=0) :

length = len(initVec)

nextVector = []
nextVector = [0] * length

for i in range(len(initVec)) :
total = 0
for j in range(len(initVec)) :
total += initVec[j]*trans[i][j]
nextVector.append((1-damp) + damp*total)
for i in range(length) :
total = sum([initVec[j]*trans[i][j] for j in range(length)])
#for j in range(length) :
# total += initVec[j]*trans[i][j]
nextVector[i] = (1-damp) + damp*total

if (initVec != nextVector and n<100) :
return PageRank(trans, nextVector, damp, n+1)
Expand Down

0 comments on commit 9e5c5f6

Please sign in to comment.