Skip to content

Commit

Permalink
siodfuishdf
Browse files Browse the repository at this point in the history
  • Loading branch information
dghauri0 committed Jan 9, 2024
1 parent 3a15957 commit 6ec652a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
18 changes: 10 additions & 8 deletions HW5/part1_slow_forward.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import math

A = [[0.66, 0.34],
[1, 0]]
B = [[0.5, 0.25, 0.25],
[0.1, 0.1, 0.8]]
pi = [0.8, 0.2]
# From lecture as check
A_ex = [[0.5, 0.5],
[0, 1]]
B_ex = [[0.5, 0.0, 0.5],
[0, 1, 0]]
pi_ex = [1, 0]
O_ex = [0, 2, 1]

def slow_forward(A, B, pi, O):
L = 0
for state in range(len(O)):
''

for state in range(len(pi)):
for time in range(len(O)):
14 changes: 14 additions & 0 deletions HW5/partec1_forward_renormalization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import math

def forward_algorithm_renorm(A, B, pi, O):
forward_variable_array = [[0] * len(O) for i in range(len(pi))]
for time in range(len(O)):
for state in range(len(pi)):
if time == 0:
forward_variable_array[state][time] = pi[state] * B[state][O[time]]
else:
for i in range(len(pi)):
forward_variable_array[state][time] += forward_variable_array[i][time - 1] * A[i][state] * B[state][
O[time]]

return forward_variable_array

0 comments on commit 6ec652a

Please sign in to comment.