Skip to content

Instantly share code, notes, and snippets.

@pcolazurdo
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcolazurdo/c71f1275341c495ada1f to your computer and use it in GitHub Desktop.
Save pcolazurdo/c71f1275341c495ada1f to your computer and use it in GitHub Desktop.
Topic - Based PageRank calculation for MMDS course
import numpy as np
# M = Web Graph
# v = initial probabilityes
# eS = Let eS be a vector that has 1 in the components in S and 0 in other components
# b = teleport set prob (based on (1-Beta)eS/|S|)
# Suppose that our topic is represented by the teleport set S = {B,D}. Then
# the vector (1 − β)eS/|S| has 1/10 for its second and fourth components and 0
# for the other two components. The reason is that 1 − β = 1/5, the size of S is
# 2, and eS has 1 in the components for B and D and 0 in the components for A
# and C.
#
beta = 0.7
M = np.dot([[0, 1, 0, 0] , [0.5, 0, 0, 0],[0.5, 0, 0, 1],[0, 0, 1, 0]], beta)
v = np.matrix(np.dot([1,1,1,1],1/4.)).T
eS = [2,1,0,0]
Sb = np.dot(np.dot(1-beta,eS), 1./np.linalg.norm(eS,1))
b = np.matrix(Sb).T
for a in range(1,10):
v= np.dot(M,v) + b
print v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment