Optmum: index out of range

Hi. Any help will be greatly appreciated! I'm having trouble using the optmum procedure.

I'm calling the optmum procedure by:

 
{xout,fout,gout,cout} = optmum(&lik_fcn,prmtr_in);

i have defined a vector of starting values:

prmtr_in = 0.001|0.0001|0.0025|0.06|0.07|0.8|0.9|0.2|0.5;

The function that I want minimized is the "lik_fcn" where I have the procedure below. It has a vector of inputs and also returns a single output. However, I am getting an error:

Currently active call:

File optutil.src, line 153, in lik_fcn
vof = fnct(x0); /* Initial function value */
Traceback:
File optutil.src, line 153, in _optmum
vof = fnct(x0); /* Initial function value */
File optmum.src, line 264, in optmum
{ x,f0,g,retcode,Lopfhess,Lopitdta } = _optmum(fnct,x0,
proc lik_fcn(prmtr);

@local variables for procedure@
local beta_mat,F,beta_ll,P_ll,j_itr,beta_tl,p_tl,eta_tl,f_tl,beta_tt,
p_tt,kt,C,Q1,Q2,Q3,Q,R,sig2d,sig2u,sig2g,gm1,gm0,d0,d1,siggu,siggd,sigdu,rho,
kappa,A,B1,B2,M0,M0b,M1, M1a,M1b,M2,M2a,M2b,beta,lnl;

@Assign Parameter values @
sig2d=prmtr[1,1];
sig2u=prmtr[2,1];
sig2g=prmtr[3,1];
gm1=prmtr[4,1];
gm0=prmtr[5,1];
d0=prmtr[6,1];
d1=prmtr[7,1];
siggu=prmtr[8,1];
siggd=0; //by assumption
sigdu=prmtr[9,1];

rho=0.969;
kappa=0.1387; //backed out
A = kappa/(1-rho) + (gm0-d0)/(1-rho);
B1 = 1/(1-rho*d1);
B2 = 1/(1-rho*gm1);

Beta_ll={0,0,0,0}; //@initial guess for coefficients@ (b_0_0)
P_ll = {10 10 10 10,10 10 10 10,10 10 10 10,10 10 10 10}; //@Uncertainty associated with initial guess@ (p_0_0)
eta_tl=zeros(2,t);

@Transition Equations@
F={gm1 0 1 0, 0 0 0 0, 0 0 0 0, 0 0 0 0};
C={0 0 0, 1 0 0, 0 1 0, 0 0 1};
Q1=sig2d~siggu~siggd;
Q2=siggu~sig2g~sigdu;
Q3=siggd~sigdu~sig2u;
Q=Q1|Q2|Q3;

@Measurement Equations@
M0=gm0|(1-d1)*A;
M1a=0~0;
M1b=0~d1;
M1=M1a|M1b;
M2a=1~1~0~0;
M2b=B2*(gm1-d1)~0~B2~-B1;
M2=M2a|M2b;
R=0;

lnl=0;

j_itr=2;
do until j_itr>t;

Beta_tl = F*beta_ll; //conditional expectation of beta
P_tl = F*P_ll*F' + C*Q*C'; //conditional expectation of var-beta

eta_tl[1:2,J_itr]=ymat[1:2,J_itr]-M0-M1*ymat[1:2,J_itr-1]-M2*Beta_tl; //prediction error
f_tl=M2*P_tl*M2' + R; //variance of Yt

Kt=P_tl*M2'*inv(f_tl); //kalman gain

Beta_tt = Beta_tl + Kt* eta_tl[1:2,J_itr]; //updating for beta
P_tt = (eye(1) - Kt*M2)*P_tl; //updating for var beta

beta_ll = beta_tt; p_ll=p_tt; //set next periods values

if j_itr < start; goto skip; endif;

lnl = lnl - 0.5*ln(2*pi*f_tl) - 0.5* (eta_tl^2)/f_tl;

skip: J_itr = J_itr+1;
endo;

retp(-lnl);
endp;

2 Answers



0



The procedure computing the objective function must return a scalar value.   That is not the case with your function.  In this statement

lnl = lnl - 0.5*ln(2*pi*f_tl) - 0.5* (eta_tl^2)/f_tl;

f_tl and eta_tl are matrices.  Also, note that the slash operator is a linear solve with a leading dot.  I suspect you really want a "./" not a "/", but in any event lnl must be a scalar value.

 



0



Thanks a lot! I understand now. I need to call the procedure twice separately.

Your Answer

2 Answers

0

The procedure computing the objective function must return a scalar value.   That is not the case with your function.  In this statement

lnl = lnl - 0.5*ln(2*pi*f_tl) - 0.5* (eta_tl^2)/f_tl;

f_tl and eta_tl are matrices.  Also, note that the slash operator is a linear solve with a leading dot.  I suspect you really want a "./" not a "/", but in any event lnl must be a scalar value.

 

0

Thanks a lot! I understand now. I need to call the procedure twice separately.


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.