%% Implicitly Create Time-Varying Diffuse State-Space Model
%%
% This example shows how to create a time-varying, diffuse state-space
% model by passing a parameter-mapping function describing the model to
% |ssm| (i.e., _implicitly_ create a diffuse state-space model).
%%
% Suppose that from periods 1 through 10, the first state model is a
% stationary AR(1) model and the second state is a random walk.  The
% observation model is the sum of the two states. From periods 11 through
% 20, the state model only includes the first AR(1) model.
%%
% Symbolically, the models
% are:
%
% $$\begin{array}{c}
% \left[ {\begin{array}{*{20}{c}}
% {{x_{1,t}}}\\
% {{x_{2,t}}}
% \end{array}} \right] = \left[ {\begin{array}{*{20}{c}}
% {{\phi _1}}&0\\
% 0&1\\
% \end{array}} \right]\left[ {\begin{array}{*{20}{c}}
% {{x_{1,t - 1}}}\\
% {{x_{2,t - 1}}}
% \end{array}} \right] + \left[ {\begin{array}{*{20}{c}}
% {{\sigma _1}}&0\\
% 0&\sigma_2
% \end{array}} \right]\left[ {\begin{array}{*{20}{c}}
% {{u_{1t}}}\\
% {{u_{2t}}}
% \end{array}} \right]\\
% {y_t} = {a_1}\left( {{x_{1,t}} + {x_{2,t}}} \right) + {\sigma _2}{\varepsilon _t}.
% \end{array}{\rm for\;}t = 1,...,10,$$
% 
% $$\begin{array}{c}
% \left[ {\begin{array}{*{20}{c}}
% {{x_{1,t}}}
% \end{array}} \right] = \left[ {\begin{array}{*{20}{c}}
% {{\phi _1}} & 0
% \end{array}} \right]\left[ {\begin{array}{*{20}{c}}
% {{x_{1,t - 1}}}\\
% {{x_{2,t - 1}}}
% \end{array}} \right] + 
% {{\sigma _1}}{u_{1t}}\\
% {y_t} = {a_2}{x_{1t}} + {\sigma _3}{\varepsilon _t}.
% \end{array}{\rm for\;}t = 11,$$
%
% $$\begin{array}{c}
% \left[ {\begin{array}{*{20}{c}}
% {{x_{1t}}}\\
% {{x_{2t}}}
% \end{array}} \right] = 
% {{\phi _1}} {{x_{1,t - 1}}} + 
% {{\sigma _1}}{u_{1t}}\\
% {y_t} = {a_2}{x_{1t}} + {\sigma _3}{\varepsilon _t}.
% \end{array}{\rm for\;}t = 12,...,20.$$
% 
%%
% Write a function that specifies how the
% parameters in |params| map to the state-space model matrices, the initial
% state values, and the type of state.
%
% <include>diffuseTimeVariantParamMap.m</include>
%
%%
% Save this code as a file named |diffuseTimeVariantParamMap.m| on your MATLAB(R)
% path.
%%
% Create the diffuse state-space model by passing the function
% |diffuseTimeVariantParamMap| as a function handle to |dssm|.

% Copyright 2015 The MathWorks, Inc.

Mdl = ssm(@diffuseTimeVariantParamMap);
%%
% |dssm| implicitly creates the diffuse state-space model. Usually, you
% cannot verify implicitly created diffuse state-space models.
%%
% |Mdl| is an |dssm| model object containing unknown parameters.  You can
% estimate the unknown parameters by passing |Mdl| and response data to
% |estimate|.