Compile additional methods for accessing the model log-probability function and parameter constraining and unconstraining.
Source:R/fit.R
fit-method-init_model_methods.RdThe $init_model_methods() method compiles and initializes the
log_prob, grad_log_prob, hessian, constrain_variables,
unconstrain_variables and unconstrain_draws functions. These are then
available as methods of the fitted model object. This requires the
additional Rcpp package. The methods compile once per model
object, so later fits of the same model reuse them. To avoid compiling
them again in every new R session, set the rcpp.cache.dir option as
described for $expose_functions().
If a model or fit object was saved with base::saveRDS() and later
reloaded, any previously compiled model-method bindings will be rebuilt in
the current R session when this method is called. A reloaded fit also
needs the data the model was fit with. Data originally passed as a file
is found again as long as the file still exists. However, data passed as
a list was written to the temporary directory, so either call
$save_data_file() before saving the fit (to keep that file) or pass
the original data again via the data argument.
Note: there may be many compiler warnings emitted during compilation but these can be ignored so long as they are warnings and not errors.
Arguments
- data
(multiple options) A named list or the path to a JSON data file. Pass the data the fit was run with when a fit reloaded in a new R session has lost its data file, which happens when the data was originally passed as a list instead of a file. Other data with the same structure is accepted, so pass it only when you mean to evaluate the draws under other data.
$data_file()then returns the new path. A list is written to the temporary directory again, so call$save_data_file()before saving the fit if you'll reload it in another session.- seed
(integer) The random seed to use when initializing the model.
- verbose
(logical) Whether to show verbose logging during compilation.
- quiet
(logical) Should the message announcing the compilation be suppressed? The default is
FALSE. Compiler output is controlled byverbose.
Examples
# \dontrun{
fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE)
# fit_mcmc$init_model_methods()
# }