optimize.m

Revision 1 - 5/31/07 at 3:43 pm by e2holmes

Back to revision history for optimize.m
This file is part of the project Teaching code for State-space models
function f = optimize(sigs,z,U)
%%%%  MATLAB function that optimizes likelihood function of annihilated Time-series
%%%%   using MATLAB fmincon function
%%%%  This accompanies the remltrend function of Staples et al

[rz cz]= size(z);

sig_1 = sigs(1);
sig_2 = sigs(2);

% construct Sigma, the cov matrix for z series 
Vhat = diag(sig_1*ones(rz+1,1)) + diag(sig_2*ones(rz,1),1) + diag(sig_2*ones(rz,1),-1);
SIGMA = U'*Vhat*U;

%   negative log likelihood function
f = .5*rz*log(2*pi) + .5*log(det(SIGMA)) + .5*z'*inv(SIGMA)*z;
Sculpin 0.2 | xhtml | problems or comments? | report bugs