NAG Library Routine Document
g13ekf (kalman_unscented_state)
1
Purpose
g13ekf applies the Unscented Kalman Filter (UKF) to a nonlinear state space model, with additive noise.
g13ekf uses direct communication for evaluating the nonlinear functionals of the state space model.
2
Specification
Fortran Interface
Subroutine g13ekf ( |
mx, my, y, lx, ly, f, h, x, st, iuser, ruser, ifail) |
Integer, Intent (In) | :: | mx, my | Integer, Intent (Inout) | :: | iuser(*), ifail | Real (Kind=nag_wp), Intent (In) | :: | y(my), lx(mx,mx), ly(my,my) | Real (Kind=nag_wp), Intent (Inout) | :: | x(mx), st(mx,mx), ruser(*) | External | :: | f, h |
|
C Header Interface
#include <nagmk26.h>
void |
g13ekf_ (const Integer *mx, const Integer *my, const double y[], const double lx[], const double ly[], void (NAG_CALL *f)(const Integer *mx, const Integer *n, const double xt[], double fxt[], Integer iuser[], double ruser[], Integer *info), void (NAG_CALL *h)(const Integer *mx, const Integer *my, const Integer *n, const double yt[], double hyt[], Integer iuser[], double ruser[], Integer *info), double x[], double st[], Integer iuser[], double ruser[], Integer *ifail) |
|
3
Description
g13ekf applies the Unscented Kalman Filter (UKF), as described in
Julier and Uhlmann (1997b) to a nonlinear state space model, with additive noise, which, at time
, can be described by:
where
represents the unobserved state vector of length
and
the observed measurement vector of length
. The process noise is denoted
, which is assumed to have mean zero and covariance structure
, and the measurement noise by
, which is assumed to have mean zero and covariance structure
.
3.1
Unscented Kalman Filter Algorithm
Given
, an initial estimate of the state and
and initial estimate of the state covariance matrix, the UKF can be described as follows:
(a) |
Generate a set of sigma points (see Section 3.2):
|
(b) |
Evaluate the known model function :
The function is assumed to accept the matrix, and return an matrix, . The columns of both and correspond to different possible states. The notation is used to denote the th column of , hence the result of applying to the th possible state.
|
(c) |
Time Update:
|
(d) |
Redraw another set of sigma points (see Section 3.2):
|
(e) |
Evaluate the known model function :
The function is assumed to accept the matrix, and return an matrix, . The columns of both and correspond to different possible states. As above is used to denote the th column of . |
(f) |
Measurement Update:
|
Here
is the Kalman gain matrix,
is the estimated state vector at time
and
the corresponding covariance matrix. Rather than implementing the standard UKF as stated above
g13ekf uses the square-root form described in the
Haykin (2001).
3.2
Sigma Points
A nonlinear state space model involves propagating a vector of random variables through a nonlinear system and we are interested in what happens to the mean and covariance matrix of those variables. Rather than trying to directly propagate the mean and covariance matrix, the UKF uses a set of carefully chosen sample points, referred to as sigma points, and propagates these through the system of interest. An estimate of the propagated mean and covariance matrix is then obtained via the weighted sample mean and covariance matrix.
For a vector of
random variables,
, with mean
and covariance matrix
, the sigma points are usually constructed as:
When calculating the weighted sample mean and covariance matrix two sets of weights are required, one used when calculating the weighted sample mean, denoted
and one used when calculated the weighted sample covariance matrix, denoted
. The weights and multiplier,
, are constructed as follows:
where, usually
and
and
are constants. The total number of sigma points,
, is given by
. The constant
is usually set to somewhere in the range
and for a Gaussian distribution, the optimal values of
and
are
and
respectively.
The constants,
,
and
are given by
,
and
. If more control is required over the construction of the sigma points then the reverse communication routine,
g13ejf, can be used instead.
4
References
Haykin S (2001) Kalman Filtering and Neural Networks John Wiley and Sons
Julier S J (2002) The scaled unscented transformation Proceedings of the 2002 American Control Conference (Volume 6) 4555–4559
Julier S J and Uhlmann J K (1997a) A consistent, debiased method for converting between polar and Cartesian coordinate systems Proceedings of AeroSense97, International Society for Optics and Phonotonics 110–121
Julier S J and Uhlmann J K (1997b) A new extension of the Kalman Filter to nonlinear systems International Symposium for Aerospace/Defense, Sensing, Simulation and Controls (Volume 3) 26
5
Arguments
- 1: – IntegerInput
-
On entry: , the number of state variables.
Constraint:
.
- 2: – IntegerInput
-
On entry: , the number of observed variables.
Constraint:
.
- 3: – Real (Kind=nag_wp) arrayInput
-
On entry: , the observed data at the current time point.
- 4: – Real (Kind=nag_wp) arrayInput
-
On entry:
, such that
, i.e., the lower triangular part of a Cholesky decomposition of the process noise covariance structure. Only the lower triangular part of
lx is referenced.
If is time dependent, the value supplied should be for time .
- 5: – Real (Kind=nag_wp) arrayInput
-
On entry:
, such that
, i.e., the lower triangular part of a Cholesky decomposition of the observation noise covariance structure. Only the lower triangular part of
ly is referenced.
If is time dependent, the value supplied should be for time .
- 6: – Subroutine, supplied by the user.External Procedure
-
The state function,
as described in
(b).
The specification of
f is:
Fortran Interface
Integer, Intent (In) | :: | mx, n | Integer, Intent (Inout) | :: | iuser(*), info | Real (Kind=nag_wp), Intent (In) | :: | xt(mx,n) | Real (Kind=nag_wp), Intent (Inout) | :: | ruser(*) | Real (Kind=nag_wp), Intent (Out) | :: | fxt(mx,n) |
|
C Header Interface
#include <nagmk26.h>
void |
f (const Integer *mx, const Integer *n, const double xt[], double fxt[], Integer iuser[], double ruser[], Integer *info) |
|
- 1: – IntegerInput
-
On entry: , the number of state variables.
- 2: – IntegerInput
-
On entry: , the number of sigma points.
- 3: – Real (Kind=nag_wp) arrayInput
-
On entry:
, the sigma points generated in
(a). For the
th sigma point, the value for the
th parameter is held in
, for
and
.
- 4: – Real (Kind=nag_wp) arrayOutput
-
On exit:
.
For the th sigma point the value for the th parameter should be held in
, for and .
- 5: – Integer arrayUser Workspace
- 6: – Real (Kind=nag_wp) arrayUser Workspace
-
f is called with the arguments
iuser and
ruser as supplied to
g13ekf. You should use the arrays
iuser and
ruser to supply information to
f.
- 7: – IntegerInput/Output
-
On entry: .
On exit: set
info to a nonzero value if you wish
g13ekf to terminate with
.
f must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
g13ekf is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: f should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
g13ekf. If your code inadvertently
does return any NaNs or infinities,
g13ekf is likely to produce unexpected results.
- 7: – Subroutine, supplied by the user.External Procedure
-
The measurement function,
as described in
(e).
The specification of
h is:
Fortran Interface
Integer, Intent (In) | :: | mx, my, n | Integer, Intent (Inout) | :: | iuser(*), info | Real (Kind=nag_wp), Intent (In) | :: | yt(mx,n) | Real (Kind=nag_wp), Intent (Inout) | :: | ruser(*) | Real (Kind=nag_wp), Intent (Out) | :: | hyt(my,n) |
|
C Header Interface
#include <nagmk26.h>
void |
h (const Integer *mx, const Integer *my, const Integer *n, const double yt[], double hyt[], Integer iuser[], double ruser[], Integer *info) |
|
- 1: – IntegerInput
-
On entry: , the number of state variables.
- 2: – IntegerInput
-
On entry: , the number of observed variables.
- 3: – IntegerInput
-
On entry: , the number of sigma points.
- 4: – Real (Kind=nag_wp) arrayInput
-
On entry:
, the sigma points generated in
(d). For the
th sigma point, the value for the
th parameter is held in
, for
and
, where
is the number of state variables and
is the number of sigma points.
- 5: – Real (Kind=nag_wp) arrayOutput
-
On exit:
.
For the th sigma point the value for the th parameter should be held in
, for and .
- 6: – Integer arrayUser Workspace
- 7: – Real (Kind=nag_wp) arrayUser Workspace
-
h is called with the arguments
iuser and
ruser as supplied to
g13ekf. You should use the arrays
iuser and
ruser to supply information to
h.
- 8: – IntegerInput/Output
-
On entry: .
On exit: set
info to a nonzero value if you wish
g13ekf to terminate with
.
h must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
g13ekf is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: h should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
g13ekf. If your code inadvertently
does return any NaNs or infinities,
g13ekf is likely to produce unexpected results.
- 8: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: the state vector for the previous time point.
On exit: the updated state vector.
- 9: – Real (Kind=nag_wp) arrayInput/Output
-
On entry:
, such that
, i.e., the lower triangular part of a Cholesky decomposition of the state covariance matrix at the previous time point. Only the lower triangular part of
st is referenced.
On exit: , the lower triangular part of a Cholesky factorization of the updated state covariance matrix.
- 10: – Integer arrayUser Workspace
- 11: – Real (Kind=nag_wp) arrayUser Workspace
-
iuser and
ruser are not used by
g13ekf, but are passed directly to
f and
h and may be used to pass information to these routines.
- 12: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry, .
Constraint: .
-
On entry, .
Constraint: .
-
User requested termination in
f.
-
User requested termination in
h.
-
A weight was negative and it was not possible to downdate the Cholesky factorization.
-
Unable to calculate the Kalman gain matrix.
-
Unable to calculate the Cholesky factorization of the updated state covariance matrix.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
Not applicable.
8
Parallelism and Performance
g13ekf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
None.
10
Example
This example implements the following nonlinear state space model, with the state vector
and state update function
given by:
where
and
are known constants and
and
are time-dependent knowns. The measurement vector
and measurement function
is given by:
where
and
are known constants. The initial values,
and
, are given by
and the Cholesky factorizations of the error covariance matrices,
and
by
10.1
Program Text
Program Text (g13ekfe.f90)
10.2
Program Data
Program Data (g13ekfe.d)
10.3
Program Results
Program Results (g13ekfe.r)
The example described above can be thought of relating to the movement of a hypothetical robot. The unknown state, , is the position of the robot (with respect to a reference frame) and facing, with giving the and coordinates and the angle (with respect to the -axis) that the robot is facing. The robot has two drive wheels, of radius on an axle of length . During time period the right wheel is believed to rotate at a velocity of and the left at a velocity of . In this example, these velocities are fixed with and . The state update function, , calculates where the robot should be at each time point, given its previous position. However, in reality, there is some random fluctuation in the velocity of the wheels, for example, due to slippage. Therefore the actual position of the robot and the position given by equation will differ.
In the area that the robot is moving there is a single wall. The position of the wall is known and defined by its distance, , from the origin and its angle, , from the -axis. The robot has a sensor that is able to measure , with being the distance to the wall and the angle to the wall. The measurement function gives the expected distance and angle to the wall if the robot's position is given by . Therefore the state space model allows the robot to incorporate the sensor information to update the estimate of its position.