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

Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions benchmarks/filtsmooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def setup(self, linearization_implementation):
)
self.regression_problem = regression_problem

self.kalman_filter = filtsmooth.gaussian.Kalman(prior_process=prior_process)
self.kalman_filter = filtsmooth.gaussian.DiscreteKalman(
prior_process=prior_process
)

def time_filter(self, linearization_implementation):
self.kalman_filter.filter(self.regression_problem)
Expand Down Expand Up @@ -99,7 +101,9 @@ def setup(self, linearization_implementation):
initarg=regression_problem.locations[0],
)

self.kalman_filter = filtsmooth.gaussian.Kalman(prior_process=prior_process)
self.kalman_filter = filtsmooth.gaussian.DiscreteKalman(
prior_process=prior_process
)
self.filtering_posterior, _ = self.kalman_filter.filter(regression_problem)

def time_smooth(self, linearization_implementation):
Expand Down Expand Up @@ -166,7 +170,9 @@ def setup(self, linearization_implementation, num_samples):
initarg=regression_problem.locations[0],
)

self.kalman_filter = filtsmooth.gaussian.Kalman(prior_process=prior_process)
self.kalman_filter = filtsmooth.gaussian.DiscreteKalman(
prior_process=prior_process
)

self.filtering_posterior, _ = self.kalman_filter.filter(regression_problem)
self.smoothing_posterior = self.kalman_filter.smooth(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
"metadata": {},
"outputs": [],
"source": [
"kalman_filter = filtsmooth.gaussian.Kalman(prior_process)"
"kalman_filter = filtsmooth.gaussian.ContinuousKalman(prior_process)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
"prior_process = randprocs.markov.MarkovProcess(\n",
" transition=linearised_dynamics_model, initrv=initial_state_rv, initarg=0.0\n",
")\n",
"kalman_filter = filtsmooth.gaussian.Kalman(prior_process)"
"kalman_filter = filtsmooth.gaussian.ContinuousKalman(prior_process)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
"metadata": {},
"outputs": [],
"source": [
"kalman_filter = filtsmooth.gaussian.Kalman(prior_process)"
"kalman_filter = filtsmooth.gaussian.DiscreteKalman(prior_process)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
"metadata": {},
"outputs": [],
"source": [
"kalman_filter = filtsmooth.gaussian.Kalman(prior_process)"
"kalman_filter = filtsmooth.gaussian.DiscreteKalman(prior_process)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _improve(self, *, data, prior_process):
)

# Infer the solution
kalman = filtsmooth.gaussian.Kalman(prior_process)
kalman = filtsmooth.gaussian.ContinuousKalman(prior_process)
out, _ = kalman.filtsmooth(regression_problem)
estimated_initrv = out.states[0]
return estimated_initrv
Expand Down
9 changes: 7 additions & 2 deletions src/probnum/filtsmooth/_kalman_filter_smoother.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

__all__ = ["filter_kalman", "smooth_rts"]

MATCH_FILTER = {
"continuous": gaussian.ContinuousKalman,
"discrete": gaussian.DiscreteKalman,
}


def filter_kalman(
observations: ArrayLike,
Expand Down Expand Up @@ -100,7 +105,7 @@ def filter_kalman(
prior_process = _setup_prior_process(
F=F, L=L, m0=m0, C0=C0, t0=locations[0], prior_model=prior_model
)
kalman = gaussian.Kalman(prior_process)
kalman = MATCH_FILTER[prior_model](prior_process)
return kalman.filter(regression_problem)[0]


Expand Down Expand Up @@ -195,7 +200,7 @@ def smooth_rts(
prior_process = _setup_prior_process(
F=F, L=L, m0=m0, C0=C0, t0=locations[0], prior_model=prior_model
)
kalman = gaussian.Kalman(prior_process)
kalman = MATCH_FILTER[prior_model](prior_process)
return kalman.filtsmooth(regression_problem)[0]


Expand Down
8 changes: 5 additions & 3 deletions src/probnum/filtsmooth/gaussian/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
"""Gaussian filtering and smoothing."""

from ._kalman import Kalman
from ._kalman import ContinuousKalman, DiscreteKalman
from ._kalmanposterior import FilteringPosterior, KalmanPosterior, SmoothingPosterior

# Public classes and functions. Order is reflected in documentation.
__all__ = [
"Kalman",
"DiscreteKalman",
"ContinuousKalman",
"KalmanPosterior",
"FilteringPosterior",
"SmoothingPosterior",
]

# Set correct module paths (for superclasses).
# Corrects links and module paths in documentation.
Kalman.__module__ = "probnum.filtsmooth.gaussian"
DiscreteKalman.__module__ = "probnum.filtsmooth.gaussian"
ContinuousKalman.__module__ = "probnum.filtsmooth.gaussian"
KalmanPosterior.__module__ = "probnum.filtsmooth.gaussian"
FilteringPosterior.__module__ = "probnum.filtsmooth.gaussian"
SmoothingPosterior.__module__ = "probnum.filtsmooth.gaussian"
Loading