theta_0 = np.array([[np.nan,1,1,np.nan],[np.nan,1,np.nan,1],[np.nan,np.nan,1,1],[1,1,1,np.nan],[np.nan,np.nan,1,1],[1,np.nan,np.nan,np.nan],[1,np.nan,np.nan,np.nan],[1,1,np.nan,np.nan]])defsimple_convert_into_pi_from_theta(theta):[m,n]= theta.shape
pi = np.zeros((m,n))for i inrange(0,m):
pi[i,:]=theta[i,:]/np.nansum(theta[i,:])
pi = np.nan_to_num(pi)return pi
from matplotlib import animation
from IPython.display import HTML
# IPython这是是大写definit():
line.set_data([],[])return(line,)defanimate(i):
state = state_history[i]
x =((state%3)+0.5)
y =2.5-int(state/3)
line.set_data(x,y)return(line,)
anim = animation.FuncAnimation(fig,animate,init_func = init,frames =len(state_history),interval =200,repeat =False)
HTML(anim.to_jshtml())