template<class Type>
Type objective_function<Type>::operator() ()
{
Type sigma = exp(logsigma);
for(int s=1;s<tmpk.size();s++)
alpha(s) = alpha(s-1) + exp(tmpk(s));
Type ans=0;
ans -=
sum(
dnorm(u,Type(0),Type(1),
true));
for(int i=0; i<y.size(); i++){
eta(i) += sigma*u(group(i));
Type P;
if(y(i)==(S-1)) P = 1.0; else P = Type(1)/(Type(1)+exp(-(alpha(y(i))-eta(i))));
if(y(i)>0) P -= Type(1)/(Type(1)+exp(-(alpha(y(i)-1)-eta(i))));
ans -= log(1.e-20+P);
}
return ans;
}
License: