Compile issue for RStan

empty, screenshot below:
image

And

system.file('include', package = 'RcppEigen')

?

image

Try first doing

rstan_options("eigen_lib" = system.file(‘include’, package = 'RcppEigen'))

then stan(...).

Hi Ben,

It still does not work, as the screenshot below indicates, previous error shows again…The RStan right now installed on my laptop is from the link: install.packages(“https://win-builder.r-project.org/jpMlFHwQs41q/rstan_2.19.1.zip”, repos = NULL)

BTW, do you think it will work if I download the R to the version 3.4.**, since right now one big difference between my personal laptop and company laptop is the R version.

R version is 3.6.0 in my company laptop
R version is 3.4.4 in my personal laptop

One thing for your reference.

When I invoke Rstan via library(rstan) in my company laptop, it always tells that the package of “RstanHeaders”, “RcppEigen”, etc. can not be loaded. I have to use the statement library(…) to invoke them before library(rstan).

it never tells the load thing when I invoke the RStan package at my own laptop.

I don’t think the version number of R matters here. In a clean R session, I would try

remove.packages("rstan")
install.packages("https://win-builder.r-project.org/jpMlFHwQs41q/rstan_2.19.1.zip", repos = NULL)

Sure, will re-try it.

What does a clean R session mean?

Without any stanfit objects being auto-loaded through the .RData file.

Hi Ben,

I re-install RStan in a clean session as you suggestion. However, it is still with issue:

As you see, BH has already installed, but when I invoke stan (…), it always mentions that Boost not found.

It is similar to the issue of “RcppEigen” yesterday, I installed “RcppEigen”, but it always ask me to install.

Additionally, I found out that although I install R, RStudio, Rtool and related package in C drive. However, when I run the statement: dotR ← file.path(Sys.getenv(“HOME”), “.R”) , it does not provide a path starting with “C:…”, the screenshot below:

image

This hint lets me assume that RStan still tries to get the necessary file from “//domain.internal/dfs/home/chzhang/…” rather than the related folder from C drive I installed related files. This may be the error source.

If my assumption correct, how to let RStan to get the necessary file from where I install?

Attach the screenshot regarding BH issue:

Hi Ben,

I run Sys.getenv() at my own laptop and company laptop. Here I highlight as yellow for the differences:

My own laptop:


My company laptop:


Please note that for all the highlight items, all are with identical names but different values; except for:
“Moz_PLUGIN_PATH” named in my own laptop with value “C:\program files…”
“MSYS2_ENV_CONV_EXCL” named in my company laptop with value “R_ARCH”

Additionally, my own laptop has two more items:
image

Hi Ben, after I set the R environment similar to my own laptop, after I run the code below:

still, I have the error message like below:

Can you call stan with the verbose = TRUE argument? It is not finding any of your header files by default.

Hi Ben,

As you suggests, I add the options “verbose = TRUE”, still the similar error:

Attached the the program source when I run the statement: fit <- stan(file = ‘C:/Users/chzhang/Desktop/RStan/Example/8schools.stan’, data = schools_dat, verbose = TRUE)

Program source:
1:
2: // includes from the plugin
3: // [[Rcpp::plugins(cpp14)]]
4:
5: // user includes
6: #define STAN__SERVICES__COMMAND_HPP// Code generated by Stan version 2.19.1
7:
8: #include <stan/model/model_header.hpp>
9:
10: namespace model4b0224a47c7_8schools_namespace {
11:
12: using std::istream;
13: using std::string;
14: using std::stringstream;
15: using std::vector;
16: using stan::io::dump;
17: using stan::math::lgamma;
18: using stan::model::prob_grad;
19: using namespace stan::math;
20:
21: static int current_statement_begin__;
22:
23: stan::io::program_reader prog_reader__() {
24: stan::io::program_reader reader;
25: reader.add_event(0, 0, “start”, “model4b0224a47c7_8schools”);
26: reader.add_event(20, 18, “end”, “model4b0224a47c7_8schools”);
27: return reader;
28: }
29:
30: class model4b0224a47c7_8schools : public prob_grad {
31: private:
32: int J;
33: std::vector y;
34: std::vector sigma;
35: public:
36: model4b0224a47c7_8schools(stan::io::var_context& context__,
37: std::ostream* pstream__ = 0)
38: : prob_grad(0) {
39: ctor_body(context__, 0, pstream__);
40: }
41:
42: model4b0224a47c7_8schools(stan::io::var_context& context__,
43: unsigned int random_seed__,
44: std::ostream* pstream__ = 0)
45: : prob_grad(0) {
46: ctor_body(context__, random_seed__, pstream__);
47: }
48:
49: void ctor_body(stan::io::var_context& context__,
50: unsigned int random_seed__,
51: std::ostream* pstream__) {
52: typedef double local_scalar_t__;
53:
54: boost::ecuyer1988 base_rng__ =
55: stan::services::util::create_rng(random_seed__, 0);
56: (void) base_rng__; // suppress unused var warning
57:
58: current_statement_begin__ = -1;
59:
60: static const char* function__ = “model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools”;
61: (void) function__; // dummy to suppress unused var warning
62: size_t pos__;
63: (void) pos__; // dummy to suppress unused var warning
64: std::vector vals_i__;
65: std::vector vals_r__;
66: local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN());
67: (void) DUMMY_VAR__; // suppress unused var warning
68:
69: try {
70: // initialize data block variables from context__
71: current_statement_begin__ = 3;
72: context__.validate_dims(“data initialization”, “J”, “int”, context__.to_vec());
73: J = int(0);
74: vals_i__ = context__.vals_i(“J”);
75: pos__ = 0;
76: J = vals_i__[pos__++];
77: check_greater_or_equal(function__, “J”, J, 0);
78:
79: current_statement_begin__ = 4;
80: validate_non_negative_index(“y”, “J”, J);
81: context__.validate_dims(“data initialization”, “y”, “double”, context__.to_vec(J));
82: y = std::vector(J, double(0));
83: vals_r__ = context__.vals_r(“y”);
84: pos__ = 0;
85: size_t y_k_0_max__ = J;
86: for (size_t k_0__ = 0; k_0__ < y_k_0_max__; ++k_0__) {
87: y[k_0__] = vals_r__[pos__++];
88: }
89:
90: current_statement_begin__ = 5;
91: validate_non_negative_index(“sigma”, “J”, J);
92: context__.validate_dims(“data initialization”, “sigma”, “double”, context__.to_vec(J));
93: sigma = std::vector(J, double(0));
94: vals_r__ = context__.vals_r(“sigma”);
95: pos__ = 0;
96: size_t sigma_k_0_max__ = J;
97: for (size_t k_0__ = 0; k_0__ < sigma_k_0_max__; ++k_0__) {
98: sigma[k_0__] = vals_r__[pos__++];
99: }
100: size_t sigma_i_0_max__ = J;
101: for (size_t i_0__ = 0; i_0__ < sigma_i_0_max__; ++i_0__) {
102: check_greater_or_equal(function__, “sigma[i_0__]”, sigma[i_0__], 0);
103: }
104:
105:
106: // initialize transformed data variables
107: // execute transformed data statements
108:
109: // validate transformed data
110:
111: // validate, set parameter ranges
112: num_params_r__ = 0U;
113: param_ranges_i__.clear();
114: current_statement_begin__ = 8;
115: num_params_r__ += 1;
116: current_statement_begin__ = 9;
117: num_params_r__ += 1;
118: current_statement_begin__ = 10;
119: validate_non_negative_index(“eta”, “J”, J);
120: num_params_r__ += J;
121: } catch (const std::exception& e) {
122: stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
123: // Next line prevents compiler griping about no return
124: throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ");
125: }
126: }
127:
128: ~model4b0224a47c7_8schools() { }
129:
130:
131: void transform_inits(const stan::io::var_context& context__,
132: std::vector& params_i__,
133: std::vector& params_r__,
134: std::ostream
pstream__) const {
135: typedef double local_scalar_t__;
136: stan::io::writer writer__(params_r__, params_i__);
137: size_t pos__;
138: (void) pos__; // dummy call to supress warning
139: std::vector vals_r__;
140: std::vector vals_i__;
141:
142: current_statement_begin__ = 8;
143: if (!(context__.contains_r(“mu”)))
144: stan::lang::rethrow_located(std::runtime_error(std::string(“Variable mu missing”)), current_statement_begin__, prog_reader__());
145: vals_r__ = context__.vals_r(“mu”);
146: pos__ = 0U;
147: context__.validate_dims(“parameter initialization”, “mu”, “double”, context__.to_vec());
148: double mu(0);
149: mu = vals_r__[pos__++];
150: try {
151: writer__.scalar_unconstrain(mu);
152: } catch (const std::exception& e) {
153: stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable mu: ") + e.what()), current_statement_begin__, prog_reader__());
154: }
155:
156: current_statement_begin__ = 9;
157: if (!(context__.contains_r(“tau”)))
158: stan::lang::rethrow_located(std::runtime_error(std::string(“Variable tau missing”)), current_statement_begin__, prog_reader__());
159: vals_r__ = context__.vals_r(“tau”);
160: pos__ = 0U;
161: context__.validate_dims(“parameter initialization”, “tau”, “double”, context__.to_vec());
162: double tau(0);
163: tau = vals_r__[pos__++];
164: try {
165: writer__.scalar_lb_unconstrain(0, tau);
166: } catch (const std::exception& e) {
167: stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable tau: ") + e.what()), current_statement_begin__, prog_reader__());
168: }
169:
170: current_statement_begin__ = 10;
171: if (!(context__.contains_r(“eta”)))
172: stan::lang::rethrow_located(std::runtime_error(std::string(“Variable eta missing”)), current_statement_begin__, prog_reader__());
173: vals_r__ = context__.vals_r(“eta”);
174: pos__ = 0U;
175: validate_non_negative_index(“eta”, “J”, J);
176: context__.validate_dims(“parameter initialization”, “eta”, “vector_d”, context__.to_vec(J));
177: Eigen::Matrix<double, Eigen::Dynamic, 1> eta(J);
178: size_t eta_j_1_max__ = J;
179: for (size_t j_1__ = 0; j_1__ < eta_j_1_max__; ++j_1__) {
180: eta(j_1__) = vals_r__[pos__++];
181: }
182: try {
183: writer__.vector_unconstrain(eta);
184: } catch (const std::exception& e) {
185: stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable eta: ") + e.what()), current_statement_begin__, prog_reader__());
186: }
187:
188: params_r__ = writer__.data_r();
189: params_i__ = writer__.data_i();
190: }
191:
192: void transform_inits(const stan::io::var_context& context,
193: Eigen::Matrix<double, Eigen::Dynamic, 1>& params_r,
194: std::ostream
pstream__) const {
195: std::vector params_r_vec;
196: std::vector params_i_vec;
197: transform_inits(context, params_i_vec, params_r_vec, pstream__);
198: params_r.resize(params_r_vec.size());
199: for (int i = 0; i < params_r.size(); ++i)
200: params_r(i) = params_r_vec[i];
201: }
202:
203:
204: template <bool propto__, bool jacobian__, typename T__>
205: T__ log_prob(std::vector<T__>& params_r__,
206: std::vector& params_i__,
207: std::ostream
pstream__ = 0) const {
208:
209: typedef T__ local_scalar_t__;
210:
211: local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN());
212: (void) DUMMY_VAR__; // dummy to suppress unused var warning
213:
214: T__ lp__(0.0);
215: stan::math::accumulator<T__> lp_accum__;
216: try {
217: stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
218:
219: // model parameters
220: current_statement_begin__ = 8;
221: local_scalar_t__ mu;
222: (void) mu; // dummy to suppress unused var warning
223: if (jacobian__)
224: mu = in__.scalar_constrain(lp__);
225: else
226: mu = in__.scalar_constrain();
227:
228: current_statement_begin__ = 9;
229: local_scalar_t__ tau;
230: (void) tau; // dummy to suppress unused var warning
231: if (jacobian__)
232: tau = in__.scalar_lb_constrain(0, lp__);
233: else
234: tau = in__.scalar_lb_constrain(0);
235:
236: current_statement_begin__ = 10;
237: Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> eta;
238: (void) eta; // dummy to suppress unused var warning
239: if (jacobian__)
240: eta = in__.vector_constrain(J, lp__);
241: else
242: eta = in__.vector_constrain(J);
243:
244: // transformed parameters
245: current_statement_begin__ = 13;
246: validate_non_negative_index(“theta”, “J”, J);
247: Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> theta(J);
248: stan::math::initialize(theta, DUMMY_VAR__);
249: stan::math::fill(theta, DUMMY_VAR__);
250: stan::math::assign(theta,add(mu, multiply(tau, eta)));
251:
252: // validate transformed parameters
253: const char* function__ = “validate transformed params”;
254: (void) function__; // dummy to suppress unused var warning
255:
256: current_statement_begin__ = 13;
257: size_t theta_j_1_max__ = J;
258: for (size_t j_1__ = 0; j_1__ < theta_j_1_max__; ++j_1__) {
259: if (stan::math::is_uninitialized(theta(j_1__))) {
260: std::stringstream msg__;
261: msg__ << “Undefined transformed parameter: theta” << “(” << j_1__ << “)”;
262: stan::lang::rethrow_located(std::runtime_error(std::string(“Error initializing variable theta: “) + msg__.str()), current_statement_begin__, prog_reader__());
263: }
264: }
265:
266: // model body
267:
268: current_statement_begin__ = 16;
269: lp_accum__.add(normal_log(eta, 0, 1));
270: current_statement_begin__ = 17;
271: lp_accum__.add(normal_log(y, theta, sigma));
272:
273: } catch (const std::exception& e) {
274: stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
275: // Next line prevents compiler griping about no return
276: throw std::runtime_error(”*** IF YOU SEE THIS, PLEASE REPORT A BUG ");
277: }
278:
279: lp_accum__.add(lp__);
280: return lp_accum__.sum();
281:
282: } // log_prob()
283:
284: template <bool propto, bool jacobian, typename T_>
285: T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
286: std::ostream
pstream = 0) const {
287: std::vector<T_> vec_params_r;
288: vec_params_r.reserve(params_r.size());
289: for (int i = 0; i < params_r.size(); ++i)
290: vec_params_r.push_back(params_r(i));
291: std::vector vec_params_i;
292: return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);
293: }
294:
295:
296: void get_param_names(std::vectorstd::string& names__) const {
297: names__.resize(0);
298: names__.push_back(“mu”);
299: names__.push_back(“tau”);
300: names__.push_back(“eta”);
301: names__.push_back(“theta”);
302: }
303:
304:
305: void get_dims(std::vector<std::vector<size_t> >& dimss__) const {
306: dimss__.resize(0);
307: std::vector<size_t> dims__;
308: dims__.resize(0);
309: dimss__.push_back(dims__);
310: dims__.resize(0);
311: dimss__.push_back(dims__);
312: dims__.resize(0);
313: dims__.push_back(J);
314: dimss__.push_back(dims__);
315: dims__.resize(0);
316: dims__.push_back(J);
317: dimss__.push_back(dims__);
318: }
319:
320: template
321: void write_array(RNG& base_rng__,
322: std::vector& params_r__,
323: std::vector& params_i__,
324: std::vector& vars__,
325: bool include_tparams__ = true,
326: bool include_gqs__ = true,
327: std::ostream
pstream__ = 0) const {
328: typedef double local_scalar_t__;
329:
330: vars__.resize(0);
331: stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
332: static const char
function__ = “model4b0224a47c7_8schools_namespace::write_array”;
333: (void) function__; // dummy to suppress unused var warning
334:
335: // read-transform, write parameters
336: double mu = in__.scalar_constrain();
337: vars__.push_back(mu);
338:
339: double tau = in__.scalar_lb_constrain(0);
340: vars__.push_back(tau);
341:
342: Eigen::Matrix<double, Eigen::Dynamic, 1> eta = in__.vector_constrain(J);
343: size_t eta_j_1_max__ = J;
344: for (size_t j_1__ = 0; j_1__ < eta_j_1_max__; ++j_1__) {
345: vars__.push_back(eta(j_1__));
346: }
347:
348: double lp__ = 0.0;
349: (void) lp__; // dummy to suppress unused var warning
350: stan::math::accumulator lp_accum__;
351:
352: local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN());
353: (void) DUMMY_VAR__; // suppress unused var warning
354:
355: if (!include_tparams__ && !include_gqs__) return;
356:
357: try {
358: // declare and define transformed parameters
359: current_statement_begin__ = 13;
360: validate_non_negative_index(“theta”, “J”, J);
361: Eigen::Matrix<double, Eigen::Dynamic, 1> theta(J);
362: stan::math::initialize(theta, DUMMY_VAR__);
363: stan::math::fill(theta, DUMMY_VAR__);
364: stan::math::assign(theta,add(mu, multiply(tau, eta)));
365:
366: if (!include_gqs__ && !include_tparams__) return;
367: // validate transformed parameters
368: const char* function__ = “validate transformed params”;
369: (void) function__; // dummy to suppress unused var warning
370:
371: // write transformed parameters
372: if (include_tparams__) {
373: size_t theta_j_1_max__ = J;
374: for (size_t j_1__ = 0; j_1__ < theta_j_1_max__; ++j_1__) {
375: vars__.push_back(theta(j_1__));
376: }
377: }
378: if (!include_gqs__) return;
379: } catch (const std::exception& e) {
380: stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
381: // Next line prevents compiler griping about no return
382: throw std::runtime_error(”*** IF YOU SEE THIS, PLEASE REPORT A BUG ");
383: }
384: }
385:
386: template
387: void write_array(RNG& base_rng,
388: Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
389: Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
390: bool include_tparams = true,
391: bool include_gqs = true,
392: std::ostream
pstream = 0) const {
393: std::vector params_r_vec(params_r.size());
394: for (int i = 0; i < params_r.size(); ++i)
395: params_r_vec[i] = params_r(i);
396: std::vector vars_vec;
397: std::vector params_i_vec;
398: write_array(base_rng, params_r_vec, params_i_vec, vars_vec, include_tparams, include_gqs, pstream);
399: vars.resize(vars_vec.size());
400: for (int i = 0; i < vars.size(); ++i)
401: vars(i) = vars_vec[i];
402: }
403:
404: static std::string model_name() {
405: return “model4b0224a47c7_8schools”;
406: }
407:
408:
409: void constrained_param_names(std::vectorstd::string& param_names__,
410: bool include_tparams__ = true,
411: bool include_gqs__ = true) const {
412: std::stringstream param_name_stream__;
413: param_name_stream__.str(std::string());
414: param_name_stream__ << “mu”;
415: param_names__.push_back(param_name_stream__.str());
416: param_name_stream__.str(std::string());
417: param_name_stream__ << “tau”;
418: param_names__.push_back(param_name_stream__.str());
419: size_t eta_j_1_max__ = J;
420: for (size_t j_1__ = 0; j_1__ < eta_j_1_max__; ++j_1__) {
421: param_name_stream__.str(std::string());
422: param_name_stream__ << “eta” << ‘.’ << j_1__ + 1;
423: param_names__.push_back(param_name_stream__.str());
424: }
425:
426: if (!include_gqs__ && !include_tparams__) return;
427:
428: if (include_tparams__) {
429: size_t theta_j_1_max__ = J;
430: for (size_t j_1__ = 0; j_1__ < theta_j_1_max__; ++j_1__) {
431: param_name_stream__.str(std::string());
432: param_name_stream__ << “theta” << ‘.’ << j_1__ + 1;
433: param_names__.push_back(param_name_stream__.str());
434: }
435: }
436:
437: if (!include_gqs__) return;
438: }
439:
440:
441: void unconstrained_param_names(std::vectorstd::string& param_names__,
442: bool include_tparams__ = true,
443: bool include_gqs__ = true) const {
444: std::stringstream param_name_stream__;
445: param_name_stream__.str(std::string());
446: param_name_stream__ << “mu”;
447: param_names__.push_back(param_name_stream__.str());
448: param_name_stream__.str(std::string());
449: param_name_stream__ << “tau”;
450: param_names__.push_back(param_name_stream__.str());
451: size_t eta_j_1_max__ = J;
452: for (size_t j_1__ = 0; j_1__ < eta_j_1_max__; ++j_1__) {
453: param_name_stream__.str(std::string());
454: param_name_stream__ << “eta” << ‘.’ << j_1__ + 1;
455: param_names__.push_back(param_name_stream__.str());
456: }
457:
458: if (!include_gqs__ && !include_tparams__) return;
459:
460: if (include_tparams__) {
461: size_t theta_j_1_max__ = J;
462: for (size_t j_1__ = 0; j_1__ < theta_j_1_max__; ++j_1__) {
463: param_name_stream__.str(std::string());
464: param_name_stream__ << “theta” << ‘.’ << j_1__ + 1;
465: param_names__.push_back(param_name_stream__.str());
466: }
467: }
468:
469: if (!include_gqs__) return;
470: }
471:
472: }; // model
473:
474: } // namespace
475:
476: typedef model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools stan_model;
477:
478: #include <rstan/rstaninc.hpp>
479: /

480: * Define Rcpp Module to expose stan_fit’s functions to R.
481: /
482: RCPP_MODULE(stan_fit4model4b0224a47c7_8schools_mod){
483: Rcpp::class_<rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools,
484: boost::random::ecuyer1988> >(“stan_fit4model4b0224a47c7_8schools”)
485: // .constructorRcpp::List()
486: .constructor<SEXP, SEXP, SEXP>()
487: // .constructor<SEXP, SEXP>()
488: .method(“call_sampler”,
489: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::call_sampler)
490: .method(“param_names”,
491: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::param_names)
492: .method(“param_names_oi”,
493: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::param_names_oi)
494: .method(“param_fnames_oi”,
495: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::param_fnames_oi)
496: .method(“param_dims”,
497: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::param_dims)
498: .method(“param_dims_oi”,
499: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::param_dims_oi)
500: .method(“update_param_oi”,
501: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::update_param_oi)
502: .method(“param_oi_tidx”,
503: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::param_oi_tidx)
504: .method(“grad_log_prob”,
505: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::grad_log_prob)
506: .method(“log_prob”,
507: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::log_prob)
508: .method(“unconstrain_pars”,
509: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::unconstrain_pars)
510: .method(“constrain_pars”,
511: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::constrain_pars)
512: .method(“num_pars_unconstrained”,
513: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::num_pars_unconstrained)
514: .method(“unconstrained_param_names”,
515: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::unconstrained_param_names)
516: .method(“constrained_param_names”,
517: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::constrained_param_names)
518: /

519: .method(“standalone_gqs”,
520: &rstan::stan_fit<model4b0224a47c7_8schools_namespace::model4b0224a47c7_8schools, boost::random::ecuyer1988>::standalone_gqs)
521: */
522: ;
523: }
524:
525: // declarations
526: extern “C” {
527: SEXP file4b03bd77d7e( ) ;
528: }
529:
530: // definition
531:
532: SEXP file4b03bd77d7e( ){
533: return Rcpp::wrap(“8schools”);
534: }
535:
536:

We need the part where it writes out the call to g++.

How to get that part?

It is right before or after the part you pasted.

Yeah, there is really some code before the source program I pasted. The things I assume they are identical to the source program; the most front line I can get is Line 97.

The thing below is all what get from the console after run the statement: fit <- stan(file = ‘C:/Users/chzhang/Desktop/RStan/Example/8schools.stan’, data = schools_dat, verbose = TRUE)

97 : for (size_t k_0__ = 0; k_0__ < sigma_k_0_max__; ++k_0__) {
98 : sigma[k_0__] = vals_r__[pos__++];
99 : }
100 : size_t sigma_i_0_max__ = J;
101 : for (size_t i_0__ = 0; i_0__ < sigma_i_0_max__; ++i_0__) {
102 : check_greater_or_equal(function__, “sigma[i_0__]”, sigma[i_0__], 0);
103 : }
104 :
105 :
106 : // initialize transformed data variables
107 : // execute transformed data statements
108 :
109 : // validate transformed data
110 :
111 : // validate, set parameter ranges
112 : num_params_r__ = 0U;
113 : param_ranges_i__.clear();
114 : current_statement_begin__ = 8;
115 : num_params_r__ += 1;
116 : current_statement_begin__ = 9;
117 : num_params_r__ += 1;
118 : current_statement_begin__ = 10;
119 : validate_non_negative_index(“eta”, “J”, J);
120 : num_params_r__ += J;
121 : } catch (const std::exception& e) {
122 : stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
123 : // Next line prevents compiler griping about no return
124 : throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ");
125 : }
126 : }
127 :
128 : ~model4b029fc1793_8schools() { }
129 :
130 :
131 : void transform_inits(const stan::io::var_context& context__,
132 : std::vector& params_i__,
133 : std::vector& params_r__,
134 : std::ostream
pstream__) const {
135 : typedef double local_scalar_t__;
136 : stan::io::writer writer__(params_r__, params_i__);
137 : size_t pos__;
138 : (void) pos__; // dummy call to supress warning
139 : std::vector vals_r__;
140 : std::vector vals_i__;
141 :
142 : current_statement_begin__ = 8;
143 : if (!(context__.contains_r(“mu”)))
144 : stan::lang::rethrow_located(std::runtime_error(std::string(“Variable mu missing”)), current_statement_begin__, prog_reader__());
145 : vals_r__ = context__.vals_r(“mu”);
146 : pos__ = 0U;
147 : context__.validate_dims(“parameter initialization”, “mu”, “double”, context__.to_vec());
148 : double mu(0);
149 : mu = vals_r__[pos__++];
150 : try {
151 : writer__.scalar_unconstrain(mu);
152 : } catch (const std::exception& e) {
153 : stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable mu: ") + e.what()), current_statement_begin__, prog_reader__());
154 : }
155 :
156 : current_statement_begin__ = 9;
157 : if (!(context__.contains_r(“tau”)))
158 : stan::lang::rethrow_located(std::runtime_error(std::string(“Variable tau missing”)), current_statement_begin__, prog_reader__());
159 : vals_r__ = context__.vals_r(“tau”);
160 : pos__ = 0U;
161 : context__.validate_dims(“parameter initialization”, “tau”, “double”, context__.to_vec());
162 : double tau(0);
163 : tau = vals_r__[pos__++];
164 : try {
165 : writer__.scalar_lb_unconstrain(0, tau);
166 : } catch (const std::exception& e) {
167 : stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable tau: ") + e.what()), current_statement_begin__, prog_reader__());
168 : }
169 :
170 : current_statement_begin__ = 10;
171 : if (!(context__.contains_r(“eta”)))
172 : stan::lang::rethrow_located(std::runtime_error(std::string(“Variable eta missing”)), current_statement_begin__, prog_reader__());
173 : vals_r__ = context__.vals_r(“eta”);
174 : pos__ = 0U;
175 : validate_non_negative_index(“eta”, “J”, J);
176 : context__.validate_dims(“parameter initialization”, “eta”, “vector_d”, context__.to_vec(J));
177 : Eigen::Matrix<double, Eigen::Dynamic, 1> eta(J);
178 : size_t eta_j_1_max__ = J;
179 : for (size_t j_1__ = 0; j_1__ < eta_j_1_max__; ++j_1__) {
180 : eta(j_1__) = vals_r__[pos__++];
181 : }
182 : try {
183 : writer__.vector_unconstrain(eta);
184 : } catch (const std::exception& e) {
185 : stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable eta: ") + e.what()), current_statement_begin__, prog_reader__());
186 : }
187 :
188 : params_r__ = writer__.data_r();
189 : params_i__ = writer__.data_i();
190 : }
191 :
192 : void transform_inits(const stan::io::var_context& context,
193 : Eigen::Matrix<double, Eigen::Dynamic, 1>& params_r,
194 : std::ostream
pstream__) const {
195 : std::vector params_r_vec;
196 : std::vector params_i_vec;
197 : transform_inits(context, params_i_vec, params_r_vec, pstream__);
198 : params_r.resize(params_r_vec.size());
199 : for (int i = 0; i < params_r.size(); ++i)
200 : params_r(i) = params_r_vec[i];
201 : }
202 :
203 :
204 : template <bool propto__, bool jacobian__, typename T__>
205 : T__ log_prob(std::vector<T__>& params_r__,
206 : std::vector& params_i__,
207 : std::ostream
pstream__ = 0) const {
208 :
209 : typedef T__ local_scalar_t__;
210 :
211 : local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN());
212 : (void) DUMMY_VAR__; // dummy to suppress unused var warning
213 :
214 : T__ lp__(0.0);
215 : stan::math::accumulator<T__> lp_accum__;
216 : try {
217 : stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
218 :
219 : // model parameters
220 : current_statement_begin__ = 8;
221 : local_scalar_t__ mu;
222 : (void) mu; // dummy to suppress unused var warning
223 : if (jacobian__)
224 : mu = in__.scalar_constrain(lp__);
225 : else
226 : mu = in__.scalar_constrain();
227 :
228 : current_statement_begin__ = 9;
229 : local_scalar_t__ tau;
230 : (void) tau; // dummy to suppress unused var warning
231 : if (jacobian__)
232 : tau = in__.scalar_lb_constrain(0, lp__);
233 : else
234 : tau = in__.scalar_lb_constrain(0);
235 :
236 : current_statement_begin__ = 10;
237 : Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> eta;
238 : (void) eta; // dummy to suppress unused var warning
239 : if (jacobian__)
240 : eta = in__.vector_constrain(J, lp__);
241 : else
242 : eta = in__.vector_constrain(J);
243 :
244 : // transformed parameters
245 : current_statement_begin__ = 13;
246 : validate_non_negative_index(“theta”, “J”, J);
247 : Eigen::Matrix<local_scalar_t__, Eigen::Dynamic, 1> theta(J);
248 : stan::math::initialize(theta, DUMMY_VAR__);
249 : stan::math::fill(theta, DUMMY_VAR__);
250 : stan::math::assign(theta,add(mu, multiply(tau, eta)));
251 :
252 : // validate transformed parameters
253 : const char* function__ = “validate transformed params”;
254 : (void) function__; // dummy to suppress unused var warning
255 :
256 : current_statement_begin__ = 13;
257 : size_t theta_j_1_max__ = J;
258 : for (size_t j_1__ = 0; j_1__ < theta_j_1_max__; ++j_1__) {
259 : if (stan::math::is_uninitialized(theta(j_1__))) {
260 : std::stringstream msg__;
261 : msg__ << “Undefined transformed parameter: theta” << “(” << j_1__ << “)”;
262 : stan::lang::rethrow_located(std::runtime_error(std::string(“Error initializing variable theta: “) + msg__.str()), current_statement_begin__, prog_reader__());
263 : }
264 : }
265 :
266 : // model body
267 :
268 : current_statement_begin__ = 16;
269 : lp_accum__.add(normal_log(eta, 0, 1));
270 : current_statement_begin__ = 17;
271 : lp_accum__.add(normal_log(y, theta, sigma));
272 :
273 : } catch (const std::exception& e) {
274 : stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
275 : // Next line prevents compiler griping about no return
276 : throw std::runtime_error(”*** IF YOU SEE THIS, PLEASE REPORT A BUG ");
277 : }
278 :
279 : lp_accum__.add(lp__);
280 : return lp_accum__.sum();
281 :
282 : } // log_prob()
283 :
284 : template <bool propto, bool jacobian, typename T_>
285 : T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
286 : std::ostream
pstream = 0) const {
287 : std::vector<T_> vec_params_r;
288 : vec_params_r.reserve(params_r.size());
289 : for (int i = 0; i < params_r.size(); ++i)
290 : vec_params_r.push_back(params_r(i));
291 : std::vector vec_params_i;
292 : return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);
293 : }
294 :
295 :
296 : void get_param_names(std::vectorstd::string& names__) const {
297 : names__.resize(0);
298 : names__.push_back(“mu”);
299 : names__.push_back(“tau”);
300 : names__.push_back(“eta”);
301 : names__.push_back(“theta”);
302 : }
303 :
304 :
305 : void get_dims(std::vector<std::vector<size_t> >& dimss__) const {
306 : dimss__.resize(0);
307 : std::vector<size_t> dims__;
308 : dims__.resize(0);
309 : dimss__.push_back(dims__);
310 : dims__.resize(0);
311 : dimss__.push_back(dims__);
312 : dims__.resize(0);
313 : dims__.push_back(J);
314 : dimss__.push_back(dims__);
315 : dims__.resize(0);
316 : dims__.push_back(J);
317 : dimss__.push_back(dims__);
318 : }
319 :
320 : template
321 : void write_array(RNG& base_rng__,
322 : std::vector& params_r__,
323 : std::vector& params_i__,
324 : std::vector& vars__,
325 : bool include_tparams__ = true,
326 : bool include_gqs__ = true,
327 : std::ostream
pstream__ = 0) const {
328 : typedef double local_scalar_t__;
329 :
330 : vars__.resize(0);
331 : stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
332 : static const char
function__ = “model4b029fc1793_8schools_namespace::write_array”;
333 : (void) function__; // dummy to suppress unused var warning
334 :
335 : // read-transform, write parameters
336 : double mu = in__.scalar_constrain();
337 : vars__.push_back(mu);
338 :
339 : double tau = in__.scalar_lb_constrain(0);
340 : vars__.push_back(tau);
341 :
342 : Eigen::Matrix<double, Eigen::Dynamic, 1> eta = in__.vector_constrain(J);
343 : size_t eta_j_1_max__ = J;
344 : for (size_t j_1__ = 0; j_1__ < eta_j_1_max__; ++j_1__) {
345 : vars__.push_back(eta(j_1__));
346 : }
347 :
348 : double lp__ = 0.0;
349 : (void) lp__; // dummy to suppress unused var warning
350 : stan::math::accumulator lp_accum__;
351 :
352 : local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN());
353 : (void) DUMMY_VAR__; // suppress unused var warning
354 :
355 : if (!include_tparams__ && !include_gqs__) return;
356 :
357 : try {
358 : // declare and define transformed parameters
359 : current_statement_begin__ = 13;
360 : validate_non_negative_index(“theta”, “J”, J);
361 : Eigen::Matrix<double, Eigen::Dynamic, 1> theta(J);
362 : stan::math::initialize(theta, DUMMY_VAR__);
363 : stan::math::fill(theta, DUMMY_VAR__);
364 : stan::math::assign(theta,add(mu, multiply(tau, eta)));
365 :
366 : if (!include_gqs__ && !include_tparams__) return;
367 : // validate transformed parameters
368 : const char* function__ = “validate transformed params”;
369 : (void) function__; // dummy to suppress unused var warning
370 :
371 : // write transformed parameters
372 : if (include_tparams__) {
373 : size_t theta_j_1_max__ = J;
374 : for (size_t j_1__ = 0; j_1__ < theta_j_1_max__; ++j_1__) {
375 : vars__.push_back(theta(j_1__));
376 : }
377 : }
378 : if (!include_gqs__) return;
379 : } catch (const std::exception& e) {
380 : stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
381 : // Next line prevents compiler griping about no return
382 : throw std::runtime_error(”*** IF YOU SEE THIS, PLEASE REPORT A BUG ");
383 : }
384 : }
385 :
386 : template
387 : void write_array(RNG& base_rng,
388 : Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
389 : Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
390 : bool include_tparams = true,
391 : bool include_gqs = true,
392 : std::ostream
pstream = 0) const {
393 : std::vector params_r_vec(params_r.size());
394 : for (int i = 0; i < params_r.size(); ++i)
395 : params_r_vec[i] = params_r(i);
396 : std::vector vars_vec;
397 : std::vector params_i_vec;
398 : write_array(base_rng, params_r_vec, params_i_vec, vars_vec, include_tparams, include_gqs, pstream);
399 : vars.resize(vars_vec.size());
400 : for (int i = 0; i < vars.size(); ++i)
401 : vars(i) = vars_vec[i];
402 : }
403 :
404 : static std::string model_name() {
405 : return “model4b029fc1793_8schools”;
406 : }
407 :
408 :
409 : void constrained_param_names(std::vectorstd::string& param_names__,
410 : bool include_tparams__ = true,
411 : bool include_gqs__ = true) const {
412 : std::stringstream param_name_stream__;
413 : param_name_stream__.str(std::string());
414 : param_name_stream__ << “mu”;
415 : param_names__.push_back(param_name_stream__.str());
416 : param_name_stream__.str(std::string());
417 : param_name_stream__ << “tau”;
418 : param_names__.push_back(param_name_stream__.str());
419 : size_t eta_j_1_max__ = J;
420 : for (size_t j_1__ = 0; j_1__ < eta_j_1_max__; ++j_1__) {
421 : param_name_stream__.str(std::string());
422 : param_name_stream__ << “eta” << ‘.’ << j_1__ + 1;
423 : param_names__.push_back(param_name_stream__.str());
424 : }
425 :
426 : if (!include_gqs__ && !include_tparams__) return;
427 :
428 : if (include_tparams__) {
429 : size_t theta_j_1_max__ = J;
430 : for (size_t j_1__ = 0; j_1__ < theta_j_1_max__; ++j_1__) {
431 : param_name_stream__.str(std::string());
432 : param_name_stream__ << “theta” << ‘.’ << j_1__ + 1;
433 : param_names__.push_back(param_name_stream__.str());
434 : }
435 : }
436 :
437 : if (!include_gqs__) return;
438 : }
439 :
440 :
441 : void unconstrained_param_names(std::vectorstd::string& param_names__,
442 : bool include_tparams__ = true,
443 : bool include_gqs__ = true) const {
444 : std::stringstream param_name_stream__;
445 : param_name_stream__.str(std::string());
446 : param_name_stream__ << “mu”;
447 : param_names__.push_back(param_name_stream__.str());
448 : param_name_stream__.str(std::string());
449 : param_name_stream__ << “tau”;
450 : param_names__.push_back(param_name_stream__.str());
451 : size_t eta_j_1_max__ = J;
452 : for (size_t j_1__ = 0; j_1__ < eta_j_1_max__; ++j_1__) {
453 : param_name_stream__.str(std::string());
454 : param_name_stream__ << “eta” << ‘.’ << j_1__ + 1;
455 : param_names__.push_back(param_name_stream__.str());
456 : }
457 :
458 : if (!include_gqs__ && !include_tparams__) return;
459 :
460 : if (include_tparams__) {
461 : size_t theta_j_1_max__ = J;
462 : for (size_t j_1__ = 0; j_1__ < theta_j_1_max__; ++j_1__) {
463 : param_name_stream__.str(std::string());
464 : param_name_stream__ << “theta” << ‘.’ << j_1__ + 1;
465 : param_names__.push_back(param_name_stream__.str());
466 : }
467 : }
468 :
469 : if (!include_gqs__) return;
470 : }
471 :
472 : }; // model
473 :
474 : } // namespace
475 :
476 : typedef model4b029fc1793_8schools_namespace::model4b029fc1793_8schools stan_model;
477 :
478 : #include <rstan/rstaninc.hpp>
479 : /

480 : * Define Rcpp Module to expose stan_fit’s functions to R.
481 : /
482 : RCPP_MODULE(stan_fit4model4b029fc1793_8schools_mod){
483 : Rcpp::class_<rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools,
484 : boost::random::ecuyer1988> >(“stan_fit4model4b029fc1793_8schools”)
485 : // .constructorRcpp::List()
486 : .constructor<SEXP, SEXP, SEXP>()
487 : // .constructor<SEXP, SEXP>()
488 : .method(“call_sampler”,
489 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::call_sampler)
490 : .method(“param_names”,
491 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::param_names)
492 : .method(“param_names_oi”,
493 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::param_names_oi)
494 : .method(“param_fnames_oi”,
495 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::param_fnames_oi)
496 : .method(“param_dims”,
497 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::param_dims)
498 : .method(“param_dims_oi”,
499 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::param_dims_oi)
500 : .method(“update_param_oi”,
501 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::update_param_oi)
502 : .method(“param_oi_tidx”,
503 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::param_oi_tidx)
504 : .method(“grad_log_prob”,
505 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::grad_log_prob)
506 : .method(“log_prob”,
507 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::log_prob)
508 : .method(“unconstrain_pars”,
509 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::unconstrain_pars)
510 : .method(“constrain_pars”,
511 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::constrain_pars)
512 : .method(“num_pars_unconstrained”,
513 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::num_pars_unconstrained)
514 : .method(“unconstrained_param_names”,
515 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::unconstrained_param_names)
516 : .method(“constrained_param_names”,
517 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::constrained_param_names)
518 : /

519 : .method(“standalone_gqs”,
520 : &rstan::stan_fit<model4b029fc1793_8schools_namespace::model4b029fc1793_8schools, boost::random::ecuyer1988>::standalone_gqs)
521 : */
522 : ;
523 : }
524 :
525 : // declarations
526 : extern “C” {
527 : SEXP file4b065d86567( ) ;
528 : }
529 :
530 : // definition
531 :
532 : SEXP file4b065d86567( ){
533 : return Rcpp::wrap(“8schools”);
534 : }
535 :
536 :

continue in next thread