Download Introduction to forward algorithm

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Ars Conjectandi wikipedia , lookup

Birthday problem wikipedia , lookup

Probability interpretations wikipedia , lookup

Probabilistic context-free grammar wikipedia , lookup

Transcript
The Forward Algorithm
Many paths give rise to the same sequence X
We would often like to know the total
probability of some sequence:
P(x) =
𝑃(π‘₯, πœ‹)
πœ‹
The problem is that the number of possible paths increases
exponentially with the length of the sequence
# of possible paths = (number of underlying states)L
Problems that grow exponentially with size can only be
solved by brute force for remarkably small problem sizes
We need a better way!!
The Forward Algorithm
Defining the forward variable
β€œThe forward variable for state k at position i”
fk(i) = P(x1…xi , pi = k)
β€œthe probability of the sequence from the beginning to the
symbol at position i, requiring that the path at position i is k”
How does this help?
The Forward Algorithm
What if we had in our possession all of the forward
variables for L, the last position of the sequence?
P(X) =
π’‡π’Œ(𝑳) π’‚π’Œ β†’ 𝒆𝒏𝒅
π’Œ
That would be pretty awesome, since to get the overall
probability of the sequence, we would need only sum the
forward variables for each state (after correcting for the
probability of the final transition to the end state)
Gee, that’s great. But I don’t yet have those β€œfinal position”
forward variables” in my possession, do I?
The Forward Algorithm
A recursive definition for forward variables
fk(i) = P(x1…xi , pi = k)
We can recursively define forward variables in terms of
their own values at prior positions in the sequence…
fl(i+1) = el(xi+1)
π’‡π’Œ(π’Š) π’‚π’Œ β†’ 𝒍
π’Œ
We’ll examine in more detail later but the termination
condition is satisfied by virtue of the fact that sequences are
finite and so we must eventually come to the beginning..
The Forward Algorithm
Putting it all together
Initialization:
β€’ fstart(0) = 1
β€’ fk(0) = 0 for all initial states k
Recursion (i = 1 … L):
fl(i) = el(xi)
Termination:
π’‡π’Œ(π’Š βˆ’ 𝟏) π’‚π’Œ β†’ 𝒍
π’Œ
P(X) =
π’‡π’Œ(𝑳) π’‚π’Œ β†’ 𝒆𝒏𝒅
π’Œ
How to express these equations in Python?
The Forward Algorithm
Reduction to Python code
The forward variables are conveniently kept in a table,
with indices that are state in one dimension and sequence
positions in another:
forward = [{}]
# a list of dicts
Here’s how one of the initialization conditions might be set:
forward[0]["S"] = log_float(1)
Later on you might have something like:
forward[position][new_state_l] = \
sum_over_states * emission_prob
Try and implement this, we’ll look carefully at how it works next time