Documentation Center

  • Trial Software
  • Product Updates

Implicitly Specify a Time-Varying State-Space Model

This example shows how to specify a time-varying state-space model by passing a parameter-mapping function describing the model to ssm (i.e., implicitly specify a state-space model). Suppose that from periods 1 to 10, the state model are stationary AR(2) and MA(1) models, respectively, and the observation model is the sum of the two states. From periods 11 to 20, the state model only includes the first AR(2) model.

Create the function timeVariantParamMap.m, which specifies how the parameters in params map to the state-space model matrices, the initial state values, and the type of state. Symbolically, the models are:

  • For periods 1 to 10,

  • For period 11,

  • For periods 12 to 20,

function [A,B,C,D,Mean0,Cov0,StateType] = timeVariantParamMap(params)
% Time-variant state-space model parameter mapping function example. This
% function maps the vector params to the state-space matrices (A, B, C, and
% D), the initial state value and the initial state variance (Mean0 and
% Cov0), and the type of state (StateType). From periods 1 through 10, the
% state model is an AR(2) and an MA(1) model, and the observation model is
% the sum of the two states. From periods 11 through 20, the state model is
% just the AR(2) model.
    varu11 = exp(params(3));  % Positive variance constraints
    vare11 = exp(params(7));
    vare12 = exp(params(9));
    A1 = {[params(1) params(2) 0 0; 1 0 0 0; 0 0 0 params(5); 0 0 0 0]};
    B1 = {[sqrt(varu11) 0; 0 0; 0 1; 0 1]};
    C1 = {params(6)*[1 0 1 0]};
    D1 = {sqrt(vare11)};
    Mean0 = [0.5 0.5 0 0];
    Cov0 = eye(4);
    StateType = [0 0 0 0];
    A2 = {[params(1) params(2) 0 0; 1 0 0 0]};
    B2 = {[sqrt(varu11); 0]};
    A3 = {[params(1) params(2); 1 0]};
    B3 = {[sqrt(varu11); 0]};
    C3 = {params(8)*[1 0]};
    D3 = {sqrt(vare12)};
    A = [repmat(A1,10,1);A2;repmat(A3,9,1)];
    B = [repmat(B1,10,1);B2;repmat(B3,9,1)];
    C = [repmat(C1,10,1);repmat(C3,10,1)];
    D = [repmat(D1,10,1);repmat(D3,10,1)];
end

Specify the state-space model by passing the function timeVariantParamMap as a function handle to ssm.

Mdl = ssm(@timeVariantParamMap)
Mdl = 

The state space model is implicitly defined by the function:
    @timeVariantParamMap

The software implicitly defines the state-space model. Usually, you cannot verify state-space models that you implicitly define.

Pass Mdl and response data to estimate to estimate the model parameters.

See Also

| |

Related Examples

Was this topic helpful?