template<class Type>
Type objective_function<Type>::operator() ()
{
Type tau = exp(log_tau);
Type kappa = exp(log_kappa);
Type omega = exp(log_omega);
Type nll = 0.0;
SparseMatrix<Type> Q =
Q_spde(spde,kappa);
vector<Type> Xbeta = X*beta;
for(int i=0; i<time.size(); i++){
Type eta = Xbeta(i) + x(meshidxloc(i))/tau;
Type lambda = exp(eta);
Type t_omega = pow(time(i),omega);
Type S = exp(-lambda*t_omega);
Type f = lambda*omega*t_omega/time(i)*S;
if(notcens(i))
nll -= log(f);
else
nll -= log(S);
}
double nu = 1.0;
Type rho = sqrt(8*nu)/kappa;
if (epsilon.size() > 0) {
Type S = x.exp().sum();
Type logS = log(S);
nll += epsilon[0] * logS;
}
return nll;
}
License: