This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#the following code takes a list such as | |
#[1,1,2,6,8,5,5,7,8,8,1,1,4,5,5,0,0,0,1,1,4,4,5,1,3,3,4,5,4,1,1] | |
#with states labeled as successive integers starting with 0 | |
#and returns a transition matrix, M, | |
#where M[i][j] is the probability of transitioning from i to j | |
def transition_matrix(transitions): | |
n = 1+ max(transitions) #number of states | |
M = [[0]*n for _ in range(n)] |