
% Copyright 2015 The MathWorks, Inc.

function [A,B,C,D,Mean0,Cov0,StateType] = diffuseTimeVariantParamMap(params)
% Time-varying, diffuse state-space model parameter mapping function
% example. This function maps the vector params to the state-space matrices
% (A, B, C, and D) and the type of state (StateType). From periods 1
% through 10, the state model is an AR(1) and a random walk. The
% observation model is the sum of the two states. From periods 11 through
% 20, the state model is just the AR(1) model.
    varu11 = exp(params(2));  % Positive variance constraints
    varu21 = exp(params(3));
    vare11 = exp(params(5));
    vare12 = exp(params(7));
    A1 = {[params(1) 0; 0 1]};
    B1 = {[sqrt(varu11) 0; 0 sqrt(varu21)]}; 
    C1 = {params(4)*[1 1]};
    D1 = {sqrt(vare11)};
    A2 = {[params(1) 0]};
    B2 = {sqrt(varu11)};
    A3 = {params(1)};
    B3 = {sqrt(varu11)}; 
    C3 = {params(6)};
    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)];
    Mean0 = []; % Let software infer Mean0 
    Cov0 = [];  % Let software infer Cov0
    StateType = [0 2];
end
