Tracking a State We Cannot Observe Directly
An alarm does not directly reveal whether equipment is healthy. Combine how states change with how each state could produce the observed alarm.
15 sections · 5 questions · 3 coding challenges
The arrow keys move between sections too.
Combining a State Model With a Measurement Model
BOTIE
We can use the same forward calculation to track the pump. First the transition model tells us how its condition might have changed. We then ask how likely the alarm is under each possible condition and update their probabilities. Our pump example uses supplied transition and alarm probabilities so we can follow each update by hand.
Sources for this history
Is the Pump Failing, or Is the Alarm Wrong?
Botie sees an alarm from a pump, but cannot directly see its internal condition. The pump can become faulty between inspections, and the alarm can occasionally be wrong.
There are two separate questions: what condition is plausible now, given the previous condition, and how plausible is this alarm under each current condition? Filtering answers them in that order.
The pump states and alarm probabilities belong to an invented two-state model.
Step 1 of 3
Predict the current condition
Rows are old states and columns are new states, ordered healthy then faulty.
| Possible state | Old belief | Predicted belief |
|---|---|---|
| Working | 0.8 | 0.76 |
| Faulty | 0.2 | 0.24 |
Working
- Old belief
- 0.8
- Predicted belief
- 0.76
Faulty
- Old belief
- 0.2
- Predicted belief
- 0.24
Step 2 of 3
Use the alarm
An alarm is more likely when faulty.
| Possible state | Alarm likelihood | Unnormalised weights |
|---|---|---|
| Working | 0.1 | 0.076 |
| Faulty | 0.9 | 0.216 |
Working
- Alarm likelihood
- 0.1
- Unnormalised weights
- 0.076
Faulty
- Alarm likelihood
- 0.9
- Unnormalised weights
- 0.216
Step 3 of 3
Normalise
The weights must become a probability distribution over current states.
Total weight = 0.076 + 0.216 = 0.292 Fault probability = 0.216 / 0.292 ≈ 0.740 Working probability = 0.076 / 0.292 ≈ 0.260
Predict the hidden state before incorporating the new reading
Prediction accounts for state changes; evidence then changes the relative support for those states.
Does today's alarm change what we believe about the pump?
First allow the pump's condition to change according to the transition model. Then compare an informative alarm with a reading equally likely in both states.
BOTIE
Updated probabilities of the hidden states
- 00.2603
- 10.7397
Follow the operations
1. Transition matrix
0.9 0.1 0.2 0.8 2. Check transition rows
0.9 0.1 0.2 0.8 3. Swap rows and columns
0.9 0.2 0.1 0.8 4. Previous state probabilities
- 00.8
- 10.2
5. Check a probability distribution
- 00.8
- 10.2
6. Matrix times vector
- 00.76
- 10.24
7. Reading likelihoods
- 00.1
- 10.9
8. Weight evidence by prior
- 00.076
- 10.216
9. Normalise non-negative weights
- 00.2603
- 10.7397
10. Result
- 00.2603
- 10.7397
This filters supplied models. It does not learn transitions or decode the most likely full path.
1. Keep Three Different Arrays
The belief vector gives probabilities over hidden states. The transition matrix describes how a state changes before the next observation. The emission likelihood gives the probability of the observation under each possible current state.
Use one fixed state order throughout. Transition rows must sum to one, but likelihoods for one observed alarm across different states do not need to sum to one.
A likelihood compares the same observation under different explanations. It is not yet a posterior.
2. Predict Before Looking at the New Alarm
With old states as rows and new states as columns, a row belief vector multiplies the transition matrix. This sums all ways to arrive at each new state.
Old belief = [0.8, 0.2]
Transition rows = [[0.9, 0.1], [0.2, 0.8]]
Predicted belief = [0.76, 0.24]Transposing the matrix without changing the vector convention silently changes the calculation.
3. Correct the Prediction With Evidence
Multiply each predicted state probability by that state’s alarm likelihood. Sum these weights to obtain the observation probability, then divide each weight by the sum.
The corrected belief becomes the starting point for the next step. Repeating prediction and correction lets evidence accumulate while still allowing the state to change.
Weights = [0.76 × 0.1, 0.24 × 0.9] = [0.076, 0.216]
Fault posterior = 0.216 / 0.292 ≈ 0.740A zero total weight means the model assigns no probability to what was observed; normalising cannot fix that.
Predict a state change before reading the alarm
Yesterday the pump was believed to be working with certainty. First allow a transition, then use a reading more likely under the faulty state.
import numpy as np
belief = np.array([1., 0.])
transition = np.array([[0.75, 0.25], [0.2, 0.8]])
reading_likelihood = np.array([0.2, 0.8])
predicted = belief @ transition
supported = predicted * reading_likelihood
print(predicted.tolist())
print(np.round(supported / supported.sum(), 3).tolist())[0.75, 0.25]
[0.429, 0.571]The transition creates some probability of a fault before the reading. The alarm then favours that state; normalising restores a probability distribution.
4. Distinguish Filtering From Explaining the Past
Filtering uses observations available up to the current time. Smoothing uses later observations to revise earlier state estimates. Viterbi decoding seeks a most likely whole state sequence, a different question again.
Our states and likelihoods are supplied. Learning them from data requires additional estimation and checks that the hidden states correspond to something useful.
The workshop performs a filtering step and never uses a future observation.
5. The State Vector Is a Belief, Not a Diagnosis
The pump's state vector stores probabilities for working and faulty. A transition matrix first moves that belief forward in time. Only then does the current alarm provide evidence about the current state.
Multiplying by alarm likelihoods changes the relative support for each state. Normalise after that multiplication so the entries again sum to one. The normalising sum is also the probability assigned to the observed alarm under the predictive belief.
6. Carry Belief through Two Reports
The first report is an alarm; the second is quiet. Both matter, but the second report should not erase the transition model or reset us to the initial belief.
Rows of the transition matrix describe the old state and columns the next state. With a row-vector belief, multiply on the right. Changing orientation silently computes a different operation.
Predict, observe and retain the result
The transition and alarm probabilities are supplied assumptions for this invented pump.
import numpy as np
belief = np.array([.9,.1])
transition = np.array([[.9,.1],[.2,.8]])
alarm = np.array([.1,.8])
for likelihood in [alarm, 1-alarm]:
predicted = belief@transition
weight = predicted*likelihood
belief = weight/weight.sum()
print(np.round(belief, 4).tolist())[0.379, 0.621]
[0.7966, 0.2034]The quiet report reduces fault probability, but the retained belief also reflects how faults persist and how often a quiet report can occur under a fault.
7. An Impossible Report Cannot Be Normalised
If every state assigns zero likelihood to a report, the normalising sum is zero. Dividing anyway does not produce a valid posterior. The observation contradicts the supplied model or an input convention is wrong.
Detect that case explicitly. With many small probabilities, numerical underflow can create a similar symptom, so stable scaling or log-space calculations become useful. Distinguish a numerical representation failure from a genuinely impossible observation.
Check yourself
Questions on Updating a Hidden-State Belief
Question 1 of 1
What should the filter do?
Use this setup.
The predictive belief is [0.7,0.3]. A report has likelihood [0,0] under the two modelled states.8. Later Evidence Answers a Different Historical Question
Filtering asks what we can infer now using reports available now. Smoothing revisits earlier hidden states after later reports have arrived. A later repair inspection can improve our account of yesterday's pump condition, but it was unavailable to yesterday's decision.
Keep that distinction when evaluating an online detector. Scoring a historical decision using a smoothed belief can give it information from the future and exaggerate how well it could have acted at the time.
Check yourself
Questions on Parts 1 to 8
Question 1 of 4
What is the corrected belief?
Use the information below.
Predicted probabilities [0.5,0.5], alarm likelihoods [0.2,0.8].Try it with Botie
Build with Botie
Write and run Python