Skip to content

Commit

Permalink
fix text failures due to hessian
Browse files Browse the repository at this point in the history
  • Loading branch information
jgabry committed Feb 14, 2025
1 parent 05c6f60 commit a1f88a0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- `model_params` element of `fit$metadata()` list (`variables` element)
- `jacobian_adjustment` argument to `fit$log_prob()` and similar methods (`jacobian` argument)
- `output_samples` argument to `model$variational()` (`draws` argument)
- `hessian` argument to `fit$init_model_methods()` (`hessian` method always compiled now)
- several arguments to `model$compile()`:
- `threads` (`cpp_options = list(stan_threads = TRUE)`)
- `compile_hessian_method` (always compiled)
Expand Down
26 changes: 12 additions & 14 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -314,28 +314,31 @@ CmdStanFit$set("public", name = "init", value = init)
#' @aliases init_model_methods
#'
#' @description The `$init_model_methods()` method compiles and initializes the
#' `log_prob`, `grad_log_prob`, `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,
#' which are not required for fitting models using
#' `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, which are not required for fitting models using
#' CmdStanR.
#'
#' Note: there may be many compiler warnings emitted during compilation but
#' Notes:
#' * There may be many compiler warnings emitted during compilation but
#' these can be ignored so long as they are warnings and not errors.
#' * The hessian method relies on higher-order autodiff, which is still
#' experimental. Please report any compilation errors that you encounter.
#'
#' @param seed (integer) The random seed to use when initializing the model.
#' @param verbose (logical) Whether to show verbose logging during compilation.
#' @param hessian (logical) Whether to expose the (experimental) hessian method.
#'
#' @examples
#' \dontrun{
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE)
#' # fit_mcmc$init_model_methods()
#' }
#' @seealso [log_prob()], [grad_log_prob()], [constrain_variables()],
#' [unconstrain_variables()], [unconstrain_draws()], [variable_skeleton()],
#' [hessian()]
#'
init_model_methods <- function(seed = 1, verbose = FALSE, hessian = FALSE) {
init_model_methods <- function(seed = 1, verbose = FALSE) {
if (os_is_wsl()) {
stop("Additional model methods are not currently available with ",
"WSL CmdStan and will not be compiled",
Expand All @@ -346,13 +349,8 @@ init_model_methods <- function(seed = 1, verbose = FALSE, hessian = FALSE) {
stop("Model methods cannot be used with a pre-compiled Stan executable, ",
"the model must be compiled again", call. = FALSE)
}
if (hessian) {
message("The hessian method relies on higher-order autodiff ",
"which is still experimental. Please report any compilation ",
"errors that you encounter")
}
if (is.null(private$model_methods_env_$model_ptr)) {
expose_model_methods(private$model_methods_env_, verbose, hessian)
expose_model_methods(private$model_methods_env_, verbose)
}
if (!("model_ptr_" %in% ls(private$model_methods_env_))) {
initialize_model_pointer(private$model_methods_env_, self$data_file(), seed)
Expand Down Expand Up @@ -435,7 +433,7 @@ CmdStanFit$set("public", name = "grad_log_prob", value = grad_log_prob)
#' @examples
#' \dontrun{
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE)
#' # fit_mcmc$init_model_methods(hessian = TRUE)
#' # fit_mcmc$init_model_methods()
#' # fit_mcmc$hessian(unconstrained_variables = c(0.5, 1.2, 1.1, 2.2))
#' }
#'
Expand Down
2 changes: 1 addition & 1 deletion man/fit-method-hessian.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions man/fit-method-init_model_methods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a1f88a0

Please sign in to comment.