This module contains Bayesian filters.
All classes from this module are currently imported to top-level pybayes module, so instead of from pybayes.filters import KalmanFilter you can type from pybayes import KalmanFilter.
Abstract prototype of a bayesian filter.
Perform approximate or exact bayes rule.
Parameters: |
|
---|---|
Returns: | always returns True (see posterior() to get posterior density) |
Return posterior probability density funcion (CPdf).
Returns: | posterior density |
---|---|
Return type: |
Filter implementations may decide to return a reference to their work pdf - it is not safe to modify it in any way, doing so may leave the filter in undefined state.
Return the logarithm of evidence function (also known as marginal likelihood) evaluated in point yt.
Parameters: | yt (numpy.ndarray) – point which to evaluate the evidence in |
---|---|
Return type: | double |
This is typically computed after bayes() with the same observation:
>>> filter.bayes(yt)
>>> log_likelihood = filter.evidence_log(yt)
Implementation of standard Kalman filter. cond in bayes() is interpreted as control (intervention) input to the system.
Kalman filter forms optimal Bayesian solution for the following system:
where is hidden state vector, is observation vector and is control vector. is normally distributed zero-mean process noise with covariance matrix , is normally distributed zero-mean observation noise with covariance matrix . Additionally, intial pdf (state_pdf) has to be Gaussian.
Initialise Kalman filter.
Parameters: |
|
---|
All matrices can be time-varying - you can modify or replace all above stated matrices providing that you don’t change their shape and all constraints still hold. On the other hand, you should not modify state_pdf unless you really know what you are doing.
>>> # initialise control-less Kalman filter:
>>> kf = pb.KalmanFilter(A=np.array([[1.]]),
C=np.array([[1.]]),
Q=np.array([[0.7]]), R=np.array([[0.3]]),
state_pdf=pb.GaussPdf(...))
Perform exact bayes rule.
Parameters: |
|
---|---|
Returns: | always returns True (see posterior() to get posterior density) |
Standard particle filter (or SIR filter, SMC method) implementation with resampling and optional support for proposal density.
Posterior pdf is represented using EmpPdf and takes following form:
Initialise particle filter.
Parameters: |
|
---|
Perform Bayes rule for new measurement ; cond is ignored.
Parameters: | cond (numpy.ndarray) – optional condition that is passed to after so that is can be rewritten as: . |
---|
The algorithm is as follows:
Simple marginalized particle filter implementation. Assume that tha state vector can be divided into two parts and that the pdf representing the process model can be factorised as follows:
and that the part (given ) can be estimated with (a subbclass of) the KalmanFilter. Such system may be suitable for the marginalized particle filter, whose posterior pdf takes the form
Note: currently is hard-coded to be process and observation noise covariance of the part. This will be changed soon and will be passed as condition to KalmanFilter.bayes().
Initialise marginalized particle filter.
Parameters: |
|
---|
Perform Bayes rule for new measurement . Uses following algorithm: