From 31ec64e585f50f4bb0a24400b0b2c010250907e4 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 9 Feb 2023 07:53:01 +0200 Subject: [PATCH 1/6] Fully delegate to rstantools --- R/stanmodels.R | 28 - configure | 5 +- configure.win | 7 +- src/Makevars | 9 - src/Makevars.win | 9 - src/stanExports_rw1_model.cc | 32 - src/stanExports_rw1_model.h | 1458 -------------- src/stanExports_rw1_model_naive.cc | 32 - src/stanExports_rw1_model_naive.h | 892 --------- src/stanExports_walker_glm.cc | 32 - src/stanExports_walker_glm.h | 2851 ---------------------------- src/stanExports_walker_lm.cc | 32 - src/stanExports_walker_lm.h | 2314 ---------------------- 13 files changed, 4 insertions(+), 7697 deletions(-) delete mode 100644 R/stanmodels.R mode change 100644 => 100755 configure.win delete mode 100644 src/Makevars delete mode 100644 src/Makevars.win delete mode 100644 src/stanExports_rw1_model.cc delete mode 100644 src/stanExports_rw1_model.h delete mode 100644 src/stanExports_rw1_model_naive.cc delete mode 100644 src/stanExports_rw1_model_naive.h delete mode 100644 src/stanExports_walker_glm.cc delete mode 100644 src/stanExports_walker_glm.h delete mode 100644 src/stanExports_walker_lm.cc delete mode 100644 src/stanExports_walker_lm.h diff --git a/R/stanmodels.R b/R/stanmodels.R deleted file mode 100644 index 8562839..0000000 --- a/R/stanmodels.R +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by rstantools. Do not edit by hand. - -# names of stan models -stanmodels <- c("rw1_model", "rw1_model_naive", "walker_glm", "walker_lm") - -# load each stan module -Rcpp::loadModule("stan_fit4rw1_model_mod", what = TRUE) -Rcpp::loadModule("stan_fit4rw1_model_naive_mod", what = TRUE) -Rcpp::loadModule("stan_fit4walker_glm_mod", what = TRUE) -Rcpp::loadModule("stan_fit4walker_lm_mod", what = TRUE) - -# instantiate each stanmodel object -stanmodels <- sapply(stanmodels, function(model_name) { - # create C++ code for stan model - stan_file <- if(dir.exists("stan")) "stan" else file.path("inst", "stan") - stan_file <- file.path(stan_file, paste0(model_name, ".stan")) - stanfit <- rstan::stanc_builder(stan_file, - allow_undefined = TRUE, - obfuscate_model_name = FALSE) - stanfit$model_cpp <- list(model_cppname = stanfit$model_name, - model_cppcode = stanfit$cppcode) - # create stanmodel object - methods::new(Class = "stanmodel", - model_name = stanfit$model_name, - model_code = stanfit$model_code, - model_cpp = stanfit$model_cpp, - mk_cppmodule = function(x) get(paste0("rstantools_model_", model_name))) -}) diff --git a/configure b/configure index 5c54af0..1c04798 100755 --- a/configure +++ b/configure @@ -1,5 +1,4 @@ +# Generated by rstantools. Do not edit by hand. + #! /bin/sh "${R_HOME}/bin/Rscript" -e "rstantools::rstan_config()" -# the flags below are now added manually as Makevars is also configured manually until rstantools updates -#"${R_HOME}/bin/Rscript" -e 'cat("PKG_LIBS += $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)", sep = "\n", file = "src/Makevars", append = TRUE)' -#"${R_HOME}/bin/Rscript" -e 'cat("PKG_LIBS += $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)", sep = "\n", file = "src/Makevars.win", append = TRUE)' diff --git a/configure.win b/configure.win old mode 100644 new mode 100755 index 91079f8..94d77bd --- a/configure.win +++ b/configure.win @@ -1,7 +1,4 @@ +# Generated by rstantools. Do not edit by hand. + #! /bin/sh "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "rstantools::rstan_config()" -# the flags below are now added manually as Makevars is also configured manually until rstantools updates -#"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e 'cat("PKG_LIBS += $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)", sep = "\n", file = "src/Makevars.win", append = TRUE)' -# This needs some trickery in order to ensure LF line endings without need to fight with git (actions) -#"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e 'f<-"src/Makevars";l<-c(readLines(f),"PKG_LIBS += $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)");f<-file(f, "wb");cat(l,sep = "\n",file=f);close(f)' - diff --git a/src/Makevars b/src/Makevars deleted file mode 100644 index d38bb47..0000000 --- a/src/Makevars +++ /dev/null @@ -1,9 +0,0 @@ -STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "message()" -e "cat(system.file('include', 'src', package = 'StanHeaders', mustWork = TRUE))" -e "message()" | grep "StanHeaders") - -STANC_FLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "cat(ifelse(utils::packageVersion('rstan') >= 2.26, '-DUSE_STANC3',''))") -PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error $(STANC_FLAGS) -PKG_CXXFLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::CxxFlags()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::CxxFlags()") -PKG_LIBS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::RcppParallelLibs()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::LdFlags()") - -CXX_STD = CXX14 -PKG_LIBS += $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) diff --git a/src/Makevars.win b/src/Makevars.win deleted file mode 100644 index cdcca38..0000000 --- a/src/Makevars.win +++ /dev/null @@ -1,9 +0,0 @@ -STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "message()" -e "cat(system.file('include', 'src', package = 'StanHeaders', mustWork = TRUE))" -e "message()" | grep "StanHeaders") - -STANC_FLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "cat(ifelse(utils::packageVersion('rstan') >= 2.26, '-DUSE_STANC3',''))") -PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DRCPP_PARALLEL_USE_TBB=1 $(STANC_FLAGS) -PKG_CXXFLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::CxxFlags()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::CxxFlags()") -PKG_LIBS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::RcppParallelLibs()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::LdFlags()") - -CXX_STD = CXX14 -PKG_LIBS += $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) diff --git a/src/stanExports_rw1_model.cc b/src/stanExports_rw1_model.cc deleted file mode 100644 index 4edd7f4..0000000 --- a/src/stanExports_rw1_model.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Generated by rstantools. Do not edit by hand. - -#include -using namespace Rcpp ; -#include "stanExports_rw1_model.h" - -RCPP_MODULE(stan_fit4rw1_model_mod) { - - - class_ >("rstantools_model_rw1_model") - - .constructor() - - - .method("call_sampler", &rstan::stan_fit ::call_sampler) - .method("param_names", &rstan::stan_fit ::param_names) - .method("param_names_oi", &rstan::stan_fit ::param_names_oi) - .method("param_fnames_oi", &rstan::stan_fit ::param_fnames_oi) - .method("param_dims", &rstan::stan_fit ::param_dims) - .method("param_dims_oi", &rstan::stan_fit ::param_dims_oi) - .method("update_param_oi", &rstan::stan_fit ::update_param_oi) - .method("param_oi_tidx", &rstan::stan_fit ::param_oi_tidx) - .method("grad_log_prob", &rstan::stan_fit ::grad_log_prob) - .method("log_prob", &rstan::stan_fit ::log_prob) - .method("unconstrain_pars", &rstan::stan_fit ::unconstrain_pars) - .method("constrain_pars", &rstan::stan_fit ::constrain_pars) - .method("num_pars_unconstrained", &rstan::stan_fit ::num_pars_unconstrained) - .method("unconstrained_param_names", &rstan::stan_fit ::unconstrained_param_names) - .method("constrained_param_names", &rstan::stan_fit ::constrained_param_names) - .method("standalone_gqs", &rstan::stan_fit ::standalone_gqs) - ; -} diff --git a/src/stanExports_rw1_model.h b/src/stanExports_rw1_model.h deleted file mode 100644 index 676048b..0000000 --- a/src/stanExports_rw1_model.h +++ /dev/null @@ -1,1458 +0,0 @@ -// Generated by rstantools. Do not edit by hand. - -/* - walker is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - licence is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with licence. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.26.1-1-g67504470 -#include -namespace model_rw1_model_namespace { -inline void validate_positive_index(const char* var_name, const char* expr, - int val) { - if (val < 1) { - std::stringstream msg; - msg << "Found dimension size less than one in simplex declaration" - << "; variable=" << var_name << "; dimension size expression=" << expr - << "; expression value=" << val; - std::string msg_str(msg.str()); - throw std::invalid_argument(msg_str.c_str()); - } -} -inline void validate_unit_vector_index(const char* var_name, const char* expr, - int val) { - if (val <= 1) { - std::stringstream msg; - if (val == 1) { - msg << "Found dimension size one in unit vector declaration." - << " One-dimensional unit vector is discrete" - << " but the target distribution must be continuous." - << " variable=" << var_name << "; dimension size expression=" << expr; - } else { - msg << "Found dimension size less than one in unit vector declaration" - << "; variable=" << var_name << "; dimension size expression=" << expr - << "; expression value=" << val; - } - std::string msg_str(msg.str()); - throw std::invalid_argument(msg_str.c_str()); - } -} -using std::istream; -using std::string; -using std::stringstream; -using std::vector; -using std::pow; -using stan::io::dump; -using stan::math::lgamma; -using stan::model::model_base_crtp; -using stan::model::rvalue; -using stan::model::cons_list; -using stan::model::index_uni; -using stan::model::index_max; -using stan::model::index_min; -using stan::model::index_min_max; -using stan::model::index_multi; -using stan::model::index_omni; -using stan::model::nil_index_list; -using namespace stan::math; -using stan::math::pow; -stan::math::profile_map profiles__; -static int current_statement__= 0; -static const std::vector locations_array__ = {" (found before start of program)", - " (in 'string', line 74, column 2 to column 27)", - " (in 'string', line 75, column 2 to column 24)", - " (in 'string', line 78, column 2 to column 21)", - " (in 'string', line 79, column 2 to column 22)", - " (in 'string', line 81, column 4 to column 31)", - " (in 'string', line 82, column 4 to column 32)", - " (in 'string', line 80, column 16 to line 83, column 3)", - " (in 'string', line 80, column 2 to line 83, column 3)", - " (in 'string', line 92, column 2 to column 18)", - " (in 'string', line 93, column 2 to column 20)", - " (in 'string', line 94, column 2 to column 22)", - " (in 'string', line 95, column 2 to column 28)", - " (in 'string', line 99, column 5 to column 55)", - " (in 'string', line 98, column 16 to line 100, column 3)", - " (in 'string', line 98, column 2 to line 100, column 3)", - " (in 'string', line 103, column 6 to column 56)", - " (in 'string', line 102, column 18 to line 104, column 5)", - " (in 'string', line 102, column 4 to line 104, column 5)", - " (in 'string', line 101, column 23 to line 105, column 3)", - " (in 'string', line 101, column 2 to line 105, column 3)", - " (in 'string', line 108, column 4 to column 73)", - " (in 'string', line 107, column 16 to line 109, column 3)", - " (in 'string', line 107, column 2 to line 109, column 3)", - " (in 'string', line 111, column 2 to column 104)", - " (in 'string', line 115, column 4 to column 77)", - " (in 'string', line 114, column 16 to line 116, column 3)", - " (in 'string', line 114, column 2 to line 116, column 3)", - " (in 'string', line 121, column 6 to column 58)", - " (in 'string', line 120, column 18 to line 122, column 5)", - " (in 'string', line 120, column 4 to line 122, column 5)", - " (in 'string', line 124, column 6 to column 84)", - " (in 'string', line 126, column 8 to column 66)", - " (in 'string', line 125, column 20 to line 127, column 7)", - " (in 'string', line 125, column 6 to line 127, column 7)", - " (in 'string', line 123, column 28 to line 128, column 5)", - " (in 'string', line 123, column 4 to line 128, column 5)", - " (in 'string', line 129, column 4 to column 94)", - " (in 'string', line 119, column 17 to line 130, column 3)", - " (in 'string', line 119, column 2 to line 130, column 3)", - " (in 'string', line 86, column 2 to column 45)", - " (in 'string', line 87, column 2 to column 45)", - " (in 'string', line 88, column 2 to column 87)", - " (in 'string', line 56, column 2 to column 17)", - " (in 'string', line 57, column 2 to column 17)", - " (in 'string', line 58, column 9 to column 10)", - " (in 'string', line 58, column 12 to column 13)", - " (in 'string', line 58, column 2 to column 20)", - " (in 'string', line 59, column 9 to column 10)", - " (in 'string', line 59, column 2 to column 14)", - " (in 'string', line 60, column 9 to column 10)", - " (in 'string', line 60, column 2 to column 22)", - " (in 'string', line 61, column 9 to column 10)", - " (in 'string', line 61, column 2 to column 20)", - " (in 'string', line 62, column 9 to column 14)", - " (in 'string', line 62, column 2 to column 27)", - " (in 'string', line 63, column 9 to column 14)", - " (in 'string', line 63, column 2 to column 25)", - " (in 'string', line 64, column 2 to column 21)", - " (in 'string', line 65, column 9 to column 10)", - " (in 'string', line 65, column 12 to column 17)", - " (in 'string', line 65, column 2 to column 28)", - " (in 'string', line 68, column 9 to column 10)", - " (in 'string', line 68, column 2 to column 42)", - " (in 'string', line 69, column 9 to column 10)", - " (in 'string', line 69, column 2 to column 38)", - " (in 'string', line 70, column 2 to column 36)", - " (in 'string', line 71, column 2 to column 32)", - " (in 'string', line 74, column 24 to column 25)", - " (in 'string', line 78, column 9 to column 10)", - " (in 'string', line 79, column 9 to column 10)", - " (in 'string', line 92, column 9 to column 10)", - " (in 'string', line 93, column 9 to column 10)", - " (in 'string', line 93, column 12 to column 13)", - " (in 'string', line 94, column 9 to column 14)", - " (in 'string', line 95, column 9 to column 10)", - " (in 'string', line 95, column 12 to column 17)", - " (in 'string', line 6, column 2 to column 18)", - " (in 'string', line 7, column 2 to column 19)", - " (in 'string', line 8, column 2 to column 20)", - " (in 'string', line 9, column 9 to column 10)", - " (in 'string', line 9, column 2 to column 19)", - " (in 'string', line 10, column 9 to column 10)", - " (in 'string', line 10, column 12 to column 13)", - " (in 'string', line 10, column 2 to column 35)", - " (in 'string', line 12, column 4 to column 42)", - " (in 'string', line 13, column 4 to column 46)", - " (in 'string', line 14, column 11 to column 12)", - " (in 'string', line 14, column 4 to column 36)", - " (in 'string', line 15, column 4 to column 15)", - " (in 'string', line 16, column 4 to column 27)", - " (in 'string', line 17, column 4 to column 41)", - " (in 'string', line 11, column 17 to line 18, column 3)", - " (in 'string', line 11, column 2 to line 18, column 3)", - " (in 'string', line 19, column 3 to column 17)", - " (in 'string', line 5, column 94 to line 20, column 3)", - " (in 'string', line 23, column 2 to column 18)", - " (in 'string', line 24, column 2 to column 19)", - " (in 'string', line 25, column 9 to column 10)", - " (in 'string', line 25, column 2 to column 19)", - " (in 'string', line 26, column 9 to column 10)", - " (in 'string', line 26, column 12 to column 13)", - " (in 'string', line 26, column 2 to column 35)", - " (in 'string', line 27, column 9 to column 10)", - " (in 'string', line 27, column 2 to column 14)", - " (in 'string', line 28, column 9 to column 10)", - " (in 'string', line 28, column 2 to column 14)", - " (in 'string', line 29, column 9 to column 10)", - " (in 'string', line 29, column 12 to column 13)", - " (in 'string', line 29, column 2 to column 17)", - " (in 'string', line 30, column 9 to column 10)", - " (in 'string', line 30, column 12 to column 15)", - " (in 'string', line 30, column 2 to column 19)", - " (in 'string', line 31, column 9 to column 10)", - " (in 'string', line 31, column 2 to column 17)", - " (in 'string', line 33, column 4 to column 40)", - " (in 'string', line 34, column 4 to column 44)", - " (in 'string', line 35, column 4 to column 34)", - " (in 'string', line 36, column 4 to column 23)", - " (in 'string', line 37, column 4 to column 40)", - " (in 'string', line 32, column 17 to line 38, column 3)", - " (in 'string', line 32, column 2 to line 38, column 3)", - " (in 'string', line 39, column 2 to column 31)", - " (in 'string', line 41, column 4 to column 23)", - " (in 'string', line 42, column 11 to column 12)", - " (in 'string', line 42, column 4 to column 28)", - " (in 'string', line 43, column 4 to column 81)", - " (in 'string', line 40, column 18 to line 44, column 3)", - " (in 'string', line 40, column 2 to line 44, column 3)", - " (in 'string', line 45, column 2 to column 15)", - " (in 'string', line 46, column 2 to column 26)", - " (in 'string', line 48, column 11 to column 12)", - " (in 'string', line 48, column 4 to column 28)", - " (in 'string', line 49, column 11 to column 12)", - " (in 'string', line 49, column 4 to column 27)", - " (in 'string', line 50, column 4 to column 28)", - " (in 'string', line 47, column 17 to line 51, column 3)", - " (in 'string', line 47, column 2 to line 51, column 3)", - " (in 'string', line 52, column 2 to column 21)", - " (in 'string', line 22, column 93 to line 53, column 3)"}; -template -stan::promote_args_t, stan::value_type_t, -stan::value_type_t, T3__, -stan::value_type_t, stan::promote_args_t>> -gaussian_filter_rw_lpdf(const T0__& y_arg__, const T1__& a1_arg__, - const T2__& P1_arg__, const T3__& Ht, - const T4__& Rt_arg__, const T5__& xreg_arg__, - std::ostream* pstream__) { - using local_scalar_t__ = stan::promote_args_t, - stan::value_type_t, - stan::value_type_t, - T3__, - stan::value_type_t, stan::promote_args_t>>; - const auto& y = to_ref(y_arg__); - const auto& a1 = to_ref(a1_arg__); - const auto& P1 = to_ref(P1_arg__); - const auto& Rt = to_ref(Rt_arg__); - const auto& xreg = to_ref(xreg_arg__); - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - int n; - n = std::numeric_limits::min(); - - current_statement__ = 77; - n = rows(y); - int m; - m = std::numeric_limits::min(); - - current_statement__ = 78; - m = rows(a1); - local_scalar_t__ loglik; - loglik = DUMMY_VAR__; - - current_statement__ = 79; - loglik = 0.0; - current_statement__ = 80; - validate_non_negative_index("x", "m", m); - Eigen::Matrix x; - x = Eigen::Matrix(m); - stan::math::fill(x, DUMMY_VAR__); - - current_statement__ = 81; - assign(x, nil_index_list(), a1, "assigning variable x"); - current_statement__ = 82; - validate_non_negative_index("P", "m", m); - current_statement__ = 83; - validate_non_negative_index("P", "m", m); - Eigen::Matrix P; - P = Eigen::Matrix(m, m); - stan::math::fill(P, DUMMY_VAR__); - - current_statement__ = 84; - assign(P, nil_index_list(), diag_matrix(P1), "assigning variable P"); - current_statement__ = 93; - for (int t = 1; t <= n; ++t) { - local_scalar_t__ F; - F = DUMMY_VAR__; - - current_statement__ = 85; - F = (quad_form(P, - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg")) + Ht); - local_scalar_t__ v; - v = DUMMY_VAR__; - - current_statement__ = 86; - v = (y[(t - 1)] - - dot_product( - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg"), x)); - current_statement__ = 87; - validate_non_negative_index("K", "m", m); - Eigen::Matrix K; - K = Eigen::Matrix(m); - stan::math::fill(K, DUMMY_VAR__); - - current_statement__ = 88; - assign(K, nil_index_list(), - divide( - multiply(P, - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg")), F), - "assigning variable K"); - current_statement__ = 89; - assign(x, nil_index_list(), - add(stan::model::deep_copy(x), multiply(K, v)), - "assigning variable x"); - current_statement__ = 90; - assign(P, nil_index_list(), - add(stan::model::deep_copy(P), - add(multiply(multiply(minus(K), transpose(K)), F), Rt)), - "assigning variable P"); - current_statement__ = 91; - loglik = (loglik - (0.5 * (stan::math::log(F) + ((v * v) / F))));} - current_statement__ = 94; - return loglik; - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - -} -struct gaussian_filter_rw_lpdf_functor__ { -template -stan::promote_args_t, stan::value_type_t, -stan::value_type_t, T3__, -stan::value_type_t, stan::promote_args_t>> -operator()(const T0__& y, const T1__& a1, const T2__& P1, const T3__& Ht, - const T4__& Rt, const T5__& xreg, std::ostream* pstream__) const -{ -return gaussian_filter_rw_lpdf(y, a1, P1, Ht, Rt, xreg, pstream__); -} -}; -template -Eigen::Matrix, stan::value_type_t, -stan::value_type_t, T3__, -stan::value_type_t, stan::promote_args_t>>, -1, -1> -gaussian_smoother_rw(const T0__& y_arg__, const T1__& a1_arg__, - const T2__& P1_arg__, const T3__& Ht, - const T4__& Rt_arg__, const T5__& xreg_arg__, - std::ostream* pstream__) { - using local_scalar_t__ = stan::promote_args_t, - stan::value_type_t, - stan::value_type_t, - T3__, - stan::value_type_t, stan::promote_args_t>>; - const auto& y = to_ref(y_arg__); - const auto& a1 = to_ref(a1_arg__); - const auto& P1 = to_ref(P1_arg__); - const auto& Rt = to_ref(Rt_arg__); - const auto& xreg = to_ref(xreg_arg__); - const static bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - int n; - n = std::numeric_limits::min(); - - current_statement__ = 96; - n = rows(y); - int m; - m = std::numeric_limits::min(); - - current_statement__ = 97; - m = rows(a1); - current_statement__ = 98; - validate_non_negative_index("x", "m", m); - Eigen::Matrix x; - x = Eigen::Matrix(m); - stan::math::fill(x, DUMMY_VAR__); - - current_statement__ = 99; - assign(x, nil_index_list(), a1, "assigning variable x"); - current_statement__ = 100; - validate_non_negative_index("P", "m", m); - current_statement__ = 101; - validate_non_negative_index("P", "m", m); - Eigen::Matrix P; - P = Eigen::Matrix(m, m); - stan::math::fill(P, DUMMY_VAR__); - - current_statement__ = 102; - assign(P, nil_index_list(), diag_matrix(P1), "assigning variable P"); - current_statement__ = 103; - validate_non_negative_index("v", "n", n); - Eigen::Matrix v; - v = Eigen::Matrix(n); - stan::math::fill(v, DUMMY_VAR__); - - current_statement__ = 105; - validate_non_negative_index("F", "n", n); - Eigen::Matrix F; - F = Eigen::Matrix(n); - stan::math::fill(F, DUMMY_VAR__); - - current_statement__ = 107; - validate_non_negative_index("K", "m", m); - current_statement__ = 108; - validate_non_negative_index("K", "n", n); - Eigen::Matrix K; - K = Eigen::Matrix(m, n); - stan::math::fill(K, DUMMY_VAR__); - - current_statement__ = 110; - validate_non_negative_index("r", "m", m); - current_statement__ = 111; - validate_non_negative_index("r", "n + 1", (n + 1)); - Eigen::Matrix r; - r = Eigen::Matrix(m, (n + 1)); - stan::math::fill(r, DUMMY_VAR__); - - current_statement__ = 113; - validate_non_negative_index("tmpr", "m", m); - Eigen::Matrix tmpr; - tmpr = Eigen::Matrix(m); - stan::math::fill(tmpr, DUMMY_VAR__); - - current_statement__ = 121; - for (int t = 1; t <= n; ++t) { - current_statement__ = 115; - assign(F, cons_list(index_uni(t), nil_index_list()), - (quad_form(P, - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg")) + Ht), - "assigning variable F"); - current_statement__ = 116; - assign(v, cons_list(index_uni(t), nil_index_list()), - (y[(t - 1)] - - dot_product( - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg"), x)), - "assigning variable v"); - current_statement__ = 117; - assign(K, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - divide( - multiply(P, - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg")), - F[(t - 1)]), "assigning variable K"); - current_statement__ = 118; - assign(x, nil_index_list(), - add(stan::model::deep_copy(x), - multiply( - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K"), v[(t - 1)])), - "assigning variable x"); - current_statement__ = 119; - assign(P, nil_index_list(), - add(stan::model::deep_copy(P), - add( - multiply( - multiply( - minus( - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K")), - transpose( - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K"))), - F[(t - 1)]), Rt)), "assigning variable P");} - current_statement__ = 122; - assign(r, - cons_list(index_omni(), - cons_list(index_uni((n + 1)), nil_index_list())), rep_vector(0.0, m), - "assigning variable r"); - current_statement__ = 128; - for (int tt = 1; tt <= n; ++tt) { - int t; - t = std::numeric_limits::min(); - - current_statement__ = 123; - t = ((n + 1) - tt); - current_statement__ = 124; - validate_non_negative_index("tmp", "m", m); - Eigen::Matrix tmp; - tmp = Eigen::Matrix(m); - stan::math::fill(tmp, DUMMY_VAR__); - - current_statement__ = 125; - assign(tmp, nil_index_list(), - rvalue(r, - cons_list(index_omni(), - cons_list(index_uni((t + 1)), nil_index_list())), "r"), - "assigning variable tmp"); - current_statement__ = 126; - assign(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - subtract( - add( - divide( - multiply( - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg"), - v[(t - 1)]), F[(t - 1)]), tmp), - multiply( - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg"), - dot_product( - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K"), tmp))), - "assigning variable r");} - current_statement__ = 129; - assign(tmpr, nil_index_list(), - rvalue(r, - cons_list(index_omni(), cons_list(index_uni(1), nil_index_list())), - "r"), "assigning variable tmpr"); - current_statement__ = 130; - assign(r, - cons_list(index_omni(), cons_list(index_uni(1), nil_index_list())), - add(a1, elt_multiply(P1, tmpr)), "assigning variable r"); - current_statement__ = 137; - for (int t = 2; t <= n; ++t) { - current_statement__ = 131; - validate_non_negative_index("tmp", "m", m); - Eigen::Matrix tmp; - tmp = Eigen::Matrix(m); - stan::math::fill(tmp, DUMMY_VAR__); - - current_statement__ = 132; - assign(tmp, nil_index_list(), - rvalue(r, - cons_list(index_omni(), - cons_list(index_uni((t - 1)), nil_index_list())), "r"), - "assigning variable tmp"); - current_statement__ = 133; - validate_non_negative_index("tmp2", "m", m); - Eigen::Matrix tmp2; - tmp2 = Eigen::Matrix(m); - stan::math::fill(tmp2, DUMMY_VAR__); - - current_statement__ = 134; - assign(tmp2, nil_index_list(), - rvalue(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - "r"), "assigning variable tmp2"); - current_statement__ = 135; - assign(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - add(tmp, multiply(Rt, tmp2)), "assigning variable r");} - current_statement__ = 138; - return rvalue(r, - cons_list(index_min_max(1, m), - cons_list(index_min_max(1, n), nil_index_list())), "r"); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - -} -struct gaussian_smoother_rw_functor__ { -template -Eigen::Matrix, stan::value_type_t, -stan::value_type_t, T3__, -stan::value_type_t, stan::promote_args_t>>, -1, -1> -operator()(const T0__& y, const T1__& a1, const T2__& P1, const T3__& Ht, - const T4__& Rt, const T5__& xreg, std::ostream* pstream__) const -{ -return gaussian_smoother_rw(y, a1, P1, Ht, Rt, xreg, pstream__); -} -}; -#include -class model_rw1_model final : public model_base_crtp { -private: - int k; - int n; - Eigen::Matrix xreg; - Eigen::Matrix y; - Eigen::Matrix beta_mean; - Eigen::Matrix beta_sd; - Eigen::Matrix sigma_mean; - Eigen::Matrix sigma_sd; - int n_new; - Eigen::Matrix xreg_new; - Eigen::Matrix sigma_b_mean; - Eigen::Matrix sigma_b_sd; - double sigma_y_mean; - double sigma_y_sd; - -public: - ~model_rw1_model() { } - - inline std::string model_name() const final { return "model_rw1_model"; } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.26.1-1-g67504470", "stancflags = "}; - } - - - model_rw1_model(stan::io::var_context& context__, - unsigned int random_seed__ = 0, - std::ostream* pstream__ = nullptr) : model_base_crtp(0) { - using local_scalar_t__ = double ; - boost::ecuyer1988 base_rng__ = - stan::services::util::create_rng(random_seed__, 0); - (void) base_rng__; // suppress unused var warning - static const char* function__ = "model_rw1_model_namespace::model_rw1_model"; - (void) function__; // suppress unused var warning - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - int pos__; - pos__ = std::numeric_limits::min(); - - pos__ = 1; - current_statement__ = 43; - context__.validate_dims("data initialization","k","int", - context__.to_vec()); - k = std::numeric_limits::min(); - - current_statement__ = 43; - k = context__.vals_i("k")[(1 - 1)]; - current_statement__ = 43; - current_statement__ = 43; - check_greater_or_equal(function__, "k", k, 0); - current_statement__ = 44; - context__.validate_dims("data initialization","n","int", - context__.to_vec()); - n = std::numeric_limits::min(); - - current_statement__ = 44; - n = context__.vals_i("n")[(1 - 1)]; - current_statement__ = 44; - current_statement__ = 44; - check_greater_or_equal(function__, "n", n, 0); - current_statement__ = 45; - validate_non_negative_index("xreg", "k", k); - current_statement__ = 46; - validate_non_negative_index("xreg", "n", n); - current_statement__ = 47; - context__.validate_dims("data initialization","xreg","double", - context__.to_vec(k, n)); - xreg = Eigen::Matrix(k, n); - stan::math::fill(xreg, std::numeric_limits::quiet_NaN()); - - { - std::vector xreg_flat__; - current_statement__ = 47; - assign(xreg_flat__, nil_index_list(), context__.vals_r("xreg"), - "assigning variable xreg_flat__"); - current_statement__ = 47; - pos__ = 1; - current_statement__ = 47; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 47; - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - current_statement__ = 47; - assign(xreg, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), - xreg_flat__[(pos__ - 1)], "assigning variable xreg"); - current_statement__ = 47; - pos__ = (pos__ + 1);}} - } - current_statement__ = 48; - validate_non_negative_index("y", "n", n); - current_statement__ = 49; - context__.validate_dims("data initialization","y","double", - context__.to_vec(n)); - y = Eigen::Matrix(n); - stan::math::fill(y, std::numeric_limits::quiet_NaN()); - - { - std::vector y_flat__; - current_statement__ = 49; - assign(y_flat__, nil_index_list(), context__.vals_r("y"), - "assigning variable y_flat__"); - current_statement__ = 49; - pos__ = 1; - current_statement__ = 49; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 49; - assign(y, cons_list(index_uni(sym1__), nil_index_list()), - y_flat__[(pos__ - 1)], "assigning variable y"); - current_statement__ = 49; - pos__ = (pos__ + 1);} - } - current_statement__ = 50; - validate_non_negative_index("beta_mean", "k", k); - current_statement__ = 51; - context__.validate_dims("data initialization","beta_mean","double", - context__.to_vec(k)); - beta_mean = Eigen::Matrix(k); - stan::math::fill(beta_mean, std::numeric_limits::quiet_NaN()); - - { - std::vector beta_mean_flat__; - current_statement__ = 51; - assign(beta_mean_flat__, nil_index_list(), - context__.vals_r("beta_mean"), - "assigning variable beta_mean_flat__"); - current_statement__ = 51; - pos__ = 1; - current_statement__ = 51; - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - current_statement__ = 51; - assign(beta_mean, cons_list(index_uni(sym1__), nil_index_list()), - beta_mean_flat__[(pos__ - 1)], "assigning variable beta_mean"); - current_statement__ = 51; - pos__ = (pos__ + 1);} - } - current_statement__ = 52; - validate_non_negative_index("beta_sd", "k", k); - current_statement__ = 53; - context__.validate_dims("data initialization","beta_sd","double", - context__.to_vec(k)); - beta_sd = Eigen::Matrix(k); - stan::math::fill(beta_sd, std::numeric_limits::quiet_NaN()); - - { - std::vector beta_sd_flat__; - current_statement__ = 53; - assign(beta_sd_flat__, nil_index_list(), context__.vals_r("beta_sd"), - "assigning variable beta_sd_flat__"); - current_statement__ = 53; - pos__ = 1; - current_statement__ = 53; - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - current_statement__ = 53; - assign(beta_sd, cons_list(index_uni(sym1__), nil_index_list()), - beta_sd_flat__[(pos__ - 1)], "assigning variable beta_sd"); - current_statement__ = 53; - pos__ = (pos__ + 1);} - } - current_statement__ = 54; - validate_non_negative_index("sigma_mean", "k + 1", (k + 1)); - current_statement__ = 55; - context__.validate_dims("data initialization","sigma_mean","double", - context__.to_vec((k + 1))); - sigma_mean = Eigen::Matrix((k + 1)); - stan::math::fill(sigma_mean, std::numeric_limits::quiet_NaN()); - - { - std::vector sigma_mean_flat__; - current_statement__ = 55; - assign(sigma_mean_flat__, nil_index_list(), - context__.vals_r("sigma_mean"), - "assigning variable sigma_mean_flat__"); - current_statement__ = 55; - pos__ = 1; - current_statement__ = 55; - for (int sym1__ = 1; sym1__ <= (k + 1); ++sym1__) { - current_statement__ = 55; - assign(sigma_mean, cons_list(index_uni(sym1__), nil_index_list()), - sigma_mean_flat__[(pos__ - 1)], "assigning variable sigma_mean"); - current_statement__ = 55; - pos__ = (pos__ + 1);} - } - current_statement__ = 56; - validate_non_negative_index("sigma_sd", "k + 1", (k + 1)); - current_statement__ = 57; - context__.validate_dims("data initialization","sigma_sd","double", - context__.to_vec((k + 1))); - sigma_sd = Eigen::Matrix((k + 1)); - stan::math::fill(sigma_sd, std::numeric_limits::quiet_NaN()); - - { - std::vector sigma_sd_flat__; - current_statement__ = 57; - assign(sigma_sd_flat__, nil_index_list(), - context__.vals_r("sigma_sd"), "assigning variable sigma_sd_flat__"); - current_statement__ = 57; - pos__ = 1; - current_statement__ = 57; - for (int sym1__ = 1; sym1__ <= (k + 1); ++sym1__) { - current_statement__ = 57; - assign(sigma_sd, cons_list(index_uni(sym1__), nil_index_list()), - sigma_sd_flat__[(pos__ - 1)], "assigning variable sigma_sd"); - current_statement__ = 57; - pos__ = (pos__ + 1);} - } - current_statement__ = 58; - context__.validate_dims("data initialization","n_new","int", - context__.to_vec()); - n_new = std::numeric_limits::min(); - - current_statement__ = 58; - n_new = context__.vals_i("n_new")[(1 - 1)]; - current_statement__ = 58; - current_statement__ = 58; - check_greater_or_equal(function__, "n_new", n_new, 0); - current_statement__ = 59; - validate_non_negative_index("xreg_new", "k", k); - current_statement__ = 60; - validate_non_negative_index("xreg_new", "n_new", n_new); - current_statement__ = 61; - context__.validate_dims("data initialization","xreg_new","double", - context__.to_vec(k, n_new)); - xreg_new = Eigen::Matrix(k, n_new); - stan::math::fill(xreg_new, std::numeric_limits::quiet_NaN()); - - { - std::vector xreg_new_flat__; - current_statement__ = 61; - assign(xreg_new_flat__, nil_index_list(), - context__.vals_r("xreg_new"), "assigning variable xreg_new_flat__"); - current_statement__ = 61; - pos__ = 1; - current_statement__ = 61; - for (int sym1__ = 1; sym1__ <= n_new; ++sym1__) { - current_statement__ = 61; - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - current_statement__ = 61; - assign(xreg_new, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), - xreg_new_flat__[(pos__ - 1)], "assigning variable xreg_new"); - current_statement__ = 61; - pos__ = (pos__ + 1);}} - } - current_statement__ = 62; - validate_non_negative_index("sigma_b_mean", "k", k); - current_statement__ = 63; - sigma_b_mean = Eigen::Matrix(k); - stan::math::fill(sigma_b_mean, std::numeric_limits::quiet_NaN()); - - current_statement__ = 63; - assign(sigma_b_mean, nil_index_list(), - rvalue(sigma_mean, cons_list(index_min(2), nil_index_list()), - "sigma_mean"), "assigning variable sigma_b_mean"); - current_statement__ = 64; - validate_non_negative_index("sigma_b_sd", "k", k); - current_statement__ = 65; - sigma_b_sd = Eigen::Matrix(k); - stan::math::fill(sigma_b_sd, std::numeric_limits::quiet_NaN()); - - current_statement__ = 65; - assign(sigma_b_sd, nil_index_list(), - rvalue(sigma_sd, cons_list(index_min(2), nil_index_list()), - "sigma_sd"), "assigning variable sigma_b_sd"); - current_statement__ = 66; - sigma_y_mean = std::numeric_limits::quiet_NaN(); - - current_statement__ = 66; - sigma_y_mean = sigma_mean[(1 - 1)]; - current_statement__ = 67; - sigma_y_sd = std::numeric_limits::quiet_NaN(); - - current_statement__ = 67; - sigma_y_sd = sigma_sd[(1 - 1)]; - current_statement__ = 68; - validate_non_negative_index("sigma_b", "k", k); - current_statement__ = 69; - validate_non_negative_index("R_vector", "k", k); - current_statement__ = 70; - validate_non_negative_index("P1_vector", "k", k); - current_statement__ = 71; - validate_non_negative_index("y_rep", "n", n); - current_statement__ = 72; - validate_non_negative_index("beta", "k", k); - current_statement__ = 73; - validate_non_negative_index("beta", "n", n); - current_statement__ = 74; - validate_non_negative_index("y_new", "n_new", n_new); - current_statement__ = 75; - validate_non_negative_index("beta_new", "k", k); - current_statement__ = 76; - validate_non_negative_index("beta_new", "n_new", n_new); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - num_params_r__ = 0U; - - try { - num_params_r__ += k; - num_params_r__ += 1; - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - } - template * = nullptr, stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t log_prob_impl(VecR& params_r__, - VecI& params_i__, - std::ostream* pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - static const char* function__ = "model_rw1_model_namespace::log_prob"; -(void) function__; // suppress unused var warning - stan::io::reader in__(params_r__, params_i__); - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - std::vector sigma_b; - sigma_b = std::vector(k, DUMMY_VAR__); - - current_statement__ = 1; - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - current_statement__ = 1; - assign(sigma_b, cons_list(index_uni(sym1__), nil_index_list()), - in__.scalar(), "assigning variable sigma_b");} - current_statement__ = 1; - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - current_statement__ = 1; - if (jacobian__) { - current_statement__ = 1; - assign(sigma_b, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_b[(sym1__ - 1)], 0, lp__), - "assigning variable sigma_b"); - } else { - current_statement__ = 1; - assign(sigma_b, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_b[(sym1__ - 1)], 0), - "assigning variable sigma_b"); - }} - local_scalar_t__ sigma_y; - sigma_y = DUMMY_VAR__; - - current_statement__ = 2; - sigma_y = in__.scalar(); - current_statement__ = 2; - if (jacobian__) { - current_statement__ = 2; - sigma_y = stan::math::lb_constrain(sigma_y, 0, lp__); - } else { - current_statement__ = 2; - sigma_y = stan::math::lb_constrain(sigma_y, 0); - } - Eigen::Matrix R_vector; - R_vector = Eigen::Matrix(k); - stan::math::fill(R_vector, DUMMY_VAR__); - - Eigen::Matrix P1_vector; - P1_vector = Eigen::Matrix(k); - stan::math::fill(P1_vector, DUMMY_VAR__); - - current_statement__ = 8; - for (int i = 1; i <= k; ++i) { - current_statement__ = 5; - assign(R_vector, cons_list(index_uni(i), nil_index_list()), - pow(sigma_b[(i - 1)], 2), "assigning variable R_vector"); - current_statement__ = 6; - assign(P1_vector, cons_list(index_uni(i), nil_index_list()), - pow(beta_sd[(i - 1)], 2), "assigning variable P1_vector");} - { - current_statement__ = 40; - lp_accum__.add( - normal_lpdf(sigma_b, sigma_b_mean, sigma_b_sd)); - current_statement__ = 41; - lp_accum__.add( - normal_lpdf(sigma_y, sigma_y_mean, sigma_y_sd)); - current_statement__ = 42; - lp_accum__.add( - gaussian_filter_rw_lpdf(y, beta_mean, P1_vector, - pow(sigma_y, 2), diag_matrix(R_vector), xreg, pstream__)); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } // log_prob_impl() - - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_std_vector_vt* = nullptr> - inline void write_array_impl(RNG& base_rng__, VecR& params_r__, - VecI& params_i__, VecVar& vars__, - const bool emit_transformed_parameters__ = true, - const bool emit_generated_quantities__ = true, - std::ostream* pstream__ = nullptr) const { - using local_scalar_t__ = double; - vars__.resize(0); - stan::io::reader in__(params_r__, params_i__); - static const char* function__ = "model_rw1_model_namespace::write_array"; -(void) function__; // suppress unused var warning - (void) function__; // suppress unused var warning - double lp__ = 0.0; - (void) lp__; // dummy to suppress unused var warning - stan::math::accumulator lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - std::vector sigma_b; - sigma_b = std::vector(k, std::numeric_limits::quiet_NaN()); - - current_statement__ = 1; - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - current_statement__ = 1; - assign(sigma_b, cons_list(index_uni(sym1__), nil_index_list()), - in__.scalar(), "assigning variable sigma_b");} - current_statement__ = 1; - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - current_statement__ = 1; - assign(sigma_b, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_b[(sym1__ - 1)], 0), - "assigning variable sigma_b");} - double sigma_y; - sigma_y = std::numeric_limits::quiet_NaN(); - - current_statement__ = 2; - sigma_y = in__.scalar(); - current_statement__ = 2; - sigma_y = stan::math::lb_constrain(sigma_y, 0); - Eigen::Matrix R_vector; - R_vector = Eigen::Matrix(k); - stan::math::fill(R_vector, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix P1_vector; - P1_vector = Eigen::Matrix(k); - stan::math::fill(P1_vector, std::numeric_limits::quiet_NaN()); - - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - vars__.emplace_back(sigma_b[(sym1__ - 1)]);} - vars__.emplace_back(sigma_y); - if (logical_negation((primitive_value(emit_transformed_parameters__) || - primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 8; - for (int i = 1; i <= k; ++i) { - current_statement__ = 5; - assign(R_vector, cons_list(index_uni(i), nil_index_list()), - pow(sigma_b[(i - 1)], 2), "assigning variable R_vector"); - current_statement__ = 6; - assign(P1_vector, cons_list(index_uni(i), nil_index_list()), - pow(beta_sd[(i - 1)], 2), "assigning variable P1_vector");} - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - vars__.emplace_back(R_vector[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - vars__.emplace_back(P1_vector[(sym1__ - 1)]);} - } - if (logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix y_rep; - y_rep = Eigen::Matrix(n); - stan::math::fill(y_rep, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix beta; - beta = Eigen::Matrix(k, n); - stan::math::fill(beta, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix y_new; - y_new = Eigen::Matrix(n_new); - stan::math::fill(y_new, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix beta_new; - beta_new = Eigen::Matrix(k, n_new); - stan::math::fill(beta_new, std::numeric_limits::quiet_NaN()); - - current_statement__ = 15; - for (int i = 1; i <= k; ++i) { - current_statement__ = 13; - assign(beta, - cons_list(index_uni(i), cons_list(index_uni(1), nil_index_list())), - normal_rng(beta_mean[(i - 1)], beta_sd[(i - 1)], base_rng__), - "assigning variable beta");} - current_statement__ = 20; - for (int t = 1; t <= (n - 1); ++t) { - current_statement__ = 18; - for (int i = 1; i <= k; ++i) { - current_statement__ = 16; - assign(beta, - cons_list(index_uni(i), - cons_list(index_uni((t + 1)), nil_index_list())), - normal_rng( - rvalue(beta, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "beta"), - sigma_b[(i - 1)], base_rng__), "assigning variable beta");}} - current_statement__ = 23; - for (int t = 1; t <= n; ++t) { - current_statement__ = 21; - assign(y_rep, cons_list(index_uni(t), nil_index_list()), - normal_rng( - dot_product( - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg"), - rvalue(beta, - cons_list(index_min_max(1, k), - cons_list(index_uni(t), nil_index_list())), "beta")), - sigma_y, base_rng__), "assigning variable y_rep");} - current_statement__ = 24; - assign(beta, nil_index_list(), - add(stan::model::deep_copy(beta), - gaussian_smoother_rw(subtract(y, y_rep), beta_mean, P1_vector, - pow(sigma_y, 2), diag_matrix(R_vector), xreg, pstream__)), - "assigning variable beta"); - current_statement__ = 27; - for (int t = 1; t <= n; ++t) { - current_statement__ = 25; - assign(y_rep, cons_list(index_uni(t), nil_index_list()), - (dot_product( - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg"), - rvalue(beta, - cons_list(index_min_max(1, k), - cons_list(index_uni(t), nil_index_list())), "beta")) + - normal_rng(0, sigma_y, base_rng__)), "assigning variable y_rep"); - } - current_statement__ = 39; - if (logical_gt(n_new, 0)) { - current_statement__ = 30; - for (int i = 1; i <= k; ++i) { - current_statement__ = 28; - assign(beta_new, - cons_list(index_uni(i), - cons_list(index_uni(1), nil_index_list())), - normal_rng( - rvalue(beta, - cons_list(index_uni(i), - cons_list(index_uni(n), nil_index_list())), "beta"), - sigma_b[(i - 1)], base_rng__), "assigning variable beta_new");} - current_statement__ = 36; - for (int t = 1; t <= (n_new - 1); ++t) { - current_statement__ = 31; - assign(y_new, cons_list(index_uni(t), nil_index_list()), - (dot_product( - rvalue(xreg_new, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg_new"), - rvalue(beta_new, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "beta_new")) + - normal_rng(0, sigma_y, base_rng__)), "assigning variable y_new"); - current_statement__ = 34; - for (int i = 1; i <= k; ++i) { - current_statement__ = 32; - assign(beta_new, - cons_list(index_uni(i), - cons_list(index_uni((t + 1)), nil_index_list())), - normal_rng( - rvalue(beta_new, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "beta_new"), - sigma_b[(i - 1)], base_rng__), "assigning variable beta_new"); - }} - current_statement__ = 37; - assign(y_new, cons_list(index_uni(n_new), nil_index_list()), - (dot_product( - rvalue(xreg_new, - cons_list(index_omni(), - cons_list(index_uni(n_new), nil_index_list())), "xreg_new"), - rvalue(beta_new, - cons_list(index_omni(), - cons_list(index_uni(n_new), nil_index_list())), "beta_new")) - + normal_rng(0, sigma_y, base_rng__)), "assigning variable y_new"); - } - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - vars__.emplace_back(y_rep[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - vars__.emplace_back( - rvalue(beta, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), "beta"));}} - for (int sym1__ = 1; sym1__ <= n_new; ++sym1__) { - vars__.emplace_back(y_new[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= n_new; ++sym1__) { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - vars__.emplace_back( - rvalue(beta_new, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), "beta_new")); - }} - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - } // write_array_impl() - - template * = nullptr, stan::require_vector_like_vt* = nullptr> - inline void transform_inits_impl(const stan::io::var_context& context__, - VecI& params_i__, VecVar& vars__, - std::ostream* pstream__ = nullptr) const { - using local_scalar_t__ = double; - vars__.clear(); - vars__.reserve(num_params_r__); - - try { - int pos__; - pos__ = std::numeric_limits::min(); - - pos__ = 1; - std::vector sigma_b; - sigma_b = std::vector(k, std::numeric_limits::quiet_NaN()); - - current_statement__ = 1; - assign(sigma_b, nil_index_list(), context__.vals_r("sigma_b"), - "assigning variable sigma_b"); - std::vector sigma_b_free__; - sigma_b_free__ = std::vector(k, std::numeric_limits::quiet_NaN()); - - current_statement__ = 1; - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - current_statement__ = 1; - assign(sigma_b_free__, - cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_free(sigma_b[(sym1__ - 1)], 0), - "assigning variable sigma_b_free__");} - double sigma_y; - sigma_y = std::numeric_limits::quiet_NaN(); - - current_statement__ = 2; - sigma_y = context__.vals_r("sigma_y")[(1 - 1)]; - double sigma_y_free__; - sigma_y_free__ = std::numeric_limits::quiet_NaN(); - - current_statement__ = 2; - sigma_y_free__ = stan::math::lb_free(sigma_y, 0); - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - vars__.emplace_back(sigma_b_free__[(sym1__ - 1)]);} - vars__.emplace_back(sigma_y_free__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - } // transform_inits_impl() - - inline void get_param_names(std::vector& names__) const { - - names__.clear(); - names__.emplace_back("sigma_b"); - names__.emplace_back("sigma_y"); - names__.emplace_back("R_vector"); - names__.emplace_back("P1_vector"); - names__.emplace_back("y_rep"); - names__.emplace_back("beta"); - names__.emplace_back("y_new"); - names__.emplace_back("beta_new"); - } // get_param_names() - - inline void get_dims(std::vector>& dimss__) const { - dimss__.clear(); - dimss__.emplace_back(std::vector{static_cast(k)}); - - dimss__.emplace_back(std::vector{}); - - dimss__.emplace_back(std::vector{static_cast(k)}); - - dimss__.emplace_back(std::vector{static_cast(k)}); - - dimss__.emplace_back(std::vector{static_cast(n)}); - - dimss__.emplace_back(std::vector{static_cast(k), - static_cast(n)}); - - dimss__.emplace_back(std::vector{static_cast(n_new)}); - - dimss__.emplace_back(std::vector{static_cast(k), - static_cast(n_new)}); - - } // get_dims() - - inline void constrained_param_names( - std::vector& param_names__, - bool emit_transformed_parameters__ = true, - bool emit_generated_quantities__ = true) const - final { - - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "sigma_b" + '.' + std::to_string(sym1__)); - }} - param_names__.emplace_back(std::string() + "sigma_y"); - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "R_vector" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "P1_vector" + '.' + std::to_string(sym1__)); - }} - } - - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_rep" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - { - param_names__.emplace_back(std::string() + "beta" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - for (int sym1__ = 1; sym1__ <= n_new; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_new" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= n_new; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - { - param_names__.emplace_back(std::string() + "beta_new" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - } - - } // constrained_param_names() - - inline void unconstrained_param_names( - std::vector& param_names__, - bool emit_transformed_parameters__ = true, - bool emit_generated_quantities__ = true) const - final { - - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "sigma_b" + '.' + std::to_string(sym1__)); - }} - param_names__.emplace_back(std::string() + "sigma_y"); - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "R_vector" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "P1_vector" + '.' + std::to_string(sym1__)); - }} - } - - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_rep" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - { - param_names__.emplace_back(std::string() + "beta" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - for (int sym1__ = 1; sym1__ <= n_new; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_new" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= n_new; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - { - param_names__.emplace_back(std::string() + "beta_new" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - } - - } // unconstrained_param_names() - - inline std::string get_constrained_sizedtypes() const { - stringstream s__; - s__ << "[{\"name\":\"sigma_b\",\"type\":{\"name\":\"array\",\"length\":" << k << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"sigma_y\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"R_vector\",\"type\":{\"name\":\"vector\",\"length\":" << k << "},\"block\":\"transformed_parameters\"},{\"name\":\"P1_vector\",\"type\":{\"name\":\"vector\",\"length\":" << k << "},\"block\":\"transformed_parameters\"},{\"name\":\"y_rep\",\"type\":{\"name\":\"vector\",\"length\":" << n << "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"matrix\",\"rows\":" << k << ",\"cols\":" << n << "},\"block\":\"generated_quantities\"},{\"name\":\"y_new\",\"type\":{\"name\":\"vector\",\"length\":" << n_new << "},\"block\":\"generated_quantities\"},{\"name\":\"beta_new\",\"type\":{\"name\":\"matrix\",\"rows\":" << k << ",\"cols\":" << n_new << "},\"block\":\"generated_quantities\"}]"; - return s__.str(); - } // get_constrained_sizedtypes() - - inline std::string get_unconstrained_sizedtypes() const { - stringstream s__; - s__ << "[{\"name\":\"sigma_b\",\"type\":{\"name\":\"array\",\"length\":" << k << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"sigma_y\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"R_vector\",\"type\":{\"name\":\"vector\",\"length\":" << k << "},\"block\":\"transformed_parameters\"},{\"name\":\"P1_vector\",\"type\":{\"name\":\"vector\",\"length\":" << k << "},\"block\":\"transformed_parameters\"},{\"name\":\"y_rep\",\"type\":{\"name\":\"vector\",\"length\":" << n << "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"matrix\",\"rows\":" << k << ",\"cols\":" << n << "},\"block\":\"generated_quantities\"},{\"name\":\"y_new\",\"type\":{\"name\":\"vector\",\"length\":" << n_new << "},\"block\":\"generated_quantities\"},{\"name\":\"beta_new\",\"type\":{\"name\":\"matrix\",\"rows\":" << k << ",\"cols\":" << n_new << "},\"block\":\"generated_quantities\"}]"; - return s__.str(); - } // get_unconstrained_sizedtypes() - - - // Begin method overload boilerplate - template - inline void write_array(RNG& base_rng, - Eigen::Matrix& params_r, - Eigen::Matrix& vars, - const bool emit_transformed_parameters = true, - const bool emit_generated_quantities = true, - std::ostream* pstream = nullptr) const { - std::vector vars_vec(vars.size()); - std::vector params_i; - write_array_impl(base_rng, params_r, params_i, vars_vec, - emit_transformed_parameters, emit_generated_quantities, pstream); - vars.resize(vars_vec.size()); - for (int i = 0; i < vars.size(); ++i) { - vars.coeffRef(i) = vars_vec[i]; - } - } - template - inline void write_array(RNG& base_rng, std::vector& params_r, - std::vector& params_i, - std::vector& vars, - bool emit_transformed_parameters = true, - bool emit_generated_quantities = true, - std::ostream* pstream = nullptr) const { - write_array_impl(base_rng, params_r, params_i, vars, emit_transformed_parameters, emit_generated_quantities, pstream); - } - template - inline T_ log_prob(Eigen::Matrix& params_r, - std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template - inline T__ log_prob(std::vector& params_r, - std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - - inline void transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, - std::ostream* pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits_impl(context, params_i, params_r_vec, pstream); - params_r.resize(params_r_vec.size()); - for (int i = 0; i < params_r.size(); ++i) { - params_r.coeffRef(i) = params_r_vec[i]; - } - } - inline void transform_inits(const stan::io::var_context& context, - std::vector& params_i, - std::vector& vars, - std::ostream* pstream = nullptr) const final { - transform_inits_impl(context, params_i, vars, pstream); - } -}; -} -using stan_model = model_rw1_model_namespace::model_rw1_model; -#ifndef USING_R -// Boilerplate -stan::model::model_base& new_model( - stan::io::var_context& data_context, - unsigned int seed, - std::ostream* msg_stream) { - stan_model* m = new stan_model(data_context, seed, msg_stream); - return *m; -} -stan::math::profile_map& get_stan_profile_data() { - return model_rw1_model_namespace::profiles__; -} -#endif -#endif diff --git a/src/stanExports_rw1_model_naive.cc b/src/stanExports_rw1_model_naive.cc deleted file mode 100644 index 1af084d..0000000 --- a/src/stanExports_rw1_model_naive.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Generated by rstantools. Do not edit by hand. - -#include -using namespace Rcpp ; -#include "stanExports_rw1_model_naive.h" - -RCPP_MODULE(stan_fit4rw1_model_naive_mod) { - - - class_ >("rstantools_model_rw1_model_naive") - - .constructor() - - - .method("call_sampler", &rstan::stan_fit ::call_sampler) - .method("param_names", &rstan::stan_fit ::param_names) - .method("param_names_oi", &rstan::stan_fit ::param_names_oi) - .method("param_fnames_oi", &rstan::stan_fit ::param_fnames_oi) - .method("param_dims", &rstan::stan_fit ::param_dims) - .method("param_dims_oi", &rstan::stan_fit ::param_dims_oi) - .method("update_param_oi", &rstan::stan_fit ::update_param_oi) - .method("param_oi_tidx", &rstan::stan_fit ::param_oi_tidx) - .method("grad_log_prob", &rstan::stan_fit ::grad_log_prob) - .method("log_prob", &rstan::stan_fit ::log_prob) - .method("unconstrain_pars", &rstan::stan_fit ::unconstrain_pars) - .method("constrain_pars", &rstan::stan_fit ::constrain_pars) - .method("num_pars_unconstrained", &rstan::stan_fit ::num_pars_unconstrained) - .method("unconstrained_param_names", &rstan::stan_fit ::unconstrained_param_names) - .method("constrained_param_names", &rstan::stan_fit ::constrained_param_names) - .method("standalone_gqs", &rstan::stan_fit ::standalone_gqs) - ; -} diff --git a/src/stanExports_rw1_model_naive.h b/src/stanExports_rw1_model_naive.h deleted file mode 100644 index 3b3ee10..0000000 --- a/src/stanExports_rw1_model_naive.h +++ /dev/null @@ -1,892 +0,0 @@ -// Generated by rstantools. Do not edit by hand. - -/* - walker is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - licence is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with licence. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.26.1-1-g67504470 -#include -namespace model_rw1_model_naive_namespace { -inline void validate_positive_index(const char* var_name, const char* expr, - int val) { - if (val < 1) { - std::stringstream msg; - msg << "Found dimension size less than one in simplex declaration" - << "; variable=" << var_name << "; dimension size expression=" << expr - << "; expression value=" << val; - std::string msg_str(msg.str()); - throw std::invalid_argument(msg_str.c_str()); - } -} -inline void validate_unit_vector_index(const char* var_name, const char* expr, - int val) { - if (val <= 1) { - std::stringstream msg; - if (val == 1) { - msg << "Found dimension size one in unit vector declaration." - << " One-dimensional unit vector is discrete" - << " but the target distribution must be continuous." - << " variable=" << var_name << "; dimension size expression=" << expr; - } else { - msg << "Found dimension size less than one in unit vector declaration" - << "; variable=" << var_name << "; dimension size expression=" << expr - << "; expression value=" << val; - } - std::string msg_str(msg.str()); - throw std::invalid_argument(msg_str.c_str()); - } -} -using std::istream; -using std::string; -using std::stringstream; -using std::vector; -using std::pow; -using stan::io::dump; -using stan::math::lgamma; -using stan::model::model_base_crtp; -using stan::model::rvalue; -using stan::model::cons_list; -using stan::model::index_uni; -using stan::model::index_max; -using stan::model::index_min; -using stan::model::index_min_max; -using stan::model::index_multi; -using stan::model::index_omni; -using stan::model::nil_index_list; -using namespace stan::math; -using stan::math::pow; -stan::math::profile_map profiles__; -static int current_statement__= 0; -static const std::vector locations_array__ = {" (found before start of program)", - " (in 'string', line 18, column 2 to column 27)", - " (in 'string', line 19, column 2 to column 24)", - " (in 'string', line 20, column 2 to column 24)", - " (in 'string', line 23, column 2 to column 20)", - " (in 'string', line 25, column 2 to column 16)", - " (in 'string', line 26, column 2 to column 51)", - " (in 'string', line 28, column 4 to column 24)", - " (in 'string', line 29, column 4 to column 58)", - " (in 'string', line 27, column 16 to line 30, column 3)", - " (in 'string', line 27, column 2 to line 30, column 3)", - " (in 'string', line 33, column 2 to column 45)", - " (in 'string', line 34, column 2 to column 45)", - " (in 'string', line 35, column 2 to column 37)", - " (in 'string', line 37, column 15 to column 16)", - " (in 'string', line 37, column 4 to column 55)", - " (in 'string', line 38, column 4 to column 28)", - " (in 'string', line 36, column 2 to line 39, column 3)", - " (in 'string', line 2, column 2 to column 17)", - " (in 'string', line 3, column 2 to column 17)", - " (in 'string', line 4, column 9 to column 10)", - " (in 'string', line 4, column 12 to column 13)", - " (in 'string', line 4, column 2 to column 20)", - " (in 'string', line 5, column 9 to column 10)", - " (in 'string', line 5, column 2 to column 14)", - " (in 'string', line 6, column 9 to column 10)", - " (in 'string', line 6, column 2 to column 22)", - " (in 'string', line 7, column 9 to column 10)", - " (in 'string', line 7, column 2 to column 20)", - " (in 'string', line 8, column 9 to column 14)", - " (in 'string', line 8, column 2 to column 27)", - " (in 'string', line 9, column 9 to column 14)", - " (in 'string', line 9, column 2 to column 25)", - " (in 'string', line 12, column 9 to column 10)", - " (in 'string', line 12, column 2 to column 42)", - " (in 'string', line 13, column 9 to column 10)", - " (in 'string', line 13, column 2 to column 38)", - " (in 'string', line 14, column 2 to column 36)", - " (in 'string', line 15, column 2 to column 32)", - " (in 'string', line 18, column 24 to column 25)", - " (in 'string', line 20, column 9 to column 10)", - " (in 'string', line 20, column 12 to column 13)", - " (in 'string', line 23, column 9 to column 10)", - " (in 'string', line 23, column 12 to column 13)", - " (in 'string', line 25, column 9 to column 10)"}; -#include -class model_rw1_model_naive final : public model_base_crtp { -private: - int k; - int n; - Eigen::Matrix xreg; - Eigen::Matrix y; - Eigen::Matrix beta_mean; - Eigen::Matrix beta_sd; - Eigen::Matrix sigma_mean; - Eigen::Matrix sigma_sd; - Eigen::Matrix sigma_b_mean; - Eigen::Matrix sigma_b_sd; - double sigma_y_mean; - double sigma_y_sd; - -public: - ~model_rw1_model_naive() { } - - inline std::string model_name() const final { return "model_rw1_model_naive"; } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.26.1-1-g67504470", "stancflags = "}; - } - - - model_rw1_model_naive(stan::io::var_context& context__, - unsigned int random_seed__ = 0, - std::ostream* pstream__ = nullptr) : model_base_crtp(0) { - using local_scalar_t__ = double ; - boost::ecuyer1988 base_rng__ = - stan::services::util::create_rng(random_seed__, 0); - (void) base_rng__; // suppress unused var warning - static const char* function__ = "model_rw1_model_naive_namespace::model_rw1_model_naive"; - (void) function__; // suppress unused var warning - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - int pos__; - pos__ = std::numeric_limits::min(); - - pos__ = 1; - current_statement__ = 18; - context__.validate_dims("data initialization","k","int", - context__.to_vec()); - k = std::numeric_limits::min(); - - current_statement__ = 18; - k = context__.vals_i("k")[(1 - 1)]; - current_statement__ = 18; - current_statement__ = 18; - check_greater_or_equal(function__, "k", k, 0); - current_statement__ = 19; - context__.validate_dims("data initialization","n","int", - context__.to_vec()); - n = std::numeric_limits::min(); - - current_statement__ = 19; - n = context__.vals_i("n")[(1 - 1)]; - current_statement__ = 19; - current_statement__ = 19; - check_greater_or_equal(function__, "n", n, 0); - current_statement__ = 20; - validate_non_negative_index("xreg", "k", k); - current_statement__ = 21; - validate_non_negative_index("xreg", "n", n); - current_statement__ = 22; - context__.validate_dims("data initialization","xreg","double", - context__.to_vec(k, n)); - xreg = Eigen::Matrix(k, n); - stan::math::fill(xreg, std::numeric_limits::quiet_NaN()); - - { - std::vector xreg_flat__; - current_statement__ = 22; - assign(xreg_flat__, nil_index_list(), context__.vals_r("xreg"), - "assigning variable xreg_flat__"); - current_statement__ = 22; - pos__ = 1; - current_statement__ = 22; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 22; - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - current_statement__ = 22; - assign(xreg, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), - xreg_flat__[(pos__ - 1)], "assigning variable xreg"); - current_statement__ = 22; - pos__ = (pos__ + 1);}} - } - current_statement__ = 23; - validate_non_negative_index("y", "n", n); - current_statement__ = 24; - context__.validate_dims("data initialization","y","double", - context__.to_vec(n)); - y = Eigen::Matrix(n); - stan::math::fill(y, std::numeric_limits::quiet_NaN()); - - { - std::vector y_flat__; - current_statement__ = 24; - assign(y_flat__, nil_index_list(), context__.vals_r("y"), - "assigning variable y_flat__"); - current_statement__ = 24; - pos__ = 1; - current_statement__ = 24; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 24; - assign(y, cons_list(index_uni(sym1__), nil_index_list()), - y_flat__[(pos__ - 1)], "assigning variable y"); - current_statement__ = 24; - pos__ = (pos__ + 1);} - } - current_statement__ = 25; - validate_non_negative_index("beta_mean", "k", k); - current_statement__ = 26; - context__.validate_dims("data initialization","beta_mean","double", - context__.to_vec(k)); - beta_mean = Eigen::Matrix(k); - stan::math::fill(beta_mean, std::numeric_limits::quiet_NaN()); - - { - std::vector beta_mean_flat__; - current_statement__ = 26; - assign(beta_mean_flat__, nil_index_list(), - context__.vals_r("beta_mean"), - "assigning variable beta_mean_flat__"); - current_statement__ = 26; - pos__ = 1; - current_statement__ = 26; - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - current_statement__ = 26; - assign(beta_mean, cons_list(index_uni(sym1__), nil_index_list()), - beta_mean_flat__[(pos__ - 1)], "assigning variable beta_mean"); - current_statement__ = 26; - pos__ = (pos__ + 1);} - } - current_statement__ = 27; - validate_non_negative_index("beta_sd", "k", k); - current_statement__ = 28; - context__.validate_dims("data initialization","beta_sd","double", - context__.to_vec(k)); - beta_sd = Eigen::Matrix(k); - stan::math::fill(beta_sd, std::numeric_limits::quiet_NaN()); - - { - std::vector beta_sd_flat__; - current_statement__ = 28; - assign(beta_sd_flat__, nil_index_list(), context__.vals_r("beta_sd"), - "assigning variable beta_sd_flat__"); - current_statement__ = 28; - pos__ = 1; - current_statement__ = 28; - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - current_statement__ = 28; - assign(beta_sd, cons_list(index_uni(sym1__), nil_index_list()), - beta_sd_flat__[(pos__ - 1)], "assigning variable beta_sd"); - current_statement__ = 28; - pos__ = (pos__ + 1);} - } - current_statement__ = 29; - validate_non_negative_index("sigma_mean", "k + 1", (k + 1)); - current_statement__ = 30; - context__.validate_dims("data initialization","sigma_mean","double", - context__.to_vec((k + 1))); - sigma_mean = Eigen::Matrix((k + 1)); - stan::math::fill(sigma_mean, std::numeric_limits::quiet_NaN()); - - { - std::vector sigma_mean_flat__; - current_statement__ = 30; - assign(sigma_mean_flat__, nil_index_list(), - context__.vals_r("sigma_mean"), - "assigning variable sigma_mean_flat__"); - current_statement__ = 30; - pos__ = 1; - current_statement__ = 30; - for (int sym1__ = 1; sym1__ <= (k + 1); ++sym1__) { - current_statement__ = 30; - assign(sigma_mean, cons_list(index_uni(sym1__), nil_index_list()), - sigma_mean_flat__[(pos__ - 1)], "assigning variable sigma_mean"); - current_statement__ = 30; - pos__ = (pos__ + 1);} - } - current_statement__ = 31; - validate_non_negative_index("sigma_sd", "k + 1", (k + 1)); - current_statement__ = 32; - context__.validate_dims("data initialization","sigma_sd","double", - context__.to_vec((k + 1))); - sigma_sd = Eigen::Matrix((k + 1)); - stan::math::fill(sigma_sd, std::numeric_limits::quiet_NaN()); - - { - std::vector sigma_sd_flat__; - current_statement__ = 32; - assign(sigma_sd_flat__, nil_index_list(), - context__.vals_r("sigma_sd"), "assigning variable sigma_sd_flat__"); - current_statement__ = 32; - pos__ = 1; - current_statement__ = 32; - for (int sym1__ = 1; sym1__ <= (k + 1); ++sym1__) { - current_statement__ = 32; - assign(sigma_sd, cons_list(index_uni(sym1__), nil_index_list()), - sigma_sd_flat__[(pos__ - 1)], "assigning variable sigma_sd"); - current_statement__ = 32; - pos__ = (pos__ + 1);} - } - current_statement__ = 33; - validate_non_negative_index("sigma_b_mean", "k", k); - current_statement__ = 34; - sigma_b_mean = Eigen::Matrix(k); - stan::math::fill(sigma_b_mean, std::numeric_limits::quiet_NaN()); - - current_statement__ = 34; - assign(sigma_b_mean, nil_index_list(), - rvalue(sigma_mean, cons_list(index_min(2), nil_index_list()), - "sigma_mean"), "assigning variable sigma_b_mean"); - current_statement__ = 35; - validate_non_negative_index("sigma_b_sd", "k", k); - current_statement__ = 36; - sigma_b_sd = Eigen::Matrix(k); - stan::math::fill(sigma_b_sd, std::numeric_limits::quiet_NaN()); - - current_statement__ = 36; - assign(sigma_b_sd, nil_index_list(), - rvalue(sigma_sd, cons_list(index_min(2), nil_index_list()), - "sigma_sd"), "assigning variable sigma_b_sd"); - current_statement__ = 37; - sigma_y_mean = std::numeric_limits::quiet_NaN(); - - current_statement__ = 37; - sigma_y_mean = sigma_mean[(1 - 1)]; - current_statement__ = 38; - sigma_y_sd = std::numeric_limits::quiet_NaN(); - - current_statement__ = 38; - sigma_y_sd = sigma_sd[(1 - 1)]; - current_statement__ = 39; - validate_non_negative_index("sigma_b", "k", k); - current_statement__ = 40; - validate_non_negative_index("beta_raw", "k", k); - current_statement__ = 41; - validate_non_negative_index("beta_raw", "n", n); - current_statement__ = 42; - validate_non_negative_index("beta", "k", k); - current_statement__ = 43; - validate_non_negative_index("beta", "n", n); - current_statement__ = 44; - validate_non_negative_index("tmp", "k", k); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - num_params_r__ = 0U; - - try { - num_params_r__ += k; - num_params_r__ += 1; - num_params_r__ += k * n; - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - } - template * = nullptr, stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t log_prob_impl(VecR& params_r__, - VecI& params_i__, - std::ostream* pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - static const char* function__ = "model_rw1_model_naive_namespace::log_prob"; -(void) function__; // suppress unused var warning - stan::io::reader in__(params_r__, params_i__); - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - std::vector sigma_b; - sigma_b = std::vector(k, DUMMY_VAR__); - - current_statement__ = 1; - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - current_statement__ = 1; - assign(sigma_b, cons_list(index_uni(sym1__), nil_index_list()), - in__.scalar(), "assigning variable sigma_b");} - current_statement__ = 1; - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - current_statement__ = 1; - if (jacobian__) { - current_statement__ = 1; - assign(sigma_b, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_b[(sym1__ - 1)], 0, lp__), - "assigning variable sigma_b"); - } else { - current_statement__ = 1; - assign(sigma_b, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_b[(sym1__ - 1)], 0), - "assigning variable sigma_b"); - }} - local_scalar_t__ sigma_y; - sigma_y = DUMMY_VAR__; - - current_statement__ = 2; - sigma_y = in__.scalar(); - current_statement__ = 2; - if (jacobian__) { - current_statement__ = 2; - sigma_y = stan::math::lb_constrain(sigma_y, 0, lp__); - } else { - current_statement__ = 2; - sigma_y = stan::math::lb_constrain(sigma_y, 0); - } - Eigen::Matrix beta_raw; - beta_raw = Eigen::Matrix(k, n); - stan::math::fill(beta_raw, DUMMY_VAR__); - - current_statement__ = 3; - beta_raw = in__.matrix(k, n); - Eigen::Matrix beta; - beta = Eigen::Matrix(k, n); - stan::math::fill(beta, DUMMY_VAR__); - - Eigen::Matrix tmp; - tmp = Eigen::Matrix(k); - stan::math::fill(tmp, DUMMY_VAR__); - - current_statement__ = 6; - assign(beta, - cons_list(index_omni(), cons_list(index_uni(1), nil_index_list())), - add(beta_mean, - elt_multiply(beta_sd, - rvalue(beta_raw, - cons_list(index_omni(), - cons_list(index_uni(1), nil_index_list())), "beta_raw"))), - "assigning variable beta"); - current_statement__ = 10; - for (int t = 2; t <= n; ++t) { - current_statement__ = 7; - assign(tmp, nil_index_list(), - rvalue(beta, - cons_list(index_omni(), - cons_list(index_uni((t - 1)), nil_index_list())), "beta"), - "assigning variable tmp"); - current_statement__ = 8; - assign(beta, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - add(tmp, - elt_multiply(to_vector(sigma_b), - rvalue(beta_raw, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "beta_raw"))), - "assigning variable beta");} - { - current_statement__ = 11; - lp_accum__.add( - normal_lpdf(sigma_b, sigma_b_mean, sigma_b_sd)); - current_statement__ = 12; - lp_accum__.add( - normal_lpdf(sigma_y, sigma_y_mean, sigma_y_sd)); - current_statement__ = 13; - lp_accum__.add(normal_lpdf(to_vector(beta_raw), 0, 1)); - { - current_statement__ = 14; - validate_non_negative_index("mu", "n", n); - Eigen::Matrix mu; - mu = Eigen::Matrix(n); - stan::math::fill(mu, DUMMY_VAR__); - - current_statement__ = 15; - assign(mu, nil_index_list(), columns_dot_product(xreg, beta), - "assigning variable mu"); - current_statement__ = 16; - lp_accum__.add(normal_lpdf(y, mu, sigma_y)); - } - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } // log_prob_impl() - - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_std_vector_vt* = nullptr> - inline void write_array_impl(RNG& base_rng__, VecR& params_r__, - VecI& params_i__, VecVar& vars__, - const bool emit_transformed_parameters__ = true, - const bool emit_generated_quantities__ = true, - std::ostream* pstream__ = nullptr) const { - using local_scalar_t__ = double; - vars__.resize(0); - stan::io::reader in__(params_r__, params_i__); - static const char* function__ = "model_rw1_model_naive_namespace::write_array"; -(void) function__; // suppress unused var warning - (void) function__; // suppress unused var warning - double lp__ = 0.0; - (void) lp__; // dummy to suppress unused var warning - stan::math::accumulator lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - std::vector sigma_b; - sigma_b = std::vector(k, std::numeric_limits::quiet_NaN()); - - current_statement__ = 1; - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - current_statement__ = 1; - assign(sigma_b, cons_list(index_uni(sym1__), nil_index_list()), - in__.scalar(), "assigning variable sigma_b");} - current_statement__ = 1; - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - current_statement__ = 1; - assign(sigma_b, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_b[(sym1__ - 1)], 0), - "assigning variable sigma_b");} - double sigma_y; - sigma_y = std::numeric_limits::quiet_NaN(); - - current_statement__ = 2; - sigma_y = in__.scalar(); - current_statement__ = 2; - sigma_y = stan::math::lb_constrain(sigma_y, 0); - Eigen::Matrix beta_raw; - beta_raw = Eigen::Matrix(k, n); - stan::math::fill(beta_raw, std::numeric_limits::quiet_NaN()); - - current_statement__ = 3; - beta_raw = in__.matrix(k, n); - Eigen::Matrix beta; - beta = Eigen::Matrix(k, n); - stan::math::fill(beta, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix tmp; - tmp = Eigen::Matrix(k); - stan::math::fill(tmp, std::numeric_limits::quiet_NaN()); - - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - vars__.emplace_back(sigma_b[(sym1__ - 1)]);} - vars__.emplace_back(sigma_y); - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - vars__.emplace_back( - rvalue(beta_raw, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), "beta_raw")); - }} - if (logical_negation((primitive_value(emit_transformed_parameters__) || - primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 6; - assign(beta, - cons_list(index_omni(), cons_list(index_uni(1), nil_index_list())), - add(beta_mean, - elt_multiply(beta_sd, - rvalue(beta_raw, - cons_list(index_omni(), - cons_list(index_uni(1), nil_index_list())), "beta_raw"))), - "assigning variable beta"); - current_statement__ = 10; - for (int t = 2; t <= n; ++t) { - current_statement__ = 7; - assign(tmp, nil_index_list(), - rvalue(beta, - cons_list(index_omni(), - cons_list(index_uni((t - 1)), nil_index_list())), "beta"), - "assigning variable tmp"); - current_statement__ = 8; - assign(beta, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - add(tmp, - elt_multiply(to_vector(sigma_b), - rvalue(beta_raw, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "beta_raw"))), - "assigning variable beta");} - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - vars__.emplace_back( - rvalue(beta, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), "beta"));} - } - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - vars__.emplace_back(tmp[(sym1__ - 1)]);} - } - if (logical_negation(emit_generated_quantities__)) { - return ; - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - } // write_array_impl() - - template * = nullptr, stan::require_vector_like_vt* = nullptr> - inline void transform_inits_impl(const stan::io::var_context& context__, - VecI& params_i__, VecVar& vars__, - std::ostream* pstream__ = nullptr) const { - using local_scalar_t__ = double; - vars__.clear(); - vars__.reserve(num_params_r__); - - try { - int pos__; - pos__ = std::numeric_limits::min(); - - pos__ = 1; - std::vector sigma_b; - sigma_b = std::vector(k, std::numeric_limits::quiet_NaN()); - - current_statement__ = 1; - assign(sigma_b, nil_index_list(), context__.vals_r("sigma_b"), - "assigning variable sigma_b"); - std::vector sigma_b_free__; - sigma_b_free__ = std::vector(k, std::numeric_limits::quiet_NaN()); - - current_statement__ = 1; - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - current_statement__ = 1; - assign(sigma_b_free__, - cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_free(sigma_b[(sym1__ - 1)], 0), - "assigning variable sigma_b_free__");} - double sigma_y; - sigma_y = std::numeric_limits::quiet_NaN(); - - current_statement__ = 2; - sigma_y = context__.vals_r("sigma_y")[(1 - 1)]; - double sigma_y_free__; - sigma_y_free__ = std::numeric_limits::quiet_NaN(); - - current_statement__ = 2; - sigma_y_free__ = stan::math::lb_free(sigma_y, 0); - Eigen::Matrix beta_raw; - beta_raw = Eigen::Matrix(k, n); - stan::math::fill(beta_raw, std::numeric_limits::quiet_NaN()); - - { - std::vector beta_raw_flat__; - current_statement__ = 3; - assign(beta_raw_flat__, nil_index_list(), - context__.vals_r("beta_raw"), "assigning variable beta_raw_flat__"); - current_statement__ = 3; - pos__ = 1; - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 3; - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - current_statement__ = 3; - assign(beta_raw, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), - beta_raw_flat__[(pos__ - 1)], "assigning variable beta_raw"); - current_statement__ = 3; - pos__ = (pos__ + 1);}} - } - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - vars__.emplace_back(sigma_b_free__[(sym1__ - 1)]);} - vars__.emplace_back(sigma_y_free__); - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - vars__.emplace_back( - rvalue(beta_raw, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), "beta_raw")); - }} - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - } // transform_inits_impl() - - inline void get_param_names(std::vector& names__) const { - - names__.clear(); - names__.emplace_back("sigma_b"); - names__.emplace_back("sigma_y"); - names__.emplace_back("beta_raw"); - names__.emplace_back("beta"); - names__.emplace_back("tmp"); - } // get_param_names() - - inline void get_dims(std::vector>& dimss__) const { - dimss__.clear(); - dimss__.emplace_back(std::vector{static_cast(k)}); - - dimss__.emplace_back(std::vector{}); - - dimss__.emplace_back(std::vector{static_cast(k), - static_cast(n)}); - - dimss__.emplace_back(std::vector{static_cast(k), - static_cast(n)}); - - dimss__.emplace_back(std::vector{static_cast(k)}); - - } // get_dims() - - inline void constrained_param_names( - std::vector& param_names__, - bool emit_transformed_parameters__ = true, - bool emit_generated_quantities__ = true) const - final { - - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "sigma_b" + '.' + std::to_string(sym1__)); - }} - param_names__.emplace_back(std::string() + "sigma_y"); - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - { - param_names__.emplace_back(std::string() + "beta_raw" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - { - param_names__.emplace_back(std::string() + "beta" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "tmp" + '.' + std::to_string(sym1__)); - }} - } - - if (emit_generated_quantities__) { - - } - - } // constrained_param_names() - - inline void unconstrained_param_names( - std::vector& param_names__, - bool emit_transformed_parameters__ = true, - bool emit_generated_quantities__ = true) const - final { - - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "sigma_b" + '.' + std::to_string(sym1__)); - }} - param_names__.emplace_back(std::string() + "sigma_y"); - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - { - param_names__.emplace_back(std::string() + "beta_raw" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - { - param_names__.emplace_back(std::string() + "beta" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - for (int sym1__ = 1; sym1__ <= k; ++sym1__) { - { - param_names__.emplace_back(std::string() + "tmp" + '.' + std::to_string(sym1__)); - }} - } - - if (emit_generated_quantities__) { - - } - - } // unconstrained_param_names() - - inline std::string get_constrained_sizedtypes() const { - stringstream s__; - s__ << "[{\"name\":\"sigma_b\",\"type\":{\"name\":\"array\",\"length\":" << k << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"sigma_y\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta_raw\",\"type\":{\"name\":\"matrix\",\"rows\":" << k << ",\"cols\":" << n << "},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"matrix\",\"rows\":" << k << ",\"cols\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"tmp\",\"type\":{\"name\":\"vector\",\"length\":" << k << "},\"block\":\"transformed_parameters\"}]"; - return s__.str(); - } // get_constrained_sizedtypes() - - inline std::string get_unconstrained_sizedtypes() const { - stringstream s__; - s__ << "[{\"name\":\"sigma_b\",\"type\":{\"name\":\"array\",\"length\":" << k << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"sigma_y\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta_raw\",\"type\":{\"name\":\"matrix\",\"rows\":" << k << ",\"cols\":" << n << "},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"matrix\",\"rows\":" << k << ",\"cols\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"tmp\",\"type\":{\"name\":\"vector\",\"length\":" << k << "},\"block\":\"transformed_parameters\"}]"; - return s__.str(); - } // get_unconstrained_sizedtypes() - - - // Begin method overload boilerplate - template - inline void write_array(RNG& base_rng, - Eigen::Matrix& params_r, - Eigen::Matrix& vars, - const bool emit_transformed_parameters = true, - const bool emit_generated_quantities = true, - std::ostream* pstream = nullptr) const { - std::vector vars_vec(vars.size()); - std::vector params_i; - write_array_impl(base_rng, params_r, params_i, vars_vec, - emit_transformed_parameters, emit_generated_quantities, pstream); - vars.resize(vars_vec.size()); - for (int i = 0; i < vars.size(); ++i) { - vars.coeffRef(i) = vars_vec[i]; - } - } - template - inline void write_array(RNG& base_rng, std::vector& params_r, - std::vector& params_i, - std::vector& vars, - bool emit_transformed_parameters = true, - bool emit_generated_quantities = true, - std::ostream* pstream = nullptr) const { - write_array_impl(base_rng, params_r, params_i, vars, emit_transformed_parameters, emit_generated_quantities, pstream); - } - template - inline T_ log_prob(Eigen::Matrix& params_r, - std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template - inline T__ log_prob(std::vector& params_r, - std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - - inline void transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, - std::ostream* pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits_impl(context, params_i, params_r_vec, pstream); - params_r.resize(params_r_vec.size()); - for (int i = 0; i < params_r.size(); ++i) { - params_r.coeffRef(i) = params_r_vec[i]; - } - } - inline void transform_inits(const stan::io::var_context& context, - std::vector& params_i, - std::vector& vars, - std::ostream* pstream = nullptr) const final { - transform_inits_impl(context, params_i, vars, pstream); - } -}; -} -using stan_model = model_rw1_model_naive_namespace::model_rw1_model_naive; -#ifndef USING_R -// Boilerplate -stan::model::model_base& new_model( - stan::io::var_context& data_context, - unsigned int seed, - std::ostream* msg_stream) { - stan_model* m = new stan_model(data_context, seed, msg_stream); - return *m; -} -stan::math::profile_map& get_stan_profile_data() { - return model_rw1_model_naive_namespace::profiles__; -} -#endif -#endif diff --git a/src/stanExports_walker_glm.cc b/src/stanExports_walker_glm.cc deleted file mode 100644 index 0d80782..0000000 --- a/src/stanExports_walker_glm.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Generated by rstantools. Do not edit by hand. - -#include -using namespace Rcpp ; -#include "stanExports_walker_glm.h" - -RCPP_MODULE(stan_fit4walker_glm_mod) { - - - class_ >("rstantools_model_walker_glm") - - .constructor() - - - .method("call_sampler", &rstan::stan_fit ::call_sampler) - .method("param_names", &rstan::stan_fit ::param_names) - .method("param_names_oi", &rstan::stan_fit ::param_names_oi) - .method("param_fnames_oi", &rstan::stan_fit ::param_fnames_oi) - .method("param_dims", &rstan::stan_fit ::param_dims) - .method("param_dims_oi", &rstan::stan_fit ::param_dims_oi) - .method("update_param_oi", &rstan::stan_fit ::update_param_oi) - .method("param_oi_tidx", &rstan::stan_fit ::param_oi_tidx) - .method("grad_log_prob", &rstan::stan_fit ::grad_log_prob) - .method("log_prob", &rstan::stan_fit ::log_prob) - .method("unconstrain_pars", &rstan::stan_fit ::unconstrain_pars) - .method("constrain_pars", &rstan::stan_fit ::constrain_pars) - .method("num_pars_unconstrained", &rstan::stan_fit ::num_pars_unconstrained) - .method("unconstrained_param_names", &rstan::stan_fit ::unconstrained_param_names) - .method("constrained_param_names", &rstan::stan_fit ::constrained_param_names) - .method("standalone_gqs", &rstan::stan_fit ::standalone_gqs) - ; -} diff --git a/src/stanExports_walker_glm.h b/src/stanExports_walker_glm.h deleted file mode 100644 index 4c52feb..0000000 --- a/src/stanExports_walker_glm.h +++ /dev/null @@ -1,2851 +0,0 @@ -// Generated by rstantools. Do not edit by hand. - -/* - walker is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - licence is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with licence. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.26.1-1-g67504470 -#include -namespace model_walker_glm_namespace { -inline void validate_positive_index(const char* var_name, const char* expr, - int val) { - if (val < 1) { - std::stringstream msg; - msg << "Found dimension size less than one in simplex declaration" - << "; variable=" << var_name << "; dimension size expression=" << expr - << "; expression value=" << val; - std::string msg_str(msg.str()); - throw std::invalid_argument(msg_str.c_str()); - } -} -inline void validate_unit_vector_index(const char* var_name, const char* expr, - int val) { - if (val <= 1) { - std::stringstream msg; - if (val == 1) { - msg << "Found dimension size one in unit vector declaration." - << " One-dimensional unit vector is discrete" - << " but the target distribution must be continuous." - << " variable=" << var_name << "; dimension size expression=" << expr; - } else { - msg << "Found dimension size less than one in unit vector declaration" - << "; variable=" << var_name << "; dimension size expression=" << expr - << "; expression value=" << val; - } - std::string msg_str(msg.str()); - throw std::invalid_argument(msg_str.c_str()); - } -} -using std::istream; -using std::string; -using std::stringstream; -using std::vector; -using std::pow; -using stan::io::dump; -using stan::math::lgamma; -using stan::model::model_base_crtp; -using stan::model::rvalue; -using stan::model::cons_list; -using stan::model::index_uni; -using stan::model::index_max; -using stan::model::index_min; -using stan::model::index_min_max; -using stan::model::index_multi; -using stan::model::index_omni; -using stan::model::nil_index_list; -using namespace stan::math; -using stan::math::pow; -stan::math::profile_map profiles__; -static int current_statement__= 0; -static const std::vector locations_array__ = {" (found before start of program)", - " (in 'string', line 230, column 2 to column 29)", - " (in 'string', line 231, column 2 to column 33)", - " (in 'string', line 232, column 2 to column 33)", - " (in 'string', line 235, column 2 to column 42)", - " (in 'string', line 236, column 2 to column 18)", - " (in 'string', line 237, column 2 to column 15)", - " (in 'string', line 238, column 2 to column 22)", - " (in 'string', line 243, column 4 to column 31)", - " (in 'string', line 242, column 9 to line 244, column 3)", - " (in 'string', line 241, column 4 to column 36)", - " (in 'string', line 240, column 19 to line 242, column 3)", - " (in 'string', line 240, column 2 to line 244, column 3)", - " (in 'string', line 245, column 2 to column 17)", - " (in 'string', line 249, column 6 to column 52)", - " (in 'string', line 248, column 22 to line 250, column 5)", - " (in 'string', line 248, column 4 to line 250, column 5)", - " (in 'string', line 252, column 6 to column 56)", - " (in 'string', line 251, column 22 to line 253, column 5)", - " (in 'string', line 251, column 4 to line 253, column 5)", - " (in 'string', line 247, column 17 to line 254, column 3)", - " (in 'string', line 247, column 2 to line 254, column 3)", - " (in 'string', line 256, column 2 to line 257, column 55)", - " (in 'string', line 271, column 2 to column 38)", - " (in 'string', line 272, column 2 to column 37)", - " (in 'string', line 273, column 2 to column 15)", - " (in 'string', line 274, column 2 to column 33)", - " (in 'string', line 275, column 2 to column 33)", - " (in 'string', line 277, column 2 to column 48)", - " (in 'string', line 281, column 11 to column 12)", - " (in 'string', line 281, column 4 to column 22)", - " (in 'string', line 282, column 11 to column 12)", - " (in 'string', line 282, column 14 to column 15)", - " (in 'string', line 282, column 4 to column 24)", - " (in 'string', line 283, column 11 to column 16)", - " (in 'string', line 283, column 18 to column 19)", - " (in 'string', line 283, column 4 to column 26)", - " (in 'string', line 284, column 20 to column 21)", - " (in 'string', line 284, column 23 to column 24)", - " (in 'string', line 284, column 26 to column 27)", - " (in 'string', line 284, column 4 to column 29)", - " (in 'string', line 285, column 18 to column 23)", - " (in 'string', line 285, column 25 to column 26)", - " (in 'string', line 285, column 28 to column 29)", - " (in 'string', line 285, column 4 to column 31)", - " (in 'string', line 286, column 11 to column 12)", - " (in 'string', line 286, column 4 to column 37)", - " (in 'string', line 296, column 8 to column 62)", - " (in 'string', line 295, column 24 to line 297, column 7)", - " (in 'string', line 295, column 6 to line 297, column 7)", - " (in 'string', line 299, column 8 to column 70)", - " (in 'string', line 300, column 8 to column 48)", - " (in 'string', line 298, column 24 to line 301, column 7)", - " (in 'string', line 298, column 6 to line 301, column 7)", - " (in 'string', line 305, column 10 to column 86)", - " (in 'string', line 304, column 26 to line 306, column 9)", - " (in 'string', line 304, column 8 to line 306, column 9)", - " (in 'string', line 308, column 10 to column 69)", - " (in 'string', line 309, column 10 to column 82)", - " (in 'string', line 307, column 26 to line 310, column 9)", - " (in 'string', line 307, column 8 to line 310, column 9)", - " (in 'string', line 303, column 27 to line 311, column 7)", - " (in 'string', line 303, column 6 to line 311, column 7)", - " (in 'string', line 314, column 8 to column 85)", - " (in 'string', line 313, column 20 to line 315, column 7)", - " (in 'string', line 313, column 6 to line 315, column 7)", - " (in 'string', line 318, column 15 to column 16)", - " (in 'string', line 318, column 18 to column 19)", - " (in 'string', line 318, column 8 to line 319, column 29)", - " (in 'string', line 320, column 8 to column 35)", - " (in 'string', line 321, column 22 to column 53)", - " (in 'string', line 321, column 8 to column 53)", - " (in 'string', line 317, column 6 to line 322, column 7)", - " (in 'string', line 324, column 6 to column 50)", - " (in 'string', line 325, column 20 to column 64)", - " (in 'string', line 325, column 6 to column 64)", - " (in 'string', line 327, column 6 to column 37)", - " (in 'string', line 336, column 10 to column 78)", - " (in 'string', line 337, column 10 to line 338, column 45)", - " (in 'string', line 335, column 22 to line 339, column 9)", - " (in 'string', line 335, column 8 to line 339, column 9)", - " (in 'string', line 334, column 13 to line 340, column 7)", - " (in 'string', line 330, column 10 to column 78)", - " (in 'string', line 331, column 10 to line 332, column 45)", - " (in 'string', line 329, column 22 to line 333, column 9)", - " (in 'string', line 329, column 8 to line 333, column 9)", - " (in 'string', line 328, column 29 to line 334, column 7)", - " (in 'string', line 328, column 6 to line 340, column 7)", - " (in 'string', line 293, column 18 to line 341, column 5)", - " (in 'string', line 293, column 4 to line 341, column 5)", - " (in 'string', line 350, column 6 to column 16)", - " (in 'string', line 351, column 13 to column 14)", - " (in 'string', line 351, column 6 to column 30)", - " (in 'string', line 352, column 6 to column 27)", - " (in 'string', line 353, column 6 to column 48)", - " (in 'string', line 354, column 6 to column 49)", - " (in 'string', line 355, column 21 to column 57)", - " (in 'string', line 355, column 6 to column 57)", - " (in 'string', line 366, column 10 to column 77)", - " (in 'string', line 367, column 10 to column 39)", - " (in 'string', line 368, column 10 to column 50)", - " (in 'string', line 365, column 22 to line 369, column 9)", - " (in 'string', line 365, column 8 to line 369, column 9)", - " (in 'string', line 364, column 13 to line 370, column 7)", - " (in 'string', line 361, column 10 to column 84)", - " (in 'string', line 362, column 10 to column 43)", - " (in 'string', line 360, column 22 to line 363, column 9)", - " (in 'string', line 360, column 8 to line 363, column 9)", - " (in 'string', line 359, column 29 to line 364, column 7)", - " (in 'string', line 359, column 6 to line 370, column 7)", - " (in 'string', line 343, column 4 to line 371, column 5)", - " (in 'string', line 279, column 17 to line 373, column 3)", - " (in 'string', line 279, column 2 to line 373, column 3)", - " (in 'string', line 261, column 2 to column 54)", - " (in 'string', line 262, column 2 to column 53)", - " (in 'string', line 263, column 2 to column 53)", - " (in 'string', line 267, column 2 to column 38)", - " (in 'string', line 162, column 2 to column 23)", - " (in 'string', line 163, column 2 to column 21)", - " (in 'string', line 164, column 2 to column 21)", - " (in 'string', line 165, column 2 to column 17)", - " (in 'string', line 166, column 2 to column 17)", - " (in 'string', line 167, column 2 to column 17)", - " (in 'string', line 168, column 2 to column 21)", - " (in 'string', line 169, column 9 to column 10)", - " (in 'string', line 169, column 12 to column 19)", - " (in 'string', line 169, column 2 to column 32)", - " (in 'string', line 170, column 9 to column 10)", - " (in 'string', line 170, column 12 to column 13)", - " (in 'string', line 170, column 2 to column 23)", - " (in 'string', line 171, column 9 to column 10)", - " (in 'string', line 171, column 2 to column 14)", - " (in 'string', line 172, column 22 to column 23)", - " (in 'string', line 172, column 2 to column 25)", - " (in 'string', line 173, column 2 to column 23)", - " (in 'string', line 174, column 2 to column 30)", - " (in 'string', line 175, column 2 to column 21)", - " (in 'string', line 176, column 2 to column 28)", - " (in 'string', line 177, column 2 to column 21)", - " (in 'string', line 178, column 2 to column 28)", - " (in 'string', line 180, column 2 to column 32)", - " (in 'string', line 181, column 2 to column 32)", - " (in 'string', line 182, column 2 to column 31)", - " (in 'string', line 183, column 2 to column 31)", - " (in 'string', line 185, column 2 to column 24)", - " (in 'string', line 186, column 2 to column 22)", - " (in 'string', line 188, column 9 to column 10)", - " (in 'string', line 188, column 2 to column 15)", - " (in 'string', line 189, column 9 to column 10)", - " (in 'string', line 189, column 2 to column 23)", - " (in 'string', line 190, column 17 to column 18)", - " (in 'string', line 190, column 2 to column 20)", - " (in 'string', line 191, column 2 to column 19)", - " (in 'string', line 192, column 2 to column 17)", - " (in 'string', line 193, column 9 to column 14)", - " (in 'string', line 193, column 16 to column 17)", - " (in 'string', line 193, column 2 to column 29)", - " (in 'string', line 194, column 9 to column 14)", - " (in 'string', line 194, column 16 to column 17)", - " (in 'string', line 194, column 2 to column 29)", - " (in 'string', line 198, column 14 to column 42)", - " (in 'string', line 198, column 2 to column 44)", - " (in 'string', line 199, column 9 to column 10)", - " (in 'string', line 199, column 2 to column 15)", - " (in 'string', line 200, column 9 to column 10)", - " (in 'string', line 200, column 12 to column 13)", - " (in 'string', line 200, column 2 to column 42)", - " (in 'string', line 201, column 9 to column 10)", - " (in 'string', line 201, column 12 to column 13)", - " (in 'string', line 201, column 2 to column 52)", - " (in 'string', line 203, column 4 to column 15)", - " (in 'string', line 206, column 8 to column 20)", - " (in 'string', line 207, column 8 to column 24)", - " (in 'string', line 205, column 25 to line 208, column 7)", - " (in 'string', line 205, column 6 to line 208, column 7)", - " (in 'string', line 204, column 22 to line 209, column 5)", - " (in 'string', line 204, column 4 to line 209, column 5)", - " (in 'string', line 202, column 2 to line 210, column 3)", - " (in 'string', line 212, column 4 to column 67)", - " (in 'string', line 211, column 16 to line 213, column 3)", - " (in 'string', line 211, column 2 to line 213, column 3)", - " (in 'string', line 216, column 4 to column 26)", - " (in 'string', line 217, column 4 to column 29)", - " (in 'string', line 215, column 20 to line 218, column 3)", - " (in 'string', line 215, column 2 to line 218, column 3)", - " (in 'string', line 220, column 4 to column 26)", - " (in 'string', line 221, column 4 to column 29)", - " (in 'string', line 219, column 26 to line 222, column 3)", - " (in 'string', line 219, column 2 to line 222, column 3)", - " (in 'string', line 224, column 4 to column 20)", - " (in 'string', line 225, column 4 to column 23)", - " (in 'string', line 223, column 22 to line 226, column 3)", - " (in 'string', line 223, column 2 to line 226, column 3)", - " (in 'string', line 230, column 9 to column 16)", - " (in 'string', line 231, column 26 to column 31)", - " (in 'string', line 232, column 26 to column 31)", - " (in 'string', line 235, column 9 to column 10)", - " (in 'string', line 235, column 12 to column 13)", - " (in 'string', line 236, column 9 to column 10)", - " (in 'string', line 237, column 9 to column 10)", - " (in 'string', line 238, column 9 to column 10)", - " (in 'string', line 271, column 9 to column 10)", - " (in 'string', line 271, column 12 to column 28)", - " (in 'string', line 272, column 9 to column 14)", - " (in 'string', line 272, column 16 to column 32)", - " (in 'string', line 274, column 9 to column 25)", - " (in 'string', line 275, column 9 to column 25)", - " (in 'string', line 277, column 9 to column 10)", - " (in 'string', line 17, column 4 to column 23)", - " (in 'string', line 18, column 4 to column 20)", - " (in 'string', line 19, column 4 to column 21)", - " (in 'string', line 20, column 11 to column 12)", - " (in 'string', line 20, column 4 to column 64)", - " (in 'string', line 21, column 11 to column 12)", - " (in 'string', line 21, column 4 to column 21)", - " (in 'string', line 22, column 11 to column 12)", - " (in 'string', line 22, column 14 to column 15)", - " (in 'string', line 22, column 4 to column 24)", - " (in 'string', line 23, column 11 to column 12)", - " (in 'string', line 23, column 4 to column 16)", - " (in 'string', line 24, column 11 to column 12)", - " (in 'string', line 24, column 4 to column 16)", - " (in 'string', line 25, column 11 to column 12)", - " (in 'string', line 25, column 14 to column 15)", - " (in 'string', line 25, column 4 to column 19)", - " (in 'string', line 26, column 11 to column 12)", - " (in 'string', line 26, column 14 to column 17)", - " (in 'string', line 26, column 4 to column 21)", - " (in 'string', line 27, column 11 to column 12)", - " (in 'string', line 27, column 4 to column 19)", - " (in 'string', line 29, column 4 to column 30)", - " (in 'string', line 33, column 6 to column 55)", - " (in 'string', line 45, column 8 to column 19)", - " (in 'string', line 46, column 8 to column 34)", - " (in 'string', line 48, column 10 to column 30)", - " (in 'string', line 47, column 23 to line 49, column 9)", - " (in 'string', line 47, column 8 to line 49, column 9)", - " (in 'string', line 44, column 13 to line 50, column 7)", - " (in 'string', line 36, column 8 to column 57)", - " (in 'string', line 37, column 8 to column 48)", - " (in 'string', line 38, column 8 to column 36)", - " (in 'string', line 39, column 8 to column 58)", - " (in 'string', line 41, column 10 to column 30)", - " (in 'string', line 40, column 23 to line 42, column 9)", - " (in 'string', line 40, column 8 to line 42, column 9)", - " (in 'string', line 43, column 8 to column 72)", - " (in 'string', line 35, column 26 to line 44, column 7)", - " (in 'string', line 35, column 6 to line 50, column 7)", - " (in 'string', line 31, column 19 to line 51, column 5)", - " (in 'string', line 31, column 4 to line 51, column 5)", - " (in 'string', line 53, column 4 to column 33)", - " (in 'string', line 55, column 6 to column 25)", - " (in 'string', line 56, column 13 to column 14)", - " (in 'string', line 56, column 6 to column 31)", - " (in 'string', line 62, column 8 to column 26)", - " (in 'string', line 61, column 13 to line 63, column 7)", - " (in 'string', line 58, column 15 to column 16)", - " (in 'string', line 58, column 8 to column 44)", - " (in 'string', line 59, column 8 to column 30)", - " (in 'string', line 60, column 8 to column 71)", - " (in 'string', line 57, column 25 to line 61, column 7)", - " (in 'string', line 57, column 6 to line 63, column 7)", - " (in 'string', line 54, column 20 to line 64, column 5)", - " (in 'string', line 54, column 4 to line 64, column 5)", - " (in 'string', line 66, column 4 to column 17)", - " (in 'string', line 67, column 4 to column 27)", - " (in 'string', line 69, column 13 to column 14)", - " (in 'string', line 69, column 6 to column 30)", - " (in 'string', line 70, column 13 to column 14)", - " (in 'string', line 70, column 6 to column 29)", - " (in 'string', line 71, column 6 to column 41)", - " (in 'string', line 68, column 19 to line 72, column 5)", - " (in 'string', line 68, column 4 to line 72, column 5)", - " (in 'string', line 87, column 10 to column 59)", - " (in 'string', line 88, column 10 to line 90, column 44)", - " (in 'string', line 86, column 27 to line 91, column 9)", - " (in 'string', line 86, column 8 to line 91, column 9)", - " (in 'string', line 85, column 20 to line 92, column 7)", - " (in 'string', line 85, column 6 to line 92, column 7)", - " (in 'string', line 84, column 11 to line 93, column 5)", - " (in 'string', line 78, column 10 to column 59)", - " (in 'string', line 79, column 10 to line 81, column 44)", - " (in 'string', line 77, column 27 to line 82, column 9)", - " (in 'string', line 77, column 8 to line 82, column 9)", - " (in 'string', line 76, column 20 to line 83, column 7)", - " (in 'string', line 76, column 6 to line 83, column 7)", - " (in 'string', line 75, column 27 to line 84, column 5)", - " (in 'string', line 75, column 4 to line 93, column 5)", - " (in 'string', line 94, column 4 to column 18)", - " (in 'string', line 15, column 41 to line 95, column 3)", - " (in 'string', line 104, column 4 to column 23)", - " (in 'string', line 105, column 4 to column 20)", - " (in 'string', line 106, column 4 to column 21)", - " (in 'string', line 107, column 11 to column 12)", - " (in 'string', line 107, column 4 to column 21)", - " (in 'string', line 108, column 11 to column 12)", - " (in 'string', line 108, column 14 to column 15)", - " (in 'string', line 108, column 4 to column 24)", - " (in 'string', line 109, column 11 to column 12)", - " (in 'string', line 109, column 4 to column 16)", - " (in 'string', line 110, column 11 to column 12)", - " (in 'string', line 110, column 4 to column 16)", - " (in 'string', line 111, column 11 to column 12)", - " (in 'string', line 111, column 14 to column 15)", - " (in 'string', line 111, column 4 to column 19)", - " (in 'string', line 112, column 11 to column 12)", - " (in 'string', line 112, column 14 to column 17)", - " (in 'string', line 112, column 4 to column 21)", - " (in 'string', line 113, column 11 to column 12)", - " (in 'string', line 113, column 4 to column 19)", - " (in 'string', line 117, column 6 to column 55)", - " (in 'string', line 128, column 8 to column 19)", - " (in 'string', line 129, column 8 to column 34)", - " (in 'string', line 131, column 10 to column 30)", - " (in 'string', line 130, column 23 to line 132, column 9)", - " (in 'string', line 130, column 8 to line 132, column 9)", - " (in 'string', line 127, column 13 to line 133, column 7)", - " (in 'string', line 120, column 8 to column 57)", - " (in 'string', line 121, column 8 to column 48)", - " (in 'string', line 122, column 8 to column 36)", - " (in 'string', line 123, column 8 to column 58)", - " (in 'string', line 125, column 10 to column 30)", - " (in 'string', line 124, column 23 to line 126, column 9)", - " (in 'string', line 124, column 8 to line 126, column 9)", - " (in 'string', line 119, column 26 to line 127, column 7)", - " (in 'string', line 119, column 6 to line 133, column 7)", - " (in 'string', line 115, column 19 to line 134, column 5)", - " (in 'string', line 115, column 4 to line 134, column 5)", - " (in 'string', line 136, column 4 to column 36)", - " (in 'string', line 138, column 6 to column 25)", - " (in 'string', line 139, column 13 to column 14)", - " (in 'string', line 139, column 6 to column 31)", - " (in 'string', line 145, column 8 to column 27)", - " (in 'string', line 144, column 13 to line 146, column 7)", - " (in 'string', line 141, column 15 to column 16)", - " (in 'string', line 141, column 8 to column 44)", - " (in 'string', line 142, column 8 to column 30)", - " (in 'string', line 143, column 8 to column 71)", - " (in 'string', line 140, column 25 to line 144, column 7)", - " (in 'string', line 140, column 6 to line 146, column 7)", - " (in 'string', line 137, column 20 to line 147, column 5)", - " (in 'string', line 137, column 4 to line 147, column 5)", - " (in 'string', line 149, column 4 to column 17)", - " (in 'string', line 150, column 4 to column 27)", - " (in 'string', line 152, column 13 to column 14)", - " (in 'string', line 152, column 6 to column 30)", - " (in 'string', line 153, column 13 to column 14)", - " (in 'string', line 153, column 6 to column 29)", - " (in 'string', line 154, column 6 to column 41)", - " (in 'string', line 151, column 19 to line 155, column 5)", - " (in 'string', line 151, column 4 to line 155, column 5)", - " (in 'string', line 157, column 4 to column 23)", - " (in 'string', line 102, column 37 to line 158, column 3)"}; -template -Eigen::Matrix, stan::value_type_t, -stan::value_type_t, stan::value_type_t, -stan::value_type_t, stan::promote_args_t, -stan::value_type_t, stan::value_type_t, -stan::value_type_t>>, -1, -1> -glm_approx_loglik(const T0__& y_arg__, const std::vector& y_miss, - const T2__& a1_arg__, const T3__& P1_arg__, - const T4__& Ht_arg__, const T5__& Tt_arg__, - const T6__& Rt_arg__, const T7__& xreg_arg__, - const int& distribution, const std::vector& u, - const T10__& y_original_arg__, - const T11__& xbeta_fixed_arg__, std::ostream* pstream__) { - using local_scalar_t__ = stan::promote_args_t, - stan::value_type_t, - stan::value_type_t, - stan::value_type_t, - stan::value_type_t, stan::promote_args_t, - stan::value_type_t, - stan::value_type_t, - stan::value_type_t>>; - const auto& y = to_ref(y_arg__); - const auto& a1 = to_ref(a1_arg__); - const auto& P1 = to_ref(P1_arg__); - const auto& Ht = to_ref(Ht_arg__); - const auto& Tt = to_ref(Tt_arg__); - const auto& Rt = to_ref(Rt_arg__); - const auto& xreg = to_ref(xreg_arg__); - const auto& y_original = to_ref(y_original_arg__); - const auto& xbeta_fixed = to_ref(xbeta_fixed_arg__); - const static bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - int k; - k = std::numeric_limits::min(); - - current_statement__ = 208; - k = rows(xreg); - int n; - n = std::numeric_limits::min(); - - current_statement__ = 209; - n = rows(y); - int m; - m = std::numeric_limits::min(); - - current_statement__ = 210; - m = rows(a1); - current_statement__ = 211; - validate_non_negative_index("loglik", "n", n); - Eigen::Matrix loglik; - loglik = Eigen::Matrix(n, 2); - stan::math::fill(loglik, DUMMY_VAR__); - - current_statement__ = 212; - assign(loglik, nil_index_list(), - rep_matrix(stan::math::negative_infinity(), n, 2), - "assigning variable loglik"); - current_statement__ = 213; - validate_non_negative_index("x", "m", m); - Eigen::Matrix x; - x = Eigen::Matrix(m); - stan::math::fill(x, DUMMY_VAR__); - - current_statement__ = 214; - assign(x, nil_index_list(), a1, "assigning variable x"); - current_statement__ = 215; - validate_non_negative_index("P", "m", m); - current_statement__ = 216; - validate_non_negative_index("P", "m", m); - Eigen::Matrix P; - P = Eigen::Matrix(m, m); - stan::math::fill(P, DUMMY_VAR__); - - current_statement__ = 217; - assign(P, nil_index_list(), P1, "assigning variable P"); - current_statement__ = 218; - validate_non_negative_index("v", "n", n); - Eigen::Matrix v; - v = Eigen::Matrix(n); - stan::math::fill(v, DUMMY_VAR__); - - current_statement__ = 220; - validate_non_negative_index("F", "n", n); - Eigen::Matrix F; - F = Eigen::Matrix(n); - stan::math::fill(F, DUMMY_VAR__); - - current_statement__ = 222; - validate_non_negative_index("K", "m", m); - current_statement__ = 223; - validate_non_negative_index("K", "n", n); - Eigen::Matrix K; - K = Eigen::Matrix(m, n); - stan::math::fill(K, DUMMY_VAR__); - - current_statement__ = 225; - validate_non_negative_index("r", "m", m); - current_statement__ = 226; - validate_non_negative_index("r", "n + 1", (n + 1)); - Eigen::Matrix r; - r = Eigen::Matrix(m, (n + 1)); - stan::math::fill(r, DUMMY_VAR__); - - current_statement__ = 228; - validate_non_negative_index("tmpr", "m", m); - Eigen::Matrix tmpr; - tmpr = Eigen::Matrix(m); - stan::math::fill(tmpr, DUMMY_VAR__); - - local_scalar_t__ log2pi; - log2pi = DUMMY_VAR__; - - current_statement__ = 230; - log2pi = stan::math::log((2 * stan::math::pi())); - current_statement__ = 249; - for (int t = 1; t <= n; ++t) { - current_statement__ = 231; - assign(F, cons_list(index_uni(t), nil_index_list()), - (quad_form( - rvalue(P, - cons_list(index_min_max(1, k), - cons_list(index_min_max(1, k), nil_index_list())), "P"), - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg")) + - Ht[(t - 1)]), "assigning variable F"); - current_statement__ = 247; - if (logical_eq(y_miss[(t - 1)], 0)) { - current_statement__ = 238; - assign(v, cons_list(index_uni(t), nil_index_list()), - (y[(t - 1)] - - dot_product( - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg"), - head(x, k))), "assigning variable v"); - current_statement__ = 239; - assign(K, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - divide( - multiply( - rvalue(P, - cons_list(index_min_max(1, m), - cons_list(index_min_max(1, k), nil_index_list())), "P"), - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg")), - F[(t - 1)]), "assigning variable K"); - current_statement__ = 240; - assign(x, nil_index_list(), - multiply(Tt, - add(stan::model::deep_copy(x), - multiply( - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K"), - v[(t - 1)]))), "assigning variable x"); - current_statement__ = 241; - assign(P, nil_index_list(), - quad_form_sym( - subtract(stan::model::deep_copy(P), - multiply( - multiply( - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K"), - transpose( - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K"))), - F[(t - 1)])), transpose(Tt)), "assigning variable P"); - current_statement__ = 244; - for (int i = 1; i <= m; ++i) { - current_statement__ = 242; - assign(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), - (rvalue(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), "P") + - rvalue(Rt, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "Rt")), - "assigning variable P");} - current_statement__ = 245; - assign(loglik, - cons_list(index_uni(t), cons_list(index_uni(1), nil_index_list())), - (-0.5 * - ((log2pi + stan::math::log(F[(t - 1)])) + - ((v[(t - 1)] * v[(t - 1)]) / F[(t - 1)]))), - "assigning variable loglik"); - } else { - current_statement__ = 232; - assign(x, nil_index_list(), multiply(Tt, stan::model::deep_copy(x)), - "assigning variable x"); - current_statement__ = 233; - assign(P, nil_index_list(), - quad_form_sym(stan::model::deep_copy(P), transpose(Tt)), - "assigning variable P"); - current_statement__ = 236; - for (int i = 1; i <= m; ++i) { - current_statement__ = 234; - assign(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), - (rvalue(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), "P") + - rvalue(Rt, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "Rt")), - "assigning variable P");} - }} - current_statement__ = 250; - assign(r, - cons_list(index_omni(), - cons_list(index_uni((n + 1)), nil_index_list())), rep_vector(0.0, m), - "assigning variable r"); - current_statement__ = 263; - for (int tt = 1; tt <= n; ++tt) { - int t; - t = std::numeric_limits::min(); - - current_statement__ = 251; - t = ((n + 1) - tt); - current_statement__ = 252; - validate_non_negative_index("tmp", "m", m); - Eigen::Matrix tmp; - tmp = Eigen::Matrix(m); - stan::math::fill(tmp, DUMMY_VAR__); - - current_statement__ = 253; - assign(tmp, nil_index_list(), - rvalue(r, - cons_list(index_omni(), - cons_list(index_uni((t + 1)), nil_index_list())), "r"), - "assigning variable tmp"); - current_statement__ = 261; - if (logical_eq(y_miss[(t - 1)], 0)) { - current_statement__ = 256; - validate_non_negative_index("tmp2", "m", m); - Eigen::Matrix tmp2; - tmp2 = Eigen::Matrix(m); - stan::math::fill(tmp2, DUMMY_VAR__); - - current_statement__ = 257; - assign(tmp2, nil_index_list(), rep_vector(0.0, m), - "assigning variable tmp2"); - current_statement__ = 258; - assign(tmp2, cons_list(index_min_max(1, k), nil_index_list()), - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg"), - "assigning variable tmp2"); - current_statement__ = 259; - assign(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - add(divide(multiply(tmp2, v[(t - 1)]), F[(t - 1)]), - multiply( - transpose( - subtract(Tt, - multiply( - multiply(Tt, - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K")), - transpose(tmp2)))), tmp)), "assigning variable r"); - } else { - current_statement__ = 254; - assign(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - multiply(transpose(Tt), tmp), "assigning variable r"); - }} - current_statement__ = 264; - assign(tmpr, nil_index_list(), - rvalue(r, - cons_list(index_omni(), cons_list(index_uni(1), nil_index_list())), - "r"), "assigning variable tmpr"); - current_statement__ = 265; - assign(r, - cons_list(index_omni(), cons_list(index_uni(1), nil_index_list())), - add(a1, multiply(P1, tmpr)), "assigning variable r"); - current_statement__ = 272; - for (int t = 2; t <= n; ++t) { - current_statement__ = 266; - validate_non_negative_index("tmp", "m", m); - Eigen::Matrix tmp; - tmp = Eigen::Matrix(m); - stan::math::fill(tmp, DUMMY_VAR__); - - current_statement__ = 267; - assign(tmp, nil_index_list(), - rvalue(r, - cons_list(index_omni(), - cons_list(index_uni((t - 1)), nil_index_list())), "r"), - "assigning variable tmp"); - current_statement__ = 268; - validate_non_negative_index("tmp2", "m", m); - Eigen::Matrix tmp2; - tmp2 = Eigen::Matrix(m); - stan::math::fill(tmp2, DUMMY_VAR__); - - current_statement__ = 269; - assign(tmp2, nil_index_list(), - rvalue(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - "r"), "assigning variable tmp2"); - current_statement__ = 270; - assign(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - add(multiply(Tt, tmp), - elt_multiply( - rvalue(Rt, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "Rt"), tmp2)), - "assigning variable r");} - current_statement__ = 287; - if (logical_eq(distribution, 1)) { - current_statement__ = 285; - for (int t = 1; t <= n; ++t) { - current_statement__ = 283; - if (logical_eq(y_miss[(t - 1)], 0)) { - local_scalar_t__ xbeta_rw; - xbeta_rw = DUMMY_VAR__; - - current_statement__ = 280; - xbeta_rw = dot_product( - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), - "xreg"), - rvalue(r, - cons_list(index_min_max(1, k), - cons_list(index_uni(t), nil_index_list())), "r")); - current_statement__ = 281; - assign(loglik, - cons_list(index_uni(t), - cons_list(index_uni(2), nil_index_list())), - (((y_original[(t - 1)] * (xbeta_rw + xbeta_fixed[(t - 1)])) - - (u[(t - 1)] * - stan::math::exp((xbeta_rw + xbeta_fixed[(t - 1)])))) + - ((0.5 * pow((y[(t - 1)] - xbeta_rw), 2)) / Ht[(t - 1)])), - "assigning variable loglik"); - } } - } else { - current_statement__ = 278; - for (int t = 1; t <= n; ++t) { - current_statement__ = 276; - if (logical_eq(y_miss[(t - 1)], 0)) { - local_scalar_t__ xbeta_rw; - xbeta_rw = DUMMY_VAR__; - - current_statement__ = 273; - xbeta_rw = dot_product( - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), - "xreg"), - rvalue(r, - cons_list(index_min_max(1, k), - cons_list(index_uni(t), nil_index_list())), "r")); - current_statement__ = 274; - assign(loglik, - cons_list(index_uni(t), - cons_list(index_uni(2), nil_index_list())), - (((y_original[(t - 1)] * (xbeta_rw + xbeta_fixed[(t - 1)])) - - (u[(t - 1)] * - stan::math::log1p( - stan::math::exp((xbeta_rw + xbeta_fixed[(t - 1)]))))) + - ((0.5 * pow((y[(t - 1)] - xbeta_rw), 2)) / Ht[(t - 1)])), - "assigning variable loglik"); - } } - } - current_statement__ = 288; - return loglik; - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - -} -struct glm_approx_loglik_functor__ { -template -Eigen::Matrix, stan::value_type_t, -stan::value_type_t, stan::value_type_t, -stan::value_type_t, stan::promote_args_t, -stan::value_type_t, stan::value_type_t, -stan::value_type_t>>, -1, -1> -operator()(const T0__& y, const std::vector& y_miss, const T2__& a1, - const T3__& P1, const T4__& Ht, const T5__& Tt, const T6__& Rt, - const T7__& xreg, const int& distribution, - const std::vector& u, const T10__& y_original, - const T11__& xbeta_fixed, std::ostream* pstream__) const -{ -return glm_approx_loglik(y, y_miss, a1, P1, Ht, Tt, Rt, xreg, distribution, - u, y_original, xbeta_fixed, pstream__); -} -}; -template -Eigen::Matrix, stan::value_type_t, -stan::value_type_t, stan::value_type_t, -stan::value_type_t, stan::promote_args_t, -stan::value_type_t>>, -1, -1> -glm_approx_smoother(const T0__& y_arg__, const std::vector& y_miss, - const T2__& a1_arg__, const T3__& P1_arg__, - const T4__& Ht_arg__, const T5__& Tt_arg__, - const T6__& Rt_arg__, const T7__& xreg_arg__, - std::ostream* pstream__) { - using local_scalar_t__ = stan::promote_args_t, - stan::value_type_t, - stan::value_type_t, - stan::value_type_t, - stan::value_type_t, stan::promote_args_t, - stan::value_type_t>>; - const auto& y = to_ref(y_arg__); - const auto& a1 = to_ref(a1_arg__); - const auto& P1 = to_ref(P1_arg__); - const auto& Ht = to_ref(Ht_arg__); - const auto& Tt = to_ref(Tt_arg__); - const auto& Rt = to_ref(Rt_arg__); - const auto& xreg = to_ref(xreg_arg__); - const static bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - int k; - k = std::numeric_limits::min(); - - current_statement__ = 290; - k = rows(xreg); - int n; - n = std::numeric_limits::min(); - - current_statement__ = 291; - n = rows(y); - int m; - m = std::numeric_limits::min(); - - current_statement__ = 292; - m = rows(a1); - current_statement__ = 293; - validate_non_negative_index("x", "m", m); - Eigen::Matrix x; - x = Eigen::Matrix(m); - stan::math::fill(x, DUMMY_VAR__); - - current_statement__ = 294; - assign(x, nil_index_list(), a1, "assigning variable x"); - current_statement__ = 295; - validate_non_negative_index("P", "m", m); - current_statement__ = 296; - validate_non_negative_index("P", "m", m); - Eigen::Matrix P; - P = Eigen::Matrix(m, m); - stan::math::fill(P, DUMMY_VAR__); - - current_statement__ = 297; - assign(P, nil_index_list(), P1, "assigning variable P"); - current_statement__ = 298; - validate_non_negative_index("v", "n", n); - Eigen::Matrix v; - v = Eigen::Matrix(n); - stan::math::fill(v, DUMMY_VAR__); - - current_statement__ = 300; - validate_non_negative_index("F", "n", n); - Eigen::Matrix F; - F = Eigen::Matrix(n); - stan::math::fill(F, DUMMY_VAR__); - - current_statement__ = 302; - validate_non_negative_index("K", "m", m); - current_statement__ = 303; - validate_non_negative_index("K", "n", n); - Eigen::Matrix K; - K = Eigen::Matrix(m, n); - stan::math::fill(K, DUMMY_VAR__); - - current_statement__ = 305; - validate_non_negative_index("r", "m", m); - current_statement__ = 306; - validate_non_negative_index("r", "n + 1", (n + 1)); - Eigen::Matrix r; - r = Eigen::Matrix(m, (n + 1)); - stan::math::fill(r, DUMMY_VAR__); - - current_statement__ = 308; - validate_non_negative_index("tmpr", "m", m); - Eigen::Matrix tmpr; - tmpr = Eigen::Matrix(m); - stan::math::fill(tmpr, DUMMY_VAR__); - - current_statement__ = 327; - for (int t = 1; t <= n; ++t) { - current_statement__ = 310; - assign(F, cons_list(index_uni(t), nil_index_list()), - (quad_form( - rvalue(P, - cons_list(index_min_max(1, k), - cons_list(index_min_max(1, k), nil_index_list())), "P"), - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg")) + - Ht[(t - 1)]), "assigning variable F"); - current_statement__ = 325; - if (logical_eq(y_miss[(t - 1)], 0)) { - current_statement__ = 317; - assign(v, cons_list(index_uni(t), nil_index_list()), - (y[(t - 1)] - - dot_product( - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg"), - head(x, k))), "assigning variable v"); - current_statement__ = 318; - assign(K, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - divide( - multiply( - rvalue(P, - cons_list(index_min_max(1, m), - cons_list(index_min_max(1, k), nil_index_list())), "P"), - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg")), - F[(t - 1)]), "assigning variable K"); - current_statement__ = 319; - assign(x, nil_index_list(), - multiply(Tt, - add(stan::model::deep_copy(x), - multiply( - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K"), - v[(t - 1)]))), "assigning variable x"); - current_statement__ = 320; - assign(P, nil_index_list(), - quad_form_sym( - subtract(stan::model::deep_copy(P), - multiply( - multiply( - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K"), - transpose( - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K"))), - F[(t - 1)])), transpose(Tt)), "assigning variable P"); - current_statement__ = 323; - for (int i = 1; i <= m; ++i) { - current_statement__ = 321; - assign(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), - (rvalue(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), "P") + - rvalue(Rt, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "Rt")), - "assigning variable P");} - } else { - current_statement__ = 311; - assign(x, nil_index_list(), multiply(Tt, stan::model::deep_copy(x)), - "assigning variable x"); - current_statement__ = 312; - assign(P, nil_index_list(), - quad_form_sym(stan::model::deep_copy(P), transpose(Tt)), - "assigning variable P"); - current_statement__ = 315; - for (int i = 1; i <= m; ++i) { - current_statement__ = 313; - assign(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), - (rvalue(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), "P") + - rvalue(Rt, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "Rt")), - "assigning variable P");} - }} - current_statement__ = 328; - assign(r, - cons_list(index_omni(), - cons_list(index_uni((n + 1)), nil_index_list())), rep_vector(0.0, m), - "assigning variable r"); - current_statement__ = 341; - for (int tt = 1; tt <= n; ++tt) { - int t; - t = std::numeric_limits::min(); - - current_statement__ = 329; - t = ((n + 1) - tt); - current_statement__ = 330; - validate_non_negative_index("tmp", "m", m); - Eigen::Matrix tmp; - tmp = Eigen::Matrix(m); - stan::math::fill(tmp, DUMMY_VAR__); - - current_statement__ = 331; - assign(tmp, nil_index_list(), - rvalue(r, - cons_list(index_omni(), - cons_list(index_uni((t + 1)), nil_index_list())), "r"), - "assigning variable tmp"); - current_statement__ = 339; - if (logical_eq(y_miss[(t - 1)], 0)) { - current_statement__ = 334; - validate_non_negative_index("tmp2", "m", m); - Eigen::Matrix tmp2; - tmp2 = Eigen::Matrix(m); - stan::math::fill(tmp2, DUMMY_VAR__); - - current_statement__ = 335; - assign(tmp2, nil_index_list(), rep_vector(0.0, m), - "assigning variable tmp2"); - current_statement__ = 336; - assign(tmp2, cons_list(index_min_max(1, k), nil_index_list()), - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg"), - "assigning variable tmp2"); - current_statement__ = 337; - assign(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - add(divide(multiply(tmp2, v[(t - 1)]), F[(t - 1)]), - multiply( - transpose( - subtract(Tt, - multiply( - multiply(Tt, - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K")), - transpose(tmp2)))), tmp)), "assigning variable r"); - } else { - current_statement__ = 332; - assign(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - multiply(transpose(Tt), tmp), "assigning variable r"); - }} - current_statement__ = 342; - assign(tmpr, nil_index_list(), - rvalue(r, - cons_list(index_omni(), cons_list(index_uni(1), nil_index_list())), - "r"), "assigning variable tmpr"); - current_statement__ = 343; - assign(r, - cons_list(index_omni(), cons_list(index_uni(1), nil_index_list())), - add(a1, multiply(P1, tmpr)), "assigning variable r"); - current_statement__ = 350; - for (int t = 2; t <= n; ++t) { - current_statement__ = 344; - validate_non_negative_index("tmp", "m", m); - Eigen::Matrix tmp; - tmp = Eigen::Matrix(m); - stan::math::fill(tmp, DUMMY_VAR__); - - current_statement__ = 345; - assign(tmp, nil_index_list(), - rvalue(r, - cons_list(index_omni(), - cons_list(index_uni((t - 1)), nil_index_list())), "r"), - "assigning variable tmp"); - current_statement__ = 346; - validate_non_negative_index("tmp2", "m", m); - Eigen::Matrix tmp2; - tmp2 = Eigen::Matrix(m); - stan::math::fill(tmp2, DUMMY_VAR__); - - current_statement__ = 347; - assign(tmp2, nil_index_list(), - rvalue(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - "r"), "assigning variable tmp2"); - current_statement__ = 348; - assign(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - add(multiply(Tt, tmp), - elt_multiply( - rvalue(Rt, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "Rt"), tmp2)), - "assigning variable r");} - current_statement__ = 351; - return rvalue(r, - cons_list(index_min_max(1, m), - cons_list(index_min_max(1, n), nil_index_list())), "r"); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - -} -struct glm_approx_smoother_functor__ { -template -Eigen::Matrix, stan::value_type_t, -stan::value_type_t, stan::value_type_t, -stan::value_type_t, stan::promote_args_t, -stan::value_type_t>>, -1, -1> -operator()(const T0__& y, const std::vector& y_miss, const T2__& a1, - const T3__& P1, const T4__& Ht, const T5__& Tt, const T6__& Rt, - const T7__& xreg, std::ostream* pstream__) const -{ -return glm_approx_smoother(y, y_miss, a1, P1, Ht, Tt, Rt, xreg, pstream__); -} -}; -#include -class model_walker_glm final : public model_base_crtp { -private: - int k_fixed; - int k_rw1; - int k_rw2; - int m; - int k; - int n; - int n_lfo; - Eigen::Matrix xreg_fixed; - Eigen::Matrix xreg_rw; - Eigen::Matrix y; - std::vector y_miss; - double beta_fixed_mean; - double beta_fixed_sd; - double beta_rw1_mean; - double beta_rw1_sd; - double beta_rw2_mean; - double beta_rw2_sd; - double sigma_rw1_shape; - double sigma_rw2_shape; - double sigma_rw1_rate; - double sigma_rw2_rate; - double nu_mean; - double nu_sd; - Eigen::Matrix Ht; - Eigen::Matrix y_original; - std::vector u; - int distribution; - int N; - Eigen::Matrix gamma_rw1; - Eigen::Matrix gamma_rw2; - std::vector obs_idx; - Eigen::Matrix a1; - Eigen::Matrix P1; - Eigen::Matrix Tt; - int beta_rw_2dim__; - int nu_2dim__; - int y_fit_1dim__; - int y_rep_1dim__; - -public: - ~model_walker_glm() { } - - inline std::string model_name() const final { return "model_walker_glm"; } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.26.1-1-g67504470", "stancflags = "}; - } - - - model_walker_glm(stan::io::var_context& context__, - unsigned int random_seed__ = 0, - std::ostream* pstream__ = nullptr) : model_base_crtp(0) { - using local_scalar_t__ = double ; - boost::ecuyer1988 base_rng__ = - stan::services::util::create_rng(random_seed__, 0); - (void) base_rng__; // suppress unused var warning - static const char* function__ = "model_walker_glm_namespace::model_walker_glm"; - (void) function__; // suppress unused var warning - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - int pos__; - pos__ = std::numeric_limits::min(); - - pos__ = 1; - current_statement__ = 117; - context__.validate_dims("data initialization","k_fixed","int", - context__.to_vec()); - k_fixed = std::numeric_limits::min(); - - current_statement__ = 117; - k_fixed = context__.vals_i("k_fixed")[(1 - 1)]; - current_statement__ = 117; - current_statement__ = 117; - check_greater_or_equal(function__, "k_fixed", k_fixed, 0); - current_statement__ = 118; - context__.validate_dims("data initialization","k_rw1","int", - context__.to_vec()); - k_rw1 = std::numeric_limits::min(); - - current_statement__ = 118; - k_rw1 = context__.vals_i("k_rw1")[(1 - 1)]; - current_statement__ = 118; - current_statement__ = 118; - check_greater_or_equal(function__, "k_rw1", k_rw1, 0); - current_statement__ = 119; - context__.validate_dims("data initialization","k_rw2","int", - context__.to_vec()); - k_rw2 = std::numeric_limits::min(); - - current_statement__ = 119; - k_rw2 = context__.vals_i("k_rw2")[(1 - 1)]; - current_statement__ = 119; - current_statement__ = 119; - check_greater_or_equal(function__, "k_rw2", k_rw2, 0); - current_statement__ = 120; - context__.validate_dims("data initialization","m","int", - context__.to_vec()); - m = std::numeric_limits::min(); - - current_statement__ = 120; - m = context__.vals_i("m")[(1 - 1)]; - current_statement__ = 120; - current_statement__ = 120; - check_greater_or_equal(function__, "m", m, 0); - current_statement__ = 121; - context__.validate_dims("data initialization","k","int", - context__.to_vec()); - k = std::numeric_limits::min(); - - current_statement__ = 121; - k = context__.vals_i("k")[(1 - 1)]; - current_statement__ = 121; - current_statement__ = 121; - check_greater_or_equal(function__, "k", k, 0); - current_statement__ = 122; - context__.validate_dims("data initialization","n","int", - context__.to_vec()); - n = std::numeric_limits::min(); - - current_statement__ = 122; - n = context__.vals_i("n")[(1 - 1)]; - current_statement__ = 122; - current_statement__ = 122; - check_greater_or_equal(function__, "n", n, 1); - current_statement__ = 123; - context__.validate_dims("data initialization","n_lfo","int", - context__.to_vec()); - n_lfo = std::numeric_limits::min(); - - current_statement__ = 123; - n_lfo = context__.vals_i("n_lfo")[(1 - 1)]; - current_statement__ = 123; - current_statement__ = 123; - check_greater_or_equal(function__, "n_lfo", n_lfo, 1); - current_statement__ = 124; - validate_non_negative_index("xreg_fixed", "n", n); - current_statement__ = 125; - validate_non_negative_index("xreg_fixed", "k_fixed", k_fixed); - current_statement__ = 126; - context__.validate_dims("data initialization","xreg_fixed","double", - context__.to_vec(n, k_fixed)); - xreg_fixed = Eigen::Matrix(n, k_fixed); - stan::math::fill(xreg_fixed, std::numeric_limits::quiet_NaN()); - - { - std::vector xreg_fixed_flat__; - current_statement__ = 126; - assign(xreg_fixed_flat__, nil_index_list(), - context__.vals_r("xreg_fixed"), - "assigning variable xreg_fixed_flat__"); - current_statement__ = 126; - pos__ = 1; - current_statement__ = 126; - for (int sym1__ = 1; sym1__ <= k_fixed; ++sym1__) { - current_statement__ = 126; - for (int sym2__ = 1; sym2__ <= n; ++sym2__) { - current_statement__ = 126; - assign(xreg_fixed, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), - xreg_fixed_flat__[(pos__ - 1)], "assigning variable xreg_fixed"); - current_statement__ = 126; - pos__ = (pos__ + 1);}} - } - current_statement__ = 127; - validate_non_negative_index("xreg_rw", "k", k); - current_statement__ = 128; - validate_non_negative_index("xreg_rw", "n", n); - current_statement__ = 129; - context__.validate_dims("data initialization","xreg_rw","double", - context__.to_vec(k, n)); - xreg_rw = Eigen::Matrix(k, n); - stan::math::fill(xreg_rw, std::numeric_limits::quiet_NaN()); - - { - std::vector xreg_rw_flat__; - current_statement__ = 129; - assign(xreg_rw_flat__, nil_index_list(), context__.vals_r("xreg_rw"), - "assigning variable xreg_rw_flat__"); - current_statement__ = 129; - pos__ = 1; - current_statement__ = 129; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 129; - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - current_statement__ = 129; - assign(xreg_rw, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), - xreg_rw_flat__[(pos__ - 1)], "assigning variable xreg_rw"); - current_statement__ = 129; - pos__ = (pos__ + 1);}} - } - current_statement__ = 130; - validate_non_negative_index("y", "n", n); - current_statement__ = 131; - context__.validate_dims("data initialization","y","double", - context__.to_vec(n)); - y = Eigen::Matrix(n); - stan::math::fill(y, std::numeric_limits::quiet_NaN()); - - { - std::vector y_flat__; - current_statement__ = 131; - assign(y_flat__, nil_index_list(), context__.vals_r("y"), - "assigning variable y_flat__"); - current_statement__ = 131; - pos__ = 1; - current_statement__ = 131; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 131; - assign(y, cons_list(index_uni(sym1__), nil_index_list()), - y_flat__[(pos__ - 1)], "assigning variable y"); - current_statement__ = 131; - pos__ = (pos__ + 1);} - } - current_statement__ = 132; - validate_non_negative_index("y_miss", "n", n); - current_statement__ = 133; - context__.validate_dims("data initialization","y_miss","int", - context__.to_vec(n)); - y_miss = std::vector(n, std::numeric_limits::min()); - - current_statement__ = 133; - assign(y_miss, nil_index_list(), context__.vals_i("y_miss"), - "assigning variable y_miss"); - current_statement__ = 133; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 133; - current_statement__ = 133; - check_greater_or_equal(function__, "y_miss[sym1__]", - y_miss[(sym1__ - 1)], 0);} - current_statement__ = 134; - context__.validate_dims("data initialization","beta_fixed_mean", - "double",context__.to_vec()); - beta_fixed_mean = std::numeric_limits::quiet_NaN(); - - current_statement__ = 134; - beta_fixed_mean = context__.vals_r("beta_fixed_mean")[(1 - 1)]; - current_statement__ = 135; - context__.validate_dims("data initialization","beta_fixed_sd","double", - context__.to_vec()); - beta_fixed_sd = std::numeric_limits::quiet_NaN(); - - current_statement__ = 135; - beta_fixed_sd = context__.vals_r("beta_fixed_sd")[(1 - 1)]; - current_statement__ = 135; - current_statement__ = 135; - check_greater_or_equal(function__, "beta_fixed_sd", beta_fixed_sd, 0); - current_statement__ = 136; - context__.validate_dims("data initialization","beta_rw1_mean","double", - context__.to_vec()); - beta_rw1_mean = std::numeric_limits::quiet_NaN(); - - current_statement__ = 136; - beta_rw1_mean = context__.vals_r("beta_rw1_mean")[(1 - 1)]; - current_statement__ = 137; - context__.validate_dims("data initialization","beta_rw1_sd","double", - context__.to_vec()); - beta_rw1_sd = std::numeric_limits::quiet_NaN(); - - current_statement__ = 137; - beta_rw1_sd = context__.vals_r("beta_rw1_sd")[(1 - 1)]; - current_statement__ = 137; - current_statement__ = 137; - check_greater_or_equal(function__, "beta_rw1_sd", beta_rw1_sd, 0); - current_statement__ = 138; - context__.validate_dims("data initialization","beta_rw2_mean","double", - context__.to_vec()); - beta_rw2_mean = std::numeric_limits::quiet_NaN(); - - current_statement__ = 138; - beta_rw2_mean = context__.vals_r("beta_rw2_mean")[(1 - 1)]; - current_statement__ = 139; - context__.validate_dims("data initialization","beta_rw2_sd","double", - context__.to_vec()); - beta_rw2_sd = std::numeric_limits::quiet_NaN(); - - current_statement__ = 139; - beta_rw2_sd = context__.vals_r("beta_rw2_sd")[(1 - 1)]; - current_statement__ = 139; - current_statement__ = 139; - check_greater_or_equal(function__, "beta_rw2_sd", beta_rw2_sd, 0); - current_statement__ = 140; - context__.validate_dims("data initialization","sigma_rw1_shape", - "double",context__.to_vec()); - sigma_rw1_shape = std::numeric_limits::quiet_NaN(); - - current_statement__ = 140; - sigma_rw1_shape = context__.vals_r("sigma_rw1_shape")[(1 - 1)]; - current_statement__ = 140; - current_statement__ = 140; - check_greater_or_equal(function__, "sigma_rw1_shape", sigma_rw1_shape, - 0); - current_statement__ = 141; - context__.validate_dims("data initialization","sigma_rw2_shape", - "double",context__.to_vec()); - sigma_rw2_shape = std::numeric_limits::quiet_NaN(); - - current_statement__ = 141; - sigma_rw2_shape = context__.vals_r("sigma_rw2_shape")[(1 - 1)]; - current_statement__ = 141; - current_statement__ = 141; - check_greater_or_equal(function__, "sigma_rw2_shape", sigma_rw2_shape, - 0); - current_statement__ = 142; - context__.validate_dims("data initialization","sigma_rw1_rate", - "double",context__.to_vec()); - sigma_rw1_rate = std::numeric_limits::quiet_NaN(); - - current_statement__ = 142; - sigma_rw1_rate = context__.vals_r("sigma_rw1_rate")[(1 - 1)]; - current_statement__ = 142; - current_statement__ = 142; - check_greater_or_equal(function__, "sigma_rw1_rate", sigma_rw1_rate, 0); - current_statement__ = 143; - context__.validate_dims("data initialization","sigma_rw2_rate", - "double",context__.to_vec()); - sigma_rw2_rate = std::numeric_limits::quiet_NaN(); - - current_statement__ = 143; - sigma_rw2_rate = context__.vals_r("sigma_rw2_rate")[(1 - 1)]; - current_statement__ = 143; - current_statement__ = 143; - check_greater_or_equal(function__, "sigma_rw2_rate", sigma_rw2_rate, 0); - current_statement__ = 144; - context__.validate_dims("data initialization","nu_mean","double", - context__.to_vec()); - nu_mean = std::numeric_limits::quiet_NaN(); - - current_statement__ = 144; - nu_mean = context__.vals_r("nu_mean")[(1 - 1)]; - current_statement__ = 144; - current_statement__ = 144; - check_greater_or_equal(function__, "nu_mean", nu_mean, 0); - current_statement__ = 145; - context__.validate_dims("data initialization","nu_sd","double", - context__.to_vec()); - nu_sd = std::numeric_limits::quiet_NaN(); - - current_statement__ = 145; - nu_sd = context__.vals_r("nu_sd")[(1 - 1)]; - current_statement__ = 145; - current_statement__ = 145; - check_greater_or_equal(function__, "nu_sd", nu_sd, 0); - current_statement__ = 146; - validate_non_negative_index("Ht", "n", n); - current_statement__ = 147; - context__.validate_dims("data initialization","Ht","double", - context__.to_vec(n)); - Ht = Eigen::Matrix(n); - stan::math::fill(Ht, std::numeric_limits::quiet_NaN()); - - { - std::vector Ht_flat__; - current_statement__ = 147; - assign(Ht_flat__, nil_index_list(), context__.vals_r("Ht"), - "assigning variable Ht_flat__"); - current_statement__ = 147; - pos__ = 1; - current_statement__ = 147; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 147; - assign(Ht, cons_list(index_uni(sym1__), nil_index_list()), - Ht_flat__[(pos__ - 1)], "assigning variable Ht"); - current_statement__ = 147; - pos__ = (pos__ + 1);} - } - current_statement__ = 148; - validate_non_negative_index("y_original", "n", n); - current_statement__ = 149; - context__.validate_dims("data initialization","y_original","double", - context__.to_vec(n)); - y_original = Eigen::Matrix(n); - stan::math::fill(y_original, std::numeric_limits::quiet_NaN()); - - { - std::vector y_original_flat__; - current_statement__ = 149; - assign(y_original_flat__, nil_index_list(), - context__.vals_r("y_original"), - "assigning variable y_original_flat__"); - current_statement__ = 149; - pos__ = 1; - current_statement__ = 149; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 149; - assign(y_original, cons_list(index_uni(sym1__), nil_index_list()), - y_original_flat__[(pos__ - 1)], "assigning variable y_original"); - current_statement__ = 149; - pos__ = (pos__ + 1);} - } - current_statement__ = 150; - validate_non_negative_index("u", "n", n); - current_statement__ = 151; - context__.validate_dims("data initialization","u","int", - context__.to_vec(n)); - u = std::vector(n, std::numeric_limits::min()); - - current_statement__ = 151; - assign(u, nil_index_list(), context__.vals_i("u"), - "assigning variable u"); - current_statement__ = 151; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 151; - current_statement__ = 151; - check_greater_or_equal(function__, "u[sym1__]", u[(sym1__ - 1)], 0);} - current_statement__ = 152; - context__.validate_dims("data initialization","distribution","int", - context__.to_vec()); - distribution = std::numeric_limits::min(); - - current_statement__ = 152; - distribution = context__.vals_i("distribution")[(1 - 1)]; - current_statement__ = 153; - context__.validate_dims("data initialization","N","int", - context__.to_vec()); - N = std::numeric_limits::min(); - - current_statement__ = 153; - N = context__.vals_i("N")[(1 - 1)]; - current_statement__ = 153; - current_statement__ = 153; - check_greater_or_equal(function__, "N", N, 0); - current_statement__ = 154; - validate_non_negative_index("gamma_rw1", "k_rw1", k_rw1); - current_statement__ = 155; - validate_non_negative_index("gamma_rw1", "n", n); - current_statement__ = 156; - context__.validate_dims("data initialization","gamma_rw1","double", - context__.to_vec(k_rw1, n)); - gamma_rw1 = Eigen::Matrix(k_rw1, n); - stan::math::fill(gamma_rw1, std::numeric_limits::quiet_NaN()); - - { - std::vector gamma_rw1_flat__; - current_statement__ = 156; - assign(gamma_rw1_flat__, nil_index_list(), - context__.vals_r("gamma_rw1"), - "assigning variable gamma_rw1_flat__"); - current_statement__ = 156; - pos__ = 1; - current_statement__ = 156; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 156; - for (int sym2__ = 1; sym2__ <= k_rw1; ++sym2__) { - current_statement__ = 156; - assign(gamma_rw1, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), - gamma_rw1_flat__[(pos__ - 1)], "assigning variable gamma_rw1"); - current_statement__ = 156; - pos__ = (pos__ + 1);}} - } - current_statement__ = 157; - validate_non_negative_index("gamma_rw2", "k_rw2", k_rw2); - current_statement__ = 158; - validate_non_negative_index("gamma_rw2", "n", n); - current_statement__ = 159; - context__.validate_dims("data initialization","gamma_rw2","double", - context__.to_vec(k_rw2, n)); - gamma_rw2 = Eigen::Matrix(k_rw2, n); - stan::math::fill(gamma_rw2, std::numeric_limits::quiet_NaN()); - - { - std::vector gamma_rw2_flat__; - current_statement__ = 159; - assign(gamma_rw2_flat__, nil_index_list(), - context__.vals_r("gamma_rw2"), - "assigning variable gamma_rw2_flat__"); - current_statement__ = 159; - pos__ = 1; - current_statement__ = 159; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 159; - for (int sym2__ = 1; sym2__ <= k_rw2; ++sym2__) { - current_statement__ = 159; - assign(gamma_rw2, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), - gamma_rw2_flat__[(pos__ - 1)], "assigning variable gamma_rw2"); - current_statement__ = 159; - pos__ = (pos__ + 1);}} - } - current_statement__ = 160; - validate_non_negative_index("obs_idx", - "n_lfo - sum(y_miss[1 : n_lfo])", - (n_lfo - - sum( - rvalue(y_miss, - cons_list(index_min_max(1, n_lfo), - nil_index_list()), "y_miss")))); - current_statement__ = 161; - obs_idx = std::vector((n_lfo - - sum( - rvalue(y_miss, - cons_list(index_min_max(1, n_lfo), - nil_index_list()), "y_miss"))), std::numeric_limits::min()); - - current_statement__ = 162; - validate_non_negative_index("a1", "m", m); - current_statement__ = 163; - a1 = Eigen::Matrix(m); - stan::math::fill(a1, std::numeric_limits::quiet_NaN()); - - current_statement__ = 164; - validate_non_negative_index("P1", "m", m); - current_statement__ = 165; - validate_non_negative_index("P1", "m", m); - current_statement__ = 166; - P1 = Eigen::Matrix(m, m); - stan::math::fill(P1, std::numeric_limits::quiet_NaN()); - - current_statement__ = 166; - assign(P1, nil_index_list(), rep_matrix(0.0, m, m), - "assigning variable P1"); - current_statement__ = 167; - validate_non_negative_index("Tt", "m", m); - current_statement__ = 168; - validate_non_negative_index("Tt", "m", m); - current_statement__ = 169; - Tt = Eigen::Matrix(m, m); - stan::math::fill(Tt, std::numeric_limits::quiet_NaN()); - - current_statement__ = 169; - assign(Tt, nil_index_list(), diag_matrix(rep_vector(1.0, m)), - "assigning variable Tt"); - { - int ii; - ii = std::numeric_limits::min(); - - current_statement__ = 170; - ii = 0; - current_statement__ = 176; - for (int i = 1; i <= n_lfo; ++i) { - current_statement__ = 174; - if (logical_eq(y_miss[(i - 1)], 0)) { - current_statement__ = 171; - ii = (ii + 1); - current_statement__ = 172; - assign(obs_idx, cons_list(index_uni(ii), nil_index_list()), i, - "assigning variable obs_idx"); - } } - } - current_statement__ = 180; - if (logical_gt(k_rw2, 0)) { - current_statement__ = 178; - assign(Tt, - cons_list(index_min_max((k_rw1 + 1), k), - cons_list(index_min_max((k + 1), m), nil_index_list())), - diag_matrix(rep_vector(1.0, k_rw2)), "assigning variable Tt"); - } - current_statement__ = 184; - for (int i = 1; i <= k_rw1; ++i) { - current_statement__ = 181; - assign(a1, cons_list(index_uni(i), nil_index_list()), beta_rw1_mean, - "assigning variable a1"); - current_statement__ = 182; - assign(P1, - cons_list(index_uni(i), cons_list(index_uni(i), nil_index_list())), - pow(beta_rw1_sd, 2), "assigning variable P1");} - current_statement__ = 188; - for (int i = (k_rw1 + 1); i <= k; ++i) { - current_statement__ = 185; - assign(a1, cons_list(index_uni(i), nil_index_list()), beta_rw2_mean, - "assigning variable a1"); - current_statement__ = 186; - assign(P1, - cons_list(index_uni(i), cons_list(index_uni(i), nil_index_list())), - pow(beta_rw2_sd, 2), "assigning variable P1");} - current_statement__ = 192; - for (int i = (k + 1); i <= m; ++i) { - current_statement__ = 189; - assign(a1, cons_list(index_uni(i), nil_index_list()), nu_mean, - "assigning variable a1"); - current_statement__ = 190; - assign(P1, - cons_list(index_uni(i), cons_list(index_uni(i), nil_index_list())), - pow(nu_sd, 2), "assigning variable P1");} - current_statement__ = 193; - validate_non_negative_index("beta_fixed", "k_fixed", k_fixed); - current_statement__ = 194; - validate_non_negative_index("sigma_rw1", "k_rw1", k_rw1); - current_statement__ = 195; - validate_non_negative_index("sigma_rw2", "k_rw2", k_rw2); - current_statement__ = 196; - validate_non_negative_index("Rt", "m", m); - current_statement__ = 197; - validate_non_negative_index("Rt", "n", n); - current_statement__ = 198; - validate_non_negative_index("xbeta", "n", n); - current_statement__ = 199; - validate_non_negative_index("y_", "n", n); - current_statement__ = 200; - validate_non_negative_index("loglik", "n", n); - current_statement__ = 201; - validate_non_negative_index("beta_rw", "k", k); - current_statement__ = 202; - beta_rw_2dim__ = std::numeric_limits::min(); - - current_statement__ = 202; - beta_rw_2dim__ = (n * logical_eq(n_lfo, n)); - current_statement__ = 202; - validate_non_negative_index("beta_rw", "n * (n_lfo == n)", - beta_rw_2dim__); - current_statement__ = 203; - validate_non_negative_index("nu", "k_rw2", k_rw2); - current_statement__ = 204; - nu_2dim__ = std::numeric_limits::min(); - - current_statement__ = 204; - nu_2dim__ = (n * logical_eq(n_lfo, n)); - current_statement__ = 204; - validate_non_negative_index("nu", "n * (n_lfo == n)", nu_2dim__); - current_statement__ = 205; - y_fit_1dim__ = std::numeric_limits::min(); - - current_statement__ = 205; - y_fit_1dim__ = (n * logical_eq(n_lfo, n)); - current_statement__ = 205; - validate_non_negative_index("y_fit", "n * (n_lfo == n)", y_fit_1dim__); - current_statement__ = 206; - y_rep_1dim__ = std::numeric_limits::min(); - - current_statement__ = 206; - y_rep_1dim__ = (n * logical_eq(n_lfo, n)); - current_statement__ = 206; - validate_non_negative_index("y_rep", "n * (n_lfo == n)", y_rep_1dim__); - current_statement__ = 207; - validate_non_negative_index("log_lik", "n", n); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - num_params_r__ = 0U; - - try { - num_params_r__ += k_fixed; - num_params_r__ += k_rw1; - num_params_r__ += k_rw2; - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - } - template * = nullptr, stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t log_prob_impl(VecR& params_r__, - VecI& params_i__, - std::ostream* pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - static const char* function__ = "model_walker_glm_namespace::log_prob"; -(void) function__; // suppress unused var warning - stan::io::reader in__(params_r__, params_i__); - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - Eigen::Matrix beta_fixed; - beta_fixed = Eigen::Matrix(k_fixed); - stan::math::fill(beta_fixed, DUMMY_VAR__); - - current_statement__ = 1; - beta_fixed = in__.vector(k_fixed); - std::vector sigma_rw1; - sigma_rw1 = std::vector(k_rw1, DUMMY_VAR__); - - current_statement__ = 2; - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - current_statement__ = 2; - assign(sigma_rw1, cons_list(index_uni(sym1__), nil_index_list()), - in__.scalar(), "assigning variable sigma_rw1");} - current_statement__ = 2; - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - current_statement__ = 2; - if (jacobian__) { - current_statement__ = 2; - assign(sigma_rw1, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_rw1[(sym1__ - 1)], 0, lp__), - "assigning variable sigma_rw1"); - } else { - current_statement__ = 2; - assign(sigma_rw1, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_rw1[(sym1__ - 1)], 0), - "assigning variable sigma_rw1"); - }} - std::vector sigma_rw2; - sigma_rw2 = std::vector(k_rw2, DUMMY_VAR__); - - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - current_statement__ = 3; - assign(sigma_rw2, cons_list(index_uni(sym1__), nil_index_list()), - in__.scalar(), "assigning variable sigma_rw2");} - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - current_statement__ = 3; - if (jacobian__) { - current_statement__ = 3; - assign(sigma_rw2, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_rw2[(sym1__ - 1)], 0, lp__), - "assigning variable sigma_rw2"); - } else { - current_statement__ = 3; - assign(sigma_rw2, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_rw2[(sym1__ - 1)], 0), - "assigning variable sigma_rw2"); - }} - Eigen::Matrix Rt; - Rt = Eigen::Matrix(m, n); - stan::math::fill(Rt, DUMMY_VAR__); - - current_statement__ = 4; - assign(Rt, nil_index_list(), rep_matrix(0.0, m, n), - "assigning variable Rt"); - Eigen::Matrix xbeta; - xbeta = Eigen::Matrix(n); - stan::math::fill(xbeta, DUMMY_VAR__); - - Eigen::Matrix y_; - y_ = Eigen::Matrix(n); - stan::math::fill(y_, DUMMY_VAR__); - - Eigen::Matrix loglik; - loglik = Eigen::Matrix(n, 2); - stan::math::fill(loglik, DUMMY_VAR__); - - current_statement__ = 12; - if (logical_gt(k_fixed, 0)) { - current_statement__ = 10; - assign(xbeta, nil_index_list(), multiply(xreg_fixed, beta_fixed), - "assigning variable xbeta"); - } else { - current_statement__ = 8; - assign(xbeta, nil_index_list(), rep_vector(0.0, n), - "assigning variable xbeta"); - } - current_statement__ = 13; - assign(y_, nil_index_list(), subtract(y, xbeta), - "assigning variable y_"); - current_statement__ = 21; - for (int t = 1; t <= n; ++t) { - current_statement__ = 16; - for (int i = 1; i <= k_rw1; ++i) { - current_statement__ = 14; - assign(Rt, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), - pow( - (rvalue(gamma_rw1, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "gamma_rw1") * - sigma_rw1[(i - 1)]), 2), "assigning variable Rt");} - current_statement__ = 19; - for (int i = 1; i <= k_rw2; ++i) { - current_statement__ = 17; - assign(Rt, - cons_list(index_uni((k + i)), - cons_list(index_uni(t), nil_index_list())), - pow( - (rvalue(gamma_rw2, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "gamma_rw2") * - sigma_rw2[(i - 1)]), 2), "assigning variable Rt");}} - current_statement__ = 22; - assign(loglik, nil_index_list(), - glm_approx_loglik(y_, y_miss, a1, P1, Ht, Tt, Rt, xreg_rw, - distribution, u, y_original, xbeta, pstream__), - "assigning variable loglik"); - { - current_statement__ = 113; - lp_accum__.add( - normal_lpdf(beta_fixed, beta_fixed_mean, beta_fixed_sd)); - current_statement__ = 114; - lp_accum__.add( - gamma_lpdf(sigma_rw1, sigma_rw1_shape, sigma_rw1_rate)); - current_statement__ = 115; - lp_accum__.add( - gamma_lpdf(sigma_rw2, sigma_rw2_shape, sigma_rw2_rate)); - current_statement__ = 116; - lp_accum__.add( - sum( - rvalue(loglik, - cons_list(index_multi(obs_idx), - cons_list(index_min_max(1, 2), nil_index_list())), "loglik"))); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } // log_prob_impl() - - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_std_vector_vt* = nullptr> - inline void write_array_impl(RNG& base_rng__, VecR& params_r__, - VecI& params_i__, VecVar& vars__, - const bool emit_transformed_parameters__ = true, - const bool emit_generated_quantities__ = true, - std::ostream* pstream__ = nullptr) const { - using local_scalar_t__ = double; - vars__.resize(0); - stan::io::reader in__(params_r__, params_i__); - static const char* function__ = "model_walker_glm_namespace::write_array"; -(void) function__; // suppress unused var warning - (void) function__; // suppress unused var warning - double lp__ = 0.0; - (void) lp__; // dummy to suppress unused var warning - stan::math::accumulator lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - Eigen::Matrix beta_fixed; - beta_fixed = Eigen::Matrix(k_fixed); - stan::math::fill(beta_fixed, std::numeric_limits::quiet_NaN()); - - current_statement__ = 1; - beta_fixed = in__.vector(k_fixed); - std::vector sigma_rw1; - sigma_rw1 = std::vector(k_rw1, std::numeric_limits::quiet_NaN()); - - current_statement__ = 2; - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - current_statement__ = 2; - assign(sigma_rw1, cons_list(index_uni(sym1__), nil_index_list()), - in__.scalar(), "assigning variable sigma_rw1");} - current_statement__ = 2; - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - current_statement__ = 2; - assign(sigma_rw1, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_rw1[(sym1__ - 1)], 0), - "assigning variable sigma_rw1");} - std::vector sigma_rw2; - sigma_rw2 = std::vector(k_rw2, std::numeric_limits::quiet_NaN()); - - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - current_statement__ = 3; - assign(sigma_rw2, cons_list(index_uni(sym1__), nil_index_list()), - in__.scalar(), "assigning variable sigma_rw2");} - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - current_statement__ = 3; - assign(sigma_rw2, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_rw2[(sym1__ - 1)], 0), - "assigning variable sigma_rw2");} - Eigen::Matrix Rt; - Rt = Eigen::Matrix(m, n); - stan::math::fill(Rt, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix xbeta; - xbeta = Eigen::Matrix(n); - stan::math::fill(xbeta, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix y_; - y_ = Eigen::Matrix(n); - stan::math::fill(y_, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix loglik; - loglik = Eigen::Matrix(n, 2); - stan::math::fill(loglik, std::numeric_limits::quiet_NaN()); - - for (int sym1__ = 1; sym1__ <= k_fixed; ++sym1__) { - vars__.emplace_back(beta_fixed[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - vars__.emplace_back(sigma_rw1[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - vars__.emplace_back(sigma_rw2[(sym1__ - 1)]);} - if (logical_negation((primitive_value(emit_transformed_parameters__) || - primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 4; - assign(Rt, nil_index_list(), rep_matrix(0.0, m, n), - "assigning variable Rt"); - current_statement__ = 12; - if (logical_gt(k_fixed, 0)) { - current_statement__ = 10; - assign(xbeta, nil_index_list(), multiply(xreg_fixed, beta_fixed), - "assigning variable xbeta"); - } else { - current_statement__ = 8; - assign(xbeta, nil_index_list(), rep_vector(0.0, n), - "assigning variable xbeta"); - } - current_statement__ = 13; - assign(y_, nil_index_list(), subtract(y, xbeta), - "assigning variable y_"); - current_statement__ = 21; - for (int t = 1; t <= n; ++t) { - current_statement__ = 16; - for (int i = 1; i <= k_rw1; ++i) { - current_statement__ = 14; - assign(Rt, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), - pow( - (rvalue(gamma_rw1, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "gamma_rw1") * - sigma_rw1[(i - 1)]), 2), "assigning variable Rt");} - current_statement__ = 19; - for (int i = 1; i <= k_rw2; ++i) { - current_statement__ = 17; - assign(Rt, - cons_list(index_uni((k + i)), - cons_list(index_uni(t), nil_index_list())), - pow( - (rvalue(gamma_rw2, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "gamma_rw2") * - sigma_rw2[(i - 1)]), 2), "assigning variable Rt");}} - current_statement__ = 22; - assign(loglik, nil_index_list(), - glm_approx_loglik(y_, y_miss, a1, P1, Ht, Tt, Rt, xreg_rw, - distribution, u, y_original, xbeta, pstream__), - "assigning variable loglik"); - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - for (int sym2__ = 1; sym2__ <= m; ++sym2__) { - vars__.emplace_back( - rvalue(Rt, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), "Rt"));}} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - vars__.emplace_back(xbeta[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - vars__.emplace_back(y_[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { - for (int sym2__ = 1; sym2__ <= n; ++sym2__) { - vars__.emplace_back( - rvalue(loglik, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), "loglik")); - }} - } - if (logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix beta_rw; - beta_rw = Eigen::Matrix(k, beta_rw_2dim__); - stan::math::fill(beta_rw, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix nu; - nu = Eigen::Matrix(k_rw2, nu_2dim__); - stan::math::fill(nu, std::numeric_limits::quiet_NaN()); - - double weights; - weights = std::numeric_limits::quiet_NaN(); - - Eigen::Matrix y_fit; - y_fit = Eigen::Matrix(y_fit_1dim__); - stan::math::fill(y_fit, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix y_rep; - y_rep = Eigen::Matrix(y_rep_1dim__); - stan::math::fill(y_rep, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix log_lik; - log_lik = Eigen::Matrix(n); - stan::math::fill(log_lik, std::numeric_limits::quiet_NaN()); - - current_statement__ = 28; - assign(log_lik, nil_index_list(), - add( - rvalue(loglik, - cons_list(index_omni(), - cons_list(index_uni(1), nil_index_list())), "loglik"), - rvalue(loglik, - cons_list(index_omni(), - cons_list(index_uni(2), nil_index_list())), "loglik")), - "assigning variable log_lik"); - current_statement__ = 112; - if (logical_eq(n_lfo, n)) { - current_statement__ = 29; - validate_non_negative_index("y_rep_j", "n", n); - Eigen::Matrix y_rep_j; - y_rep_j = Eigen::Matrix(n); - stan::math::fill(y_rep_j, std::numeric_limits::quiet_NaN()); - - current_statement__ = 31; - validate_non_negative_index("beta_j", "k", k); - current_statement__ = 32; - validate_non_negative_index("beta_j", "n", n); - Eigen::Matrix beta_j; - beta_j = Eigen::Matrix(k, n); - stan::math::fill(beta_j, std::numeric_limits::quiet_NaN()); - - current_statement__ = 34; - validate_non_negative_index("nu_j", "k_rw2", k_rw2); - current_statement__ = 35; - validate_non_negative_index("nu_j", "n", n); - Eigen::Matrix nu_j; - nu_j = Eigen::Matrix(k_rw2, n); - stan::math::fill(nu_j, std::numeric_limits::quiet_NaN()); - - current_statement__ = 37; - validate_non_negative_index("beta_array", "k", k); - current_statement__ = 38; - validate_non_negative_index("beta_array", "n", n); - current_statement__ = 39; - validate_non_negative_index("beta_array", "N", N); - std::vector>> beta_array; - beta_array = std::vector>>(k, std::vector>(n, std::vector(N, std::numeric_limits::quiet_NaN()))); - - current_statement__ = 41; - validate_non_negative_index("nu_array", "k_rw2", k_rw2); - current_statement__ = 42; - validate_non_negative_index("nu_array", "n", n); - current_statement__ = 43; - validate_non_negative_index("nu_array", "N", N); - std::vector>> nu_array; - nu_array = std::vector>>(k_rw2, std::vector>(n, std::vector(N, std::numeric_limits::quiet_NaN()))); - - current_statement__ = 45; - validate_non_negative_index("w", "N", N); - Eigen::Matrix w; - w = Eigen::Matrix(N); - stan::math::fill(w, std::numeric_limits::quiet_NaN()); - - current_statement__ = 46; - assign(w, nil_index_list(), rep_vector(0.0, N), - "assigning variable w"); - current_statement__ = 89; - for (int j = 1; j <= N; ++j) { - current_statement__ = 49; - for (int i = 1; i <= k_rw1; ++i) { - current_statement__ = 47; - assign(beta_j, - cons_list(index_uni(i), - cons_list(index_uni(1), nil_index_list())), - normal_rng(beta_rw1_mean, beta_rw1_sd, base_rng__), - "assigning variable beta_j");} - current_statement__ = 53; - for (int i = 1; i <= k_rw2; ++i) { - current_statement__ = 50; - assign(beta_j, - cons_list(index_uni((k_rw1 + i)), - cons_list(index_uni(1), nil_index_list())), - normal_rng(beta_rw2_mean, beta_rw2_sd, base_rng__), - "assigning variable beta_j"); - current_statement__ = 51; - assign(nu_j, - cons_list(index_uni(i), - cons_list(index_uni(1), nil_index_list())), - normal_rng(nu_mean, nu_sd, base_rng__), - "assigning variable nu_j");} - current_statement__ = 62; - for (int t = 1; t <= (n - 1); ++t) { - current_statement__ = 56; - for (int i = 1; i <= k_rw1; ++i) { - current_statement__ = 54; - assign(beta_j, - cons_list(index_uni(i), - cons_list(index_uni((t + 1)), nil_index_list())), - normal_rng( - rvalue(beta_j, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "beta_j"), - (rvalue(gamma_rw1, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), - "gamma_rw1") * sigma_rw1[(i - 1)]), base_rng__), - "assigning variable beta_j");} - current_statement__ = 60; - for (int i = 1; i <= k_rw2; ++i) { - current_statement__ = 57; - assign(beta_j, - cons_list(index_uni((k_rw1 + i)), - cons_list(index_uni((t + 1)), nil_index_list())), - (rvalue(beta_j, - cons_list(index_uni((k_rw1 + i)), - cons_list(index_uni(t), nil_index_list())), "beta_j") + - rvalue(nu_j, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "nu_j")), - "assigning variable beta_j"); - current_statement__ = 58; - assign(nu_j, - cons_list(index_uni(i), - cons_list(index_uni((t + 1)), nil_index_list())), - normal_rng( - rvalue(nu_j, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "nu_j"), - (rvalue(gamma_rw2, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), - "gamma_rw2") * sigma_rw2[(i - 1)]), base_rng__), - "assigning variable nu_j");}} - current_statement__ = 65; - for (int t = 1; t <= n; ++t) { - current_statement__ = 63; - assign(y_rep_j, cons_list(index_uni(t), nil_index_list()), - normal_rng( - dot_product( - rvalue(xreg_rw, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg_rw"), - rvalue(beta_j, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "beta_j")), - stan::math::sqrt(Ht[(t - 1)]), base_rng__), - "assigning variable y_rep_j");} - { - current_statement__ = 66; - validate_non_negative_index("states", "m", m); - current_statement__ = 67; - validate_non_negative_index("states", "n", n); - Eigen::Matrix states; - states = Eigen::Matrix(m, n); - stan::math::fill(states, std::numeric_limits::quiet_NaN()); - - current_statement__ = 68; - assign(states, nil_index_list(), - glm_approx_smoother(subtract(y_, y_rep_j), y_miss, a1, P1, Ht, - Tt, Rt, xreg_rw, pstream__), "assigning variable states"); - current_statement__ = 69; - assign(beta_j, nil_index_list(), - add(stan::model::deep_copy(beta_j), - rvalue(states, - cons_list(index_min_max(1, k), - cons_list(index_min_max(1, n), nil_index_list())), - "states")), "assigning variable beta_j"); - current_statement__ = 71; - if (logical_gt(k_rw2, 0)) { - current_statement__ = 70; - assign(nu_j, nil_index_list(), - add(stan::model::deep_copy(nu_j), - rvalue(states, - cons_list(index_min_max((k + 1), m), - cons_list(index_min_max(1, n), nil_index_list())), - "states")), "assigning variable nu_j"); - } - } - current_statement__ = 73; - assign(beta_array, - cons_list(index_min_max(1, k), - cons_list(index_min_max(1, n), - cons_list(index_uni(j), nil_index_list()))), - to_array_2d(beta_j), "assigning variable beta_array"); - current_statement__ = 75; - if (logical_gt(k_rw2, 0)) { - current_statement__ = 74; - assign(nu_array, - cons_list(index_min_max(1, k_rw2), - cons_list(index_min_max(1, n), - cons_list(index_uni(j), nil_index_list()))), - to_array_2d(nu_j), "assigning variable nu_array"); - } - current_statement__ = 76; - assign(w, cons_list(index_uni(j), nil_index_list()), - -sum( - rvalue(loglik, - cons_list(index_multi(obs_idx), - cons_list(index_uni(2), nil_index_list())), "loglik")), - "assigning variable w"); - current_statement__ = 87; - if (logical_eq(distribution, 1)) { - current_statement__ = 85; - for (int t = 1; t <= n; ++t) { - double xbeta_tmp; - xbeta_tmp = std::numeric_limits::quiet_NaN(); - - current_statement__ = 82; - xbeta_tmp = (xbeta[(t - 1)] + - dot_product( - rvalue(xreg_rw, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), - "xreg_rw"), - rvalue(beta_j, - cons_list(index_min_max(1, k), - cons_list(index_uni(t), nil_index_list())), - "beta_j"))); - current_statement__ = 83; - assign(w, cons_list(index_uni(j), nil_index_list()), - (w[(j - 1)] + - (((y_original[(t - 1)] * xbeta_tmp) - - (u[(t - 1)] * stan::math::exp(xbeta_tmp))) + - ((0.5 * pow((y[(t - 1)] - xbeta_tmp), 2)) / Ht[(t - 1)]))), - "assigning variable w");} - } else { - current_statement__ = 80; - for (int t = 1; t <= n; ++t) { - double xbeta_tmp; - xbeta_tmp = std::numeric_limits::quiet_NaN(); - - current_statement__ = 77; - xbeta_tmp = (xbeta[(t - 1)] + - dot_product( - rvalue(xreg_rw, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), - "xreg_rw"), - rvalue(beta_j, - cons_list(index_min_max(1, k), - cons_list(index_uni(t), nil_index_list())), - "beta_j"))); - current_statement__ = 78; - assign(w, cons_list(index_uni(j), nil_index_list()), - (w[(j - 1)] + - (((y_original[(t - 1)] * xbeta_tmp) - - (u[(t - 1)] * - stan::math::log1p(stan::math::exp(xbeta_tmp)))) + - ((0.5 * pow((y[(t - 1)] - xbeta_tmp), 2)) / Ht[(t - 1)]))), - "assigning variable w");} - }} - { - int index; - index = std::numeric_limits::min(); - - current_statement__ = 91; - validate_non_negative_index("expw", "N", N); - Eigen::Matrix expw; - expw = Eigen::Matrix(N); - stan::math::fill(expw, std::numeric_limits::quiet_NaN()); - - current_statement__ = 92; - assign(expw, nil_index_list(), stan::math::exp(w), - "assigning variable expw"); - current_statement__ = 93; - weights = mean(expw); - current_statement__ = 94; - index = categorical_rng(divide(expw, sum(expw)), base_rng__); - current_statement__ = 95; - assign(beta_rw, nil_index_list(), - to_matrix( - rvalue(beta_array, - cons_list(index_omni(), - cons_list(index_omni(), - cons_list(index_uni(index), nil_index_list()))), - "beta_array")), "assigning variable beta_rw"); - current_statement__ = 97; - if (logical_gt(k_rw2, 0)) { - current_statement__ = 96; - assign(nu, nil_index_list(), - to_matrix( - rvalue(nu_array, - cons_list(index_omni(), - cons_list(index_omni(), - cons_list(index_uni(index), nil_index_list()))), - "nu_array")), "assigning variable nu"); - } - current_statement__ = 109; - if (logical_eq(distribution, 1)) { - current_statement__ = 107; - for (int t = 1; t <= n; ++t) { - current_statement__ = 104; - assign(y_fit, cons_list(index_uni(t), nil_index_list()), - (u[(t - 1)] * - stan::math::exp( - (xbeta[(t - 1)] + - dot_product( - rvalue(xreg_rw, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), - "xreg_rw"), - rvalue(beta_rw, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), - "beta_rw"))))), "assigning variable y_fit"); - current_statement__ = 105; - assign(y_rep, cons_list(index_uni(t), nil_index_list()), - poisson_rng(y_fit[(t - 1)], base_rng__), - "assigning variable y_rep");} - } else { - current_statement__ = 102; - for (int t = 1; t <= n; ++t) { - double tmp; - tmp = std::numeric_limits::quiet_NaN(); - - current_statement__ = 98; - tmp = stan::math::exp( - (xbeta[(t - 1)] + - dot_product( - rvalue(xreg_rw, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), - "xreg_rw"), - rvalue(beta_rw, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), - "beta_rw")))); - current_statement__ = 99; - assign(y_fit, cons_list(index_uni(t), nil_index_list()), - (tmp / (1.0 + tmp)), "assigning variable y_fit"); - current_statement__ = 100; - assign(y_rep, cons_list(index_uni(t), nil_index_list()), - binomial_rng(u[(t - 1)], y_fit[(t - 1)], base_rng__), - "assigning variable y_rep");} - } - } - } - for (int sym1__ = 1; sym1__ <= beta_rw_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - vars__.emplace_back( - rvalue(beta_rw, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), "beta_rw")); - }} - for (int sym1__ = 1; sym1__ <= nu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= k_rw2; ++sym2__) { - vars__.emplace_back( - rvalue(nu, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), "nu"));}} - vars__.emplace_back(weights); - for (int sym1__ = 1; sym1__ <= y_fit_1dim__; ++sym1__) { - vars__.emplace_back(y_fit[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= y_rep_1dim__; ++sym1__) { - vars__.emplace_back(y_rep[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - vars__.emplace_back(log_lik[(sym1__ - 1)]);} - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - } // write_array_impl() - - template * = nullptr, stan::require_vector_like_vt* = nullptr> - inline void transform_inits_impl(const stan::io::var_context& context__, - VecI& params_i__, VecVar& vars__, - std::ostream* pstream__ = nullptr) const { - using local_scalar_t__ = double; - vars__.clear(); - vars__.reserve(num_params_r__); - - try { - int pos__; - pos__ = std::numeric_limits::min(); - - pos__ = 1; - Eigen::Matrix beta_fixed; - beta_fixed = Eigen::Matrix(k_fixed); - stan::math::fill(beta_fixed, std::numeric_limits::quiet_NaN()); - - { - std::vector beta_fixed_flat__; - current_statement__ = 1; - assign(beta_fixed_flat__, nil_index_list(), - context__.vals_r("beta_fixed"), - "assigning variable beta_fixed_flat__"); - current_statement__ = 1; - pos__ = 1; - current_statement__ = 1; - for (int sym1__ = 1; sym1__ <= k_fixed; ++sym1__) { - current_statement__ = 1; - assign(beta_fixed, cons_list(index_uni(sym1__), nil_index_list()), - beta_fixed_flat__[(pos__ - 1)], "assigning variable beta_fixed"); - current_statement__ = 1; - pos__ = (pos__ + 1);} - } - std::vector sigma_rw1; - sigma_rw1 = std::vector(k_rw1, std::numeric_limits::quiet_NaN()); - - current_statement__ = 2; - assign(sigma_rw1, nil_index_list(), context__.vals_r("sigma_rw1"), - "assigning variable sigma_rw1"); - std::vector sigma_rw1_free__; - sigma_rw1_free__ = std::vector(k_rw1, std::numeric_limits::quiet_NaN()); - - current_statement__ = 2; - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - current_statement__ = 2; - assign(sigma_rw1_free__, - cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_free(sigma_rw1[(sym1__ - 1)], 0), - "assigning variable sigma_rw1_free__");} - std::vector sigma_rw2; - sigma_rw2 = std::vector(k_rw2, std::numeric_limits::quiet_NaN()); - - current_statement__ = 3; - assign(sigma_rw2, nil_index_list(), context__.vals_r("sigma_rw2"), - "assigning variable sigma_rw2"); - std::vector sigma_rw2_free__; - sigma_rw2_free__ = std::vector(k_rw2, std::numeric_limits::quiet_NaN()); - - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - current_statement__ = 3; - assign(sigma_rw2_free__, - cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_free(sigma_rw2[(sym1__ - 1)], 0), - "assigning variable sigma_rw2_free__");} - for (int sym1__ = 1; sym1__ <= k_fixed; ++sym1__) { - vars__.emplace_back(beta_fixed[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - vars__.emplace_back(sigma_rw1_free__[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - vars__.emplace_back(sigma_rw2_free__[(sym1__ - 1)]);} - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - } // transform_inits_impl() - - inline void get_param_names(std::vector& names__) const { - - names__.clear(); - names__.emplace_back("beta_fixed"); - names__.emplace_back("sigma_rw1"); - names__.emplace_back("sigma_rw2"); - names__.emplace_back("Rt"); - names__.emplace_back("xbeta"); - names__.emplace_back("y_"); - names__.emplace_back("loglik"); - names__.emplace_back("beta_rw"); - names__.emplace_back("nu"); - names__.emplace_back("weights"); - names__.emplace_back("y_fit"); - names__.emplace_back("y_rep"); - names__.emplace_back("log_lik"); - } // get_param_names() - - inline void get_dims(std::vector>& dimss__) const { - dimss__.clear(); - dimss__.emplace_back(std::vector{static_cast(k_fixed)}); - - dimss__.emplace_back(std::vector{static_cast(k_rw1)}); - - dimss__.emplace_back(std::vector{static_cast(k_rw2)}); - - dimss__.emplace_back(std::vector{static_cast(m), - static_cast(n)}); - - dimss__.emplace_back(std::vector{static_cast(n)}); - - dimss__.emplace_back(std::vector{static_cast(n)}); - - dimss__.emplace_back(std::vector{static_cast(n), - static_cast(2)}); - - dimss__.emplace_back(std::vector{static_cast(k), - static_cast(beta_rw_2dim__) - }); - - dimss__.emplace_back(std::vector{static_cast(k_rw2), - static_cast(nu_2dim__)}); - - dimss__.emplace_back(std::vector{}); - - dimss__.emplace_back(std::vector{ - static_cast(y_fit_1dim__)}); - - dimss__.emplace_back(std::vector{ - static_cast(y_rep_1dim__)}); - - dimss__.emplace_back(std::vector{static_cast(n)}); - - } // get_dims() - - inline void constrained_param_names( - std::vector& param_names__, - bool emit_transformed_parameters__ = true, - bool emit_generated_quantities__ = true) const - final { - - for (int sym1__ = 1; sym1__ <= k_fixed; ++sym1__) { - { - param_names__.emplace_back(std::string() + "beta_fixed" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - { - param_names__.emplace_back(std::string() + "sigma_rw1" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - { - param_names__.emplace_back(std::string() + "sigma_rw2" + '.' + std::to_string(sym1__)); - }} - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= m; ++sym2__) { - { - param_names__.emplace_back(std::string() + "Rt" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - param_names__.emplace_back(std::string() + "xbeta" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= n; ++sym2__) { - { - param_names__.emplace_back(std::string() + "loglik" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - } - - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= beta_rw_2dim__; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - { - param_names__.emplace_back(std::string() + "beta_rw" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - for (int sym1__ = 1; sym1__ <= nu_2dim__; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k_rw2; ++sym2__) { - { - param_names__.emplace_back(std::string() + "nu" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - param_names__.emplace_back(std::string() + "weights"); - for (int sym1__ = 1; sym1__ <= y_fit_1dim__; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_fit" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= y_rep_1dim__; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_rep" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - param_names__.emplace_back(std::string() + "log_lik" + '.' + std::to_string(sym1__)); - }} - } - - } // constrained_param_names() - - inline void unconstrained_param_names( - std::vector& param_names__, - bool emit_transformed_parameters__ = true, - bool emit_generated_quantities__ = true) const - final { - - for (int sym1__ = 1; sym1__ <= k_fixed; ++sym1__) { - { - param_names__.emplace_back(std::string() + "beta_fixed" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - { - param_names__.emplace_back(std::string() + "sigma_rw1" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - { - param_names__.emplace_back(std::string() + "sigma_rw2" + '.' + std::to_string(sym1__)); - }} - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= m; ++sym2__) { - { - param_names__.emplace_back(std::string() + "Rt" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - param_names__.emplace_back(std::string() + "xbeta" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= 2; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= n; ++sym2__) { - { - param_names__.emplace_back(std::string() + "loglik" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - } - - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= beta_rw_2dim__; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - { - param_names__.emplace_back(std::string() + "beta_rw" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - for (int sym1__ = 1; sym1__ <= nu_2dim__; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k_rw2; ++sym2__) { - { - param_names__.emplace_back(std::string() + "nu" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - param_names__.emplace_back(std::string() + "weights"); - for (int sym1__ = 1; sym1__ <= y_fit_1dim__; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_fit" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= y_rep_1dim__; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_rep" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - param_names__.emplace_back(std::string() + "log_lik" + '.' + std::to_string(sym1__)); - }} - } - - } // unconstrained_param_names() - - inline std::string get_constrained_sizedtypes() const { - stringstream s__; - s__ << "[{\"name\":\"beta_fixed\",\"type\":{\"name\":\"vector\",\"length\":" << k_fixed << "},\"block\":\"parameters\"},{\"name\":\"sigma_rw1\",\"type\":{\"name\":\"array\",\"length\":" << k_rw1 << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"sigma_rw2\",\"type\":{\"name\":\"array\",\"length\":" << k_rw2 << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"Rt\",\"type\":{\"name\":\"matrix\",\"rows\":" << m << ",\"cols\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"xbeta\",\"type\":{\"name\":\"vector\",\"length\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"y_\",\"type\":{\"name\":\"vector\",\"length\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"loglik\",\"type\":{\"name\":\"matrix\",\"rows\":" << n << ",\"cols\":" << 2 << "},\"block\":\"transformed_parameters\"},{\"name\":\"beta_rw\",\"type\":{\"name\":\"matrix\",\"rows\":" << k << ",\"cols\":" << beta_rw_2dim__ << "},\"block\":\"generated_quantities\"},{\"name\":\"nu\",\"type\":{\"name\":\"matrix\",\"rows\":" << k_rw2 << ",\"cols\":" << nu_2dim__ << "},\"block\":\"generated_quantities\"},{\"name\":\"weights\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"y_fit\",\"type\":{\"name\":\"vector\",\"length\":" << y_fit_1dim__ << "},\"block\":\"generated_quantities\"},{\"name\":\"y_rep\",\"type\":{\"name\":\"vector\",\"length\":" << y_rep_1dim__ << "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" << n << "},\"block\":\"generated_quantities\"}]"; - return s__.str(); - } // get_constrained_sizedtypes() - - inline std::string get_unconstrained_sizedtypes() const { - stringstream s__; - s__ << "[{\"name\":\"beta_fixed\",\"type\":{\"name\":\"vector\",\"length\":" << k_fixed << "},\"block\":\"parameters\"},{\"name\":\"sigma_rw1\",\"type\":{\"name\":\"array\",\"length\":" << k_rw1 << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"sigma_rw2\",\"type\":{\"name\":\"array\",\"length\":" << k_rw2 << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"Rt\",\"type\":{\"name\":\"matrix\",\"rows\":" << m << ",\"cols\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"xbeta\",\"type\":{\"name\":\"vector\",\"length\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"y_\",\"type\":{\"name\":\"vector\",\"length\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"loglik\",\"type\":{\"name\":\"matrix\",\"rows\":" << n << ",\"cols\":" << 2 << "},\"block\":\"transformed_parameters\"},{\"name\":\"beta_rw\",\"type\":{\"name\":\"matrix\",\"rows\":" << k << ",\"cols\":" << beta_rw_2dim__ << "},\"block\":\"generated_quantities\"},{\"name\":\"nu\",\"type\":{\"name\":\"matrix\",\"rows\":" << k_rw2 << ",\"cols\":" << nu_2dim__ << "},\"block\":\"generated_quantities\"},{\"name\":\"weights\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"},{\"name\":\"y_fit\",\"type\":{\"name\":\"vector\",\"length\":" << y_fit_1dim__ << "},\"block\":\"generated_quantities\"},{\"name\":\"y_rep\",\"type\":{\"name\":\"vector\",\"length\":" << y_rep_1dim__ << "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" << n << "},\"block\":\"generated_quantities\"}]"; - return s__.str(); - } // get_unconstrained_sizedtypes() - - - // Begin method overload boilerplate - template - inline void write_array(RNG& base_rng, - Eigen::Matrix& params_r, - Eigen::Matrix& vars, - const bool emit_transformed_parameters = true, - const bool emit_generated_quantities = true, - std::ostream* pstream = nullptr) const { - std::vector vars_vec(vars.size()); - std::vector params_i; - write_array_impl(base_rng, params_r, params_i, vars_vec, - emit_transformed_parameters, emit_generated_quantities, pstream); - vars.resize(vars_vec.size()); - for (int i = 0; i < vars.size(); ++i) { - vars.coeffRef(i) = vars_vec[i]; - } - } - template - inline void write_array(RNG& base_rng, std::vector& params_r, - std::vector& params_i, - std::vector& vars, - bool emit_transformed_parameters = true, - bool emit_generated_quantities = true, - std::ostream* pstream = nullptr) const { - write_array_impl(base_rng, params_r, params_i, vars, emit_transformed_parameters, emit_generated_quantities, pstream); - } - template - inline T_ log_prob(Eigen::Matrix& params_r, - std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template - inline T__ log_prob(std::vector& params_r, - std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - - inline void transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, - std::ostream* pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits_impl(context, params_i, params_r_vec, pstream); - params_r.resize(params_r_vec.size()); - for (int i = 0; i < params_r.size(); ++i) { - params_r.coeffRef(i) = params_r_vec[i]; - } - } - inline void transform_inits(const stan::io::var_context& context, - std::vector& params_i, - std::vector& vars, - std::ostream* pstream = nullptr) const final { - transform_inits_impl(context, params_i, vars, pstream); - } -}; -} -using stan_model = model_walker_glm_namespace::model_walker_glm; -#ifndef USING_R -// Boilerplate -stan::model::model_base& new_model( - stan::io::var_context& data_context, - unsigned int seed, - std::ostream* msg_stream) { - stan_model* m = new stan_model(data_context, seed, msg_stream); - return *m; -} -stan::math::profile_map& get_stan_profile_data() { - return model_walker_glm_namespace::profiles__; -} -#endif -#endif diff --git a/src/stanExports_walker_lm.cc b/src/stanExports_walker_lm.cc deleted file mode 100644 index 589964a..0000000 --- a/src/stanExports_walker_lm.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Generated by rstantools. Do not edit by hand. - -#include -using namespace Rcpp ; -#include "stanExports_walker_lm.h" - -RCPP_MODULE(stan_fit4walker_lm_mod) { - - - class_ >("rstantools_model_walker_lm") - - .constructor() - - - .method("call_sampler", &rstan::stan_fit ::call_sampler) - .method("param_names", &rstan::stan_fit ::param_names) - .method("param_names_oi", &rstan::stan_fit ::param_names_oi) - .method("param_fnames_oi", &rstan::stan_fit ::param_fnames_oi) - .method("param_dims", &rstan::stan_fit ::param_dims) - .method("param_dims_oi", &rstan::stan_fit ::param_dims_oi) - .method("update_param_oi", &rstan::stan_fit ::update_param_oi) - .method("param_oi_tidx", &rstan::stan_fit ::param_oi_tidx) - .method("grad_log_prob", &rstan::stan_fit ::grad_log_prob) - .method("log_prob", &rstan::stan_fit ::log_prob) - .method("unconstrain_pars", &rstan::stan_fit ::unconstrain_pars) - .method("constrain_pars", &rstan::stan_fit ::constrain_pars) - .method("num_pars_unconstrained", &rstan::stan_fit ::num_pars_unconstrained) - .method("unconstrained_param_names", &rstan::stan_fit ::unconstrained_param_names) - .method("constrained_param_names", &rstan::stan_fit ::constrained_param_names) - .method("standalone_gqs", &rstan::stan_fit ::standalone_gqs) - ; -} diff --git a/src/stanExports_walker_lm.h b/src/stanExports_walker_lm.h deleted file mode 100644 index b72697e..0000000 --- a/src/stanExports_walker_lm.h +++ /dev/null @@ -1,2314 +0,0 @@ -// Generated by rstantools. Do not edit by hand. - -/* - walker is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - licence is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with licence. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.26.1-1-g67504470 -#include -namespace model_walker_lm_namespace { -inline void validate_positive_index(const char* var_name, const char* expr, - int val) { - if (val < 1) { - std::stringstream msg; - msg << "Found dimension size less than one in simplex declaration" - << "; variable=" << var_name << "; dimension size expression=" << expr - << "; expression value=" << val; - std::string msg_str(msg.str()); - throw std::invalid_argument(msg_str.c_str()); - } -} -inline void validate_unit_vector_index(const char* var_name, const char* expr, - int val) { - if (val <= 1) { - std::stringstream msg; - if (val == 1) { - msg << "Found dimension size one in unit vector declaration." - << " One-dimensional unit vector is discrete" - << " but the target distribution must be continuous." - << " variable=" << var_name << "; dimension size expression=" << expr; - } else { - msg << "Found dimension size less than one in unit vector declaration" - << "; variable=" << var_name << "; dimension size expression=" << expr - << "; expression value=" << val; - } - std::string msg_str(msg.str()); - throw std::invalid_argument(msg_str.c_str()); - } -} -using std::istream; -using std::string; -using std::stringstream; -using std::vector; -using std::pow; -using stan::io::dump; -using stan::math::lgamma; -using stan::model::model_base_crtp; -using stan::model::rvalue; -using stan::model::cons_list; -using stan::model::index_uni; -using stan::model::index_max; -using stan::model::index_min; -using stan::model::index_min_max; -using stan::model::index_multi; -using stan::model::index_omni; -using stan::model::nil_index_list; -using namespace stan::math; -using stan::math::pow; -stan::math::profile_map profiles__; -static int current_statement__= 0; -static const std::vector locations_array__ = {" (found before start of program)", - " (in 'string', line 169, column 2 to column 29)", - " (in 'string', line 170, column 2 to column 33)", - " (in 'string', line 171, column 2 to column 33)", - " (in 'string', line 172, column 2 to column 24)", - " (in 'string', line 175, column 2 to column 20)", - " (in 'string', line 176, column 2 to column 42)", - " (in 'string', line 177, column 2 to column 18)", - " (in 'string', line 178, column 2 to column 15)", - " (in 'string', line 183, column 4 to column 31)", - " (in 'string', line 182, column 9 to line 184, column 3)", - " (in 'string', line 181, column 4 to column 36)", - " (in 'string', line 180, column 19 to line 182, column 3)", - " (in 'string', line 180, column 2 to line 184, column 3)", - " (in 'string', line 185, column 2 to column 17)", - " (in 'string', line 188, column 6 to column 52)", - " (in 'string', line 187, column 22 to line 189, column 5)", - " (in 'string', line 187, column 4 to line 189, column 5)", - " (in 'string', line 191, column 6 to column 56)", - " (in 'string', line 190, column 22 to line 192, column 5)", - " (in 'string', line 190, column 4 to line 192, column 5)", - " (in 'string', line 186, column 17 to line 193, column 3)", - " (in 'string', line 186, column 2 to line 193, column 3)", - " (in 'string', line 194, column 2 to column 86)", - " (in 'string', line 207, column 2 to column 33)", - " (in 'string', line 208, column 2 to column 38)", - " (in 'string', line 209, column 2 to column 37)", - " (in 'string', line 210, column 2 to column 33)", - " (in 'string', line 216, column 6 to column 61)", - " (in 'string', line 215, column 22 to line 217, column 5)", - " (in 'string', line 215, column 4 to line 217, column 5)", - " (in 'string', line 219, column 6 to column 69)", - " (in 'string', line 220, column 6 to column 44)", - " (in 'string', line 218, column 22 to line 221, column 5)", - " (in 'string', line 218, column 4 to line 221, column 5)", - " (in 'string', line 225, column 8 to column 86)", - " (in 'string', line 224, column 24 to line 226, column 7)", - " (in 'string', line 224, column 6 to line 226, column 7)", - " (in 'string', line 228, column 8 to column 67)", - " (in 'string', line 229, column 8 to column 76)", - " (in 'string', line 227, column 24 to line 230, column 7)", - " (in 'string', line 227, column 6 to line 230, column 7)", - " (in 'string', line 223, column 25 to line 231, column 5)", - " (in 'string', line 223, column 4 to line 231, column 5)", - " (in 'string', line 234, column 6 to column 91)", - " (in 'string', line 233, column 18 to line 235, column 5)", - " (in 'string', line 233, column 4 to line 235, column 5)", - " (in 'string', line 238, column 13 to column 14)", - " (in 'string', line 238, column 16 to column 17)", - " (in 'string', line 238, column 6 to line 239, column 44)", - " (in 'string', line 240, column 6 to column 34)", - " (in 'string', line 241, column 20 to column 49)", - " (in 'string', line 241, column 6 to column 49)", - " (in 'string', line 237, column 4 to line 242, column 5)", - " (in 'string', line 246, column 6 to column 68)", - " (in 'string', line 247, column 6 to column 60)", - " (in 'string', line 245, column 18 to line 248, column 5)", - " (in 'string', line 245, column 4 to line 248, column 5)", - " (in 'string', line 212, column 17 to line 249, column 3)", - " (in 'string', line 212, column 2 to line 249, column 3)", - " (in 'string', line 197, column 2 to column 54)", - " (in 'string', line 198, column 2 to column 47)", - " (in 'string', line 199, column 2 to column 53)", - " (in 'string', line 200, column 2 to column 53)", - " (in 'string', line 204, column 2 to column 34)", - " (in 'string', line 103, column 2 to column 23)", - " (in 'string', line 104, column 2 to column 21)", - " (in 'string', line 105, column 2 to column 21)", - " (in 'string', line 106, column 2 to column 17)", - " (in 'string', line 107, column 2 to column 17)", - " (in 'string', line 108, column 2 to column 17)", - " (in 'string', line 109, column 2 to column 21)", - " (in 'string', line 110, column 9 to column 10)", - " (in 'string', line 110, column 12 to column 19)", - " (in 'string', line 110, column 2 to column 32)", - " (in 'string', line 111, column 9 to column 10)", - " (in 'string', line 111, column 12 to column 13)", - " (in 'string', line 111, column 2 to column 23)", - " (in 'string', line 112, column 9 to column 10)", - " (in 'string', line 112, column 2 to column 14)", - " (in 'string', line 113, column 22 to column 23)", - " (in 'string', line 113, column 2 to column 25)", - " (in 'string', line 114, column 2 to column 30)", - " (in 'string', line 115, column 2 to column 29)", - " (in 'string', line 117, column 2 to column 23)", - " (in 'string', line 118, column 2 to column 30)", - " (in 'string', line 119, column 2 to column 21)", - " (in 'string', line 120, column 2 to column 28)", - " (in 'string', line 121, column 2 to column 21)", - " (in 'string', line 122, column 2 to column 28)", - " (in 'string', line 124, column 2 to column 32)", - " (in 'string', line 125, column 2 to column 32)", - " (in 'string', line 126, column 2 to column 31)", - " (in 'string', line 127, column 2 to column 31)", - " (in 'string', line 129, column 2 to column 24)", - " (in 'string', line 130, column 2 to column 22)", - " (in 'string', line 131, column 9 to column 10)", - " (in 'string', line 131, column 2 to column 20)", - " (in 'string', line 132, column 9 to column 14)", - " (in 'string', line 132, column 16 to column 17)", - " (in 'string', line 132, column 2 to column 29)", - " (in 'string', line 133, column 9 to column 14)", - " (in 'string', line 133, column 16 to column 17)", - " (in 'string', line 133, column 2 to column 29)", - " (in 'string', line 137, column 14 to column 42)", - " (in 'string', line 137, column 2 to column 44)", - " (in 'string', line 138, column 9 to column 10)", - " (in 'string', line 138, column 2 to column 15)", - " (in 'string', line 139, column 9 to column 10)", - " (in 'string', line 139, column 12 to column 13)", - " (in 'string', line 139, column 2 to column 42)", - " (in 'string', line 140, column 9 to column 10)", - " (in 'string', line 140, column 12 to column 13)", - " (in 'string', line 140, column 2 to column 52)", - " (in 'string', line 141, column 9 to column 10)", - " (in 'string', line 141, column 2 to column 42)", - " (in 'string', line 144, column 4 to column 15)", - " (in 'string', line 147, column 8 to column 20)", - " (in 'string', line 148, column 8 to column 24)", - " (in 'string', line 146, column 25 to line 149, column 7)", - " (in 'string', line 146, column 6 to line 149, column 7)", - " (in 'string', line 145, column 22 to line 150, column 5)", - " (in 'string', line 145, column 4 to line 150, column 5)", - " (in 'string', line 143, column 2 to line 151, column 3)", - " (in 'string', line 153, column 4 to column 67)", - " (in 'string', line 152, column 16 to line 154, column 3)", - " (in 'string', line 152, column 2 to line 154, column 3)", - " (in 'string', line 156, column 4 to column 26)", - " (in 'string', line 157, column 4 to column 29)", - " (in 'string', line 155, column 20 to line 158, column 3)", - " (in 'string', line 155, column 2 to line 158, column 3)", - " (in 'string', line 160, column 4 to column 26)", - " (in 'string', line 161, column 4 to column 29)", - " (in 'string', line 159, column 26 to line 162, column 3)", - " (in 'string', line 159, column 2 to line 162, column 3)", - " (in 'string', line 164, column 4 to column 20)", - " (in 'string', line 165, column 4 to column 23)", - " (in 'string', line 163, column 22 to line 166, column 3)", - " (in 'string', line 163, column 2 to line 166, column 3)", - " (in 'string', line 169, column 9 to column 16)", - " (in 'string', line 170, column 26 to column 31)", - " (in 'string', line 171, column 26 to column 31)", - " (in 'string', line 175, column 9 to column 10)", - " (in 'string', line 176, column 9 to column 10)", - " (in 'string', line 176, column 12 to column 13)", - " (in 'string', line 177, column 9 to column 10)", - " (in 'string', line 178, column 9 to column 10)", - " (in 'string', line 207, column 9 to column 25)", - " (in 'string', line 208, column 9 to column 10)", - " (in 'string', line 208, column 12 to column 28)", - " (in 'string', line 209, column 9 to column 14)", - " (in 'string', line 209, column 16 to column 32)", - " (in 'string', line 210, column 9 to column 25)", - " (in 'string', line 9, column 4 to column 23)", - " (in 'string', line 10, column 4 to column 20)", - " (in 'string', line 11, column 4 to column 21)", - " (in 'string', line 12, column 11 to column 12)", - " (in 'string', line 12, column 4 to column 58)", - " (in 'string', line 14, column 11 to column 12)", - " (in 'string', line 14, column 4 to column 21)", - " (in 'string', line 15, column 11 to column 12)", - " (in 'string', line 15, column 14 to column 15)", - " (in 'string', line 15, column 4 to column 24)", - " (in 'string', line 17, column 4 to column 30)", - " (in 'string', line 20, column 6 to column 68)", - " (in 'string', line 32, column 8 to column 19)", - " (in 'string', line 33, column 8 to column 34)", - " (in 'string', line 35, column 10 to column 30)", - " (in 'string', line 34, column 23 to line 36, column 9)", - " (in 'string', line 34, column 8 to line 36, column 9)", - " (in 'string', line 31, column 13 to line 37, column 7)", - " (in 'string', line 23, column 8 to column 59)", - " (in 'string', line 24, column 15 to column 16)", - " (in 'string', line 24, column 8 to column 50)", - " (in 'string', line 25, column 8 to column 29)", - " (in 'string', line 26, column 8 to column 47)", - " (in 'string', line 28, column 10 to column 30)", - " (in 'string', line 27, column 23 to line 29, column 9)", - " (in 'string', line 27, column 8 to line 29, column 9)", - " (in 'string', line 30, column 8 to column 57)", - " (in 'string', line 22, column 26 to line 31, column 7)", - " (in 'string', line 22, column 6 to line 37, column 7)", - " (in 'string', line 19, column 19 to line 38, column 5)", - " (in 'string', line 19, column 4 to line 38, column 5)", - " (in 'string', line 39, column 4 to column 18)", - " (in 'string', line 7, column 54 to line 41, column 3)", - " (in 'string', line 46, column 4 to column 23)", - " (in 'string', line 47, column 4 to column 20)", - " (in 'string', line 48, column 4 to column 21)", - " (in 'string', line 49, column 11 to column 12)", - " (in 'string', line 49, column 4 to column 21)", - " (in 'string', line 50, column 11 to column 12)", - " (in 'string', line 50, column 14 to column 15)", - " (in 'string', line 50, column 4 to column 24)", - " (in 'string', line 51, column 11 to column 12)", - " (in 'string', line 51, column 4 to column 16)", - " (in 'string', line 52, column 11 to column 12)", - " (in 'string', line 52, column 4 to column 16)", - " (in 'string', line 53, column 11 to column 12)", - " (in 'string', line 53, column 14 to column 15)", - " (in 'string', line 53, column 4 to column 19)", - " (in 'string', line 54, column 11 to column 12)", - " (in 'string', line 54, column 14 to column 19)", - " (in 'string', line 54, column 4 to column 23)", - " (in 'string', line 55, column 11 to column 12)", - " (in 'string', line 55, column 4 to column 19)", - " (in 'string', line 59, column 6 to column 66)", - " (in 'string', line 70, column 8 to column 19)", - " (in 'string', line 71, column 8 to column 34)", - " (in 'string', line 73, column 10 to column 30)", - " (in 'string', line 72, column 23 to line 74, column 9)", - " (in 'string', line 72, column 8 to line 74, column 9)", - " (in 'string', line 69, column 13 to line 75, column 7)", - " (in 'string', line 62, column 8 to column 57)", - " (in 'string', line 63, column 8 to column 48)", - " (in 'string', line 64, column 8 to column 36)", - " (in 'string', line 65, column 8 to column 58)", - " (in 'string', line 67, column 10 to column 30)", - " (in 'string', line 66, column 23 to line 68, column 9)", - " (in 'string', line 66, column 8 to line 68, column 9)", - " (in 'string', line 61, column 44 to line 69, column 7)", - " (in 'string', line 61, column 6 to line 75, column 7)", - " (in 'string', line 57, column 19 to line 76, column 5)", - " (in 'string', line 57, column 4 to line 76, column 5)", - " (in 'string', line 78, column 4 to column 33)", - " (in 'string', line 80, column 6 to column 25)", - " (in 'string', line 81, column 13 to column 14)", - " (in 'string', line 81, column 6 to column 31)", - " (in 'string', line 87, column 8 to column 26)", - " (in 'string', line 86, column 13 to line 88, column 7)", - " (in 'string', line 83, column 15 to column 16)", - " (in 'string', line 83, column 8 to column 44)", - " (in 'string', line 84, column 8 to column 30)", - " (in 'string', line 85, column 8 to column 71)", - " (in 'string', line 82, column 43 to line 86, column 7)", - " (in 'string', line 82, column 6 to line 88, column 7)", - " (in 'string', line 79, column 20 to line 89, column 5)", - " (in 'string', line 79, column 4 to line 89, column 5)", - " (in 'string', line 91, column 4 to column 17)", - " (in 'string', line 92, column 4 to column 27)", - " (in 'string', line 94, column 13 to column 14)", - " (in 'string', line 94, column 6 to column 30)", - " (in 'string', line 95, column 13 to column 14)", - " (in 'string', line 95, column 6 to column 29)", - " (in 'string', line 96, column 6 to column 41)", - " (in 'string', line 93, column 19 to line 97, column 5)", - " (in 'string', line 93, column 4 to line 97, column 5)", - " (in 'string', line 98, column 4 to column 23)", - " (in 'string', line 44, column 53 to line 99, column 3)"}; -template -Eigen::Matrix, stan::value_type_t, -stan::value_type_t, T4__, -stan::value_type_t, stan::promote_args_t, -stan::value_type_t, -stan::value_type_t>>, -1, 1> -gaussian_filter(const T0__& y_arg__, const std::vector& y_miss, - const T2__& a1_arg__, const T3__& P1_arg__, const T4__& Ht, - const T5__& Tt_arg__, const T6__& Rt_arg__, - const T7__& xreg_arg__, const T8__& gamma2_y_arg__, - std::ostream* pstream__) { - using local_scalar_t__ = stan::promote_args_t, - stan::value_type_t, - stan::value_type_t, - T4__, - stan::value_type_t, stan::promote_args_t, - stan::value_type_t, - stan::value_type_t>>; - const auto& y = to_ref(y_arg__); - const auto& a1 = to_ref(a1_arg__); - const auto& P1 = to_ref(P1_arg__); - const auto& Tt = to_ref(Tt_arg__); - const auto& Rt = to_ref(Rt_arg__); - const auto& xreg = to_ref(xreg_arg__); - const auto& gamma2_y = to_ref(gamma2_y_arg__); - const static bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - int k; - k = std::numeric_limits::min(); - - current_statement__ = 153; - k = rows(xreg); - int n; - n = std::numeric_limits::min(); - - current_statement__ = 154; - n = rows(y); - int m; - m = std::numeric_limits::min(); - - current_statement__ = 155; - m = rows(a1); - current_statement__ = 156; - validate_non_negative_index("loglik", "n", n); - Eigen::Matrix loglik; - loglik = Eigen::Matrix(n); - stan::math::fill(loglik, DUMMY_VAR__); - - current_statement__ = 157; - assign(loglik, nil_index_list(), - rep_vector(stan::math::negative_infinity(), n), - "assigning variable loglik"); - current_statement__ = 158; - validate_non_negative_index("x", "m", m); - Eigen::Matrix x; - x = Eigen::Matrix(m); - stan::math::fill(x, DUMMY_VAR__); - - current_statement__ = 159; - assign(x, nil_index_list(), a1, "assigning variable x"); - current_statement__ = 160; - validate_non_negative_index("P", "m", m); - current_statement__ = 161; - validate_non_negative_index("P", "m", m); - Eigen::Matrix P; - P = Eigen::Matrix(m, m); - stan::math::fill(P, DUMMY_VAR__); - - current_statement__ = 162; - assign(P, nil_index_list(), P1, "assigning variable P"); - local_scalar_t__ log2pi; - log2pi = DUMMY_VAR__; - - current_statement__ = 163; - log2pi = stan::math::log((2 * stan::math::pi())); - current_statement__ = 183; - for (int t = 1; t <= n; ++t) { - local_scalar_t__ F; - F = DUMMY_VAR__; - - current_statement__ = 164; - F = (quad_form( - rvalue(P, - cons_list(index_min_max(1, k), - cons_list(index_min_max(1, k), nil_index_list())), "P"), - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg")) + - (gamma2_y[(t - 1)] * Ht)); - current_statement__ = 181; - if (logical_eq(y_miss[(t - 1)], 0)) { - local_scalar_t__ v; - v = DUMMY_VAR__; - - current_statement__ = 171; - v = (y[(t - 1)] - - dot_product( - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg"), - head(x, k))); - current_statement__ = 172; - validate_non_negative_index("K", "m", m); - Eigen::Matrix K; - K = Eigen::Matrix(m); - stan::math::fill(K, DUMMY_VAR__); - - current_statement__ = 173; - assign(K, nil_index_list(), - divide( - multiply( - rvalue(P, - cons_list(index_min_max(1, m), - cons_list(index_min_max(1, k), nil_index_list())), "P"), - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg")), F), - "assigning variable K"); - current_statement__ = 174; - assign(x, nil_index_list(), - multiply(Tt, add(stan::model::deep_copy(x), multiply(K, v))), - "assigning variable x"); - current_statement__ = 175; - assign(P, nil_index_list(), - quad_form_sym( - subtract(stan::model::deep_copy(P), - multiply(multiply(K, transpose(K)), F)), transpose(Tt)), - "assigning variable P"); - current_statement__ = 178; - for (int i = 1; i <= m; ++i) { - current_statement__ = 176; - assign(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), - (rvalue(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), "P") + - rvalue(Rt, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "Rt")), - "assigning variable P");} - current_statement__ = 179; - assign(loglik, cons_list(index_uni(t), nil_index_list()), - (-0.5 * ((log2pi + stan::math::log(F)) + ((v * v) / F))), - "assigning variable loglik"); - } else { - current_statement__ = 165; - assign(x, nil_index_list(), multiply(Tt, stan::model::deep_copy(x)), - "assigning variable x"); - current_statement__ = 166; - assign(P, nil_index_list(), - quad_form_sym(stan::model::deep_copy(P), transpose(Tt)), - "assigning variable P"); - current_statement__ = 169; - for (int i = 1; i <= m; ++i) { - current_statement__ = 167; - assign(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), - (rvalue(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), "P") + - rvalue(Rt, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "Rt")), - "assigning variable P");} - }} - current_statement__ = 184; - return loglik; - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - -} -struct gaussian_filter_functor__ { -template -Eigen::Matrix, stan::value_type_t, -stan::value_type_t, T4__, -stan::value_type_t, stan::promote_args_t, -stan::value_type_t, -stan::value_type_t>>, -1, 1> -operator()(const T0__& y, const std::vector& y_miss, const T2__& a1, - const T3__& P1, const T4__& Ht, const T5__& Tt, const T6__& Rt, - const T7__& xreg, const T8__& gamma2_y, std::ostream* pstream__) const -{ -return gaussian_filter(y, y_miss, a1, P1, Ht, Tt, Rt, xreg, gamma2_y, - pstream__); -} -}; -template -Eigen::Matrix, stan::value_type_t, -stan::value_type_t, T4__, -stan::value_type_t, stan::promote_args_t, -stan::value_type_t, -stan::value_type_t>>, -1, -1> -gaussian_smoother(const T0__& y_arg__, const std::vector& y_miss, - const T2__& a1_arg__, const T3__& P1_arg__, const T4__& Ht, - const T5__& Tt_arg__, const T6__& Rt_arg__, - const T7__& xreg_arg__, const T8__& gamma2_y_arg__, - std::ostream* pstream__) { - using local_scalar_t__ = stan::promote_args_t, - stan::value_type_t, - stan::value_type_t, - T4__, - stan::value_type_t, stan::promote_args_t, - stan::value_type_t, - stan::value_type_t>>; - const auto& y = to_ref(y_arg__); - const auto& a1 = to_ref(a1_arg__); - const auto& P1 = to_ref(P1_arg__); - const auto& Tt = to_ref(Tt_arg__); - const auto& Rt = to_ref(Rt_arg__); - const auto& xreg = to_ref(xreg_arg__); - const auto& gamma2_y = to_ref(gamma2_y_arg__); - const static bool propto__ = true; - (void) propto__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - int k; - k = std::numeric_limits::min(); - - current_statement__ = 186; - k = rows(xreg); - int n; - n = std::numeric_limits::min(); - - current_statement__ = 187; - n = rows(y); - int m; - m = std::numeric_limits::min(); - - current_statement__ = 188; - m = rows(a1); - current_statement__ = 189; - validate_non_negative_index("x", "m", m); - Eigen::Matrix x; - x = Eigen::Matrix(m); - stan::math::fill(x, DUMMY_VAR__); - - current_statement__ = 190; - assign(x, nil_index_list(), a1, "assigning variable x"); - current_statement__ = 191; - validate_non_negative_index("P", "m", m); - current_statement__ = 192; - validate_non_negative_index("P", "m", m); - Eigen::Matrix P; - P = Eigen::Matrix(m, m); - stan::math::fill(P, DUMMY_VAR__); - - current_statement__ = 193; - assign(P, nil_index_list(), P1, "assigning variable P"); - current_statement__ = 194; - validate_non_negative_index("v", "n", n); - Eigen::Matrix v; - v = Eigen::Matrix(n); - stan::math::fill(v, DUMMY_VAR__); - - current_statement__ = 196; - validate_non_negative_index("F", "n", n); - Eigen::Matrix F; - F = Eigen::Matrix(n); - stan::math::fill(F, DUMMY_VAR__); - - current_statement__ = 198; - validate_non_negative_index("K", "m", m); - current_statement__ = 199; - validate_non_negative_index("K", "n", n); - Eigen::Matrix K; - K = Eigen::Matrix(m, n); - stan::math::fill(K, DUMMY_VAR__); - - current_statement__ = 201; - validate_non_negative_index("r", "m", m); - current_statement__ = 202; - validate_non_negative_index("r", "n + 1", (n + 1)); - Eigen::Matrix r; - r = Eigen::Matrix(m, (n + 1)); - stan::math::fill(r, DUMMY_VAR__); - - current_statement__ = 204; - validate_non_negative_index("tmpr", "m", m); - Eigen::Matrix tmpr; - tmpr = Eigen::Matrix(m); - stan::math::fill(tmpr, DUMMY_VAR__); - - current_statement__ = 223; - for (int t = 1; t <= n; ++t) { - current_statement__ = 206; - assign(F, cons_list(index_uni(t), nil_index_list()), - (quad_form( - rvalue(P, - cons_list(index_min_max(1, k), - cons_list(index_min_max(1, k), nil_index_list())), "P"), - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg")) + - (gamma2_y[(t - 1)] * Ht)), "assigning variable F"); - current_statement__ = 221; - if ((primitive_value(logical_eq(y_miss[(t - 1)], 0)) && - primitive_value(logical_gt(F[(t - 1)], 1.0e-12)))) { - current_statement__ = 213; - assign(v, cons_list(index_uni(t), nil_index_list()), - (y[(t - 1)] - - dot_product( - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg"), - head(x, k))), "assigning variable v"); - current_statement__ = 214; - assign(K, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - divide( - multiply( - rvalue(P, - cons_list(index_min_max(1, m), - cons_list(index_min_max(1, k), nil_index_list())), "P"), - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg")), - F[(t - 1)]), "assigning variable K"); - current_statement__ = 215; - assign(x, nil_index_list(), - multiply(Tt, - add(stan::model::deep_copy(x), - multiply( - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K"), - v[(t - 1)]))), "assigning variable x"); - current_statement__ = 216; - assign(P, nil_index_list(), - quad_form_sym( - subtract(stan::model::deep_copy(P), - multiply( - multiply( - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K"), - transpose( - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K"))), - F[(t - 1)])), transpose(Tt)), "assigning variable P"); - current_statement__ = 219; - for (int i = 1; i <= m; ++i) { - current_statement__ = 217; - assign(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), - (rvalue(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), "P") + - rvalue(Rt, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "Rt")), - "assigning variable P");} - } else { - current_statement__ = 207; - assign(x, nil_index_list(), multiply(Tt, stan::model::deep_copy(x)), - "assigning variable x"); - current_statement__ = 208; - assign(P, nil_index_list(), - quad_form_sym(stan::model::deep_copy(P), transpose(Tt)), - "assigning variable P"); - current_statement__ = 211; - for (int i = 1; i <= m; ++i) { - current_statement__ = 209; - assign(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), - (rvalue(P, - cons_list(index_uni(i), - cons_list(index_uni(i), nil_index_list())), "P") + - rvalue(Rt, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "Rt")), - "assigning variable P");} - }} - current_statement__ = 224; - assign(r, - cons_list(index_omni(), - cons_list(index_uni((n + 1)), nil_index_list())), rep_vector(0.0, m), - "assigning variable r"); - current_statement__ = 237; - for (int tt = 1; tt <= n; ++tt) { - int t; - t = std::numeric_limits::min(); - - current_statement__ = 225; - t = ((n + 1) - tt); - current_statement__ = 226; - validate_non_negative_index("tmp", "m", m); - Eigen::Matrix tmp; - tmp = Eigen::Matrix(m); - stan::math::fill(tmp, DUMMY_VAR__); - - current_statement__ = 227; - assign(tmp, nil_index_list(), - rvalue(r, - cons_list(index_omni(), - cons_list(index_uni((t + 1)), nil_index_list())), "r"), - "assigning variable tmp"); - current_statement__ = 235; - if ((primitive_value(logical_eq(y_miss[(t - 1)], 0)) && - primitive_value(logical_gt(F[(t - 1)], 1.0e-12)))) { - current_statement__ = 230; - validate_non_negative_index("tmp2", "m", m); - Eigen::Matrix tmp2; - tmp2 = Eigen::Matrix(m); - stan::math::fill(tmp2, DUMMY_VAR__); - - current_statement__ = 231; - assign(tmp2, nil_index_list(), rep_vector(0.0, m), - "assigning variable tmp2"); - current_statement__ = 232; - assign(tmp2, cons_list(index_min_max(1, k), nil_index_list()), - rvalue(xreg, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg"), - "assigning variable tmp2"); - current_statement__ = 233; - assign(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - add(divide(multiply(tmp2, v[(t - 1)]), F[(t - 1)]), - multiply( - transpose( - subtract(Tt, - multiply( - multiply(Tt, - rvalue(K, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "K")), - transpose(tmp2)))), tmp)), "assigning variable r"); - } else { - current_statement__ = 228; - assign(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - multiply(transpose(Tt), tmp), "assigning variable r"); - }} - current_statement__ = 238; - assign(tmpr, nil_index_list(), - rvalue(r, - cons_list(index_omni(), cons_list(index_uni(1), nil_index_list())), - "r"), "assigning variable tmpr"); - current_statement__ = 239; - assign(r, - cons_list(index_omni(), cons_list(index_uni(1), nil_index_list())), - add(a1, multiply(P1, tmpr)), "assigning variable r"); - current_statement__ = 246; - for (int t = 2; t <= n; ++t) { - current_statement__ = 240; - validate_non_negative_index("tmp", "m", m); - Eigen::Matrix tmp; - tmp = Eigen::Matrix(m); - stan::math::fill(tmp, DUMMY_VAR__); - - current_statement__ = 241; - assign(tmp, nil_index_list(), - rvalue(r, - cons_list(index_omni(), - cons_list(index_uni((t - 1)), nil_index_list())), "r"), - "assigning variable tmp"); - current_statement__ = 242; - validate_non_negative_index("tmp2", "m", m); - Eigen::Matrix tmp2; - tmp2 = Eigen::Matrix(m); - stan::math::fill(tmp2, DUMMY_VAR__); - - current_statement__ = 243; - assign(tmp2, nil_index_list(), - rvalue(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - "r"), "assigning variable tmp2"); - current_statement__ = 244; - assign(r, - cons_list(index_omni(), cons_list(index_uni(t), nil_index_list())), - add(multiply(Tt, tmp), - elt_multiply( - rvalue(Rt, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "Rt"), tmp2)), - "assigning variable r");} - current_statement__ = 247; - return rvalue(r, - cons_list(index_min_max(1, m), - cons_list(index_min_max(1, n), nil_index_list())), "r"); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - -} -struct gaussian_smoother_functor__ { -template -Eigen::Matrix, stan::value_type_t, -stan::value_type_t, T4__, -stan::value_type_t, stan::promote_args_t, -stan::value_type_t, -stan::value_type_t>>, -1, -1> -operator()(const T0__& y, const std::vector& y_miss, const T2__& a1, - const T3__& P1, const T4__& Ht, const T5__& Tt, const T6__& Rt, - const T7__& xreg, const T8__& gamma2_y, std::ostream* pstream__) const -{ -return gaussian_smoother(y, y_miss, a1, P1, Ht, Tt, Rt, xreg, gamma2_y, - pstream__); -} -}; -#include -class model_walker_lm final : public model_base_crtp { -private: - int k_fixed; - int k_rw1; - int k_rw2; - int m; - int k; - int n; - int n_lfo; - Eigen::Matrix xreg_fixed; - Eigen::Matrix xreg_rw; - Eigen::Matrix y; - std::vector y_miss; - double sigma_y_shape; - double sigma_y_rate; - double beta_fixed_mean; - double beta_fixed_sd; - double beta_rw1_mean; - double beta_rw1_sd; - double beta_rw2_mean; - double beta_rw2_sd; - double sigma_rw1_shape; - double sigma_rw2_shape; - double sigma_rw1_rate; - double sigma_rw2_rate; - double nu_mean; - double nu_sd; - Eigen::Matrix gamma_y; - Eigen::Matrix gamma_rw1; - Eigen::Matrix gamma_rw2; - std::vector obs_idx; - Eigen::Matrix a1; - Eigen::Matrix P1; - Eigen::Matrix Tt; - Eigen::Matrix gamma2_y; - int y_rep_1dim__; - int beta_rw_2dim__; - int nu_2dim__; - int y_fit_1dim__; - -public: - ~model_walker_lm() { } - - inline std::string model_name() const final { return "model_walker_lm"; } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.26.1-1-g67504470", "stancflags = "}; - } - - - model_walker_lm(stan::io::var_context& context__, - unsigned int random_seed__ = 0, - std::ostream* pstream__ = nullptr) : model_base_crtp(0) { - using local_scalar_t__ = double ; - boost::ecuyer1988 base_rng__ = - stan::services::util::create_rng(random_seed__, 0); - (void) base_rng__; // suppress unused var warning - static const char* function__ = "model_walker_lm_namespace::model_walker_lm"; - (void) function__; // suppress unused var warning - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - int pos__; - pos__ = std::numeric_limits::min(); - - pos__ = 1; - current_statement__ = 65; - context__.validate_dims("data initialization","k_fixed","int", - context__.to_vec()); - k_fixed = std::numeric_limits::min(); - - current_statement__ = 65; - k_fixed = context__.vals_i("k_fixed")[(1 - 1)]; - current_statement__ = 65; - current_statement__ = 65; - check_greater_or_equal(function__, "k_fixed", k_fixed, 0); - current_statement__ = 66; - context__.validate_dims("data initialization","k_rw1","int", - context__.to_vec()); - k_rw1 = std::numeric_limits::min(); - - current_statement__ = 66; - k_rw1 = context__.vals_i("k_rw1")[(1 - 1)]; - current_statement__ = 66; - current_statement__ = 66; - check_greater_or_equal(function__, "k_rw1", k_rw1, 0); - current_statement__ = 67; - context__.validate_dims("data initialization","k_rw2","int", - context__.to_vec()); - k_rw2 = std::numeric_limits::min(); - - current_statement__ = 67; - k_rw2 = context__.vals_i("k_rw2")[(1 - 1)]; - current_statement__ = 67; - current_statement__ = 67; - check_greater_or_equal(function__, "k_rw2", k_rw2, 0); - current_statement__ = 68; - context__.validate_dims("data initialization","m","int", - context__.to_vec()); - m = std::numeric_limits::min(); - - current_statement__ = 68; - m = context__.vals_i("m")[(1 - 1)]; - current_statement__ = 68; - current_statement__ = 68; - check_greater_or_equal(function__, "m", m, 0); - current_statement__ = 69; - context__.validate_dims("data initialization","k","int", - context__.to_vec()); - k = std::numeric_limits::min(); - - current_statement__ = 69; - k = context__.vals_i("k")[(1 - 1)]; - current_statement__ = 69; - current_statement__ = 69; - check_greater_or_equal(function__, "k", k, 0); - current_statement__ = 70; - context__.validate_dims("data initialization","n","int", - context__.to_vec()); - n = std::numeric_limits::min(); - - current_statement__ = 70; - n = context__.vals_i("n")[(1 - 1)]; - current_statement__ = 70; - current_statement__ = 70; - check_greater_or_equal(function__, "n", n, 1); - current_statement__ = 71; - context__.validate_dims("data initialization","n_lfo","int", - context__.to_vec()); - n_lfo = std::numeric_limits::min(); - - current_statement__ = 71; - n_lfo = context__.vals_i("n_lfo")[(1 - 1)]; - current_statement__ = 71; - current_statement__ = 71; - check_greater_or_equal(function__, "n_lfo", n_lfo, 1); - current_statement__ = 72; - validate_non_negative_index("xreg_fixed", "n", n); - current_statement__ = 73; - validate_non_negative_index("xreg_fixed", "k_fixed", k_fixed); - current_statement__ = 74; - context__.validate_dims("data initialization","xreg_fixed","double", - context__.to_vec(n, k_fixed)); - xreg_fixed = Eigen::Matrix(n, k_fixed); - stan::math::fill(xreg_fixed, std::numeric_limits::quiet_NaN()); - - { - std::vector xreg_fixed_flat__; - current_statement__ = 74; - assign(xreg_fixed_flat__, nil_index_list(), - context__.vals_r("xreg_fixed"), - "assigning variable xreg_fixed_flat__"); - current_statement__ = 74; - pos__ = 1; - current_statement__ = 74; - for (int sym1__ = 1; sym1__ <= k_fixed; ++sym1__) { - current_statement__ = 74; - for (int sym2__ = 1; sym2__ <= n; ++sym2__) { - current_statement__ = 74; - assign(xreg_fixed, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), - xreg_fixed_flat__[(pos__ - 1)], "assigning variable xreg_fixed"); - current_statement__ = 74; - pos__ = (pos__ + 1);}} - } - current_statement__ = 75; - validate_non_negative_index("xreg_rw", "k", k); - current_statement__ = 76; - validate_non_negative_index("xreg_rw", "n", n); - current_statement__ = 77; - context__.validate_dims("data initialization","xreg_rw","double", - context__.to_vec(k, n)); - xreg_rw = Eigen::Matrix(k, n); - stan::math::fill(xreg_rw, std::numeric_limits::quiet_NaN()); - - { - std::vector xreg_rw_flat__; - current_statement__ = 77; - assign(xreg_rw_flat__, nil_index_list(), context__.vals_r("xreg_rw"), - "assigning variable xreg_rw_flat__"); - current_statement__ = 77; - pos__ = 1; - current_statement__ = 77; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 77; - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - current_statement__ = 77; - assign(xreg_rw, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), - xreg_rw_flat__[(pos__ - 1)], "assigning variable xreg_rw"); - current_statement__ = 77; - pos__ = (pos__ + 1);}} - } - current_statement__ = 78; - validate_non_negative_index("y", "n", n); - current_statement__ = 79; - context__.validate_dims("data initialization","y","double", - context__.to_vec(n)); - y = Eigen::Matrix(n); - stan::math::fill(y, std::numeric_limits::quiet_NaN()); - - { - std::vector y_flat__; - current_statement__ = 79; - assign(y_flat__, nil_index_list(), context__.vals_r("y"), - "assigning variable y_flat__"); - current_statement__ = 79; - pos__ = 1; - current_statement__ = 79; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 79; - assign(y, cons_list(index_uni(sym1__), nil_index_list()), - y_flat__[(pos__ - 1)], "assigning variable y"); - current_statement__ = 79; - pos__ = (pos__ + 1);} - } - current_statement__ = 80; - validate_non_negative_index("y_miss", "n", n); - current_statement__ = 81; - context__.validate_dims("data initialization","y_miss","int", - context__.to_vec(n)); - y_miss = std::vector(n, std::numeric_limits::min()); - - current_statement__ = 81; - assign(y_miss, nil_index_list(), context__.vals_i("y_miss"), - "assigning variable y_miss"); - current_statement__ = 81; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 81; - current_statement__ = 81; - check_greater_or_equal(function__, "y_miss[sym1__]", - y_miss[(sym1__ - 1)], 0);} - current_statement__ = 82; - context__.validate_dims("data initialization","sigma_y_shape","double", - context__.to_vec()); - sigma_y_shape = std::numeric_limits::quiet_NaN(); - - current_statement__ = 82; - sigma_y_shape = context__.vals_r("sigma_y_shape")[(1 - 1)]; - current_statement__ = 82; - current_statement__ = 82; - check_greater_or_equal(function__, "sigma_y_shape", sigma_y_shape, 0); - current_statement__ = 83; - context__.validate_dims("data initialization","sigma_y_rate","double", - context__.to_vec()); - sigma_y_rate = std::numeric_limits::quiet_NaN(); - - current_statement__ = 83; - sigma_y_rate = context__.vals_r("sigma_y_rate")[(1 - 1)]; - current_statement__ = 83; - current_statement__ = 83; - check_greater_or_equal(function__, "sigma_y_rate", sigma_y_rate, 0); - current_statement__ = 84; - context__.validate_dims("data initialization","beta_fixed_mean", - "double",context__.to_vec()); - beta_fixed_mean = std::numeric_limits::quiet_NaN(); - - current_statement__ = 84; - beta_fixed_mean = context__.vals_r("beta_fixed_mean")[(1 - 1)]; - current_statement__ = 85; - context__.validate_dims("data initialization","beta_fixed_sd","double", - context__.to_vec()); - beta_fixed_sd = std::numeric_limits::quiet_NaN(); - - current_statement__ = 85; - beta_fixed_sd = context__.vals_r("beta_fixed_sd")[(1 - 1)]; - current_statement__ = 85; - current_statement__ = 85; - check_greater_or_equal(function__, "beta_fixed_sd", beta_fixed_sd, 0); - current_statement__ = 86; - context__.validate_dims("data initialization","beta_rw1_mean","double", - context__.to_vec()); - beta_rw1_mean = std::numeric_limits::quiet_NaN(); - - current_statement__ = 86; - beta_rw1_mean = context__.vals_r("beta_rw1_mean")[(1 - 1)]; - current_statement__ = 87; - context__.validate_dims("data initialization","beta_rw1_sd","double", - context__.to_vec()); - beta_rw1_sd = std::numeric_limits::quiet_NaN(); - - current_statement__ = 87; - beta_rw1_sd = context__.vals_r("beta_rw1_sd")[(1 - 1)]; - current_statement__ = 87; - current_statement__ = 87; - check_greater_or_equal(function__, "beta_rw1_sd", beta_rw1_sd, 0); - current_statement__ = 88; - context__.validate_dims("data initialization","beta_rw2_mean","double", - context__.to_vec()); - beta_rw2_mean = std::numeric_limits::quiet_NaN(); - - current_statement__ = 88; - beta_rw2_mean = context__.vals_r("beta_rw2_mean")[(1 - 1)]; - current_statement__ = 89; - context__.validate_dims("data initialization","beta_rw2_sd","double", - context__.to_vec()); - beta_rw2_sd = std::numeric_limits::quiet_NaN(); - - current_statement__ = 89; - beta_rw2_sd = context__.vals_r("beta_rw2_sd")[(1 - 1)]; - current_statement__ = 89; - current_statement__ = 89; - check_greater_or_equal(function__, "beta_rw2_sd", beta_rw2_sd, 0); - current_statement__ = 90; - context__.validate_dims("data initialization","sigma_rw1_shape", - "double",context__.to_vec()); - sigma_rw1_shape = std::numeric_limits::quiet_NaN(); - - current_statement__ = 90; - sigma_rw1_shape = context__.vals_r("sigma_rw1_shape")[(1 - 1)]; - current_statement__ = 90; - current_statement__ = 90; - check_greater_or_equal(function__, "sigma_rw1_shape", sigma_rw1_shape, - 0); - current_statement__ = 91; - context__.validate_dims("data initialization","sigma_rw2_shape", - "double",context__.to_vec()); - sigma_rw2_shape = std::numeric_limits::quiet_NaN(); - - current_statement__ = 91; - sigma_rw2_shape = context__.vals_r("sigma_rw2_shape")[(1 - 1)]; - current_statement__ = 91; - current_statement__ = 91; - check_greater_or_equal(function__, "sigma_rw2_shape", sigma_rw2_shape, - 0); - current_statement__ = 92; - context__.validate_dims("data initialization","sigma_rw1_rate", - "double",context__.to_vec()); - sigma_rw1_rate = std::numeric_limits::quiet_NaN(); - - current_statement__ = 92; - sigma_rw1_rate = context__.vals_r("sigma_rw1_rate")[(1 - 1)]; - current_statement__ = 92; - current_statement__ = 92; - check_greater_or_equal(function__, "sigma_rw1_rate", sigma_rw1_rate, 0); - current_statement__ = 93; - context__.validate_dims("data initialization","sigma_rw2_rate", - "double",context__.to_vec()); - sigma_rw2_rate = std::numeric_limits::quiet_NaN(); - - current_statement__ = 93; - sigma_rw2_rate = context__.vals_r("sigma_rw2_rate")[(1 - 1)]; - current_statement__ = 93; - current_statement__ = 93; - check_greater_or_equal(function__, "sigma_rw2_rate", sigma_rw2_rate, 0); - current_statement__ = 94; - context__.validate_dims("data initialization","nu_mean","double", - context__.to_vec()); - nu_mean = std::numeric_limits::quiet_NaN(); - - current_statement__ = 94; - nu_mean = context__.vals_r("nu_mean")[(1 - 1)]; - current_statement__ = 94; - current_statement__ = 94; - check_greater_or_equal(function__, "nu_mean", nu_mean, 0); - current_statement__ = 95; - context__.validate_dims("data initialization","nu_sd","double", - context__.to_vec()); - nu_sd = std::numeric_limits::quiet_NaN(); - - current_statement__ = 95; - nu_sd = context__.vals_r("nu_sd")[(1 - 1)]; - current_statement__ = 95; - current_statement__ = 95; - check_greater_or_equal(function__, "nu_sd", nu_sd, 0); - current_statement__ = 96; - validate_non_negative_index("gamma_y", "n", n); - current_statement__ = 97; - context__.validate_dims("data initialization","gamma_y","double", - context__.to_vec(n)); - gamma_y = Eigen::Matrix(n); - stan::math::fill(gamma_y, std::numeric_limits::quiet_NaN()); - - { - std::vector gamma_y_flat__; - current_statement__ = 97; - assign(gamma_y_flat__, nil_index_list(), context__.vals_r("gamma_y"), - "assigning variable gamma_y_flat__"); - current_statement__ = 97; - pos__ = 1; - current_statement__ = 97; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 97; - assign(gamma_y, cons_list(index_uni(sym1__), nil_index_list()), - gamma_y_flat__[(pos__ - 1)], "assigning variable gamma_y"); - current_statement__ = 97; - pos__ = (pos__ + 1);} - } - current_statement__ = 98; - validate_non_negative_index("gamma_rw1", "k_rw1", k_rw1); - current_statement__ = 99; - validate_non_negative_index("gamma_rw1", "n", n); - current_statement__ = 100; - context__.validate_dims("data initialization","gamma_rw1","double", - context__.to_vec(k_rw1, n)); - gamma_rw1 = Eigen::Matrix(k_rw1, n); - stan::math::fill(gamma_rw1, std::numeric_limits::quiet_NaN()); - - { - std::vector gamma_rw1_flat__; - current_statement__ = 100; - assign(gamma_rw1_flat__, nil_index_list(), - context__.vals_r("gamma_rw1"), - "assigning variable gamma_rw1_flat__"); - current_statement__ = 100; - pos__ = 1; - current_statement__ = 100; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 100; - for (int sym2__ = 1; sym2__ <= k_rw1; ++sym2__) { - current_statement__ = 100; - assign(gamma_rw1, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), - gamma_rw1_flat__[(pos__ - 1)], "assigning variable gamma_rw1"); - current_statement__ = 100; - pos__ = (pos__ + 1);}} - } - current_statement__ = 101; - validate_non_negative_index("gamma_rw2", "k_rw2", k_rw2); - current_statement__ = 102; - validate_non_negative_index("gamma_rw2", "n", n); - current_statement__ = 103; - context__.validate_dims("data initialization","gamma_rw2","double", - context__.to_vec(k_rw2, n)); - gamma_rw2 = Eigen::Matrix(k_rw2, n); - stan::math::fill(gamma_rw2, std::numeric_limits::quiet_NaN()); - - { - std::vector gamma_rw2_flat__; - current_statement__ = 103; - assign(gamma_rw2_flat__, nil_index_list(), - context__.vals_r("gamma_rw2"), - "assigning variable gamma_rw2_flat__"); - current_statement__ = 103; - pos__ = 1; - current_statement__ = 103; - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - current_statement__ = 103; - for (int sym2__ = 1; sym2__ <= k_rw2; ++sym2__) { - current_statement__ = 103; - assign(gamma_rw2, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), - gamma_rw2_flat__[(pos__ - 1)], "assigning variable gamma_rw2"); - current_statement__ = 103; - pos__ = (pos__ + 1);}} - } - current_statement__ = 104; - validate_non_negative_index("obs_idx", - "n_lfo - sum(y_miss[1 : n_lfo])", - (n_lfo - - sum( - rvalue(y_miss, - cons_list(index_min_max(1, n_lfo), - nil_index_list()), "y_miss")))); - current_statement__ = 105; - obs_idx = std::vector((n_lfo - - sum( - rvalue(y_miss, - cons_list(index_min_max(1, n_lfo), - nil_index_list()), "y_miss"))), std::numeric_limits::min()); - - current_statement__ = 106; - validate_non_negative_index("a1", "m", m); - current_statement__ = 107; - a1 = Eigen::Matrix(m); - stan::math::fill(a1, std::numeric_limits::quiet_NaN()); - - current_statement__ = 108; - validate_non_negative_index("P1", "m", m); - current_statement__ = 109; - validate_non_negative_index("P1", "m", m); - current_statement__ = 110; - P1 = Eigen::Matrix(m, m); - stan::math::fill(P1, std::numeric_limits::quiet_NaN()); - - current_statement__ = 110; - assign(P1, nil_index_list(), rep_matrix(0.0, m, m), - "assigning variable P1"); - current_statement__ = 111; - validate_non_negative_index("Tt", "m", m); - current_statement__ = 112; - validate_non_negative_index("Tt", "m", m); - current_statement__ = 113; - Tt = Eigen::Matrix(m, m); - stan::math::fill(Tt, std::numeric_limits::quiet_NaN()); - - current_statement__ = 113; - assign(Tt, nil_index_list(), diag_matrix(rep_vector(1.0, m)), - "assigning variable Tt"); - current_statement__ = 114; - validate_non_negative_index("gamma2_y", "n", n); - current_statement__ = 115; - gamma2_y = Eigen::Matrix(n); - stan::math::fill(gamma2_y, std::numeric_limits::quiet_NaN()); - - current_statement__ = 115; - assign(gamma2_y, nil_index_list(), elt_multiply(gamma_y, gamma_y), - "assigning variable gamma2_y"); - { - int ii; - ii = std::numeric_limits::min(); - - current_statement__ = 116; - ii = 0; - current_statement__ = 122; - for (int i = 1; i <= n_lfo; ++i) { - current_statement__ = 120; - if (logical_eq(y_miss[(i - 1)], 0)) { - current_statement__ = 117; - ii = (ii + 1); - current_statement__ = 118; - assign(obs_idx, cons_list(index_uni(ii), nil_index_list()), i, - "assigning variable obs_idx"); - } } - } - current_statement__ = 126; - if (logical_gt(k_rw2, 0)) { - current_statement__ = 124; - assign(Tt, - cons_list(index_min_max((k_rw1 + 1), k), - cons_list(index_min_max((k + 1), m), nil_index_list())), - diag_matrix(rep_vector(1.0, k_rw2)), "assigning variable Tt"); - } - current_statement__ = 130; - for (int i = 1; i <= k_rw1; ++i) { - current_statement__ = 127; - assign(a1, cons_list(index_uni(i), nil_index_list()), beta_rw1_mean, - "assigning variable a1"); - current_statement__ = 128; - assign(P1, - cons_list(index_uni(i), cons_list(index_uni(i), nil_index_list())), - pow(beta_rw1_sd, 2), "assigning variable P1");} - current_statement__ = 134; - for (int i = (k_rw1 + 1); i <= k; ++i) { - current_statement__ = 131; - assign(a1, cons_list(index_uni(i), nil_index_list()), beta_rw2_mean, - "assigning variable a1"); - current_statement__ = 132; - assign(P1, - cons_list(index_uni(i), cons_list(index_uni(i), nil_index_list())), - pow(beta_rw2_sd, 2), "assigning variable P1");} - current_statement__ = 138; - for (int i = (k + 1); i <= m; ++i) { - current_statement__ = 135; - assign(a1, cons_list(index_uni(i), nil_index_list()), nu_mean, - "assigning variable a1"); - current_statement__ = 136; - assign(P1, - cons_list(index_uni(i), cons_list(index_uni(i), nil_index_list())), - pow(nu_sd, 2), "assigning variable P1");} - current_statement__ = 139; - validate_non_negative_index("beta_fixed", "k_fixed", k_fixed); - current_statement__ = 140; - validate_non_negative_index("sigma_rw1", "k_rw1", k_rw1); - current_statement__ = 141; - validate_non_negative_index("sigma_rw2", "k_rw2", k_rw2); - current_statement__ = 142; - validate_non_negative_index("log_lik", "n", n); - current_statement__ = 143; - validate_non_negative_index("Rt", "m", m); - current_statement__ = 144; - validate_non_negative_index("Rt", "n", n); - current_statement__ = 145; - validate_non_negative_index("xbeta", "n", n); - current_statement__ = 146; - validate_non_negative_index("y_", "n", n); - current_statement__ = 147; - y_rep_1dim__ = std::numeric_limits::min(); - - current_statement__ = 147; - y_rep_1dim__ = (n * logical_eq(n_lfo, n)); - current_statement__ = 147; - validate_non_negative_index("y_rep", "n * (n_lfo == n)", y_rep_1dim__); - current_statement__ = 148; - validate_non_negative_index("beta_rw", "k", k); - current_statement__ = 149; - beta_rw_2dim__ = std::numeric_limits::min(); - - current_statement__ = 149; - beta_rw_2dim__ = (n * logical_eq(n_lfo, n)); - current_statement__ = 149; - validate_non_negative_index("beta_rw", "n * (n_lfo == n)", - beta_rw_2dim__); - current_statement__ = 150; - validate_non_negative_index("nu", "k_rw2", k_rw2); - current_statement__ = 151; - nu_2dim__ = std::numeric_limits::min(); - - current_statement__ = 151; - nu_2dim__ = (n * logical_eq(n_lfo, n)); - current_statement__ = 151; - validate_non_negative_index("nu", "n * (n_lfo == n)", nu_2dim__); - current_statement__ = 152; - y_fit_1dim__ = std::numeric_limits::min(); - - current_statement__ = 152; - y_fit_1dim__ = (n * logical_eq(n_lfo, n)); - current_statement__ = 152; - validate_non_negative_index("y_fit", "n * (n_lfo == n)", y_fit_1dim__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - num_params_r__ = 0U; - - try { - num_params_r__ += k_fixed; - num_params_r__ += k_rw1; - num_params_r__ += k_rw2; - num_params_r__ += 1; - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - } - template * = nullptr, stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t log_prob_impl(VecR& params_r__, - VecI& params_i__, - std::ostream* pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - static const char* function__ = "model_walker_lm_namespace::log_prob"; -(void) function__; // suppress unused var warning - stan::io::reader in__(params_r__, params_i__); - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - Eigen::Matrix beta_fixed; - beta_fixed = Eigen::Matrix(k_fixed); - stan::math::fill(beta_fixed, DUMMY_VAR__); - - current_statement__ = 1; - beta_fixed = in__.vector(k_fixed); - std::vector sigma_rw1; - sigma_rw1 = std::vector(k_rw1, DUMMY_VAR__); - - current_statement__ = 2; - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - current_statement__ = 2; - assign(sigma_rw1, cons_list(index_uni(sym1__), nil_index_list()), - in__.scalar(), "assigning variable sigma_rw1");} - current_statement__ = 2; - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - current_statement__ = 2; - if (jacobian__) { - current_statement__ = 2; - assign(sigma_rw1, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_rw1[(sym1__ - 1)], 0, lp__), - "assigning variable sigma_rw1"); - } else { - current_statement__ = 2; - assign(sigma_rw1, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_rw1[(sym1__ - 1)], 0), - "assigning variable sigma_rw1"); - }} - std::vector sigma_rw2; - sigma_rw2 = std::vector(k_rw2, DUMMY_VAR__); - - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - current_statement__ = 3; - assign(sigma_rw2, cons_list(index_uni(sym1__), nil_index_list()), - in__.scalar(), "assigning variable sigma_rw2");} - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - current_statement__ = 3; - if (jacobian__) { - current_statement__ = 3; - assign(sigma_rw2, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_rw2[(sym1__ - 1)], 0, lp__), - "assigning variable sigma_rw2"); - } else { - current_statement__ = 3; - assign(sigma_rw2, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_rw2[(sym1__ - 1)], 0), - "assigning variable sigma_rw2"); - }} - local_scalar_t__ sigma_y; - sigma_y = DUMMY_VAR__; - - current_statement__ = 4; - sigma_y = in__.scalar(); - current_statement__ = 4; - if (jacobian__) { - current_statement__ = 4; - sigma_y = stan::math::lb_constrain(sigma_y, 0, lp__); - } else { - current_statement__ = 4; - sigma_y = stan::math::lb_constrain(sigma_y, 0); - } - Eigen::Matrix log_lik; - log_lik = Eigen::Matrix(n); - stan::math::fill(log_lik, DUMMY_VAR__); - - Eigen::Matrix Rt; - Rt = Eigen::Matrix(m, n); - stan::math::fill(Rt, DUMMY_VAR__); - - current_statement__ = 6; - assign(Rt, nil_index_list(), rep_matrix(0.0, m, n), - "assigning variable Rt"); - Eigen::Matrix xbeta; - xbeta = Eigen::Matrix(n); - stan::math::fill(xbeta, DUMMY_VAR__); - - Eigen::Matrix y_; - y_ = Eigen::Matrix(n); - stan::math::fill(y_, DUMMY_VAR__); - - current_statement__ = 13; - if (logical_gt(k_fixed, 0)) { - current_statement__ = 11; - assign(xbeta, nil_index_list(), multiply(xreg_fixed, beta_fixed), - "assigning variable xbeta"); - } else { - current_statement__ = 9; - assign(xbeta, nil_index_list(), rep_vector(0.0, n), - "assigning variable xbeta"); - } - current_statement__ = 14; - assign(y_, nil_index_list(), subtract(y, xbeta), - "assigning variable y_"); - current_statement__ = 22; - for (int t = 1; t <= n; ++t) { - current_statement__ = 17; - for (int i = 1; i <= k_rw1; ++i) { - current_statement__ = 15; - assign(Rt, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), - pow( - (rvalue(gamma_rw1, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "gamma_rw1") * - sigma_rw1[(i - 1)]), 2), "assigning variable Rt");} - current_statement__ = 20; - for (int i = 1; i <= k_rw2; ++i) { - current_statement__ = 18; - assign(Rt, - cons_list(index_uni((k + i)), - cons_list(index_uni(t), nil_index_list())), - pow( - (rvalue(gamma_rw2, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "gamma_rw2") * - sigma_rw2[(i - 1)]), 2), "assigning variable Rt");}} - current_statement__ = 23; - assign(log_lik, nil_index_list(), - gaussian_filter(y_, y_miss, a1, P1, pow(sigma_y, 2), Tt, Rt, xreg_rw, - gamma2_y, pstream__), "assigning variable log_lik"); - { - current_statement__ = 60; - lp_accum__.add( - normal_lpdf(beta_fixed, beta_fixed_mean, beta_fixed_sd)); - current_statement__ = 61; - lp_accum__.add( - gamma_lpdf(sigma_y, sigma_y_shape, sigma_y_rate)); - current_statement__ = 62; - lp_accum__.add( - gamma_lpdf(sigma_rw1, sigma_rw1_shape, sigma_rw1_rate)); - current_statement__ = 63; - lp_accum__.add( - gamma_lpdf(sigma_rw2, sigma_rw2_shape, sigma_rw2_rate)); - current_statement__ = 64; - lp_accum__.add( - sum( - rvalue(log_lik, - cons_list(index_multi(obs_idx), nil_index_list()), "log_lik"))); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } // log_prob_impl() - - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_std_vector_vt* = nullptr> - inline void write_array_impl(RNG& base_rng__, VecR& params_r__, - VecI& params_i__, VecVar& vars__, - const bool emit_transformed_parameters__ = true, - const bool emit_generated_quantities__ = true, - std::ostream* pstream__ = nullptr) const { - using local_scalar_t__ = double; - vars__.resize(0); - stan::io::reader in__(params_r__, params_i__); - static const char* function__ = "model_walker_lm_namespace::write_array"; -(void) function__; // suppress unused var warning - (void) function__; // suppress unused var warning - double lp__ = 0.0; - (void) lp__; // dummy to suppress unused var warning - stan::math::accumulator lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - (void) DUMMY_VAR__; // suppress unused var warning - - try { - Eigen::Matrix beta_fixed; - beta_fixed = Eigen::Matrix(k_fixed); - stan::math::fill(beta_fixed, std::numeric_limits::quiet_NaN()); - - current_statement__ = 1; - beta_fixed = in__.vector(k_fixed); - std::vector sigma_rw1; - sigma_rw1 = std::vector(k_rw1, std::numeric_limits::quiet_NaN()); - - current_statement__ = 2; - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - current_statement__ = 2; - assign(sigma_rw1, cons_list(index_uni(sym1__), nil_index_list()), - in__.scalar(), "assigning variable sigma_rw1");} - current_statement__ = 2; - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - current_statement__ = 2; - assign(sigma_rw1, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_rw1[(sym1__ - 1)], 0), - "assigning variable sigma_rw1");} - std::vector sigma_rw2; - sigma_rw2 = std::vector(k_rw2, std::numeric_limits::quiet_NaN()); - - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - current_statement__ = 3; - assign(sigma_rw2, cons_list(index_uni(sym1__), nil_index_list()), - in__.scalar(), "assigning variable sigma_rw2");} - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - current_statement__ = 3; - assign(sigma_rw2, cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_constrain(sigma_rw2[(sym1__ - 1)], 0), - "assigning variable sigma_rw2");} - double sigma_y; - sigma_y = std::numeric_limits::quiet_NaN(); - - current_statement__ = 4; - sigma_y = in__.scalar(); - current_statement__ = 4; - sigma_y = stan::math::lb_constrain(sigma_y, 0); - Eigen::Matrix log_lik; - log_lik = Eigen::Matrix(n); - stan::math::fill(log_lik, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix Rt; - Rt = Eigen::Matrix(m, n); - stan::math::fill(Rt, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix xbeta; - xbeta = Eigen::Matrix(n); - stan::math::fill(xbeta, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix y_; - y_ = Eigen::Matrix(n); - stan::math::fill(y_, std::numeric_limits::quiet_NaN()); - - for (int sym1__ = 1; sym1__ <= k_fixed; ++sym1__) { - vars__.emplace_back(beta_fixed[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - vars__.emplace_back(sigma_rw1[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - vars__.emplace_back(sigma_rw2[(sym1__ - 1)]);} - vars__.emplace_back(sigma_y); - if (logical_negation((primitive_value(emit_transformed_parameters__) || - primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 6; - assign(Rt, nil_index_list(), rep_matrix(0.0, m, n), - "assigning variable Rt"); - current_statement__ = 13; - if (logical_gt(k_fixed, 0)) { - current_statement__ = 11; - assign(xbeta, nil_index_list(), multiply(xreg_fixed, beta_fixed), - "assigning variable xbeta"); - } else { - current_statement__ = 9; - assign(xbeta, nil_index_list(), rep_vector(0.0, n), - "assigning variable xbeta"); - } - current_statement__ = 14; - assign(y_, nil_index_list(), subtract(y, xbeta), - "assigning variable y_"); - current_statement__ = 22; - for (int t = 1; t <= n; ++t) { - current_statement__ = 17; - for (int i = 1; i <= k_rw1; ++i) { - current_statement__ = 15; - assign(Rt, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), - pow( - (rvalue(gamma_rw1, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "gamma_rw1") * - sigma_rw1[(i - 1)]), 2), "assigning variable Rt");} - current_statement__ = 20; - for (int i = 1; i <= k_rw2; ++i) { - current_statement__ = 18; - assign(Rt, - cons_list(index_uni((k + i)), - cons_list(index_uni(t), nil_index_list())), - pow( - (rvalue(gamma_rw2, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "gamma_rw2") * - sigma_rw2[(i - 1)]), 2), "assigning variable Rt");}} - current_statement__ = 23; - assign(log_lik, nil_index_list(), - gaussian_filter(y_, y_miss, a1, P1, pow(sigma_y, 2), Tt, Rt, xreg_rw, - gamma2_y, pstream__), "assigning variable log_lik"); - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - vars__.emplace_back(log_lik[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - for (int sym2__ = 1; sym2__ <= m; ++sym2__) { - vars__.emplace_back( - rvalue(Rt, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), "Rt"));}} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - vars__.emplace_back(xbeta[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - vars__.emplace_back(y_[(sym1__ - 1)]);} - } - if (logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix y_rep; - y_rep = Eigen::Matrix(y_rep_1dim__); - stan::math::fill(y_rep, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix beta_rw; - beta_rw = Eigen::Matrix(k, beta_rw_2dim__); - stan::math::fill(beta_rw, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix nu; - nu = Eigen::Matrix(k_rw2, nu_2dim__); - stan::math::fill(nu, std::numeric_limits::quiet_NaN()); - - Eigen::Matrix y_fit; - y_fit = Eigen::Matrix(y_fit_1dim__); - stan::math::fill(y_fit, std::numeric_limits::quiet_NaN()); - - current_statement__ = 59; - if (logical_eq(n_lfo, n)) { - current_statement__ = 30; - for (int i = 1; i <= k_rw1; ++i) { - current_statement__ = 28; - assign(beta_rw, - cons_list(index_uni(i), - cons_list(index_uni(1), nil_index_list())), - normal_rng(beta_rw1_mean, beta_rw1_sd, base_rng__), - "assigning variable beta_rw");} - current_statement__ = 34; - for (int i = 1; i <= k_rw2; ++i) { - current_statement__ = 31; - assign(beta_rw, - cons_list(index_uni((k_rw1 + i)), - cons_list(index_uni(1), nil_index_list())), - normal_rng(beta_rw2_mean, beta_rw2_sd, base_rng__), - "assigning variable beta_rw"); - current_statement__ = 32; - assign(nu, - cons_list(index_uni(i), - cons_list(index_uni(1), nil_index_list())), - normal_rng(nu_mean, nu_sd, base_rng__), "assigning variable nu"); - } - current_statement__ = 43; - for (int t = 1; t <= (n - 1); ++t) { - current_statement__ = 37; - for (int i = 1; i <= k_rw1; ++i) { - current_statement__ = 35; - assign(beta_rw, - cons_list(index_uni(i), - cons_list(index_uni((t + 1)), nil_index_list())), - normal_rng( - rvalue(beta_rw, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "beta_rw"), - (rvalue(gamma_rw1, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "gamma_rw1") - * sigma_rw1[(i - 1)]), base_rng__), - "assigning variable beta_rw");} - current_statement__ = 41; - for (int i = 1; i <= k_rw2; ++i) { - current_statement__ = 38; - assign(beta_rw, - cons_list(index_uni((k_rw1 + i)), - cons_list(index_uni((t + 1)), nil_index_list())), - (rvalue(beta_rw, - cons_list(index_uni((k_rw1 + i)), - cons_list(index_uni(t), nil_index_list())), "beta_rw") + - rvalue(nu, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "nu")), - "assigning variable beta_rw"); - current_statement__ = 39; - assign(nu, - cons_list(index_uni(i), - cons_list(index_uni((t + 1)), nil_index_list())), - normal_rng( - rvalue(nu, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "nu"), - (rvalue(gamma_rw2, - cons_list(index_uni(i), - cons_list(index_uni(t), nil_index_list())), "gamma_rw2") - * sigma_rw2[(i - 1)]), base_rng__), "assigning variable nu"); - }} - current_statement__ = 46; - for (int t = 1; t <= n; ++t) { - current_statement__ = 44; - assign(y_rep, cons_list(index_uni(t), nil_index_list()), - normal_rng( - dot_product( - rvalue(xreg_rw, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg_rw"), - rvalue(beta_rw, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "beta_rw")), - (gamma_y[(t - 1)] * sigma_y), base_rng__), - "assigning variable y_rep");} - { - current_statement__ = 47; - validate_non_negative_index("states", "m", m); - current_statement__ = 48; - validate_non_negative_index("states", "n", n); - Eigen::Matrix states; - states = Eigen::Matrix(m, n); - stan::math::fill(states, std::numeric_limits::quiet_NaN()); - - current_statement__ = 49; - assign(states, nil_index_list(), - gaussian_smoother(subtract(y_, y_rep), y_miss, a1, P1, - pow(sigma_y, 2), Tt, Rt, xreg_rw, gamma2_y, pstream__), - "assigning variable states"); - current_statement__ = 50; - assign(beta_rw, nil_index_list(), - add(stan::model::deep_copy(beta_rw), - rvalue(states, - cons_list(index_min_max(1, k), - cons_list(index_min_max(1, n), nil_index_list())), - "states")), "assigning variable beta_rw"); - current_statement__ = 52; - if (logical_gt(k_rw2, 0)) { - current_statement__ = 51; - assign(nu, nil_index_list(), - add(stan::model::deep_copy(nu), - rvalue(states, - cons_list(index_min_max((k + 1), m), - cons_list(index_min_max(1, n), nil_index_list())), - "states")), "assigning variable nu"); - } - } - current_statement__ = 57; - for (int t = 1; t <= n; ++t) { - current_statement__ = 54; - assign(y_fit, cons_list(index_uni(t), nil_index_list()), - (xbeta[(t - 1)] + - dot_product( - rvalue(xreg_rw, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "xreg_rw"), - rvalue(beta_rw, - cons_list(index_omni(), - cons_list(index_uni(t), nil_index_list())), "beta_rw"))), - "assigning variable y_fit"); - current_statement__ = 55; - assign(y_rep, cons_list(index_uni(t), nil_index_list()), - normal_rng(y_fit[(t - 1)], (gamma_y[(t - 1)] * sigma_y), - base_rng__), "assigning variable y_rep");} - } - for (int sym1__ = 1; sym1__ <= y_rep_1dim__; ++sym1__) { - vars__.emplace_back(y_rep[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= beta_rw_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - vars__.emplace_back( - rvalue(beta_rw, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), "beta_rw")); - }} - for (int sym1__ = 1; sym1__ <= nu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= k_rw2; ++sym2__) { - vars__.emplace_back( - rvalue(nu, - cons_list(index_uni(sym2__), - cons_list(index_uni(sym1__), nil_index_list())), "nu"));}} - for (int sym1__ = 1; sym1__ <= y_fit_1dim__; ++sym1__) { - vars__.emplace_back(y_fit[(sym1__ - 1)]);} - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - } // write_array_impl() - - template * = nullptr, stan::require_vector_like_vt* = nullptr> - inline void transform_inits_impl(const stan::io::var_context& context__, - VecI& params_i__, VecVar& vars__, - std::ostream* pstream__ = nullptr) const { - using local_scalar_t__ = double; - vars__.clear(); - vars__.reserve(num_params_r__); - - try { - int pos__; - pos__ = std::numeric_limits::min(); - - pos__ = 1; - Eigen::Matrix beta_fixed; - beta_fixed = Eigen::Matrix(k_fixed); - stan::math::fill(beta_fixed, std::numeric_limits::quiet_NaN()); - - { - std::vector beta_fixed_flat__; - current_statement__ = 1; - assign(beta_fixed_flat__, nil_index_list(), - context__.vals_r("beta_fixed"), - "assigning variable beta_fixed_flat__"); - current_statement__ = 1; - pos__ = 1; - current_statement__ = 1; - for (int sym1__ = 1; sym1__ <= k_fixed; ++sym1__) { - current_statement__ = 1; - assign(beta_fixed, cons_list(index_uni(sym1__), nil_index_list()), - beta_fixed_flat__[(pos__ - 1)], "assigning variable beta_fixed"); - current_statement__ = 1; - pos__ = (pos__ + 1);} - } - std::vector sigma_rw1; - sigma_rw1 = std::vector(k_rw1, std::numeric_limits::quiet_NaN()); - - current_statement__ = 2; - assign(sigma_rw1, nil_index_list(), context__.vals_r("sigma_rw1"), - "assigning variable sigma_rw1"); - std::vector sigma_rw1_free__; - sigma_rw1_free__ = std::vector(k_rw1, std::numeric_limits::quiet_NaN()); - - current_statement__ = 2; - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - current_statement__ = 2; - assign(sigma_rw1_free__, - cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_free(sigma_rw1[(sym1__ - 1)], 0), - "assigning variable sigma_rw1_free__");} - std::vector sigma_rw2; - sigma_rw2 = std::vector(k_rw2, std::numeric_limits::quiet_NaN()); - - current_statement__ = 3; - assign(sigma_rw2, nil_index_list(), context__.vals_r("sigma_rw2"), - "assigning variable sigma_rw2"); - std::vector sigma_rw2_free__; - sigma_rw2_free__ = std::vector(k_rw2, std::numeric_limits::quiet_NaN()); - - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - current_statement__ = 3; - assign(sigma_rw2_free__, - cons_list(index_uni(sym1__), nil_index_list()), - stan::math::lb_free(sigma_rw2[(sym1__ - 1)], 0), - "assigning variable sigma_rw2_free__");} - double sigma_y; - sigma_y = std::numeric_limits::quiet_NaN(); - - current_statement__ = 4; - sigma_y = context__.vals_r("sigma_y")[(1 - 1)]; - double sigma_y_free__; - sigma_y_free__ = std::numeric_limits::quiet_NaN(); - - current_statement__ = 4; - sigma_y_free__ = stan::math::lb_free(sigma_y, 0); - for (int sym1__ = 1; sym1__ <= k_fixed; ++sym1__) { - vars__.emplace_back(beta_fixed[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - vars__.emplace_back(sigma_rw1_free__[(sym1__ - 1)]);} - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - vars__.emplace_back(sigma_rw2_free__[(sym1__ - 1)]);} - vars__.emplace_back(sigma_y_free__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - // Next line prevents compiler griping about no return - throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***"); - } - } // transform_inits_impl() - - inline void get_param_names(std::vector& names__) const { - - names__.clear(); - names__.emplace_back("beta_fixed"); - names__.emplace_back("sigma_rw1"); - names__.emplace_back("sigma_rw2"); - names__.emplace_back("sigma_y"); - names__.emplace_back("log_lik"); - names__.emplace_back("Rt"); - names__.emplace_back("xbeta"); - names__.emplace_back("y_"); - names__.emplace_back("y_rep"); - names__.emplace_back("beta_rw"); - names__.emplace_back("nu"); - names__.emplace_back("y_fit"); - } // get_param_names() - - inline void get_dims(std::vector>& dimss__) const { - dimss__.clear(); - dimss__.emplace_back(std::vector{static_cast(k_fixed)}); - - dimss__.emplace_back(std::vector{static_cast(k_rw1)}); - - dimss__.emplace_back(std::vector{static_cast(k_rw2)}); - - dimss__.emplace_back(std::vector{}); - - dimss__.emplace_back(std::vector{static_cast(n)}); - - dimss__.emplace_back(std::vector{static_cast(m), - static_cast(n)}); - - dimss__.emplace_back(std::vector{static_cast(n)}); - - dimss__.emplace_back(std::vector{static_cast(n)}); - - dimss__.emplace_back(std::vector{ - static_cast(y_rep_1dim__)}); - - dimss__.emplace_back(std::vector{static_cast(k), - static_cast(beta_rw_2dim__) - }); - - dimss__.emplace_back(std::vector{static_cast(k_rw2), - static_cast(nu_2dim__)}); - - dimss__.emplace_back(std::vector{ - static_cast(y_fit_1dim__)}); - - } // get_dims() - - inline void constrained_param_names( - std::vector& param_names__, - bool emit_transformed_parameters__ = true, - bool emit_generated_quantities__ = true) const - final { - - for (int sym1__ = 1; sym1__ <= k_fixed; ++sym1__) { - { - param_names__.emplace_back(std::string() + "beta_fixed" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - { - param_names__.emplace_back(std::string() + "sigma_rw1" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - { - param_names__.emplace_back(std::string() + "sigma_rw2" + '.' + std::to_string(sym1__)); - }} - param_names__.emplace_back(std::string() + "sigma_y"); - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - param_names__.emplace_back(std::string() + "log_lik" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= m; ++sym2__) { - { - param_names__.emplace_back(std::string() + "Rt" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - param_names__.emplace_back(std::string() + "xbeta" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_" + '.' + std::to_string(sym1__)); - }} - } - - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= y_rep_1dim__; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_rep" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= beta_rw_2dim__; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - { - param_names__.emplace_back(std::string() + "beta_rw" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - for (int sym1__ = 1; sym1__ <= nu_2dim__; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k_rw2; ++sym2__) { - { - param_names__.emplace_back(std::string() + "nu" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - for (int sym1__ = 1; sym1__ <= y_fit_1dim__; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_fit" + '.' + std::to_string(sym1__)); - }} - } - - } // constrained_param_names() - - inline void unconstrained_param_names( - std::vector& param_names__, - bool emit_transformed_parameters__ = true, - bool emit_generated_quantities__ = true) const - final { - - for (int sym1__ = 1; sym1__ <= k_fixed; ++sym1__) { - { - param_names__.emplace_back(std::string() + "beta_fixed" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= k_rw1; ++sym1__) { - { - param_names__.emplace_back(std::string() + "sigma_rw1" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= k_rw2; ++sym1__) { - { - param_names__.emplace_back(std::string() + "sigma_rw2" + '.' + std::to_string(sym1__)); - }} - param_names__.emplace_back(std::string() + "sigma_y"); - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - param_names__.emplace_back(std::string() + "log_lik" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= m; ++sym2__) { - { - param_names__.emplace_back(std::string() + "Rt" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - param_names__.emplace_back(std::string() + "xbeta" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= n; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_" + '.' + std::to_string(sym1__)); - }} - } - - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= y_rep_1dim__; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_rep" + '.' + std::to_string(sym1__)); - }} - for (int sym1__ = 1; sym1__ <= beta_rw_2dim__; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k; ++sym2__) { - { - param_names__.emplace_back(std::string() + "beta_rw" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - for (int sym1__ = 1; sym1__ <= nu_2dim__; ++sym1__) { - { - for (int sym2__ = 1; sym2__ <= k_rw2; ++sym2__) { - { - param_names__.emplace_back(std::string() + "nu" + '.' + std::to_string(sym2__) + '.' + std::to_string(sym1__)); - }} - }} - for (int sym1__ = 1; sym1__ <= y_fit_1dim__; ++sym1__) { - { - param_names__.emplace_back(std::string() + "y_fit" + '.' + std::to_string(sym1__)); - }} - } - - } // unconstrained_param_names() - - inline std::string get_constrained_sizedtypes() const { - stringstream s__; - s__ << "[{\"name\":\"beta_fixed\",\"type\":{\"name\":\"vector\",\"length\":" << k_fixed << "},\"block\":\"parameters\"},{\"name\":\"sigma_rw1\",\"type\":{\"name\":\"array\",\"length\":" << k_rw1 << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"sigma_rw2\",\"type\":{\"name\":\"array\",\"length\":" << k_rw2 << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"sigma_y\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"Rt\",\"type\":{\"name\":\"matrix\",\"rows\":" << m << ",\"cols\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"xbeta\",\"type\":{\"name\":\"vector\",\"length\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"y_\",\"type\":{\"name\":\"vector\",\"length\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"y_rep\",\"type\":{\"name\":\"vector\",\"length\":" << y_rep_1dim__ << "},\"block\":\"generated_quantities\"},{\"name\":\"beta_rw\",\"type\":{\"name\":\"matrix\",\"rows\":" << k << ",\"cols\":" << beta_rw_2dim__ << "},\"block\":\"generated_quantities\"},{\"name\":\"nu\",\"type\":{\"name\":\"matrix\",\"rows\":" << k_rw2 << ",\"cols\":" << nu_2dim__ << "},\"block\":\"generated_quantities\"},{\"name\":\"y_fit\",\"type\":{\"name\":\"vector\",\"length\":" << y_fit_1dim__ << "},\"block\":\"generated_quantities\"}]"; - return s__.str(); - } // get_constrained_sizedtypes() - - inline std::string get_unconstrained_sizedtypes() const { - stringstream s__; - s__ << "[{\"name\":\"beta_fixed\",\"type\":{\"name\":\"vector\",\"length\":" << k_fixed << "},\"block\":\"parameters\"},{\"name\":\"sigma_rw1\",\"type\":{\"name\":\"array\",\"length\":" << k_rw1 << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"sigma_rw2\",\"type\":{\"name\":\"array\",\"length\":" << k_rw2 << ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"sigma_y\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"Rt\",\"type\":{\"name\":\"matrix\",\"rows\":" << m << ",\"cols\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"xbeta\",\"type\":{\"name\":\"vector\",\"length\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"y_\",\"type\":{\"name\":\"vector\",\"length\":" << n << "},\"block\":\"transformed_parameters\"},{\"name\":\"y_rep\",\"type\":{\"name\":\"vector\",\"length\":" << y_rep_1dim__ << "},\"block\":\"generated_quantities\"},{\"name\":\"beta_rw\",\"type\":{\"name\":\"matrix\",\"rows\":" << k << ",\"cols\":" << beta_rw_2dim__ << "},\"block\":\"generated_quantities\"},{\"name\":\"nu\",\"type\":{\"name\":\"matrix\",\"rows\":" << k_rw2 << ",\"cols\":" << nu_2dim__ << "},\"block\":\"generated_quantities\"},{\"name\":\"y_fit\",\"type\":{\"name\":\"vector\",\"length\":" << y_fit_1dim__ << "},\"block\":\"generated_quantities\"}]"; - return s__.str(); - } // get_unconstrained_sizedtypes() - - - // Begin method overload boilerplate - template - inline void write_array(RNG& base_rng, - Eigen::Matrix& params_r, - Eigen::Matrix& vars, - const bool emit_transformed_parameters = true, - const bool emit_generated_quantities = true, - std::ostream* pstream = nullptr) const { - std::vector vars_vec(vars.size()); - std::vector params_i; - write_array_impl(base_rng, params_r, params_i, vars_vec, - emit_transformed_parameters, emit_generated_quantities, pstream); - vars.resize(vars_vec.size()); - for (int i = 0; i < vars.size(); ++i) { - vars.coeffRef(i) = vars_vec[i]; - } - } - template - inline void write_array(RNG& base_rng, std::vector& params_r, - std::vector& params_i, - std::vector& vars, - bool emit_transformed_parameters = true, - bool emit_generated_quantities = true, - std::ostream* pstream = nullptr) const { - write_array_impl(base_rng, params_r, params_i, vars, emit_transformed_parameters, emit_generated_quantities, pstream); - } - template - inline T_ log_prob(Eigen::Matrix& params_r, - std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template - inline T__ log_prob(std::vector& params_r, - std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - - inline void transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, - std::ostream* pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits_impl(context, params_i, params_r_vec, pstream); - params_r.resize(params_r_vec.size()); - for (int i = 0; i < params_r.size(); ++i) { - params_r.coeffRef(i) = params_r_vec[i]; - } - } - inline void transform_inits(const stan::io::var_context& context, - std::vector& params_i, - std::vector& vars, - std::ostream* pstream = nullptr) const final { - transform_inits_impl(context, params_i, vars, pstream); - } -}; -} -using stan_model = model_walker_lm_namespace::model_walker_lm; -#ifndef USING_R -// Boilerplate -stan::model::model_base& new_model( - stan::io::var_context& data_context, - unsigned int seed, - std::ostream* msg_stream) { - stan_model* m = new stan_model(data_context, seed, msg_stream); - return *m; -} -stan::math::profile_map& get_stan_profile_data() { - return model_walker_lm_namespace::profiles__; -} -#endif -#endif From 92278e7649c62d5015ac38e9429b2e9b06b8b2fc Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 9 Feb 2023 07:56:39 +0200 Subject: [PATCH 2/6] Update workflow --- .github/workflows/R-CMD-check.yaml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index e4c311d..03eaa2b 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -22,9 +22,12 @@ jobs: fail-fast: false matrix: config: + config: + - {os: macOS-latest, r: 'release'} - {os: windows-latest, r: 'release'} - - {os: macOS-latest, r: 'release'} - - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true @@ -34,11 +37,11 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} - - uses: r-lib/actions/setup-pandoc@v1 + - uses: r-lib/actions/setup-pandoc@v2 - name: Query dependencies run: | @@ -63,11 +66,10 @@ jobs: eval sudo $cmd done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') - - name: Install dependencies - run: | - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("rcmdcheck") - shell: Rscript {0} + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check - name: Check env: From 2df98aa4e24aae3a1ddd0a7b0c2dcad8ba966dfb Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 9 Feb 2023 07:57:19 +0200 Subject: [PATCH 3/6] Update workflow --- .github/workflows/R-CMD-check.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 03eaa2b..dbd34d6 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -21,7 +21,6 @@ jobs: strategy: fail-fast: false matrix: - config: config: - {os: macOS-latest, r: 'release'} - {os: windows-latest, r: 'release'} From 2adf5987fe4eecfdea4d2333ccbda45bceb663a5 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 9 Feb 2023 08:09:16 +0200 Subject: [PATCH 4/6] Update RcppExports --- src/RcppExports.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 455592b..6ea01ff 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -61,18 +61,9 @@ BEGIN_RCPP END_RCPP } -RcppExport SEXP _rcpp_module_boot_stan_fit4rw1_model_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4rw1_model_naive_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4walker_glm_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4walker_lm_mod(); - static const R_CallMethodDef CallEntries[] = { {"_walker_predict_walker", (DL_FUNC) &_walker_predict_walker, 13}, {"_walker_predict_walker_glm", (DL_FUNC) &_walker_predict_walker_glm, 15}, - {"_rcpp_module_boot_stan_fit4rw1_model_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4rw1_model_mod, 0}, - {"_rcpp_module_boot_stan_fit4rw1_model_naive_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4rw1_model_naive_mod, 0}, - {"_rcpp_module_boot_stan_fit4walker_glm_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4walker_glm_mod, 0}, - {"_rcpp_module_boot_stan_fit4walker_lm_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4walker_lm_mod, 0}, {NULL, NULL, 0} }; From 7e3c79b1de505663735a7e39cd52afc7719dbe28 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 9 Feb 2023 08:21:15 +0200 Subject: [PATCH 5/6] Update linking --- configure | 1 + configure.win | 1 + 2 files changed, 2 insertions(+) diff --git a/configure b/configure index 1c04798..c0759ce 100755 --- a/configure +++ b/configure @@ -2,3 +2,4 @@ #! /bin/sh "${R_HOME}/bin/Rscript" -e "rstantools::rstan_config()" +echo "PKG_LIBS += \$(LAPACK_LIBS) \$(BLAS_LIBS) \$(FLIBS)" >> src/Makevars diff --git a/configure.win b/configure.win index 94d77bd..b0e7c85 100755 --- a/configure.win +++ b/configure.win @@ -2,3 +2,4 @@ #! /bin/sh "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "rstantools::rstan_config()" +echo "PKG_LIBS += \$(LAPACK_LIBS) \$(BLAS_LIBS) \$(FLIBS)" >> src/Makevars.win From 54997f3ea6548d4cdf49aad18b6601c1a92a318b Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 9 Feb 2023 09:39:21 +0200 Subject: [PATCH 6/6] Trigger CI