# Help Needed: Kalman Filter with PyMC and pytensor.tensor.KalmanFilter Error

**URL:** <https://discourse.pymc.io/t/help-needed-kalman-filter-with-pymc-and-pytensor-tensor-kalmanfilter-error/14640>\
**Category:** v5\
**Created:** [June 20, 2024, 5:16pm UTC](https://discourse.pymc.io/t/help-needed-kalman-filter-with-pymc-and-pytensor-tensor-kalmanfilter-error/14640 "2024-06-20T17:16:45Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)\
**Post date:** [June 20, 2024, 5:46pm UTC](https://discourse.pymc.io/t/help-needed-kalman-filter-with-pymc-and-pytensor-tensor-kalmanfilter-error/14640/2 "2024-06-20T17:46:59Z")

</div>

Hi Dimitri,

There are Kalman Filters implemented in pymc-experimental, you can take a look at the docs [here](https://www.pymc.io/projects/experimental/en/latest/statespace/generated/pymc_experimental.statespace.filters.StandardFilter.html#pymc_experimental.statespace.filters.StandardFilter). If you just want to fit a TP-VAR, you can do it with the VARMAX model. Docs [here](https://www.pymc.io/projects/experimental/en/latest/statespace/generated/pymc_experimental.statespace.models.BayesianVARMAX.html#pymc_experimental.statespace.models.BayesianVARMAX), example notebook [here](https://github.com/pymc-devs/pymc-experimental/blob/main/notebooks/VARMAX%20Example.ipynb). Just a heads up that there are some known bugs in the main branch I’m working on squashing, but if you’re willing to be a bit of a guinea pig I’d be happy to try to help.

That said, there are many ways to write down a VAR in PyMC. The TP part will just come from putting time-varying priors on the coefficient matrix, e.g. using a GaussianRandomWalk (or MvGaussianRandomWalk). After you do this it would be trivial to implement without having to go through the hassle of using a full statespace setup. For example, you can implement it has a [2d convolution](https://github.com/jessegrabowski/VAR-Blog/blob/main/Big%20VAR%20Blog%20Post.ipynb), or as a [simple regression over lagged data](https://www.pymc.io/projects/examples/en/latest/time_series/bayesian_var_model.html).

It’s not really clear to me what your objective is with the Kalman Filter code you posted. Do you have missing data you want to interpolate, or is that just an algorithm you’re familiar with for fitting these kinds of models? In principal you don’t need it; PyMC can derive the log likelihood of a sequence of observations without using the KF recursions.

---

_[View the full topic](https://discourse.pymc.io/t/help-needed-kalman-filter-with-pymc-and-pytensor-tensor-kalmanfilter-error/14640)._
