# Particle filter and measurement equation

**URL:** <https://forum.dynare.org/t/particle-filter-and-measurement-equation/21025>\
**Category:** ML/Bayesian estimation\
**Created:** [5 September 2022 08:13 UTC](https://forum.dynare.org/t/particle-filter-and-measurement-equation/21025 "2022-09-05T08:13:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![burgerino](https://forum.dynare.org/letter_avatar_proxy/v4/letter/b/a587f6/32.png) [@burgerino](https://forum.dynare.org/u/burgerino)\
**Post date:** [5 September 2022 08:13 UTC](https://forum.dynare.org/t/particle-filter-and-measurement-equation/21025/1 "2022-09-05T08:13:20Z")

</div>

Hi, I would like to ask about what is the correct way to write the state space equation when using particle filter.

To illustrate better, suppose the non linear case, as used in the simulation with stochastic volatility by Born and Pfeifer in [https://github.com/JohannesPfeifer/Particle\_Filtering](https://github.com/JohannesPfeifer/Particle_Filtering)  
y\_t=\phi y\_{t-1}+\sigma\_t e\_t  
\log \sigma\_t=\log \sigma\_{t-1}+ u\_t  
where the first equation is a measurement and the second is the state transition equation.  
In my case, I have missing observation, so I expect filter and smoother to fill the gaps. For that reason, I put the level variable into another state transition equation, s.t.  
a\_t=\phi a\_{t-1}+\sigma\_t e\_t  
\log \sigma\_t=\log \sigma\_{t-1}+ u\_t  
and my measurement becomes y\_t=a\_t.

However, here I get lost. To my understanding, the particle filter requires measurement error, so that particles would not become degenerate. I was wondering how dynare handles this situation? [I am not sure, but can the answer be related to this [post]([Question about particle filter code](https://forum.dynare.org/t/question-about-particle-filter-code/2560))]

Does that mean I have to rewrite the specification differently? As an alternative, I was thinking to write in the following way:  
Measurement: y\_t=\phi a\_{t-1}+\sigma\_t v\_t.  
State equations  
a\_t=\phi a\_{t-1}+\sigma\_t e\_t  
\log \sigma\_t=\log \sigma\_{t-1}+ u\_t

But I guess this fails one of the assumptions, such that errors in state and measurement equations are independent?

I appreciate your help. Thanks

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [5 September 2022 09:04 UTC](https://forum.dynare.org/t/particle-filter-and-measurement-equation/21025/2 "2022-09-05T09:04:39Z")

</div>

@frederic.karame Do you know the answer?

---

<div class="post-metadata">

**Author:** ![frederic.karame](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/53a042/32.png) [@frederic.karame](https://forum.dynare.org/u/frederic.karame)\
**Post date:** [6 September 2022 18:02 UTC](https://forum.dynare.org/t/particle-filter-and-measurement-equation/21025/3 "2022-09-06T18:02:46Z")

</div>

If my understanding is correct, there is no need to rewrite the model. Think in the Kalman filter update equation:  
\alpha\_{t|t} = \alpha\_{t|t-1} + K\_t \eta\_t  
The last term updates the state prediction \alpha\_{t|t-1} to obtain the filtered state \alpha\_{t|t}.  
If no observation is available, there is no update so \alpha\_{t|t} = \alpha\_{t|t-1} in this case.  
This is the same for a particle filter with particle swarms.

---

<div class="post-metadata">

**Author:** ![burgerino](https://forum.dynare.org/letter_avatar_proxy/v4/letter/b/a587f6/32.png) [@burgerino](https://forum.dynare.org/u/burgerino)\
**Post date:** [6 September 2022 18:18 UTC](https://forum.dynare.org/t/particle-filter-and-measurement-equation/21025/4 "2022-09-06T18:18:36Z")

</div>

Thanks for the answer. Yes, that is how it would work with the missing data in Kalman filter. But where I am still confused is that the predictive density p(y|a) is degenerate as y\_t=a\_t, meaning that if one particle does not hit this point, weights will be equal to zero.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [7 September 2022 07:44 UTC](https://forum.dynare.org/t/particle-filter-and-measurement-equation/21025/5 "2022-09-07T07:44:38Z")

</div>

If I understand you correctly, you are observing one of the state variables.

---

<div class="post-metadata">

**Author:** ![burgerino](https://forum.dynare.org/letter_avatar_proxy/v4/letter/b/a587f6/32.png) [@burgerino](https://forum.dynare.org/u/burgerino)\
**Post date:** [7 September 2022 09:13 UTC](https://forum.dynare.org/t/particle-filter-and-measurement-equation/21025/6 "2022-09-07T09:13:06Z")

</div>

Exactly, I specify the model as if I observe some state variables. This is entirely to fill missing gaps using the law of motion of the state equation even though this leads to a much larger state vector.

Given that, Kalman filter can handle this easily but I am just unsure if particle filter can. Since the measurement does not have any measurement errors, particles that do not satisfy this constraint will have a density of zero, leading to degeneracy. I think engineering people face the same issue if their measurements, provided by some sensors, are too precise such that particles do not hit the peak of density. My case is even more extreme, such that the measurement is exact.

Again, I would like to thank a lot for looking into this.
