Loading required package: StanHeaders Loading required package: ggplot2 rstan (Version 2.21.3, GitRev: 2e1f913d3ca3) For execution on a local, multicore CPU with excess RAM we recommend calling options(mc.cores = parallel::detectCores()). To avoid recompilation of unchanged Stan programs, we recommend calling rstan_options(auto_write = TRUE) Attaching package: ‘circular’ The following objects are masked from ‘package:stats’: sd, var Warning message: In as.circular(x) : an object is coerced to the class 'circular' using default value for the following components: type: 'angles' units: 'radians' template: 'none' modulo: 'asis' zero: 0 rotation: 'counter' conversion.circularmuradians0counter TRANSLATING MODEL 'model_code' FROM Stan CODE TO C++ CODE NOW. successful in parsing the Stan model 'model_code'. TRANSLATING MODEL 'b785e1b459e1a1bedfb490735b98118b' FROM Stan CODE TO C++ CODE NOW. successful in parsing the Stan model 'b785e1b459e1a1bedfb490735b98118b'. OS: x86_64, linux-gnu; rstan: 2.21.3; Rcpp: 1.0.5; inline: 0.3.16 >> setting environment variables: PKG_LIBS = '/home/satya/R/x86_64-pc-linux-gnu-library/4.0/rstan/lib//libStanServices.a' -L'/home/satya/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/lib/' -lStanHeaders -L'/home/satya/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/lib/' -ltbb PKG_CPPFLAGS = -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include/" -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include/" -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include/unsupported" -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/BH/include" -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/src/" -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/" -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include/" -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/home/satya/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 >> Program source : 1 : 2 : // includes from the plugin 3 : // [[Rcpp::plugins(cpp14)]] 4 : 5 : 6 : // user includes 7 : #include 8 : #include 9 : #include 10 : #include 11 : #include 12 : // Code generated by Stan version 2.21.0 13 : 14 : #include 15 : 16 : namespace model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b_namespace { 17 : 18 : using std::istream; 19 : using std::string; 20 : using std::stringstream; 21 : using std::vector; 22 : using stan::io::dump; 23 : using stan::math::lgamma; 24 : using stan::model::prob_grad; 25 : using namespace stan::math; 26 : 27 : static int current_statement_begin__; 28 : 29 : stan::io::program_reader prog_reader__() { 30 : stan::io::program_reader reader; 31 : reader.add_event(0, 0, "start", "model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b"); 32 : reader.add_event(20, 18, "end", "model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b"); 33 : return reader; 34 : } 35 : 36 : template 37 : typename boost::math::tools::promote_args::type 38 : custom_von_mises_lpdf(const T0__& y, 39 : const T1__& mu, 40 : const Eigen::Matrix& kappa, std::ostream* pstream__); 41 : 42 : 43 : #include "/home/satya/wrk/motocyte/src/motility_analysis/examples/glm/rstan_vmf/custom_von_mises_lpdf.hpp" 44 : class model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b 45 : : public stan::model::model_base_crtp { 46 : private: 47 : int N; 48 : int K; 49 : matrix_d X; 50 : vector_d y; 51 : public: 52 : model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b(rstan::io::rlist_ref_var_context& context__, 53 : std::ostream* pstream__ = 0) 54 : : model_base_crtp(0) { 55 : ctor_body(context__, 0, pstream__); 56 : } 57 : 58 : model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b(stan::io::var_context& context__, 59 : unsigned int random_seed__, 60 : std::ostream* pstream__ = 0) 61 : : model_base_crtp(0) { 62 : ctor_body(context__, random_seed__, pstream__); 63 : } 64 : 65 : void ctor_body(stan::io::var_context& context__, 66 : unsigned int random_seed__, 67 : std::ostream* pstream__) { 68 : typedef double local_scalar_t__; 69 : 70 : boost::ecuyer1988 base_rng__ = 71 : stan::services::util::create_rng(random_seed__, 0); 72 : (void) base_rng__; // suppress unused var warning 73 : 74 : current_statement_begin__ = -1; 75 : 76 : static const char* function__ = "model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b_namespace::model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b"; 77 : (void) function__; // dummy to suppress unused var warning 78 : size_t pos__; 79 : (void) pos__; // dummy to suppress unused var warning 80 : std::vector vals_i__; 81 : std::vector vals_r__; 82 : local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); 83 : (void) DUMMY_VAR__; // suppress unused var warning 84 : 85 : try { 86 : // initialize data block variables from context__ 87 : current_statement_begin__ = 6; 88 : context__.validate_dims("data initialization", "N", "int", context__.to_vec()); 89 : N = int(0); 90 : vals_i__ = context__.vals_i("N"); 91 : pos__ = 0; 92 : N = vals_i__[pos__++]; 93 : check_greater_or_equal(function__, "N", N, 0); 94 : 95 : current_statement_begin__ = 7; 96 : context__.validate_dims("data initialization", "K", "int", context__.to_vec()); 97 : K = int(0); 98 : vals_i__ = context__.vals_i("K"); 99 : pos__ = 0; 100 : K = vals_i__[pos__++]; 101 : check_greater_or_equal(function__, "K", K, 0); 102 : 103 : current_statement_begin__ = 8; 104 : validate_non_negative_index("X", "N", N); 105 : validate_non_negative_index("X", "K", K); 106 : context__.validate_dims("data initialization", "X", "matrix_d", context__.to_vec(N,K)); 107 : X = Eigen::Matrix(N, K); 108 : vals_r__ = context__.vals_r("X"); 109 : pos__ = 0; 110 : size_t X_j_2_max__ = K; 111 : size_t X_j_1_max__ = N; 112 : for (size_t j_2__ = 0; j_2__ < X_j_2_max__; ++j_2__) { 113 : for (size_t j_1__ = 0; j_1__ < X_j_1_max__; ++j_1__) { 114 : X(j_1__, j_2__) = vals_r__[pos__++]; 115 : } 116 : } 117 : 118 : current_statement_begin__ = 9; 119 : validate_non_negative_index("y", "N", N); 120 : context__.validate_dims("data initialization", "y", "vector_d", context__.to_vec(N)); 121 : y = Eigen::Matrix(N); 122 : vals_r__ = context__.vals_r("y"); 123 : pos__ = 0; 124 : size_t y_j_1_max__ = N; 125 : for (size_t j_1__ = 0; j_1__ < y_j_1_max__; ++j_1__) { 126 : y(j_1__) = vals_r__[pos__++]; 127 : } 128 : 129 : 130 : // initialize transformed data variables 131 : // execute transformed data statements 132 : 133 : // validate transformed data 134 : 135 : // validate, set parameter ranges 136 : num_params_r__ = 0U; 137 : param_ranges_i__.clear(); 138 : current_statement_begin__ = 12; 139 : num_params_r__ += 1; 140 : current_statement_begin__ = 13; 141 : num_params_r__ += 1; 142 : } catch (const std::exception& e) { 143 : stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__()); 144 : // Next line prevents compiler griping about no return 145 : throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 146 : } 147 : } 148 : 149 : ~model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b() { } 150 : 151 : 152 : void transform_inits(const stan::io::var_context& context__, 153 : std::vector& params_i__, 154 : std::vector& params_r__, 155 : std::ostream* pstream__) const { 156 : typedef double local_scalar_t__; 157 : stan::io::writer writer__(params_r__, params_i__); 158 : size_t pos__; 159 : (void) pos__; // dummy call to supress warning 160 : std::vector vals_r__; 161 : std::vector vals_i__; 162 : 163 : current_statement_begin__ = 12; 164 : if (!(context__.contains_r("kappa"))) 165 : stan::lang::rethrow_located(std::runtime_error(std::string("Variable kappa missing")), current_statement_begin__, prog_reader__()); 166 : vals_r__ = context__.vals_r("kappa"); 167 : pos__ = 0U; 168 : context__.validate_dims("parameter initialization", "kappa", "double", context__.to_vec()); 169 : double kappa(0); 170 : kappa = vals_r__[pos__++]; 171 : try { 172 : writer__.scalar_unconstrain(kappa); 173 : } catch (const std::exception& e) { 174 : stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable kappa: ") + e.what()), current_statement_begin__, prog_reader__()); 175 : } 176 : 177 : current_statement_begin__ = 13; 178 : if (!(context__.contains_r("mu"))) 179 : stan::lang::rethrow_located(std::runtime_error(std::string("Variable mu missing")), current_statement_begin__, prog_reader__()); 180 : vals_r__ = context__.vals_r("mu"); 181 : pos__ = 0U; 182 : context__.validate_dims("parameter initialization", "mu", "double", context__.to_vec()); 183 : double mu(0); 184 : mu = vals_r__[pos__++]; 185 : try { 186 : writer__.scalar_unconstrain(mu); 187 : } catch (const std::exception& e) { 188 : stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable mu: ") + e.what()), current_statement_begin__, prog_reader__()); 189 : } 190 : 191 : params_r__ = writer__.data_r(); 192 : params_i__ = writer__.data_i(); 193 : } 194 : 195 : void transform_inits(const stan::io::var_context& context, 196 : Eigen::Matrix& params_r, 197 : std::ostream* pstream__) const { 198 : std::vector params_r_vec; 199 : std::vector params_i_vec; 200 : transform_inits(context, params_i_vec, params_r_vec, pstream__); 201 : params_r.resize(params_r_vec.size()); 202 : for (int i = 0; i < params_r.size(); ++i) 203 : params_r(i) = params_r_vec[i]; 204 : } 205 : 206 : 207 : template 208 : T__ log_prob(std::vector& params_r__, 209 : std::vector& params_i__, 210 : std::ostream* pstream__ = 0) const { 211 : 212 : typedef T__ local_scalar_t__; 213 : 214 : local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); 215 : (void) DUMMY_VAR__; // dummy to suppress unused var warning 216 : 217 : T__ lp__(0.0); 218 : stan::math::accumulator lp_accum__; 219 : try { 220 : stan::io::reader in__(params_r__, params_i__); 221 : 222 : // model parameters 223 : current_statement_begin__ = 12; 224 : local_scalar_t__ kappa; 225 : (void) kappa; // dummy to suppress unused var warning 226 : if (jacobian__) 227 : kappa = in__.scalar_constrain(lp__); 228 : else 229 : kappa = in__.scalar_constrain(); 230 : 231 : current_statement_begin__ = 13; 232 : local_scalar_t__ mu; 233 : (void) mu; // dummy to suppress unused var warning 234 : if (jacobian__) 235 : mu = in__.scalar_constrain(lp__); 236 : else 237 : mu = in__.scalar_constrain(); 238 : 239 : // model body 240 : 241 : current_statement_begin__ = 16; 242 : for (int i = 1; i <= N; ++i) { 243 : current_statement_begin__ = 17; 244 : lp_accum__.add(custom_von_mises_lpdf(get_base1(y, i, "y", 1), (2 * stan::math::atan(mu)), stan::math::exp(multiply(stan::model::rvalue(X, stan::model::cons_list(stan::model::index_uni(i), stan::model::cons_list(stan::model::index_omni(), stan::model::nil_index_list())), "X"), kappa)), pstream__)); 245 : } 246 : 247 : } catch (const std::exception& e) { 248 : stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__()); 249 : // Next line prevents compiler griping about no return 250 : throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 251 : } 252 : 253 : lp_accum__.add(lp__); 254 : return lp_accum__.sum(); 255 : 256 : } // log_prob() 257 : 258 : template 259 : T_ log_prob(Eigen::Matrix& params_r, 260 : std::ostream* pstream = 0) const { 261 : std::vector vec_params_r; 262 : vec_params_r.reserve(params_r.size()); 263 : for (int i = 0; i < params_r.size(); ++i) 264 : vec_params_r.push_back(params_r(i)); 265 : std::vector vec_params_i; 266 : return log_prob(vec_params_r, vec_params_i, pstream); 267 : } 268 : 269 : 270 : void get_param_names(std::vector& names__) const { 271 : names__.resize(0); 272 : names__.push_back("kappa"); 273 : names__.push_back("mu"); 274 : } 275 : 276 : 277 : void get_dims(std::vector >& dimss__) const { 278 : dimss__.resize(0); 279 : std::vector dims__; 280 : dims__.resize(0); 281 : dimss__.push_back(dims__); 282 : dims__.resize(0); 283 : dimss__.push_back(dims__); 284 : } 285 : 286 : template 287 : void write_array(RNG& base_rng__, 288 : std::vector& params_r__, 289 : std::vector& params_i__, 290 : std::vector& vars__, 291 : bool include_tparams__ = true, 292 : bool include_gqs__ = true, 293 : std::ostream* pstream__ = 0) const { 294 : typedef double local_scalar_t__; 295 : 296 : vars__.resize(0); 297 : stan::io::reader in__(params_r__, params_i__); 298 : static const char* function__ = "model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b_namespace::write_array"; 299 : (void) function__; // dummy to suppress unused var warning 300 : 301 : // read-transform, write parameters 302 : double kappa = in__.scalar_constrain(); 303 : vars__.push_back(kappa); 304 : 305 : double mu = in__.scalar_constrain(); 306 : vars__.push_back(mu); 307 : 308 : double lp__ = 0.0; 309 : (void) lp__; // dummy to suppress unused var warning 310 : stan::math::accumulator lp_accum__; 311 : 312 : local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); 313 : (void) DUMMY_VAR__; // suppress unused var warning 314 : 315 : if (!include_tparams__ && !include_gqs__) return; 316 : 317 : try { 318 : if (!include_gqs__ && !include_tparams__) return; 319 : if (!include_gqs__) return; 320 : } catch (const std::exception& e) { 321 : stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__()); 322 : // Next line prevents compiler griping about no return 323 : throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 324 : } 325 : } 326 : 327 : template 328 : void write_array(RNG& base_rng, 329 : Eigen::Matrix& params_r, 330 : Eigen::Matrix& vars, 331 : bool include_tparams = true, 332 : bool include_gqs = true, 333 : std::ostream* pstream = 0) const { 334 : std::vector params_r_vec(params_r.size()); 335 : for (int i = 0; i < params_r.size(); ++i) 336 : params_r_vec[i] = params_r(i); 337 : std::vector vars_vec; 338 : std::vector params_i_vec; 339 : write_array(base_rng, params_r_vec, params_i_vec, vars_vec, include_tparams, include_gqs, pstream); 340 : vars.resize(vars_vec.size()); 341 : for (int i = 0; i < vars.size(); ++i) 342 : vars(i) = vars_vec[i]; 343 : } 344 : 345 : std::string model_name() const { 346 : return "model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b"; 347 : } 348 : 349 : 350 : void constrained_param_names(std::vector& param_names__, 351 : bool include_tparams__ = true, 352 : bool include_gqs__ = true) const { 353 : std::stringstream param_name_stream__; 354 : param_name_stream__.str(std::string()); 355 : param_name_stream__ << "kappa"; 356 : param_names__.push_back(param_name_stream__.str()); 357 : param_name_stream__.str(std::string()); 358 : param_name_stream__ << "mu"; 359 : param_names__.push_back(param_name_stream__.str()); 360 : 361 : if (!include_gqs__ && !include_tparams__) return; 362 : 363 : if (include_tparams__) { 364 : } 365 : 366 : if (!include_gqs__) return; 367 : } 368 : 369 : 370 : void unconstrained_param_names(std::vector& param_names__, 371 : bool include_tparams__ = true, 372 : bool include_gqs__ = true) const { 373 : std::stringstream param_name_stream__; 374 : param_name_stream__.str(std::string()); 375 : param_name_stream__ << "kappa"; 376 : param_names__.push_back(param_name_stream__.str()); 377 : param_name_stream__.str(std::string()); 378 : param_name_stream__ << "mu"; 379 : param_names__.push_back(param_name_stream__.str()); 380 : 381 : if (!include_gqs__ && !include_tparams__) return; 382 : 383 : if (include_tparams__) { 384 : } 385 : 386 : if (!include_gqs__) return; 387 : } 388 : 389 : }; // model 390 : 391 : } // namespace 392 : 393 : typedef model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b_namespace::model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b stan_model; 394 : 395 : #ifndef USING_R 396 : 397 : stan::model::model_base& new_model( 398 : stan::io::var_context& data_context, 399 : unsigned int seed, 400 : std::ostream* msg_stream) { 401 : stan_model* m = new stan_model(data_context, seed, msg_stream); 402 : return *m; 403 : } 404 : 405 : #endif 406 : 407 : 408 : 409 : #include 410 : 411 : struct stan_model_holder { 412 : stan_model_holder(rstan::io::rlist_ref_var_context rcontext, 413 : unsigned int random_seed) 414 : : rcontext_(rcontext), random_seed_(random_seed) 415 : { 416 : } 417 : 418 : //stan::math::ChainableStack ad_stack; 419 : rstan::io::rlist_ref_var_context rcontext_; 420 : unsigned int random_seed_; 421 : }; 422 : 423 : Rcpp::XPtr model_ptr(stan_model_holder* smh) { 424 : Rcpp::XPtr model_instance(new stan_model(smh->rcontext_, smh->random_seed_), true); 425 : return model_instance; 426 : } 427 : 428 : Rcpp::XPtr fit_ptr(stan_model_holder* smh) { 429 : return Rcpp::XPtr(new rstan::stan_fit(model_ptr(smh), smh->random_seed_), true); 430 : } 431 : 432 : std::string model_name(stan_model_holder* smh) { 433 : return model_ptr(smh).get()->model_name(); 434 : } 435 : 436 : RCPP_MODULE(stan_fit4model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b_mod){ 437 : Rcpp::class_("stan_fit4model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b") 438 : .constructor() 439 : .method("model_ptr", &model_ptr) 440 : .method("fit_ptr", &fit_ptr) 441 : .method("model_name", &model_name) 442 : ; 443 : } 444 : 445 : 446 : // declarations 447 : extern "C" { 448 : SEXP file380e0d1ba533e4( ) ; 449 : } 450 : 451 : // definition 452 : 453 : SEXP file380e0d1ba533e4( ){ 454 : return Rcpp::wrap("b785e1b459e1a1bedfb490735b98118b"); 455 : } 456 : 457 : make cmd is make -f '/usr/lib/R/etc/Makeconf' -f '/usr/share/R/share/make/shlib.mk' -f '/home/satya/.R/Makevars' CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB='file380e0d1ba533e4.so' OBJECTS='file380e0d1ba533e4.o' make would use g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include/" -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include/" -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include/unsupported" -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/BH/include" -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/src/" -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/" -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/include/" -I"/home/satya/R/x86_64-pc-linux-gnu-library/4.0/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/home/satya/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -fpic -O3 -march=native -mtune=native -fPIC -c file380e0d1ba533e4.cpp -o file380e0d1ba533e4.o if test "zfile380e0d1ba533e4.o" != "z"; then \ echo g++ -std=gnu++14 -shared -L"/usr/lib/R/lib" -Wl,-Bsymbolic-functions -Wl,-z,relro -o file380e0d1ba533e4.so file380e0d1ba533e4.o '/home/satya/R/x86_64-pc-linux-gnu-library/4.0/rstan/lib//libStanServices.a' -L'/home/satya/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/lib/' -lStanHeaders -L'/home/satya/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/lib/' -ltbb -L"/usr/lib/R/lib" -lR; \ g++ -std=gnu++14 -shared -L"/usr/lib/R/lib" -Wl,-Bsymbolic-functions -Wl,-z,relro -o file380e0d1ba533e4.so file380e0d1ba533e4.o '/home/satya/R/x86_64-pc-linux-gnu-library/4.0/rstan/lib//libStanServices.a' -L'/home/satya/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/lib/' -lStanHeaders -L'/home/satya/R/x86_64-pc-linux-gnu-library/4.0/RcppParallel/lib/' -ltbb -L"/usr/lib/R/lib" -lR; \ fi ERROR(s) during compilation: source code errors or compiler configuration errors! Program source: 1: 2: // includes from the plugin 3: // [[Rcpp::plugins(cpp14)]] 4: 5: 6: // user includes 7: #include 8: #include 9: #include 10: #include 11: #include 12: // Code generated by Stan version 2.21.0 13: 14: #include 15: 16: namespace model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b_namespace { 17: 18: using std::istream; 19: using std::string; 20: using std::stringstream; 21: using std::vector; 22: using stan::io::dump; 23: using stan::math::lgamma; 24: using stan::model::prob_grad; 25: using namespace stan::math; 26: 27: static int current_statement_begin__; 28: 29: stan::io::program_reader prog_reader__() { 30: stan::io::program_reader reader; 31: reader.add_event(0, 0, "start", "model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b"); 32: reader.add_event(20, 18, "end", "model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b"); 33: return reader; 34: } 35: 36: template 37: typename boost::math::tools::promote_args::type 38: custom_von_mises_lpdf(const T0__& y, 39: const T1__& mu, 40: const Eigen::Matrix& kappa, std::ostream* pstream__); 41: 42: 43: #include "/home/satya/wrk/motocyte/src/motility_analysis/examples/glm/rstan_vmf/custom_von_mises_lpdf.hpp" 44: class model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b 45: : public stan::model::model_base_crtp { 46: private: 47: int N; 48: int K; 49: matrix_d X; 50: vector_d y; 51: public: 52: model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b(rstan::io::rlist_ref_var_context& context__, 53: std::ostream* pstream__ = 0) 54: : model_base_crtp(0) { 55: ctor_body(context__, 0, pstream__); 56: } 57: 58: model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b(stan::io::var_context& context__, 59: unsigned int random_seed__, 60: std::ostream* pstream__ = 0) 61: : model_base_crtp(0) { 62: ctor_body(context__, random_seed__, pstream__); 63: } 64: 65: void ctor_body(stan::io::var_context& context__, 66: unsigned int random_seed__, 67: std::ostream* pstream__) { 68: typedef double local_scalar_t__; 69: 70: boost::ecuyer1988 base_rng__ = 71: stan::services::util::create_rng(random_seed__, 0); 72: (void) base_rng__; // suppress unused var warning 73: 74: current_statement_begin__ = -1; 75: 76: static const char* function__ = "model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b_namespace::model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b"; 77: (void) function__; // dummy to suppress unused var warning 78: size_t pos__; 79: (void) pos__; // dummy to suppress unused var warning 80: std::vector vals_i__; 81: std::vector vals_r__; 82: local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); 83: (void) DUMMY_VAR__; // suppress unused var warning 84: 85: try { 86: // initialize data block variables from context__ 87: current_statement_begin__ = 6; 88: context__.validate_dims("data initialization", "N", "int", context__.to_vec()); 89: N = int(0); 90: vals_i__ = context__.vals_i("N"); 91: pos__ = 0; 92: N = vals_i__[pos__++]; 93: check_greater_or_equal(function__, "N", N, 0); 94: 95: current_statement_begin__ = 7; 96: context__.validate_dims("data initialization", "K", "int", context__.to_vec()); 97: K = int(0); 98: vals_i__ = context__.vals_i("K"); 99: pos__ = 0; 100: K = vals_i__[pos__++]; 101: check_greater_or_equal(function__, "K", K, 0); 102: 103: current_statement_begin__ = 8; 104: validate_non_negative_index("X", "N", N); 105: validate_non_negative_index("X", "K", K); 106: context__.validate_dims("data initialization", "X", "matrix_d", context__.to_vec(N,K)); 107: X = Eigen::Matrix(N, K); 108: vals_r__ = context__.vals_r("X"); 109: pos__ = 0; 110: size_t X_j_2_max__ = K; 111: size_t X_j_1_max__ = N; 112: for (size_t j_2__ = 0; j_2__ < X_j_2_max__; ++j_2__) { 113: for (size_t j_1__ = 0; j_1__ < X_j_1_max__; ++j_1__) { 114: X(j_1__, j_2__) = vals_r__[pos__++]; 115: } 116: } 117: 118: current_statement_begin__ = 9; 119: validate_non_negative_index("y", "N", N); 120: context__.validate_dims("data initialization", "y", "vector_d", context__.to_vec(N)); 121: y = Eigen::Matrix(N); 122: vals_r__ = context__.vals_r("y"); 123: pos__ = 0; 124: size_t y_j_1_max__ = N; 125: for (size_t j_1__ = 0; j_1__ < y_j_1_max__; ++j_1__) { 126: y(j_1__) = vals_r__[pos__++]; 127: } 128: 129: 130: // initialize transformed data variables 131: // execute transformed data statements 132: 133: // validate transformed data 134: 135: // validate, set parameter ranges 136: num_params_r__ = 0U; 137: param_ranges_i__.clear(); 138: current_statement_begin__ = 12; 139: num_params_r__ += 1; 140: current_statement_begin__ = 13; 141: num_params_r__ += 1; 142: } catch (const std::exception& e) { 143: stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__()); 144: // Next line prevents compiler griping about no return 145: throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 146: } 147: } 148: 149: ~model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b() { } 150: 151: 152: void transform_inits(const stan::io::var_context& context__, 153: std::vector& params_i__, 154: std::vector& params_r__, 155: std::ostream* pstream__) const { 156: typedef double local_scalar_t__; 157: stan::io::writer writer__(params_r__, params_i__); 158: size_t pos__; 159: (void) pos__; // dummy call to supress warning 160: std::vector vals_r__; 161: std::vector vals_i__; 162: 163: current_statement_begin__ = 12; 164: if (!(context__.contains_r("kappa"))) 165: stan::lang::rethrow_located(std::runtime_error(std::string("Variable kappa missing")), current_statement_begin__, prog_reader__()); 166: vals_r__ = context__.vals_r("kappa"); 167: pos__ = 0U; 168: context__.validate_dims("parameter initialization", "kappa", "double", context__.to_vec()); 169: double kappa(0); 170: kappa = vals_r__[pos__++]; 171: try { 172: writer__.scalar_unconstrain(kappa); 173: } catch (const std::exception& e) { 174: stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable kappa: ") + e.what()), current_statement_begin__, prog_reader__()); 175: } 176: 177: current_statement_begin__ = 13; 178: if (!(context__.contains_r("mu"))) 179: stan::lang::rethrow_located(std::runtime_error(std::string("Variable mu missing")), current_statement_begin__, prog_reader__()); 180: vals_r__ = context__.vals_r("mu"); 181: pos__ = 0U; 182: context__.validate_dims("parameter initialization", "mu", "double", context__.to_vec()); 183: double mu(0); 184: mu = vals_r__[pos__++]; 185: try { 186: writer__.scalar_unconstrain(mu); 187: } catch (const std::exception& e) { 188: stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable mu: ") + e.what()), current_statement_begin__, prog_reader__()); 189: } 190: 191: params_r__ = writer__.data_r(); 192: params_i__ = writer__.data_i(); 193: } 194: 195: void transform_inits(const stan::io::var_context& context, 196: Eigen::Matrix& params_r, 197: std::ostream* pstream__) const { 198: std::vector params_r_vec; 199: std::vector params_i_vec; 200: transform_inits(context, params_i_vec, params_r_vec, pstream__); 201: params_r.resize(params_r_vec.size()); 202: for (int i = 0; i < params_r.size(); ++i) 203: params_r(i) = params_r_vec[i]; 204: } 205: 206: 207: template 208: T__ log_prob(std::vector& params_r__, 209: std::vector& params_i__, 210: std::ostream* pstream__ = 0) const { 211: 212: typedef T__ local_scalar_t__; 213: 214: local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); 215: (void) DUMMY_VAR__; // dummy to suppress unused var warning 216: 217: T__ lp__(0.0); 218: stan::math::accumulator lp_accum__; 219: try { 220: stan::io::reader in__(params_r__, params_i__); 221: 222: // model parameters 223: current_statement_begin__ = 12; 224: local_scalar_t__ kappa; 225: (void) kappa; // dummy to suppress unused var warning 226: if (jacobian__) 227: kappa = in__.scalar_constrain(lp__); 228: else 229: kappa = in__.scalar_constrain(); 230: 231: current_statement_begin__ = 13; 232: local_scalar_t__ mu; 233: (void) mu; // dummy to suppress unused var warning 234: if (jacobian__) 235: mu = in__.scalar_constrain(lp__); 236: else 237: mu = in__.scalar_constrain(); 238: 239: // model body 240: 241: current_statement_begin__ = 16; 242: for (int i = 1; i <= N; ++i) { 243: current_statement_begin__ = 17; 244: lp_accum__.add(custom_von_mises_lpdf(get_base1(y, i, "y", 1), (2 * stan::math::atan(mu)), stan::math::exp(multiply(stan::model::rvalue(X, stan::model::cons_list(stan::model::index_uni(i), stan::model::cons_list(stan::model::index_omni(), stan::model::nil_index_list())), "X"), kappa)), pstream__)); 245: } 246: 247: } catch (const std::exception& e) { 248: stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__()); 249: // Next line prevents compiler griping about no return 250: throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 251: } 252: 253: lp_accum__.add(lp__); 254: return lp_accum__.sum(); 255: 256: } // log_prob() 257: 258: template 259: T_ log_prob(Eigen::Matrix& params_r, 260: std::ostream* pstream = 0) const { 261: std::vector vec_params_r; 262: vec_params_r.reserve(params_r.size()); 263: for (int i = 0; i < params_r.size(); ++i) 264: vec_params_r.push_back(params_r(i)); 265: std::vector vec_params_i; 266: return log_prob(vec_params_r, vec_params_i, pstream); 267: } 268: 269: 270: void get_param_names(std::vector& names__) const { 271: names__.resize(0); 272: names__.push_back("kappa"); 273: names__.push_back("mu"); 274: } 275: 276: 277: void get_dims(std::vector >& dimss__) const { 278: dimss__.resize(0); 279: std::vector dims__; 280: dims__.resize(0); 281: dimss__.push_back(dims__); 282: dims__.resize(0); 283: dimss__.push_back(dims__); 284: } 285: 286: template 287: void write_array(RNG& base_rng__, 288: std::vector& params_r__, 289: std::vector& params_i__, 290: std::vector& vars__, 291: bool include_tparams__ = true, 292: bool include_gqs__ = true, 293: std::ostream* pstream__ = 0) const { 294: typedef double local_scalar_t__; 295: 296: vars__.resize(0); 297: stan::io::reader in__(params_r__, params_i__); 298: static const char* function__ = "model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b_namespace::write_array"; 299: (void) function__; // dummy to suppress unused var warning 300: 301: // read-transform, write parameters 302: double kappa = in__.scalar_constrain(); 303: vars__.push_back(kappa); 304: 305: double mu = in__.scalar_constrain(); 306: vars__.push_back(mu); 307: 308: double lp__ = 0.0; 309: (void) lp__; // dummy to suppress unused var warning 310: stan::math::accumulator lp_accum__; 311: 312: local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); 313: (void) DUMMY_VAR__; // suppress unused var warning 314: 315: if (!include_tparams__ && !include_gqs__) return; 316: 317: try { 318: if (!include_gqs__ && !include_tparams__) return; 319: if (!include_gqs__) return; 320: } catch (const std::exception& e) { 321: stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__()); 322: // Next line prevents compiler griping about no return 323: throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); 324: } 325: } 326: 327: template 328: void write_array(RNG& base_rng, 329: Eigen::Matrix& params_r, 330: Eigen::Matrix& vars, 331: bool include_tparams = true, 332: bool include_gqs = true, 333: std::ostream* pstream = 0) const { 334: std::vector params_r_vec(params_r.size()); 335: for (int i = 0; i < params_r.size(); ++i) 336: params_r_vec[i] = params_r(i); 337: std::vector vars_vec; 338: std::vector params_i_vec; 339: write_array(base_rng, params_r_vec, params_i_vec, vars_vec, include_tparams, include_gqs, pstream); 340: vars.resize(vars_vec.size()); 341: for (int i = 0; i < vars.size(); ++i) 342: vars(i) = vars_vec[i]; 343: } 344: 345: std::string model_name() const { 346: return "model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b"; 347: } 348: 349: 350: void constrained_param_names(std::vector& param_names__, 351: bool include_tparams__ = true, 352: bool include_gqs__ = true) const { 353: std::stringstream param_name_stream__; 354: param_name_stream__.str(std::string()); 355: param_name_stream__ << "kappa"; 356: param_names__.push_back(param_name_stream__.str()); 357: param_name_stream__.str(std::string()); 358: param_name_stream__ << "mu"; 359: param_names__.push_back(param_name_stream__.str()); 360: 361: if (!include_gqs__ && !include_tparams__) return; 362: 363: if (include_tparams__) { 364: } 365: 366: if (!include_gqs__) return; 367: } 368: 369: 370: void unconstrained_param_names(std::vector& param_names__, 371: bool include_tparams__ = true, 372: bool include_gqs__ = true) const { 373: std::stringstream param_name_stream__; 374: param_name_stream__.str(std::string()); 375: param_name_stream__ << "kappa"; 376: param_names__.push_back(param_name_stream__.str()); 377: param_name_stream__.str(std::string()); 378: param_name_stream__ << "mu"; 379: param_names__.push_back(param_name_stream__.str()); 380: 381: if (!include_gqs__ && !include_tparams__) return; 382: 383: if (include_tparams__) { 384: } 385: 386: if (!include_gqs__) return; 387: } 388: 389: }; // model 390: 391: } // namespace 392: 393: typedef model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b_namespace::model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b stan_model; 394: 395: #ifndef USING_R 396: 397: stan::model::model_base& new_model( 398: stan::io::var_context& data_context, 399: unsigned int seed, 400: std::ostream* msg_stream) { 401: stan_model* m = new stan_model(data_context, seed, msg_stream); 402: return *m; 403: } 404: 405: #endif 406: 407: 408: 409: #include 410: 411: struct stan_model_holder { 412: stan_model_holder(rstan::io::rlist_ref_var_context rcontext, 413: unsigned int random_seed) 414: : rcontext_(rcontext), random_seed_(random_seed) 415: { 416: } 417: 418: //stan::math::ChainableStack ad_stack; 419: rstan::io::rlist_ref_var_context rcontext_; 420: unsigned int random_seed_; 421: }; 422: 423: Rcpp::XPtr model_ptr(stan_model_holder* smh) { 424: Rcpp::XPtr model_instance(new stan_model(smh->rcontext_, smh->random_seed_), true); 425: return model_instance; 426: } 427: 428: Rcpp::XPtr fit_ptr(stan_model_holder* smh) { 429: return Rcpp::XPtr(new rstan::stan_fit(model_ptr(smh), smh->random_seed_), true); 430: } 431: 432: std::string model_name(stan_model_holder* smh) { 433: return model_ptr(smh).get()->model_name(); 434: } 435: 436: RCPP_MODULE(stan_fit4model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b_mod){ 437: Rcpp::class_("stan_fit4model380e0d78ed73db_b785e1b459e1a1bedfb490735b98118b") 438: .constructor() 439: .method("model_ptr", &model_ptr) 440: .method("fit_ptr", &fit_ptr) 441: .method("model_name", &model_name) 442: ; 443: } 444: 445: 446: // declarations 447: extern "C" { 448: SEXP file380e0d1ba533e4( ) ; 449: } 450: 451: // definition 452: 453: SEXP file380e0d1ba533e4( ){ 454: return Rcpp::wrap("b785e1b459e1a1bedfb490735b98118b"); 455: } 456: 457: Compilation ERROR, function(s)/method(s) not created! Error in compileCode(f, code, language = language, verbose = verbose) : /home/satya/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/stan/math/rev/mat/functor/adj_jac_apply.hpp:535:10: required from ‘void stan::math::adj_jac_vari::chain() [with F = stan::math::internal::softmax_op; Targs = {Eigen::Matrix}]’/home/satya/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/stan/math/rev/mat/functor/adj_jac_apply.hpp:531:8: required from here/home/satya/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:650:34: warning: ignoring attributes on template argument ‘Eigen::internal::packet_traits::type’ {aka ‘__vector(4) double’} [-Wignored-attributes] 650 | return internal::first_aligned::alignment),Derived>(m); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~make: *** [/usr/lib/R/etc/Makeconf:176: file380e0d1ba533e4.o] Error 1 Calls: stan_model ... cxxfunctionplus -> -> cxxfunction -> compileCode Execution halted