NAG Library Routine Document
G13EAF
1 Purpose
G13EAF performs a combined measurement and time update of one iteration of the time-varying Kalman filter using a square root covariance filter.
2 Specification
SUBROUTINE G13EAF ( |
N, M, L, A, LDS, B, STQ, Q, LDQ, C, LDM, R, S, K, H, TOL, IWK, WK, IFAIL) |
INTEGER |
N, M, L, LDS, LDQ, LDM, IWK(M), IFAIL |
REAL (KIND=nag_wp) |
A(LDS,N), B(LDS,L), Q(LDQ,*), C(LDM,N), R(LDM,M), S(LDS,N), K(LDS,M), H(LDM,M), TOL, WK((N+M)*(N+M+L)) |
LOGICAL |
STQ |
|
3 Description
The Kalman filter arises from the state space model given by:
where
is the state vector of length
at time
,
is the observation vector of length
at time
, and
of length
and
of length
are the independent state noise and measurement noise respectively.
The estimate of
given observations
to
is denoted by
with state covariance matrix
, while the estimate of
given observations
to
is denoted by
with covariance matrix
. The update of the estimate,
, from time
to time
, is computed in two stages. First, the measurement-update is given by
and
where
is the Kalman gain matrix. The second stage is the time-update for
which is given by
and
where
represents any deterministic control used.
The square root covariance filter algorithm provides a stable method for computing the Kalman gain matrix and the state covariance matrix. The algorithm can be summarised as
where
is an orthogonal transformation triangularizing the left-hand pre-array to produce the right-hand post-array. The relationship between the Kalman gain matrix,
, and
is given by
G13EAF requires the input of the lower triangular Cholesky factors of the noise covariance matrices
and, optionally,
and the lower triangular Cholesky factor of the current state covariance matrix,
, and returns the product of the matrices
and
,
, the Cholesky factor of the updated state covariance matrix
and the matrix
used in the computation of the likelihood for the model.
4 References
Vanbegin M, van Dooren P and Verhaegen M H G (1989) Algorithm 675: FORTRAN subroutines for computing the square root covariance filter and square root information filter in dense or Hessenberg forms ACM Trans. Math. Software 15 243–256
Verhaegen M H G and van Dooren P (1986) Numerical aspects of different Kalman filter implementations IEEE Trans. Auto. Contr. AC-31 907–917
5 Parameters
- 1: N – INTEGERInput
On entry: , the size of the state vector.
Constraint:
.
- 2: M – INTEGERInput
On entry: , the size of the observation vector.
Constraint:
.
- 3: L – INTEGERInput
On entry: , the dimension of the state noise.
Constraint:
.
- 4: A(LDS,N) – REAL (KIND=nag_wp) arrayInput
On entry: the state transition matrix, .
- 5: LDS – INTEGERInput
On entry: the first dimension of the arrays
A,
B,
S and
K as declared in the (sub)program from which G13EAF is called.
Constraint:
.
- 6: B(LDS,L) – REAL (KIND=nag_wp) arrayInput
On entry: the noise coefficient matrix .
- 7: STQ – LOGICALInput
On entry: if
, the state noise covariance matrix
is assumed to be the identity matrix. Otherwise the lower triangular Cholesky factor,
, must be provided in
Q.
- 8: Q(LDQ,) – REAL (KIND=nag_wp) arrayInput
-
Note: the second dimension of the array
Q
must be at least
if
and at least
if
.
On entry: if
,
Q must contain the lower triangular Cholesky factor of the state noise covariance matrix,
. Otherwise
Q is not referenced.
- 9: LDQ – INTEGERInput
On entry: the first dimension of the array
Q as declared in the (sub)program from which G13EAF is called.
Constraints:
- if , ;
- otherwise .
- 10: C(LDM,N) – REAL (KIND=nag_wp) arrayInput
On entry: the measurement coefficient matrix, .
- 11: LDM – INTEGERInput
On entry: the first dimension of the arrays
C,
R and
H as declared in the (sub)program from which G13EAF is called.
Constraint:
.
- 12: R(LDM,M) – REAL (KIND=nag_wp) arrayInput
On entry: the lower triangular Cholesky factor of the measurement noise covariance matrix .
- 13: S(LDS,N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the lower triangular Cholesky factor of the state covariance matrix, .
On exit: the lower triangular Cholesky factor of the state covariance matrix, .
- 14: K(LDS,M) – REAL (KIND=nag_wp) arrayOutput
On exit: the Kalman gain matrix, , premultiplied by the state transition matrix, , .
- 15: H(LDM,M) – REAL (KIND=nag_wp) arrayOutput
On exit: the lower triangular matrix .
- 16: TOL – REAL (KIND=nag_wp)Input
On entry: the tolerance used to test for the singularity of
. If
, then
is used instead. The inverse of the condition number of
is estimated by a call to
F07TGF (DTRCON). If this estimate is less than
TOL then
is assumed to be singular.
Suggested value:
.
Constraint:
.
- 17: IWK(M) – INTEGER arrayWorkspace
- 18: WK() – REAL (KIND=nag_wp) arrayWorkspace
- 19: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction 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 parameter, 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, | , |
or | , |
or | , |
or | , |
or | , |
or | and , |
or | and , |
or | . |
The matrix is singular.
7 Accuracy
The use of the square root algorithm improves the stability of the computations as compared with the direct coding of the Kalman filter. The accuracy will depend on the model.
For models with time-invariant
and
,
G13EBF can be used.
The estimate of the state vector
can be computed from
by
where
are the independent one step prediction residuals. The required matrix-vector multiplications can be performed by
F06PAF (DGEMV).
If
and
are independent multivariate
Normal variates then the log-likelihood for observations
is given by
where
is a constant.
The Cholesky factors of the covariance matrices can be computed using
F07FDF (DPOTRF).
Note that the model
can be specified either with
B set to the identity matrix and
and the matrix
input in
Q or with
and
B set to
.
The algorithm requires
operations and is backward stable (see
Verhaegen and van Dooren (1986)).
9 Example
This example first inputs the number of updates to be computed and the problem sizes. The initial state vector and state covariance matrix are input followed by the model matrices
and optionally
. The Cholesky factors of the covariance matrices can be computed if required. The model matrices can be input at each update or only once at the first step. At each update the observed values are input and the residuals are computed and printed and the estimate of the state vector,
, and the deviance are updated. The deviance is
log-likelihood ignoring the constant. After the final update the state covariance matrix is computed from
S and printed along with final estimate of the state vector and the value of the deviance.
The data is for a two-dimensional time series to which a VARMA
has been fitted. For the specification of a VARMA model as a state space model see the
G13 Chapter Introduction. The initial value of
,
, is the solution to
For convenience, the mean of each series is input before the first update and subtracted from the observations before the measurement update is computed.
9.1 Program Text
Program Text (g13eafe.f90)
9.2 Program Data
Program Data (g13eafe.d)
9.3 Program Results
Program Results (g13eafe.r)