or goes to one of the other corners with probability each if it is in the middleit stays in the middle with probability otherwise it moves to one the cornerseach with probability probhmm py -(continued trans specifies the dynamics trans[iis the distribution over states resulting from state trans[ ][jgives ( = =ism= mmc= transition probabilities when in middle sc= mcm= mcc= transition probabilities when in corner trans {'middle':{'middle':sm' ':mmc' ':mmc' ':mmc}was in middle ' ':{'middle':mcm' ':sc' ':mcc' ':mcc}was in corner ' ':{'middle':mcm' ':mcc' ':sc' ':mcc}was in corner ' ':{'middle':mcm' ':mcc' ':mcc' ':sc}was in corner initially the animal is in one of the four stateswith equal probability probhmm py -(continued initially we have uniform distribution over the animal' state indist {st: /len(states for st in states hmm hmm(states obs pobs trans indist exact filtering for hmms hmmvefilter has current state distribution which can be updated by observing or by advancing to the next time probhmm py -(continued from display import displayable class hmmvefilter(displayable)def __init__(self,hmm)self hmm hmm self state_dist hmm indist def filter(selfobsseq)"""updates and returns the state distribution following the sequence of observations in obsseq using variable elimination note that it first advances time this is what is required if it is called sequentially if that is not what is wanted initiallydo an observe first ""for obs in obsseqversion june