Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

first hitting time python

from numpy import *

hit_idx = (0,4)

# Define a graph by edge list
edges = [[0,1],[1,2],[2,3],[2,4]]

# Create adj. matrix
A = zeros((5,5))
A[zip(*edges)] = 1
# Undirected condition
A += A.T

# Make the final state an absorbing condition
A[hit_idx[1],:] = 0
A[hit_idx[1],hit_idx[1]] = 1

# Make a proper Markov matrix by row normalizing
A = (A.T/A.sum(axis=1)).T

B = A.copy()
Z = []
for n in xrange(100):
    Z.append( B[hit_idx] )
    B = dot(B,A)

from pylab import *
plot(Z)
xlabel("steps")
ylabel("hit probability")
show()    
Comment

PREVIOUS NEXT
Code Example
Python :: get number of occurrences of substring case independent python 
Python :: multiclass.roc plot title 
Python :: django create view filter options 
Python :: yamaha palhetas 
Python :: how to convert string labels to numpy array 
Python :: Mat.at(row,col) Opencv 
Python :: python: dunder init method 
Python :: crear ondas segun musica python 
Python :: linear algebra ipython notebook 
Python :: python how to get variable value in dict 
Python :: extract label from tf data 
Python :: how to press enter python keyboard 
Python :: left rotation in list 
Python :: discord.py get channel object from id 
Python :: program fibonacci series number in python 
Python :: duplicate characters in a string python 
Python :: set_flip_h( false ) 
Python :: updating to database 
Python :: pandas print nonzero in series 
Python :: pandas show all columns 
Python :: mechanize python XE #29 
Python :: take substring of every element in dataframe 
Python :: python sys replace text 
Python :: remove duplicate rows in pandas 
Python :: Find number of triangles that can be made by given sides of triangle 
Python :: python sorted vs sort 
Python :: allowed_hosts error ecs django 
Python :: modern ui python 
Python :: Grading program using if else 
Python :: NO OF CLASSES IN PAVIA UNIV DATASET 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =