View Source ExStan.Model (ExStan v0.1.1)

Stores data associated with a Stan model and proxies calls to Stan services.

Returned by ExStan.build. Users will not instantiate this class directly.

Summary

Functions

Calculate the log probability of a set of unconstrained parameters.

Draws samples from the model using stan::services::sample::fixed_param.

Calculate the gradient of the log posterior evaluated at the unconstrained parameters.

Draws samples from the model using stan::services::sample::hmc_nuts_diag_e_adapt.

Calculate the log probability of a set of unconstrained parameters.

Draws samples from the model. For easy reference, documentation is copied from Pystan.

Reads constrained parameter values from their specified context and returns a sequence of unconstrained parameter values.

Functions

Link to this function

constrain_pars(model, unconstrained_parameters, include_tparams \\ true, include_gqs \\ true)

View Source

Calculate the log probability of a set of unconstrained parameters.

Arguments:

model: The model containing the data.
unconstrained_parameters: A sequence of unconstrained parameters.
include_tparams: Apply jacobian adjust transform for transformed parameters.
include_gqs: Apply jacobian adjust transform for generated quantities.

Returns:

The log probability of the unconstrained parameters.

Notes:

The unconstrained parameters are passed to the log_prob
function in stan::model.
Link to this function

fixed_param(model, opts \\ [])

View Source

Draws samples from the model using stan::services::sample::fixed_param.

Parameters in opts will be passed to stan::services::sample::fixed_param. Parameter names are identical to those used in CmdStan. See the CmdStan documentation for parameter descriptions and default values.

num_chains is an ExStan-specific argument indicating the number of independent processes to use when drawing samples.

Returns:

  • %ExStan.Fit{}: An instance of %ExStan.Fit{} allowing access to draws.
Link to this function

grad_log_prob(model, unconstrained_parameters)

View Source

Calculate the gradient of the log posterior evaluated at the unconstrained parameters.

Arguments:

model: The model containing the data.
unconstrained_parameters: A sequence of unconstrained parameters.

Returns:

The gradient of the log posterior evaluated at the unconstrained parameters.

Notes:

The unconstrained parameters are passed to the log_prob_grad
function in stan::model.
Link to this function

hmc_nuts_diag_e_adapt(model, opts)

View Source

Draws samples from the model using stan::services::sample::hmc_nuts_diag_e_adapt.

Parameters in opts will be passed to stan::services::sample::hmc_nuts_diag_e_adapt. Parameter names are identical to those used in CmdStan. See the CmdStan documentation for parameter descriptions and default values.

There is one exception: num_chains. num_chains is an ExStan-specific keyword argument. It indicates the number of independent processes to use when drawing samples.

Returns

  • %ExStan.Fit{}: An instance of %ExStan.Fit{} allowing access to draws.
Link to this function

log_prob(model, unconstrained_parameters, adjust_transform \\ true)

View Source

Calculate the log probability of a set of unconstrained parameters.

Arguments:

model: The model containing the data.
unconstrained_parameters: A sequence of unconstrained parameters.
adjust_transform: Apply jacobian adjust transform.

Returns:

The log probability of the unconstrained parameters.

Notes:

The unconstrained parameters are passed to the log_prob
function in stan::model.
Link to this function

sample(model, opts \\ [])

View Source

Draws samples from the model. For easy reference, documentation is copied from Pystan.

Parameters in params will be passed to the default sample function. The default sample function is currently stan::services::sample::hmc_nuts_diag_e_adapt. Parameter names are identical to those used in CmdStan. See the CmdStan documentation for parameter descriptions and default values.

The function also accepts all options supported by CmdStand. Specifically, num_chains indicates the number of independent processes to use when drawing samples.

Returns

  • Fit: instance of Fit allowing access to draws.

Examples

User-defined initial values for parameters must be provided for each chain. Typically they will be the same for each chain. The following example shows how user-defined initial parameters are provided:

program_code = "parameters {real y;} model {y ~ normal(0,1);}"
posterior = ExStan.build(program_code)
fit = ExStan.Model.sample(posterior, num_chains: 2, init: [{"y": 3}, {"y": 3}])
Link to this function

unconstrain_pars(model, constrained_parameters)

View Source

Reads constrained parameter values from their specified context and returns a sequence of unconstrained parameter values.

Arguments:

model: The model containing the data.
constrained_parameters: Constrained parameter values and their specified context

Returns:

A sequence of unconstrained parameters.

Notes:

The unconstrained parameters are passed to the `transform_inits` method of the
`model_base` instance. See `model_base.hpp` in the Stan C++ library for details.