# Expectation-Maximization for Kalman Filter with Continuous State Variables

**URL:** https://discourse.julialang.org/t/expectation-maximization-for-kalman-filter-with-continuous-state-variables/120983
**Category:** Optimization (Mathematical)
**Created:** [October 7, 2024, 12:07am UTC](https://discourse.julialang.org/t/expectation-maximization-for-kalman-filter-with-continuous-state-variables/120983 "2024-10-07T00:07:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![adannenberg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adannenberg/32/7869_2.png) [@adannenberg](https://discourse.julialang.org/u/adannenberg)
#### Post date: [October 7, 2024, 12:07am UTC](https://discourse.julialang.org/t/expectation-maximization-for-kalman-filter-with-continuous-state-variables/120983/1 "2024-10-07T00:07:18Z")

</div>

I would like to use a Kalman Filter + the EM algorithm to fit model parameters for a Hidden Markov Model with continuous hidden state variables, and then use the Kalman filter for prediction using the fitted parameters. I’ve implemented the KF and tried using Optim.optimize to do MLE inference of the parameters that generated synthetic data I created and it fails miserably so I’d like to try EM. It may be that my likelihood as a function of the parameters to be fit is too flat, i.e. that a change in 1 param can approximately (but not exactly) offset a change in another.

At any rate, does anyone have a concrete example of how to do this? Or is there, perhaps, a package that does both KF and EM?

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [October 7, 2024, 1:35am UTC](https://discourse.julialang.org/t/expectation-maximization-for-kalman-filter-with-continuous-state-variables/120983/2 "2024-10-07T01:35:07Z")

</div>

Here are a couple of examples

> **[Parameter estimation · LowLevelParticleFilters Documentation](https://baggepinnen.github.io/LowLevelParticleFilters.jl/dev/parameter_estimation/)**
>
> Documentation for LowLevelParticleFilters Documentation.

I don’t use EM in any of them, but I find that MLE works rather well in most cases.

> [@adannenberg](#):
>
> It may be that my likelihood as a function of the parameters to be fit is too flat, i.e. that a change in 1 param can approximately (but not exactly) offset a change in another.

Which optimizer were you trying? In cases like this, it might be beneficial to use second-order information, i.e., a Newton-type algorithm. If you’re minimizing prediction errors (equivalent to MLE unless you’re estimating noise properties as well), you can use a Gauss-Newton algorithm to get quadratic convergence near the optimum without computing the exact hessian. This is also demonstrated on the link above.

---

<div class="post-metadata">

### Author: ![adannenberg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adannenberg/32/7869_2.png) [@adannenberg](https://discourse.julialang.org/u/adannenberg)
#### Post date: [October 7, 2024, 3:56am UTC](https://discourse.julialang.org/t/expectation-maximization-for-kalman-filter-with-continuous-state-variables/120983/3 "2024-10-07T03:56:14Z")

</div>

Thank you. I will look.

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [October 8, 2024, 6:54am UTC](https://discourse.julialang.org/t/expectation-maximization-for-kalman-filter-with-continuous-state-variables/120983/4 "2024-10-08T06:54:33Z")

</div>

Did you manage to make any progress?
