Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split discrete and continuous Kalman filter implementations #645

Conversation

pnkraemer
Copy link
Collaborator

@pnkraemer pnkraemer commented Feb 16, 2022

In a Nutshell

Splits the current Kalman implementation into a discrete and a continuous part. The DiscreteKalman does Gaussian filtering and smoothing for discrete-discrete state-space models. The ContinuousKalman does the same for continuous-discrete state-space models. The goal of this PR is to make another step towards easier-to-maintain filtering and smoothing code.
(This PR also does some first mini-steps in simplifying the filter() implementation in the discrete object.)

Detailed Description

The filter() and smooth() functions in the Kalman filter currently carry around a lot of dead weights for discrete models. Most notably, a dt variable, which does not make sense. (Also, the t variable is pointless, but this can only be refactored as a part of a bigger effort; detailed in #627.)
Soon, when there are suitable priors/problem classes for discrete vs continuous state-space models (see also #646), and when approximate Kalman filters are refactored, the gains obtained through the separation introduced here will be even more evident.

Some further changes:

  • Iterated filtsmooth in Kalman was not used anymore, so I deleted it. (It is superseded by filtsmooth.gaussian.optim)
  • discrete-discrete iterated Kalman smoothing did not have a test case, which I added.

@codecov
Copy link

codecov bot commented Feb 16, 2022

Codecov Report

Merging #645 (2408077) into main (3e2e59b) will increase coverage by 0.13%.
The diff coverage is 100.00%.

❗ Current head 2408077 differs from pull request most recent head c64d6a6. Consider uploading reports for the commit c64d6a6 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #645      +/-   ##
==========================================
+ Coverage   90.12%   90.26%   +0.13%     
==========================================
  Files         194      194              
  Lines        7353     7343      -10     
  Branches     1163     1160       -3     
==========================================
+ Hits         6627     6628       +1     
+ Misses        486      470      -16     
- Partials      240      245       +5     
Impacted Files Coverage Δ
.../odefilter/init_routines/_non_probabilistic_fit.py 100.00% <100.00%> (ø)
src/probnum/filtsmooth/_kalman_filter_smoother.py 100.00% <100.00%> (ø)
src/probnum/filtsmooth/gaussian/__init__.py 100.00% <100.00%> (ø)
src/probnum/filtsmooth/gaussian/_kalman.py 96.72% <100.00%> (+28.46%) ⬆️
src/probnum/quad/solvers/bayesian_quadrature.py 86.04% <0.00%> (-7.29%) ⬇️
src/probnum/quad/_bayesquad.py 94.44% <0.00%> (-5.56%) ⬇️
...bnum/quad/solvers/belief_updates/_belief_update.py 96.96% <0.00%> (-0.09%) ⬇️
src/probnum/typing.py 100.00% <0.00%> (ø)
src/probnum/quad/__init__.py 100.00% <0.00%> (ø)
... and 17 more

@pnkraemer pnkraemer changed the title Split discrete and continuous kalman Split discrete and continuous Kalman filter implementations Feb 16, 2022
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

regression_problem: problems.TimeSeriesRegressionProblem,
_previous_posterior: Optional[_timeseriesposterior.TimeSeriesPosterior] = None,
):
def filter(self, *args, **kwargs):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wrapper around the state generator works with args and kwargs for the following reason:

Soon, the regression problems might change types (discrete vs continuous), and the filter() and iterated_filtsmooth_generator() signature adapts accordingly. But this function here (and the filtsmooth() style methods below) remains the same. args and kwargs lead to a smaller, more meaningful diff in the future.

@pnkraemer pnkraemer marked this pull request as ready for review February 16, 2022 11:51
@pnkraemer pnkraemer requested review from schmidtjonathan and a team as code owners February 16, 2022 11:51
@pnkraemer pnkraemer removed the request for review from a team February 16, 2022 11:51
@pnkraemer pnkraemer removed the request for review from schmidtjonathan April 19, 2022 10:02
@pnkraemer pnkraemer closed this Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant