Construct a Stan model
stan_model.RdConstruct an instance of S4 class stanmodel from a model
specified in Stan's modeling language. A stanmodel object
can then be used to draw samples from the model. The Stan program
(the model expressed in the Stan modeling language) is first translated to
C++ code and then the C++ code for the model plus other auxiliary
code is compiled into a dynamic shared object (DSO) and then loaded.
The loaded DSO for the model can be executed to draw samples, allowing
inference to be performed for the model and data.
Usage
stan_model(
file, model_name = "anon_model",
model_code = "", stanc_ret = NULL,
boost_lib = NULL, eigen_lib = NULL,
save_dso = TRUE, verbose = FALSE,
auto_write = rstan_options("auto_write"),
obfuscate_model_name = TRUE,
allow_undefined = isTRUE(getOption("stanc.allow_undefined", FALSE)),
allow_optimizations = isTRUE(getOption("stanc.allow_optimizations", FALSE)),
standalone_functions = isTRUE(getOption("stanc.standalone_functions", FALSE)),
use_opencl = isTRUE(getOption("stanc.use_opencl", FALSE)),
warn_pedantic = isTRUE(getOption("stanc.warn_pedantic", FALSE)),
warn_uninitialized = isTRUE(getOption("stanc.warn_uninitialized", FALSE)),
includes = NULL,
isystem = c(if (!missing(file)) dirname(file), getwd()))Arguments
- file
A character string or a connection that R supports specifying the Stan model specification in Stan's modeling language.
- model_name
A character string naming the model; defaults to
"anon_model". However, the model name will be derived fromfileormodel_code(ifmodel_codeis the name of a character string object) ifmodel_nameis not specified.- model_code
Either a character string containing the model specification or the name of a character string object in the workspace. This is an alternative to specifying the model via the
fileorstanc_retarguments.- stanc_ret
A named list returned from a previous call to the
stancfunction. The list can be used to specify the model instead of using thefileormodel_codearguments.- boost_lib
The path to a version of the Boost C++ library to use instead of the one in the BH package.
- eigen_lib
The path to a version of the Eigen C++ library to use instead of the one in the RcppEigen package.
- save_dso
Logical, defaulting to
TRUE, indicating whether the dynamic shared object (DSO) compiled from the C++ code for the model will be saved or not. IfTRUE, we can draw samples from the same model in another R session using the saved DSO (i.e., without compiling the C++ code again).- verbose
Logical, defaulting to
FALSE, indicating whether to report additional intermediate output to the console, which might be helpful for debugging.- auto_write
Logical, defaulting to the value of
rstan_options("auto_write"), indicating whether to write the object to the hard disk usingsaveRDS. Although this argument isFALSEby default, we recommend callingrstan_options("auto_write" = TRUE)in order to avoid unnecessary recompilations. Iffileis supplied and itsdirnameis writable, then the object will be written to that same directory, substituting a.rdsextension for the.stanextension. Otherwise, the object will be written to thetempdir.- obfuscate_model_name
A logical scalar that is
TRUEby default and passed tostanc.- allow_undefined
A logical scalar that is
FALSEby default and passed tostanc.- allow_optimizations
A logical scalar that is
FALSEby default and passed tostanc.- standalone_functions
A logical scalar that is
FALSEby default and passed tostanc.- use_opencl
A logical scalar that is
FALSEby default and passed tostanc.- warn_pedantic
A logical scalar that is
FALSEby default and passed tostanc.- warn_uninitialized
A logical scalar that is
FALSEby default and passed tostanc.- includes
If not
NULL(the default), then a character vector of length one (possibly containing one or more"\n") of the form'#include "/full/path/to/my_header.hpp"', which will be inserted into the C++ code in the model's namespace and can be used to provide definitions of functions that are declared but not defined infileormodel_codewhenallow_undefined = TRUE- isystem
A character vector naming a path to look for file paths in
filethat are to be included within the Stan program named byfile. See the Details section below.
Details
If a previously compiled stanmodel exists on the hard drive, its validity
is checked and then returned without recompiling. The most common form of
invalidity seems to be Stan code that ends with a } rather than a blank
line, which causes the hash checker to think that the current model is different
than the one saved on the hard drive. To avoid reading previously
compiled stanmodels from the hard drive, supply the stanc_ret
argument rather than the file or model_code arguments.
There are three ways to specify the model's code for stan_model:
parameter
model_code: a character string containing the Stan model specification,parameter
file: a file name (or a connection) from which to read the Stan model specification, orparameter
stanc_ret: a list returned bystancto be reused.
Value
An instance of S4 class stanmodel that can be
passed to the sampling, optimizing, and
vb functions.
References
The Stan Development Team Stan Modeling Language User's Guide and Reference Manual. https://mc-stan.org/.
See also
stanmodel for details on the class.
sampling, optimizing, and vb,
which take a stanmodel object as input, for estimating the model
parameters.
More details on Stan, including the full user's guide and reference manual, can be found at https://mc-stan.org/.
Examples
# \dontrun{
stancode <- 'data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}'
mod <- stan_model(model_code = stancode, verbose = TRUE)
#>
#> TRANSLATING MODEL '' FROM Stan CODE TO C++ CODE NOW.
#> OS: x86_64, linux-gnu; rstan: 2.32.7; Rcpp: 1.1.0; inline: 0.3.21
#> >> setting environment variables:
#> PKG_LIBS = '/home/runner/work/_temp/Library/rstan/lib//libStanServices.a' -L'/home/runner/work/_temp/Library/StanHeaders/lib/' -lStanHeaders -L'/home/runner/work/_temp/Library/RcppParallel/lib/' -ltbb
#> PKG_CPPFLAGS = -I"/home/runner/work/_temp/Library/Rcpp/include/" -I"/home/runner/work/_temp/Library/RcppEigen/include/" -I"/home/runner/work/_temp/Library/RcppEigen/include/unsupported" -I"/home/runner/work/_temp/Library/BH/include" -I"/home/runner/work/_temp/Library/StanHeaders/include/src/" -I"/home/runner/work/_temp/Library/StanHeaders/include/" -I"/home/runner/work/_temp/Library/RcppParallel/include/" -I"/home/runner/work/_temp/Library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0 -include '/home/runner/work/_temp/Library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1
#> >> Program source :
#>
#> 1 :
#> 2 : // includes from the plugin
#> 3 : // [[Rcpp::plugins(cpp17)]]
#> 4 :
#> 5 :
#> 6 : // user includes
#> 7 : #include <Rcpp.h>
#> 8 : using namespace Rcpp;
#> 9 : #ifndef MODELS_HPP
#> 10 : #define MODELS_HPP
#> 11 : #define STAN__SERVICES__COMMAND_HPP
#> 12 : #include <rstan/rstaninc.hpp>
#> 13 : #ifndef USE_STANC3
#> 14 : #define USE_STANC3
#> 15 : #endif
#> 16 : // Code generated by stanc v2.37.0-172-g8d78669
#> 17 : #include <stan/model/model_header.hpp>
#> 18 : namespace model1c005434557a__namespace {
#> 19 : using stan::model::model_base_crtp;
#> 20 : using namespace stan::math;
#> 21 : stan::math::profile_map profiles__;
#> 22 : static constexpr std::array<const char*, 4> locations_array__ =
#> 23 : {" (found before start of program)",
#> 24 : " (in 'anon_model', line 1, column 32 to column 39)",
#> 25 : " (in 'anon_model', line 1, column 48 to column 69)",
#> 26 : " (in 'anon_model', line 1, column 6 to column 18)"};
#> 27 : class model1c005434557a_ final : public model_base_crtp<model1c005434557a_> {
#> 28 : private:
#> 29 : double y_mean;
#> 30 : public:
#> 31 : ~model1c005434557a_() {}
#> 32 : model1c005434557a_(stan::io::var_context& context__, unsigned int
#> 33 : random_seed__ = 0, std::ostream* pstream__ = nullptr)
#> 34 : : model_base_crtp(0) {
#> 35 : int current_statement__ = 0;
#> 36 : // suppress unused var warning
#> 37 : (void) current_statement__;
#> 38 : using local_scalar_t__ = double;
#> 39 : auto base_rng__ = stan::services::util::create_rng(random_seed__, 0);
#> 40 : // suppress unused var warning
#> 41 : (void) base_rng__;
#> 42 : static constexpr const char* function__ =
#> 43 : "model1c005434557a__namespace::model1c005434557a_";
#> 44 : // suppress unused var warning
#> 45 : (void) function__;
#> 46 : local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
#> 47 : // suppress unused var warning
#> 48 : (void) DUMMY_VAR__;
#> 49 : try {
#> 50 : current_statement__ = 3;
#> 51 : context__.validate_dims("data initialization", "y_mean", "double",
#> 52 : std::vector<size_t>{});
#> 53 : y_mean = std::numeric_limits<double>::quiet_NaN();
#> 54 : current_statement__ = 3;
#> 55 : y_mean = context__.vals_r("y_mean")[(1 - 1)];
#> 56 : } catch (const std::exception& e) {
#> 57 : stan::lang::rethrow_located(e, locations_array__[current_statement__]);
#> 58 : }
#> 59 : num_params_r__ = 1;
#> 60 : }
#> 61 : inline std::string model_name() const final {
#> 62 : return "model1c005434557a_";
#> 63 : }
#> 64 : inline std::vector<std::string> model_compile_info() const noexcept {
#> 65 : return std::vector<std::string>{"stanc_version = stanc3 v2.37.0-172-g8d78669",
#> 66 : "stancflags = --"};
#> 67 : }
#> 68 : // Base log prob
#> 69 : template <bool propto__, bool jacobian__, typename VecR, typename VecI,
#> 70 : stan::require_vector_like_t<VecR>* = nullptr,
#> 71 : stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr,
#> 72 : stan::require_not_st_var<VecR>* = nullptr>
#> 73 : inline stan::scalar_type_t<VecR>
#> 74 : log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream*
#> 75 : pstream__ = nullptr) const {
#> 76 : using T__ = stan::scalar_type_t<VecR>;
#> 77 : using local_scalar_t__ = T__;
#> 78 : T__ lp__(0.0);
#> 79 : stan::math::accumulator<T__> lp_accum__;
#> 80 : stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
#> 81 : int current_statement__ = 0;
#> 82 : // suppress unused var warning
#> 83 : (void) current_statement__;
#> 84 : local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
#> 85 : // suppress unused var warning
#> 86 : (void) DUMMY_VAR__;
#> 87 : static constexpr const char* function__ =
#> 88 : "model1c005434557a__namespace::log_prob";
#> 89 : // suppress unused var warning
#> 90 : (void) function__;
#> 91 : try {
#> 92 : current_statement__ = 1;
#> 93 : auto y = in__.template read<local_scalar_t__>();
#> 94 : {
#> 95 : current_statement__ = 2;
#> 96 : lp_accum__.add(stan::math::normal_lpdf<propto__>(y, y_mean, 1));
#> 97 : }
#> 98 : } catch (const std::exception& e) {
#> 99 : stan::lang::rethrow_located(e, locations_array__[current_statement__]);
#> 100 : }
#> 101 : lp_accum__.add(lp__);
#> 102 : return lp_accum__.sum();
#> 103 : }
#> 104 : // Reverse mode autodiff log prob
#> 105 : template <bool propto__, bool jacobian__, typename VecR, typename VecI,
#> 106 : stan::require_vector_like_t<VecR>* = nullptr,
#> 107 : stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr,
#> 108 : stan::require_st_var<VecR>* = nullptr>
#> 109 : inline stan::scalar_type_t<VecR>
#> 110 : log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream*
#> 111 : pstream__ = nullptr) const {
#> 112 : using T__ = stan::scalar_type_t<VecR>;
#> 113 : using local_scalar_t__ = T__;
#> 114 : T__ lp__(0.0);
#> 115 : stan::math::accumulator<T__> lp_accum__;
#> 116 : stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
#> 117 : int current_statement__ = 0;
#> 118 : // suppress unused var warning
#> 119 : (void) current_statement__;
#> 120 : local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
#> 121 : // suppress unused var warning
#> 122 : (void) DUMMY_VAR__;
#> 123 : static constexpr const char* function__ =
#> 124 : "model1c005434557a__namespace::log_prob";
#> 125 : // suppress unused var warning
#> 126 : (void) function__;
#> 127 : try {
#> 128 : current_statement__ = 1;
#> 129 : auto y = in__.template read<local_scalar_t__>();
#> 130 : {
#> 131 : current_statement__ = 2;
#> 132 : lp_accum__.add(stan::math::normal_lpdf<propto__>(y, y_mean, 1));
#> 133 : }
#> 134 : } catch (const std::exception& e) {
#> 135 : stan::lang::rethrow_located(e, locations_array__[current_statement__]);
#> 136 : }
#> 137 : lp_accum__.add(lp__);
#> 138 : return lp_accum__.sum();
#> 139 : }
#> 140 : template <typename RNG, typename VecR, typename VecI, typename VecVar,
#> 141 : stan::require_vector_like_vt<std::is_floating_point,
#> 142 : VecR>* = nullptr, stan::require_vector_like_vt<std::is_integral,
#> 143 : VecI>* = nullptr, stan::require_vector_vt<std::is_floating_point,
#> 144 : VecVar>* = nullptr>
#> 145 : inline void
#> 146 : write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__,
#> 147 : VecVar& vars__, const bool
#> 148 : emit_transformed_parameters__ = true, const bool
#> 149 : emit_generated_quantities__ = true, std::ostream*
#> 150 : pstream__ = nullptr) const {
#> 151 : using local_scalar_t__ = double;
#> 152 : stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
#> 153 : stan::io::serializer<local_scalar_t__> out__(vars__);
#> 154 : static constexpr bool propto__ = true;
#> 155 : // suppress unused var warning
#> 156 : (void) propto__;
#> 157 : double lp__ = 0.0;
#> 158 : // suppress unused var warning
#> 159 : (void) lp__;
#> 160 : int current_statement__ = 0;
#> 161 : // suppress unused var warning
#> 162 : (void) current_statement__;
#> 163 : stan::math::accumulator<double> lp_accum__;
#> 164 : local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
#> 165 : // suppress unused var warning
#> 166 : (void) DUMMY_VAR__;
#> 167 : constexpr bool jacobian__ = false;
#> 168 : // suppress unused var warning
#> 169 : (void) jacobian__;
#> 170 : static constexpr const char* function__ =
#> 171 : "model1c005434557a__namespace::write_array";
#> 172 : // suppress unused var warning
#> 173 : (void) function__;
#> 174 : try {
#> 175 : current_statement__ = 1;
#> 176 : auto y = in__.template read<local_scalar_t__>();
#> 177 : out__.write(y);
#> 178 : if (stan::math::logical_negation(
#> 179 : (stan::math::primitive_value(emit_transformed_parameters__) ||
#> 180 : stan::math::primitive_value(emit_generated_quantities__)))) {
#> 181 : return ;
#> 182 : }
#> 183 : if (stan::math::logical_negation(emit_generated_quantities__)) {
#> 184 : return ;
#> 185 : }
#> 186 : } catch (const std::exception& e) {
#> 187 : stan::lang::rethrow_located(e, locations_array__[current_statement__]);
#> 188 : }
#> 189 : }
#> 190 : template <typename VecVar, typename VecI,
#> 191 : stan::require_vector_t<VecVar>* = nullptr,
#> 192 : stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
#> 193 : inline void
#> 194 : unconstrain_array_impl(const VecVar& params_r__, const VecI& params_i__,
#> 195 : VecVar& vars__, std::ostream* pstream__ = nullptr) const {
#> 196 : using local_scalar_t__ = double;
#> 197 : stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
#> 198 : stan::io::serializer<local_scalar_t__> out__(vars__);
#> 199 : int current_statement__ = 0;
#> 200 : // suppress unused var warning
#> 201 : (void) current_statement__;
#> 202 : local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
#> 203 : // suppress unused var warning
#> 204 : (void) DUMMY_VAR__;
#> 205 : try {
#> 206 : local_scalar_t__ y = DUMMY_VAR__;
#> 207 : current_statement__ = 1;
#> 208 : y = in__.read<local_scalar_t__>();
#> 209 : out__.write(y);
#> 210 : } catch (const std::exception& e) {
#> 211 : stan::lang::rethrow_located(e, locations_array__[current_statement__]);
#> 212 : }
#> 213 : }
#> 214 : template <typename VecVar, stan::require_vector_t<VecVar>* = nullptr>
#> 215 : inline void
#> 216 : transform_inits_impl(const stan::io::var_context& context__, VecVar&
#> 217 : vars__, std::ostream* pstream__ = nullptr) const {
#> 218 : using local_scalar_t__ = double;
#> 219 : stan::io::serializer<local_scalar_t__> out__(vars__);
#> 220 : int current_statement__ = 0;
#> 221 : // suppress unused var warning
#> 222 : (void) current_statement__;
#> 223 : local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
#> 224 : // suppress unused var warning
#> 225 : (void) DUMMY_VAR__;
#> 226 : try {
#> 227 : current_statement__ = 1;
#> 228 : context__.validate_dims("parameter initialization", "y", "double",
#> 229 : std::vector<size_t>{});
#> 230 : local_scalar_t__ y = DUMMY_VAR__;
#> 231 : current_statement__ = 1;
#> 232 : y = context__.vals_r("y")[(1 - 1)];
#> 233 : out__.write(y);
#> 234 : } catch (const std::exception& e) {
#> 235 : stan::lang::rethrow_located(e, locations_array__[current_statement__]);
#> 236 : }
#> 237 : }
#> 238 : inline void
#> 239 : get_param_names(std::vector<std::string>& names__, const bool
#> 240 : emit_transformed_parameters__ = true, const bool
#> 241 : emit_generated_quantities__ = true) const {
#> 242 : names__ = std::vector<std::string>{"y"};
#> 243 : if (emit_transformed_parameters__) {}
#> 244 : if (emit_generated_quantities__) {}
#> 245 : }
#> 246 : inline void
#> 247 : get_dims(std::vector<std::vector<size_t>>& dimss__, const bool
#> 248 : emit_transformed_parameters__ = true, const bool
#> 249 : emit_generated_quantities__ = true) const {
#> 250 : dimss__ = std::vector<std::vector<size_t>>{std::vector<size_t>{}};
#> 251 : if (emit_transformed_parameters__) {}
#> 252 : if (emit_generated_quantities__) {}
#> 253 : }
#> 254 : inline void
#> 255 : constrained_param_names(std::vector<std::string>& param_names__, bool
#> 256 : emit_transformed_parameters__ = true, bool
#> 257 : emit_generated_quantities__ = true) const final {
#> 258 : param_names__.emplace_back(std::string() + "y");
#> 259 : if (emit_transformed_parameters__) {}
#> 260 : if (emit_generated_quantities__) {}
#> 261 : }
#> 262 : inline void
#> 263 : unconstrained_param_names(std::vector<std::string>& param_names__, bool
#> 264 : emit_transformed_parameters__ = true, bool
#> 265 : emit_generated_quantities__ = true) const final {
#> 266 : param_names__.emplace_back(std::string() + "y");
#> 267 : if (emit_transformed_parameters__) {}
#> 268 : if (emit_generated_quantities__) {}
#> 269 : }
#> 270 : inline std::string get_constrained_sizedtypes() const {
#> 271 : return std::string("[{\"name\":\"y\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"}]");
#> 272 : }
#> 273 : inline std::string get_unconstrained_sizedtypes() const {
#> 274 : return std::string("[{\"name\":\"y\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"}]");
#> 275 : }
#> 276 : // Begin method overload boilerplate
#> 277 : template <typename RNG> inline void
#> 278 : write_array(RNG& base_rng, Eigen::Matrix<double,-1,1>& params_r,
#> 279 : Eigen::Matrix<double,-1,1>& vars, const bool
#> 280 : emit_transformed_parameters = true, const bool
#> 281 : emit_generated_quantities = true, std::ostream*
#> 282 : pstream = nullptr) const {
#> 283 : const size_t num_params__ = 1;
#> 284 : const size_t num_transformed = emit_transformed_parameters * (0U);
#> 285 : const size_t num_gen_quantities = emit_generated_quantities * (0U);
#> 286 : const size_t num_to_write = num_params__ + num_transformed +
#> 287 : num_gen_quantities;
#> 288 : std::vector<int> params_i;
#> 289 : vars = Eigen::Matrix<double,-1,1>::Constant(num_to_write,
#> 290 : std::numeric_limits<double>::quiet_NaN());
#> 291 : write_array_impl(base_rng, params_r, params_i, vars,
#> 292 : emit_transformed_parameters, emit_generated_quantities, pstream);
#> 293 : }
#> 294 : template <typename RNG> inline void
#> 295 : write_array(RNG& base_rng, std::vector<double>& params_r, std::vector<int>&
#> 296 : params_i, std::vector<double>& vars, bool
#> 297 : emit_transformed_parameters = true, bool
#> 298 : emit_generated_quantities = true, std::ostream*
#> 299 : pstream = nullptr) const {
#> 300 : const size_t num_params__ = 1;
#> 301 : const size_t num_transformed = emit_transformed_parameters * (0U);
#> 302 : const size_t num_gen_quantities = emit_generated_quantities * (0U);
#> 303 : const size_t num_to_write = num_params__ + num_transformed +
#> 304 : num_gen_quantities;
#> 305 : vars = std::vector<double>(num_to_write,
#> 306 : std::numeric_limits<double>::quiet_NaN());
#> 307 : write_array_impl(base_rng, params_r, params_i, vars,
#> 308 : emit_transformed_parameters, emit_generated_quantities, pstream);
#> 309 : }
#> 310 : template <bool propto__, bool jacobian__, typename T_> inline T_
#> 311 : log_prob(Eigen::Matrix<T_,-1,1>& params_r, std::ostream* pstream = nullptr) const {
#> 312 : Eigen::Matrix<int,-1,1> params_i;
#> 313 : return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
#> 314 : }
#> 315 : template <bool propto__, bool jacobian__, typename T_> inline T_
#> 316 : log_prob(std::vector<T_>& params_r, std::vector<int>& params_i,
#> 317 : std::ostream* pstream = nullptr) const {
#> 318 : return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
#> 319 : }
#> 320 : inline void
#> 321 : transform_inits(const stan::io::var_context& context,
#> 322 : Eigen::Matrix<double,-1,1>& params_r, std::ostream*
#> 323 : pstream = nullptr) const final {
#> 324 : std::vector<double> params_r_vec(params_r.size());
#> 325 : std::vector<int> params_i;
#> 326 : transform_inits(context, params_i, params_r_vec, pstream);
#> 327 : params_r = Eigen::Map<Eigen::Matrix<double,-1,1>>(params_r_vec.data(),
#> 328 : params_r_vec.size());
#> 329 : }
#> 330 : inline void
#> 331 : transform_inits(const stan::io::var_context& context, std::vector<int>&
#> 332 : params_i, std::vector<double>& vars, std::ostream*
#> 333 : pstream__ = nullptr) const {
#> 334 : vars.resize(num_params_r__);
#> 335 : transform_inits_impl(context, vars, pstream__);
#> 336 : }
#> 337 : inline void
#> 338 : unconstrain_array(const std::vector<double>& params_constrained,
#> 339 : std::vector<double>& params_unconstrained, std::ostream*
#> 340 : pstream = nullptr) const {
#> 341 : const std::vector<int> params_i;
#> 342 : params_unconstrained = std::vector<double>(num_params_r__,
#> 343 : std::numeric_limits<double>::quiet_NaN());
#> 344 : unconstrain_array_impl(params_constrained, params_i,
#> 345 : params_unconstrained, pstream);
#> 346 : }
#> 347 : inline void
#> 348 : unconstrain_array(const Eigen::Matrix<double,-1,1>& params_constrained,
#> 349 : Eigen::Matrix<double,-1,1>& params_unconstrained,
#> 350 : std::ostream* pstream = nullptr) const {
#> 351 : const std::vector<int> params_i;
#> 352 : params_unconstrained = Eigen::Matrix<double,-1,1>::Constant(num_params_r__,
#> 353 : std::numeric_limits<double>::quiet_NaN());
#> 354 : unconstrain_array_impl(params_constrained, params_i,
#> 355 : params_unconstrained, pstream);
#> 356 : }
#> 357 : };
#> 358 : }
#> 359 : using stan_model = model1c005434557a__namespace::model1c005434557a_;
#> 360 : #ifndef USING_R
#> 361 : // Boilerplate
#> 362 : stan::model::model_base&
#> 363 : new_model(stan::io::var_context& data_context, unsigned int seed,
#> 364 : std::ostream* msg_stream) {
#> 365 : stan_model* m = new stan_model(data_context, seed, msg_stream);
#> 366 : return *m;
#> 367 : }
#> 368 : stan::math::profile_map& get_stan_profile_data() {
#> 369 : return model1c005434557a__namespace::profiles__;
#> 370 : }
#> 371 : #endif
#> 372 : #endif
#> 373 :
#> 374 : RCPP_MODULE(stan_fit4model1c005434557a__mod) {
#> 375 : class_<rstan::stan_fit<stan_model, boost::random::mixmax> >(
#> 376 : "stan_fit4model1c005434557a_")
#> 377 :
#> 378 : .constructor<SEXP, SEXP, SEXP>()
#> 379 :
#> 380 : .method(
#> 381 : "call_sampler",
#> 382 : &rstan::stan_fit<stan_model, boost::random::mixmax>::call_sampler)
#> 383 : .method(
#> 384 : "param_names",
#> 385 : &rstan::stan_fit<stan_model, boost::random::mixmax>::param_names)
#> 386 : .method("param_names_oi",
#> 387 : &rstan::stan_fit<stan_model,
#> 388 : boost::random::mixmax>::param_names_oi)
#> 389 : .method("param_fnames_oi",
#> 390 : &rstan::stan_fit<stan_model,
#> 391 : boost::random::mixmax>::param_fnames_oi)
#> 392 : .method(
#> 393 : "param_dims",
#> 394 : &rstan::stan_fit<stan_model, boost::random::mixmax>::param_dims)
#> 395 : .method("param_dims_oi",
#> 396 : &rstan::stan_fit<stan_model,
#> 397 : boost::random::mixmax>::param_dims_oi)
#> 398 : .method("update_param_oi",
#> 399 : &rstan::stan_fit<stan_model,
#> 400 : boost::random::mixmax>::update_param_oi)
#> 401 : .method("param_oi_tidx",
#> 402 : &rstan::stan_fit<stan_model,
#> 403 : boost::random::mixmax>::param_oi_tidx)
#> 404 : .method("grad_log_prob",
#> 405 : &rstan::stan_fit<stan_model,
#> 406 : boost::random::mixmax>::grad_log_prob)
#> 407 : .method("log_prob",
#> 408 : &rstan::stan_fit<stan_model, boost::random::mixmax>::log_prob)
#> 409 : .method("unconstrain_pars",
#> 410 : &rstan::stan_fit<stan_model,
#> 411 : boost::random::mixmax>::unconstrain_pars)
#> 412 : .method("constrain_pars",
#> 413 : &rstan::stan_fit<stan_model,
#> 414 : boost::random::mixmax>::constrain_pars)
#> 415 : .method(
#> 416 : "num_pars_unconstrained",
#> 417 : &rstan::stan_fit<stan_model,
#> 418 : boost::random::mixmax>::num_pars_unconstrained)
#> 419 : .method(
#> 420 : "unconstrained_param_names",
#> 421 : &rstan::stan_fit<
#> 422 : stan_model, boost::random::mixmax>::unconstrained_param_names)
#> 423 : .method(
#> 424 : "constrained_param_names",
#> 425 : &rstan::stan_fit<stan_model,
#> 426 : boost::random::mixmax>::constrained_param_names)
#> 427 : .method("standalone_gqs",
#> 428 : &rstan::stan_fit<stan_model,
#> 429 : boost::random::mixmax>::standalone_gqs);
#> 430 : }
#> 431 :
#> 432 :
#> 433 : // declarations
#> 434 : extern "C" {
#> 435 : SEXP file1c0032db598f( ) ;
#> 436 : }
#> 437 :
#> 438 : // definition
#> 439 : SEXP file1c0032db598f() {
#> 440 : return Rcpp::wrap("anon_model");
#> 441 : }
fit <- sampling(mod, data = list(y_mean = 0))
#>
#> SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
#> Chain 1:
#> Chain 1: Gradient evaluation took 2e-06 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.02 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1:
#> Chain 1:
#> Chain 1: Iteration: 1 / 2000 [ 0%] (Warmup)
#> Chain 1: Iteration: 200 / 2000 [ 10%] (Warmup)
#> Chain 1: Iteration: 400 / 2000 [ 20%] (Warmup)
#> Chain 1: Iteration: 600 / 2000 [ 30%] (Warmup)
#> Chain 1: Iteration: 800 / 2000 [ 40%] (Warmup)
#> Chain 1: Iteration: 1000 / 2000 [ 50%] (Warmup)
#> Chain 1: Iteration: 1001 / 2000 [ 50%] (Sampling)
#> Chain 1: Iteration: 1200 / 2000 [ 60%] (Sampling)
#> Chain 1: Iteration: 1400 / 2000 [ 70%] (Sampling)
#> Chain 1: Iteration: 1600 / 2000 [ 80%] (Sampling)
#> Chain 1: Iteration: 1800 / 2000 [ 90%] (Sampling)
#> Chain 1: Iteration: 2000 / 2000 [100%] (Sampling)
#> Chain 1:
#> Chain 1: Elapsed Time: 0.003 seconds (Warm-up)
#> Chain 1: 0.002 seconds (Sampling)
#> Chain 1: 0.005 seconds (Total)
#> Chain 1:
#>
#> SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 2).
#> Chain 2:
#> Chain 2: Gradient evaluation took 0 seconds
#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
#> Chain 2: Adjust your expectations accordingly!
#> Chain 2:
#> Chain 2:
#> Chain 2: Iteration: 1 / 2000 [ 0%] (Warmup)
#> Chain 2: Iteration: 200 / 2000 [ 10%] (Warmup)
#> Chain 2: Iteration: 400 / 2000 [ 20%] (Warmup)
#> Chain 2: Iteration: 600 / 2000 [ 30%] (Warmup)
#> Chain 2: Iteration: 800 / 2000 [ 40%] (Warmup)
#> Chain 2: Iteration: 1000 / 2000 [ 50%] (Warmup)
#> Chain 2: Iteration: 1001 / 2000 [ 50%] (Sampling)
#> Chain 2: Iteration: 1200 / 2000 [ 60%] (Sampling)
#> Chain 2: Iteration: 1400 / 2000 [ 70%] (Sampling)
#> Chain 2: Iteration: 1600 / 2000 [ 80%] (Sampling)
#> Chain 2: Iteration: 1800 / 2000 [ 90%] (Sampling)
#> Chain 2: Iteration: 2000 / 2000 [100%] (Sampling)
#> Chain 2:
#> Chain 2: Elapsed Time: 0.003 seconds (Warm-up)
#> Chain 2: 0.003 seconds (Sampling)
#> Chain 2: 0.006 seconds (Total)
#> Chain 2:
#>
#> SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 3).
#> Chain 3:
#> Chain 3: Gradient evaluation took 0 seconds
#> Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
#> Chain 3: Adjust your expectations accordingly!
#> Chain 3:
#> Chain 3:
#> Chain 3: Iteration: 1 / 2000 [ 0%] (Warmup)
#> Chain 3: Iteration: 200 / 2000 [ 10%] (Warmup)
#> Chain 3: Iteration: 400 / 2000 [ 20%] (Warmup)
#> Chain 3: Iteration: 600 / 2000 [ 30%] (Warmup)
#> Chain 3: Iteration: 800 / 2000 [ 40%] (Warmup)
#> Chain 3: Iteration: 1000 / 2000 [ 50%] (Warmup)
#> Chain 3: Iteration: 1001 / 2000 [ 50%] (Sampling)
#> Chain 3: Iteration: 1200 / 2000 [ 60%] (Sampling)
#> Chain 3: Iteration: 1400 / 2000 [ 70%] (Sampling)
#> Chain 3: Iteration: 1600 / 2000 [ 80%] (Sampling)
#> Chain 3: Iteration: 1800 / 2000 [ 90%] (Sampling)
#> Chain 3: Iteration: 2000 / 2000 [100%] (Sampling)
#> Chain 3:
#> Chain 3: Elapsed Time: 0.003 seconds (Warm-up)
#> Chain 3: 0.003 seconds (Sampling)
#> Chain 3: 0.006 seconds (Total)
#> Chain 3:
#>
#> SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 4).
#> Chain 4:
#> Chain 4: Gradient evaluation took 0 seconds
#> Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
#> Chain 4: Adjust your expectations accordingly!
#> Chain 4:
#> Chain 4:
#> Chain 4: Iteration: 1 / 2000 [ 0%] (Warmup)
#> Chain 4: Iteration: 200 / 2000 [ 10%] (Warmup)
#> Chain 4: Iteration: 400 / 2000 [ 20%] (Warmup)
#> Chain 4: Iteration: 600 / 2000 [ 30%] (Warmup)
#> Chain 4: Iteration: 800 / 2000 [ 40%] (Warmup)
#> Chain 4: Iteration: 1000 / 2000 [ 50%] (Warmup)
#> Chain 4: Iteration: 1001 / 2000 [ 50%] (Sampling)
#> Chain 4: Iteration: 1200 / 2000 [ 60%] (Sampling)
#> Chain 4: Iteration: 1400 / 2000 [ 70%] (Sampling)
#> Chain 4: Iteration: 1600 / 2000 [ 80%] (Sampling)
#> Chain 4: Iteration: 1800 / 2000 [ 90%] (Sampling)
#> Chain 4: Iteration: 2000 / 2000 [100%] (Sampling)
#> Chain 4:
#> Chain 4: Elapsed Time: 0.003 seconds (Warm-up)
#> Chain 4: 0.003 seconds (Sampling)
#> Chain 4: 0.006 seconds (Total)
#> Chain 4:
fit2 <- sampling(mod, data = list(y_mean = 5))
#>
#> SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
#> Chain 1:
#> Chain 1: Gradient evaluation took 2e-06 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.02 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1:
#> Chain 1:
#> Chain 1: Iteration: 1 / 2000 [ 0%] (Warmup)
#> Chain 1: Iteration: 200 / 2000 [ 10%] (Warmup)
#> Chain 1: Iteration: 400 / 2000 [ 20%] (Warmup)
#> Chain 1: Iteration: 600 / 2000 [ 30%] (Warmup)
#> Chain 1: Iteration: 800 / 2000 [ 40%] (Warmup)
#> Chain 1: Iteration: 1000 / 2000 [ 50%] (Warmup)
#> Chain 1: Iteration: 1001 / 2000 [ 50%] (Sampling)
#> Chain 1: Iteration: 1200 / 2000 [ 60%] (Sampling)
#> Chain 1: Iteration: 1400 / 2000 [ 70%] (Sampling)
#> Chain 1: Iteration: 1600 / 2000 [ 80%] (Sampling)
#> Chain 1: Iteration: 1800 / 2000 [ 90%] (Sampling)
#> Chain 1: Iteration: 2000 / 2000 [100%] (Sampling)
#> Chain 1:
#> Chain 1: Elapsed Time: 0.003 seconds (Warm-up)
#> Chain 1: 0.003 seconds (Sampling)
#> Chain 1: 0.006 seconds (Total)
#> Chain 1:
#>
#> SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 2).
#> Chain 2:
#> Chain 2: Gradient evaluation took 0 seconds
#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
#> Chain 2: Adjust your expectations accordingly!
#> Chain 2:
#> Chain 2:
#> Chain 2: Iteration: 1 / 2000 [ 0%] (Warmup)
#> Chain 2: Iteration: 200 / 2000 [ 10%] (Warmup)
#> Chain 2: Iteration: 400 / 2000 [ 20%] (Warmup)
#> Chain 2: Iteration: 600 / 2000 [ 30%] (Warmup)
#> Chain 2: Iteration: 800 / 2000 [ 40%] (Warmup)
#> Chain 2: Iteration: 1000 / 2000 [ 50%] (Warmup)
#> Chain 2: Iteration: 1001 / 2000 [ 50%] (Sampling)
#> Chain 2: Iteration: 1200 / 2000 [ 60%] (Sampling)
#> Chain 2: Iteration: 1400 / 2000 [ 70%] (Sampling)
#> Chain 2: Iteration: 1600 / 2000 [ 80%] (Sampling)
#> Chain 2: Iteration: 1800 / 2000 [ 90%] (Sampling)
#> Chain 2: Iteration: 2000 / 2000 [100%] (Sampling)
#> Chain 2:
#> Chain 2: Elapsed Time: 0.003 seconds (Warm-up)
#> Chain 2: 0.002 seconds (Sampling)
#> Chain 2: 0.005 seconds (Total)
#> Chain 2:
#>
#> SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 3).
#> Chain 3:
#> Chain 3: Gradient evaluation took 0 seconds
#> Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
#> Chain 3: Adjust your expectations accordingly!
#> Chain 3:
#> Chain 3:
#> Chain 3: Iteration: 1 / 2000 [ 0%] (Warmup)
#> Chain 3: Iteration: 200 / 2000 [ 10%] (Warmup)
#> Chain 3: Iteration: 400 / 2000 [ 20%] (Warmup)
#> Chain 3: Iteration: 600 / 2000 [ 30%] (Warmup)
#> Chain 3: Iteration: 800 / 2000 [ 40%] (Warmup)
#> Chain 3: Iteration: 1000 / 2000 [ 50%] (Warmup)
#> Chain 3: Iteration: 1001 / 2000 [ 50%] (Sampling)
#> Chain 3: Iteration: 1200 / 2000 [ 60%] (Sampling)
#> Chain 3: Iteration: 1400 / 2000 [ 70%] (Sampling)
#> Chain 3: Iteration: 1600 / 2000 [ 80%] (Sampling)
#> Chain 3: Iteration: 1800 / 2000 [ 90%] (Sampling)
#> Chain 3: Iteration: 2000 / 2000 [100%] (Sampling)
#> Chain 3:
#> Chain 3: Elapsed Time: 0.003 seconds (Warm-up)
#> Chain 3: 0.002 seconds (Sampling)
#> Chain 3: 0.005 seconds (Total)
#> Chain 3:
#>
#> SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 4).
#> Chain 4:
#> Chain 4: Gradient evaluation took 0 seconds
#> Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
#> Chain 4: Adjust your expectations accordingly!
#> Chain 4:
#> Chain 4:
#> Chain 4: Iteration: 1 / 2000 [ 0%] (Warmup)
#> Chain 4: Iteration: 200 / 2000 [ 10%] (Warmup)
#> Chain 4: Iteration: 400 / 2000 [ 20%] (Warmup)
#> Chain 4: Iteration: 600 / 2000 [ 30%] (Warmup)
#> Chain 4: Iteration: 800 / 2000 [ 40%] (Warmup)
#> Chain 4: Iteration: 1000 / 2000 [ 50%] (Warmup)
#> Chain 4: Iteration: 1001 / 2000 [ 50%] (Sampling)
#> Chain 4: Iteration: 1200 / 2000 [ 60%] (Sampling)
#> Chain 4: Iteration: 1400 / 2000 [ 70%] (Sampling)
#> Chain 4: Iteration: 1600 / 2000 [ 80%] (Sampling)
#> Chain 4: Iteration: 1800 / 2000 [ 90%] (Sampling)
#> Chain 4: Iteration: 2000 / 2000 [100%] (Sampling)
#> Chain 4:
#> Chain 4: Elapsed Time: 0.003 seconds (Warm-up)
#> Chain 4: 0.002 seconds (Sampling)
#> Chain 4: 0.005 seconds (Total)
#> Chain 4:
# }