Esempio n. 1
0
n = 5
h = 1.0/n


K = (1 + h*A)
K.setSym("K") 
Y = [Y0]*(n+1)
for i in xrange(n+1):
    if i==0:
        pass
    else:
        Y[i] = Y[i-1] * K
        Y[i].setSym("Y" + str(i))  
P = NDProductDistr([Factor1DDistr(A), Factor1DDistr(Y[0])])
M = Model(P, Y[1:])
M.eliminate_other([K] + Y)

#M2 = M.inference2([Y[0], A], [Y[n]], [1])
#M2.plot(); print M2; show()
#M2 = M.inference2([Y[0]], [Y[n]], [0.5])
#figure()
#M2.plot(); print M2; 
figure()
Y[-1].plot(color='r',linewidth=5)
M3 = M.inference([Y[-1]], [], [])

M3.plot(); print M3; 

X0 = BetaDistr(2, 2)
y = X0 * exp(A) 
y.summary()
Esempio n. 2
0
        Y.append(Y0 * K+ h*U[i])
    else:
        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))
Esempio n. 3
0
        Y.append(Y0 * K + h * U[i])
    else:
        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)
Esempio n. 4
0
Y0 = BetaDistr(2, 2, sym="Y0")
n = 5
h = 1.0 / n

K = (1 + h * A)
K.setSym("K")
Y = [Y0] * (n + 1)
for i in xrange(n + 1):
    if i == 0:
        pass
    else:
        Y[i] = Y[i - 1] * K
        Y[i].setSym("Y" + str(i))
P = NDProductDistr([Factor1DDistr(A), Factor1DDistr(Y[0])])
M = Model(P, Y[1:])
M.eliminate_other([K] + Y)

#M2 = M.inference2([Y[0], A], [Y[n]], [1])
#M2.plot(); print M2; show()
#M2 = M.inference2([Y[0]], [Y[n]], [0.5])
#figure()
#M2.plot(); print M2;
figure()
Y[-1].plot(color='r', linewidth=5)
M3 = M.inference([Y[-1]], [], [])

M3.plot()
print M3

X0 = BetaDistr(2, 2)
y = X0 * exp(A)
Esempio n. 5
0
for i in range(n):
    print(i)
    if i==0:
        X[i] = BetaDistr(3, 3, sym = "X0")
        Y[i] = BetaDistr(3, 3, sym = "Y0")
    else:
        X[i] = X[i-1] + h*(A*X[i-1] - B*Y[i-1])
        Y[i] = Y[i-1] + h*(-C*X[i-1] + D*Y[i-1])
        
        X[i].setSym("X{}".format(i))
        Y[i].setSym("Y{}".format(i))



M = Model([X[0], Y[0], A, B, C, D], X[1:] + Y[1:] )
print(M)
M.eliminate_other([X[0], Y[0], A, B, C, D] + X[1:] + Y[1:])
print(M)
print(Y[1].range())

#M1 = M.inference([X[2], Y[2]], [X[0], Y[0]], [0.5, 0.2])\
figure()
    
for i in range(n):
    M1 = M.inference([X[i], Y[i]], [A, B, C, D], [0.9, 0.2, 0.3, 0.6])
    print(M1)
    M1.plot(cont_levels=1)
    #figure()
    #M1.plot(have_3d=True)
show()
Esempio n. 6
0
h=0.1
for i in range(n):
    print i
    if i==0:
        X[i] = BetaDistr(3, 3, sym = "X0")
        Y[i] = BetaDistr(3, 3, sym = "Y0")
    else:
        X[i] = X[i-1] + h*(A*X[i-1] - B*Y[i-1])
        Y[i] = Y[i-1] + h*(-C*X[i-1] + D*Y[i-1])
        
        X[i].setSym("X{}".format(i))
        Y[i].setSym("Y{}".format(i))



M = Model([X[0], Y[0], A, B, C, D], X[1:] + Y[1:] )
print M
M.eliminate_other([X[0], Y[0], A, B, C, D] + X[1:] + Y[1:])
print M
print Y[1].range()

#M1 = M.inference([X[2], Y[2]], [X[0], Y[0]], [0.5, 0.2])\
figure()
    
for i in range(n):
    M1 = M.inference([X[i], Y[i]], [A, B, C, D], [0.9, 0.2, 0.3, 0.6])
    print M1
    M1.plot(cont_levels=1)
    #figure()
    #M1.plot(have_3d=True)
show()