diff --git a/src/stanExports_constant_multi_ind.h b/src/stanExports_constant_multi_ind.h index a30c3f5..d5dede6 100644 --- a/src/stanExports_constant_multi_ind.h +++ b/src/stanExports_constant_multi_ind.h @@ -21,91 +21,144 @@ #define USE_STANC3 #endif #include -// Code generated by stanc v2.32.2 +// Code generated by stanc v2.26.1-4-gd72b68b7-dirty #include namespace model_constant_multi_ind_namespace { +inline void validate_positive_index(const char* var_name, const char* expr, + int val) { + if (val < 1) { + std::stringstream msg; + msg << "Found dimension size less than one in simplex declaration" + << "; variable=" << var_name << "; dimension size expression=" << expr + << "; expression value=" << val; + std::string msg_str(msg.str()); + throw std::invalid_argument(msg_str.c_str()); + } +} +inline void validate_unit_vector_index(const char* var_name, const char* expr, + int val) { + if (val <= 1) { + std::stringstream msg; + if (val == 1) { + msg << "Found dimension size one in unit vector declaration." + << " One-dimensional unit vector is discrete" + << " but the target distribution must be continuous." + << " variable=" << var_name << "; dimension size expression=" << expr; + } else { + msg << "Found dimension size less than one in unit vector declaration" + << "; variable=" << var_name << "; dimension size expression=" << expr + << "; expression value=" << val; + } + std::string msg_str(msg.str()); + throw std::invalid_argument(msg_str.c_str()); + } +} +using std::istream; +using std::string; +using std::stringstream; +using std::vector; +using std::pow; +using stan::io::dump; +using stan::math::lgamma; using stan::model::model_base_crtp; +using stan::model::rvalue; +using stan::model::cons_list; +using stan::model::index_uni; +using stan::model::index_max; +using stan::model::index_min; +using stan::model::index_min_max; +using stan::model::index_multi; +using stan::model::index_omni; +using stan::model::nil_index_list; using namespace stan::math; +using stan::math::pow; stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'constant_multi_ind', line 21, column 2 to column 31)", - " (in 'constant_multi_ind', line 22, column 2 to column 32)", - " (in 'constant_multi_ind', line 23, column 2 to column 23)", - " (in 'constant_multi_ind', line 24, column 2 to column 35)", - " (in 'constant_multi_ind', line 26, column 2 to column 35)", - " (in 'constant_multi_ind', line 62, column 2 to column 20)", - " (in 'constant_multi_ind', line 63, column 2 to column 24)", - " (in 'constant_multi_ind', line 67, column 6 to column 36)", - " (in 'constant_multi_ind', line 66, column 23 to line 68, column 5)", - " (in 'constant_multi_ind', line 66, column 4 to line 68, column 5)", - " (in 'constant_multi_ind', line 70, column 4 to column 47)", - " (in 'constant_multi_ind', line 75, column 8 to column 65)", - " (in 'constant_multi_ind', line 73, column 32 to line 76, column 7)", - " (in 'constant_multi_ind', line 73, column 6 to line 76, column 7)", - " (in 'constant_multi_ind', line 72, column 17 to line 77, column 5)", - " (in 'constant_multi_ind', line 72, column 4 to line 77, column 5)", - " (in 'constant_multi_ind', line 64, column 19 to line 78, column 3)", - " (in 'constant_multi_ind', line 64, column 2 to line 78, column 3)", - " (in 'constant_multi_ind', line 30, column 13 to column 18)", - " (in 'constant_multi_ind', line 30, column 2 to column 20)", - " (in 'constant_multi_ind', line 31, column 17 to column 22)", - " (in 'constant_multi_ind', line 31, column 2 to column 24)", - " (in 'constant_multi_ind', line 35, column 6 to column 36)", - " (in 'constant_multi_ind', line 34, column 23 to line 36, column 5)", - " (in 'constant_multi_ind', line 34, column 4 to line 36, column 5)", - " (in 'constant_multi_ind', line 38, column 4 to column 47)", - " (in 'constant_multi_ind', line 43, column 8 to column 65)", - " (in 'constant_multi_ind', line 41, column 32 to line 44, column 7)", - " (in 'constant_multi_ind', line 41, column 6 to line 44, column 7)", - " (in 'constant_multi_ind', line 40, column 17 to line 45, column 5)", - " (in 'constant_multi_ind', line 40, column 4 to line 45, column 5)", - " (in 'constant_multi_ind', line 32, column 19 to line 46, column 3)", - " (in 'constant_multi_ind', line 32, column 2 to line 46, column 3)", - " (in 'constant_multi_ind', line 48, column 2 to column 44)", - " (in 'constant_multi_ind', line 51, column 2 to column 48)", - " (in 'constant_multi_ind', line 52, column 2 to line 53, column 40)", - " (in 'constant_multi_ind', line 55, column 2 to column 35)", - " (in 'constant_multi_ind', line 56, column 2 to column 37)", - " (in 'constant_multi_ind', line 58, column 2 to column 37)", - " (in 'constant_multi_ind', line 10, column 2 to column 12)", - " (in 'constant_multi_ind', line 11, column 2 to column 12)", - " (in 'constant_multi_ind', line 12, column 13 to column 18)", - " (in 'constant_multi_ind', line 12, column 2 to column 20)", - " (in 'constant_multi_ind', line 13, column 16 to column 21)", - " (in 'constant_multi_ind', line 13, column 2 to column 23)", - " (in 'constant_multi_ind', line 14, column 12 to column 17)", - " (in 'constant_multi_ind', line 14, column 2 to column 19)", - " (in 'constant_multi_ind', line 15, column 13 to column 18)", - " (in 'constant_multi_ind', line 15, column 2 to column 20)", - " (in 'constant_multi_ind', line 16, column 15 to column 20)", - " (in 'constant_multi_ind', line 16, column 2 to column 22)", - " (in 'constant_multi_ind', line 21, column 24 to column 29)", - " (in 'constant_multi_ind', line 22, column 25 to column 30)", - " (in 'constant_multi_ind', line 62, column 13 to column 18)", - " (in 'constant_multi_ind', line 63, column 17 to column 22)", - " (in 'constant_multi_ind', line 5, column 4 to column 16)", - " (in 'constant_multi_ind', line 4, column 24 to line 6, column 3)"}; -template >* = nullptr> -stan::promote_args_t growth(const T0__& beta, std::ostream* pstream__); -template >*> -stan::promote_args_t growth(const T0__& beta, std::ostream* pstream__) { +static int current_statement__= 0; +static const std::vector locations_array__ = {" (found before start of program)", + " (in 'constant_multi_ind', line 21, column 2 to column 31)", + " (in 'constant_multi_ind', line 22, column 2 to column 32)", + " (in 'constant_multi_ind', line 23, column 2 to column 23)", + " (in 'constant_multi_ind', line 24, column 2 to column 35)", + " (in 'constant_multi_ind', line 26, column 2 to column 35)", + " (in 'constant_multi_ind', line 62, column 2 to column 20)", + " (in 'constant_multi_ind', line 63, column 2 to column 24)", + " (in 'constant_multi_ind', line 67, column 6 to column 36)", + " (in 'constant_multi_ind', line 66, column 23 to line 68, column 5)", + " (in 'constant_multi_ind', line 66, column 4 to line 68, column 5)", + " (in 'constant_multi_ind', line 70, column 4 to column 47)", + " (in 'constant_multi_ind', line 75, column 8 to column 65)", + " (in 'constant_multi_ind', line 73, column 32 to line 76, column 7)", + " (in 'constant_multi_ind', line 73, column 6 to line 76, column 7)", + " (in 'constant_multi_ind', line 72, column 17 to line 77, column 5)", + " (in 'constant_multi_ind', line 72, column 4 to line 77, column 5)", + " (in 'constant_multi_ind', line 64, column 19 to line 78, column 3)", + " (in 'constant_multi_ind', line 64, column 2 to line 78, column 3)", + " (in 'constant_multi_ind', line 30, column 13 to column 18)", + " (in 'constant_multi_ind', line 30, column 2 to column 20)", + " (in 'constant_multi_ind', line 31, column 17 to column 22)", + " (in 'constant_multi_ind', line 31, column 2 to column 24)", + " (in 'constant_multi_ind', line 35, column 6 to column 36)", + " (in 'constant_multi_ind', line 34, column 23 to line 36, column 5)", + " (in 'constant_multi_ind', line 34, column 4 to line 36, column 5)", + " (in 'constant_multi_ind', line 38, column 4 to column 47)", + " (in 'constant_multi_ind', line 43, column 8 to column 65)", + " (in 'constant_multi_ind', line 41, column 32 to line 44, column 7)", + " (in 'constant_multi_ind', line 41, column 6 to line 44, column 7)", + " (in 'constant_multi_ind', line 40, column 17 to line 45, column 5)", + " (in 'constant_multi_ind', line 40, column 4 to line 45, column 5)", + " (in 'constant_multi_ind', line 32, column 19 to line 46, column 3)", + " (in 'constant_multi_ind', line 32, column 2 to line 46, column 3)", + " (in 'constant_multi_ind', line 48, column 2 to column 44)", + " (in 'constant_multi_ind', line 51, column 2 to column 48)", + " (in 'constant_multi_ind', line 52, column 2 to line 53, column 40)", + " (in 'constant_multi_ind', line 55, column 2 to column 35)", + " (in 'constant_multi_ind', line 56, column 2 to column 37)", + " (in 'constant_multi_ind', line 58, column 2 to column 37)", + " (in 'constant_multi_ind', line 10, column 2 to column 12)", + " (in 'constant_multi_ind', line 11, column 2 to column 12)", + " (in 'constant_multi_ind', line 12, column 13 to column 18)", + " (in 'constant_multi_ind', line 12, column 2 to column 20)", + " (in 'constant_multi_ind', line 13, column 16 to column 21)", + " (in 'constant_multi_ind', line 13, column 2 to column 23)", + " (in 'constant_multi_ind', line 14, column 12 to column 17)", + " (in 'constant_multi_ind', line 14, column 2 to column 19)", + " (in 'constant_multi_ind', line 15, column 13 to column 18)", + " (in 'constant_multi_ind', line 15, column 2 to column 20)", + " (in 'constant_multi_ind', line 16, column 15 to column 20)", + " (in 'constant_multi_ind', line 16, column 2 to column 22)", + " (in 'constant_multi_ind', line 21, column 24 to column 29)", + " (in 'constant_multi_ind', line 22, column 25 to column 30)", + " (in 'constant_multi_ind', line 62, column 13 to column 18)", + " (in 'constant_multi_ind', line 63, column 17 to column 22)", + " (in 'constant_multi_ind', line 5, column 4 to column 16)", + " (in 'constant_multi_ind', line 4, column 24 to line 6, column 3)"}; +template +stan::promote_args_t +growth(const T0__& beta, std::ostream* pstream__) { using local_scalar_t__ = stan::promote_args_t; - int current_statement__ = 0; - static constexpr bool propto__ = true; - // suppress unused var warning + const static bool propto__ = true; (void) propto__; local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; + (void) DUMMY_VAR__; // suppress unused var warning + try { current_statement__ = 56; return beta; } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); } + +} +struct growth_functor__ { +template +stan::promote_args_t +operator()(const T0__& beta, std::ostream* pstream__) const +{ +return growth(beta, pstream__); } +}; #include class model_constant_multi_ind final : public model_base_crtp { private: @@ -116,622 +169,657 @@ class model_constant_multi_ind final : public model_base_crtp time; std::vector ind_id; std::vector y_0_obs; + public: - ~model_constant_multi_ind() {} - model_constant_multi_ind(stan::io::var_context& context__, unsigned int - random_seed__ = 0, std::ostream* - pstream__ = nullptr) : model_base_crtp(0) { - int current_statement__ = 0; - using local_scalar_t__ = double; - boost::ecuyer1988 base_rng__ = - stan::services::util::create_rng(random_seed__, 0); - // suppress unused var warning - (void) base_rng__; - static constexpr const char* function__ = - "model_constant_multi_ind_namespace::model_constant_multi_ind"; - // suppress unused var warning - (void) function__; + ~model_constant_multi_ind() { } + + inline std::string model_name() const final { return "model_constant_multi_ind"; } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.26.1-4-gd72b68b7-dirty", "stancflags = "}; + } + + + model_constant_multi_ind(stan::io::var_context& context__, + unsigned int random_seed__ = 0, + std::ostream* pstream__ = nullptr) : model_base_crtp(0) { + using local_scalar_t__ = double ; + boost::ecuyer1988 base_rng__ = + stan::services::util::create_rng(random_seed__, 0); + (void) base_rng__; // suppress unused var warning + static const char* function__ = "model_constant_multi_ind_namespace::model_constant_multi_ind"; + (void) function__; // suppress unused var warning local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; + (void) DUMMY_VAR__; // suppress unused var warning + try { - int pos__ = std::numeric_limits::min(); + int pos__; + pos__ = std::numeric_limits::min(); + pos__ = 1; current_statement__ = 40; - context__.validate_dims("data initialization", "n_obs", "int", - std::vector{}); + context__.validate_dims("data initialization","n_obs","int", + context__.to_vec()); n_obs = std::numeric_limits::min(); + current_statement__ = 40; n_obs = context__.vals_i("n_obs")[(1 - 1)]; current_statement__ = 41; - context__.validate_dims("data initialization", "n_ind", "int", - std::vector{}); + context__.validate_dims("data initialization","n_ind","int", + context__.to_vec()); n_ind = std::numeric_limits::min(); + current_statement__ = 41; n_ind = context__.vals_i("n_ind")[(1 - 1)]; current_statement__ = 42; - stan::math::validate_non_negative_index("y_obs", "n_obs", n_obs); + validate_non_negative_index("y_obs", "n_obs", n_obs); current_statement__ = 43; - context__.validate_dims("data initialization", "y_obs", "double", - std::vector{static_cast(n_obs)}); - y_obs = std::vector(n_obs, - std::numeric_limits::quiet_NaN()); + context__.validate_dims("data initialization","y_obs","double", + context__.to_vec(n_obs)); + y_obs = std::vector(n_obs, std::numeric_limits::quiet_NaN()); + current_statement__ = 43; - y_obs = context__.vals_r("y_obs"); + assign(y_obs, nil_index_list(), context__.vals_r("y_obs"), + "assigning variable y_obs"); current_statement__ = 44; - stan::math::validate_non_negative_index("obs_index", "n_obs", n_obs); + validate_non_negative_index("obs_index", "n_obs", n_obs); current_statement__ = 45; - context__.validate_dims("data initialization", "obs_index", "int", - std::vector{static_cast(n_obs)}); + context__.validate_dims("data initialization","obs_index","int", + context__.to_vec(n_obs)); obs_index = std::vector(n_obs, std::numeric_limits::min()); + current_statement__ = 45; - obs_index = context__.vals_i("obs_index"); + assign(obs_index, nil_index_list(), context__.vals_i("obs_index"), + "assigning variable obs_index"); current_statement__ = 46; - stan::math::validate_non_negative_index("time", "n_obs", n_obs); + validate_non_negative_index("time", "n_obs", n_obs); current_statement__ = 47; - context__.validate_dims("data initialization", "time", "double", - std::vector{static_cast(n_obs)}); - time = std::vector(n_obs, - std::numeric_limits::quiet_NaN()); + context__.validate_dims("data initialization","time","double", + context__.to_vec(n_obs)); + time = std::vector(n_obs, std::numeric_limits::quiet_NaN()); + current_statement__ = 47; - time = context__.vals_r("time"); + assign(time, nil_index_list(), context__.vals_r("time"), + "assigning variable time"); current_statement__ = 48; - stan::math::validate_non_negative_index("ind_id", "n_obs", n_obs); + validate_non_negative_index("ind_id", "n_obs", n_obs); current_statement__ = 49; - context__.validate_dims("data initialization", "ind_id", "int", - std::vector{static_cast(n_obs)}); + context__.validate_dims("data initialization","ind_id","int", + context__.to_vec(n_obs)); ind_id = std::vector(n_obs, std::numeric_limits::min()); + current_statement__ = 49; - ind_id = context__.vals_i("ind_id"); + assign(ind_id, nil_index_list(), context__.vals_i("ind_id"), + "assigning variable ind_id"); current_statement__ = 50; - stan::math::validate_non_negative_index("y_0_obs", "n_ind", n_ind); + validate_non_negative_index("y_0_obs", "n_ind", n_ind); current_statement__ = 51; - context__.validate_dims("data initialization", "y_0_obs", "double", - std::vector{static_cast(n_ind)}); - y_0_obs = std::vector(n_ind, - std::numeric_limits::quiet_NaN()); + context__.validate_dims("data initialization","y_0_obs","double", + context__.to_vec(n_ind)); + y_0_obs = std::vector(n_ind, std::numeric_limits::quiet_NaN()); + current_statement__ = 51; - y_0_obs = context__.vals_r("y_0_obs"); + assign(y_0_obs, nil_index_list(), context__.vals_r("y_0_obs"), + "assigning variable y_0_obs"); current_statement__ = 52; - stan::math::validate_non_negative_index("ind_y_0", "n_ind", n_ind); + validate_non_negative_index("ind_y_0", "n_ind", n_ind); current_statement__ = 53; - stan::math::validate_non_negative_index("ind_beta", "n_ind", n_ind); + validate_non_negative_index("ind_beta", "n_ind", n_ind); current_statement__ = 54; - stan::math::validate_non_negative_index("y_hat", "n_obs", n_obs); + validate_non_negative_index("y_hat", "n_obs", n_obs); current_statement__ = 55; - stan::math::validate_non_negative_index("Delta_hat", "n_obs", n_obs); + validate_non_negative_index("Delta_hat", "n_obs", n_obs); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); + } + num_params_r__ = 0U; + + try { + num_params_r__ += n_ind; + num_params_r__ += n_ind; + num_params_r__ += 1; + num_params_r__ += 1; + num_params_r__ += 1; + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); } - num_params_r__ = n_ind + n_ind + 1 + 1 + 1; - } - inline std::string model_name() const final { - return "model_constant_multi_ind"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { + template * = nullptr, stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t log_prob_impl(VecR& params_r__, + VecI& params_i__, + std::ostream* pstream__ = nullptr) const { using T__ = stan::scalar_type_t; using local_scalar_t__ = T__; T__ lp__(0.0); stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; + static const char* function__ = "model_constant_multi_ind_namespace::log_prob"; +(void) function__; // suppress unused var warning + stan::io::reader in__(params_r__, params_i__); local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_constant_multi_ind_namespace::log_prob"; - // suppress unused var warning - (void) function__; + (void) DUMMY_VAR__; // suppress unused var warning + try { - std::vector ind_y_0 = - std::vector(n_ind, DUMMY_VAR__); + std::vector ind_y_0; + ind_y_0 = std::vector(n_ind, DUMMY_VAR__); + + current_statement__ = 1; + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { + current_statement__ = 1; + assign(ind_y_0, cons_list(index_uni(sym1__), nil_index_list()), + in__.scalar(), "assigning variable ind_y_0");} current_statement__ = 1; - ind_y_0 = in__.template read_constrain_lb< - std::vector, jacobian__>(0, lp__, n_ind); - std::vector ind_beta = - std::vector(n_ind, DUMMY_VAR__); + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { + current_statement__ = 1; + if (jacobian__) { + current_statement__ = 1; + assign(ind_y_0, cons_list(index_uni(sym1__), nil_index_list()), + stan::math::lb_constrain(ind_y_0[(sym1__ - 1)], 0, lp__), + "assigning variable ind_y_0"); + } else { + current_statement__ = 1; + assign(ind_y_0, cons_list(index_uni(sym1__), nil_index_list()), + stan::math::lb_constrain(ind_y_0[(sym1__ - 1)], 0), + "assigning variable ind_y_0"); + }} + std::vector ind_beta; + ind_beta = std::vector(n_ind, DUMMY_VAR__); + current_statement__ = 2; - ind_beta = in__.template read_constrain_lb< - std::vector, jacobian__>(0, lp__, n_ind); - local_scalar_t__ species_beta_mu = DUMMY_VAR__; + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { + current_statement__ = 2; + assign(ind_beta, cons_list(index_uni(sym1__), nil_index_list()), + in__.scalar(), "assigning variable ind_beta");} + current_statement__ = 2; + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { + current_statement__ = 2; + if (jacobian__) { + current_statement__ = 2; + assign(ind_beta, cons_list(index_uni(sym1__), nil_index_list()), + stan::math::lb_constrain(ind_beta[(sym1__ - 1)], 0, lp__), + "assigning variable ind_beta"); + } else { + current_statement__ = 2; + assign(ind_beta, cons_list(index_uni(sym1__), nil_index_list()), + stan::math::lb_constrain(ind_beta[(sym1__ - 1)], 0), + "assigning variable ind_beta"); + }} + local_scalar_t__ species_beta_mu; + species_beta_mu = DUMMY_VAR__; + current_statement__ = 3; - species_beta_mu = in__.template read(); - local_scalar_t__ species_beta_sigma = DUMMY_VAR__; + species_beta_mu = in__.scalar(); + local_scalar_t__ species_beta_sigma; + species_beta_sigma = DUMMY_VAR__; + + current_statement__ = 4; + species_beta_sigma = in__.scalar(); current_statement__ = 4; - species_beta_sigma = in__.template read_constrain_lb(0, lp__); - local_scalar_t__ global_error_sigma = DUMMY_VAR__; + if (jacobian__) { + current_statement__ = 4; + species_beta_sigma = stan::math::lb_constrain(species_beta_sigma, 0, + lp__); + } else { + current_statement__ = 4; + species_beta_sigma = stan::math::lb_constrain(species_beta_sigma, 0); + } + local_scalar_t__ global_error_sigma; + global_error_sigma = DUMMY_VAR__; + current_statement__ = 5; - global_error_sigma = in__.template read_constrain_lb(0, lp__); + global_error_sigma = in__.scalar(); + current_statement__ = 5; + if (jacobian__) { + current_statement__ = 5; + global_error_sigma = stan::math::lb_constrain(global_error_sigma, 0, + lp__); + } else { + current_statement__ = 5; + global_error_sigma = stan::math::lb_constrain(global_error_sigma, 0); + } { current_statement__ = 19; - stan::math::validate_non_negative_index("y_hat", "n_obs", n_obs); - std::vector y_hat = - std::vector(n_obs, DUMMY_VAR__); + validate_non_negative_index("y_hat", "n_obs", n_obs); + std::vector y_hat; + y_hat = std::vector(n_obs, DUMMY_VAR__); + current_statement__ = 21; - stan::math::validate_non_negative_index("Delta_hat", "n_obs", n_obs); - std::vector Delta_hat = - std::vector(n_obs, DUMMY_VAR__); + validate_non_negative_index("Delta_hat", "n_obs", n_obs); + std::vector Delta_hat; + Delta_hat = std::vector(n_obs, DUMMY_VAR__); + current_statement__ = 33; for (int i = 1; i <= n_obs; ++i) { current_statement__ = 25; - if (stan::math::logical_eq( - stan::model::rvalue(obs_index, "obs_index", - stan::model::index_uni(i)), 1)) { + if (logical_eq(obs_index[(i - 1)], 1)) { current_statement__ = 23; - stan::model::assign(y_hat, - stan::model::rvalue(ind_y_0, "ind_y_0", - stan::model::index_uni( - stan::model::rvalue(ind_id, "ind_id", - stan::model::index_uni(i)))), "assigning variable y_hat", - stan::model::index_uni(i)); - } + assign(y_hat, cons_list(index_uni(i), nil_index_list()), + ind_y_0[(ind_id[(i - 1)] - 1)], "assigning variable y_hat"); + } current_statement__ = 26; - stan::model::assign(Delta_hat, - growth( - stan::model::rvalue(ind_beta, "ind_beta", - stan::model::index_uni( - stan::model::rvalue(ind_id, "ind_id", - stan::model::index_uni(i)))), pstream__), - "assigning variable Delta_hat", stan::model::index_uni(i)); + assign(Delta_hat, cons_list(index_uni(i), nil_index_list()), + growth(ind_beta[(ind_id[(i - 1)] - 1)], pstream__), + "assigning variable Delta_hat"); current_statement__ = 31; - if (stan::math::logical_lt(i, n_obs)) { + if (logical_lt(i, n_obs)) { current_statement__ = 29; - if (stan::math::logical_eq( - stan::model::rvalue(ind_id, "ind_id", - stan::model::index_uni((i + 1))), - stan::model::rvalue(ind_id, "ind_id", - stan::model::index_uni(i)))) { + if (logical_eq(ind_id[((i + 1) - 1)], ind_id[(i - 1)])) { current_statement__ = 27; - stan::model::assign(y_hat, - (stan::model::rvalue(y_hat, "y_hat", - stan::model::index_uni(i)) + - (stan::model::rvalue(Delta_hat, "Delta_hat", - stan::model::index_uni(i)) * - (stan::model::rvalue(time, "time", - stan::model::index_uni((i + 1))) - - stan::model::rvalue(time, "time", stan::model::index_uni(i))))), - "assigning variable y_hat", stan::model::index_uni((i + 1))); - } - } - } + assign(y_hat, cons_list(index_uni((i + 1)), nil_index_list()), + (y_hat[(i - 1)] + + (Delta_hat[(i - 1)] * + (time[((i + 1) - 1)] - time[(i - 1)]))), + "assigning variable y_hat"); + } + } } current_statement__ = 34; - lp_accum__.add(stan::math::normal_lpdf(y_obs, y_hat, - global_error_sigma)); + lp_accum__.add( + normal_lpdf(y_obs, y_hat, global_error_sigma)); current_statement__ = 35; - lp_accum__.add(stan::math::normal_lpdf(ind_y_0, y_0_obs, - global_error_sigma)); + lp_accum__.add( + normal_lpdf(ind_y_0, y_0_obs, global_error_sigma)); current_statement__ = 36; - lp_accum__.add(stan::math::lognormal_lpdf(ind_beta, - species_beta_mu, species_beta_sigma)); + lp_accum__.add( + lognormal_lpdf(ind_beta, species_beta_mu, + species_beta_sigma)); current_statement__ = 37; - lp_accum__.add(stan::math::normal_lpdf(species_beta_mu, - 0.1, 1)); + lp_accum__.add(normal_lpdf(species_beta_mu, 0.1, 1)); current_statement__ = 38; - lp_accum__.add(stan::math::cauchy_lpdf(species_beta_sigma, - 0.1, 1)); + lp_accum__.add(cauchy_lpdf(species_beta_sigma, 0.1, 1)); current_statement__ = 39; - lp_accum__.add(stan::math::cauchy_lpdf(global_error_sigma, - 0.1, 1)); + lp_accum__.add(cauchy_lpdf(global_error_sigma, 0.1, 1)); } } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); } lp_accum__.add(lp__); return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { + } // log_prob_impl() + + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_std_vector_vt* = nullptr> + inline void write_array_impl(RNG& base_rng__, VecR& params_r__, + VecI& params_i__, VecVar& vars__, + const bool emit_transformed_parameters__ = true, + const bool emit_generated_quantities__ = true, + std::ostream* pstream__ = nullptr) const { using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - static constexpr bool propto__ = true; - // suppress unused var warning - (void) propto__; + vars__.resize(0); + stan::io::reader in__(params_r__, params_i__); + static const char* function__ = "model_constant_multi_ind_namespace::write_array"; +(void) function__; // suppress unused var warning + (void) function__; // suppress unused var warning double lp__ = 0.0; - // suppress unused var warning - (void) lp__; - int current_statement__ = 0; + (void) lp__; // dummy to suppress unused var warning stan::math::accumulator lp_accum__; local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_constant_multi_ind_namespace::write_array"; - // suppress unused var warning - (void) function__; + (void) DUMMY_VAR__; // suppress unused var warning + try { - std::vector ind_y_0 = - std::vector(n_ind, std::numeric_limits::quiet_NaN()); + std::vector ind_y_0; + ind_y_0 = std::vector(n_ind, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; - ind_y_0 = in__.template read_constrain_lb< - std::vector, jacobian__>(0, lp__, n_ind); - std::vector ind_beta = - std::vector(n_ind, std::numeric_limits::quiet_NaN()); + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { + current_statement__ = 1; + assign(ind_y_0, cons_list(index_uni(sym1__), nil_index_list()), + in__.scalar(), "assigning variable ind_y_0");} + current_statement__ = 1; + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { + current_statement__ = 1; + assign(ind_y_0, cons_list(index_uni(sym1__), nil_index_list()), + stan::math::lb_constrain(ind_y_0[(sym1__ - 1)], 0), + "assigning variable ind_y_0");} + std::vector ind_beta; + ind_beta = std::vector(n_ind, std::numeric_limits::quiet_NaN()); + + current_statement__ = 2; + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { + current_statement__ = 2; + assign(ind_beta, cons_list(index_uni(sym1__), nil_index_list()), + in__.scalar(), "assigning variable ind_beta");} current_statement__ = 2; - ind_beta = in__.template read_constrain_lb< - std::vector, jacobian__>(0, lp__, n_ind); - double species_beta_mu = std::numeric_limits::quiet_NaN(); + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { + current_statement__ = 2; + assign(ind_beta, cons_list(index_uni(sym1__), nil_index_list()), + stan::math::lb_constrain(ind_beta[(sym1__ - 1)], 0), + "assigning variable ind_beta");} + double species_beta_mu; + species_beta_mu = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; - species_beta_mu = in__.template read(); - double species_beta_sigma = std::numeric_limits::quiet_NaN(); + species_beta_mu = in__.scalar(); + double species_beta_sigma; + species_beta_sigma = std::numeric_limits::quiet_NaN(); + + current_statement__ = 4; + species_beta_sigma = in__.scalar(); current_statement__ = 4; - species_beta_sigma = in__.template read_constrain_lb(0, lp__); - double global_error_sigma = std::numeric_limits::quiet_NaN(); + species_beta_sigma = stan::math::lb_constrain(species_beta_sigma, 0); + double global_error_sigma; + global_error_sigma = std::numeric_limits::quiet_NaN(); + current_statement__ = 5; - global_error_sigma = in__.template read_constrain_lb(0, lp__); - out__.write(ind_y_0); - out__.write(ind_beta); - out__.write(species_beta_mu); - out__.write(species_beta_sigma); - out__.write(global_error_sigma); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { + global_error_sigma = in__.scalar(); + current_statement__ = 5; + global_error_sigma = stan::math::lb_constrain(global_error_sigma, 0); + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { + vars__.emplace_back(ind_y_0[(sym1__ - 1)]);} + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { + vars__.emplace_back(ind_beta[(sym1__ - 1)]);} + vars__.emplace_back(species_beta_mu); + vars__.emplace_back(species_beta_sigma); + vars__.emplace_back(global_error_sigma); + if (logical_negation((primitive_value(emit_transformed_parameters__) || + primitive_value(emit_generated_quantities__)))) { return ; - } - if (stan::math::logical_negation(emit_generated_quantities__)) { + } + if (logical_negation(emit_generated_quantities__)) { return ; - } - std::vector y_hat = - std::vector(n_obs, std::numeric_limits::quiet_NaN()); - std::vector Delta_hat = - std::vector(n_obs, std::numeric_limits::quiet_NaN()); + } + std::vector y_hat; + y_hat = std::vector(n_obs, std::numeric_limits::quiet_NaN()); + + std::vector Delta_hat; + Delta_hat = std::vector(n_obs, std::numeric_limits::quiet_NaN()); + current_statement__ = 18; for (int i = 1; i <= n_obs; ++i) { current_statement__ = 10; - if (stan::math::logical_eq( - stan::model::rvalue(obs_index, "obs_index", - stan::model::index_uni(i)), 1)) { + if (logical_eq(obs_index[(i - 1)], 1)) { current_statement__ = 8; - stan::model::assign(y_hat, - stan::model::rvalue(ind_y_0, "ind_y_0", - stan::model::index_uni( - stan::model::rvalue(ind_id, "ind_id", - stan::model::index_uni(i)))), "assigning variable y_hat", - stan::model::index_uni(i)); - } + assign(y_hat, cons_list(index_uni(i), nil_index_list()), + ind_y_0[(ind_id[(i - 1)] - 1)], "assigning variable y_hat"); + } current_statement__ = 11; - stan::model::assign(Delta_hat, - growth( - stan::model::rvalue(ind_beta, "ind_beta", - stan::model::index_uni( - stan::model::rvalue(ind_id, "ind_id", - stan::model::index_uni(i)))), pstream__), - "assigning variable Delta_hat", stan::model::index_uni(i)); + assign(Delta_hat, cons_list(index_uni(i), nil_index_list()), + growth(ind_beta[(ind_id[(i - 1)] - 1)], pstream__), + "assigning variable Delta_hat"); current_statement__ = 16; - if (stan::math::logical_lt(i, n_obs)) { + if (logical_lt(i, n_obs)) { current_statement__ = 14; - if (stan::math::logical_eq( - stan::model::rvalue(ind_id, "ind_id", - stan::model::index_uni((i + 1))), - stan::model::rvalue(ind_id, "ind_id", - stan::model::index_uni(i)))) { + if (logical_eq(ind_id[((i + 1) - 1)], ind_id[(i - 1)])) { current_statement__ = 12; - stan::model::assign(y_hat, - (stan::model::rvalue(y_hat, "y_hat", stan::model::index_uni(i)) - + - (stan::model::rvalue(Delta_hat, "Delta_hat", - stan::model::index_uni(i)) * - (stan::model::rvalue(time, "time", - stan::model::index_uni((i + 1))) - - stan::model::rvalue(time, "time", stan::model::index_uni(i))))), - "assigning variable y_hat", stan::model::index_uni((i + 1))); - } - } - } - out__.write(y_hat); - out__.write(Delta_hat); + assign(y_hat, cons_list(index_uni((i + 1)), nil_index_list()), + (y_hat[(i - 1)] + + (Delta_hat[(i - 1)] * (time[((i + 1) - 1)] - time[(i - 1)]))), + "assigning variable y_hat"); + } + } } + for (int sym1__ = 1; sym1__ <= n_obs; ++sym1__) { + vars__.emplace_back(y_hat[(sym1__ - 1)]);} + for (int sym1__ = 1; sym1__ <= n_obs; ++sym1__) { + vars__.emplace_back(Delta_hat[(sym1__ - 1)]);} } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); } - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline void - unconstrain_array_impl(const VecVar& params_r__, const VecI& params_i__, - VecVar& vars__, std::ostream* pstream__ = nullptr) const { + } // write_array_impl() + + template * = nullptr, stan::require_vector_like_vt* = nullptr> + inline void transform_inits_impl(const stan::io::var_context& context__, + VecI& params_i__, VecVar& vars__, + std::ostream* pstream__ = nullptr) const { using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; + vars__.clear(); + vars__.reserve(num_params_r__); + try { - int pos__ = std::numeric_limits::min(); + int pos__; + pos__ = std::numeric_limits::min(); + pos__ = 1; - std::vector ind_y_0 = - std::vector(n_ind, DUMMY_VAR__); + std::vector ind_y_0; + ind_y_0 = std::vector(n_ind, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; - stan::model::assign(ind_y_0, - in__.read>(n_ind), + assign(ind_y_0, nil_index_list(), context__.vals_r("ind_y_0"), "assigning variable ind_y_0"); - out__.write_free_lb(0, ind_y_0); - std::vector ind_beta = - std::vector(n_ind, DUMMY_VAR__); - current_statement__ = 2; - stan::model::assign(ind_beta, - in__.read>(n_ind), - "assigning variable ind_beta"); - out__.write_free_lb(0, ind_beta); - local_scalar_t__ species_beta_mu = DUMMY_VAR__; - current_statement__ = 3; - species_beta_mu = in__.read(); - out__.write(species_beta_mu); - local_scalar_t__ species_beta_sigma = DUMMY_VAR__; - current_statement__ = 4; - species_beta_sigma = in__.read(); - out__.write_free_lb(0, species_beta_sigma); - local_scalar_t__ global_error_sigma = DUMMY_VAR__; - current_statement__ = 5; - global_error_sigma = in__.read(); - out__.write_free_lb(0, global_error_sigma); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr> - inline void - transform_inits_impl(const stan::io::var_context& context__, VecVar& - vars__, std::ostream* pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { + std::vector ind_y_0_free__; + ind_y_0_free__ = std::vector(n_ind, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; - context__.validate_dims("parameter initialization", "ind_y_0", - "double", std::vector{static_cast(n_ind)}); + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { + current_statement__ = 1; + assign(ind_y_0_free__, + cons_list(index_uni(sym1__), nil_index_list()), + stan::math::lb_free(ind_y_0[(sym1__ - 1)], 0), + "assigning variable ind_y_0_free__");} + std::vector ind_beta; + ind_beta = std::vector(n_ind, std::numeric_limits::quiet_NaN()); + current_statement__ = 2; - context__.validate_dims("parameter initialization", "ind_beta", - "double", std::vector{static_cast(n_ind)}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "species_beta_mu", - "double", std::vector{}); - current_statement__ = 4; - context__.validate_dims("parameter initialization", - "species_beta_sigma", "double", std::vector{}); - current_statement__ = 5; - context__.validate_dims("parameter initialization", - "global_error_sigma", "double", std::vector{}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector ind_y_0 = - std::vector(n_ind, DUMMY_VAR__); - current_statement__ = 1; - ind_y_0 = context__.vals_r("ind_y_0"); - out__.write_free_lb(0, ind_y_0); - std::vector ind_beta = - std::vector(n_ind, DUMMY_VAR__); + assign(ind_beta, nil_index_list(), context__.vals_r("ind_beta"), + "assigning variable ind_beta"); + std::vector ind_beta_free__; + ind_beta_free__ = std::vector(n_ind, std::numeric_limits::quiet_NaN()); + current_statement__ = 2; - ind_beta = context__.vals_r("ind_beta"); - out__.write_free_lb(0, ind_beta); - local_scalar_t__ species_beta_mu = DUMMY_VAR__; + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { + current_statement__ = 2; + assign(ind_beta_free__, + cons_list(index_uni(sym1__), nil_index_list()), + stan::math::lb_free(ind_beta[(sym1__ - 1)], 0), + "assigning variable ind_beta_free__");} + double species_beta_mu; + species_beta_mu = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; species_beta_mu = context__.vals_r("species_beta_mu")[(1 - 1)]; - out__.write(species_beta_mu); - local_scalar_t__ species_beta_sigma = DUMMY_VAR__; + double species_beta_sigma; + species_beta_sigma = std::numeric_limits::quiet_NaN(); + current_statement__ = 4; species_beta_sigma = context__.vals_r("species_beta_sigma")[(1 - 1)]; - out__.write_free_lb(0, species_beta_sigma); - local_scalar_t__ global_error_sigma = DUMMY_VAR__; + double species_beta_sigma_free__; + species_beta_sigma_free__ = std::numeric_limits::quiet_NaN(); + + current_statement__ = 4; + species_beta_sigma_free__ = stan::math::lb_free(species_beta_sigma, 0); + double global_error_sigma; + global_error_sigma = std::numeric_limits::quiet_NaN(); + current_statement__ = 5; global_error_sigma = context__.vals_r("global_error_sigma")[(1 - 1)]; - out__.write_free_lb(0, global_error_sigma); + double global_error_sigma_free__; + global_error_sigma_free__ = std::numeric_limits::quiet_NaN(); + + current_statement__ = 5; + global_error_sigma_free__ = stan::math::lb_free(global_error_sigma, 0); + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { + vars__.emplace_back(ind_y_0_free__[(sym1__ - 1)]);} + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { + vars__.emplace_back(ind_beta_free__[(sym1__ - 1)]);} + vars__.emplace_back(species_beta_mu); + vars__.emplace_back(species_beta_sigma_free__); + vars__.emplace_back(global_error_sigma_free__); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"ind_y_0", "ind_beta", - "species_beta_mu", "species_beta_sigma", - "global_error_sigma"}; - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) { - std::vector temp{"y_hat", "Delta_hat"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - n_ind)}, - std::vector{static_cast(n_ind)}, - std::vector{}, std::vector{}, - std::vector{}}; - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(n_obs)}, - std::vector{static_cast(n_obs)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { + } // transform_inits_impl() + + inline void get_param_names(std::vector& names__) const { + + names__.clear(); + names__.emplace_back("ind_y_0"); + names__.emplace_back("ind_beta"); + names__.emplace_back("species_beta_mu"); + names__.emplace_back("species_beta_sigma"); + names__.emplace_back("global_error_sigma"); + names__.emplace_back("y_hat"); + names__.emplace_back("Delta_hat"); + } // get_param_names() + + inline void get_dims(std::vector>& dimss__) const { + dimss__.clear(); + dimss__.emplace_back(std::vector{static_cast(n_ind)}); + + dimss__.emplace_back(std::vector{static_cast(n_ind)}); + + dimss__.emplace_back(std::vector{}); + + dimss__.emplace_back(std::vector{}); + + dimss__.emplace_back(std::vector{}); + + dimss__.emplace_back(std::vector{static_cast(n_obs)}); + + dimss__.emplace_back(std::vector{static_cast(n_obs)}); + + } // get_dims() + + inline void constrained_param_names( + std::vector& param_names__, + bool emit_transformed_parameters__ = true, + bool emit_generated_quantities__ = true) const + final { + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { - param_names__.emplace_back(std::string() + "ind_y_0" + '.' + - std::to_string(sym1__)); - } + { + param_names__.emplace_back(std::string() + "ind_y_0" + '.' + std::to_string(sym1__)); + }} for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { - param_names__.emplace_back(std::string() + "ind_beta" + '.' + - std::to_string(sym1__)); - } + { + param_names__.emplace_back(std::string() + "ind_beta" + '.' + std::to_string(sym1__)); + }} param_names__.emplace_back(std::string() + "species_beta_mu"); param_names__.emplace_back(std::string() + "species_beta_sigma"); param_names__.emplace_back(std::string() + "global_error_sigma"); - if (emit_transformed_parameters__) {} + if (emit_transformed_parameters__) { + + } + if (emit_generated_quantities__) { for (int sym1__ = 1; sym1__ <= n_obs; ++sym1__) { - param_names__.emplace_back(std::string() + "y_hat" + '.' + - std::to_string(sym1__)); - } + { + param_names__.emplace_back(std::string() + "y_hat" + '.' + std::to_string(sym1__)); + }} for (int sym1__ = 1; sym1__ <= n_obs; ++sym1__) { - param_names__.emplace_back(std::string() + "Delta_hat" + '.' + - std::to_string(sym1__)); - } + { + param_names__.emplace_back(std::string() + "Delta_hat" + '.' + std::to_string(sym1__)); + }} } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { + + } // constrained_param_names() + + inline void unconstrained_param_names( + std::vector& param_names__, + bool emit_transformed_parameters__ = true, + bool emit_generated_quantities__ = true) const + final { + for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { - param_names__.emplace_back(std::string() + "ind_y_0" + '.' + - std::to_string(sym1__)); - } + { + param_names__.emplace_back(std::string() + "ind_y_0" + '.' + std::to_string(sym1__)); + }} for (int sym1__ = 1; sym1__ <= n_ind; ++sym1__) { - param_names__.emplace_back(std::string() + "ind_beta" + '.' + - std::to_string(sym1__)); - } + { + param_names__.emplace_back(std::string() + "ind_beta" + '.' + std::to_string(sym1__)); + }} param_names__.emplace_back(std::string() + "species_beta_mu"); param_names__.emplace_back(std::string() + "species_beta_sigma"); param_names__.emplace_back(std::string() + "global_error_sigma"); - if (emit_transformed_parameters__) {} + if (emit_transformed_parameters__) { + + } + if (emit_generated_quantities__) { for (int sym1__ = 1; sym1__ <= n_obs; ++sym1__) { - param_names__.emplace_back(std::string() + "y_hat" + '.' + - std::to_string(sym1__)); - } + { + param_names__.emplace_back(std::string() + "y_hat" + '.' + std::to_string(sym1__)); + }} for (int sym1__ = 1; sym1__ <= n_obs; ++sym1__) { - param_names__.emplace_back(std::string() + "Delta_hat" + '.' + - std::to_string(sym1__)); - } + { + param_names__.emplace_back(std::string() + "Delta_hat" + '.' + std::to_string(sym1__)); + }} } - } + + } // unconstrained_param_names() + inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"ind_y_0\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(n_ind) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"ind_beta\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(n_ind) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"species_beta_mu\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"species_beta_sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"global_error_sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"y_hat\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(n_obs) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"},{\"name\":\"Delta_hat\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(n_obs) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"}]"); - } + stringstream s__; + s__ << "[{\"name\":\"ind_y_0\",\"type\":{\"name\":\"array\",\"length\":" << n_ind << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"ind_beta\",\"type\":{\"name\":\"array\",\"length\":" << n_ind << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"species_beta_mu\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"species_beta_sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"global_error_sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"y_hat\",\"type\":{\"name\":\"array\",\"length\":" << n_obs << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"},{\"name\":\"Delta_hat\",\"type\":{\"name\":\"array\",\"length\":" << n_obs << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"}]"; + return s__.str(); + } // get_constrained_sizedtypes() + inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"ind_y_0\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(n_ind) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"ind_beta\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(n_ind) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"species_beta_mu\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"species_beta_sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"global_error_sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"y_hat\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(n_obs) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"},{\"name\":\"Delta_hat\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(n_obs) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((((n_ind + n_ind) + 1) + 1) + 1); - const size_t num_transformed = emit_transformed_parameters * (0); - const size_t num_gen_quantities = emit_generated_quantities * ((n_obs + - n_obs)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((((n_ind + n_ind) + 1) + 1) + 1); - const size_t num_transformed = emit_transformed_parameters * (0); - const size_t num_gen_quantities = emit_generated_quantities * ((n_obs + - n_obs)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } + stringstream s__; + s__ << "[{\"name\":\"ind_y_0\",\"type\":{\"name\":\"array\",\"length\":" << n_ind << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"ind_beta\",\"type\":{\"name\":\"array\",\"length\":" << n_ind << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"species_beta_mu\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"species_beta_sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"global_error_sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"y_hat\",\"type\":{\"name\":\"array\",\"length\":" << n_obs << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"},{\"name\":\"Delta_hat\",\"type\":{\"name\":\"array\",\"length\":" << n_obs << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"}]"; + return s__.str(); + } // get_unconstrained_sizedtypes() + + + // Begin method overload boilerplate + template + inline void write_array(RNG& base_rng, + Eigen::Matrix& params_r, + Eigen::Matrix& vars, + const bool emit_transformed_parameters = true, + const bool emit_generated_quantities = true, + std::ostream* pstream = nullptr) const { + std::vector vars_vec(vars.size()); + std::vector params_i; + write_array_impl(base_rng, params_r, params_i, vars_vec, + emit_transformed_parameters, emit_generated_quantities, pstream); + vars.resize(vars_vec.size()); + for (int i = 0; i < vars.size(); ++i) { + vars.coeffRef(i) = vars_vec[i]; + } + } + template + inline void write_array(RNG& base_rng, std::vector& params_r, + std::vector& params_i, + std::vector& vars, + bool emit_transformed_parameters = true, + bool emit_generated_quantities = true, + std::ostream* pstream = nullptr) const { + write_array_impl(base_rng, params_r, params_i, vars, emit_transformed_parameters, emit_generated_quantities, pstream); + } + template + inline T_ log_prob(Eigen::Matrix& params_r, + std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template + inline T__ log_prob(std::vector& params_r, + std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + + inline void transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, + std::ostream* pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits_impl(context, params_i, params_r_vec, pstream); + params_r.resize(params_r_vec.size()); + for (int i = 0; i < params_r.size(); ++i) { + params_r.coeffRef(i) = params_r_vec[i]; + } + } + inline void transform_inits(const stan::io::var_context& context, + std::vector& params_i, + std::vector& vars, + std::ostream* pstream = nullptr) const final { + transform_inits_impl(context, params_i, vars, pstream); + } }; } using stan_model = model_constant_multi_ind_namespace::model_constant_multi_ind; #ifndef USING_R // Boilerplate -stan::model::model_base& -new_model(stan::io::var_context& data_context, unsigned int seed, - std::ostream* msg_stream) { +stan::model::model_base& new_model( + stan::io::var_context& data_context, + unsigned int seed, + std::ostream* msg_stream) { stan_model* m = new stan_model(data_context, seed, msg_stream); return *m; } diff --git a/src/stanExports_constant_single_ind.h b/src/stanExports_constant_single_ind.h index c97f444..a88757d 100644 --- a/src/stanExports_constant_single_ind.h +++ b/src/stanExports_constant_single_ind.h @@ -21,82 +21,132 @@ #define USE_STANC3 #endif #include -// Code generated by stanc v2.32.2 +// Code generated by stanc v2.26.1-4-gd72b68b7-dirty #include namespace model_constant_single_ind_namespace { +inline void validate_positive_index(const char* var_name, const char* expr, + int val) { + if (val < 1) { + std::stringstream msg; + msg << "Found dimension size less than one in simplex declaration" + << "; variable=" << var_name << "; dimension size expression=" << expr + << "; expression value=" << val; + std::string msg_str(msg.str()); + throw std::invalid_argument(msg_str.c_str()); + } +} +inline void validate_unit_vector_index(const char* var_name, const char* expr, + int val) { + if (val <= 1) { + std::stringstream msg; + if (val == 1) { + msg << "Found dimension size one in unit vector declaration." + << " One-dimensional unit vector is discrete" + << " but the target distribution must be continuous." + << " variable=" << var_name << "; dimension size expression=" << expr; + } else { + msg << "Found dimension size less than one in unit vector declaration" + << "; variable=" << var_name << "; dimension size expression=" << expr + << "; expression value=" << val; + } + std::string msg_str(msg.str()); + throw std::invalid_argument(msg_str.c_str()); + } +} +using std::istream; +using std::string; +using std::stringstream; +using std::vector; +using std::pow; +using stan::io::dump; +using stan::math::lgamma; using stan::model::model_base_crtp; +using stan::model::rvalue; +using stan::model::cons_list; +using stan::model::index_uni; +using stan::model::index_max; +using stan::model::index_min; +using stan::model::index_min_max; +using stan::model::index_multi; +using stan::model::index_omni; +using stan::model::nil_index_list; using namespace stan::math; +using stan::math::pow; stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'constant_single_ind', line 19, column 2 to column 24)", - " (in 'constant_single_ind', line 20, column 2 to column 25)", - " (in 'constant_single_ind', line 22, column 2 to column 35)", - " (in 'constant_single_ind', line 48, column 2 to column 20)", - " (in 'constant_single_ind', line 49, column 2 to column 24)", - " (in 'constant_single_ind', line 52, column 6 to column 25)", - " (in 'constant_single_ind', line 51, column 23 to line 53, column 5)", - " (in 'constant_single_ind', line 51, column 4 to line 53, column 5)", - " (in 'constant_single_ind', line 54, column 4 to column 46)", - " (in 'constant_single_ind', line 56, column 6 to column 63)", - " (in 'constant_single_ind', line 55, column 17 to line 57, column 5)", - " (in 'constant_single_ind', line 55, column 4 to line 57, column 5)", - " (in 'constant_single_ind', line 50, column 19 to line 58, column 3)", - " (in 'constant_single_ind', line 50, column 2 to line 58, column 3)", - " (in 'constant_single_ind', line 26, column 13 to column 18)", - " (in 'constant_single_ind', line 26, column 2 to column 20)", - " (in 'constant_single_ind', line 27, column 17 to column 22)", - " (in 'constant_single_ind', line 27, column 2 to column 24)", - " (in 'constant_single_ind', line 30, column 6 to column 25)", - " (in 'constant_single_ind', line 29, column 23 to line 31, column 5)", - " (in 'constant_single_ind', line 29, column 4 to line 31, column 5)", - " (in 'constant_single_ind', line 32, column 4 to column 46)", - " (in 'constant_single_ind', line 34, column 6 to column 63)", - " (in 'constant_single_ind', line 33, column 17 to line 35, column 5)", - " (in 'constant_single_ind', line 33, column 4 to line 35, column 5)", - " (in 'constant_single_ind', line 28, column 19 to line 36, column 3)", - " (in 'constant_single_ind', line 28, column 2 to line 36, column 3)", - " (in 'constant_single_ind', line 38, column 2 to column 44)", - " (in 'constant_single_ind', line 41, column 2 to column 48)", - " (in 'constant_single_ind', line 42, column 2 to column 31)", - " (in 'constant_single_ind', line 44, column 2 to column 37)", - " (in 'constant_single_ind', line 10, column 2 to column 12)", - " (in 'constant_single_ind', line 11, column 13 to column 18)", - " (in 'constant_single_ind', line 11, column 2 to column 20)", - " (in 'constant_single_ind', line 12, column 16 to column 21)", - " (in 'constant_single_ind', line 12, column 2 to column 23)", - " (in 'constant_single_ind', line 13, column 12 to column 17)", - " (in 'constant_single_ind', line 13, column 2 to column 19)", - " (in 'constant_single_ind', line 14, column 2 to column 15)", - " (in 'constant_single_ind', line 48, column 13 to column 18)", - " (in 'constant_single_ind', line 49, column 17 to column 22)", - " (in 'constant_single_ind', line 5, column 4 to column 16)", - " (in 'constant_single_ind', line 4, column 32 to line 6, column 3)"}; -template , - stan::is_stan_scalar>* = nullptr> -stan::promote_args_t -growth(const T0__& y, const T1__& beta, std::ostream* pstream__); -template , - stan::is_stan_scalar>*> -stan::promote_args_t +static int current_statement__= 0; +static const std::vector locations_array__ = {" (found before start of program)", + " (in 'constant_single_ind', line 19, column 2 to column 24)", + " (in 'constant_single_ind', line 20, column 2 to column 25)", + " (in 'constant_single_ind', line 22, column 2 to column 35)", + " (in 'constant_single_ind', line 48, column 2 to column 20)", + " (in 'constant_single_ind', line 49, column 2 to column 24)", + " (in 'constant_single_ind', line 52, column 6 to column 25)", + " (in 'constant_single_ind', line 51, column 23 to line 53, column 5)", + " (in 'constant_single_ind', line 51, column 4 to line 53, column 5)", + " (in 'constant_single_ind', line 54, column 4 to column 46)", + " (in 'constant_single_ind', line 56, column 6 to column 63)", + " (in 'constant_single_ind', line 55, column 17 to line 57, column 5)", + " (in 'constant_single_ind', line 55, column 4 to line 57, column 5)", + " (in 'constant_single_ind', line 50, column 19 to line 58, column 3)", + " (in 'constant_single_ind', line 50, column 2 to line 58, column 3)", + " (in 'constant_single_ind', line 26, column 13 to column 18)", + " (in 'constant_single_ind', line 26, column 2 to column 20)", + " (in 'constant_single_ind', line 27, column 17 to column 22)", + " (in 'constant_single_ind', line 27, column 2 to column 24)", + " (in 'constant_single_ind', line 30, column 6 to column 25)", + " (in 'constant_single_ind', line 29, column 23 to line 31, column 5)", + " (in 'constant_single_ind', line 29, column 4 to line 31, column 5)", + " (in 'constant_single_ind', line 32, column 4 to column 46)", + " (in 'constant_single_ind', line 34, column 6 to column 63)", + " (in 'constant_single_ind', line 33, column 17 to line 35, column 5)", + " (in 'constant_single_ind', line 33, column 4 to line 35, column 5)", + " (in 'constant_single_ind', line 28, column 19 to line 36, column 3)", + " (in 'constant_single_ind', line 28, column 2 to line 36, column 3)", + " (in 'constant_single_ind', line 38, column 2 to column 44)", + " (in 'constant_single_ind', line 41, column 2 to column 48)", + " (in 'constant_single_ind', line 42, column 2 to column 31)", + " (in 'constant_single_ind', line 44, column 2 to column 37)", + " (in 'constant_single_ind', line 10, column 2 to column 12)", + " (in 'constant_single_ind', line 11, column 13 to column 18)", + " (in 'constant_single_ind', line 11, column 2 to column 20)", + " (in 'constant_single_ind', line 12, column 16 to column 21)", + " (in 'constant_single_ind', line 12, column 2 to column 23)", + " (in 'constant_single_ind', line 13, column 12 to column 17)", + " (in 'constant_single_ind', line 13, column 2 to column 19)", + " (in 'constant_single_ind', line 14, column 2 to column 15)", + " (in 'constant_single_ind', line 48, column 13 to column 18)", + " (in 'constant_single_ind', line 49, column 17 to column 22)", + " (in 'constant_single_ind', line 5, column 4 to column 16)", + " (in 'constant_single_ind', line 4, column 32 to line 6, column 3)"}; +template +stan::promote_args_t growth(const T0__& y, const T1__& beta, std::ostream* pstream__) { using local_scalar_t__ = stan::promote_args_t; - int current_statement__ = 0; - static constexpr bool propto__ = true; - // suppress unused var warning + const static bool propto__ = true; (void) propto__; local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; + (void) DUMMY_VAR__; // suppress unused var warning + try { current_statement__ = 42; return beta; } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); } + +} +struct growth_functor__ { +template +stan::promote_args_t +operator()(const T0__& y, const T1__& beta, std::ostream* pstream__) const +{ +return growth(y, beta, pstream__); } +}; #include class model_constant_single_ind final : public model_base_crtp { private: @@ -105,496 +155,498 @@ class model_constant_single_ind final : public model_base_crtp obs_index; std::vector time; double y_0_obs; + public: - ~model_constant_single_ind() {} - model_constant_single_ind(stan::io::var_context& context__, unsigned int - random_seed__ = 0, std::ostream* - pstream__ = nullptr) : model_base_crtp(0) { - int current_statement__ = 0; - using local_scalar_t__ = double; - boost::ecuyer1988 base_rng__ = - stan::services::util::create_rng(random_seed__, 0); - // suppress unused var warning - (void) base_rng__; - static constexpr const char* function__ = - "model_constant_single_ind_namespace::model_constant_single_ind"; - // suppress unused var warning - (void) function__; + ~model_constant_single_ind() { } + + inline std::string model_name() const final { return "model_constant_single_ind"; } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.26.1-4-gd72b68b7-dirty", "stancflags = "}; + } + + + model_constant_single_ind(stan::io::var_context& context__, + unsigned int random_seed__ = 0, + std::ostream* pstream__ = nullptr) : model_base_crtp(0) { + using local_scalar_t__ = double ; + boost::ecuyer1988 base_rng__ = + stan::services::util::create_rng(random_seed__, 0); + (void) base_rng__; // suppress unused var warning + static const char* function__ = "model_constant_single_ind_namespace::model_constant_single_ind"; + (void) function__; // suppress unused var warning local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; + (void) DUMMY_VAR__; // suppress unused var warning + try { - int pos__ = std::numeric_limits::min(); + int pos__; + pos__ = std::numeric_limits::min(); + pos__ = 1; current_statement__ = 32; - context__.validate_dims("data initialization", "n_obs", "int", - std::vector{}); + context__.validate_dims("data initialization","n_obs","int", + context__.to_vec()); n_obs = std::numeric_limits::min(); + current_statement__ = 32; n_obs = context__.vals_i("n_obs")[(1 - 1)]; current_statement__ = 33; - stan::math::validate_non_negative_index("y_obs", "n_obs", n_obs); + validate_non_negative_index("y_obs", "n_obs", n_obs); current_statement__ = 34; - context__.validate_dims("data initialization", "y_obs", "double", - std::vector{static_cast(n_obs)}); - y_obs = std::vector(n_obs, - std::numeric_limits::quiet_NaN()); + context__.validate_dims("data initialization","y_obs","double", + context__.to_vec(n_obs)); + y_obs = std::vector(n_obs, std::numeric_limits::quiet_NaN()); + current_statement__ = 34; - y_obs = context__.vals_r("y_obs"); + assign(y_obs, nil_index_list(), context__.vals_r("y_obs"), + "assigning variable y_obs"); current_statement__ = 35; - stan::math::validate_non_negative_index("obs_index", "n_obs", n_obs); + validate_non_negative_index("obs_index", "n_obs", n_obs); current_statement__ = 36; - context__.validate_dims("data initialization", "obs_index", "int", - std::vector{static_cast(n_obs)}); + context__.validate_dims("data initialization","obs_index","int", + context__.to_vec(n_obs)); obs_index = std::vector(n_obs, std::numeric_limits::min()); + current_statement__ = 36; - obs_index = context__.vals_i("obs_index"); + assign(obs_index, nil_index_list(), context__.vals_i("obs_index"), + "assigning variable obs_index"); current_statement__ = 37; - stan::math::validate_non_negative_index("time", "n_obs", n_obs); + validate_non_negative_index("time", "n_obs", n_obs); current_statement__ = 38; - context__.validate_dims("data initialization", "time", "double", - std::vector{static_cast(n_obs)}); - time = std::vector(n_obs, - std::numeric_limits::quiet_NaN()); + context__.validate_dims("data initialization","time","double", + context__.to_vec(n_obs)); + time = std::vector(n_obs, std::numeric_limits::quiet_NaN()); + current_statement__ = 38; - time = context__.vals_r("time"); + assign(time, nil_index_list(), context__.vals_r("time"), + "assigning variable time"); current_statement__ = 39; - context__.validate_dims("data initialization", "y_0_obs", "double", - std::vector{}); + context__.validate_dims("data initialization","y_0_obs","double", + context__.to_vec()); y_0_obs = std::numeric_limits::quiet_NaN(); + current_statement__ = 39; y_0_obs = context__.vals_r("y_0_obs")[(1 - 1)]; current_statement__ = 40; - stan::math::validate_non_negative_index("y_hat", "n_obs", n_obs); + validate_non_negative_index("y_hat", "n_obs", n_obs); current_statement__ = 41; - stan::math::validate_non_negative_index("Delta_hat", "n_obs", n_obs); + validate_non_negative_index("Delta_hat", "n_obs", n_obs); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); + } + num_params_r__ = 0U; + + try { + num_params_r__ += 1; + num_params_r__ += 1; + num_params_r__ += 1; + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); } - num_params_r__ = 1 + 1 + 1; - } - inline std::string model_name() const final { - return "model_constant_single_ind"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { + template * = nullptr, stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t log_prob_impl(VecR& params_r__, + VecI& params_i__, + std::ostream* pstream__ = nullptr) const { using T__ = stan::scalar_type_t; using local_scalar_t__ = T__; T__ lp__(0.0); stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; + static const char* function__ = "model_constant_single_ind_namespace::log_prob"; +(void) function__; // suppress unused var warning + stan::io::reader in__(params_r__, params_i__); local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_constant_single_ind_namespace::log_prob"; - // suppress unused var warning - (void) function__; + (void) DUMMY_VAR__; // suppress unused var warning + try { - local_scalar_t__ ind_y_0 = DUMMY_VAR__; + local_scalar_t__ ind_y_0; + ind_y_0 = DUMMY_VAR__; + + current_statement__ = 1; + ind_y_0 = in__.scalar(); current_statement__ = 1; - ind_y_0 = in__.template read_constrain_lb(0, lp__); - local_scalar_t__ ind_beta = DUMMY_VAR__; + if (jacobian__) { + current_statement__ = 1; + ind_y_0 = stan::math::lb_constrain(ind_y_0, 0, lp__); + } else { + current_statement__ = 1; + ind_y_0 = stan::math::lb_constrain(ind_y_0, 0); + } + local_scalar_t__ ind_beta; + ind_beta = DUMMY_VAR__; + current_statement__ = 2; - ind_beta = in__.template read_constrain_lb(0, lp__); - local_scalar_t__ global_error_sigma = DUMMY_VAR__; + ind_beta = in__.scalar(); + current_statement__ = 2; + if (jacobian__) { + current_statement__ = 2; + ind_beta = stan::math::lb_constrain(ind_beta, 0, lp__); + } else { + current_statement__ = 2; + ind_beta = stan::math::lb_constrain(ind_beta, 0); + } + local_scalar_t__ global_error_sigma; + global_error_sigma = DUMMY_VAR__; + current_statement__ = 3; - global_error_sigma = in__.template read_constrain_lb(0, lp__); + global_error_sigma = in__.scalar(); + current_statement__ = 3; + if (jacobian__) { + current_statement__ = 3; + global_error_sigma = stan::math::lb_constrain(global_error_sigma, 0, + lp__); + } else { + current_statement__ = 3; + global_error_sigma = stan::math::lb_constrain(global_error_sigma, 0); + } { current_statement__ = 15; - stan::math::validate_non_negative_index("y_hat", "n_obs", n_obs); - std::vector y_hat = - std::vector(n_obs, DUMMY_VAR__); + validate_non_negative_index("y_hat", "n_obs", n_obs); + std::vector y_hat; + y_hat = std::vector(n_obs, DUMMY_VAR__); + current_statement__ = 17; - stan::math::validate_non_negative_index("Delta_hat", "n_obs", n_obs); - std::vector Delta_hat = - std::vector(n_obs, DUMMY_VAR__); + validate_non_negative_index("Delta_hat", "n_obs", n_obs); + std::vector Delta_hat; + Delta_hat = std::vector(n_obs, DUMMY_VAR__); + current_statement__ = 27; for (int i = 1; i <= n_obs; ++i) { current_statement__ = 21; - if (stan::math::logical_eq( - stan::model::rvalue(obs_index, "obs_index", - stan::model::index_uni(i)), 1)) { + if (logical_eq(obs_index[(i - 1)], 1)) { current_statement__ = 19; - stan::model::assign(y_hat, ind_y_0, "assigning variable y_hat", - stan::model::index_uni(i)); - } + assign(y_hat, cons_list(index_uni(i), nil_index_list()), ind_y_0, + "assigning variable y_hat"); + } current_statement__ = 22; - stan::model::assign(Delta_hat, - growth( - stan::model::rvalue(y_hat, "y_hat", stan::model::index_uni(i)), - ind_beta, pstream__), "assigning variable Delta_hat", - stan::model::index_uni(i)); + assign(Delta_hat, cons_list(index_uni(i), nil_index_list()), + growth(y_hat[(i - 1)], ind_beta, pstream__), + "assigning variable Delta_hat"); current_statement__ = 25; - if (stan::math::logical_lt(i, n_obs)) { + if (logical_lt(i, n_obs)) { current_statement__ = 23; - stan::model::assign(y_hat, - (stan::model::rvalue(y_hat, "y_hat", stan::model::index_uni(i)) - + - (stan::model::rvalue(Delta_hat, "Delta_hat", - stan::model::index_uni(i)) * - (stan::model::rvalue(time, "time", - stan::model::index_uni((i + 1))) - - stan::model::rvalue(time, "time", stan::model::index_uni(i))))), - "assigning variable y_hat", stan::model::index_uni((i + 1))); - } - } + assign(y_hat, cons_list(index_uni((i + 1)), nil_index_list()), + (y_hat[(i - 1)] + + (Delta_hat[(i - 1)] * (time[((i + 1) - 1)] - time[(i - 1)]))), + "assigning variable y_hat"); + } } current_statement__ = 28; - lp_accum__.add(stan::math::normal_lpdf(y_obs, y_hat, - global_error_sigma)); + lp_accum__.add( + normal_lpdf(y_obs, y_hat, global_error_sigma)); current_statement__ = 29; - lp_accum__.add(stan::math::normal_lpdf(ind_y_0, y_0_obs, - global_error_sigma)); + lp_accum__.add( + normal_lpdf(ind_y_0, y_0_obs, global_error_sigma)); current_statement__ = 30; - lp_accum__.add(stan::math::lognormal_lpdf(ind_beta, 0.1, 1)); + lp_accum__.add(lognormal_lpdf(ind_beta, 0.1, 1)); current_statement__ = 31; - lp_accum__.add(stan::math::cauchy_lpdf(global_error_sigma, - 0.1, 1)); + lp_accum__.add(cauchy_lpdf(global_error_sigma, 0.1, 1)); } } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); } lp_accum__.add(lp__); return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { + } // log_prob_impl() + + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_std_vector_vt* = nullptr> + inline void write_array_impl(RNG& base_rng__, VecR& params_r__, + VecI& params_i__, VecVar& vars__, + const bool emit_transformed_parameters__ = true, + const bool emit_generated_quantities__ = true, + std::ostream* pstream__ = nullptr) const { using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - static constexpr bool propto__ = true; - // suppress unused var warning - (void) propto__; + vars__.resize(0); + stan::io::reader in__(params_r__, params_i__); + static const char* function__ = "model_constant_single_ind_namespace::write_array"; +(void) function__; // suppress unused var warning + (void) function__; // suppress unused var warning double lp__ = 0.0; - // suppress unused var warning - (void) lp__; - int current_statement__ = 0; + (void) lp__; // dummy to suppress unused var warning stan::math::accumulator lp_accum__; local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_constant_single_ind_namespace::write_array"; - // suppress unused var warning - (void) function__; + (void) DUMMY_VAR__; // suppress unused var warning + try { - double ind_y_0 = std::numeric_limits::quiet_NaN(); + double ind_y_0; + ind_y_0 = std::numeric_limits::quiet_NaN(); + current_statement__ = 1; - ind_y_0 = in__.template read_constrain_lb(0, lp__); - double ind_beta = std::numeric_limits::quiet_NaN(); + ind_y_0 = in__.scalar(); + current_statement__ = 1; + ind_y_0 = stan::math::lb_constrain(ind_y_0, 0); + double ind_beta; + ind_beta = std::numeric_limits::quiet_NaN(); + + current_statement__ = 2; + ind_beta = in__.scalar(); current_statement__ = 2; - ind_beta = in__.template read_constrain_lb(0, lp__); - double global_error_sigma = std::numeric_limits::quiet_NaN(); + ind_beta = stan::math::lb_constrain(ind_beta, 0); + double global_error_sigma; + global_error_sigma = std::numeric_limits::quiet_NaN(); + + current_statement__ = 3; + global_error_sigma = in__.scalar(); current_statement__ = 3; - global_error_sigma = in__.template read_constrain_lb(0, lp__); - out__.write(ind_y_0); - out__.write(ind_beta); - out__.write(global_error_sigma); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { + global_error_sigma = stan::math::lb_constrain(global_error_sigma, 0); + vars__.emplace_back(ind_y_0); + vars__.emplace_back(ind_beta); + vars__.emplace_back(global_error_sigma); + if (logical_negation((primitive_value(emit_transformed_parameters__) || + primitive_value(emit_generated_quantities__)))) { return ; - } - if (stan::math::logical_negation(emit_generated_quantities__)) { + } + if (logical_negation(emit_generated_quantities__)) { return ; - } - std::vector y_hat = - std::vector(n_obs, std::numeric_limits::quiet_NaN()); - std::vector Delta_hat = - std::vector(n_obs, std::numeric_limits::quiet_NaN()); + } + std::vector y_hat; + y_hat = std::vector(n_obs, std::numeric_limits::quiet_NaN()); + + std::vector Delta_hat; + Delta_hat = std::vector(n_obs, std::numeric_limits::quiet_NaN()); + current_statement__ = 14; for (int i = 1; i <= n_obs; ++i) { current_statement__ = 8; - if (stan::math::logical_eq( - stan::model::rvalue(obs_index, "obs_index", - stan::model::index_uni(i)), 1)) { + if (logical_eq(obs_index[(i - 1)], 1)) { current_statement__ = 6; - stan::model::assign(y_hat, ind_y_0, "assigning variable y_hat", - stan::model::index_uni(i)); - } + assign(y_hat, cons_list(index_uni(i), nil_index_list()), ind_y_0, + "assigning variable y_hat"); + } current_statement__ = 9; - stan::model::assign(Delta_hat, - growth( - stan::model::rvalue(y_hat, "y_hat", stan::model::index_uni(i)), - ind_beta, pstream__), "assigning variable Delta_hat", - stan::model::index_uni(i)); + assign(Delta_hat, cons_list(index_uni(i), nil_index_list()), + growth(y_hat[(i - 1)], ind_beta, pstream__), + "assigning variable Delta_hat"); current_statement__ = 12; - if (stan::math::logical_lt(i, n_obs)) { + if (logical_lt(i, n_obs)) { current_statement__ = 10; - stan::model::assign(y_hat, - (stan::model::rvalue(y_hat, "y_hat", stan::model::index_uni(i)) + - (stan::model::rvalue(Delta_hat, "Delta_hat", - stan::model::index_uni(i)) * - (stan::model::rvalue(time, "time", - stan::model::index_uni((i + 1))) - - stan::model::rvalue(time, "time", stan::model::index_uni(i))))), - "assigning variable y_hat", stan::model::index_uni((i + 1))); - } - } - out__.write(y_hat); - out__.write(Delta_hat); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline void - unconstrain_array_impl(const VecVar& params_r__, const VecI& params_i__, - VecVar& vars__, std::ostream* pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - local_scalar_t__ ind_y_0 = DUMMY_VAR__; - current_statement__ = 1; - ind_y_0 = in__.read(); - out__.write_free_lb(0, ind_y_0); - local_scalar_t__ ind_beta = DUMMY_VAR__; - current_statement__ = 2; - ind_beta = in__.read(); - out__.write_free_lb(0, ind_beta); - local_scalar_t__ global_error_sigma = DUMMY_VAR__; - current_statement__ = 3; - global_error_sigma = in__.read(); - out__.write_free_lb(0, global_error_sigma); + assign(y_hat, cons_list(index_uni((i + 1)), nil_index_list()), + (y_hat[(i - 1)] + + (Delta_hat[(i - 1)] * (time[((i + 1) - 1)] - time[(i - 1)]))), + "assigning variable y_hat"); + } } + for (int sym1__ = 1; sym1__ <= n_obs; ++sym1__) { + vars__.emplace_back(y_hat[(sym1__ - 1)]);} + for (int sym1__ = 1; sym1__ <= n_obs; ++sym1__) { + vars__.emplace_back(Delta_hat[(sym1__ - 1)]);} } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); } - } - template * = nullptr> - inline void - transform_inits_impl(const stan::io::var_context& context__, VecVar& - vars__, std::ostream* pstream__ = nullptr) const { + } // write_array_impl() + + template * = nullptr, stan::require_vector_like_vt* = nullptr> + inline void transform_inits_impl(const stan::io::var_context& context__, + VecI& params_i__, VecVar& vars__, + std::ostream* pstream__ = nullptr) const { using local_scalar_t__ = double; - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; + vars__.clear(); + vars__.reserve(num_params_r__); + try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "ind_y_0", - "double", std::vector{}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "ind_beta", - "double", std::vector{}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", - "global_error_sigma", "double", std::vector{}); - int pos__ = std::numeric_limits::min(); + int pos__; + pos__ = std::numeric_limits::min(); + pos__ = 1; - local_scalar_t__ ind_y_0 = DUMMY_VAR__; + double ind_y_0; + ind_y_0 = std::numeric_limits::quiet_NaN(); + current_statement__ = 1; ind_y_0 = context__.vals_r("ind_y_0")[(1 - 1)]; - out__.write_free_lb(0, ind_y_0); - local_scalar_t__ ind_beta = DUMMY_VAR__; + double ind_y_0_free__; + ind_y_0_free__ = std::numeric_limits::quiet_NaN(); + + current_statement__ = 1; + ind_y_0_free__ = stan::math::lb_free(ind_y_0, 0); + double ind_beta; + ind_beta = std::numeric_limits::quiet_NaN(); + current_statement__ = 2; ind_beta = context__.vals_r("ind_beta")[(1 - 1)]; - out__.write_free_lb(0, ind_beta); - local_scalar_t__ global_error_sigma = DUMMY_VAR__; + double ind_beta_free__; + ind_beta_free__ = std::numeric_limits::quiet_NaN(); + + current_statement__ = 2; + ind_beta_free__ = stan::math::lb_free(ind_beta, 0); + double global_error_sigma; + global_error_sigma = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; global_error_sigma = context__.vals_r("global_error_sigma")[(1 - 1)]; - out__.write_free_lb(0, global_error_sigma); + double global_error_sigma_free__; + global_error_sigma_free__ = std::numeric_limits::quiet_NaN(); + + current_statement__ = 3; + global_error_sigma_free__ = stan::math::lb_free(global_error_sigma, 0); + vars__.emplace_back(ind_y_0_free__); + vars__.emplace_back(ind_beta_free__); + vars__.emplace_back(global_error_sigma_free__); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"ind_y_0", "ind_beta", - "global_error_sigma"}; - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) { - std::vector temp{"y_hat", "Delta_hat"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{}, - std::vector{}, std::vector{}}; - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(n_obs)}, - std::vector{static_cast(n_obs)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { + } // transform_inits_impl() + + inline void get_param_names(std::vector& names__) const { + + names__.clear(); + names__.emplace_back("ind_y_0"); + names__.emplace_back("ind_beta"); + names__.emplace_back("global_error_sigma"); + names__.emplace_back("y_hat"); + names__.emplace_back("Delta_hat"); + } // get_param_names() + + inline void get_dims(std::vector>& dimss__) const { + dimss__.clear(); + dimss__.emplace_back(std::vector{}); + + dimss__.emplace_back(std::vector{}); + + dimss__.emplace_back(std::vector{}); + + dimss__.emplace_back(std::vector{static_cast(n_obs)}); + + dimss__.emplace_back(std::vector{static_cast(n_obs)}); + + } // get_dims() + + inline void constrained_param_names( + std::vector& param_names__, + bool emit_transformed_parameters__ = true, + bool emit_generated_quantities__ = true) const + final { + param_names__.emplace_back(std::string() + "ind_y_0"); param_names__.emplace_back(std::string() + "ind_beta"); param_names__.emplace_back(std::string() + "global_error_sigma"); - if (emit_transformed_parameters__) {} + if (emit_transformed_parameters__) { + + } + if (emit_generated_quantities__) { for (int sym1__ = 1; sym1__ <= n_obs; ++sym1__) { - param_names__.emplace_back(std::string() + "y_hat" + '.' + - std::to_string(sym1__)); - } + { + param_names__.emplace_back(std::string() + "y_hat" + '.' + std::to_string(sym1__)); + }} for (int sym1__ = 1; sym1__ <= n_obs; ++sym1__) { - param_names__.emplace_back(std::string() + "Delta_hat" + '.' + - std::to_string(sym1__)); - } + { + param_names__.emplace_back(std::string() + "Delta_hat" + '.' + std::to_string(sym1__)); + }} } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { + + } // constrained_param_names() + + inline void unconstrained_param_names( + std::vector& param_names__, + bool emit_transformed_parameters__ = true, + bool emit_generated_quantities__ = true) const + final { + param_names__.emplace_back(std::string() + "ind_y_0"); param_names__.emplace_back(std::string() + "ind_beta"); param_names__.emplace_back(std::string() + "global_error_sigma"); - if (emit_transformed_parameters__) {} + if (emit_transformed_parameters__) { + + } + if (emit_generated_quantities__) { for (int sym1__ = 1; sym1__ <= n_obs; ++sym1__) { - param_names__.emplace_back(std::string() + "y_hat" + '.' + - std::to_string(sym1__)); - } + { + param_names__.emplace_back(std::string() + "y_hat" + '.' + std::to_string(sym1__)); + }} for (int sym1__ = 1; sym1__ <= n_obs; ++sym1__) { - param_names__.emplace_back(std::string() + "Delta_hat" + '.' + - std::to_string(sym1__)); - } + { + param_names__.emplace_back(std::string() + "Delta_hat" + '.' + std::to_string(sym1__)); + }} } - } + + } // unconstrained_param_names() + inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"ind_y_0\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"ind_beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"global_error_sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"y_hat\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(n_obs) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"},{\"name\":\"Delta_hat\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(n_obs) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"}]"); - } + stringstream s__; + s__ << "[{\"name\":\"ind_y_0\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"ind_beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"global_error_sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"y_hat\",\"type\":{\"name\":\"array\",\"length\":" << n_obs << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"},{\"name\":\"Delta_hat\",\"type\":{\"name\":\"array\",\"length\":" << n_obs << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"}]"; + return s__.str(); + } // get_constrained_sizedtypes() + inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"ind_y_0\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"ind_beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"global_error_sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"y_hat\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(n_obs) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"},{\"name\":\"Delta_hat\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(n_obs) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((1 + 1) + 1); - const size_t num_transformed = emit_transformed_parameters * (0); - const size_t num_gen_quantities = emit_generated_quantities * ((n_obs + - n_obs)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((1 + 1) + 1); - const size_t num_transformed = emit_transformed_parameters * (0); - const size_t num_gen_quantities = emit_generated_quantities * ((n_obs + - n_obs)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } + stringstream s__; + s__ << "[{\"name\":\"ind_y_0\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"ind_beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"global_error_sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"y_hat\",\"type\":{\"name\":\"array\",\"length\":" << n_obs << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"},{\"name\":\"Delta_hat\",\"type\":{\"name\":\"array\",\"length\":" << n_obs << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"generated_quantities\"}]"; + return s__.str(); + } // get_unconstrained_sizedtypes() + + + // Begin method overload boilerplate + template + inline void write_array(RNG& base_rng, + Eigen::Matrix& params_r, + Eigen::Matrix& vars, + const bool emit_transformed_parameters = true, + const bool emit_generated_quantities = true, + std::ostream* pstream = nullptr) const { + std::vector vars_vec(vars.size()); + std::vector params_i; + write_array_impl(base_rng, params_r, params_i, vars_vec, + emit_transformed_parameters, emit_generated_quantities, pstream); + vars.resize(vars_vec.size()); + for (int i = 0; i < vars.size(); ++i) { + vars.coeffRef(i) = vars_vec[i]; + } + } + template + inline void write_array(RNG& base_rng, std::vector& params_r, + std::vector& params_i, + std::vector& vars, + bool emit_transformed_parameters = true, + bool emit_generated_quantities = true, + std::ostream* pstream = nullptr) const { + write_array_impl(base_rng, params_r, params_i, vars, emit_transformed_parameters, emit_generated_quantities, pstream); + } + template + inline T_ log_prob(Eigen::Matrix& params_r, + std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template + inline T__ log_prob(std::vector& params_r, + std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + + inline void transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, + std::ostream* pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits_impl(context, params_i, params_r_vec, pstream); + params_r.resize(params_r_vec.size()); + for (int i = 0; i < params_r.size(); ++i) { + params_r.coeffRef(i) = params_r_vec[i]; + } + } + inline void transform_inits(const stan::io::var_context& context, + std::vector& params_i, + std::vector& vars, + std::ostream* pstream = nullptr) const final { + transform_inits_impl(context, params_i, vars, pstream); + } }; } using stan_model = model_constant_single_ind_namespace::model_constant_single_ind; #ifndef USING_R // Boilerplate -stan::model::model_base& -new_model(stan::io::var_context& data_context, unsigned int seed, - std::ostream* msg_stream) { +stan::model::model_base& new_model( + stan::io::var_context& data_context, + unsigned int seed, + std::ostream* msg_stream) { stan_model* m = new stan_model(data_context, seed, msg_stream); return *m; } diff --git a/src/stanExports_linear.h b/src/stanExports_linear.h index b9e1696..b072723 100644 --- a/src/stanExports_linear.h +++ b/src/stanExports_linear.h @@ -21,418 +21,457 @@ #define USE_STANC3 #endif #include -// Code generated by stanc v2.32.2 +// Code generated by stanc v2.26.1-4-gd72b68b7-dirty #include namespace model_linear_namespace { +inline void validate_positive_index(const char* var_name, const char* expr, + int val) { + if (val < 1) { + std::stringstream msg; + msg << "Found dimension size less than one in simplex declaration" + << "; variable=" << var_name << "; dimension size expression=" << expr + << "; expression value=" << val; + std::string msg_str(msg.str()); + throw std::invalid_argument(msg_str.c_str()); + } +} +inline void validate_unit_vector_index(const char* var_name, const char* expr, + int val) { + if (val <= 1) { + std::stringstream msg; + if (val == 1) { + msg << "Found dimension size one in unit vector declaration." + << " One-dimensional unit vector is discrete" + << " but the target distribution must be continuous." + << " variable=" << var_name << "; dimension size expression=" << expr; + } else { + msg << "Found dimension size less than one in unit vector declaration" + << "; variable=" << var_name << "; dimension size expression=" << expr + << "; expression value=" << val; + } + std::string msg_str(msg.str()); + throw std::invalid_argument(msg_str.c_str()); + } +} +using std::istream; +using std::string; +using std::stringstream; +using std::vector; +using std::pow; +using stan::io::dump; +using stan::math::lgamma; using stan::model::model_base_crtp; +using stan::model::rvalue; +using stan::model::cons_list; +using stan::model::index_uni; +using stan::model::index_max; +using stan::model::index_min; +using stan::model::index_min_max; +using stan::model::index_multi; +using stan::model::index_omni; +using stan::model::nil_index_list; using namespace stan::math; +using stan::math::pow; stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'linear', line 8, column 2 to column 17)", - " (in 'linear', line 9, column 2 to column 12)", - " (in 'linear', line 10, column 2 to column 22)", - " (in 'linear', line 14, column 2 to column 42)", - " (in 'linear', line 3, column 2 to column 17)", - " (in 'linear', line 4, column 9 to column 10)", - " (in 'linear', line 4, column 2 to column 14)", - " (in 'linear', line 5, column 9 to column 10)", - " (in 'linear', line 5, column 2 to column 14)"}; +static int current_statement__= 0; +static const std::vector locations_array__ = {" (found before start of program)", + " (in 'linear', line 8, column 2 to column 17)", + " (in 'linear', line 9, column 2 to column 12)", + " (in 'linear', line 10, column 2 to column 22)", + " (in 'linear', line 14, column 2 to column 42)", + " (in 'linear', line 3, column 2 to column 17)", + " (in 'linear', line 4, column 9 to column 10)", + " (in 'linear', line 4, column 2 to column 14)", + " (in 'linear', line 5, column 9 to column 10)", + " (in 'linear', line 5, column 2 to column 14)"}; #include class model_linear final : public model_base_crtp { private: int N; - Eigen::Matrix X_data__; - Eigen::Matrix Y_data__; - Eigen::Map> X{nullptr, 0}; - Eigen::Map> Y{nullptr, 0}; + Eigen::Matrix X; + Eigen::Matrix Y; + public: - ~model_linear() {} - model_linear(stan::io::var_context& context__, unsigned int - random_seed__ = 0, std::ostream* pstream__ = nullptr) - : model_base_crtp(0) { - int current_statement__ = 0; - using local_scalar_t__ = double; - boost::ecuyer1988 base_rng__ = - stan::services::util::create_rng(random_seed__, 0); - // suppress unused var warning - (void) base_rng__; - static constexpr const char* function__ = - "model_linear_namespace::model_linear"; - // suppress unused var warning - (void) function__; + ~model_linear() { } + + inline std::string model_name() const final { return "model_linear"; } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.26.1-4-gd72b68b7-dirty", "stancflags = "}; + } + + + model_linear(stan::io::var_context& context__, + unsigned int random_seed__ = 0, + std::ostream* pstream__ = nullptr) : model_base_crtp(0) { + using local_scalar_t__ = double ; + boost::ecuyer1988 base_rng__ = + stan::services::util::create_rng(random_seed__, 0); + (void) base_rng__; // suppress unused var warning + static const char* function__ = "model_linear_namespace::model_linear"; + (void) function__; // suppress unused var warning local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; + (void) DUMMY_VAR__; // suppress unused var warning + try { - int pos__ = std::numeric_limits::min(); + int pos__; + pos__ = std::numeric_limits::min(); + pos__ = 1; current_statement__ = 5; - context__.validate_dims("data initialization", "N", "int", - std::vector{}); + context__.validate_dims("data initialization","N","int", + context__.to_vec()); N = std::numeric_limits::min(); + current_statement__ = 5; N = context__.vals_i("N")[(1 - 1)]; current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "N", N, 1); + current_statement__ = 5; + check_greater_or_equal(function__, "N", N, 1); current_statement__ = 6; - stan::math::validate_non_negative_index("X", "N", N); + validate_non_negative_index("X", "N", N); current_statement__ = 7; - context__.validate_dims("data initialization", "X", "double", - std::vector{static_cast(N)}); - X_data__ = Eigen::Matrix::Constant(N, - std::numeric_limits::quiet_NaN()); - new (&X) Eigen::Map>(X_data__.data(), N); + context__.validate_dims("data initialization","X","double", + context__.to_vec(N)); + X = Eigen::Matrix(N); + stan::math::fill(X, std::numeric_limits::quiet_NaN()); + { std::vector X_flat__; current_statement__ = 7; - X_flat__ = context__.vals_r("X"); + assign(X_flat__, nil_index_list(), context__.vals_r("X"), + "assigning variable X_flat__"); current_statement__ = 7; pos__ = 1; current_statement__ = 7; for (int sym1__ = 1; sym1__ <= N; ++sym1__) { current_statement__ = 7; - stan::model::assign(X, X_flat__[(pos__ - 1)], - "assigning variable X", stan::model::index_uni(sym1__)); + assign(X, cons_list(index_uni(sym1__), nil_index_list()), + X_flat__[(pos__ - 1)], "assigning variable X"); current_statement__ = 7; - pos__ = (pos__ + 1); - } + pos__ = (pos__ + 1);} } current_statement__ = 8; - stan::math::validate_non_negative_index("Y", "N", N); + validate_non_negative_index("Y", "N", N); current_statement__ = 9; - context__.validate_dims("data initialization", "Y", "double", - std::vector{static_cast(N)}); - Y_data__ = Eigen::Matrix::Constant(N, - std::numeric_limits::quiet_NaN()); - new (&Y) Eigen::Map>(Y_data__.data(), N); + context__.validate_dims("data initialization","Y","double", + context__.to_vec(N)); + Y = Eigen::Matrix(N); + stan::math::fill(Y, std::numeric_limits::quiet_NaN()); + { std::vector Y_flat__; current_statement__ = 9; - Y_flat__ = context__.vals_r("Y"); + assign(Y_flat__, nil_index_list(), context__.vals_r("Y"), + "assigning variable Y_flat__"); current_statement__ = 9; pos__ = 1; current_statement__ = 9; for (int sym1__ = 1; sym1__ <= N; ++sym1__) { current_statement__ = 9; - stan::model::assign(Y, Y_flat__[(pos__ - 1)], - "assigning variable Y", stan::model::index_uni(sym1__)); + assign(Y, cons_list(index_uni(sym1__), nil_index_list()), + Y_flat__[(pos__ - 1)], "assigning variable Y"); current_statement__ = 9; - pos__ = (pos__ + 1); - } + pos__ = (pos__ + 1);} } } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); + } + num_params_r__ = 0U; + + try { + num_params_r__ += 1; + num_params_r__ += 1; + num_params_r__ += 1; + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); } - num_params_r__ = 1 + 1 + 1; - } - inline std::string model_name() const final { - return "model_linear"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { + template * = nullptr, stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t log_prob_impl(VecR& params_r__, + VecI& params_i__, + std::ostream* pstream__ = nullptr) const { using T__ = stan::scalar_type_t; using local_scalar_t__ = T__; T__ lp__(0.0); stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; + static const char* function__ = "model_linear_namespace::log_prob"; +(void) function__; // suppress unused var warning + stan::io::reader in__(params_r__, params_i__); local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_linear_namespace::log_prob"; - // suppress unused var warning - (void) function__; + (void) DUMMY_VAR__; // suppress unused var warning + try { - local_scalar_t__ intercept = DUMMY_VAR__; + local_scalar_t__ intercept; + intercept = DUMMY_VAR__; + current_statement__ = 1; - intercept = in__.template read(); - local_scalar_t__ beta = DUMMY_VAR__; + intercept = in__.scalar(); + local_scalar_t__ beta; + beta = DUMMY_VAR__; + current_statement__ = 2; - beta = in__.template read(); - local_scalar_t__ sigma = DUMMY_VAR__; + beta = in__.scalar(); + local_scalar_t__ sigma; + sigma = DUMMY_VAR__; + + current_statement__ = 3; + sigma = in__.scalar(); current_statement__ = 3; - sigma = in__.template read_constrain_lb(0, lp__); + if (jacobian__) { + current_statement__ = 3; + sigma = stan::math::lb_constrain(sigma, 0, lp__); + } else { + current_statement__ = 3; + sigma = stan::math::lb_constrain(sigma, 0); + } { current_statement__ = 4; - lp_accum__.add(stan::math::normal_lpdf(Y, - stan::math::add(intercept, - stan::math::multiply(beta, X)), sigma)); + lp_accum__.add( + normal_lpdf(Y, add(intercept, multiply(beta, X)), sigma)); } } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); } lp_accum__.add(lp__); return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { + } // log_prob_impl() + + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_std_vector_vt* = nullptr> + inline void write_array_impl(RNG& base_rng__, VecR& params_r__, + VecI& params_i__, VecVar& vars__, + const bool emit_transformed_parameters__ = true, + const bool emit_generated_quantities__ = true, + std::ostream* pstream__ = nullptr) const { using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - static constexpr bool propto__ = true; - // suppress unused var warning - (void) propto__; + vars__.resize(0); + stan::io::reader in__(params_r__, params_i__); + static const char* function__ = "model_linear_namespace::write_array"; +(void) function__; // suppress unused var warning + (void) function__; // suppress unused var warning double lp__ = 0.0; - // suppress unused var warning - (void) lp__; - int current_statement__ = 0; + (void) lp__; // dummy to suppress unused var warning stan::math::accumulator lp_accum__; local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_linear_namespace::write_array"; - // suppress unused var warning - (void) function__; + (void) DUMMY_VAR__; // suppress unused var warning + try { - double intercept = std::numeric_limits::quiet_NaN(); + double intercept; + intercept = std::numeric_limits::quiet_NaN(); + current_statement__ = 1; - intercept = in__.template read(); - double beta = std::numeric_limits::quiet_NaN(); + intercept = in__.scalar(); + double beta; + beta = std::numeric_limits::quiet_NaN(); + current_statement__ = 2; - beta = in__.template read(); - double sigma = std::numeric_limits::quiet_NaN(); + beta = in__.scalar(); + double sigma; + sigma = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; - sigma = in__.template read_constrain_lb(0, lp__); - out__.write(intercept); - out__.write(beta); - out__.write(sigma); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { + sigma = in__.scalar(); + current_statement__ = 3; + sigma = stan::math::lb_constrain(sigma, 0); + vars__.emplace_back(intercept); + vars__.emplace_back(beta); + vars__.emplace_back(sigma); + if (logical_negation((primitive_value(emit_transformed_parameters__) || + primitive_value(emit_generated_quantities__)))) { return ; - } - if (stan::math::logical_negation(emit_generated_quantities__)) { + } + if (logical_negation(emit_generated_quantities__)) { return ; - } + } } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); } - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline void - unconstrain_array_impl(const VecVar& params_r__, const VecI& params_i__, - VecVar& vars__, std::ostream* pstream__ = nullptr) const { + } // write_array_impl() + + template * = nullptr, stan::require_vector_like_vt* = nullptr> + inline void transform_inits_impl(const stan::io::var_context& context__, + VecI& params_i__, VecVar& vars__, + std::ostream* pstream__ = nullptr) const { using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; + vars__.clear(); + vars__.reserve(num_params_r__); + try { - int pos__ = std::numeric_limits::min(); + int pos__; + pos__ = std::numeric_limits::min(); + pos__ = 1; - local_scalar_t__ intercept = DUMMY_VAR__; - current_statement__ = 1; - intercept = in__.read(); - out__.write(intercept); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 2; - beta = in__.read(); - out__.write(beta); - local_scalar_t__ sigma = DUMMY_VAR__; - current_statement__ = 3; - sigma = in__.read(); - out__.write_free_lb(0, sigma); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr> - inline void - transform_inits_impl(const stan::io::var_context& context__, VecVar& - vars__, std::ostream* pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "intercept", - "double", std::vector{}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "beta", "double", - std::vector{}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "sigma", "double", - std::vector{}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - local_scalar_t__ intercept = DUMMY_VAR__; + double intercept; + intercept = std::numeric_limits::quiet_NaN(); + current_statement__ = 1; intercept = context__.vals_r("intercept")[(1 - 1)]; - out__.write(intercept); - local_scalar_t__ beta = DUMMY_VAR__; + double beta; + beta = std::numeric_limits::quiet_NaN(); + current_statement__ = 2; beta = context__.vals_r("beta")[(1 - 1)]; - out__.write(beta); - local_scalar_t__ sigma = DUMMY_VAR__; + double sigma; + sigma = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; sigma = context__.vals_r("sigma")[(1 - 1)]; - out__.write_free_lb(0, sigma); + double sigma_free__; + sigma_free__ = std::numeric_limits::quiet_NaN(); + + current_statement__ = 3; + sigma_free__ = stan::math::lb_free(sigma, 0); + vars__.emplace_back(intercept); + vars__.emplace_back(beta); + vars__.emplace_back(sigma_free__); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); + // Next line prevents compiler griping about no return + throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"intercept", "beta", "sigma"}; - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) {} - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{}, - std::vector{}, std::vector{}}; - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) {} - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { + } // transform_inits_impl() + + inline void get_param_names(std::vector& names__) const { + + names__.clear(); + names__.emplace_back("intercept"); + names__.emplace_back("beta"); + names__.emplace_back("sigma"); + } // get_param_names() + + inline void get_dims(std::vector>& dimss__) const { + dimss__.clear(); + dimss__.emplace_back(std::vector{}); + + dimss__.emplace_back(std::vector{}); + + dimss__.emplace_back(std::vector{}); + + } // get_dims() + + inline void constrained_param_names( + std::vector& param_names__, + bool emit_transformed_parameters__ = true, + bool emit_generated_quantities__ = true) const + final { + param_names__.emplace_back(std::string() + "intercept"); param_names__.emplace_back(std::string() + "beta"); param_names__.emplace_back(std::string() + "sigma"); - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) {} - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { + if (emit_transformed_parameters__) { + + } + + if (emit_generated_quantities__) { + + } + + } // constrained_param_names() + + inline void unconstrained_param_names( + std::vector& param_names__, + bool emit_transformed_parameters__ = true, + bool emit_generated_quantities__ = true) const + final { + param_names__.emplace_back(std::string() + "intercept"); param_names__.emplace_back(std::string() + "beta"); param_names__.emplace_back(std::string() + "sigma"); - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) {} - } + if (emit_transformed_parameters__) { + + } + + if (emit_generated_quantities__) { + + } + + } // unconstrained_param_names() + inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"intercept\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"}]"); - } + stringstream s__; + s__ << "[{\"name\":\"intercept\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"}]"; + return s__.str(); + } // get_constrained_sizedtypes() + inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"intercept\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((1 + 1) + 1); - const size_t num_transformed = emit_transformed_parameters * (0); - const size_t num_gen_quantities = emit_generated_quantities * (0); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((1 + 1) + 1); - const size_t num_transformed = emit_transformed_parameters * (0); - const size_t num_gen_quantities = emit_generated_quantities * (0); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } + stringstream s__; + s__ << "[{\"name\":\"intercept\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"sigma\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"}]"; + return s__.str(); + } // get_unconstrained_sizedtypes() + + + // Begin method overload boilerplate + template + inline void write_array(RNG& base_rng, + Eigen::Matrix& params_r, + Eigen::Matrix& vars, + const bool emit_transformed_parameters = true, + const bool emit_generated_quantities = true, + std::ostream* pstream = nullptr) const { + std::vector vars_vec(vars.size()); + std::vector params_i; + write_array_impl(base_rng, params_r, params_i, vars_vec, + emit_transformed_parameters, emit_generated_quantities, pstream); + vars.resize(vars_vec.size()); + for (int i = 0; i < vars.size(); ++i) { + vars.coeffRef(i) = vars_vec[i]; + } + } + template + inline void write_array(RNG& base_rng, std::vector& params_r, + std::vector& params_i, + std::vector& vars, + bool emit_transformed_parameters = true, + bool emit_generated_quantities = true, + std::ostream* pstream = nullptr) const { + write_array_impl(base_rng, params_r, params_i, vars, emit_transformed_parameters, emit_generated_quantities, pstream); + } + template + inline T_ log_prob(Eigen::Matrix& params_r, + std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template + inline T__ log_prob(std::vector& params_r, + std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + + inline void transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, + std::ostream* pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits_impl(context, params_i, params_r_vec, pstream); + params_r.resize(params_r_vec.size()); + for (int i = 0; i < params_r.size(); ++i) { + params_r.coeffRef(i) = params_r_vec[i]; + } + } + inline void transform_inits(const stan::io::var_context& context, + std::vector& params_i, + std::vector& vars, + std::ostream* pstream = nullptr) const final { + transform_inits_impl(context, params_i, vars, pstream); + } }; } using stan_model = model_linear_namespace::model_linear; #ifndef USING_R // Boilerplate -stan::model::model_base& -new_model(stan::io::var_context& data_context, unsigned int seed, - std::ostream* msg_stream) { +stan::model::model_base& new_model( + stan::io::var_context& data_context, + unsigned int seed, + std::ostream* msg_stream) { stan_model* m = new stan_model(data_context, seed, msg_stream); return *m; } diff --git a/tests/testthat/fixtures/constant/constant_baseline_output_multi_ind.rds b/tests/testthat/fixtures/constant/constant_baseline_output_multi_ind.rds deleted file mode 100644 index 1836e71..0000000 Binary files a/tests/testthat/fixtures/constant/constant_baseline_output_multi_ind.rds and /dev/null differ diff --git a/tests/testthat/fixtures/constant/constant_baseline_output_single_ind.rds b/tests/testthat/fixtures/constant/constant_baseline_output_single_ind.rds deleted file mode 100644 index 300e10d..0000000 Binary files a/tests/testthat/fixtures/constant/constant_baseline_output_single_ind.rds and /dev/null differ diff --git a/tests/testthat/fixtures/constant/constant_data_multi_ind.rds b/tests/testthat/fixtures/constant/constant_data_multi_ind.rds index 90092ae..082c760 100644 Binary files a/tests/testthat/fixtures/constant/constant_data_multi_ind.rds and b/tests/testthat/fixtures/constant/constant_data_multi_ind.rds differ diff --git a/tests/testthat/fixtures/constant/constant_data_single_ind.rds b/tests/testthat/fixtures/constant/constant_data_single_ind.rds index 47134b4..b2e6775 100644 Binary files a/tests/testthat/fixtures/constant/constant_data_single_ind.rds and b/tests/testthat/fixtures/constant/constant_data_single_ind.rds differ diff --git a/tests/testthat/fixtures/constant/make_constant.R b/tests/testthat/fixtures/constant/make_constant.R index 1ffe8cf..aab703d 100644 --- a/tests/testthat/fixtures/constant/make_constant.R +++ b/tests/testthat/fixtures/constant/make_constant.R @@ -4,23 +4,12 @@ DE <- function(y, pars){ return(pars[1]) } -#Normally distributed error -add_error_process <- function(y, sigma_e=0.001){ - return(y + rnorm(length(y), mean=0, sd=sigma_e)) -} - #Function to generate distribution of DE parameters DE_par_generation <- function(n_ind, pars=list(mean=0, sd=1)){ par_sample <- data.frame(beta=exp(rnorm(n_ind, mean = pars[[1]], sd=pars[[2]]))) return(par_sample) } -#Generate initial conditions -initial_condition_generation <- function(n_ind, pars=list(mean=2, sd=1)){ - y_0_sample <- data.frame(y_0=exp(rnorm(n_ind, mean = pars[[1]], sd=pars[[2]]))) - return(y_0_sample) -} - #Set required values model_name <- "constant" n_ind <- 3 #Number of individuals for multi-individual data. Single individual takes the first. @@ -30,14 +19,14 @@ time = seq(from = 0, by = interval, length.out = n_obs_per_ind) #Produce parameters DE_pars <- DE_par_generation(n_ind) -initial_conditions <- initial_condition_generation(n_ind) +initial_conditions <- data.frame(y_0=exp(rnorm(n_ind, mean = 2, sd=1))) #Generate true values true_data <- rmot_build_true_test_data(n_ind, n_obs_per_ind, interval, DE_pars, initial_conditions, DE) #Generate observations -y_obs <- add_error_process(true_data$y_true) +y_obs <- rmot_add_normal_error(true_data$y_true) #Export datasets rmot_export_test_data(n_obs_per_ind, @@ -48,52 +37,3 @@ rmot_export_test_data(n_obs_per_ind, initial_conditions, true_data, model_name) - -#Build model fit single ind -const_data <- readRDS(test_path("fixtures/constant/constant_data_single_ind.rds")) -suppressWarnings( #Suppresses stan warnings - constant_single_ind_test <- rmot_model("constant_single_ind") |> - rmot_assign_data(n_obs = const_data$n_obs, #integer - y_obs = const_data$y_obs, - obs_index = const_data$obs_index, #vector length N_obs - time = const_data$time, #Vector length N_obs - y_0_obs = const_data$y_0_obs #vector length N_ind - ) |> - rmot_run(chains = 1, iter = 300, verbose = FALSE, show_messages = FALSE, seed=1) -) - -# Extract 100 rows of the samples -constant_baseline_output_single_ind <- rstan::extract(constant_single_ind_test, permuted = FALSE, inc_warmup = FALSE) |> - as.data.frame() |> - head(n=100) - -# Save the output to compare againest -saveRDS(constant_baseline_output_single_ind, - file = test_path("fixtures/constant/constant_baseline_output_single_ind.rds") -) - -#Build model fit multiple inds -const_data <- readRDS(test_path("fixtures/constant/constant_data_multi_ind.rds")) -suppressWarnings( #Suppresses stan warnings - constant_multi_ind_test <- rmot_model("constant_multi_ind") |> - rmot_assign_data(n_obs = const_data$n_obs, #integer - n_ind = const_data$n_ind, #integer - y_obs = const_data$y_obs, #vector length N_obs - obs_index = const_data$obs_index, #vector length N_obs - time = const_data$time, #Vector length N_obs - ind_id = const_data$ind_id, #Vector length N_obs - y_0_obs = const_data$y_0_obs #vector length N_ind - ) |> - rmot_run(chains = 1, iter = 300, verbose = FALSE, show_messages = FALSE, seed=1) -) - -# Extract 100 rows of the samples -constant_baseline_output_multi_ind <- rstan::extract(constant_multi_ind_test, permuted = FALSE, inc_warmup = FALSE) |> - as.data.frame() |> - head(n=100) - -# Save the output to compare againest -saveRDS(constant_baseline_output_multi_ind, - file = test_path("fixtures/constant/constant_baseline_output_multi_ind.rds") - ) - diff --git a/tests/testthat/helper.R b/tests/testthat/helper-data_generation.R similarity index 92% rename from tests/testthat/helper.R rename to tests/testthat/helper-data_generation.R index e4399d8..23f51e9 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper-data_generation.R @@ -1,6 +1,4 @@ - #General functions for data generation - #Runge-Kutta 4th order rmot_rk4_est <- function(y_0, DE, pars, step_size, n_step){ runge_kutta_int <- c(y_0) @@ -46,6 +44,10 @@ rmot_build_true_test_data <- function(n_ind, n_obs, interval, return(true_data) } +rmot_add_normal_error <- function(y, sigma_e=0.001){ + return(y + rnorm(length(y), mean=0, sd=sigma_e)) +} + #Save data to files rmot_export_test_data <- function(n_obs_per_ind, n_ind, @@ -63,6 +65,7 @@ rmot_export_test_data <- function(n_obs_per_ind, obs_index = 1:n_obs_per_ind, #Vector indexed by n_obs time = time, #Vector indexed by n_obs y_0_obs = y_obs[1], #Number + n_pars = ncol(DE_pars), #Number single_true_data = list( DE_pars = DE_pars[1,], initial_conditions = initial_conditions[1,], @@ -80,6 +83,7 @@ rmot_export_test_data <- function(n_obs_per_ind, time = rep(time, times=n_ind), #Vector indexed by n_obs ind_id = sort(rep(1:n_ind, times = n_obs_per_ind)), #Vector indexed by n_obs y_0_obs = y_obs[seq(from = 1, to=n_ind*n_obs_per_ind, by=n_obs_per_ind)], #Vector indexed by n_ind + n_pars = ncol(DE_pars), multi_true_data = list( DE_pars = DE_pars, initial_conditions = initial_conditions, @@ -88,7 +92,7 @@ rmot_export_test_data <- function(n_obs_per_ind, ) ) - if(! exists(test_path("fixtures", model_name))) dir.create(test_path("fixtures", model_name)) + if(! dir.exists(test_path("fixtures", model_name))) dir.create(test_path("fixtures", model_name)) filename <- paste("tests/testthat/fixtures", "/", model_name, "/", model_name, "_data", sep="") saveRDS(single_ind_data, file=paste(filename, "single_ind.rds", sep="_")) saveRDS(multi_ind_data, file=paste(filename, "multi_ind.rds", sep="_")) diff --git a/tests/testthat/helper-testing.R b/tests/testthat/helper-testing.R new file mode 100644 index 0000000..1e105f6 --- /dev/null +++ b/tests/testthat/helper-testing.R @@ -0,0 +1,72 @@ +rmot_test_model_functions <- function(model_name){ + single_ind_name <- paste0(model_name, "_single_ind") + multi_ind_name <- paste0(model_name, "_multi_ind") + + # Single individual + expect_named(rmot_model(single_ind_name)) + expect_type(rmot_model(single_ind_name), "list") + expect_visible(rmot_model(single_ind_name)) + #Multiple individuals + expect_named(rmot_model(multi_ind_name)) + expect_type(rmot_model(multi_ind_name), "list") + expect_visible(rmot_model(multi_ind_name)) +} + +rmot_test_single_individual <- function(model_name, + par_names){ + data <- readRDS(test_path("fixtures", model_name, + paste0(model_name, "_data_single_ind.rds"))) + + # Test constant single individual + suppressWarnings( #Suppresses stan warnings + single_ind_test <- rmot_model(paste0(model_name, "_single_ind")) |> + rmot_assign_data(n_obs = data$n_obs, #integer + y_obs = data$y_obs, + obs_index = data$obs_index, #vector length N_obs + time = data$time, #Vector length N_obs + y_0_obs = data$y_0_obs #vector length N_ind + ) |> + rmot_run(chains = 1, iter = 1000, verbose = FALSE, show_messages = FALSE) + ) + + # Extract samples and check if parameter estimates are reasonable. + ind_samples <- rstan::extract(single_ind_test, permuted = TRUE, + inc_warmup = FALSE) + par_ests <- c() + for(i in length(par_names)){ + par_ests[i] <- mean(ind_samples[[par_names[i]]]) + } + + initial_condition <- mean(ind_samples$ind_y_0) + expect_equal(par_ests, data$single_true_data$DE_pars, + tolerance = 1e-1) + expect_equal(initial_condition, data$single_true_data$initial_conditions, + tolerance = 1e-1) + + # hecks for output existence and type + expect_visible(single_ind_test) + expect_s4_class(single_ind_test, "stanfit") +} + +rmot_test_multi_individual <- function(model_name, data, est_dim){ + # Test constant multi-individual + suppressWarnings( #Suppresses stan warnings + multi_ind_test <- rmot_model(paste0(model_name, "_multi_ind")) |> + rmot_assign_data(n_obs = data$n_obs, #integer + n_ind = data$n_ind, #integer + y_obs = data$y_obs, #vector length N_obs + obs_index = data$obs_index, #vector length N_obs + time = data$time, #Vector length N_obs + ind_id = data$ind_id, #Vector length N_obs + y_0_obs = data$y_0_obs #vector length N_ind + ) |> + rmot_run(chains = 2, iter = 100, verbose = FALSE, show_messages = FALSE) + ) + + # Extract samples + multi_samples <- rstan::extract(multi_ind_test, permuted = FALSE, inc_warmup = TRUE) + expect_equal(dim(multi_samples), c(100, 2, est_dim)) + + expect_visible(multi_ind_test) + expect_s4_class(multi_ind_test, "stanfit") +} diff --git a/tests/testthat/test-rmot_models.R b/tests/testthat/test-rmot_models.R index 380d762..26976d0 100644 --- a/tests/testthat/test-rmot_models.R +++ b/tests/testthat/test-rmot_models.R @@ -1,17 +1,7 @@ -test_that("Model structures", { +test_that("Model structures: Linear", { expect_named(rmot_model("linear")) expect_type(rmot_model("linear"), "list") expect_visible(rmot_model("linear")) - - # Constant models - # Single individual - expect_named(rmot_model("constant_single_ind")) - expect_type(rmot_model("constant_single_ind"), "list") - expect_visible(rmot_model("constant_single_ind")) - #Multiple individuals - expect_named(rmot_model("constant_multi_ind")) - expect_type(rmot_model("constant_multi_ind"), "list") - expect_visible(rmot_model("constant_multi_ind")) }) test_that("Execution and output: Linear", { @@ -37,66 +27,3 @@ test_that("Execution and output: Linear", { expect_visible(lm_test) expect_s4_class(lm_test, "stanfit") }) - -test_that("Execution: Constant single individual", { - const_data <- readRDS(test_path("fixtures", "constant", - "constant_data_single_ind.rds")) - const_single_ind_baseline_output <- readRDS(test_path("fixtures", "constant", - "constant_baseline_output_single_ind.rds")) - - # Test constant single individual - suppressWarnings( #Suppresses stan warnings - constant_single_ind_test <- rmot_model("constant_single_ind") |> - rmot_assign_data(n_obs = const_data$n_obs, #integer - y_obs = const_data$y_obs, - obs_index = const_data$obs_index, #vector length N_obs - time = const_data$time, #Vector length N_obs - y_0_obs = const_data$y_0_obs #vector length N_ind - ) |> - rmot_run(chains = 1, iter = 300, verbose = FALSE, show_messages = FALSE, - seed = 1) - ) - - # Extract samples - constant_ind_samples <- rstan::extract(constant_single_ind_test, permuted = FALSE, inc_warmup = FALSE) |> - as.data.frame() |> - head(n=100) - - expect_equal(constant_ind_samples, - const_single_ind_baseline_output, tolerance = 1e-5) - expect_visible(constant_single_ind_test) - expect_s4_class(constant_single_ind_test, "stanfit") - -}) - -test_that("Execution: Constant multiple individuals", { - const_data <- readRDS(test_path("fixtures", "constant", - "constant_data_multi_ind.rds")) - const_multi_ind_baseline_output <- readRDS(test_path("fixtures", "constant", - "constant_baseline_output_multi_ind.rds")) - - # Test constant multi-individual - suppressWarnings( #Suppresses stan warnings - constant_multi_ind_test <- rmot_model("constant_multi_ind") |> - rmot_assign_data(n_obs = const_data$n_obs, #integer - n_ind = const_data$n_ind, #integer - y_obs = const_data$y_obs, #vector length N_obs - obs_index = const_data$obs_index, #vector length N_obs - time = const_data$time, #Vector length N_obs - ind_id = const_data$ind_id, #Vector length N_obs - y_0_obs = const_data$y_0_obs #vector length N_ind - ) |> - rmot_run(chains = 1, iter = 300, verbose = FALSE, show_messages = FALSE, - seed = 1) - ) - - # Extract samples - constant_multi_samples <- rstan::extract(constant_multi_ind_test, permuted = FALSE, inc_warmup = FALSE) |> - as.data.frame() |> - head(n=100) - - expect_equal(constant_multi_samples, - const_multi_ind_baseline_output, tolerance = 1e-5) - expect_visible(constant_multi_ind_test) - expect_s4_class(constant_multi_ind_test, "stanfit") -}) diff --git a/tests/testthat/test-rmot_models_constant.R b/tests/testthat/test-rmot_models_constant.R new file mode 100644 index 0000000..56ba31f --- /dev/null +++ b/tests/testthat/test-rmot_models_constant.R @@ -0,0 +1,36 @@ +#Testing for constant model +test_that("Model structures: Constant", { + # Single individual + expect_named(rmot_model("constant_single_ind")) + expect_type(rmot_model("constant_single_ind"), "list") + expect_visible(rmot_model("constant_single_ind")) + #Multiple individuals + expect_named(rmot_model("constant_multi_ind")) + expect_type(rmot_model("constant_multi_ind"), "list") + expect_visible(rmot_model("constant_multi_ind")) +}) + +test_that("Execution: Constant single individual", { + model_name <- "constant" + par_names <- "ind_beta" + + rmot_test_single_individual(model_name, par_names) +}) + +test_that("Execution: Constant multiple individuals", { + model_name <- "constant" + + data <- readRDS(test_path("fixtures", "constant", + "constant_data_multi_ind.rds")) + + #Dimension is: + est_dim <- data$n_ind + #Initial condition + data$n_pars * data$n_ind + #Individual parameters + data$n_pars * 2 + #Population parameters + 1 + #Global error + data$n_obs + #y_ij + data$n_obs + #Delta y_ij + 1 #lp__ + + rmot_test_multi_individual(model_name, data, est_dim) +})