#show() #A = UniformDistr(0,1, sym = "A") #B = UniformDistr(0,1, sym = "B") for i in range(n): print "X{}".format(i) X[i] = BetaDistr(2, 2, sym = "X{}".format(i)) if i==0: S[i] = X[0] else: S[i] = S[i-1] + X[i] S[i].setSym("S{}".format(i)) M = Model(X, S[1:]) print M M.toGraphwiz() #M = M.inference([S[-1], S[-4]], [S[-3]], [1]) #M = M.inference([X[0], X[1]], [S[-1]], [3.5]) print "====================" M1 = M.inference(wanted_rvs =[X[0], X[1]], cond_rvs=[S[-1]], cond_X=[1]) print "====================",M1 M2 = M.inference(wanted_rvs =[S[1], S[4]]) print "====================",M2 M3 = M.inference(wanted_rvs =[S[1], S[4]], cond_rvs=[S[3]], cond_X=[2]) print "====================",M3 MC_X0 = M.inference(wanted_rvs =[X[0]], cond_rvs=[S[-1]], cond_X=[1]) print "====================" print M1 figure() M1.plot(cont_levels=10)
Y.append(Y[i-1] * K+ h*U[i]) Y[-1].setSym("Y" + str(i+1)) ei = NormalDistr(0.0, 0.1) | Between(-0.4, 0.4) ei.setSym("E{0}".format(i)) E.append(ei) O.append(Y[-1] + E[-1]) O[-1].setSym("O{0}".format(i)) #! #! Model #! ----- P = NDProductDistr([A, Y0] + E + U) M = Model(P, O) print M M.eliminate_other(E + Y + O + [A, Y0] + U) print M M.toGraphwiz(f=open('bn.dot', mode="w+")) #! #! Joint distribution of initial condition and parameter of equation #! ----------------------------------------------------------------- i = 0 ay0 = [] ui = [0.0]*n figure() for yend in [0.25, 1.25, 2.25]: M2 = M.inference(wanted_rvs=[A, Y0], cond_rvs=[O[-1]] + U, cond_X=[yend] + ui) subplot(1, 3, i + 1) title("O_{0}={1}".format(n, yend)) M2.plot() ay0.append(M2.nddistr.mode()) # "most probable" state
#show() #A = UniformDistr(0,1, sym = "A") #B = UniformDistr(0,1, sym = "B") for i in range(n): print("X{}".format(i)) X[i] = BetaDistr(2, 2, sym = "X{}".format(i)) if i==0: S[i] = X[0] else: S[i] = S[i-1] + X[i] S[i].setSym("S{}".format(i)) M = Model(X, S[1:]) print(M) M.toGraphwiz() #M = M.inference([S[-1], S[-4]], [S[-3]], [1]) #M = M.inference([X[0], X[1]], [S[-1]], [3.5]) print("====================") M1 = M.inference(wanted_rvs =[X[0], X[1]], cond_rvs=[S[-1]], cond_X=[1]) print("====================",M1) M2 = M.inference(wanted_rvs =[S[1], S[4]]) print("====================",M2) M3 = M.inference(wanted_rvs =[S[1], S[4]], cond_rvs=[S[3]], cond_X=[2]) print("====================",M3) MC_X0 = M.inference(wanted_rvs =[X[0]], cond_rvs=[S[-1]], cond_X=[1]) print("====================") print(M1) figure() M1.plot(cont_levels=10)
Y.append(Y[i - 1] * K + h * U[i]) Y[-1].setSym("Y" + str(i + 1)) ei = NormalDistr(0.0, 0.1) | Between(-0.4, 0.4) ei.setSym("E{0}".format(i)) E.append(ei) O.append(Y[-1] + E[-1]) O[-1].setSym("O{0}".format(i)) #! #! Model #! ----- P = NDProductDistr([A, Y0] + E + U) M = Model(P, O) print M M.eliminate_other(E + Y + O + [A, Y0] + U) print M M.toGraphwiz(f=open('bn.dot', mode="w+")) #! #! Joint distribution of initial condition and parameter of equation #! ----------------------------------------------------------------- i = 0 ay0 = [] ui = [0.0] * n figure() for yend in [0.25, 1.25, 2.25]: M2 = M.inference(wanted_rvs=[A, Y0], cond_rvs=[O[-1]] + U, cond_X=[yend] + ui) subplot(1, 3, i + 1) title("O_{0}={1}".format(n, yend))
for i in range(n): U.append(UniformDistr(-0.2, 0.2, sym="U{0}".format(i))) if i == 0: Y.append(Y0 * K + U[i]) else: Y.append(Y[i - 1] * K + U[i]) Y[i].setSym("Y" + str(i + 1)) ei = NormalDistr(0.05, 0.1) | Between(-0.4, 0.4) ei.setSym("E{0}".format(i)) E.append(ei) O.append(Y[-1] + E[-1]) O[-1].setSym("O{0}".format(i)) # print O[-1].range(), O[-1].range_() M = Model(U + [Y0] + E, Y + O) print(M) M.toGraphwiz(f=open("bn.dot", mode="w+")) #! #! Simulation with signal filtering #! -------------------------------- nT = 100 u = zeros(nT) t = zeros(nT) Yorg = zeros(nT) Ynoised = zeros(nT) Ydenoised = zeros(nT) Udenoised = zeros(nT) yi = 0.0 ydenoise = 0.0 ynoise = 0.0 y = 0.0 figure()