template <class Type>
Type objective_function<Type>::operator()()
{
Type r = exp(logr);
Type theta = exp(logtheta);
Type K = exp(logK);
Type Q = exp(logQ);
Type S = exp(logS);
int timeSteps = Y.size();
Type nll = 0;
for (int i = 1; i < timeSteps; i++) {
Type m = X[i - 1] + r * (1.0 - pow(exp(X[i - 1]) / K, theta));
nll -=
dnorm(X[i], m, sqrt(Q),
true);
}
for (int i = 0; i < timeSteps; i++) {
nll -= keep(i) *
dpois(Y[i], S * exp(X[i]),
true);
}
return nll;
}
License: