This code completes the discussion starting on p.6 of these notes:
from IPython.display import Image
Image('w4.png')
mweb={1:[2,3],2:[3],3:[1],4:[3]}
T= array([[1./len(mweb[i]) if m in mweb[i] else 0. for m in mweb] for i in mweb])
T
array([[ 0. , 0.5, 0.5, 0. ], [ 0. , 0. , 1. , 0. ], [ 1. , 0. , 0. , 0. ], [ 0. , 0. , 1. , 0. ]])
around(reduce(dot,[T]*25),3)
array([[ 0.4, 0.2, 0.4, 0. ], [ 0.4, 0.2, 0.4, 0. ], [ 0.4, 0.2, 0.4, 0. ], [ 0.4, 0.2, 0.4, 0. ]])
Now add the "teleportation" term, with p=.2:
p=.2
n=len(T)
Tp=p*ones([n,n])/n + (1-p)*T
Tp
array([[ 0.05, 0.45, 0.45, 0.05], [ 0.05, 0.05, 0.85, 0.05], [ 0.85, 0.05, 0.05, 0.05], [ 0.05, 0.05, 0.85, 0.05]])
Converges reasonably well after just 8 iterations:
linalg.matrix_power(Tp,8)
array([[ 0.3698848 , 0.19271104, 0.38740416, 0.05 ], [ 0.35939904, 0.2031968 , 0.38740416, 0.05 ], [ 0.35939904, 0.19271104, 0.39788992, 0.05 ], [ 0.35939904, 0.2031968 , 0.38740416, 0.05 ]])
The result starting from the equiprobability state $(1/4,1/4,1/4,1/4)$:
(1/4.)*ones(4).dot(linalg.matrix_power(Tp,8))
array([ 0.36202048, 0.19795392, 0.3900256 , 0.05 ])