Evaluate a julia model's likelihood and gradient at given parameters
Source:R/ctJuliaBackend.R
ctJuliaEvaluate.RdEvaluates the objective the julia backend optimises – the log likelihood,
with the random effects integrated as the model's intoverpop route
integrates them – at a vector of raw (unconstrained) parameters, and its
gradient. For checking a fit, profiling by hand, or handing ctsem's
likelihood to an optimiser or sampler of your own.
Arguments
- object
A fit from
ctFit(..., backend = 'julia'), or a model prepared without fitting byctFit(..., backend = 'julia', fit = FALSE)(classctJuliaModel).- pars
Raw (unconstrained) parameters, in the order of
coef(fit); defaults to a fit's estimate, and must be given for a prepared model.- gradient
Also return the gradient with respect to
pars.- contributions
Return subject and row contribution details when available.
- gradient_method
Either "adjoint" (reverse mode, the default) or "forward" (ForwardDiff). Both compute the same gradient. "adjoint" costs the same regardless of how many free parameters a model has, and is faster than "forward" at every model size measured, by a margin that grows with the parameter count. See
optimcontrol$gradientinctFit.- cores
The most engine threads this evaluation uses, restored afterwards.
NAleaves the ceiling already in force, for a caller that has set one around a run of evaluations.
Examples
# \donttest{
# Needs a working julia backend, so the example is inert where Julia is
# absent -- including on CRAN, whose check machines have none.
if (isTRUE(ctJuliaStatus()$available)) {
model <- ctModel(type = 'ct', manifestNames = 'Y1', latentNames = 'eta1',
LAMBDA = matrix(1))
model$pars$indvarying <- FALSE
prepared <- ctFit(ctstantestdat, model, backend = 'julia', fit = FALSE)
start <- ctJuliaEvaluate(prepared, pars = rep(0, 6), cores = 1)
str(start)
# Julia keeps running between calls, holding what it has compiled;
# this ends it.
ctJuliaKill("session")
}
# }