Skip to contents

Evaluates 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.

Usage

ctJuliaEvaluate(
  object,
  pars = NULL,
  gradient = TRUE,
  contributions = FALSE,
  gradient_method = c("adjoint", "forward"),
  cores = getOption("mc.cores", 2L)
)

Arguments

object

A fit from ctFit(..., backend = 'julia'), or a model prepared without fitting by ctFit(..., backend = 'julia', fit = FALSE) (class ctJuliaModel).

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$gradient in ctFit.

cores

The most engine threads this evaluation uses, restored afterwards. NA leaves the ceiling already in force, for a caller that has set one around a run of evaluations.

Value

A list containing the log likelihood and, when requested, the gradient and the contributions.

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")
}
# }