template <class Type>
Type f(Type x){return Type(2)/(Type(1) + exp(-Type(2) * x)) - Type(1);}
template<class Type>
Type objective_function<Type>::operator() ()
{
int timeSteps=obs.dim[1];
int stateDim=obs.dim[0];
Type rho=f(transf_rho);
for(int i=0;i<stateDim;i++)
for(int j=0;j<stateDim;j++)
cov(i,j)=pow(rho,Type(abs(i-j)))*sds[i]*sds[j];
Type ans=0;
for(int i=1;i<timeSteps;i++)
ans += neg_log_density(u.col(i)-u.col(i-1));
for(int i=0; i<timeSteps; i++)
ans -=
dnorm(obs.col(i).vec(), u.col(i).vec(), sdObs,
true).
sum();
return ans;
}
License: