The routine may be called by the names g13ebf or nagf_tsa_multi_kalman_sqrt_invar.
3Description
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 matrices and are time invariant.
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
(1)
where is the Kalman gain matrix. The second stage is the time-update for , which is given by
(2)
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 triangularization is carried out via Householder transformations exploiting the zero pattern of the pre-array. The relationship between the Kalman gain matrix and is given by
In order to exploit the invariant parts of the model to simplify the computation of the results for the transformed state space are computed where is the transformation that reduces the matrix pair to lower observer Hessenberg form. That is, the matrix is computed such that the compound matrix
is a lower trapezoidal matrix. Further the matrix is transformed to . These transformations need only be computed once at the start of a series, and g13ebf will, optionally, compute them. g13ebf returns transformed matrices , , and , the Cholesky factor of the updated transformed state covariance matrix (where ) and the matrix , valid for both transformed and original models, which is used in the computation of the likelihood for the model. Note that the covariance matrices and can be time-varying.
4References
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. Software15 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
5Arguments
1: – Character(1)Input
On entry: indicates whether to transform the input matrix pair to lower observer Hessenberg form. The transformation will only be required on the first call to g13ebf.
The matrices in arrays a and c are transformed to lower observer Hessenberg form and the matrices in b and s are transformed as described in Section 3.
The matrices in arrays a, c and b should be as returned from a previous call to g13ebf with .
Constraint:
or .
2: – IntegerInput
On entry: , the size of the state vector.
Constraint:
.
3: – IntegerInput
On entry: , the size of the observation vector.
Constraint:
.
4: – IntegerInput
On entry: , the dimension of the state noise.
Constraint:
.
5: – Real (Kind=nag_wp) arrayInput/Output
On entry: if , the state transition matrix, .
If , the transformed matrix as returned by a previous call to g13ebf with .
On exit: if , the transformed matrix, , otherwise a is unchanged.
6: – IntegerInput
On entry: the first dimension of the arrays a, b, s, k and u as declared in the (sub)program from which g13ebf is called.
Constraint:
.
7: – Real (Kind=nag_wp) arrayInput/Output
On entry: if , the noise coefficient matrix .
If , the transformed matrix as returned by a previous call to g13ebf with .
On exit: if , the transformed matrix, , otherwise b is unchanged.
8: – 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.
9: – Real (Kind=nag_wp) arrayInput
Note: the second dimension of the array q
must be 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.
10: – IntegerInput
On entry: the first dimension of the array q as declared in the (sub)program from which g13ebf is called.
Constraints:
if , ;
otherwise .
11: – Real (Kind=nag_wp) arrayInput/Output
On entry: if , the measurement coefficient matrix, .
If , the transformed matrix as returned by a previous call to g13ebf with .
On exit: if , the transformed matrix, , otherwise c is unchanged.
12: – IntegerInput
On entry: the first dimension of the arrays c, r and h as declared in the (sub)program from which g13ebf is called.
Constraint:
.
13: – Real (Kind=nag_wp) arrayInput
On entry: the lower triangular Cholesky factor of the measurement noise covariance matrix .
14: – Real (Kind=nag_wp) arrayInput/Output
On entry: if the lower triangular Cholesky factor of the state covariance matrix, .
If the lower triangular Cholesky factor of the covariance matrix of the transformed state vector as returned from a previous call to g13ebf with .
On exit: the lower triangular Cholesky factor of the transformed state covariance matrix, .
15: – Real (Kind=nag_wp) arrayOutput
On exit: the Kalman gain matrix for the transformed state vector premultiplied by the state transformed transition matrix, .
16: – Real (Kind=nag_wp) arrayOutput
On exit: the lower triangular matrix .
17: – Real (Kind=nag_wp) arrayOutput
Note: the second dimension of the array u
must be at least
if .
On exit: if the transformation matrix , otherwise u is not referenced.
18: – 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. If this estimate is less than tol then is assumed to be singular.
Suggested value:
.
Constraint:
.
19: – Integer arrayWorkspace
20: – Real (Kind=nag_wp) arrayWorkspace
21: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or 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).
6Error 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, and . Constraint: .
On entry, .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, . Constraint: .
On entry, . Constraint: or .
The matrix is singular.
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
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.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g13ebf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g13ebf 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.
9Further Comments
For models with time-varying and , g13eaf can be used.
The initial estimate of the transformed state vector can be computed from the estimate of the original state vector , say, by premultiplying it by as returned by g13ebf with ; that is, . The estimate of the transformed state vector can be computed from the previous value by
where
are the independent one-step prediction residuals for both the transformed and original model. The estimate of the original state vector can be computed from the transformed state vector as . The required matrix-vector multiplications can be performed by f06paf.
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.
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)). The transformation to lower observer Hessenberg form requires operations.
10Example
This example first inputs the number of updates to be computed and the problem sizes. The initial state vector and the Cholesky factor of the state covariance matrix are input followed by the model matrices and optionally (the Cholesky factors of the covariance matrices being input). At the first update the matrices are transformed using the option and the initial value of the state vector is transformed. At each update the observed values are input and the residuals are computed and printed and the estimate of the transformed state vector, , and the deviance are updated. The deviance is ignoring the constant. After the final update the estimate of the state vector is computed from the transformed state vector and the state covariance matrix is computed from s and these are printed along with 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 means of the two series are included as additional states that do not change over time. The initial value of , , is the solution to