The $diagnose()
method of a CmdStanModel
object
runs Stan's basic diagnostic feature that will calculate the gradients
of the initial state and compare them with gradients calculated by
finite differences. Discrepancies between the two indicate that there is
a problem with the model or initial states or else there is a bug in Stan.
diagnose( data = NULL, seed = NULL, init = NULL, output_dir = NULL, output_basename = NULL, epsilon = NULL, error = NULL )
data | (multiple options) The data to use for the variables specified in the data block of the Stan program. One of the following:
|
---|---|
seed | (positive integer(s)) A seed for the (P)RNG to pass to CmdStan.
In the case of multi-chain sampling the single |
init | (multiple options) The initialization method to use for the variables declared in the parameters block of the Stan program. One of the following:
|
output_dir | (string) A path to a directory where CmdStan should write
its output CSV files. For interactive use this can typically be left at
|
output_basename | (string) A string to use as a prefix for the names of
the output CSV files of CmdStan. If |
epsilon | (positive real) The finite difference step size. Default value is 1e-6. |
error | (positive real) The error threshold. Default value is 1e-6. |
A CmdStanDiagnose
object.
The CmdStanR website (mc-stan.org/cmdstanr) for online documentation and tutorials.
The Stan and CmdStan documentation:
Stan documentation: mc-stan.org/users/documentation
CmdStan User’s Guide: mc-stan.org/docs/cmdstan-guide
Other CmdStanModel methods:
model-method-check_syntax
,
model-method-compile
,
model-method-format
,
model-method-generate-quantities
,
model-method-optimize
,
model-method-sample_mpi
,
model-method-sample
,
model-method-variables
,
model-method-variational
# \dontrun{ test <- cmdstanr_example("logistic", method = "diagnose") # retrieve the gradients test$gradients()#> param_idx value model finite_diff error #> 1 0 1.3362100 -9.33442 -9.33442 2.88445e-08 #> 2 1 1.7816500 -32.65590 -32.65590 -2.89809e-10 #> 3 2 -0.0718337 -2.56116 -2.56116 -2.13148e-08 #> 4 3 -1.9334500 29.16060 29.16060 -3.65847e-08# }