Miniker 102 manual: 4.3 Kalman filter

[ < ] | [ > ] |  | [Contents] | [Index] | [ ? ]

## 4.3 Kalman filter

The Kalman filter allows for data assimilation along the model run. In that case it is assumed that there is a real-world model with stochastic perturbations on the states, and that noisy observations are available. The situation implemented in Miniker corresponds to a continuous stochastic perturbation on the state, and discrete noisy observations. In the TEF this leads to:

The observations ω are available at discrete time steps t = si. The stochastic perturbation on state, μ is characterized by a variance-covariance matrix Q and the noise on the observation, ν has a variance-covariance matrix R. W relates states with stochastic perturbations. At each time step the Kalman filter recomputes an estimation of the state and the variance-covariance matrix of the state.

In the following we use the example of a linear model with perturbation on state and observation of state. The model has 3 states and 3 corresponding transfers (equal to the states), but the error on the state is of dimension 2. The 3 states are observed. The corresponding equations read:

[ < ] | [ > ] |  | [Contents] | [Index] | [ ? ]

### 4.3.1 Coding the Kalman filter

First of all the Kalman filter code should be activated. The observations code is also required (see Observations). If cmz is used the code should be selected with the select flag kalman in the ‘`selseq.kumac`’:

    sel kalman

With make the `kalman` variable should be set to 1:

    kalman = 1

The kalman code is actually used by setting the flag `zkalman` to `.true.`, for example in the ‘`zinit`’:

    zkalman = .True.;

With the Kalman filter the dimension of estimated states, of the error on the state and of the observation, the W matrix, the observation function, the initial variance-covariance matrices on the state and the variance-covariance matrices of errors have to be given.

[ < ] | [ > ] |  | [Contents] | [Index] | [ ? ]

#### 4.3.1.1 Kalman filter vectors dimensions

These dimensions should be set in the ‘`zinit`’ sequence. The size of the estimated states is given by the parameter `nkp`. You can set this to `np` if all the states are estimated, but in case there are some deterministic state variables, `nkp` may be less than `np`. In that case the first `nkp` elements of `eta(.)` will be estimated using the Kalman filter.

The error on state dimension is associated with the parameter `nerrp` and the size of the observations vector is `mobs` (see Observations). In our example the dimensions are set with:

    parameter (nkp=np);
    parameter (mobs=3);
    parameter (nerrp=2);

All the states are estimated, there are 3 observation functions and the error on the state vector is of dimension 2.

If the sizes are set explicitely, the parameters should be set in ‘`dimetaphi`’.

[ < ] | [ > ] |  | [Contents] | [Index] | [ ? ]

#### 4.3.1.2 Error and observation matrices

#### Initial variance-covariance matrix on the state

The variance-covariance on the state matrix is `covfor(.,.)`. The initial values have to be given for this matrix, as in our example:

    covfor(1,1) = 1000.; covfor(1,2) = 10.; covfor(1,3) = 10.;
    covfor(2,1) = 10.; covfor(2,2) = 5000.; covfor(2,3) = 5.;
    covfor(3,1) = 10.; covfor(3,2) = 5.; covfor(3,3) = 2000.;

This matrix is updated by the filter at each time step because the states are pertubated by some noise, and when assimilation takes place as new information reduce the error.

#### Observations and error on state matrix

The matrix that relates errors on states vector components to states, corresponding with W is `mereta(.,.)`. In our example it is set by:

    mereta(1,1) = 1.;  mereta(1,2) = 0.;
    mereta(2,1) = 0.;  mereta(2,2) = 1.;
    mereta(3,1) = 0.5;  mereta(3,2) = 0.5;

The observation functions are set by a `f_set` macro with `Obs_tef(.)` as described in Observations. In our example the observation functions are set by:

    f_set Obs_tef(1) = ff(1) ;
    f_set Obs_tef(2) = eta(2);
    f_set Obs_tef(3) = eta(3);

#### Error variance-covariance matrices

The variance-covariance matrix on observation noise is `covobs(.,.)` set, in our example, by:

    covobs(1,1) = 0.3; covobs(1,2) = 0.; covobs(1,3) = 0.;
    covobs(2,1) = 0.; covobs(2,2) = 0.1; covobs(2,3) = 0.;
    covobs(3,1) = 0.; covobs(3,2) = 0.; covobs(3,3) = 0.2;

The variance-covariance matrix on state noise is `coveta(.,.)` set, in our example, by:

    coveta(1,1) = 0.2; coveta(1,2) = 0.001;
    coveta(2,1) = 0.001; coveta(2,2) = 0.1;

These matrices are not changed during the run of the model as part of the filtering process. They may be changed by the user in ‘`zsteer`’.

[ < ] | [ > ] |  | [Contents] | [Index] | [ ? ]

### 4.3.2 Kalman filter run and output

[ < ] | [ > ] |  | [Contents] | [Index] | [ ? ]

#### 4.3.2.1 Feeding the observations to the model

The observations must be made available to the model during the run. These observations are set in the `vobs(.)` array, and the assimilation (also called the analysis step of the filter) takes place if the logical variable `zgetobs` is `.true.` (see Data).

These steps are typically performed in the ‘`zsteer`’ sequence. In this sequence there should be some code such that when there are data ready to be assimilated, `zgetobs` is set to `.true.` and the data is stored in `vobs(.)`, ready for the next step processing.

[ < ] | [ > ] |  | [Contents] | [Index] | [ ? ]

#### 4.3.2.2 Kalman filter results

The estimated states and transfers are still in the same ‘`.data`’ files, ‘`res.data`’ and ‘`tr.data`’ and there is the additional file with observations, called ‘`obs.data`’ (see Observations). Each time `zgetobs` is `.true.` the data, and the optimally weighted innovations are output in the file associated with data, ‘`data.data`’ (see Data).

[ < ] | [ > ] |  | [Contents] | [Index] | [ ? ]

### 4.3.3 Executing code after the analysis

The analysis takes place before the time step advance when `zgetobs` is `.true.`. It may be usefull to add some code after the analysis and before the time step advance. For example the analysis may lead to absurd values for some states or parameters, it could be usefull to correct them in that case. The sequence included after the analysis is called ‘`kalsteer`’. At this point, in addition to the usual variables the following variables could be usefull:

`etafor(.)`

  The state before the analysis.

`kgain(.)`

  The Kalman gain.

`innobs(.)`

  The innovation vector (observations coherent with the states minus data values).

`covana(.,.)`

  The variance-covariance error matrix after the analysis.

At each time step the derivative of the observation function with respect to transfer and cells variables are recomputed. The elimination of transfers is also performed to get the partial derivative of the observation function of the equivalent model, with states only, with respect to the states. In other words, the Kalman filter does not follow the TEF formalism, because the advance of the var-covar matrix could not yet be set in the TEF form.

`obspha(.,.)`

  derivative of observation function in state space with respect to cell variables.

[Contents] | [Index] | [ ? ]

This document was generated by a tester on a sunny day using texi2html.