%----------------------------------------------------------------------------
%                          DEMONSTRATION PROGRAM-2
%           FOR  MMLE.M  MAXIMUM LIKELIHOOD IDENTIFICATION FUNCTION
%           IDENTIFIES 2*2 TRANSITION MATRIX WITH SINGLE DUMMY STATE
%    - A QUADRATIC COST FUNCTION EXAMPLE TO CHECK NEWTON ALGO CONVERGENCE -
%----------------------------------------------------------------------------

format compact,clc
diary ml_demo2.log

'-----------------------------------------------------------------------------';
rule=ans;disp(ans)
disp('                          MMLE  DEMONSTRATION  No 2')
disp('                      No dynamics, 2 by 2 mixing matrix')
disp('                       True parameters are [ 1 1 1 1 ]')
%--------------------------------------------------------------------------

p2snam='ml_p2ss2';%                   FOR DEMO_2 WE GENERATE SIMULATED DATA
ptrue=[1 1 1 1];
[a,phi,gam,c,d]=eval([p2snam,'(ptrue)']);%             GET SIMULATED SYSTEM

uydata=ones(100,4);%                                        CREATE AN INPUT
uydata(1:50,1)=zeros(50,1);

randn('seed',0);%                 INITIALIZE RANDOM GENERATOR

uydata(:,3:4)=dlsim(phi,gam,c,d,uydata(:,1:2))+randn(100,2)/100;%   SIMULATE


% Note: IF WE DON'T ADD SOME NOISE OR MODELING ERROR, THE RESPONSE FIT WILL
%       BECOME PERFECT AND THE INNOVATIONS COVARIANCE WILL BECOME ZERO TO
%       CAUSE NUMERICAL PROBLEMS IN THE gg ESTIMATION PHASE.  EITHER ADD
%       NOISE OR DON'T ESTIMATE gg ON SIMULATED DATA. THIS PROBLEM ONLY
%       OCCURS WITH SIMULATED DATA.

disp(rule)

% IN ADDITION TO uydata AND p2snam (DEFINED ABOVE), MUST CHOOSE VALUES FOR :

gg0=eye(2);
p0=[0 0 0 0];
pert=.001;
pidq=1;
pidm=[1:4];
pidf=[1:4];
opt=[0 5 5 5 .02 .01 .001 1];
mmle
diary off
%------------------------------------------------------------- end ml_demo2.m

