Skip to content

Instantly share code, notes, and snippets.

@seantalts
Last active June 21, 2019 21:32
Show Gist options
  • Save seantalts/b91a1df4378455f1e7a8c0351b8f366a to your computer and use it in GitHub Desktop.
Save seantalts/b91a1df4378455f1e7a8c0351b8f366a to your computer and use it in GitHub Desktop.
// Code generated by %%NAME%% %%VERSION%%
#include <stan/model/model_header.hpp>
namespace hepatitis_model_namespace {
using stan::io::dump;
using stan::math::lgamma;
using stan::model::assign;
using stan::model::cons_list;
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::index_uni;
using stan::model::nil_index_list;
using stan::model::prob_grad;
using stan::model::rvalue;
using std::istream;
using std::string;
using std::stringstream;
using std::vector;
using namespace stan::math;
static int current_statement__ = 0;
static const std::vector<string> locations_array__ = {
"Found before start of program.",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 30, columns 2-26",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 31, columns 2-30",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 32, columns 2-29",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 33, columns 2-16",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 34, columns 2-15",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 35, columns 2-13",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 36, columns 2-14",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 37, columns 2-13",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 42, columns 2-15",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 43, columns 2-19",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 44, columns 2-18",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 45, columns 2-29",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 46, columns 2-37",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 47, columns 2-35",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 51, columns 2-11",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 52, columns 2-13",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 54, columns 4-21",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 55, columns 4-87",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 53, column 18 to line 56, column 3",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 53, column 2 to line 56, column 3",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 57, columns 2-29",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 59, columns 2-38",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 60, columns 2-35",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 62, columns 2-36",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 63, columns 2-40",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 64, columns 2-39",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 65, columns 2-27",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 66, columns 2-26",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 67, columns 2-26",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 16, columns 2-18",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 17, columns 2-17",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 18, columns 2-17",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 19, columns 2-17",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 20, columns 2-25",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 21, columns 2-13",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 25, columns 2-15",
"At file ../example-models/bugs_examples/vol3/hepatitis/hepatitis.stan, "
"line 26, columns 2-22"};
class hepatitis_model : public prob_grad {
private:
int pos__;
int N1;
int N;
std::vector<double> Yvec1;
std::vector<double> tvec1;
std::vector<int> idxn1;
std::vector<double> y0;
double y0_mean;
public:
~hepatitis_model() {}
static std::string model_name() { return "hepatitis_model"; }
hepatitis_model(stan::io::var_context &context__,
unsigned int random_seed__ = 0,
std::ostream *pstream__ = nullptr)
: prob_grad(0) {
typedef double local_scalar_t__;
boost::ecuyer1988 base_rng__ =
stan::services::util::create_rng(random_seed__, 0);
(void)base_rng__; // suppress unused var warning
static const char *function__ =
"hepatitis_model_namespace::hepatitis_model";
(void)function__; // suppress unused var warning
try {
current_statement__ = 31;
current_statement__ = 31;
assign(N1, nil_index_list(), context__.vals_i("N1")[(1 - 1)],
"assigning variable N1");
current_statement__ = 32;
current_statement__ = 32;
assign(N, nil_index_list(), context__.vals_i("N")[(1 - 1)],
"assigning variable N");
Yvec1 = std::vector<double>(N1, 0);
current_statement__ = 33;
pos__ = 1;
current_statement__ = 33;
for (size_t sym1__ = 1; sym1__ <= N1; ++sym1__) {
current_statement__ = 33;
assign(Yvec1, cons_list(index_uni(sym1__), nil_index_list()),
context__.vals_r("Yvec1")[(pos__ - 1)],
"assigning variable Yvec1[(sym1__ - 1)]");
current_statement__ = 33;
assign(pos__, nil_index_list(), (stan::model::deep_copy(pos__) + 1),
"assigning variable pos__");
}
tvec1 = std::vector<double>(N1, 0);
current_statement__ = 34;
pos__ = 1;
current_statement__ = 34;
for (size_t sym1__ = 1; sym1__ <= N1; ++sym1__) {
current_statement__ = 34;
assign(tvec1, cons_list(index_uni(sym1__), nil_index_list()),
context__.vals_r("tvec1")[(pos__ - 1)],
"assigning variable tvec1[(sym1__ - 1)]");
current_statement__ = 34;
assign(pos__, nil_index_list(), (stan::model::deep_copy(pos__) + 1),
"assigning variable pos__");
}
idxn1 = std::vector<int>(N1, 0);
current_statement__ = 35;
pos__ = 1;
current_statement__ = 35;
for (size_t sym1__ = 1; sym1__ <= N1; ++sym1__) {
current_statement__ = 35;
assign(idxn1, cons_list(index_uni(sym1__), nil_index_list()),
context__.vals_i("idxn1")[(pos__ - 1)],
"assigning variable idxn1[(sym1__ - 1)]");
current_statement__ = 35;
assign(pos__, nil_index_list(), (stan::model::deep_copy(pos__) + 1),
"assigning variable pos__");
}
y0 = std::vector<double>(N, 0);
current_statement__ = 36;
pos__ = 1;
current_statement__ = 36;
for (size_t sym1__ = 1; sym1__ <= N; ++sym1__) {
current_statement__ = 36;
assign(y0, cons_list(index_uni(sym1__), nil_index_list()),
context__.vals_r("y0")[(pos__ - 1)],
"assigning variable y0[(sym1__ - 1)]");
current_statement__ = 36;
assign(pos__, nil_index_list(), (stan::model::deep_copy(pos__) + 1),
"assigning variable pos__");
}
current_statement__ = 38;
assign(y0_mean, nil_index_list(), mean(y0), "assigning variable y0_mean");
current_statement__ = 31;
current_statement__ = 31;
check_greater_or_equal(function__, "N1", N1, 0);
current_statement__ = 32;
current_statement__ = 32;
check_greater_or_equal(function__, "N", N, 0);
current_statement__ = 35;
for (size_t sym1__ = 1; sym1__ <= N1; ++sym1__) {
current_statement__ = 35;
current_statement__ = 35;
check_greater_or_equal(
function__, "idxn1[sym1__]",
rvalue(idxn1, cons_list(index_uni(sym1__), nil_index_list()),
"pretty printed e"),
0);
}
} catch (const std::exception &e) {
stan::lang::rethrow_located(
std::runtime_error(std::string("inside ctor") + ": " + e.what()),
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;
num_params_r__ += 1;
num_params_r__ += 1;
num_params_r__ += 1;
num_params_r__ += N;
num_params_r__ += N;
num_params_r__ += 1;
num_params_r__ += 1;
num_params_r__ += 1;
}
template <bool propto__, bool jacobian__, typename T__>
T__ log_prob(std::vector<T__> &params_r__, std::vector<int> &params_i__,
std::ostream *pstream__ = 0) const {
typedef T__ local_scalar_t__;
local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
(void)DUMMY_VAR__; // suppress unused var warning
T__ lp__(0.0);
stan::math::accumulator<T__> lp_accum__;
static const char *function__ = "hepatitis_model_namespace::log_prob";
(void)function__; // suppress unused var warning
stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
try {
local_scalar_t__ sigmasq_y;
current_statement__ = 2;
assign(sigmasq_y, nil_index_list(), in__.scalar(),
"assigning variable sigmasq_y");
current_statement__ = 2;
if (jacobian__) {
current_statement__ = 2;
assign(sigmasq_y, nil_index_list(), lb_constrain(sigmasq_y, 0, lp__),
"assigning variable sigmasq_y");
} else {
current_statement__ = 2;
assign(sigmasq_y, nil_index_list(), lb_constrain(sigmasq_y, 0),
"assigning variable sigmasq_y");
}
local_scalar_t__ sigmasq_alpha;
current_statement__ = 3;
assign(sigmasq_alpha, nil_index_list(), in__.scalar(),
"assigning variable sigmasq_alpha");
current_statement__ = 3;
if (jacobian__) {
current_statement__ = 3;
assign(sigmasq_alpha, nil_index_list(),
lb_constrain(sigmasq_alpha, 0, lp__),
"assigning variable sigmasq_alpha");
} else {
current_statement__ = 3;
assign(sigmasq_alpha, nil_index_list(), lb_constrain(sigmasq_alpha, 0),
"assigning variable sigmasq_alpha");
}
local_scalar_t__ sigmasq_beta;
current_statement__ = 4;
assign(sigmasq_beta, nil_index_list(), in__.scalar(),
"assigning variable sigmasq_beta");
current_statement__ = 4;
if (jacobian__) {
current_statement__ = 4;
assign(sigmasq_beta, nil_index_list(),
lb_constrain(sigmasq_beta, 0, lp__),
"assigning variable sigmasq_beta");
} else {
current_statement__ = 4;
assign(sigmasq_beta, nil_index_list(), lb_constrain(sigmasq_beta, 0),
"assigning variable sigmasq_beta");
}
std::vector<local_scalar_t__> alpha;
alpha = std::vector<local_scalar_t__>(N, 0);
current_statement__ = 5;
for (size_t sym1__ = 1; sym1__ <= N; ++sym1__) {
current_statement__ = 5;
assign(alpha, cons_list(index_uni(sym1__), nil_index_list()),
in__.scalar(), "assigning variable alpha[(sym1__ - 1)]");
}
std::vector<local_scalar_t__> beta;
beta = std::vector<local_scalar_t__>(N, 0);
current_statement__ = 6;
for (size_t sym1__ = 1; sym1__ <= N; ++sym1__) {
current_statement__ = 6;
assign(beta, cons_list(index_uni(sym1__), nil_index_list()),
in__.scalar(), "assigning variable beta[(sym1__ - 1)]");
}
local_scalar_t__ gamma;
current_statement__ = 7;
assign(gamma, nil_index_list(), in__.scalar(),
"assigning variable gamma");
local_scalar_t__ alpha0;
current_statement__ = 8;
assign(alpha0, nil_index_list(), in__.scalar(),
"assigning variable alpha0");
local_scalar_t__ beta0;
current_statement__ = 9;
assign(beta0, nil_index_list(), in__.scalar(),
"assigning variable beta0");
local_scalar_t__ sigma_y;
local_scalar_t__ sigma_alpha;
local_scalar_t__ sigma_beta;
current_statement__ = 13;
assign(sigma_y, nil_index_list(), stan::math::sqrt(sigmasq_y),
"assigning variable sigma_y");
current_statement__ = 14;
assign(sigma_alpha, nil_index_list(), stan::math::sqrt(sigmasq_alpha),
"assigning variable sigma_alpha");
current_statement__ = 15;
assign(sigma_beta, nil_index_list(), stan::math::sqrt(sigmasq_beta),
"assigning variable sigma_beta");
{
int oldn;
std::vector<local_scalar_t__> m;
m = std::vector<local_scalar_t__>(N1, 0);
current_statement__ = 21;
for (size_t n = 1; n <= N1; ++n) {
current_statement__ = 18;
assign(oldn, nil_index_list(),
rvalue(idxn1, cons_list(index_uni(n), nil_index_list()),
"pretty printed e"),
"assigning variable oldn");
current_statement__ = 19;
assign(m, cons_list(index_uni(n), nil_index_list()),
((rvalue(alpha, cons_list(index_uni(oldn), nil_index_list()),
"pretty printed e") +
(rvalue(beta, cons_list(index_uni(oldn), nil_index_list()),
"pretty printed e") *
(rvalue(tvec1, cons_list(index_uni(n), nil_index_list()),
"pretty printed e") -
6.5))) +
(gamma *
(rvalue(y0, cons_list(index_uni(oldn), nil_index_list()),
"pretty printed e") -
y0_mean))),
"assigning variable m[(n - 1)]");
}
current_statement__ = 22;
lp_accum__.add(normal_log<propto__>(Yvec1, m, sigma_y));
current_statement__ = 23;
lp_accum__.add(normal_log<propto__>(alpha, alpha0, sigma_alpha));
current_statement__ = 24;
lp_accum__.add(normal_log<propto__>(beta, beta0, sigma_beta));
current_statement__ = 25;
lp_accum__.add(inv_gamma_log<propto__>(sigmasq_y, .001, .001));
current_statement__ = 26;
lp_accum__.add(inv_gamma_log<propto__>(sigmasq_alpha, .001, .001));
current_statement__ = 27;
lp_accum__.add(inv_gamma_log<propto__>(sigmasq_beta, .001, .001));
current_statement__ = 28;
lp_accum__.add(normal_log<propto__>(alpha0, 0, 1000));
current_statement__ = 29;
lp_accum__.add(normal_log<propto__>(beta0, 0, 1000));
current_statement__ = 30;
lp_accum__.add(normal_log<propto__>(gamma, 0, 1000));
}
} catch (const std::exception &e) {
stan::lang::rethrow_located(
std::runtime_error(std::string("inside log_prob") + ": " + e.what()),
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();
} // log_prob()
void get_param_names(std::vector<std::string> &names__) const {
names__.resize(0);
names__.push_back("sigmasq_y");
names__.push_back("sigmasq_alpha");
names__.push_back("sigmasq_beta");
names__.push_back("alpha");
names__.push_back("beta");
names__.push_back("gamma");
names__.push_back("alpha0");
names__.push_back("beta0");
names__.push_back("sigma_y");
names__.push_back("sigma_alpha");
names__.push_back("sigma_beta");
} // get_param_names()
void get_dims(std::vector<std::vector<size_t>> &dimss__) const {
dimss__.resize(0);
std::vector<size_t> dims__;
dimss__.push_back(dims__);
dims__.resize(0);
dimss__.push_back(dims__);
dims__.resize(0);
dimss__.push_back(dims__);
dims__.resize(0);
dims__.push_back(N);
dimss__.push_back(dims__);
dims__.resize(0);
dims__.push_back(N);
dimss__.push_back(dims__);
dims__.resize(0);
dimss__.push_back(dims__);
dims__.resize(0);
dimss__.push_back(dims__);
dims__.resize(0);
dimss__.push_back(dims__);
dims__.resize(0);
dimss__.push_back(dims__);
dims__.resize(0);
dimss__.push_back(dims__);
dims__.resize(0);
dimss__.push_back(dims__);
dims__.resize(0);
} // get_dims()
template <typename RNG>
void write_array(RNG &base_rng__, std::vector<double> &params_r__,
std::vector<int> &params_i__, std::vector<double> &vars__,
bool emit_transformed_parameters__ = true,
bool emit_generated_quantities__ = true,
std::ostream *pstream__ = 0) const {
typedef double local_scalar_t__;
vars__.resize(0);
stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
static const char *function__ = "hepatitis_model_namespace::write_array";
(void)function__; // suppress unused var warning
(void)function__; // suppress unused var warning
try {
double sigmasq_y;
current_statement__ = 2;
assign(sigmasq_y, nil_index_list(), in__.scalar(),
"assigning variable sigmasq_y");
current_statement__ = 2;
assign(sigmasq_y, nil_index_list(), lb_constrain(sigmasq_y, 0),
"assigning variable sigmasq_y");
double sigmasq_alpha;
current_statement__ = 3;
assign(sigmasq_alpha, nil_index_list(), in__.scalar(),
"assigning variable sigmasq_alpha");
current_statement__ = 3;
assign(sigmasq_alpha, nil_index_list(), lb_constrain(sigmasq_alpha, 0),
"assigning variable sigmasq_alpha");
double sigmasq_beta;
current_statement__ = 4;
assign(sigmasq_beta, nil_index_list(), in__.scalar(),
"assigning variable sigmasq_beta");
current_statement__ = 4;
assign(sigmasq_beta, nil_index_list(), lb_constrain(sigmasq_beta, 0),
"assigning variable sigmasq_beta");
std::vector<double> alpha;
alpha = std::vector<double>(N, 0);
current_statement__ = 5;
for (size_t sym1__ = 1; sym1__ <= N; ++sym1__) {
current_statement__ = 5;
assign(alpha, cons_list(index_uni(sym1__), nil_index_list()),
in__.scalar(), "assigning variable alpha[(sym1__ - 1)]");
}
std::vector<double> beta;
beta = std::vector<double>(N, 0);
current_statement__ = 6;
for (size_t sym1__ = 1; sym1__ <= N; ++sym1__) {
current_statement__ = 6;
assign(beta, cons_list(index_uni(sym1__), nil_index_list()),
in__.scalar(), "assigning variable beta[(sym1__ - 1)]");
}
double gamma;
current_statement__ = 7;
assign(gamma, nil_index_list(), in__.scalar(),
"assigning variable gamma");
double alpha0;
current_statement__ = 8;
assign(alpha0, nil_index_list(), in__.scalar(),
"assigning variable alpha0");
double beta0;
current_statement__ = 9;
assign(beta0, nil_index_list(), in__.scalar(),
"assigning variable beta0");
current_statement__ = 0;
vars__.push_back(sigmasq_y);
current_statement__ = 0;
vars__.push_back(sigmasq_alpha);
current_statement__ = 0;
vars__.push_back(sigmasq_beta);
current_statement__ = 0;
for (size_t sym1__ = 1; sym1__ <= N; ++sym1__) {
current_statement__ = 0;
vars__.push_back(rvalue(alpha,
cons_list(index_uni(sym1__), nil_index_list()),
"pretty printed e"));
}
current_statement__ = 0;
for (size_t sym1__ = 1; sym1__ <= N; ++sym1__) {
current_statement__ = 0;
vars__.push_back(rvalue(beta,
cons_list(index_uni(sym1__), nil_index_list()),
"pretty printed e"));
}
current_statement__ = 0;
vars__.push_back(gamma);
current_statement__ = 0;
vars__.push_back(alpha0);
current_statement__ = 0;
vars__.push_back(beta0);
double sigma_y;
double sigma_alpha;
double sigma_beta;
current_statement__ = 0;
if (emit_transformed_parameters__) {
current_statement__ = 13;
assign(sigma_y, nil_index_list(), stan::math::sqrt(sigmasq_y),
"assigning variable sigma_y");
current_statement__ = 14;
assign(sigma_alpha, nil_index_list(), stan::math::sqrt(sigmasq_alpha),
"assigning variable sigma_alpha");
current_statement__ = 15;
assign(sigma_beta, nil_index_list(), stan::math::sqrt(sigmasq_beta),
"assigning variable sigma_beta");
current_statement__ = 0;
vars__.push_back(sigma_y);
current_statement__ = 0;
vars__.push_back(sigma_alpha);
current_statement__ = 0;
vars__.push_back(sigma_beta);
}
} catch (const std::exception &e) {
stan::lang::rethrow_located(
std::runtime_error(std::string("inside write_array") + ": " +
e.what()),
locations_array__[current_statement__]);
// Next line prevents compiler griping about no return
throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
}
} // write_array()
void constrained_param_names(std::vector<std::string> &param_names__,
bool emit_transformed_parameters__ = true,
bool emit_generated_quantities__ = true) const {
param_names__.push_back(std::string() + "sigmasq_y");
param_names__.push_back(std::string() + "sigmasq_alpha");
param_names__.push_back(std::string() + "sigmasq_beta");
for (size_t sym1__ = 1; sym1__ <= N; ++sym1__) {
{
param_names__.push_back(std::string() + "alpha" + '.' +
std::to_string(sym1__));
}
}
for (size_t sym1__ = 1; sym1__ <= N; ++sym1__) {
{
param_names__.push_back(std::string() + "beta" + '.' +
std::to_string(sym1__));
}
}
param_names__.push_back(std::string() + "gamma");
param_names__.push_back(std::string() + "alpha0");
param_names__.push_back(std::string() + "beta0");
if (emit_transformed_parameters__) {
param_names__.push_back(std::string() + "sigma_y");
param_names__.push_back(std::string() + "sigma_alpha");
param_names__.push_back(std::string() + "sigma_beta");
}
if (emit_generated_quantities__) {
}
} // constrained_param_names()
void
unconstrained_param_names(std::vector<std::string> &param_names__,
bool emit_transformed_parameters__ = true,
bool emit_generated_quantities__ = true) const {
param_names__.push_back(std::string() + "sigmasq_y");
param_names__.push_back(std::string() + "sigmasq_alpha");
param_names__.push_back(std::string() + "sigmasq_beta");
for (size_t sym1__ = 1; sym1__ <= N; ++sym1__) {
{
param_names__.push_back(std::string() + "alpha" + '.' +
std::to_string(sym1__));
}
}
for (size_t sym1__ = 1; sym1__ <= N; ++sym1__) {
{
param_names__.push_back(std::string() + "beta" + '.' +
std::to_string(sym1__));
}
}
param_names__.push_back(std::string() + "gamma");
param_names__.push_back(std::string() + "alpha0");
param_names__.push_back(std::string() + "beta0");
if (emit_transformed_parameters__) {
param_names__.push_back(std::string() + "sigma_y");
param_names__.push_back(std::string() + "sigma_alpha");
param_names__.push_back(std::string() + "sigma_beta");
}
if (emit_generated_quantities__) {
}
} // unconstrained_param_names()
void transform_inits(const stan::io::var_context &context__,
std::vector<int> &params_i__,
std::vector<double> &params_r__,
std::ostream *pstream__) const {
typedef double local_scalar_t__;
stan::io::writer<double> writer__(params_r__, params_i__);
std::vector<double> vals_r__;
std::vector<int> vals_i__;
try {
int pos__;
double sigmasq_y;
current_statement__ = 2;
current_statement__ = 2;
assign(sigmasq_y, nil_index_list(),
context__.vals_r("sigmasq_y")[(1 - 1)],
"assigning variable sigmasq_y");
current_statement__ = 2;
assign(sigmasq_y, nil_index_list(), lb_free(sigmasq_y, 0),
"assigning variable sigmasq_y");
double sigmasq_alpha;
current_statement__ = 3;
current_statement__ = 3;
assign(sigmasq_alpha, nil_index_list(),
context__.vals_r("sigmasq_alpha")[(1 - 1)],
"assigning variable sigmasq_alpha");
current_statement__ = 3;
assign(sigmasq_alpha, nil_index_list(), lb_free(sigmasq_alpha, 0),
"assigning variable sigmasq_alpha");
double sigmasq_beta;
current_statement__ = 4;
current_statement__ = 4;
assign(sigmasq_beta, nil_index_list(),
context__.vals_r("sigmasq_beta")[(1 - 1)],
"assigning variable sigmasq_beta");
current_statement__ = 4;
assign(sigmasq_beta, nil_index_list(), lb_free(sigmasq_beta, 0),
"assigning variable sigmasq_beta");
std::vector<double> alpha;
alpha = std::vector<double>(N, 0);
current_statement__ = 5;
pos__ = 1;
current_statement__ = 5;
for (size_t sym1__ = 1; sym1__ <= N; ++sym1__) {
current_statement__ = 5;
assign(alpha, cons_list(index_uni(sym1__), nil_index_list()),
context__.vals_r("alpha")[(pos__ - 1)],
"assigning variable alpha[(sym1__ - 1)]");
current_statement__ = 5;
assign(pos__, nil_index_list(), (stan::model::deep_copy(pos__) + 1),
"assigning variable pos__");
}
std::vector<double> beta;
beta = std::vector<double>(N, 0);
current_statement__ = 6;
pos__ = 1;
current_statement__ = 6;
for (size_t sym1__ = 1; sym1__ <= N; ++sym1__) {
current_statement__ = 6;
assign(beta, cons_list(index_uni(sym1__), nil_index_list()),
context__.vals_r("beta")[(pos__ - 1)],
"assigning variable beta[(sym1__ - 1)]");
current_statement__ = 6;
assign(pos__, nil_index_list(), (stan::model::deep_copy(pos__) + 1),
"assigning variable pos__");
}
double gamma;
current_statement__ = 7;
current_statement__ = 7;
assign(gamma, nil_index_list(), context__.vals_r("gamma")[(1 - 1)],
"assigning variable gamma");
double alpha0;
current_statement__ = 8;
current_statement__ = 8;
assign(alpha0, nil_index_list(), context__.vals_r("alpha0")[(1 - 1)],
"assigning variable alpha0");
double beta0;
current_statement__ = 9;
current_statement__ = 9;
assign(beta0, nil_index_list(), context__.vals_r("beta0")[(1 - 1)],
"assigning variable beta0");
} catch (const std::exception &e) {
stan::lang::rethrow_located(
std::runtime_error(std::string("inside transform_inits") + ": " +
e.what()),
locations_array__[current_statement__]);
// Next line prevents compiler griping about no return
throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
}
} // transform_inits()
template <typename RNG>
void write_array(RNG &base_rng__,
Eigen::Matrix<double, Eigen::Dynamic, 1> &params_r,
Eigen::Matrix<double, Eigen::Dynamic, 1> &vars,
bool emit_transformed_parameters__ = true,
bool emit_generated_quantities__ = true,
std::ostream *pstream = 0) const {
std::vector<double> params_r_vec(params_r.size());
for (int i = 0; i < params_r.size(); ++i)
params_r_vec[i] = params_r(i);
std::vector<double> vars_vec;
std::vector<int> params_i_vec;
write_array(base_rng__, params_r_vec, params_i_vec, vars_vec,
emit_transformed_parameters__, emit_generated_quantities__,
pstream);
vars.resize(vars_vec.size());
for (int i = 0; i < vars.size(); ++i)
vars(i) = vars_vec[i];
}
template <bool propto__, bool jacobian__, typename T_>
T_ log_prob(Eigen::Matrix<T_, Eigen::Dynamic, 1> &params_r,
std::ostream *pstream = 0) const {
std::vector<T_> vec_params_r;
vec_params_r.reserve(params_r.size());
for (int i = 0; i < params_r.size(); ++i)
vec_params_r.push_back(params_r(i));
std::vector<int> vec_params_i;
return log_prob<propto__, jacobian__, T_>(vec_params_r, vec_params_i,
pstream);
}
};
} // namespace hepatitis_model_namespace
typedef hepatitis_model_namespace::hepatitis_model stan_model;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment