All problems
State Space Local Level Step
Problem
Perform one step of a local level state space model. Given the current level and variance p, an observation, process noise q, and observation noise r: predict p_pred = p + q, compute K = p_pred / (p_pred + r), and return [level + K * (obs - level), (1 - K) * p_pred].
Return a gain of 0.0 when the denominator is zero.
Hint
Process noise raises the prior variance before the measurement update.
Test cases
case 1
in: [10,1,12,0.5,2]
expected: [10.857142857142858,0.8571428571428571]
case 2
in: [0,1,1,0,1]
expected: [0.5,0.5]
case 3
in: [5,0,5,1,3]
expected: [5,0.75]
case 4
in: [0,2,10,0,1]
expected: [6.666666666666666,0.6666666666666667]
Starter codePython
def state_space_local_level_step(level, p, obs, q, r):
# Your code here
pass4 test cases · run your code against them in the editor