for it=0 in range(iterations)
A:
[[ 0.1 0.8 0.1 0. ]
[ 0.1 0.1 0.6 0.2]
[ 0.4 0.3 0.2 0.1]
[ 0. 0. 0. 1. ]]
B:
[[ 0.8 0.1 0.1 0. ]
[ 0.1 0.8 0.1 0. ]
[ 0.1 0.8 0.1 0. ]
[ 0. 0. 1. 0. ]
[ 0. 0.2 0.8 0. ]
[ 1. 0. 0. 0. ]
[ 0. 0.1 0.9 0. ]
[ 0. 0. 0. 1. ]]
S:
4
pi:
[ 0.4 0.3 0.3 0. ]
for observations=[0, 1, 3, 5, 0, 6, 7, 7] in training
alpha, za = forward((pi, A, B), observations)
beta, zb = backward((pi, A, B), observations)
alpha:
[[ 0.32 0.03 0.03 0. ]
[ 0.0047 0.2144 0.0056 0. ]
[ 0. 0. 0.13023 0. ]
[ 0.052092 0. 0. 0. ]
[ 0.00416736 0.00416736 0.00052092 0. ]
[ 0. 0.00039069 0.0027192 0. ]
[ 0. 0. 0. 0.00035006]
[ 0. 0. 0. 0.00035006]]
beta:
[[ 0.00104026 0.00016397 0.00040858 0. ]
[ 0.0002688 0.0016128 0.0005376 0. ]
[ 0.000672 0.000672 0.002688 0. ]
[ 0.00672 0.004 0.01016 0. ]
[ 0.025 0.056 0.024 0. ]
[ 0. 0.2 0.1 1. ]
[ 0. 0.2 0.1 1. ]
[ 1. 1. 1. 1. ]]
za:
0.0003500582400000003
zb:
0.0003500582400000002
pi1 += alpha[0, :] * beta[0, :] / za
pi1:
[ 0.95093296 0.01405206 0.03501497 0. ]
for i in range(0, len(observations)):
B1[observations[0], :] += alpha[0, :] * beta[0, :] / za
B1[observations[1], :] += alpha[1, :] * beta[1, :] / za
B1[observations[2], :] += alpha[2, :] * beta[2, :] / za
B1[observations[3], :] += alpha[3, :] * beta[3, :] / za
B1[observations[4], :] += alpha[4, :] * beta[4, :] / za
B1[observations[5], :] += alpha[5, :] * beta[5, :] / za
B1[observations[6], :] += alpha[6, :] * beta[6, :] / za
B1[observations[7], :] += alpha[7, :] * beta[7, :] / za
B1:
[[ 1.24855201 0.68071873 0.07072926 0. ]
[ 0.003609 0.98779083 0.00860017 0. ]
[ 0. 0. 0. 0. ]
[ 0. 0. 1. 0. ]
[ 0. 0. 0. 0. ]
[ 1. 0. 0. 0. ]
[ 0. 0.22321429 0.77678571 0. ]
[ 0. 0. 0. 2. ]]
for i in range(1, len(observations)):
for s1 in range(S=4)
for s2 in range(S=4)
A1[0, 0] += alpha[0, 0] * A[0, 0] * B[observations[1], 0] * beta[1, 0] / za
A1[0, 1] += alpha[0, 0] * A[0, 1] * B[observations[1], 1] * beta[1, 1] / za
A1[0, 2] += alpha[0, 0] * A[0, 2] * B[observations[1], 2] * beta[1, 2] / za
A1[0, 3] += alpha[0, 0] * A[0, 3] * B[observations[1], 3] * beta[1, 3] / za
for s2 in range(S=4)
A1[1, 0] += alpha[0, 1] * A[1, 0] * B[observations[1], 0] * beta[1, 0] / za
A1[1, 1] += alpha[0, 1] * A[1, 1] * B[observations[1], 1] * beta[1, 1] / za
A1[1, 2] += alpha[0, 1] * A[1, 2] * B[observations[1], 2] * beta[1, 2] / za
A1[1, 3] += alpha[0, 1] * A[1, 3] * B[observations[1], 3] * beta[1, 3] / za
for s2 in range(S=4)
A1[2, 0] += alpha[0, 2] * A[2, 0] * B[observations[1], 0] * beta[1, 0] / za
A1[2, 1] += alpha[0, 2] * A[2, 1] * B[observations[1], 1] * beta[1, 1] / za
A1[2, 2] += alpha[0, 2] * A[2, 2] * B[observations[1], 2] * beta[1, 2] / za
A1[2, 3] += alpha[0, 2] * A[2, 3] * B[observations[1], 3] * beta[1, 3] / za
for s2 in range(S=4)
A1[3, 0] += alpha[0, 3] * A[3, 0] * B[observations[1], 0] * beta[1, 0] / za
A1[3, 1] += alpha[0, 3] * A[3, 1] * B[observations[1], 1] * beta[1, 1] / za
A1[3, 2] += alpha[0, 3] * A[3, 2] * B[observations[1], 2] * beta[1, 2] / za
A1[3, 3] += alpha[0, 3] * A[3, 3] * B[observations[1], 3] * beta[1, 3] / za
for s1 in range(S=4)
for s2 in range(S=4)
A1[0, 0] += alpha[1, 0] * A[0, 0] * B[observations[2], 0] * beta[2, 0] / za
A1[0, 1] += alpha[1, 0] * A[0, 1] * B[observations[2], 1] * beta[2, 1] / za
A1[0, 2] += alpha[1, 0] * A[0, 2] * B[observations[2], 2] * beta[2, 2] / za
A1[0, 3] += alpha[1, 0] * A[0, 3] * B[observations[2], 3] * beta[2, 3] / za
for s2 in range(S=4)
A1[1, 0] += alpha[1, 1] * A[1, 0] * B[observations[2], 0] * beta[2, 0] / za
A1[1, 1] += alpha[1, 1] * A[1, 1] * B[observations[2], 1] * beta[2, 1] / za
A1[1, 2] += alpha[1, 1] * A[1, 2] * B[observations[2], 2] * beta[2, 2] / za
A1[1, 3] += alpha[1, 1] * A[1, 3] * B[observations[2], 3] * beta[2, 3] / za
for s2 in range(S=4)
A1[2, 0] += alpha[1, 2] * A[2, 0] * B[observations[2], 0] * beta[2, 0] / za
A1[2, 1] += alpha[1, 2] * A[2, 1] * B[observations[2], 1] * beta[2, 1] / za
A1[2, 2] += alpha[1, 2] * A[2, 2] * B[observations[2], 2] * beta[2, 2] / za
A1[2, 3] += alpha[1, 2] * A[2, 3] * B[observations[2], 3] * beta[2, 3] / za
for s2 in range(S=4)
A1[3, 0] += alpha[1, 3] * A[3, 0] * B[observations[2], 0] * beta[2, 0] / za
A1[3, 1] += alpha[1, 3] * A[3, 1] * B[observations[2], 1] * beta[2, 1] / za
A1[3, 2] += alpha[1, 3] * A[3, 2] * B[observations[2], 2] * beta[2, 2] / za
A1[3, 3] += alpha[1, 3] * A[3, 3] * B[observations[2], 3] * beta[2, 3] / za
for s1 in range(S=4)
for s2 in range(S=4)
A1[0, 0] += alpha[2, 0] * A[0, 0] * B[observations[3], 0] * beta[3, 0] / za
A1[0, 1] += alpha[2, 0] * A[0, 1] * B[observations[3], 1] * beta[3, 1] / za
A1[0, 2] += alpha[2, 0] * A[0, 2] * B[observations[3], 2] * beta[3, 2] / za
A1[0, 3] += alpha[2, 0] * A[0, 3] * B[observations[3], 3] * beta[3, 3] / za
for s2 in range(S=4)
A1[1, 0] += alpha[2, 1] * A[1, 0] * B[observations[3], 0] * beta[3, 0] / za
A1[1, 1] += alpha[2, 1] * A[1, 1] * B[observations[3], 1] * beta[3, 1] / za
A1[1, 2] += alpha[2, 1] * A[1, 2] * B[observations[3], 2] * beta[3, 2] / za
A1[1, 3] += alpha[2, 1] * A[1, 3] * B[observations[3], 3] * beta[3, 3] / za
for s2 in range(S=4)
A1[2, 0] += alpha[2, 2] * A[2, 0] * B[observations[3], 0] * beta[3, 0] / za
A1[2, 1] += alpha[2, 2] * A[2, 1] * B[observations[3], 1] * beta[3, 1] / za
A1[2, 2] += alpha[2, 2] * A[2, 2] * B[observations[3], 2] * beta[3, 2] / za
A1[2, 3] += alpha[2, 2] * A[2, 3] * B[observations[3], 3] * beta[3, 3] / za
for s2 in range(S=4)
A1[3, 0] += alpha[2, 3] * A[3, 0] * B[observations[3], 0] * beta[3, 0] / za
A1[3, 1] += alpha[2, 3] * A[3, 1] * B[observations[3], 1] * beta[3, 1] / za
A1[3, 2] += alpha[2, 3] * A[3, 2] * B[observations[3], 2] * beta[3, 2] / za
A1[3, 3] += alpha[2, 3] * A[3, 3] * B[observations[3], 3] * beta[3, 3] / za
for s1 in range(S=4)
for s2 in range(S=4)
A1[0, 0] += alpha[3, 0] * A[0, 0] * B[observations[4], 0] * beta[4, 0] / za
A1[0, 1] += alpha[3, 0] * A[0, 1] * B[observations[4], 1] * beta[4, 1] / za
A1[0, 2] += alpha[3, 0] * A[0, 2] * B[observations[4], 2] * beta[4, 2] / za
A1[0, 3] += alpha[3, 0] * A[0, 3] * B[observations[4], 3] * beta[4, 3] / za
for s2 in range(S=4)
A1[1, 0] += alpha[3, 1] * A[1, 0] * B[observations[4], 0] * beta[4, 0] / za
A1[1, 1] += alpha[3, 1] * A[1, 1] * B[observations[4], 1] * beta[4, 1] / za
A1[1, 2] += alpha[3, 1] * A[1, 2] * B[observations[4], 2] * beta[4, 2] / za
A1[1, 3] += alpha[3, 1] * A[1, 3] * B[observations[4], 3] * beta[4, 3] / za
for s2 in range(S=4)
A1[2, 0] += alpha[3, 2] * A[2, 0] * B[observations[4], 0] * beta[4, 0] / za
A1[2, 1] += alpha[3, 2] * A[2, 1] * B[observations[4], 1] * beta[4, 1] / za
A1[2, 2] += alpha[3, 2] * A[2, 2] * B[observations[4], 2] * beta[4, 2] / za
A1[2, 3] += alpha[3, 2] * A[2, 3] * B[observations[4], 3] * beta[4, 3] / za
for s2 in range(S=4)
A1[3, 0] += alpha[3, 3] * A[3, 0] * B[observations[4], 0] * beta[4, 0] / za
A1[3, 1] += alpha[3, 3] * A[3, 1] * B[observations[4], 1] * beta[4, 1] / za
A1[3, 2] += alpha[3, 3] * A[3, 2] * B[observations[4], 2] * beta[4, 2] / za
A1[3, 3] += alpha[3, 3] * A[3, 3] * B[observations[4], 3] * beta[4, 3] / za
for s1 in range(S=4)
for s2 in range(S=4)
A1[0, 0] += alpha[4, 0] * A[0, 0] * B[observations[5], 0] * beta[5, 0] / za
A1[0, 1] += alpha[4, 0] * A[0, 1] * B[observations[5], 1] * beta[5, 1] / za
A1[0, 2] += alpha[4, 0] * A[0, 2] * B[observations[5], 2] * beta[5, 2] / za
A1[0, 3] += alpha[4, 0] * A[0, 3] * B[observations[5], 3] * beta[5, 3] / za
for s2 in range(S=4)
A1[1, 0] += alpha[4, 1] * A[1, 0] * B[observations[5], 0] * beta[5, 0] / za
A1[1, 1] += alpha[4, 1] * A[1, 1] * B[observations[5], 1] * beta[5, 1] / za
A1[1, 2] += alpha[4, 1] * A[1, 2] * B[observations[5], 2] * beta[5, 2] / za
A1[1, 3] += alpha[4, 1] * A[1, 3] * B[observations[5], 3] * beta[5, 3] / za
for s2 in range(S=4)
A1[2, 0] += alpha[4, 2] * A[2, 0] * B[observations[5], 0] * beta[5, 0] / za
A1[2, 1] += alpha[4, 2] * A[2, 1] * B[observations[5], 1] * beta[5, 1] / za
A1[2, 2] += alpha[4, 2] * A[2, 2] * B[observations[5], 2] * beta[5, 2] / za
A1[2, 3] += alpha[4, 2] * A[2, 3] * B[observations[5], 3] * beta[5, 3] / za
for s2 in range(S=4)
A1[3, 0] += alpha[4, 3] * A[3, 0] * B[observations[5], 0] * beta[5, 0] / za
A1[3, 1] += alpha[4, 3] * A[3, 1] * B[observations[5], 1] * beta[5, 1] / za
A1[3, 2] += alpha[4, 3] * A[3, 2] * B[observations[5], 2] * beta[5, 2] / za
A1[3, 3] += alpha[4, 3] * A[3, 3] * B[observations[5], 3] * beta[5, 3] / za
for s1 in range(S=4)
for s2 in range(S=4)
A1[0, 0] += alpha[5, 0] * A[0, 0] * B[observations[6], 0] * beta[6, 0] / za
A1[0, 1] += alpha[5, 0] * A[0, 1] * B[observations[6], 1] * beta[6, 1] / za
A1[0, 2] += alpha[5, 0] * A[0, 2] * B[observations[6], 2] * beta[6, 2] / za
A1[0, 3] += alpha[5, 0] * A[0, 3] * B[observations[6], 3] * beta[6, 3] / za
for s2 in range(S=4)
A1[1, 0] += alpha[5, 1] * A[1, 0] * B[observations[6], 0] * beta[6, 0] / za
A1[1, 1] += alpha[5, 1] * A[1, 1] * B[observations[6], 1] * beta[6, 1] / za
A1[1, 2] += alpha[5, 1] * A[1, 2] * B[observations[6], 2] * beta[6, 2] / za
A1[1, 3] += alpha[5, 1] * A[1, 3] * B[observations[6], 3] * beta[6, 3] / za
for s2 in range(S=4)
A1[2, 0] += alpha[5, 2] * A[2, 0] * B[observations[6], 0] * beta[6, 0] / za
A1[2, 1] += alpha[5, 2] * A[2, 1] * B[observations[6], 1] * beta[6, 1] / za
A1[2, 2] += alpha[5, 2] * A[2, 2] * B[observations[6], 2] * beta[6, 2] / za
A1[2, 3] += alpha[5, 2] * A[2, 3] * B[observations[6], 3] * beta[6, 3] / za
for s2 in range(S=4)
A1[3, 0] += alpha[5, 3] * A[3, 0] * B[observations[6], 0] * beta[6, 0] / za
A1[3, 1] += alpha[5, 3] * A[3, 1] * B[observations[6], 1] * beta[6, 1] / za
A1[3, 2] += alpha[5, 3] * A[3, 2] * B[observations[6], 2] * beta[6, 2] / za
A1[3, 3] += alpha[5, 3] * A[3, 3] * B[observations[6], 3] * beta[6, 3] / za
for s1 in range(S=4)
for s2 in range(S=4)
A1[0, 0] += alpha[6, 0] * A[0, 0] * B[observations[7], 0] * beta[7, 0] / za
A1[0, 1] += alpha[6, 0] * A[0, 1] * B[observations[7], 1] * beta[7, 1] / za
A1[0, 2] += alpha[6, 0] * A[0, 2] * B[observations[7], 2] * beta[7, 2] / za
A1[0, 3] += alpha[6, 0] * A[0, 3] * B[observations[7], 3] * beta[7, 3] / za
for s2 in range(S=4)
A1[1, 0] += alpha[6, 1] * A[1, 0] * B[observations[7], 0] * beta[7, 0] / za
A1[1, 1] += alpha[6, 1] * A[1, 1] * B[observations[7], 1] * beta[7, 1] / za
A1[1, 2] += alpha[6, 1] * A[1, 2] * B[observations[7], 2] * beta[7, 2] / za
A1[1, 3] += alpha[6, 1] * A[1, 3] * B[observations[7], 3] * beta[7, 3] / za
for s2 in range(S=4)
A1[2, 0] += alpha[6, 2] * A[2, 0] * B[observations[7], 0] * beta[7, 0] / za
A1[2, 1] += alpha[6, 2] * A[2, 1] * B[observations[7], 1] * beta[7, 1] / za
A1[2, 2] += alpha[6, 2] * A[2, 2] * B[observations[7], 2] * beta[7, 2] / za
A1[2, 3] += alpha[6, 2] * A[2, 3] * B[observations[7], 3] * beta[7, 3] / za
for s2 in range(S=4)
A1[3, 0] += alpha[6, 3] * A[3, 0] * B[observations[7], 0] * beta[7, 0] / za
A1[3, 1] += alpha[6, 3] * A[3, 1] * B[observations[7], 1] * beta[7, 1] / za
A1[3, 2] += alpha[6, 3] * A[3, 2] * B[observations[7], 2] * beta[7, 2] / za
A1[3, 3] += alpha[6, 3] * A[3, 3] * B[observations[7], 3] * beta[7, 3] / za
A1:
[[ 0.30007624 1.80070425 0.15138052 0. ]
[ 0.00023036 0.03486688 1.63341231 0.22321429]
[ 1.00092145 0.04210065 0.03630733 0.77678571]
[ 0. 0. 0. 1. ]]
for observations=[0, 2, 4, 5, 0, 6, 7, 7] in training
alpha, za = forward((pi, A, B), observations)
beta, zb = backward((pi, A, B), observations)
alpha:
[[ 0.32 0.03 0.03 0. ]
[ 0.0047 0.2144 0.0056 0. ]
[ 0. 0.005376 0.104184 0. ]
[ 0.0422112 0. 0. 0. ]
[ 0.0033769 0.0033769 0.00042211 0. ]
[ 0. 0.00031658 0.00220342 0. ]
[ 0. 0. 0. 0.00028366]
[ 0. 0. 0. 0.00028366]]
beta:
[[ 0.00084228 0.00013574 0.00033519 0. ]
[ 0.00032256 0.00130368 0.0004704 0. ]
[ 0.000672 0.000672 0.002688 0. ]
[ 0.00672 0.004 0.01016 0. ]
[ 0.025 0.056 0.024 0. ]
[ 0. 0.2 0.1 1. ]
[ 0. 0.2 0.1 1. ]
[ 1. 1. 1. 1. ]]
za:
0.0002836592640000002
zb:
0.00028365926400000015
pi1 += alpha[0, :] * beta[0, :] / za
pi1:
[ 1.90112628 0.02840844 0.07046528 0. ]
for i in range(0, len(observations)):
B1[observations[0], :] += alpha[0, :] * beta[0, :] / za
B1[observations[1], :] += alpha[1, :] * beta[1, :] / za
B1[observations[2], :] += alpha[2, :] * beta[2, :] / za
B1[observations[3], :] += alpha[3, :] * beta[3, :] / za
B1[observations[4], :] += alpha[4, :] * beta[4, :] / za
B1[observations[5], :] += alpha[5, :] * beta[5, :] / za
B1[observations[6], :] += alpha[6, :] * beta[6, :] / za
B1[observations[7], :] += alpha[7, :] * beta[7, :] / za
B1:
[[ 2.49636437 1.36174177 0.14189385 0. ]
[ 0.003609 0.98779083 0.00860017 0. ]
[ 0.00534455 0.98536881 0.00928663 0. ]
[ 0. 0. 1. 0. ]
[ 0. 0.01273596 0.98726404 0. ]
[ 2. 0. 0. 0. ]
[ 0. 0.44642857 1.55357143 0. ]
[ 0. 0. 0. 4. ]]
for i in range(1, len(observations)):
for s1 in range(S=4)
for s2 in range(S=4)
A1[0, 0] += alpha[0, 0] * A[0, 0] * B[observations[1], 0] * beta[1, 0] / za
A1[0, 1] += alpha[0, 0] * A[0, 1] * B[observations[1], 1] * beta[1, 1] / za
A1[0, 2] += alpha[0, 0] * A[0, 2] * B[observations[1], 2] * beta[1, 2] / za
A1[0, 3] += alpha[0, 0] * A[0, 3] * B[observations[1], 3] * beta[1, 3] / za
for s2 in range(S=4)
A1[1, 0] += alpha[0, 1] * A[1, 0] * B[observations[1], 0] * beta[1, 0] / za
A1[1, 1] += alpha[0, 1] * A[1, 1] * B[observations[1], 1] * beta[1, 1] / za
A1[1, 2] += alpha[0, 1] * A[1, 2] * B[observations[1], 2] * beta[1, 2] / za
A1[1, 3] += alpha[0, 1] * A[1, 3] * B[observations[1], 3] * beta[1, 3] / za
for s2 in range(S=4)
A1[2, 0] += alpha[0, 2] * A[2, 0] * B[observations[1], 0] * beta[1, 0] / za
A1[2, 1] += alpha[0, 2] * A[2, 1] * B[observations[1], 1] * beta[1, 1] / za
A1[2, 2] += alpha[0, 2] * A[2, 2] * B[observations[1], 2] * beta[1, 2] / za
A1[2, 3] += alpha[0, 2] * A[2, 3] * B[observations[1], 3] * beta[1, 3] / za
for s2 in range(S=4)
A1[3, 0] += alpha[0, 3] * A[3, 0] * B[observations[1], 0] * beta[1, 0] / za
A1[3, 1] += alpha[0, 3] * A[3, 1] * B[observations[1], 1] * beta[1, 1] / za
A1[3, 2] += alpha[0, 3] * A[3, 2] * B[observations[1], 2] * beta[1, 2] / za
A1[3, 3] += alpha[0, 3] * A[3, 3] * B[observations[1], 3] * beta[1, 3] / za
for s1 in range(S=4)
for s2 in range(S=4)
A1[0, 0] += alpha[1, 0] * A[0, 0] * B[observations[2], 0] * beta[2, 0] / za
A1[0, 1] += alpha[1, 0] * A[0, 1] * B[observations[2], 1] * beta[2, 1] / za
A1[0, 2] += alpha[1, 0] * A[0, 2] * B[observations[2], 2] * beta[2, 2] / za
A1[0, 3] += alpha[1, 0] * A[0, 3] * B[observations[2], 3] * beta[2, 3] / za
for s2 in range(S=4)
A1[1, 0] += alpha[1, 1] * A[1, 0] * B[observations[2], 0] * beta[2, 0] / za
A1[1, 1] += alpha[1, 1] * A[1, 1] * B[observations[2], 1] * beta[2, 1] / za
A1[1, 2] += alpha[1, 1] * A[1, 2] * B[observations[2], 2] * beta[2, 2] / za
A1[1, 3] += alpha[1, 1] * A[1, 3] * B[observations[2], 3] * beta[2, 3] / za
for s2 in range(S=4)
A1[2, 0] += alpha[1, 2] * A[2, 0] * B[observations[2], 0] * beta[2, 0] / za
A1[2, 1] += alpha[1, 2] * A[2, 1] * B[observations[2], 1] * beta[2, 1] / za
A1[2, 2] += alpha[1, 2] * A[2, 2] * B[observations[2], 2] * beta[2, 2] / za
A1[2, 3] += alpha[1, 2] * A[2, 3] * B[observations[2], 3] * beta[2, 3] / za
for s2 in range(S=4)
A1[3, 0] += alpha[1, 3] * A[3, 0] * B[observations[2], 0] * beta[2, 0] / za
A1[3, 1] += alpha[1, 3] * A[3, 1] * B[observations[2], 1] * beta[2, 1] / za
A1[3, 2] += alpha[1, 3] * A[3, 2] * B[observations[2], 2] * beta[2, 2] / za
A1[3, 3] += alpha[1, 3] * A[3, 3] * B[observations[2], 3] * beta[2, 3] / za
for s1 in range(S=4)
for s2 in range(S=4)
A1[0, 0] += alpha[2, 0] * A[0, 0] * B[observations[3], 0] * beta[3, 0] / za
A1[0, 1] += alpha[2, 0] * A[0, 1] * B[observations[3], 1] * beta[3, 1] / za
A1[0, 2] += alpha[2, 0] * A[0, 2] * B[observations[3], 2] * beta[3, 2] / za
A1[0, 3] += alpha[2, 0] * A[0, 3] * B[observations[3], 3] * beta[3, 3] / za
for s2 in range(S=4)
A1[1, 0] += alpha[2, 1] * A[1, 0] * B[observations[3], 0] * beta[3, 0] / za
A1[1, 1] += alpha[2, 1] * A[1, 1] * B[observations[3], 1] * beta[3, 1] / za
A1[1, 2] += alpha[2, 1] * A[1, 2] * B[observations[3], 2] * beta[3, 2] / za
A1[1, 3] += alpha[2, 1] * A[1, 3] * B[observations[3], 3] * beta[3, 3] / za
for s2 in range(S=4)
A1[2, 0] += alpha[2, 2] * A[2, 0] * B[observations[3], 0] * beta[3, 0] / za
A1[2, 1] += alpha[2, 2] * A[2, 1] * B[observations[3], 1] * beta[3, 1] / za
A1[2, 2] += alpha[2, 2] * A[2, 2] * B[observations[3], 2] * beta[3, 2] / za
A1[2, 3] += alpha[2, 2] * A[2, 3] * B[observations[3], 3] * beta[3, 3] / za
for s2 in range(S=4)
A1[3, 0] += alpha[2, 3] * A[3, 0] * B[observations[3], 0] * beta[3, 0] / za
A1[3, 1] += alpha[2, 3] * A[3, 1] * B[observations[3], 1] * beta[3, 1] / za
A1[3, 2] += alpha[2, 3] * A[3, 2] * B[observations[3], 2] * beta[3, 2] / za
A1[3, 3] += alpha[2, 3] * A[3, 3] * B[observations[3], 3] * beta[3, 3] / za
for s1 in range(S=4)
for s2 in range(S=4)
A1[0, 0] += alpha[3, 0] * A[0, 0] * B[observations[4], 0] * beta[4, 0] / za
A1[0, 1] += alpha[3, 0] * A[0, 1] * B[observations[4], 1] * beta[4, 1] / za
A1[0, 2] += alpha[3, 0] * A[0, 2] * B[observations[4], 2] * beta[4, 2] / za
A1[0, 3] += alpha[3, 0] * A[0, 3] * B[observations[4], 3] * beta[4, 3] / za
for s2 in range(S=4)
A1[1, 0] += alpha[3, 1] * A[1, 0] * B[observations[4], 0] * beta[4, 0] / za
A1[1, 1] += alpha[3, 1] * A[1, 1] * B[observations[4], 1] * beta[4, 1] / za
A1[1, 2] += alpha[3, 1] * A[1, 2] * B[observations[4], 2] * beta[4, 2] / za
A1[1, 3] += alpha[3, 1] * A[1, 3] * B[observations[4], 3] * beta[4, 3] / za
for s2 in range(S=4)
A1[2, 0] += alpha[3, 2] * A[2, 0] * B[observations[4], 0] * beta[4, 0] / za
A1[2, 1] += alpha[3, 2] * A[2, 1] * B[observations[4], 1] * beta[4, 1] / za
A1[2, 2] += alpha[3, 2] * A[2, 2] * B[observations[4], 2] * beta[4, 2] / za
A1[2, 3] += alpha[3, 2] * A[2, 3] * B[observations[4], 3] * beta[4, 3] / za
for s2 in range(S=4)
A1[3, 0] += alpha[3, 3] * A[3, 0] * B[observations[4], 0] * beta[4, 0] / za
A1[3, 1] += alpha[3, 3] * A[3, 1] * B[observations[4], 1] * beta[4, 1] / za
A1[3, 2] += alpha[3, 3] * A[3, 2] * B[observations[4], 2] * beta[4, 2] / za
A1[3, 3] += alpha[3, 3] * A[3, 3] * B[observations[4], 3] * beta[4, 3] / za
for s1 in range(S=4)
for s2 in range(S=4)
A1[0, 0] += alpha[4, 0] * A[0, 0] * B[observations[5], 0] * beta[5, 0] / za
A1[0, 1] += alpha[4, 0] * A[0, 1] * B[observations[5], 1] * beta[5, 1] / za
A1[0, 2] += alpha[4, 0] * A[0, 2] * B[observations[5], 2] * beta[5, 2] / za
A1[0, 3] += alpha[4, 0] * A[0, 3] * B[observations[5], 3] * beta[5, 3] / za
for s2 in range(S=4)
A1[1, 0] += alpha[4, 1] * A[1, 0] * B[observations[5], 0] * beta[5, 0] / za
A1[1, 1] += alpha[4, 1] * A[1, 1] * B[observations[5], 1] * beta[5, 1] / za
A1[1, 2] += alpha[4, 1] * A[1, 2] * B[observations[5], 2] * beta[5, 2] / za
A1[1, 3] += alpha[4, 1] * A[1, 3] * B[observations[5], 3] * beta[5, 3] / za
for s2 in range(S=4)
A1[2, 0] += alpha[4, 2] * A[2, 0] * B[observations[5], 0] * beta[5, 0] / za
A1[2, 1] += alpha[4, 2] * A[2, 1] * B[observations[5], 1] * beta[5, 1] / za
A1[2, 2] += alpha[4, 2] * A[2, 2] * B[observations[5], 2] * beta[5, 2] / za
A1[2, 3] += alpha[4, 2] * A[2, 3] * B[observations[5], 3] * beta[5, 3] / za
for s2 in range(S=4)
A1[3, 0] += alpha[4, 3] * A[3, 0] * B[observations[5], 0] * beta[5, 0] / za
A1[3, 1] += alpha[4, 3] * A[3, 1] * B[observations[5], 1] * beta[5, 1] / za
A1[3, 2] += alpha[4, 3] * A[3, 2] * B[observations[5], 2] * beta[5, 2] / za
A1[3, 3] += alpha[4, 3] * A[3, 3] * B[observations[5], 3] * beta[5, 3] / za
for s1 in range(S=4)
for s2 in range(S=4)
A1[0, 0] += alpha[5, 0] * A[0, 0] * B[observations[6], 0] * beta[6, 0] / za
A1[0, 1] += alpha[5, 0] * A[0, 1] * B[observations[6], 1] * beta[6, 1] / za
A1[0, 2] += alpha[5, 0] * A[0, 2] * B[observations[6], 2] * beta[6, 2] / za
A1[0, 3] += alpha[5, 0] * A[0, 3] * B[observations[6], 3] * beta[6, 3] / za
for s2 in range(S=4)
A1[1, 0] += alpha[5, 1] * A[1, 0] * B[observations[6], 0] * beta[6, 0] / za
A1[1, 1] += alpha[5, 1] * A[1, 1] * B[observations[6], 1] * beta[6, 1] / za
A1[1, 2] += alpha[5, 1] * A[1, 2] * B[observations[6], 2] * beta[6, 2] / za
A1[1, 3] += alpha[5, 1] * A[1, 3] * B[observations[6], 3] * beta[6, 3] / za
for s2 in range(S=4)
A1[2, 0] += alpha[5, 2] * A[2, 0] * B[observations[6], 0] * beta[6, 0] / za
A1[2, 1] += alpha[5, 2] * A[2, 1] * B[observations[6], 1] * beta[6, 1] / za
A1[2, 2] += alpha[5, 2] * A[2, 2] * B[observations[6], 2] * beta[6, 2] / za
A1[2, 3] += alpha[5, 2] * A[2, 3] * B[observations[6], 3] * beta[6, 3] / za
for s2 in range(S=4)
A1[3, 0] += alpha[5, 3] * A[3, 0] * B[observations[6], 0] * beta[6, 0] / za
A1[3, 1] += alpha[5, 3] * A[3, 1] * B[observations[6], 1] * beta[6, 1] / za
A1[3, 2] += alpha[5, 3] * A[3, 2] * B[observations[6], 2] * beta[6, 2] / za
A1[3, 3] += alpha[5, 3] * A[3, 3] * B[observations[6], 3] * beta[6, 3] / za
for s1 in range(S=4)
for s2 in range(S=4)
A1[0, 0] += alpha[6, 0] * A[0, 0] * B[observations[7], 0] * beta[7, 0] / za
A1[0, 1] += alpha[6, 0] * A[0, 1] * B[observations[7], 1] * beta[7, 1] / za
A1[0, 2] += alpha[6, 0] * A[0, 2] * B[observations[7], 2] * beta[7, 2] / za
A1[0, 3] += alpha[6, 0] * A[0, 3] * B[observations[7], 3] * beta[7, 3] / za
for s2 in range(S=4)
A1[1, 0] += alpha[6, 1] * A[1, 0] * B[observations[7], 0] * beta[7, 0] / za
A1[1, 1] += alpha[6, 1] * A[1, 1] * B[observations[7], 1] * beta[7, 1] / za
A1[1, 2] += alpha[6, 1] * A[1, 2] * B[observations[7], 2] * beta[7, 2] / za
A1[1, 3] += alpha[6, 1] * A[1, 3] * B[observations[7], 3] * beta[7, 3] / za
for s2 in range(S=4)
A1[2, 0] += alpha[6, 2] * A[2, 0] * B[observations[7], 0] * beta[7, 0] / za
A1[2, 1] += alpha[6, 2] * A[2, 1] * B[observations[7], 1] * beta[7, 1] / za
A1[2, 2] += alpha[6, 2] * A[2, 2] * B[observations[7], 2] * beta[7, 2] / za
A1[2, 3] += alpha[6, 2] * A[2, 3] * B[observations[7], 3] * beta[7, 3] / za
for s2 in range(S=4)
A1[3, 0] += alpha[6, 3] * A[3, 0] * B[observations[7], 0] * beta[7, 0] / za
A1[3, 1] += alpha[6, 3] * A[3, 1] * B[observations[7], 1] * beta[7, 1] / za
A1[3, 2] += alpha[6, 3] * A[3, 2] * B[observations[7], 2] * beta[7, 2] / za
A1[3, 3] += alpha[6, 3] * A[3, 3] * B[observations[7], 3] * beta[7, 3] / za
A1:
[[ 0.60133413 3.60087644 0.30310735 0. ]
[ 0.01330746 0.0798651 3.25446482 0.44642857]
[ 1.98955006 0.08491596 0.07257868 1.55357143]
[ 0. 0. 0. 2. ]]
D N V E
D 0.133472 0.799250 0.067278 0.000000
N 0.003507 0.021050 0.857778 0.117665
V 0.537627 0.022946 0.019613 0.419814
E 0.000000 0.000000 0.000000 1.000000
D N V E
the 0.624091 0.340435 0.035473 0.0
dog 0.003609 0.987791 0.008600 0.0
cat 0.005345 0.985369 0.009287 0.0
walked 0.000000 0.000000 1.000000 0.0
ran 0.000000 0.200000 0.800000 0.0
in 1.000000 0.000000 0.000000 0.0
park 0.000000 0.100000 0.900000 0.0
end 0.000000 0.000000 0.000000 1.0