Kalman

class probnum.filtsmooth.Kalman(dynamic_model, measurement_model, initrv)[source]

Bases: probnum.filtsmooth.bayesfiltsmooth.BayesFiltSmooth

Gaussian filtering and smoothing, i.e. Kalman-like filters and smoothers.

Attributes Summary

dynamicmodel

Convenience function for accessing self.dynamod.

initialdistribution

Convenience function for accessing self.initdist.

initialrandomvariable

Convenience function for accessing self.initrv.

measurementmodel

Convenience function for accessing self.measmod.

Methods Summary

condition_state_on_measurement(randvar, …)

Condition the state on the observed data.

filter(dataset, times, **kwargs)

Apply Gaussian filtering (no smoothing!) to a data set.

filter_step(start, stop, current_rv, data, …)

A single filter step.

filtsmooth(dataset, times, **kwargs)

Apply Gaussian filtering and smoothing to a data set.

measure(time, randvar, **kwargs)

Propagate the state through the measurement model.

predict(start, stop, randvar, **kwargs)

Prediction step of the Bayesian filter.

smooth(filter_posterior, **kwargs)

Apply Gaussian smoothing to the filtering outcome (i.e.

smooth_list(rv_list, locations, **kwargs)

Apply smoothing to a list of RVs with desired final random variable.

smooth_step(unsmoothed_rv, smoothed_rv, …)

A single smoother step.

smoother_step(**kwargs)

Smoother step.

update(time, randvar, data, **kwargs)

Gaussian filter update step.

Attributes Documentation

dynamicmodel

Convenience function for accessing self.dynamod.

initialdistribution

Convenience function for accessing self.initdist.

initialrandomvariable

Convenience function for accessing self.initrv.

measurementmodel

Convenience function for accessing self.measmod.

Methods Documentation

condition_state_on_measurement(randvar, meas_rv, data, crosscov, **kwargs)[source]

Condition the state on the observed data.

Parameters
  • randvar (Normal) – Random variable to be updated with the measurement and data.

  • meas_rv (Normal) – Measured random variable, as returned by the measurement model.

  • data (np.ndarray) – Data to update on.

  • crosscov (np.ndarray) – Cross-covariance between the state random variable randvar and the measurement random variable meas_rv.

Returns

Updated Normal random variable (new filter estimate)

Return type

Normal

filter(dataset, times, **kwargs)[source]

Apply Gaussian filtering (no smoothing!) to a data set.

Parameters
  • dataset (array_like, shape (N, M)) – Data set that is filtered.

  • times (array_like, shape (N,)) – Temporal locations of the data points.

Returns

Posterior distribution of the filtered output

Return type

KalmanPosterior

filter_step(start, stop, current_rv, data, **kwargs)[source]

A single filter step.

Consists of a prediction step (t -> t+1) and an update step (at t+1).

Parameters
  • start (float) – Predict FROM this time point.

  • stop (float) – Predict TO this time point.

  • current_rv (RandomVariable) – Predict based on this random variable. For instance, this can be the result of a previous call to filter_step.

  • data (array_like) – Compute the update based on this data.

Returns

  • RandomVariable – Resulting filter estimate after the single step.

  • dict – Additional information provided by predict() and update(). Contains keys pred_rv, info_pred, meas_rv, info_upd.

filtsmooth(dataset, times, **kwargs)[source]

Apply Gaussian filtering and smoothing to a data set.

Parameters
  • dataset (array_like, shape (N, M)) – Data set that is filtered.

  • times (array_like, shape (N,)) – Temporal locations of the data points.

Returns

Posterior distribution of the smoothed output

Return type

KalmanPosterior

measure(time, randvar, **kwargs)[source]

Propagate the state through the measurement model.

Parameters
  • time (float) – Time of the measurement.

  • randvar (Normal) – Random variable to be propagated through the measurement model.

Returns

  • meas_rv (Normal) – Measured random variable, as returned by the measurement model.

  • info (dict) – Additional info. Contains at leas the key crosscov which is the cross covariance between the input random variable and the measured random variable.

predict(start, stop, randvar, **kwargs)[source]

Prediction step of the Bayesian filter.

Not required for all filters, e.g. the Particle Filter only has an update() method.

smooth(filter_posterior, **kwargs)[source]

Apply Gaussian smoothing to the filtering outcome (i.e. a KalmanPosterior).

Parameters

filter_posterior (KalmanPosterior) – Posterior distribution obtained after filtering

Returns

Posterior distribution of the smoothed output

Return type

KalmanPosterior

smooth_list(rv_list, locations, **kwargs)[source]

Apply smoothing to a list of RVs with desired final random variable.

Specification of a final RV is useful to compute joint samples from a KalmanPosterior object, because in this case, the final RV is a Dirac (over a sample from the final Normal RV) and not a Normal RV.

Parameters
  • rv_list (_RandomVariableList or array_like) – List of random variables to be smoothed.

  • locations (array_like) – Locations of the random variables in rv_list.

Returns

List of smoothed random variables.

Return type

_RandomVariableList

smooth_step(unsmoothed_rv, smoothed_rv, start, stop, **kwargs)[source]

A single smoother step.

Consists of predicting from the filtering distribution at time t to time t+1 and then updating based on the discrepancy to the smoothing solution at time t+1.

Parameters
  • unsmoothed_rv (RandomVariable) – Filtering distribution at time t.

  • smoothed_rv (RandomVariable) – Prediction at time t+1 of the filtering distribution at time t.

  • start (float) – Time-point of the to-be-smoothed RV.

  • stop (float) – Time-point of the already-smoothed RV.

smoother_step(**kwargs)

Smoother step.

update(time, randvar, data, **kwargs)[source]

Gaussian filter update step. Consists of a measurement step and a conditioning step.

Parameters
  • time (float) – Time of the update.

  • randvar (RandomVariable) – Random variable to be updated. Result of predict().

  • data (np.ndarray) – Data to update on.

Returns

  • filt_rv (Normal) – Updated Normal RV (new filter estimate).

  • meas_rv (Normal) – Measured random variable, as returned by the measurement model.

  • info (dict) – Additional info. Contains at least the key crosscov, which is the crosscov between input RV and measured RV. The crosscov does not relate to the updated RV!