diff --git a/R/coef.R b/R/coef.R index caa12b5f..f9ba611c 100644 --- a/R/coef.R +++ b/R/coef.R @@ -53,17 +53,29 @@ coef.nhmm <- function(object, probs = c(0.025, 0.975), ...) { p_s <- length(beta_s_raw) p_o <- length(beta_o_raw) sds <- try( - sqrt(diag(solve(-object$estimation_results$hessian))), + diag(solve(-object$estimation_results$hessian)), silent = TRUE ) if (inherits(sds, "try-error")) { warning_( paste0( - "Standard errors could not be computed due to singular Hessian.", + "Standard errors could not be computed due to singular Hessian. ", "Confidence intervals will not be provided." ) ) sds <- rep(NA, p_i + p_s + p_o) + } else { + if (any(sds < 0)) { + warning_( + paste0( + "Standard errors could not be computed due to negative variances. ", + "Confidence intervals will not be provided." + ) + ) + sds <- rep(NA, p_i + p_s + p_o) + } else { + sds <- sqrt(sds) + } } for(i in seq_along(probs)) { q <- qnorm(probs[i]) diff --git a/R/estimate_mnhmm.R b/R/estimate_mnhmm.R index b3513542..80fd40f9 100644 --- a/R/estimate_mnhmm.R +++ b/R/estimate_mnhmm.R @@ -44,14 +44,14 @@ estimate_mnhmm <- function( data = NULL, time = NULL, id = NULL, state_names = NULL, channel_names = NULL, cluster_names = NULL, inits = "random", init_sd = 2, restarts = 0L, threads = 1L, store_data = TRUE, verbose = TRUE, - restart_method = "1", ...) { + restart_method = "1", penalize = TRUE, penalty = 5, ...) { call <- match.call() model <- build_mnhmm( observations, n_states, n_clusters, initial_formula, transition_formula, emission_formula, cluster_formula, data, time, id, state_names, channel_names, cluster_names - ) + ) stopifnot_( checkmate::test_flag(x = store_data), "Argument {.arg store_data} must be a single {.cls logical} value.") @@ -59,9 +59,11 @@ estimate_mnhmm <- function( model$data <- data } if (restart_method == "1") { - out <- fit_mnhmm(model, inits, init_sd, restarts, threads, verbose, ...) + out <- fit_mnhmm(model, inits, init_sd, restarts, threads, verbose, + penalize, penalty, ...) } else { - out <- fit_mnhmm2(model, inits, init_sd, restarts, threads, verbose, ...) + out <- fit_mnhmm2(model, inits, init_sd, restarts, threads, verbose, + penalize, penalty, ...) } attr(out, "call") <- call out diff --git a/R/estimate_nhmm.R b/R/estimate_nhmm.R index cb30f82d..ad4499c2 100644 --- a/R/estimate_nhmm.R +++ b/R/estimate_nhmm.R @@ -73,7 +73,7 @@ estimate_nhmm <- function( transition_formula = ~1, emission_formula = ~1, data = NULL, time = NULL, id = NULL, state_names = NULL, channel_names = NULL, inits = "random", init_sd = 2, restarts = 0L, threads = 1L, - store_data = TRUE, verbose = TRUE, ...) { + store_data = TRUE, verbose = TRUE, penalize = TRUE, penalty = 5, ...) { call <- match.call() @@ -88,7 +88,8 @@ estimate_nhmm <- function( if (store_data) { model$data <- data } - out <- fit_nhmm(model, inits, init_sd, restarts, threads, verbose, ...) + out <- fit_nhmm(model, inits, init_sd, restarts, threads, verbose, + penalize, penalty, ...) attr(out, "call") <- call out } diff --git a/R/fit_mnhmm.R b/R/fit_mnhmm.R index 425587fb..bdff8294 100644 --- a/R/fit_mnhmm.R +++ b/R/fit_mnhmm.R @@ -1,7 +1,7 @@ #' Estimate a Mixture Non-homogeneous Hidden Markov Model #' #' @noRd -fit_mnhmm <- function(model, inits, init_sd, restarts, threads, verbose, ...) { +fit_mnhmm <- function(model, inits, init_sd, restarts, threads, verbose, penalize, penalty, ...) { stopifnot_( checkmate::test_int(x = threads, lower = 1L), "Argument {.arg threads} must be a single positive integer." @@ -57,6 +57,8 @@ fit_mnhmm <- function(model, inits, init_sd, restarts, threads, verbose, ...) { c(list( model_code, init = init, data = list( + penalty = penalty, + penalize = penalize, N = model$n_sequences, T = model$sequence_lengths, max_T = model$length_of_sequences, @@ -107,6 +109,8 @@ fit_mnhmm <- function(model, inits, init_sd, restarts, threads, verbose, ...) { c(list( model_code, data = list( + penalty = penalty, + penalize = penalize, N = model$n_sequences, T = model$sequence_lengths, max_T = model$length_of_sequences, diff --git a/R/fit_mnhmm2.R b/R/fit_mnhmm2.R index e39c0514..be38b0cb 100644 --- a/R/fit_mnhmm2.R +++ b/R/fit_mnhmm2.R @@ -1,7 +1,8 @@ #' Estimate a Mixture Non-homogeneous Hidden Markov Model #' #' @noRd -fit_mnhmm2 <- function(model, inits, init_sd, restarts, threads, verbose, ...) { +fit_mnhmm2 <- function(model, inits, init_sd, restarts, threads, verbose, + penalize, penalty, ...) { stopifnot_( checkmate::test_int(x = threads, lower = 1L), "Argument {.arg threads} must be a single positive integer." @@ -61,6 +62,8 @@ fit_mnhmm2 <- function(model, inits, init_sd, restarts, threads, verbose, ...) { c(list( model_code, init = init, data = list( + penalize = penalize, + penalty = penalty, N = model$n_sequences, T = model$sequence_lengths, max_T = model$length_of_sequences, @@ -99,6 +102,8 @@ fit_mnhmm2 <- function(model, inits, init_sd, restarts, threads, verbose, ...) { c(list( model_code, init = out0[[idx[i]]]$par, data = list( + penalize = penalize, + penalty = penalty, N = model$n_sequences, T = model$sequence_lengths, max_T = model$length_of_sequences, @@ -149,6 +154,8 @@ fit_mnhmm2 <- function(model, inits, init_sd, restarts, threads, verbose, ...) { c(list( model_code, data = list( + penalize = penalize, + penalty = penalty, N = model$n_sequences, T = model$sequence_lengths, max_T = model$length_of_sequences, diff --git a/R/fit_nhmm.R b/R/fit_nhmm.R index 8945b172..97073db1 100644 --- a/R/fit_nhmm.R +++ b/R/fit_nhmm.R @@ -1,7 +1,7 @@ #' Estimate a Non-homogeneous Hidden Markov Model #' #' @noRd -fit_nhmm <- function(model, inits, init_sd, restarts, threads, verbose, ...) { +fit_nhmm <- function(model, inits, init_sd, restarts, threads, verbose, penalize, penalty, ...) { stopifnot_( checkmate::test_int(x = threads, lower = 1L), "Argument {.arg threads} must be a single positive integer." @@ -53,6 +53,8 @@ fit_nhmm <- function(model, inits, init_sd, restarts, threads, verbose, ...) { c(list( model_code, init = init, data = list( + penalty = penalty, + penalize = penalize, N = model$n_sequences, T = model$sequence_lengths, max_T = model$length_of_sequences, @@ -100,6 +102,8 @@ fit_nhmm <- function(model, inits, init_sd, restarts, threads, verbose, ...) { c(list( model_code, data = list( + penalty = penalty, + penalize = penalize, N = model$n_sequences, T = model$sequence_lengths, max_T = model$length_of_sequences, diff --git a/inst/stan/include/data_covariates.stan b/inst/stan/include/data_covariates.stan index 884ab084..63092d98 100644 --- a/inst/stan/include/data_covariates.stan +++ b/inst/stan/include/data_covariates.stan @@ -4,5 +4,5 @@ array[max_T, N] vector[K_s] X_s; // covariates for transitions (including the intercept) int K_o; // number of covariates for emission probabilities (including the intercept) array[max_T, N] vector[K_o] X_o; // covariates for emissions (including the intercept) - - + int penalize; // penalize the likelihood of the model + real penalty; // standard deviation of the priors diff --git a/inst/stan/include/priors_multichannel.stan b/inst/stan/include/priors_multichannel.stan index d183876d..189632fc 100644 --- a/inst/stan/include/priors_multichannel.stan +++ b/inst/stan/include/priors_multichannel.stan @@ -1,7 +1,9 @@ real prior = 0; -// priors for (very weak) regularisation -prior += normal_lpdf(to_vector(beta_i_raw) | 0, 5); -for(s in 1:S) { - prior += normal_lpdf(to_vector(beta_s_raw[s]) | 0, 5); +if (penalize == 1) { + // priors for (very weak) regularisation + prior += normal_lpdf(to_vector(beta_i_raw) | 0, penalty); + for(s in 1:S) { + prior += normal_lpdf(to_vector(beta_s_raw[s]) | 0, penalty); + } + prior += normal_lpdf(beta_o_raw | 0, penalty); } -prior += normal_lpdf(beta_o_raw | 0, 5); diff --git a/inst/stan/include/priors_multichannel_mixture.stan b/inst/stan/include/priors_multichannel_mixture.stan index 494a833d..96ba3f1c 100644 --- a/inst/stan/include/priors_multichannel_mixture.stan +++ b/inst/stan/include/priors_multichannel_mixture.stan @@ -1,10 +1,12 @@ // priors for (very weak) regularisation real prior = 0; -for (d in 1:D){ - prior += normal_lpdf(to_vector(beta_i_raw[d]) | 0, 5); - for(s in 1:S) { - prior += normal_lpdf(to_vector(beta_s_raw[d, s]) | 0, 5); +if (penalize == 1) { + for (d in 1:D){ + prior += normal_lpdf(to_vector(beta_i_raw[d]) | 0, penalty); + for(s in 1:S) { + prior += normal_lpdf(to_vector(beta_s_raw[d, s]) | 0, penalty); + } + prior += normal_lpdf(beta_o_raw[d] | 0, penalty); } - prior += normal_lpdf(beta_o_raw[d] | 0, 5); + prior += normal_lpdf(to_vector(theta_raw) | 0, penalty); } -prior += normal_lpdf(to_vector(theta_raw) | 0, 5); diff --git a/inst/stan/include/priors_singlechannel.stan b/inst/stan/include/priors_singlechannel.stan index 6786f080..f5c5fa86 100644 --- a/inst/stan/include/priors_singlechannel.stan +++ b/inst/stan/include/priors_singlechannel.stan @@ -1,6 +1,9 @@ // priors for (very weak) regularisation -real prior = normal_lpdf(to_vector(beta_i_raw) | 0, 5); -for(s in 1:S) { - prior += normal_lpdf(to_vector(beta_s_raw[s]) | 0, 5); - prior += normal_lpdf(to_vector(beta_o_raw[s]) | 0, 5); +real prior = 0; +if (penalize == 1) { + prior += normal_lpdf(to_vector(beta_i_raw) | 0, penalty); + for(s in 1:S) { + prior += normal_lpdf(to_vector(beta_s_raw[s]) | 0, penalty); + prior += normal_lpdf(to_vector(beta_o_raw[s]) | 0, penalty); + } } diff --git a/inst/stan/include/priors_singlechannel_mixture.stan b/inst/stan/include/priors_singlechannel_mixture.stan index a57de49b..7ec86711 100644 --- a/inst/stan/include/priors_singlechannel_mixture.stan +++ b/inst/stan/include/priors_singlechannel_mixture.stan @@ -1,10 +1,12 @@ // priors for (very weak) regularisation real prior = 0; -for (d in 1:D){ - prior += normal_lpdf(to_vector(beta_i_raw[d]) | 0, 5); - for(s in 1:S) { - prior += normal_lpdf(to_vector(beta_s_raw[d, s]) | 0, 5); - prior += normal_lpdf(to_vector(beta_o_raw[d, s]) | 0, 5); +if (penalize == 1) { + for (d in 1:D){ + prior += normal_lpdf(to_vector(beta_i_raw[d]) | 0, penalty); + for(s in 1:S) { + prior += normal_lpdf(to_vector(beta_s_raw[d, s]) | 0, penalty); + prior += normal_lpdf(to_vector(beta_o_raw[d, s]) | 0, penalty); + } } + prior += normal_lpdf(to_vector(theta_raw) | 0, penalty); } -prior += normal_lpdf(to_vector(theta_raw) | 0, 5); diff --git a/inst/stan/mnhmm.stan b/inst/stan/mnhmm.stan index 42b80943..13e2f05f 100644 --- a/inst/stan/mnhmm.stan +++ b/inst/stan/mnhmm.stan @@ -22,7 +22,6 @@ model { target += log_lik; } generated quantities { - print("not yet!"); real ploglik_N = prior + log_lik; if (N > N_sample) { ploglik_N = prior + loglik_sc_mix(beta_i_raw, beta_s_raw, diff --git a/src/stanExports_mnhmm.h b/src/stanExports_mnhmm.h index de1f3973..2da1f767 100644 --- a/src/stanExports_mnhmm.h +++ b/src/stanExports_mnhmm.h @@ -27,29 +27,30 @@ namespace model_mnhmm_namespace { using stan::model::model_base_crtp; using namespace stan::math; stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = +static constexpr std::array locations_array__ = {" (found before start of program)", - " (in 'string', line 120, column 2 to column 41)", - " (in 'string', line 122, column 2 to column 44)", + " (in 'string', line 122, column 2 to column 41)", " (in 'string', line 124, column 2 to column 44)", - " (in 'string', line 125, column 2 to column 31)", - " (in 'string', line 129, column 0 to column 15)", - " (in 'string', line 138, column 2 to line 139, column 48)", - " (in 'string', line 147, column 2 to column 35)", - " (in 'string', line 131, column 2 to column 56)", - " (in 'string', line 133, column 4 to column 61)", - " (in 'string', line 134, column 4 to column 61)", - " (in 'string', line 132, column 16 to line 135, column 3)", - " (in 'string', line 132, column 2 to line 135, column 3)", - " (in 'string', line 130, column 14 to line 136, column 1)", - " (in 'string', line 130, column 0 to line 136, column 1)", - " (in 'string', line 137, column 0 to column 50)", - " (in 'string', line 146, column 2 to column 20)", - " (in 'string', line 149, column 4 to line 151, column 14)", - " (in 'string', line 148, column 20 to line 152, column 3)", - " (in 'string', line 148, column 2 to line 152, column 3)", - " (in 'string', line 142, column 2 to column 18)", - " (in 'string', line 143, column 2 to column 20)", + " (in 'string', line 126, column 2 to column 44)", + " (in 'string', line 127, column 2 to column 31)", + " (in 'string', line 131, column 0 to column 15)", + " (in 'string', line 142, column 2 to line 143, column 48)", + " (in 'string', line 150, column 2 to column 35)", + " (in 'string', line 134, column 4 to column 64)", + " (in 'string', line 136, column 6 to column 69)", + " (in 'string', line 137, column 6 to column 69)", + " (in 'string', line 135, column 18 to line 138, column 5)", + " (in 'string', line 135, column 4 to line 138, column 5)", + " (in 'string', line 133, column 16 to line 139, column 3)", + " (in 'string', line 133, column 2 to line 139, column 3)", + " (in 'string', line 140, column 2 to column 58)", + " (in 'string', line 132, column 19 to line 141, column 1)", + " (in 'string', line 132, column 0 to line 141, column 1)", + " (in 'string', line 152, column 4 to line 154, column 14)", + " (in 'string', line 151, column 20 to line 155, column 3)", + " (in 'string', line 151, column 2 to line 155, column 3)", + " (in 'string', line 146, column 2 to column 18)", + " (in 'string', line 147, column 2 to column 20)", " (in 'string', line 100, column 2 to column 17)", " (in 'string', line 101, column 2 to column 21)", " (in 'string', line 102, column 8 to column 9)", @@ -76,24 +77,26 @@ static constexpr std::array locations_array__ = " (in 'string', line 113, column 15 to column 16)", " (in 'string', line 113, column 25 to column 28)", " (in 'string', line 113, column 2 to column 34)", - " (in 'string', line 114, column 2 to column 17)", - " (in 'string', line 115, column 2 to column 19)", - " (in 'string', line 116, column 8 to column 9)", - " (in 'string', line 116, column 18 to column 21)", - " (in 'string', line 116, column 2 to column 27)", - " (in 'string', line 120, column 8 to column 9)", - " (in 'string', line 120, column 18 to column 23)", - " (in 'string', line 120, column 25 to column 28)", + " (in 'string', line 114, column 2 to column 32)", + " (in 'string', line 115, column 2 to column 24)", + " (in 'string', line 116, column 2 to column 17)", + " (in 'string', line 117, column 2 to column 19)", + " (in 'string', line 118, column 8 to column 9)", + " (in 'string', line 118, column 18 to column 21)", + " (in 'string', line 118, column 2 to column 27)", " (in 'string', line 122, column 8 to column 9)", - " (in 'string', line 122, column 11 to column 12)", - " (in 'string', line 122, column 21 to column 26)", - " (in 'string', line 122, column 28 to column 31)", + " (in 'string', line 122, column 18 to column 23)", + " (in 'string', line 122, column 25 to column 28)", " (in 'string', line 124, column 8 to column 9)", " (in 'string', line 124, column 11 to column 12)", " (in 'string', line 124, column 21 to column 26)", " (in 'string', line 124, column 28 to column 31)", - " (in 'string', line 125, column 9 to column 14)", - " (in 'string', line 125, column 16 to column 19)", + " (in 'string', line 126, column 8 to column 9)", + " (in 'string', line 126, column 11 to column 12)", + " (in 'string', line 126, column 21 to column 26)", + " (in 'string', line 126, column 28 to column 31)", + " (in 'string', line 127, column 9 to column 14)", + " (in 'string', line 127, column 16 to column 19)", " (in 'string', line 8, column 4 to column 25)", " (in 'string', line 9, column 10 to column 16)", " (in 'string', line 9, column 4 to column 24)", @@ -254,21 +257,21 @@ add(const std::vector& x, const std::vector& y, std::ostream* (void) DUMMY_VAR__; try { int x_size = std::numeric_limits::min(); - current_statement__ = 66; + current_statement__ = 69; x_size = stan::math::size(x); - current_statement__ = 67; + current_statement__ = 70; stan::math::validate_non_negative_index("z", "x_size", x_size); std::vector z = std::vector(x_size, std::numeric_limits::min()); - current_statement__ = 71; + current_statement__ = 74; for (int i = 1; i <= x_size; ++i) { - current_statement__ = 69; + current_statement__ = 72; stan::model::assign(z, (stan::model::rvalue(x, "x", stan::model::index_uni(i)) + stan::model::rvalue(y, "y", stan::model::index_uni(i))), "assigning variable z", stan::model::index_uni(i)); } - current_statement__ = 72; + current_statement__ = 75; return z; } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -286,20 +289,20 @@ add(const int& x, const std::vector& y, std::ostream* pstream__) { (void) DUMMY_VAR__; try { int y_size = std::numeric_limits::min(); - current_statement__ = 74; + current_statement__ = 77; y_size = stan::math::size(y); - current_statement__ = 75; + current_statement__ = 78; stan::math::validate_non_negative_index("z", "y_size", y_size); std::vector z = std::vector(y_size, std::numeric_limits::min()); - current_statement__ = 79; + current_statement__ = 82; for (int i = 1; i <= y_size; ++i) { - current_statement__ = 77; + current_statement__ = 80; stan::model::assign(z, (x + stan::model::rvalue(y, "y", stan::model::index_uni(i))), "assigning variable z", stan::model::index_uni(i)); } - current_statement__ = 80; + current_statement__ = 83; return z; } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -317,20 +320,20 @@ add(const std::vector& x, const int& y, std::ostream* pstream__) { (void) DUMMY_VAR__; try { int x_size = std::numeric_limits::min(); - current_statement__ = 82; + current_statement__ = 85; x_size = stan::math::size(x); - current_statement__ = 83; + current_statement__ = 86; stan::math::validate_non_negative_index("z", "x_size", x_size); std::vector z = std::vector(x_size, std::numeric_limits::min()); - current_statement__ = 87; + current_statement__ = 90; for (int i = 1; i <= x_size; ++i) { - current_statement__ = 85; + current_statement__ = 88; stan::model::assign(z, (stan::model::rvalue(x, "x", stan::model::index_uni(i)) + y), "assigning variable z", stan::model::index_uni(i)); } - current_statement__ = 88; + current_statement__ = 91; return z; } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -375,175 +378,175 @@ loglik_sc_mix(const std::vector>& beta_i_raw, (void) DUMMY_VAR__; try { int D = std::numeric_limits::min(); - current_statement__ = 90; + current_statement__ = 93; D = stan::math::size(beta_i_raw); int S = std::numeric_limits::min(); - current_statement__ = 91; + current_statement__ = 94; S = (stan::math::rows( stan::model::rvalue(beta_i_raw, "beta_i_raw", stan::model::index_uni(1))) + 1); int N = std::numeric_limits::min(); - current_statement__ = 92; + current_statement__ = 95; N = stan::math::size(X_i); int K_i = std::numeric_limits::min(); - current_statement__ = 93; + current_statement__ = 96; K_i = stan::math::num_elements( stan::model::rvalue(X_i, "X_i", stan::model::index_uni(1))); int K_s = std::numeric_limits::min(); - current_statement__ = 94; + current_statement__ = 97; K_s = stan::math::num_elements( stan::model::rvalue(X_s, "X_s", stan::model::index_uni(1), stan::model::index_uni(1))); int K_o = std::numeric_limits::min(); - current_statement__ = 95; + current_statement__ = 98; K_o = stan::math::num_elements( stan::model::rvalue(X_o, "X_o", stan::model::index_uni(1), stan::model::index_uni(1))); int K_d = std::numeric_limits::min(); - current_statement__ = 96; + current_statement__ = 99; K_d = stan::math::num_elements( stan::model::rvalue(X_d, "X_d", stan::model::index_uni(1))); - current_statement__ = 97; + current_statement__ = 100; stan::math::validate_non_negative_index("zeros_row_K_i", "K_i", K_i); Eigen::Matrix zeros_row_K_i = Eigen::Matrix::Constant(K_i, DUMMY_VAR__); - current_statement__ = 98; + current_statement__ = 101; stan::model::assign(zeros_row_K_i, stan::math::rep_row_vector(0, K_i), "assigning variable zeros_row_K_i"); - current_statement__ = 99; + current_statement__ = 102; stan::math::validate_non_negative_index("zeros_row_K_s", "K_s", K_s); Eigen::Matrix zeros_row_K_s = Eigen::Matrix::Constant(K_s, DUMMY_VAR__); - current_statement__ = 100; + current_statement__ = 103; stan::model::assign(zeros_row_K_s, stan::math::rep_row_vector(0, K_s), "assigning variable zeros_row_K_s"); - current_statement__ = 101; + current_statement__ = 104; stan::math::validate_non_negative_index("zeros_row_K_o", "K_o", K_o); Eigen::Matrix zeros_row_K_o = Eigen::Matrix::Constant(K_o, DUMMY_VAR__); - current_statement__ = 102; + current_statement__ = 105; stan::model::assign(zeros_row_K_o, stan::math::rep_row_vector(0, K_o), "assigning variable zeros_row_K_o"); - current_statement__ = 103; + current_statement__ = 106; stan::math::validate_non_negative_index("zeros_row_K_d", "K_d", K_d); Eigen::Matrix zeros_row_K_d = Eigen::Matrix::Constant(K_d, DUMMY_VAR__); - current_statement__ = 104; + current_statement__ = 107; stan::model::assign(zeros_row_K_d, stan::math::rep_row_vector(0, K_d), "assigning variable zeros_row_K_d"); - current_statement__ = 105; + current_statement__ = 108; stan::math::validate_non_negative_index("zeros_S", "S", S); Eigen::Matrix zeros_S = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 106; + current_statement__ = 109; stan::model::assign(zeros_S, stan::math::rep_vector(0, S), "assigning variable zeros_S"); - current_statement__ = 107; + current_statement__ = 110; stan::math::validate_non_negative_index("ll", "N", N); - current_statement__ = 108; + current_statement__ = 111; stan::math::validate_non_negative_index("ll", "D", D); Eigen::Matrix ll = Eigen::Matrix::Constant(N, D, DUMMY_VAR__); - current_statement__ = 110; + current_statement__ = 113; stan::math::validate_non_negative_index("log_Pi", "S", S); Eigen::Matrix log_Pi = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 112; + current_statement__ = 115; stan::math::validate_non_negative_index("log_A", "S", S); - current_statement__ = 113; + current_statement__ = 116; stan::math::validate_non_negative_index("log_A", "S", S); Eigen::Matrix log_A = Eigen::Matrix::Constant(S, S, DUMMY_VAR__); - current_statement__ = 115; + current_statement__ = 118; stan::math::validate_non_negative_index("log_B", "S", S); - current_statement__ = 116; + current_statement__ = 119; stan::math::validate_non_negative_index("log_B", "M + 1", (M + 1)); Eigen::Matrix log_B = Eigen::Matrix::Constant(S, (M + 1), DUMMY_VAR__); - current_statement__ = 118; + current_statement__ = 121; stan::math::validate_non_negative_index("log_py", "S", S); Eigen::Matrix log_py = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 120; + current_statement__ = 123; stan::math::validate_non_negative_index("log_alpha", "S", S); Eigen::Matrix log_alpha = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 122; + current_statement__ = 125; stan::math::validate_non_negative_index("log_alpha_new", "S", S); Eigen::Matrix log_alpha_new = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 124; + current_statement__ = 127; stan::math::validate_non_negative_index("beta_i", "S", S); - current_statement__ = 125; + current_statement__ = 128; stan::math::validate_non_negative_index("beta_i", "K_i", K_i); Eigen::Matrix beta_i = Eigen::Matrix::Constant(S, K_i, DUMMY_VAR__); - current_statement__ = 127; + current_statement__ = 130; stan::math::validate_non_negative_index("beta_s", "S", S); - current_statement__ = 128; + current_statement__ = 131; stan::math::validate_non_negative_index("beta_s", "S", S); - current_statement__ = 129; + current_statement__ = 132; stan::math::validate_non_negative_index("beta_s", "K_s", K_s); std::vector> beta_s = std::vector>(S, Eigen::Matrix::Constant(S, K_s, DUMMY_VAR__)); - current_statement__ = 131; + current_statement__ = 134; stan::math::validate_non_negative_index("beta_o", "S", S); - current_statement__ = 132; + current_statement__ = 135; stan::math::validate_non_negative_index("beta_o", "M", M); - current_statement__ = 133; + current_statement__ = 136; stan::math::validate_non_negative_index("beta_o", "K_o", K_o); std::vector> beta_o = std::vector>(S, Eigen::Matrix::Constant(M, K_o, DUMMY_VAR__)); - current_statement__ = 135; + current_statement__ = 138; stan::math::validate_non_negative_index("theta", "D", D); - current_statement__ = 136; + current_statement__ = 139; stan::math::validate_non_negative_index("theta", "K_d", K_d); Eigen::Matrix theta = Eigen::Matrix::Constant(D, K_d, DUMMY_VAR__); - current_statement__ = 137; + current_statement__ = 140; stan::model::assign(theta, stan::math::append_row(zeros_row_K_d, theta_raw), "assigning variable theta"); - current_statement__ = 169; + current_statement__ = 172; for (int d = 1; d <= D; ++d) { - current_statement__ = 138; + current_statement__ = 141; stan::model::assign(beta_i, stan::math::append_row(zeros_row_K_i, stan::model::rvalue(beta_i_raw, "beta_i_raw", stan::model::index_uni(d))), "assigning variable beta_i"); - current_statement__ = 142; + current_statement__ = 145; for (int s = 1; s <= S; ++s) { - current_statement__ = 139; + current_statement__ = 142; stan::model::assign(beta_s, stan::math::append_row(zeros_row_K_s, stan::model::rvalue(beta_s_raw, "beta_s_raw", stan::model::index_uni(d), stan::model::index_uni(s))), "assigning variable beta_s", stan::model::index_uni(s)); - current_statement__ = 140; + current_statement__ = 143; stan::model::assign(beta_o, stan::math::append_row(zeros_row_K_o, stan::model::rvalue(beta_o_raw, "beta_o_raw", stan::model::index_uni(d), stan::model::index_uni(s))), "assigning variable beta_o", stan::model::index_uni(s)); } - current_statement__ = 167; + current_statement__ = 170; for (int ii = 1; ii <= N_sample; ++ii) { int i = std::numeric_limits::min(); - current_statement__ = 143; + current_statement__ = 146; i = stan::model::rvalue(ids, "ids", stan::model::index_uni(ii)); - current_statement__ = 144; + current_statement__ = 147; stan::model::assign(log_Pi, stan::math::log_softmax( stan::math::multiply(beta_i, stan::model::rvalue(X_i, "X_i", stan::model::index_uni(i)))), "assigning variable log_Pi"); - current_statement__ = 148; + current_statement__ = 151; for (int s = 1; s <= S; ++s) { - current_statement__ = 145; + current_statement__ = 148; stan::model::assign(log_B, stan::math::transpose( stan::math::log_softmax( @@ -554,25 +557,25 @@ loglik_sc_mix(const std::vector>& beta_i_raw, stan::model::index_uni(i))))), "assigning variable log_B", stan::model::index_uni(s), stan::model::index_min_max(1, M)); - current_statement__ = 146; + current_statement__ = 149; stan::model::assign(log_B, 0, "assigning variable log_B", stan::model::index_uni(s), stan::model::index_uni((M + 1))); } - current_statement__ = 149; + current_statement__ = 152; stan::model::assign(log_py, stan::model::rvalue(log_B, "log_B", stan::model::index_omni(), stan::model::index_uni( stan::model::rvalue(obs, "obs", stan::model::index_uni(1), stan::model::index_uni(i)))), "assigning variable log_py"); - current_statement__ = 150; + current_statement__ = 153; stan::model::assign(log_alpha, stan::math::add(log_Pi, log_py), "assigning variable log_alpha"); - current_statement__ = 164; + current_statement__ = 167; for (int t = 2; t <= stan::model::rvalue(T, "T", stan::model::index_uni(i)); ++t) { - current_statement__ = 154; + current_statement__ = 157; for (int s = 1; s <= S; ++s) { - current_statement__ = 151; + current_statement__ = 154; stan::model::assign(log_B, stan::math::transpose( stan::math::log_softmax( @@ -583,19 +586,19 @@ loglik_sc_mix(const std::vector>& beta_i_raw, stan::model::index_uni(t), stan::model::index_uni(i))))), "assigning variable log_B", stan::model::index_uni(s), stan::model::index_min_max(1, M)); - current_statement__ = 152; + current_statement__ = 155; stan::model::assign(log_B, 0, "assigning variable log_B", stan::model::index_uni(s), stan::model::index_uni((M + 1))); } - current_statement__ = 155; + current_statement__ = 158; stan::model::assign(log_py, stan::model::rvalue(log_B, "log_B", stan::model::index_omni(), stan::model::index_uni( stan::model::rvalue(obs, "obs", stan::model::index_uni(t), stan::model::index_uni(i)))), "assigning variable log_py"); - current_statement__ = 158; + current_statement__ = 161; for (int s = 1; s <= S; ++s) { - current_statement__ = 156; + current_statement__ = 159; stan::model::assign(log_A, stan::math::transpose( stan::math::log_softmax( @@ -608,9 +611,9 @@ loglik_sc_mix(const std::vector>& beta_i_raw, "assigning variable log_A", stan::model::index_uni(s), stan::model::index_omni()); } - current_statement__ = 161; + current_statement__ = 164; for (int k = 1; k <= S; ++k) { - current_statement__ = 159; + current_statement__ = 162; stan::model::assign(log_alpha_new, stan::math::log_sum_exp( stan::math::add( @@ -621,36 +624,36 @@ loglik_sc_mix(const std::vector>& beta_i_raw, stan::model::index_uni(k)))), "assigning variable log_alpha_new", stan::model::index_uni(k)); } - current_statement__ = 162; + current_statement__ = 165; stan::model::assign(log_alpha, log_alpha_new, "assigning variable log_alpha"); } - current_statement__ = 165; + current_statement__ = 168; stan::model::assign(ll, stan::math::log_sum_exp(log_alpha), "assigning variable ll", stan::model::index_uni(i), stan::model::index_uni(d)); } } - current_statement__ = 170; + current_statement__ = 173; stan::math::validate_non_negative_index("ll_i", "N_sample", N_sample); Eigen::Matrix ll_i = Eigen::Matrix::Constant(N_sample, DUMMY_VAR__); - current_statement__ = 177; + current_statement__ = 180; for (int ii = 1; ii <= N_sample; ++ii) { int i = std::numeric_limits::min(); - current_statement__ = 172; + current_statement__ = 175; i = stan::model::rvalue(ids, "ids", stan::model::index_uni(ii)); - current_statement__ = 173; + current_statement__ = 176; stan::math::validate_non_negative_index("log_omega", "D", D); Eigen::Matrix log_omega = Eigen::Matrix::Constant(D, DUMMY_VAR__); - current_statement__ = 174; + current_statement__ = 177; stan::model::assign(log_omega, stan::math::log_softmax( stan::math::multiply(theta, stan::model::rvalue(X_d, "X_d", stan::model::index_uni(i)))), "assigning variable log_omega"); - current_statement__ = 175; + current_statement__ = 178; stan::model::assign(ll_i, stan::math::log_sum_exp( stan::math::add(log_omega, @@ -659,7 +662,7 @@ loglik_sc_mix(const std::vector>& beta_i_raw, stan::model::index_omni())))), "assigning variable ll_i", stan::model::index_uni(i)); } - current_statement__ = 178; + current_statement__ = 181; return stan::math::sum(ll_i); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -682,6 +685,8 @@ class model_mnhmm final : public model_base_crtp { std::vector>> X_s; int K_o; std::vector>> X_o; + int penalize; + double penalty; int D; int K_d; std::vector> X_d; @@ -710,55 +715,55 @@ class model_mnhmm final : public model_base_crtp { try { int pos__ = std::numeric_limits::min(); pos__ = 1; - current_statement__ = 22; + current_statement__ = 23; context__.validate_dims("data initialization", "N", "int", std::vector{}); N = std::numeric_limits::min(); - current_statement__ = 22; + current_statement__ = 23; N = context__.vals_i("N")[(1 - 1)]; - current_statement__ = 22; - stan::math::check_greater_or_equal(function__, "N", N, 1); current_statement__ = 23; + stan::math::check_greater_or_equal(function__, "N", N, 1); + current_statement__ = 24; context__.validate_dims("data initialization", "max_T", "int", std::vector{}); max_T = std::numeric_limits::min(); - current_statement__ = 23; + current_statement__ = 24; max_T = context__.vals_i("max_T")[(1 - 1)]; - current_statement__ = 23; - stan::math::check_greater_or_equal(function__, "max_T", max_T, 2); current_statement__ = 24; - stan::math::validate_non_negative_index("T", "N", N); + stan::math::check_greater_or_equal(function__, "max_T", max_T, 2); current_statement__ = 25; + stan::math::validate_non_negative_index("T", "N", N); + current_statement__ = 26; context__.validate_dims("data initialization", "T", "int", std::vector{static_cast(N)}); T = std::vector(N, std::numeric_limits::min()); - current_statement__ = 25; + current_statement__ = 26; T = context__.vals_i("T"); - current_statement__ = 25; + current_statement__ = 26; stan::math::check_greater_or_equal(function__, "T", T, 2); - current_statement__ = 25; - stan::math::check_less_or_equal(function__, "T", T, max_T); current_statement__ = 26; + stan::math::check_less_or_equal(function__, "T", T, max_T); + current_statement__ = 27; context__.validate_dims("data initialization", "M", "int", std::vector{}); M = std::numeric_limits::min(); - current_statement__ = 26; + current_statement__ = 27; M = context__.vals_i("M")[(1 - 1)]; - current_statement__ = 26; - stan::math::check_greater_or_equal(function__, "M", M, 2); current_statement__ = 27; + stan::math::check_greater_or_equal(function__, "M", M, 2); + current_statement__ = 28; context__.validate_dims("data initialization", "S", "int", std::vector{}); S = std::numeric_limits::min(); - current_statement__ = 27; + current_statement__ = 28; S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 27; - stan::math::check_greater_or_equal(function__, "S", S, 1); current_statement__ = 28; - stan::math::validate_non_negative_index("obs", "max_T", max_T); + stan::math::check_greater_or_equal(function__, "S", S, 1); current_statement__ = 29; - stan::math::validate_non_negative_index("obs", "N", N); + stan::math::validate_non_negative_index("obs", "max_T", max_T); current_statement__ = 30; + stan::math::validate_non_negative_index("obs", "N", N); + current_statement__ = 31; context__.validate_dims("data initialization", "obs", "int", std::vector{static_cast(max_T), static_cast(N)}); @@ -766,56 +771,56 @@ class model_mnhmm final : public model_base_crtp { std::vector(N, std::numeric_limits::min())); { std::vector obs_flat__; - current_statement__ = 30; + current_statement__ = 31; obs_flat__ = context__.vals_i("obs"); - current_statement__ = 30; + current_statement__ = 31; pos__ = 1; - current_statement__ = 30; + current_statement__ = 31; for (int sym1__ = 1; sym1__ <= N; ++sym1__) { - current_statement__ = 30; + current_statement__ = 31; for (int sym2__ = 1; sym2__ <= max_T; ++sym2__) { - current_statement__ = 30; + current_statement__ = 31; stan::model::assign(obs, obs_flat__[(pos__ - 1)], "assigning variable obs", stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 30; + current_statement__ = 31; pos__ = (pos__ + 1); } } } - current_statement__ = 30; + current_statement__ = 31; stan::math::check_greater_or_equal(function__, "obs", obs, 0); - current_statement__ = 30; - stan::math::check_less_or_equal(function__, "obs", obs, (M + 1)); current_statement__ = 31; + stan::math::check_less_or_equal(function__, "obs", obs, (M + 1)); + current_statement__ = 32; context__.validate_dims("data initialization", "N_sample", "int", std::vector{}); N_sample = std::numeric_limits::min(); - current_statement__ = 31; + current_statement__ = 32; N_sample = context__.vals_i("N_sample")[(1 - 1)]; - current_statement__ = 31; - stan::math::check_less_or_equal(function__, "N_sample", N_sample, N); current_statement__ = 32; - stan::math::validate_non_negative_index("ids", "N_sample", N_sample); + stan::math::check_less_or_equal(function__, "N_sample", N_sample, N); current_statement__ = 33; + stan::math::validate_non_negative_index("ids", "N_sample", N_sample); + current_statement__ = 34; context__.validate_dims("data initialization", "ids", "int", std::vector{static_cast(N_sample)}); ids = std::vector(N_sample, std::numeric_limits::min()); - current_statement__ = 33; - ids = context__.vals_i("ids"); current_statement__ = 34; + ids = context__.vals_i("ids"); + current_statement__ = 35; context__.validate_dims("data initialization", "K_i", "int", std::vector{}); K_i = std::numeric_limits::min(); - current_statement__ = 34; + current_statement__ = 35; K_i = context__.vals_i("K_i")[(1 - 1)]; - current_statement__ = 34; - stan::math::check_greater_or_equal(function__, "K_i", K_i, 1); current_statement__ = 35; - stan::math::validate_non_negative_index("X_i", "N", N); + stan::math::check_greater_or_equal(function__, "K_i", K_i, 1); current_statement__ = 36; - stan::math::validate_non_negative_index("X_i", "K_i", K_i); + stan::math::validate_non_negative_index("X_i", "N", N); current_statement__ = 37; + stan::math::validate_non_negative_index("X_i", "K_i", K_i); + current_statement__ = 38; context__.validate_dims("data initialization", "X_i", "double", std::vector{static_cast(N), static_cast(K_i)}); X_i = std::vector>(N, @@ -823,38 +828,38 @@ class model_mnhmm final : public model_base_crtp { std::numeric_limits::quiet_NaN())); { std::vector X_i_flat__; - current_statement__ = 37; + current_statement__ = 38; X_i_flat__ = context__.vals_r("X_i"); - current_statement__ = 37; + current_statement__ = 38; pos__ = 1; - current_statement__ = 37; + current_statement__ = 38; for (int sym1__ = 1; sym1__ <= K_i; ++sym1__) { - current_statement__ = 37; + current_statement__ = 38; for (int sym2__ = 1; sym2__ <= N; ++sym2__) { - current_statement__ = 37; + current_statement__ = 38; stan::model::assign(X_i, X_i_flat__[(pos__ - 1)], "assigning variable X_i", stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 37; + current_statement__ = 38; pos__ = (pos__ + 1); } } } - current_statement__ = 38; + current_statement__ = 39; context__.validate_dims("data initialization", "K_s", "int", std::vector{}); K_s = std::numeric_limits::min(); - current_statement__ = 38; + current_statement__ = 39; K_s = context__.vals_i("K_s")[(1 - 1)]; - current_statement__ = 38; - stan::math::check_greater_or_equal(function__, "K_s", K_s, 1); current_statement__ = 39; - stan::math::validate_non_negative_index("X_s", "max_T", max_T); + stan::math::check_greater_or_equal(function__, "K_s", K_s, 1); current_statement__ = 40; - stan::math::validate_non_negative_index("X_s", "N", N); + stan::math::validate_non_negative_index("X_s", "max_T", max_T); current_statement__ = 41; - stan::math::validate_non_negative_index("X_s", "K_s", K_s); + stan::math::validate_non_negative_index("X_s", "N", N); current_statement__ = 42; + stan::math::validate_non_negative_index("X_s", "K_s", K_s); + current_statement__ = 43; context__.validate_dims("data initialization", "X_s", "double", std::vector{static_cast(max_T), static_cast(N), static_cast(K_s)}); @@ -864,42 +869,42 @@ class model_mnhmm final : public model_base_crtp { std::numeric_limits::quiet_NaN()))); { std::vector X_s_flat__; - current_statement__ = 42; + current_statement__ = 43; X_s_flat__ = context__.vals_r("X_s"); - current_statement__ = 42; + current_statement__ = 43; pos__ = 1; - current_statement__ = 42; + current_statement__ = 43; for (int sym1__ = 1; sym1__ <= K_s; ++sym1__) { - current_statement__ = 42; + current_statement__ = 43; for (int sym2__ = 1; sym2__ <= N; ++sym2__) { - current_statement__ = 42; + current_statement__ = 43; for (int sym3__ = 1; sym3__ <= max_T; ++sym3__) { - current_statement__ = 42; + current_statement__ = 43; stan::model::assign(X_s, X_s_flat__[(pos__ - 1)], "assigning variable X_s", stan::model::index_uni(sym3__), stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 42; + current_statement__ = 43; pos__ = (pos__ + 1); } } } } - current_statement__ = 43; + current_statement__ = 44; context__.validate_dims("data initialization", "K_o", "int", std::vector{}); K_o = std::numeric_limits::min(); - current_statement__ = 43; + current_statement__ = 44; K_o = context__.vals_i("K_o")[(1 - 1)]; - current_statement__ = 43; - stan::math::check_greater_or_equal(function__, "K_o", K_o, 1); current_statement__ = 44; - stan::math::validate_non_negative_index("X_o", "max_T", max_T); + stan::math::check_greater_or_equal(function__, "K_o", K_o, 1); current_statement__ = 45; - stan::math::validate_non_negative_index("X_o", "N", N); + stan::math::validate_non_negative_index("X_o", "max_T", max_T); current_statement__ = 46; - stan::math::validate_non_negative_index("X_o", "K_o", K_o); + stan::math::validate_non_negative_index("X_o", "N", N); current_statement__ = 47; + stan::math::validate_non_negative_index("X_o", "K_o", K_o); + current_statement__ = 48; context__.validate_dims("data initialization", "X_o", "double", std::vector{static_cast(max_T), static_cast(N), static_cast(K_o)}); @@ -909,48 +914,66 @@ class model_mnhmm final : public model_base_crtp { std::numeric_limits::quiet_NaN()))); { std::vector X_o_flat__; - current_statement__ = 47; + current_statement__ = 48; X_o_flat__ = context__.vals_r("X_o"); - current_statement__ = 47; + current_statement__ = 48; pos__ = 1; - current_statement__ = 47; + current_statement__ = 48; for (int sym1__ = 1; sym1__ <= K_o; ++sym1__) { - current_statement__ = 47; + current_statement__ = 48; for (int sym2__ = 1; sym2__ <= N; ++sym2__) { - current_statement__ = 47; + current_statement__ = 48; for (int sym3__ = 1; sym3__ <= max_T; ++sym3__) { - current_statement__ = 47; + current_statement__ = 48; stan::model::assign(X_o, X_o_flat__[(pos__ - 1)], "assigning variable X_o", stan::model::index_uni(sym3__), stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 47; + current_statement__ = 48; pos__ = (pos__ + 1); } } } } - current_statement__ = 48; + current_statement__ = 49; + context__.validate_dims("data initialization", "penalize", "int", + std::vector{}); + penalize = std::numeric_limits::min(); + current_statement__ = 49; + penalize = context__.vals_i("penalize")[(1 - 1)]; + current_statement__ = 49; + stan::math::check_greater_or_equal(function__, "penalize", penalize, 0); + current_statement__ = 49; + stan::math::check_less_or_equal(function__, "penalize", penalize, 1); + current_statement__ = 50; + context__.validate_dims("data initialization", "penalty", "double", + std::vector{}); + penalty = std::numeric_limits::quiet_NaN(); + current_statement__ = 50; + penalty = context__.vals_r("penalty")[(1 - 1)]; + current_statement__ = 50; + stan::math::check_greater_or_equal(function__, "penalty", penalty, 0); + current_statement__ = 51; context__.validate_dims("data initialization", "D", "int", std::vector{}); D = std::numeric_limits::min(); - current_statement__ = 48; + current_statement__ = 51; D = context__.vals_i("D")[(1 - 1)]; - current_statement__ = 48; + current_statement__ = 51; stan::math::check_greater_or_equal(function__, "D", D, 2); - current_statement__ = 49; + current_statement__ = 52; context__.validate_dims("data initialization", "K_d", "int", std::vector{}); K_d = std::numeric_limits::min(); - current_statement__ = 49; + current_statement__ = 52; K_d = context__.vals_i("K_d")[(1 - 1)]; - current_statement__ = 49; + current_statement__ = 52; stan::math::check_greater_or_equal(function__, "K_d", K_d, 1); - current_statement__ = 50; + current_statement__ = 53; stan::math::validate_non_negative_index("X_d", "N", N); - current_statement__ = 51; + current_statement__ = 54; stan::math::validate_non_negative_index("X_d", "K_d", K_d); - current_statement__ = 52; + current_statement__ = 55; context__.validate_dims("data initialization", "X_d", "double", std::vector{static_cast(N), static_cast(K_d)}); X_d = std::vector>(N, @@ -958,68 +981,68 @@ class model_mnhmm final : public model_base_crtp { std::numeric_limits::quiet_NaN())); { std::vector X_d_flat__; - current_statement__ = 52; + current_statement__ = 55; X_d_flat__ = context__.vals_r("X_d"); - current_statement__ = 52; + current_statement__ = 55; pos__ = 1; - current_statement__ = 52; + current_statement__ = 55; for (int sym1__ = 1; sym1__ <= K_d; ++sym1__) { - current_statement__ = 52; + current_statement__ = 55; for (int sym2__ = 1; sym2__ <= N; ++sym2__) { - current_statement__ = 52; + current_statement__ = 55; stan::model::assign(X_d, X_d_flat__[(pos__ - 1)], "assigning variable X_d", stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 52; + current_statement__ = 55; pos__ = (pos__ + 1); } } } - current_statement__ = 53; + current_statement__ = 56; stan::math::validate_non_negative_index("beta_i_raw", "D", D); - current_statement__ = 54; + current_statement__ = 57; beta_i_raw_2dim__ = std::numeric_limits::min(); - current_statement__ = 54; + current_statement__ = 57; beta_i_raw_2dim__ = (S - 1); - current_statement__ = 54; + current_statement__ = 57; stan::math::validate_non_negative_index("beta_i_raw", "S - 1", beta_i_raw_2dim__); - current_statement__ = 55; + current_statement__ = 58; stan::math::validate_non_negative_index("beta_i_raw", "K_i", K_i); - current_statement__ = 56; + current_statement__ = 59; stan::math::validate_non_negative_index("beta_s_raw", "D", D); - current_statement__ = 57; + current_statement__ = 60; stan::math::validate_non_negative_index("beta_s_raw", "S", S); - current_statement__ = 58; + current_statement__ = 61; beta_s_raw_3dim__ = std::numeric_limits::min(); - current_statement__ = 58; + current_statement__ = 61; beta_s_raw_3dim__ = (S - 1); - current_statement__ = 58; + current_statement__ = 61; stan::math::validate_non_negative_index("beta_s_raw", "S - 1", beta_s_raw_3dim__); - current_statement__ = 59; + current_statement__ = 62; stan::math::validate_non_negative_index("beta_s_raw", "K_s", K_s); - current_statement__ = 60; + current_statement__ = 63; stan::math::validate_non_negative_index("beta_o_raw", "D", D); - current_statement__ = 61; + current_statement__ = 64; stan::math::validate_non_negative_index("beta_o_raw", "S", S); - current_statement__ = 62; + current_statement__ = 65; beta_o_raw_3dim__ = std::numeric_limits::min(); - current_statement__ = 62; + current_statement__ = 65; beta_o_raw_3dim__ = (M - 1); - current_statement__ = 62; + current_statement__ = 65; stan::math::validate_non_negative_index("beta_o_raw", "M - 1", beta_o_raw_3dim__); - current_statement__ = 63; + current_statement__ = 66; stan::math::validate_non_negative_index("beta_o_raw", "K_o", K_o); - current_statement__ = 64; + current_statement__ = 67; theta_raw_1dim__ = std::numeric_limits::min(); - current_statement__ = 64; + current_statement__ = 67; theta_raw_1dim__ = (D - 1); - current_statement__ = 64; + current_statement__ = 67; stan::math::validate_non_negative_index("theta_raw", "D - 1", theta_raw_1dim__); - current_statement__ = 65; + current_statement__ = 68; stan::math::validate_non_negative_index("theta_raw", "K_d", K_d); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -1095,43 +1118,47 @@ class model_mnhmm final : public model_base_crtp { local_scalar_t__ prior = DUMMY_VAR__; current_statement__ = 5; prior = 0; - current_statement__ = 14; - for (int d = 1; d <= D; ++d) { - current_statement__ = 8; - prior = (prior + - stan::math::normal_lpdf( - stan::math::to_vector( - stan::model::rvalue(beta_i_raw, "beta_i_raw", - stan::model::index_uni(d))), 0, 5)); - current_statement__ = 12; - for (int s = 1; s <= S; ++s) { - current_statement__ = 9; + current_statement__ = 17; + if (stan::math::logical_eq(penalize, 1)) { + current_statement__ = 14; + for (int d = 1; d <= D; ++d) { + current_statement__ = 8; prior = (prior + stan::math::normal_lpdf( stan::math::to_vector( - stan::model::rvalue(beta_s_raw, "beta_s_raw", - stan::model::index_uni(d), stan::model::index_uni(s))), 0, - 5)); - current_statement__ = 10; - prior = (prior + - stan::math::normal_lpdf( - stan::math::to_vector( - stan::model::rvalue(beta_o_raw, "beta_o_raw", - stan::model::index_uni(d), stan::model::index_uni(s))), 0, - 5)); + stan::model::rvalue(beta_i_raw, "beta_i_raw", + stan::model::index_uni(d))), 0, penalty)); + current_statement__ = 12; + for (int s = 1; s <= S; ++s) { + current_statement__ = 9; + prior = (prior + + stan::math::normal_lpdf( + stan::math::to_vector( + stan::model::rvalue(beta_s_raw, "beta_s_raw", + stan::model::index_uni(d), stan::model::index_uni(s))), + 0, penalty)); + current_statement__ = 10; + prior = (prior + + stan::math::normal_lpdf( + stan::math::to_vector( + stan::model::rvalue(beta_o_raw, "beta_o_raw", + stan::model::index_uni(d), stan::model::index_uni(s))), + 0, penalty)); + } } + current_statement__ = 15; + prior = (prior + + stan::math::normal_lpdf(stan::math::to_vector(theta_raw), 0, + penalty)); } - current_statement__ = 15; - prior = (prior + - stan::math::normal_lpdf(stan::math::to_vector(theta_raw), 0, 5)); local_scalar_t__ log_lik = DUMMY_VAR__; current_statement__ = 6; log_lik = loglik_sc_mix(beta_i_raw, beta_s_raw, beta_o_raw, theta_raw, obs, M, T, N_sample, ids, X_s, X_o, X_i, X_d, pstream__); { - current_statement__ = 20; - lp_accum__.add(prior); current_statement__ = 21; + lp_accum__.add(prior); + current_statement__ = 22; lp_accum__.add(log_lik); } } catch (const std::exception& e) { @@ -1252,35 +1279,39 @@ class model_mnhmm final : public model_base_crtp { } current_statement__ = 5; prior = 0; - current_statement__ = 14; - for (int d = 1; d <= D; ++d) { - current_statement__ = 8; - prior = (prior + - stan::math::normal_lpdf( - stan::math::to_vector( - stan::model::rvalue(beta_i_raw, "beta_i_raw", - stan::model::index_uni(d))), 0, 5)); - current_statement__ = 12; - for (int s = 1; s <= S; ++s) { - current_statement__ = 9; + current_statement__ = 17; + if (stan::math::logical_eq(penalize, 1)) { + current_statement__ = 14; + for (int d = 1; d <= D; ++d) { + current_statement__ = 8; prior = (prior + stan::math::normal_lpdf( stan::math::to_vector( - stan::model::rvalue(beta_s_raw, "beta_s_raw", - stan::model::index_uni(d), stan::model::index_uni(s))), 0, - 5)); - current_statement__ = 10; - prior = (prior + - stan::math::normal_lpdf( - stan::math::to_vector( - stan::model::rvalue(beta_o_raw, "beta_o_raw", - stan::model::index_uni(d), stan::model::index_uni(s))), 0, - 5)); + stan::model::rvalue(beta_i_raw, "beta_i_raw", + stan::model::index_uni(d))), 0, penalty)); + current_statement__ = 12; + for (int s = 1; s <= S; ++s) { + current_statement__ = 9; + prior = (prior + + stan::math::normal_lpdf( + stan::math::to_vector( + stan::model::rvalue(beta_s_raw, "beta_s_raw", + stan::model::index_uni(d), stan::model::index_uni(s))), + 0, penalty)); + current_statement__ = 10; + prior = (prior + + stan::math::normal_lpdf( + stan::math::to_vector( + stan::model::rvalue(beta_o_raw, "beta_o_raw", + stan::model::index_uni(d), stan::model::index_uni(s))), + 0, penalty)); + } } + current_statement__ = 15; + prior = (prior + + stan::math::normal_lpdf(stan::math::to_vector(theta_raw), 0, + penalty)); } - current_statement__ = 15; - prior = (prior + - stan::math::normal_lpdf(stan::math::to_vector(theta_raw), 0, 5)); current_statement__ = 6; log_lik = loglik_sc_mix(beta_i_raw, beta_s_raw, beta_o_raw, theta_raw, obs, M, T, N_sample, ids, X_s, X_o, X_i, X_d, pstream__); @@ -1291,17 +1322,12 @@ class model_mnhmm final : public model_base_crtp { if (stan::math::logical_negation(emit_generated_quantities__)) { return ; } - current_statement__ = 16; - if (pstream__) { - stan::math::stan_print(pstream__, "not yet!"); - *(pstream__) << std::endl; - } double ploglik_N = std::numeric_limits::quiet_NaN(); current_statement__ = 7; ploglik_N = (prior + log_lik); - current_statement__ = 19; + current_statement__ = 20; if (stan::math::logical_gt(N, N_sample)) { - current_statement__ = 17; + current_statement__ = 18; ploglik_N = (prior + loglik_sc_mix(beta_i_raw, beta_s_raw, beta_o_raw, theta_raw, obs, M, T, N, stan::math::linspaced_int_array(N, 1, N), X_s, X_o, X_i, diff --git a/src/stanExports_multichannel_mnhmm.h b/src/stanExports_multichannel_mnhmm.h index 3e9320b8..ef711ee4 100644 --- a/src/stanExports_multichannel_mnhmm.h +++ b/src/stanExports_multichannel_mnhmm.h @@ -27,28 +27,30 @@ namespace model_multichannel_mnhmm_namespace { using stan::model::model_base_crtp; using namespace stan::math; stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = +static constexpr std::array locations_array__ = {" (found before start of program)", - " (in 'string', line 140, column 2 to column 41)", - " (in 'string', line 142, column 2 to column 44)", - " (in 'string', line 144, column 2 to column 57)", - " (in 'string', line 145, column 2 to column 31)", - " (in 'string', line 149, column 0 to column 15)", - " (in 'string', line 158, column 2 to line 159, column 48)", - " (in 'string', line 166, column 2 to column 35)", - " (in 'string', line 151, column 2 to column 56)", - " (in 'string', line 153, column 4 to column 61)", - " (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 155, column 2 to column 45)", - " (in 'string', line 150, column 14 to line 156, column 1)", - " (in 'string', line 150, column 0 to line 156, column 1)", - " (in 'string', line 157, column 0 to column 50)", - " (in 'string', line 168, column 4 to line 169, column 68)", - " (in 'string', line 167, column 20 to line 170, column 3)", - " (in 'string', line 167, column 2 to line 170, column 3)", - " (in 'string', line 162, column 2 to column 18)", - " (in 'string', line 163, column 2 to column 20)", + " (in 'string', line 142, column 2 to column 41)", + " (in 'string', line 144, column 2 to column 44)", + " (in 'string', line 146, column 2 to column 57)", + " (in 'string', line 147, column 2 to column 31)", + " (in 'string', line 151, column 0 to column 15)", + " (in 'string', line 162, column 2 to line 163, column 48)", + " (in 'string', line 170, column 2 to column 35)", + " (in 'string', line 154, column 4 to column 64)", + " (in 'string', line 156, column 6 to column 69)", + " (in 'string', line 155, column 18 to line 157, column 5)", + " (in 'string', line 155, column 4 to line 157, column 5)", + " (in 'string', line 158, column 4 to column 53)", + " (in 'string', line 153, column 16 to line 159, column 3)", + " (in 'string', line 153, column 2 to line 159, column 3)", + " (in 'string', line 160, column 2 to column 58)", + " (in 'string', line 152, column 19 to line 161, column 1)", + " (in 'string', line 152, column 0 to line 161, column 1)", + " (in 'string', line 172, column 4 to line 173, column 68)", + " (in 'string', line 171, column 20 to line 174, column 3)", + " (in 'string', line 171, column 2 to line 174, column 3)", + " (in 'string', line 166, column 2 to column 18)", + " (in 'string', line 167, column 2 to column 20)", " (in 'string', line 118, column 2 to column 17)", " (in 'string', line 119, column 2 to column 21)", " (in 'string', line 120, column 8 to column 9)", @@ -79,22 +81,24 @@ static constexpr std::array locations_array__ = " (in 'string', line 133, column 15 to column 16)", " (in 'string', line 133, column 25 to column 28)", " (in 'string', line 133, column 2 to column 34)", - " (in 'string', line 134, column 2 to column 17)", - " (in 'string', line 135, column 2 to column 19)", - " (in 'string', line 136, column 8 to column 9)", - " (in 'string', line 136, column 18 to column 21)", - " (in 'string', line 136, column 2 to column 27)", - " (in 'string', line 140, column 8 to column 9)", - " (in 'string', line 140, column 18 to column 23)", - " (in 'string', line 140, column 25 to column 28)", + " (in 'string', line 134, column 2 to column 32)", + " (in 'string', line 135, column 2 to column 24)", + " (in 'string', line 136, column 2 to column 17)", + " (in 'string', line 137, column 2 to column 19)", + " (in 'string', line 138, column 8 to column 9)", + " (in 'string', line 138, column 18 to column 21)", + " (in 'string', line 138, column 2 to column 27)", " (in 'string', line 142, column 8 to column 9)", - " (in 'string', line 142, column 11 to column 12)", - " (in 'string', line 142, column 21 to column 26)", - " (in 'string', line 142, column 28 to column 31)", + " (in 'string', line 142, column 18 to column 23)", + " (in 'string', line 142, column 25 to column 28)", " (in 'string', line 144, column 8 to column 9)", - " (in 'string', line 144, column 22 to column 44)", - " (in 'string', line 145, column 9 to column 14)", - " (in 'string', line 145, column 16 to column 19)", + " (in 'string', line 144, column 11 to column 12)", + " (in 'string', line 144, column 21 to column 26)", + " (in 'string', line 144, column 28 to column 31)", + " (in 'string', line 146, column 8 to column 9)", + " (in 'string', line 146, column 22 to column 44)", + " (in 'string', line 147, column 9 to column 14)", + " (in 'string', line 147, column 16 to column 19)", " (in 'string', line 8, column 4 to column 25)", " (in 'string', line 9, column 10 to column 16)", " (in 'string', line 9, column 4 to column 24)", @@ -275,21 +279,21 @@ add(const std::vector& x, const std::vector& y, std::ostream* (void) DUMMY_VAR__; try { int x_size = std::numeric_limits::min(); - current_statement__ = 67; + current_statement__ = 71; x_size = stan::math::size(x); - current_statement__ = 68; + current_statement__ = 72; stan::math::validate_non_negative_index("z", "x_size", x_size); std::vector z = std::vector(x_size, std::numeric_limits::min()); - current_statement__ = 72; + current_statement__ = 76; for (int i = 1; i <= x_size; ++i) { - current_statement__ = 70; + current_statement__ = 74; stan::model::assign(z, (stan::model::rvalue(x, "x", stan::model::index_uni(i)) + stan::model::rvalue(y, "y", stan::model::index_uni(i))), "assigning variable z", stan::model::index_uni(i)); } - current_statement__ = 73; + current_statement__ = 77; return z; } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -307,20 +311,20 @@ add(const int& x, const std::vector& y, std::ostream* pstream__) { (void) DUMMY_VAR__; try { int y_size = std::numeric_limits::min(); - current_statement__ = 75; + current_statement__ = 79; y_size = stan::math::size(y); - current_statement__ = 76; + current_statement__ = 80; stan::math::validate_non_negative_index("z", "y_size", y_size); std::vector z = std::vector(y_size, std::numeric_limits::min()); - current_statement__ = 80; + current_statement__ = 84; for (int i = 1; i <= y_size; ++i) { - current_statement__ = 78; + current_statement__ = 82; stan::model::assign(z, (x + stan::model::rvalue(y, "y", stan::model::index_uni(i))), "assigning variable z", stan::model::index_uni(i)); } - current_statement__ = 81; + current_statement__ = 85; return z; } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -338,20 +342,20 @@ add(const std::vector& x, const int& y, std::ostream* pstream__) { (void) DUMMY_VAR__; try { int x_size = std::numeric_limits::min(); - current_statement__ = 83; + current_statement__ = 87; x_size = stan::math::size(x); - current_statement__ = 84; + current_statement__ = 88; stan::math::validate_non_negative_index("z", "x_size", x_size); std::vector z = std::vector(x_size, std::numeric_limits::min()); - current_statement__ = 88; + current_statement__ = 92; for (int i = 1; i <= x_size; ++i) { - current_statement__ = 86; + current_statement__ = 90; stan::model::assign(z, (stan::model::rvalue(x, "x", stan::model::index_uni(i)) + y), "assigning variable z", stan::model::index_uni(i)); } - current_statement__ = 89; + current_statement__ = 93; return z; } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -395,171 +399,171 @@ loglik_mc_mix(const std::vector>& beta_i_raw, (void) DUMMY_VAR__; try { int D = std::numeric_limits::min(); - current_statement__ = 91; + current_statement__ = 95; D = stan::math::size(beta_i_raw); int S = std::numeric_limits::min(); - current_statement__ = 92; + current_statement__ = 96; S = (stan::math::rows( stan::model::rvalue(beta_i_raw, "beta_i_raw", stan::model::index_uni(1))) + 1); int N = std::numeric_limits::min(); - current_statement__ = 93; + current_statement__ = 97; N = stan::math::size(X_i); int K_i = std::numeric_limits::min(); - current_statement__ = 94; + current_statement__ = 98; K_i = stan::math::num_elements( stan::model::rvalue(X_i, "X_i", stan::model::index_uni(1))); int K_s = std::numeric_limits::min(); - current_statement__ = 95; + current_statement__ = 99; K_s = stan::math::num_elements( stan::model::rvalue(X_s, "X_s", stan::model::index_uni(1), stan::model::index_uni(1))); int K_o = std::numeric_limits::min(); - current_statement__ = 96; + current_statement__ = 100; K_o = stan::math::num_elements( stan::model::rvalue(X_o, "X_o", stan::model::index_uni(1), stan::model::index_uni(1))); int K_d = std::numeric_limits::min(); - current_statement__ = 97; + current_statement__ = 101; K_d = stan::math::num_elements( stan::model::rvalue(X_d, "X_d", stan::model::index_uni(1))); int C = std::numeric_limits::min(); - current_statement__ = 98; + current_statement__ = 102; C = stan::math::size(M); int max_M = std::numeric_limits::min(); - current_statement__ = 99; + current_statement__ = 103; max_M = stan::math::max(M); - current_statement__ = 100; + current_statement__ = 104; stan::math::validate_non_negative_index("zeros_row_K_i", "K_i", K_i); Eigen::Matrix zeros_row_K_i = Eigen::Matrix::Constant(K_i, DUMMY_VAR__); - current_statement__ = 101; + current_statement__ = 105; stan::model::assign(zeros_row_K_i, stan::math::rep_row_vector(0, K_i), "assigning variable zeros_row_K_i"); - current_statement__ = 102; + current_statement__ = 106; stan::math::validate_non_negative_index("zeros_row_K_s", "K_s", K_s); Eigen::Matrix zeros_row_K_s = Eigen::Matrix::Constant(K_s, DUMMY_VAR__); - current_statement__ = 103; + current_statement__ = 107; stan::model::assign(zeros_row_K_s, stan::math::rep_row_vector(0, K_s), "assigning variable zeros_row_K_s"); - current_statement__ = 104; + current_statement__ = 108; stan::math::validate_non_negative_index("zeros_mat_M_K_o", "max_M", max_M); - current_statement__ = 105; + current_statement__ = 109; stan::math::validate_non_negative_index("zeros_mat_M_K_o", "K_o", K_o); Eigen::Matrix zeros_mat_M_K_o = Eigen::Matrix::Constant(max_M, K_o, DUMMY_VAR__); - current_statement__ = 106; + current_statement__ = 110; stan::model::assign(zeros_mat_M_K_o, stan::math::rep_matrix(0, max_M, K_o), "assigning variable zeros_mat_M_K_o"); - current_statement__ = 107; + current_statement__ = 111; stan::math::validate_non_negative_index("zeros_row_K_d", "K_d", K_d); Eigen::Matrix zeros_row_K_d = Eigen::Matrix::Constant(K_d, DUMMY_VAR__); - current_statement__ = 108; + current_statement__ = 112; stan::model::assign(zeros_row_K_d, stan::math::rep_row_vector(0, K_d), "assigning variable zeros_row_K_d"); - current_statement__ = 109; + current_statement__ = 113; stan::math::validate_non_negative_index("zeros_S", "S", S); Eigen::Matrix zeros_S = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 110; + current_statement__ = 114; stan::model::assign(zeros_S, stan::math::rep_vector(0, S), "assigning variable zeros_S"); - current_statement__ = 111; + current_statement__ = 115; stan::math::validate_non_negative_index("cumsum_M", "C + 1", (C + 1)); std::vector cumsum_M = std::vector((C + 1), std::numeric_limits::min()); - current_statement__ = 112; + current_statement__ = 116; stan::model::assign(cumsum_M, stan::math::append_array(std::vector{0}, stan::math::cumulative_sum(M)), "assigning variable cumsum_M"); - current_statement__ = 113; + current_statement__ = 117; stan::math::validate_non_negative_index("ll", "N", N); - current_statement__ = 114; + current_statement__ = 118; stan::math::validate_non_negative_index("ll", "D", D); Eigen::Matrix ll = Eigen::Matrix::Constant(N, D, DUMMY_VAR__); - current_statement__ = 116; + current_statement__ = 120; stan::math::validate_non_negative_index("log_Pi", "S", S); Eigen::Matrix log_Pi = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 118; + current_statement__ = 122; stan::math::validate_non_negative_index("log_A", "S", S); - current_statement__ = 119; + current_statement__ = 123; stan::math::validate_non_negative_index("log_A", "S", S); Eigen::Matrix log_A = Eigen::Matrix::Constant(S, S, DUMMY_VAR__); - current_statement__ = 121; + current_statement__ = 125; stan::math::validate_non_negative_index("log_B", "S", S); - current_statement__ = 122; + current_statement__ = 126; stan::math::validate_non_negative_index("log_B", "max_M + 1", (max_M + 1)); Eigen::Matrix log_B = Eigen::Matrix::Constant(S, (max_M + 1), DUMMY_VAR__); - current_statement__ = 124; + current_statement__ = 128; stan::math::validate_non_negative_index("log_py", "S", S); Eigen::Matrix log_py = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 126; + current_statement__ = 130; stan::math::validate_non_negative_index("log_alpha", "S", S); Eigen::Matrix log_alpha = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 128; + current_statement__ = 132; stan::math::validate_non_negative_index("log_alpha_new", "S", S); Eigen::Matrix log_alpha_new = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 130; + current_statement__ = 134; stan::math::validate_non_negative_index("beta_i", "S", S); - current_statement__ = 131; + current_statement__ = 135; stan::math::validate_non_negative_index("beta_i", "K_i", K_i); Eigen::Matrix beta_i = Eigen::Matrix::Constant(S, K_i, DUMMY_VAR__); - current_statement__ = 133; + current_statement__ = 137; stan::math::validate_non_negative_index("beta_s", "S", S); - current_statement__ = 134; + current_statement__ = 138; stan::math::validate_non_negative_index("beta_s", "S", S); - current_statement__ = 135; + current_statement__ = 139; stan::math::validate_non_negative_index("beta_s", "K_s", K_s); std::vector> beta_s = std::vector>(S, Eigen::Matrix::Constant(S, K_s, DUMMY_VAR__)); - current_statement__ = 137; + current_statement__ = 141; stan::math::validate_non_negative_index("beta_o", "C", C); - current_statement__ = 138; + current_statement__ = 142; stan::math::validate_non_negative_index("beta_o", "S", S); - current_statement__ = 139; + current_statement__ = 143; stan::math::validate_non_negative_index("beta_o", "max_M", max_M); - current_statement__ = 140; + current_statement__ = 144; stan::math::validate_non_negative_index("beta_o", "K_o", K_o); std::vector>> beta_o = std::vector>>(C, std::vector>(S, Eigen::Matrix::Constant(max_M, K_o, DUMMY_VAR__))); - current_statement__ = 142; + current_statement__ = 146; stan::math::validate_non_negative_index("theta", "D", D); - current_statement__ = 143; + current_statement__ = 147; stan::math::validate_non_negative_index("theta", "K_d", K_d); Eigen::Matrix theta = Eigen::Matrix::Constant(D, K_d, DUMMY_VAR__); - current_statement__ = 144; + current_statement__ = 148; stan::model::assign(theta, stan::math::append_row(zeros_row_K_d, theta_raw), "assigning variable theta"); - current_statement__ = 191; + current_statement__ = 195; for (int d = 1; d <= D; ++d) { - current_statement__ = 145; + current_statement__ = 149; stan::model::assign(beta_i, stan::math::append_row(zeros_row_K_i, stan::model::rvalue(beta_i_raw, "beta_i_raw", stan::model::index_uni(d))), "assigning variable beta_i"); - current_statement__ = 148; + current_statement__ = 152; for (int s = 1; s <= S; ++s) { - current_statement__ = 146; + current_statement__ = 150; stan::model::assign(beta_s, stan::math::append_row(zeros_row_K_s, stan::model::rvalue(beta_s_raw, "beta_s_raw", @@ -567,21 +571,21 @@ loglik_mc_mix(const std::vector>& beta_i_raw, "assigning variable beta_s", stan::model::index_uni(s)); } int idx = std::numeric_limits::min(); - current_statement__ = 149; + current_statement__ = 153; idx = 1; - current_statement__ = 158; + current_statement__ = 162; for (int c = 1; c <= C; ++c) { - current_statement__ = 156; + current_statement__ = 160; for (int s = 1; s <= S; ++s) { - current_statement__ = 150; + current_statement__ = 154; stan::model::assign(beta_o, zeros_mat_M_K_o, "assigning variable beta_o", stan::model::index_uni(c), stan::model::index_uni(s), stan::model::index_omni(), stan::model::index_omni()); - current_statement__ = 154; + current_statement__ = 158; for (int m = 2; m <= stan::model::rvalue(M, "M", stan::model::index_uni(c)); ++m) { - current_statement__ = 151; + current_statement__ = 155; stan::model::assign(beta_o, stan::model::rvalue(beta_o_raw, "beta_o_raw", stan::model::index_uni(d), @@ -589,29 +593,29 @@ loglik_mc_mix(const std::vector>& beta_i_raw, "assigning variable beta_o", stan::model::index_uni(c), stan::model::index_uni(s), stan::model::index_uni(m), stan::model::index_omni()); - current_statement__ = 152; + current_statement__ = 156; idx = (idx + K_o); } } } - current_statement__ = 189; + current_statement__ = 193; for (int ii = 1; ii <= N_sample; ++ii) { int i = std::numeric_limits::min(); - current_statement__ = 159; + current_statement__ = 163; i = stan::model::rvalue(ids, "ids", stan::model::index_uni(ii)); - current_statement__ = 160; + current_statement__ = 164; stan::model::assign(log_Pi, stan::math::log_softmax( stan::math::multiply(beta_i, stan::model::rvalue(X_i, "X_i", stan::model::index_uni(i)))), "assigning variable log_Pi"); - current_statement__ = 161; + current_statement__ = 165; stan::model::assign(log_py, zeros_S, "assigning variable log_py"); - current_statement__ = 168; + current_statement__ = 172; for (int c = 1; c <= C; ++c) { - current_statement__ = 165; + current_statement__ = 169; for (int s = 1; s <= S; ++s) { - current_statement__ = 162; + current_statement__ = 166; stan::model::assign(log_B, stan::math::transpose( stan::math::log_softmax( @@ -626,13 +630,13 @@ loglik_mc_mix(const std::vector>& beta_i_raw, "assigning variable log_B", stan::model::index_uni(s), stan::model::index_min_max(1, stan::model::rvalue(M, "M", stan::model::index_uni(c)))); - current_statement__ = 163; + current_statement__ = 167; stan::model::assign(log_B, 0, "assigning variable log_B", stan::model::index_uni(s), stan::model::index_uni( (stan::model::rvalue(M, "M", stan::model::index_uni(c)) + 1))); } - current_statement__ = 166; + current_statement__ = 170; stan::model::assign(log_py, stan::math::add(stan::model::deep_copy(log_py), stan::model::rvalue(log_B, "log_B", stan::model::index_omni(), @@ -641,19 +645,19 @@ loglik_mc_mix(const std::vector>& beta_i_raw, stan::model::index_uni(1), stan::model::index_uni(i))))), "assigning variable log_py"); } - current_statement__ = 169; + current_statement__ = 173; stan::model::assign(log_alpha, stan::math::add(log_Pi, log_py), "assigning variable log_alpha"); - current_statement__ = 186; + current_statement__ = 190; for (int t = 2; t <= stan::model::rvalue(T, "T", stan::model::index_uni(i)); ++t) { - current_statement__ = 170; + current_statement__ = 174; stan::model::assign(log_py, zeros_S, "assigning variable log_py"); - current_statement__ = 177; + current_statement__ = 181; for (int c = 1; c <= C; ++c) { - current_statement__ = 174; + current_statement__ = 178; for (int s = 1; s <= S; ++s) { - current_statement__ = 171; + current_statement__ = 175; stan::model::assign(log_B, stan::math::transpose( stan::math::log_softmax( @@ -669,14 +673,14 @@ loglik_mc_mix(const std::vector>& beta_i_raw, "assigning variable log_B", stan::model::index_uni(s), stan::model::index_min_max(1, stan::model::rvalue(M, "M", stan::model::index_uni(c)))); - current_statement__ = 172; + current_statement__ = 176; stan::model::assign(log_B, 0, "assigning variable log_B", stan::model::index_uni(s), stan::model::index_uni( (stan::model::rvalue(M, "M", stan::model::index_uni(c)) + 1))); } - current_statement__ = 175; + current_statement__ = 179; stan::model::assign(log_py, stan::math::add(stan::model::deep_copy(log_py), stan::model::rvalue(log_B, "log_B", @@ -687,9 +691,9 @@ loglik_mc_mix(const std::vector>& beta_i_raw, stan::model::index_uni(i))))), "assigning variable log_py"); } - current_statement__ = 180; + current_statement__ = 184; for (int s = 1; s <= S; ++s) { - current_statement__ = 178; + current_statement__ = 182; stan::model::assign(log_A, stan::math::transpose( stan::math::log_softmax( @@ -702,9 +706,9 @@ loglik_mc_mix(const std::vector>& beta_i_raw, "assigning variable log_A", stan::model::index_uni(s), stan::model::index_omni()); } - current_statement__ = 183; + current_statement__ = 187; for (int k = 1; k <= S; ++k) { - current_statement__ = 181; + current_statement__ = 185; stan::model::assign(log_alpha_new, stan::math::log_sum_exp( stan::math::add( @@ -715,36 +719,36 @@ loglik_mc_mix(const std::vector>& beta_i_raw, stan::model::index_uni(k)))), "assigning variable log_alpha_new", stan::model::index_uni(k)); } - current_statement__ = 184; + current_statement__ = 188; stan::model::assign(log_alpha, log_alpha_new, "assigning variable log_alpha"); } - current_statement__ = 187; + current_statement__ = 191; stan::model::assign(ll, stan::math::log_sum_exp(log_alpha), "assigning variable ll", stan::model::index_uni(i), stan::model::index_uni(d)); } } - current_statement__ = 192; + current_statement__ = 196; stan::math::validate_non_negative_index("ll_i", "N_sample", N_sample); Eigen::Matrix ll_i = Eigen::Matrix::Constant(N_sample, DUMMY_VAR__); - current_statement__ = 199; + current_statement__ = 203; for (int ii = 1; ii <= N_sample; ++ii) { int i = std::numeric_limits::min(); - current_statement__ = 194; + current_statement__ = 198; i = stan::model::rvalue(ids, "ids", stan::model::index_uni(ii)); - current_statement__ = 195; + current_statement__ = 199; stan::math::validate_non_negative_index("log_omega", "D", D); Eigen::Matrix log_omega = Eigen::Matrix::Constant(D, DUMMY_VAR__); - current_statement__ = 196; + current_statement__ = 200; stan::model::assign(log_omega, stan::math::log_softmax( stan::math::multiply(theta, stan::model::rvalue(X_d, "X_d", stan::model::index_uni(i)))), "assigning variable log_omega"); - current_statement__ = 197; + current_statement__ = 201; stan::model::assign(ll_i, stan::math::log_sum_exp( stan::math::add(log_omega, @@ -753,7 +757,7 @@ loglik_mc_mix(const std::vector>& beta_i_raw, stan::model::index_omni())))), "assigning variable ll_i", stan::model::index_uni(i)); } - current_statement__ = 200; + current_statement__ = 204; return stan::math::sum(ll_i); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -778,6 +782,8 @@ class model_multichannel_mnhmm final : public model_base_crtp>> X_s; int K_o; std::vector>> X_o; + int penalize; + double penalty; int D; int K_d; std::vector> X_d; @@ -806,77 +812,77 @@ class model_multichannel_mnhmm final : public model_base_crtp::min(); pos__ = 1; - current_statement__ = 21; + current_statement__ = 23; context__.validate_dims("data initialization", "N", "int", std::vector{}); N = std::numeric_limits::min(); - current_statement__ = 21; + current_statement__ = 23; N = context__.vals_i("N")[(1 - 1)]; - current_statement__ = 21; + current_statement__ = 23; stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 22; + current_statement__ = 24; context__.validate_dims("data initialization", "max_T", "int", std::vector{}); max_T = std::numeric_limits::min(); - current_statement__ = 22; + current_statement__ = 24; max_T = context__.vals_i("max_T")[(1 - 1)]; - current_statement__ = 22; + current_statement__ = 24; stan::math::check_greater_or_equal(function__, "max_T", max_T, 2); - current_statement__ = 23; + current_statement__ = 25; stan::math::validate_non_negative_index("T", "N", N); - current_statement__ = 24; + current_statement__ = 26; context__.validate_dims("data initialization", "T", "int", std::vector{static_cast(N)}); T = std::vector(N, std::numeric_limits::min()); - current_statement__ = 24; + current_statement__ = 26; T = context__.vals_i("T"); - current_statement__ = 24; + current_statement__ = 26; stan::math::check_greater_or_equal(function__, "T", T, 2); - current_statement__ = 24; + current_statement__ = 26; stan::math::check_less_or_equal(function__, "T", T, max_T); - current_statement__ = 25; + current_statement__ = 27; context__.validate_dims("data initialization", "max_M", "int", std::vector{}); max_M = std::numeric_limits::min(); - current_statement__ = 25; + current_statement__ = 27; max_M = context__.vals_i("max_M")[(1 - 1)]; - current_statement__ = 25; + current_statement__ = 27; stan::math::check_greater_or_equal(function__, "max_M", max_M, 2); - current_statement__ = 26; + current_statement__ = 28; context__.validate_dims("data initialization", "S", "int", std::vector{}); S = std::numeric_limits::min(); - current_statement__ = 26; + current_statement__ = 28; S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 26; + current_statement__ = 28; stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 27; + current_statement__ = 29; context__.validate_dims("data initialization", "C", "int", std::vector{}); C = std::numeric_limits::min(); - current_statement__ = 27; + current_statement__ = 29; C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 27; + current_statement__ = 29; stan::math::check_greater_or_equal(function__, "C", C, 2); - current_statement__ = 28; + current_statement__ = 30; stan::math::validate_non_negative_index("M", "C", C); - current_statement__ = 29; + current_statement__ = 31; context__.validate_dims("data initialization", "M", "int", std::vector{static_cast(C)}); M = std::vector(C, std::numeric_limits::min()); - current_statement__ = 29; + current_statement__ = 31; M = context__.vals_i("M"); - current_statement__ = 29; + current_statement__ = 31; stan::math::check_greater_or_equal(function__, "M", M, 2); - current_statement__ = 29; + current_statement__ = 31; stan::math::check_less_or_equal(function__, "M", M, max_M); - current_statement__ = 30; + current_statement__ = 32; stan::math::validate_non_negative_index("obs", "C", C); - current_statement__ = 31; + current_statement__ = 33; stan::math::validate_non_negative_index("obs", "max_T", max_T); - current_statement__ = 32; + current_statement__ = 34; stan::math::validate_non_negative_index("obs", "N", N); - current_statement__ = 33; + current_statement__ = 35; context__.validate_dims("data initialization", "obs", "int", std::vector{static_cast(C), static_cast(max_T), static_cast(N)}); @@ -885,60 +891,60 @@ class model_multichannel_mnhmm final : public model_base_crtp(N, std::numeric_limits::min()))); { std::vector obs_flat__; - current_statement__ = 33; + current_statement__ = 35; obs_flat__ = context__.vals_i("obs"); - current_statement__ = 33; + current_statement__ = 35; pos__ = 1; - current_statement__ = 33; + current_statement__ = 35; for (int sym1__ = 1; sym1__ <= N; ++sym1__) { - current_statement__ = 33; + current_statement__ = 35; for (int sym2__ = 1; sym2__ <= max_T; ++sym2__) { - current_statement__ = 33; + current_statement__ = 35; for (int sym3__ = 1; sym3__ <= C; ++sym3__) { - current_statement__ = 33; + current_statement__ = 35; stan::model::assign(obs, obs_flat__[(pos__ - 1)], "assigning variable obs", stan::model::index_uni(sym3__), stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 33; + current_statement__ = 35; pos__ = (pos__ + 1); } } } } - current_statement__ = 33; + current_statement__ = 35; stan::math::check_greater_or_equal(function__, "obs", obs, 0); - current_statement__ = 33; + current_statement__ = 35; stan::math::check_less_or_equal(function__, "obs", obs, (max_M + 1)); - current_statement__ = 34; + current_statement__ = 36; context__.validate_dims("data initialization", "N_sample", "int", std::vector{}); N_sample = std::numeric_limits::min(); - current_statement__ = 34; + current_statement__ = 36; N_sample = context__.vals_i("N_sample")[(1 - 1)]; - current_statement__ = 34; + current_statement__ = 36; stan::math::check_less_or_equal(function__, "N_sample", N_sample, N); - current_statement__ = 35; + current_statement__ = 37; stan::math::validate_non_negative_index("ids", "N_sample", N_sample); - current_statement__ = 36; + current_statement__ = 38; context__.validate_dims("data initialization", "ids", "int", std::vector{static_cast(N_sample)}); ids = std::vector(N_sample, std::numeric_limits::min()); - current_statement__ = 36; + current_statement__ = 38; ids = context__.vals_i("ids"); - current_statement__ = 37; + current_statement__ = 39; context__.validate_dims("data initialization", "K_i", "int", std::vector{}); K_i = std::numeric_limits::min(); - current_statement__ = 37; + current_statement__ = 39; K_i = context__.vals_i("K_i")[(1 - 1)]; - current_statement__ = 37; + current_statement__ = 39; stan::math::check_greater_or_equal(function__, "K_i", K_i, 1); - current_statement__ = 38; + current_statement__ = 40; stan::math::validate_non_negative_index("X_i", "N", N); - current_statement__ = 39; + current_statement__ = 41; stan::math::validate_non_negative_index("X_i", "K_i", K_i); - current_statement__ = 40; + current_statement__ = 42; context__.validate_dims("data initialization", "X_i", "double", std::vector{static_cast(N), static_cast(K_i)}); X_i = std::vector>(N, @@ -946,38 +952,38 @@ class model_multichannel_mnhmm final : public model_base_crtp::quiet_NaN())); { std::vector X_i_flat__; - current_statement__ = 40; + current_statement__ = 42; X_i_flat__ = context__.vals_r("X_i"); - current_statement__ = 40; + current_statement__ = 42; pos__ = 1; - current_statement__ = 40; + current_statement__ = 42; for (int sym1__ = 1; sym1__ <= K_i; ++sym1__) { - current_statement__ = 40; + current_statement__ = 42; for (int sym2__ = 1; sym2__ <= N; ++sym2__) { - current_statement__ = 40; + current_statement__ = 42; stan::model::assign(X_i, X_i_flat__[(pos__ - 1)], "assigning variable X_i", stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 40; + current_statement__ = 42; pos__ = (pos__ + 1); } } } - current_statement__ = 41; + current_statement__ = 43; context__.validate_dims("data initialization", "K_s", "int", std::vector{}); K_s = std::numeric_limits::min(); - current_statement__ = 41; + current_statement__ = 43; K_s = context__.vals_i("K_s")[(1 - 1)]; - current_statement__ = 41; + current_statement__ = 43; stan::math::check_greater_or_equal(function__, "K_s", K_s, 1); - current_statement__ = 42; + current_statement__ = 44; stan::math::validate_non_negative_index("X_s", "max_T", max_T); - current_statement__ = 43; + current_statement__ = 45; stan::math::validate_non_negative_index("X_s", "N", N); - current_statement__ = 44; + current_statement__ = 46; stan::math::validate_non_negative_index("X_s", "K_s", K_s); - current_statement__ = 45; + current_statement__ = 47; context__.validate_dims("data initialization", "X_s", "double", std::vector{static_cast(max_T), static_cast(N), static_cast(K_s)}); @@ -987,42 +993,42 @@ class model_multichannel_mnhmm final : public model_base_crtp::quiet_NaN()))); { std::vector X_s_flat__; - current_statement__ = 45; + current_statement__ = 47; X_s_flat__ = context__.vals_r("X_s"); - current_statement__ = 45; + current_statement__ = 47; pos__ = 1; - current_statement__ = 45; + current_statement__ = 47; for (int sym1__ = 1; sym1__ <= K_s; ++sym1__) { - current_statement__ = 45; + current_statement__ = 47; for (int sym2__ = 1; sym2__ <= N; ++sym2__) { - current_statement__ = 45; + current_statement__ = 47; for (int sym3__ = 1; sym3__ <= max_T; ++sym3__) { - current_statement__ = 45; + current_statement__ = 47; stan::model::assign(X_s, X_s_flat__[(pos__ - 1)], "assigning variable X_s", stan::model::index_uni(sym3__), stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 45; + current_statement__ = 47; pos__ = (pos__ + 1); } } } } - current_statement__ = 46; + current_statement__ = 48; context__.validate_dims("data initialization", "K_o", "int", std::vector{}); K_o = std::numeric_limits::min(); - current_statement__ = 46; + current_statement__ = 48; K_o = context__.vals_i("K_o")[(1 - 1)]; - current_statement__ = 46; + current_statement__ = 48; stan::math::check_greater_or_equal(function__, "K_o", K_o, 1); - current_statement__ = 47; + current_statement__ = 49; stan::math::validate_non_negative_index("X_o", "max_T", max_T); - current_statement__ = 48; + current_statement__ = 50; stan::math::validate_non_negative_index("X_o", "N", N); - current_statement__ = 49; + current_statement__ = 51; stan::math::validate_non_negative_index("X_o", "K_o", K_o); - current_statement__ = 50; + current_statement__ = 52; context__.validate_dims("data initialization", "X_o", "double", std::vector{static_cast(max_T), static_cast(N), static_cast(K_o)}); @@ -1032,48 +1038,66 @@ class model_multichannel_mnhmm final : public model_base_crtp::quiet_NaN()))); { std::vector X_o_flat__; - current_statement__ = 50; + current_statement__ = 52; X_o_flat__ = context__.vals_r("X_o"); - current_statement__ = 50; + current_statement__ = 52; pos__ = 1; - current_statement__ = 50; + current_statement__ = 52; for (int sym1__ = 1; sym1__ <= K_o; ++sym1__) { - current_statement__ = 50; + current_statement__ = 52; for (int sym2__ = 1; sym2__ <= N; ++sym2__) { - current_statement__ = 50; + current_statement__ = 52; for (int sym3__ = 1; sym3__ <= max_T; ++sym3__) { - current_statement__ = 50; + current_statement__ = 52; stan::model::assign(X_o, X_o_flat__[(pos__ - 1)], "assigning variable X_o", stan::model::index_uni(sym3__), stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 50; + current_statement__ = 52; pos__ = (pos__ + 1); } } } } - current_statement__ = 51; + current_statement__ = 53; + context__.validate_dims("data initialization", "penalize", "int", + std::vector{}); + penalize = std::numeric_limits::min(); + current_statement__ = 53; + penalize = context__.vals_i("penalize")[(1 - 1)]; + current_statement__ = 53; + stan::math::check_greater_or_equal(function__, "penalize", penalize, 0); + current_statement__ = 53; + stan::math::check_less_or_equal(function__, "penalize", penalize, 1); + current_statement__ = 54; + context__.validate_dims("data initialization", "penalty", "double", + std::vector{}); + penalty = std::numeric_limits::quiet_NaN(); + current_statement__ = 54; + penalty = context__.vals_r("penalty")[(1 - 1)]; + current_statement__ = 54; + stan::math::check_greater_or_equal(function__, "penalty", penalty, 0); + current_statement__ = 55; context__.validate_dims("data initialization", "D", "int", std::vector{}); D = std::numeric_limits::min(); - current_statement__ = 51; + current_statement__ = 55; D = context__.vals_i("D")[(1 - 1)]; - current_statement__ = 51; + current_statement__ = 55; stan::math::check_greater_or_equal(function__, "D", D, 2); - current_statement__ = 52; + current_statement__ = 56; context__.validate_dims("data initialization", "K_d", "int", std::vector{}); K_d = std::numeric_limits::min(); - current_statement__ = 52; + current_statement__ = 56; K_d = context__.vals_i("K_d")[(1 - 1)]; - current_statement__ = 52; + current_statement__ = 56; stan::math::check_greater_or_equal(function__, "K_d", K_d, 1); - current_statement__ = 53; + current_statement__ = 57; stan::math::validate_non_negative_index("X_d", "N", N); - current_statement__ = 54; + current_statement__ = 58; stan::math::validate_non_negative_index("X_d", "K_d", K_d); - current_statement__ = 55; + current_statement__ = 59; context__.validate_dims("data initialization", "X_d", "double", std::vector{static_cast(N), static_cast(K_d)}); X_d = std::vector>(N, @@ -1081,64 +1105,64 @@ class model_multichannel_mnhmm final : public model_base_crtp::quiet_NaN())); { std::vector X_d_flat__; - current_statement__ = 55; + current_statement__ = 59; X_d_flat__ = context__.vals_r("X_d"); - current_statement__ = 55; + current_statement__ = 59; pos__ = 1; - current_statement__ = 55; + current_statement__ = 59; for (int sym1__ = 1; sym1__ <= K_d; ++sym1__) { - current_statement__ = 55; + current_statement__ = 59; for (int sym2__ = 1; sym2__ <= N; ++sym2__) { - current_statement__ = 55; + current_statement__ = 59; stan::model::assign(X_d, X_d_flat__[(pos__ - 1)], "assigning variable X_d", stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 55; + current_statement__ = 59; pos__ = (pos__ + 1); } } } - current_statement__ = 56; + current_statement__ = 60; stan::math::validate_non_negative_index("beta_i_raw", "D", D); - current_statement__ = 57; + current_statement__ = 61; beta_i_raw_2dim__ = std::numeric_limits::min(); - current_statement__ = 57; + current_statement__ = 61; beta_i_raw_2dim__ = (S - 1); - current_statement__ = 57; + current_statement__ = 61; stan::math::validate_non_negative_index("beta_i_raw", "S - 1", beta_i_raw_2dim__); - current_statement__ = 58; + current_statement__ = 62; stan::math::validate_non_negative_index("beta_i_raw", "K_i", K_i); - current_statement__ = 59; + current_statement__ = 63; stan::math::validate_non_negative_index("beta_s_raw", "D", D); - current_statement__ = 60; + current_statement__ = 64; stan::math::validate_non_negative_index("beta_s_raw", "S", S); - current_statement__ = 61; + current_statement__ = 65; beta_s_raw_3dim__ = std::numeric_limits::min(); - current_statement__ = 61; + current_statement__ = 65; beta_s_raw_3dim__ = (S - 1); - current_statement__ = 61; + current_statement__ = 65; stan::math::validate_non_negative_index("beta_s_raw", "S - 1", beta_s_raw_3dim__); - current_statement__ = 62; + current_statement__ = 66; stan::math::validate_non_negative_index("beta_s_raw", "K_s", K_s); - current_statement__ = 63; + current_statement__ = 67; stan::math::validate_non_negative_index("beta_o_raw", "D", D); - current_statement__ = 64; + current_statement__ = 68; beta_o_raw_2dim__ = std::numeric_limits::min(); - current_statement__ = 64; + current_statement__ = 68; beta_o_raw_2dim__ = ((S * (stan::math::sum(M) - C)) * K_o); - current_statement__ = 64; + current_statement__ = 68; stan::math::validate_non_negative_index("beta_o_raw", "S * (sum(M) - C) * K_o", beta_o_raw_2dim__); - current_statement__ = 65; + current_statement__ = 69; theta_raw_1dim__ = std::numeric_limits::min(); - current_statement__ = 65; + current_statement__ = 69; theta_raw_1dim__ = (D - 1); - current_statement__ = 65; + current_statement__ = 69; stan::math::validate_non_negative_index("theta_raw", "D - 1", theta_raw_1dim__); - current_statement__ = 66; + current_statement__ = 70; stan::math::validate_non_negative_index("theta_raw", "K_d", K_d); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -1211,41 +1235,45 @@ class model_multichannel_mnhmm final : public model_base_crtp( - stan::math::to_vector( - stan::model::rvalue(beta_i_raw, "beta_i_raw", - stan::model::index_uni(d))), 0, 5)); - current_statement__ = 11; - for (int s = 1; s <= S; ++s) { - current_statement__ = 9; + current_statement__ = 17; + if (stan::math::logical_eq(penalize, 1)) { + current_statement__ = 14; + for (int d = 1; d <= D; ++d) { + current_statement__ = 8; prior = (prior + stan::math::normal_lpdf( stan::math::to_vector( - stan::model::rvalue(beta_s_raw, "beta_s_raw", - stan::model::index_uni(d), stan::model::index_uni(s))), 0, - 5)); + stan::model::rvalue(beta_i_raw, "beta_i_raw", + stan::model::index_uni(d))), 0, penalty)); + current_statement__ = 11; + for (int s = 1; s <= S; ++s) { + current_statement__ = 9; + prior = (prior + + stan::math::normal_lpdf( + stan::math::to_vector( + stan::model::rvalue(beta_s_raw, "beta_s_raw", + stan::model::index_uni(d), stan::model::index_uni(s))), + 0, penalty)); + } + current_statement__ = 12; + prior = (prior + + stan::math::normal_lpdf( + stan::model::rvalue(beta_o_raw, "beta_o_raw", + stan::model::index_uni(d)), 0, penalty)); } - current_statement__ = 12; + current_statement__ = 15; prior = (prior + - stan::math::normal_lpdf( - stan::model::rvalue(beta_o_raw, "beta_o_raw", - stan::model::index_uni(d)), 0, 5)); + stan::math::normal_lpdf(stan::math::to_vector(theta_raw), 0, + penalty)); } - current_statement__ = 15; - prior = (prior + - stan::math::normal_lpdf(stan::math::to_vector(theta_raw), 0, 5)); local_scalar_t__ log_lik = DUMMY_VAR__; current_statement__ = 6; log_lik = loglik_mc_mix(beta_i_raw, beta_s_raw, beta_o_raw, theta_raw, obs, M, T, N_sample, ids, X_s, X_o, X_i, X_d, pstream__); { - current_statement__ = 19; + current_statement__ = 21; lp_accum__.add(prior); - current_statement__ = 20; + current_statement__ = 22; lp_accum__.add(log_lik); } } catch (const std::exception& e) { @@ -1356,33 +1384,37 @@ class model_multichannel_mnhmm final : public model_base_crtp( - stan::math::to_vector( - stan::model::rvalue(beta_i_raw, "beta_i_raw", - stan::model::index_uni(d))), 0, 5)); - current_statement__ = 11; - for (int s = 1; s <= S; ++s) { - current_statement__ = 9; + current_statement__ = 17; + if (stan::math::logical_eq(penalize, 1)) { + current_statement__ = 14; + for (int d = 1; d <= D; ++d) { + current_statement__ = 8; prior = (prior + stan::math::normal_lpdf( stan::math::to_vector( - stan::model::rvalue(beta_s_raw, "beta_s_raw", - stan::model::index_uni(d), stan::model::index_uni(s))), 0, - 5)); + stan::model::rvalue(beta_i_raw, "beta_i_raw", + stan::model::index_uni(d))), 0, penalty)); + current_statement__ = 11; + for (int s = 1; s <= S; ++s) { + current_statement__ = 9; + prior = (prior + + stan::math::normal_lpdf( + stan::math::to_vector( + stan::model::rvalue(beta_s_raw, "beta_s_raw", + stan::model::index_uni(d), stan::model::index_uni(s))), + 0, penalty)); + } + current_statement__ = 12; + prior = (prior + + stan::math::normal_lpdf( + stan::model::rvalue(beta_o_raw, "beta_o_raw", + stan::model::index_uni(d)), 0, penalty)); } - current_statement__ = 12; + current_statement__ = 15; prior = (prior + - stan::math::normal_lpdf( - stan::model::rvalue(beta_o_raw, "beta_o_raw", - stan::model::index_uni(d)), 0, 5)); + stan::math::normal_lpdf(stan::math::to_vector(theta_raw), 0, + penalty)); } - current_statement__ = 15; - prior = (prior + - stan::math::normal_lpdf(stan::math::to_vector(theta_raw), 0, 5)); current_statement__ = 6; log_lik = loglik_mc_mix(beta_i_raw, beta_s_raw, beta_o_raw, theta_raw, obs, M, T, N_sample, ids, X_s, X_o, X_i, X_d, pstream__); @@ -1396,9 +1428,9 @@ class model_multichannel_mnhmm final : public model_base_crtp::quiet_NaN(); current_statement__ = 7; ploglik_N = (prior + log_lik); - current_statement__ = 18; + current_statement__ = 20; if (stan::math::logical_gt(N, N_sample)) { - current_statement__ = 16; + current_statement__ = 18; ploglik_N = (prior + loglik_mc_mix(beta_i_raw, beta_s_raw, beta_o_raw, theta_raw, obs, M, T, N, stan::math::linspaced_int_array(N, 1, N), X_s, X_o, X_i, diff --git a/src/stanExports_multichannel_nhmm.h b/src/stanExports_multichannel_nhmm.h index 25818ef6..b39ef3eb 100644 --- a/src/stanExports_multichannel_nhmm.h +++ b/src/stanExports_multichannel_nhmm.h @@ -27,24 +27,26 @@ namespace model_multichannel_nhmm_namespace { using stan::model::model_base_crtp; using namespace stan::math; stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = +static constexpr std::array locations_array__ = {" (found before start of program)", - " (in 'string', line 125, column 2 to column 32)", - " (in 'string', line 127, column 2 to column 41)", - " (in 'string', line 129, column 2 to column 48)", - " (in 'string', line 132, column 0 to column 15)", - " (in 'string', line 139, column 2 to line 140, column 32)", - " (in 'string', line 147, column 2 to column 35)", - " (in 'string', line 134, column 0 to column 51)", - " (in 'string', line 136, column 2 to column 56)", - " (in 'string', line 135, column 14 to line 137, column 1)", - " (in 'string', line 135, column 0 to line 137, column 1)", - " (in 'string', line 138, column 0 to column 40)", - " (in 'string', line 149, column 4 to line 150, column 58)", - " (in 'string', line 148, column 20 to line 151, column 3)", - " (in 'string', line 148, column 2 to line 151, column 3)", - " (in 'string', line 143, column 2 to column 18)", - " (in 'string', line 144, column 2 to column 20)", + " (in 'string', line 127, column 2 to column 32)", + " (in 'string', line 129, column 2 to column 41)", + " (in 'string', line 131, column 2 to column 48)", + " (in 'string', line 134, column 0 to column 15)", + " (in 'string', line 143, column 2 to line 144, column 32)", + " (in 'string', line 151, column 2 to column 35)", + " (in 'string', line 137, column 2 to column 59)", + " (in 'string', line 139, column 4 to column 64)", + " (in 'string', line 138, column 16 to line 140, column 3)", + " (in 'string', line 138, column 2 to line 140, column 3)", + " (in 'string', line 141, column 2 to column 48)", + " (in 'string', line 135, column 19 to line 142, column 1)", + " (in 'string', line 135, column 0 to line 142, column 1)", + " (in 'string', line 153, column 4 to line 154, column 58)", + " (in 'string', line 152, column 20 to line 155, column 3)", + " (in 'string', line 152, column 2 to line 155, column 3)", + " (in 'string', line 147, column 2 to column 18)", + " (in 'string', line 148, column 2 to column 20)", " (in 'string', line 106, column 2 to column 17)", " (in 'string', line 107, column 2 to column 21)", " (in 'string', line 108, column 8 to column 9)", @@ -75,12 +77,14 @@ static constexpr std::array locations_array__ = " (in 'string', line 121, column 15 to column 16)", " (in 'string', line 121, column 25 to column 28)", " (in 'string', line 121, column 2 to column 34)", - " (in 'string', line 125, column 9 to column 14)", - " (in 'string', line 125, column 16 to column 19)", - " (in 'string', line 127, column 8 to column 9)", - " (in 'string', line 127, column 18 to column 23)", - " (in 'string', line 127, column 25 to column 28)", - " (in 'string', line 129, column 13 to column 35)", + " (in 'string', line 122, column 2 to column 32)", + " (in 'string', line 123, column 2 to column 24)", + " (in 'string', line 127, column 9 to column 14)", + " (in 'string', line 127, column 16 to column 19)", + " (in 'string', line 129, column 8 to column 9)", + " (in 'string', line 129, column 18 to column 23)", + " (in 'string', line 129, column 25 to column 28)", + " (in 'string', line 131, column 13 to column 35)", " (in 'string', line 8, column 4 to column 25)", " (in 'string', line 9, column 10 to column 16)", " (in 'string', line 9, column 4 to column 24)", @@ -240,21 +244,21 @@ add(const std::vector& x, const std::vector& y, std::ostream* (void) DUMMY_VAR__; try { int x_size = std::numeric_limits::min(); - current_statement__ = 53; + current_statement__ = 57; x_size = stan::math::size(x); - current_statement__ = 54; + current_statement__ = 58; stan::math::validate_non_negative_index("z", "x_size", x_size); std::vector z = std::vector(x_size, std::numeric_limits::min()); - current_statement__ = 58; + current_statement__ = 62; for (int i = 1; i <= x_size; ++i) { - current_statement__ = 56; + current_statement__ = 60; stan::model::assign(z, (stan::model::rvalue(x, "x", stan::model::index_uni(i)) + stan::model::rvalue(y, "y", stan::model::index_uni(i))), "assigning variable z", stan::model::index_uni(i)); } - current_statement__ = 59; + current_statement__ = 63; return z; } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -272,20 +276,20 @@ add(const int& x, const std::vector& y, std::ostream* pstream__) { (void) DUMMY_VAR__; try { int y_size = std::numeric_limits::min(); - current_statement__ = 61; + current_statement__ = 65; y_size = stan::math::size(y); - current_statement__ = 62; + current_statement__ = 66; stan::math::validate_non_negative_index("z", "y_size", y_size); std::vector z = std::vector(y_size, std::numeric_limits::min()); - current_statement__ = 66; + current_statement__ = 70; for (int i = 1; i <= y_size; ++i) { - current_statement__ = 64; + current_statement__ = 68; stan::model::assign(z, (x + stan::model::rvalue(y, "y", stan::model::index_uni(i))), "assigning variable z", stan::model::index_uni(i)); } - current_statement__ = 67; + current_statement__ = 71; return z; } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -303,20 +307,20 @@ add(const std::vector& x, const int& y, std::ostream* pstream__) { (void) DUMMY_VAR__; try { int x_size = std::numeric_limits::min(); - current_statement__ = 69; + current_statement__ = 73; x_size = stan::math::size(x); - current_statement__ = 70; + current_statement__ = 74; stan::math::validate_non_negative_index("z", "x_size", x_size); std::vector z = std::vector(x_size, std::numeric_limits::min()); - current_statement__ = 74; + current_statement__ = 78; for (int i = 1; i <= x_size; ++i) { - current_statement__ = 72; + current_statement__ = 76; stan::model::assign(z, (stan::model::rvalue(x, "x", stan::model::index_uni(i)) + y), "assigning variable z", stan::model::index_uni(i)); } - current_statement__ = 75; + current_statement__ = 79; return z; } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -358,139 +362,139 @@ loglik_mc(const T0__& beta_i_raw_arg__, (void) DUMMY_VAR__; try { int S = std::numeric_limits::min(); - current_statement__ = 77; + current_statement__ = 81; S = (stan::math::rows(beta_i_raw) + 1); int N = std::numeric_limits::min(); - current_statement__ = 78; + current_statement__ = 82; N = stan::math::size(X_i); int K_i = std::numeric_limits::min(); - current_statement__ = 79; + current_statement__ = 83; K_i = stan::math::num_elements( stan::model::rvalue(X_i, "X_i", stan::model::index_uni(1))); int K_s = std::numeric_limits::min(); - current_statement__ = 80; + current_statement__ = 84; K_s = stan::math::num_elements( stan::model::rvalue(X_s, "X_s", stan::model::index_uni(1), stan::model::index_uni(1))); int K_o = std::numeric_limits::min(); - current_statement__ = 81; + current_statement__ = 85; K_o = stan::math::num_elements( stan::model::rvalue(X_o, "X_o", stan::model::index_uni(1), stan::model::index_uni(1))); int C = std::numeric_limits::min(); - current_statement__ = 82; + current_statement__ = 86; C = stan::math::size(M); int max_M = std::numeric_limits::min(); - current_statement__ = 83; + current_statement__ = 87; max_M = stan::math::max(M); - current_statement__ = 84; + current_statement__ = 88; stan::math::validate_non_negative_index("zeros_row_K_i", "K_i", K_i); Eigen::Matrix zeros_row_K_i = Eigen::Matrix::Constant(K_i, DUMMY_VAR__); - current_statement__ = 85; + current_statement__ = 89; stan::model::assign(zeros_row_K_i, stan::math::rep_row_vector(0, K_i), "assigning variable zeros_row_K_i"); - current_statement__ = 86; + current_statement__ = 90; stan::math::validate_non_negative_index("zeros_row_K_s", "K_s", K_s); Eigen::Matrix zeros_row_K_s = Eigen::Matrix::Constant(K_s, DUMMY_VAR__); - current_statement__ = 87; + current_statement__ = 91; stan::model::assign(zeros_row_K_s, stan::math::rep_row_vector(0, K_s), "assigning variable zeros_row_K_s"); - current_statement__ = 88; + current_statement__ = 92; stan::math::validate_non_negative_index("zeros_mat_M_K_o", "max_M", max_M); - current_statement__ = 89; + current_statement__ = 93; stan::math::validate_non_negative_index("zeros_mat_M_K_o", "K_o", K_o); Eigen::Matrix zeros_mat_M_K_o = Eigen::Matrix::Constant(max_M, K_o, DUMMY_VAR__); - current_statement__ = 90; + current_statement__ = 94; stan::model::assign(zeros_mat_M_K_o, stan::math::rep_matrix(0, max_M, K_o), "assigning variable zeros_mat_M_K_o"); - current_statement__ = 91; + current_statement__ = 95; stan::math::validate_non_negative_index("zeros_S", "S", S); Eigen::Matrix zeros_S = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 92; + current_statement__ = 96; stan::model::assign(zeros_S, stan::math::rep_vector(0, S), "assigning variable zeros_S"); - current_statement__ = 93; + current_statement__ = 97; stan::math::validate_non_negative_index("cumsum_M", "C + 1", (C + 1)); std::vector cumsum_M = std::vector((C + 1), std::numeric_limits::min()); - current_statement__ = 94; + current_statement__ = 98; stan::model::assign(cumsum_M, stan::math::append_array(std::vector{0}, stan::math::cumulative_sum(M)), "assigning variable cumsum_M"); - current_statement__ = 95; + current_statement__ = 99; stan::math::validate_non_negative_index("ll", "N", N); Eigen::Matrix ll = Eigen::Matrix::Constant(N, DUMMY_VAR__); - current_statement__ = 97; + current_statement__ = 101; stan::math::validate_non_negative_index("log_Pi", "S", S); Eigen::Matrix log_Pi = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 99; + current_statement__ = 103; stan::math::validate_non_negative_index("log_A", "S", S); - current_statement__ = 100; + current_statement__ = 104; stan::math::validate_non_negative_index("log_A", "S", S); Eigen::Matrix log_A = Eigen::Matrix::Constant(S, S, DUMMY_VAR__); - current_statement__ = 102; + current_statement__ = 106; stan::math::validate_non_negative_index("log_B", "S", S); - current_statement__ = 103; + current_statement__ = 107; stan::math::validate_non_negative_index("log_B", "max_M + 1", (max_M + 1)); Eigen::Matrix log_B = Eigen::Matrix::Constant(S, (max_M + 1), DUMMY_VAR__); - current_statement__ = 105; + current_statement__ = 109; stan::math::validate_non_negative_index("log_py", "S", S); Eigen::Matrix log_py = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 107; + current_statement__ = 111; stan::math::validate_non_negative_index("log_alpha", "S", S); Eigen::Matrix log_alpha = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 109; + current_statement__ = 113; stan::math::validate_non_negative_index("log_alpha_new", "S", S); Eigen::Matrix log_alpha_new = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 111; + current_statement__ = 115; stan::math::validate_non_negative_index("beta_i", "S", S); - current_statement__ = 112; + current_statement__ = 116; stan::math::validate_non_negative_index("beta_i", "K_i", K_i); Eigen::Matrix beta_i = Eigen::Matrix::Constant(S, K_i, DUMMY_VAR__); - current_statement__ = 114; + current_statement__ = 118; stan::math::validate_non_negative_index("beta_s", "S", S); - current_statement__ = 115; + current_statement__ = 119; stan::math::validate_non_negative_index("beta_s", "S", S); - current_statement__ = 116; + current_statement__ = 120; stan::math::validate_non_negative_index("beta_s", "K_s", K_s); std::vector> beta_s = std::vector>(S, Eigen::Matrix::Constant(S, K_s, DUMMY_VAR__)); - current_statement__ = 118; + current_statement__ = 122; stan::math::validate_non_negative_index("beta_o", "C", C); - current_statement__ = 119; + current_statement__ = 123; stan::math::validate_non_negative_index("beta_o", "S", S); - current_statement__ = 120; + current_statement__ = 124; stan::math::validate_non_negative_index("beta_o", "max_M", max_M); - current_statement__ = 121; + current_statement__ = 125; stan::math::validate_non_negative_index("beta_o", "K_o", K_o); std::vector>> beta_o = std::vector>>(C, std::vector>(S, Eigen::Matrix::Constant(max_M, K_o, DUMMY_VAR__))); - current_statement__ = 123; + current_statement__ = 127; stan::model::assign(beta_i, stan::math::append_row(zeros_row_K_i, beta_i_raw), "assigning variable beta_i"); - current_statement__ = 126; + current_statement__ = 130; for (int s = 1; s <= S; ++s) { - current_statement__ = 124; + current_statement__ = 128; stan::model::assign(beta_s, stan::math::append_row(zeros_row_K_s, stan::model::rvalue(beta_s_raw, "beta_s_raw", @@ -498,50 +502,50 @@ loglik_mc(const T0__& beta_i_raw_arg__, stan::model::index_uni(s)); } int idx = std::numeric_limits::min(); - current_statement__ = 127; + current_statement__ = 131; idx = 1; - current_statement__ = 136; + current_statement__ = 140; for (int c = 1; c <= C; ++c) { - current_statement__ = 134; + current_statement__ = 138; for (int s = 1; s <= S; ++s) { - current_statement__ = 128; + current_statement__ = 132; stan::model::assign(beta_o, zeros_mat_M_K_o, "assigning variable beta_o", stan::model::index_uni(c), stan::model::index_uni(s), stan::model::index_omni(), stan::model::index_omni()); - current_statement__ = 132; + current_statement__ = 136; for (int m = 2; m <= stan::model::rvalue(M, "M", stan::model::index_uni(c)); ++m) { - current_statement__ = 129; + current_statement__ = 133; stan::model::assign(beta_o, stan::model::rvalue(beta_o_raw, "beta_o_raw", stan::model::index_min_max(idx, ((idx + K_o) - 1))), "assigning variable beta_o", stan::model::index_uni(c), stan::model::index_uni(s), stan::model::index_uni(m), stan::model::index_omni()); - current_statement__ = 130; + current_statement__ = 134; idx = (idx + K_o); } } } - current_statement__ = 167; + current_statement__ = 171; for (int ii = 1; ii <= N_sample; ++ii) { int i = std::numeric_limits::min(); - current_statement__ = 137; + current_statement__ = 141; i = stan::model::rvalue(ids, "ids", stan::model::index_uni(ii)); - current_statement__ = 138; + current_statement__ = 142; stan::model::assign(log_Pi, stan::math::log_softmax( stan::math::multiply(beta_i, stan::model::rvalue(X_i, "X_i", stan::model::index_uni(i)))), "assigning variable log_Pi"); - current_statement__ = 139; + current_statement__ = 143; stan::model::assign(log_py, zeros_S, "assigning variable log_py"); - current_statement__ = 146; + current_statement__ = 150; for (int c = 1; c <= C; ++c) { - current_statement__ = 143; + current_statement__ = 147; for (int s = 1; s <= S; ++s) { - current_statement__ = 140; + current_statement__ = 144; stan::model::assign(log_B, stan::math::transpose( stan::math::log_softmax( @@ -556,13 +560,13 @@ loglik_mc(const T0__& beta_i_raw_arg__, "assigning variable log_B", stan::model::index_uni(s), stan::model::index_min_max(1, stan::model::rvalue(M, "M", stan::model::index_uni(c)))); - current_statement__ = 141; + current_statement__ = 145; stan::model::assign(log_B, 0, "assigning variable log_B", stan::model::index_uni(s), stan::model::index_uni( (stan::model::rvalue(M, "M", stan::model::index_uni(c)) + 1))); } - current_statement__ = 144; + current_statement__ = 148; stan::model::assign(log_py, stan::math::add(stan::model::deep_copy(log_py), stan::model::rvalue(log_B, "log_B", stan::model::index_omni(), @@ -571,19 +575,19 @@ loglik_mc(const T0__& beta_i_raw_arg__, stan::model::index_uni(1), stan::model::index_uni(i))))), "assigning variable log_py"); } - current_statement__ = 147; + current_statement__ = 151; stan::model::assign(log_alpha, stan::math::add(log_Pi, log_py), "assigning variable log_alpha"); - current_statement__ = 164; + current_statement__ = 168; for (int t = 2; t <= stan::model::rvalue(T, "T", stan::model::index_uni(i)); ++t) { - current_statement__ = 148; + current_statement__ = 152; stan::model::assign(log_py, zeros_S, "assigning variable log_py"); - current_statement__ = 155; + current_statement__ = 159; for (int c = 1; c <= C; ++c) { - current_statement__ = 152; + current_statement__ = 156; for (int s = 1; s <= S; ++s) { - current_statement__ = 149; + current_statement__ = 153; stan::model::assign(log_B, stan::math::transpose( stan::math::log_softmax( @@ -598,13 +602,13 @@ loglik_mc(const T0__& beta_i_raw_arg__, "assigning variable log_B", stan::model::index_uni(s), stan::model::index_min_max(1, stan::model::rvalue(M, "M", stan::model::index_uni(c)))); - current_statement__ = 150; + current_statement__ = 154; stan::model::assign(log_B, 0, "assigning variable log_B", stan::model::index_uni(s), stan::model::index_uni( (stan::model::rvalue(M, "M", stan::model::index_uni(c)) + 1))); } - current_statement__ = 153; + current_statement__ = 157; stan::model::assign(log_py, stan::math::add(stan::model::deep_copy(log_py), stan::model::rvalue(log_B, "log_B", stan::model::index_omni(), @@ -613,9 +617,9 @@ loglik_mc(const T0__& beta_i_raw_arg__, stan::model::index_uni(t), stan::model::index_uni(i))))), "assigning variable log_py"); } - current_statement__ = 158; + current_statement__ = 162; for (int s = 1; s <= S; ++s) { - current_statement__ = 156; + current_statement__ = 160; stan::model::assign(log_A, stan::math::transpose( stan::math::log_softmax( @@ -628,9 +632,9 @@ loglik_mc(const T0__& beta_i_raw_arg__, "assigning variable log_A", stan::model::index_uni(s), stan::model::index_omni()); } - current_statement__ = 161; + current_statement__ = 165; for (int k = 1; k <= S; ++k) { - current_statement__ = 159; + current_statement__ = 163; stan::model::assign(log_alpha_new, stan::math::log_sum_exp( stan::math::add( @@ -641,15 +645,15 @@ loglik_mc(const T0__& beta_i_raw_arg__, stan::model::index_uni(k)))), "assigning variable log_alpha_new", stan::model::index_uni(k)); } - current_statement__ = 162; + current_statement__ = 166; stan::model::assign(log_alpha, log_alpha_new, "assigning variable log_alpha"); } - current_statement__ = 165; + current_statement__ = 169; stan::model::assign(ll, stan::math::log_sum_exp(log_alpha), "assigning variable ll", stan::model::index_uni(i)); } - current_statement__ = 168; + current_statement__ = 172; return stan::math::sum(ll); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -674,6 +678,8 @@ class model_multichannel_nhmm final : public model_base_crtp>> X_s; int K_o; std::vector>> X_o; + int penalize; + double penalty; int beta_i_raw_1dim__; int beta_s_raw_2dim__; int beta_o_raw_1dim__; @@ -698,77 +704,77 @@ class model_multichannel_nhmm final : public model_base_crtp::min(); pos__ = 1; - current_statement__ = 17; + current_statement__ = 19; context__.validate_dims("data initialization", "N", "int", std::vector{}); N = std::numeric_limits::min(); - current_statement__ = 17; + current_statement__ = 19; N = context__.vals_i("N")[(1 - 1)]; - current_statement__ = 17; + current_statement__ = 19; stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 18; + current_statement__ = 20; context__.validate_dims("data initialization", "max_T", "int", std::vector{}); max_T = std::numeric_limits::min(); - current_statement__ = 18; + current_statement__ = 20; max_T = context__.vals_i("max_T")[(1 - 1)]; - current_statement__ = 18; + current_statement__ = 20; stan::math::check_greater_or_equal(function__, "max_T", max_T, 2); - current_statement__ = 19; + current_statement__ = 21; stan::math::validate_non_negative_index("T", "N", N); - current_statement__ = 20; + current_statement__ = 22; context__.validate_dims("data initialization", "T", "int", std::vector{static_cast(N)}); T = std::vector(N, std::numeric_limits::min()); - current_statement__ = 20; + current_statement__ = 22; T = context__.vals_i("T"); - current_statement__ = 20; + current_statement__ = 22; stan::math::check_greater_or_equal(function__, "T", T, 2); - current_statement__ = 20; + current_statement__ = 22; stan::math::check_less_or_equal(function__, "T", T, max_T); - current_statement__ = 21; + current_statement__ = 23; context__.validate_dims("data initialization", "max_M", "int", std::vector{}); max_M = std::numeric_limits::min(); - current_statement__ = 21; + current_statement__ = 23; max_M = context__.vals_i("max_M")[(1 - 1)]; - current_statement__ = 21; + current_statement__ = 23; stan::math::check_greater_or_equal(function__, "max_M", max_M, 2); - current_statement__ = 22; + current_statement__ = 24; context__.validate_dims("data initialization", "S", "int", std::vector{}); S = std::numeric_limits::min(); - current_statement__ = 22; + current_statement__ = 24; S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 22; + current_statement__ = 24; stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 23; + current_statement__ = 25; context__.validate_dims("data initialization", "C", "int", std::vector{}); C = std::numeric_limits::min(); - current_statement__ = 23; + current_statement__ = 25; C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 23; + current_statement__ = 25; stan::math::check_greater_or_equal(function__, "C", C, 2); - current_statement__ = 24; + current_statement__ = 26; stan::math::validate_non_negative_index("M", "C", C); - current_statement__ = 25; + current_statement__ = 27; context__.validate_dims("data initialization", "M", "int", std::vector{static_cast(C)}); M = std::vector(C, std::numeric_limits::min()); - current_statement__ = 25; + current_statement__ = 27; M = context__.vals_i("M"); - current_statement__ = 25; + current_statement__ = 27; stan::math::check_greater_or_equal(function__, "M", M, 2); - current_statement__ = 25; + current_statement__ = 27; stan::math::check_less_or_equal(function__, "M", M, max_M); - current_statement__ = 26; + current_statement__ = 28; stan::math::validate_non_negative_index("obs", "C", C); - current_statement__ = 27; + current_statement__ = 29; stan::math::validate_non_negative_index("obs", "max_T", max_T); - current_statement__ = 28; + current_statement__ = 30; stan::math::validate_non_negative_index("obs", "N", N); - current_statement__ = 29; + current_statement__ = 31; context__.validate_dims("data initialization", "obs", "int", std::vector{static_cast(C), static_cast(max_T), static_cast(N)}); @@ -777,60 +783,60 @@ class model_multichannel_nhmm final : public model_base_crtp(N, std::numeric_limits::min()))); { std::vector obs_flat__; - current_statement__ = 29; + current_statement__ = 31; obs_flat__ = context__.vals_i("obs"); - current_statement__ = 29; + current_statement__ = 31; pos__ = 1; - current_statement__ = 29; + current_statement__ = 31; for (int sym1__ = 1; sym1__ <= N; ++sym1__) { - current_statement__ = 29; + current_statement__ = 31; for (int sym2__ = 1; sym2__ <= max_T; ++sym2__) { - current_statement__ = 29; + current_statement__ = 31; for (int sym3__ = 1; sym3__ <= C; ++sym3__) { - current_statement__ = 29; + current_statement__ = 31; stan::model::assign(obs, obs_flat__[(pos__ - 1)], "assigning variable obs", stan::model::index_uni(sym3__), stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 29; + current_statement__ = 31; pos__ = (pos__ + 1); } } } } - current_statement__ = 29; + current_statement__ = 31; stan::math::check_greater_or_equal(function__, "obs", obs, 0); - current_statement__ = 29; + current_statement__ = 31; stan::math::check_less_or_equal(function__, "obs", obs, (max_M + 1)); - current_statement__ = 30; + current_statement__ = 32; context__.validate_dims("data initialization", "N_sample", "int", std::vector{}); N_sample = std::numeric_limits::min(); - current_statement__ = 30; + current_statement__ = 32; N_sample = context__.vals_i("N_sample")[(1 - 1)]; - current_statement__ = 30; + current_statement__ = 32; stan::math::check_less_or_equal(function__, "N_sample", N_sample, N); - current_statement__ = 31; + current_statement__ = 33; stan::math::validate_non_negative_index("ids", "N_sample", N_sample); - current_statement__ = 32; + current_statement__ = 34; context__.validate_dims("data initialization", "ids", "int", std::vector{static_cast(N_sample)}); ids = std::vector(N_sample, std::numeric_limits::min()); - current_statement__ = 32; + current_statement__ = 34; ids = context__.vals_i("ids"); - current_statement__ = 33; + current_statement__ = 35; context__.validate_dims("data initialization", "K_i", "int", std::vector{}); K_i = std::numeric_limits::min(); - current_statement__ = 33; + current_statement__ = 35; K_i = context__.vals_i("K_i")[(1 - 1)]; - current_statement__ = 33; + current_statement__ = 35; stan::math::check_greater_or_equal(function__, "K_i", K_i, 1); - current_statement__ = 34; + current_statement__ = 36; stan::math::validate_non_negative_index("X_i", "N", N); - current_statement__ = 35; + current_statement__ = 37; stan::math::validate_non_negative_index("X_i", "K_i", K_i); - current_statement__ = 36; + current_statement__ = 38; context__.validate_dims("data initialization", "X_i", "double", std::vector{static_cast(N), static_cast(K_i)}); X_i = std::vector>(N, @@ -838,38 +844,38 @@ class model_multichannel_nhmm final : public model_base_crtp::quiet_NaN())); { std::vector X_i_flat__; - current_statement__ = 36; + current_statement__ = 38; X_i_flat__ = context__.vals_r("X_i"); - current_statement__ = 36; + current_statement__ = 38; pos__ = 1; - current_statement__ = 36; + current_statement__ = 38; for (int sym1__ = 1; sym1__ <= K_i; ++sym1__) { - current_statement__ = 36; + current_statement__ = 38; for (int sym2__ = 1; sym2__ <= N; ++sym2__) { - current_statement__ = 36; + current_statement__ = 38; stan::model::assign(X_i, X_i_flat__[(pos__ - 1)], "assigning variable X_i", stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 36; + current_statement__ = 38; pos__ = (pos__ + 1); } } } - current_statement__ = 37; + current_statement__ = 39; context__.validate_dims("data initialization", "K_s", "int", std::vector{}); K_s = std::numeric_limits::min(); - current_statement__ = 37; + current_statement__ = 39; K_s = context__.vals_i("K_s")[(1 - 1)]; - current_statement__ = 37; + current_statement__ = 39; stan::math::check_greater_or_equal(function__, "K_s", K_s, 1); - current_statement__ = 38; + current_statement__ = 40; stan::math::validate_non_negative_index("X_s", "max_T", max_T); - current_statement__ = 39; + current_statement__ = 41; stan::math::validate_non_negative_index("X_s", "N", N); - current_statement__ = 40; + current_statement__ = 42; stan::math::validate_non_negative_index("X_s", "K_s", K_s); - current_statement__ = 41; + current_statement__ = 43; context__.validate_dims("data initialization", "X_s", "double", std::vector{static_cast(max_T), static_cast(N), static_cast(K_s)}); @@ -879,42 +885,42 @@ class model_multichannel_nhmm final : public model_base_crtp::quiet_NaN()))); { std::vector X_s_flat__; - current_statement__ = 41; + current_statement__ = 43; X_s_flat__ = context__.vals_r("X_s"); - current_statement__ = 41; + current_statement__ = 43; pos__ = 1; - current_statement__ = 41; + current_statement__ = 43; for (int sym1__ = 1; sym1__ <= K_s; ++sym1__) { - current_statement__ = 41; + current_statement__ = 43; for (int sym2__ = 1; sym2__ <= N; ++sym2__) { - current_statement__ = 41; + current_statement__ = 43; for (int sym3__ = 1; sym3__ <= max_T; ++sym3__) { - current_statement__ = 41; + current_statement__ = 43; stan::model::assign(X_s, X_s_flat__[(pos__ - 1)], "assigning variable X_s", stan::model::index_uni(sym3__), stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 41; + current_statement__ = 43; pos__ = (pos__ + 1); } } } } - current_statement__ = 42; + current_statement__ = 44; context__.validate_dims("data initialization", "K_o", "int", std::vector{}); K_o = std::numeric_limits::min(); - current_statement__ = 42; + current_statement__ = 44; K_o = context__.vals_i("K_o")[(1 - 1)]; - current_statement__ = 42; + current_statement__ = 44; stan::math::check_greater_or_equal(function__, "K_o", K_o, 1); - current_statement__ = 43; + current_statement__ = 45; stan::math::validate_non_negative_index("X_o", "max_T", max_T); - current_statement__ = 44; + current_statement__ = 46; stan::math::validate_non_negative_index("X_o", "N", N); - current_statement__ = 45; + current_statement__ = 47; stan::math::validate_non_negative_index("X_o", "K_o", K_o); - current_statement__ = 46; + current_statement__ = 48; context__.validate_dims("data initialization", "X_o", "double", std::vector{static_cast(max_T), static_cast(N), static_cast(K_o)}); @@ -924,52 +930,70 @@ class model_multichannel_nhmm final : public model_base_crtp::quiet_NaN()))); { std::vector X_o_flat__; - current_statement__ = 46; + current_statement__ = 48; X_o_flat__ = context__.vals_r("X_o"); - current_statement__ = 46; + current_statement__ = 48; pos__ = 1; - current_statement__ = 46; + current_statement__ = 48; for (int sym1__ = 1; sym1__ <= K_o; ++sym1__) { - current_statement__ = 46; + current_statement__ = 48; for (int sym2__ = 1; sym2__ <= N; ++sym2__) { - current_statement__ = 46; + current_statement__ = 48; for (int sym3__ = 1; sym3__ <= max_T; ++sym3__) { - current_statement__ = 46; + current_statement__ = 48; stan::model::assign(X_o, X_o_flat__[(pos__ - 1)], "assigning variable X_o", stan::model::index_uni(sym3__), stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 46; + current_statement__ = 48; pos__ = (pos__ + 1); } } } } - current_statement__ = 47; + current_statement__ = 49; + context__.validate_dims("data initialization", "penalize", "int", + std::vector{}); + penalize = std::numeric_limits::min(); + current_statement__ = 49; + penalize = context__.vals_i("penalize")[(1 - 1)]; + current_statement__ = 49; + stan::math::check_greater_or_equal(function__, "penalize", penalize, 0); + current_statement__ = 49; + stan::math::check_less_or_equal(function__, "penalize", penalize, 1); + current_statement__ = 50; + context__.validate_dims("data initialization", "penalty", "double", + std::vector{}); + penalty = std::numeric_limits::quiet_NaN(); + current_statement__ = 50; + penalty = context__.vals_r("penalty")[(1 - 1)]; + current_statement__ = 50; + stan::math::check_greater_or_equal(function__, "penalty", penalty, 0); + current_statement__ = 51; beta_i_raw_1dim__ = std::numeric_limits::min(); - current_statement__ = 47; + current_statement__ = 51; beta_i_raw_1dim__ = (S - 1); - current_statement__ = 47; + current_statement__ = 51; stan::math::validate_non_negative_index("beta_i_raw", "S - 1", beta_i_raw_1dim__); - current_statement__ = 48; + current_statement__ = 52; stan::math::validate_non_negative_index("beta_i_raw", "K_i", K_i); - current_statement__ = 49; + current_statement__ = 53; stan::math::validate_non_negative_index("beta_s_raw", "S", S); - current_statement__ = 50; + current_statement__ = 54; beta_s_raw_2dim__ = std::numeric_limits::min(); - current_statement__ = 50; + current_statement__ = 54; beta_s_raw_2dim__ = (S - 1); - current_statement__ = 50; + current_statement__ = 54; stan::math::validate_non_negative_index("beta_s_raw", "S - 1", beta_s_raw_2dim__); - current_statement__ = 51; + current_statement__ = 55; stan::math::validate_non_negative_index("beta_s_raw", "K_s", K_s); - current_statement__ = 52; + current_statement__ = 56; beta_o_raw_1dim__ = std::numeric_limits::min(); - current_statement__ = 52; + current_statement__ = 56; beta_o_raw_1dim__ = ((S * (stan::math::sum(M) - C)) * K_o); - current_statement__ = 52; + current_statement__ = 56; stan::math::validate_non_negative_index("beta_o_raw", "S * (sum(M) - C) * K_o", beta_o_raw_1dim__); } catch (const std::exception& e) { @@ -1029,29 +1053,33 @@ class model_multichannel_nhmm final : public model_base_crtp(stan::math::to_vector(beta_i_raw), 0, - 5)); - current_statement__ = 10; - for (int s = 1; s <= S; ++s) { - current_statement__ = 8; + current_statement__ = 13; + if (stan::math::logical_eq(penalize, 1)) { + current_statement__ = 7; prior = (prior + - stan::math::normal_lpdf( - stan::math::to_vector( - stan::model::rvalue(beta_s_raw, "beta_s_raw", - stan::model::index_uni(s))), 0, 5)); + stan::math::normal_lpdf(stan::math::to_vector(beta_i_raw), + 0, penalty)); + current_statement__ = 10; + for (int s = 1; s <= S; ++s) { + current_statement__ = 8; + prior = (prior + + stan::math::normal_lpdf( + stan::math::to_vector( + stan::model::rvalue(beta_s_raw, "beta_s_raw", + stan::model::index_uni(s))), 0, penalty)); + } + current_statement__ = 11; + prior = (prior + + stan::math::normal_lpdf(beta_o_raw, 0, penalty)); } - current_statement__ = 11; - prior = (prior + stan::math::normal_lpdf(beta_o_raw, 0, 5)); local_scalar_t__ log_lik = DUMMY_VAR__; current_statement__ = 5; log_lik = loglik_mc(beta_i_raw, beta_s_raw, beta_o_raw, obs, M, T, N_sample, ids, X_s, X_o, X_i, pstream__); { - current_statement__ = 15; + current_statement__ = 17; lp_accum__.add(prior); - current_statement__ = 16; + current_statement__ = 18; lp_accum__.add(log_lik); } } catch (const std::exception& e) { @@ -1133,21 +1161,25 @@ class model_multichannel_nhmm final : public model_base_crtp(stan::math::to_vector(beta_i_raw), 0, - 5)); - current_statement__ = 10; - for (int s = 1; s <= S; ++s) { - current_statement__ = 8; + current_statement__ = 13; + if (stan::math::logical_eq(penalize, 1)) { + current_statement__ = 7; + prior = (prior + + stan::math::normal_lpdf(stan::math::to_vector(beta_i_raw), + 0, penalty)); + current_statement__ = 10; + for (int s = 1; s <= S; ++s) { + current_statement__ = 8; + prior = (prior + + stan::math::normal_lpdf( + stan::math::to_vector( + stan::model::rvalue(beta_s_raw, "beta_s_raw", + stan::model::index_uni(s))), 0, penalty)); + } + current_statement__ = 11; prior = (prior + - stan::math::normal_lpdf( - stan::math::to_vector( - stan::model::rvalue(beta_s_raw, "beta_s_raw", - stan::model::index_uni(s))), 0, 5)); + stan::math::normal_lpdf(beta_o_raw, 0, penalty)); } - current_statement__ = 11; - prior = (prior + stan::math::normal_lpdf(beta_o_raw, 0, 5)); current_statement__ = 5; log_lik = loglik_mc(beta_i_raw, beta_s_raw, beta_o_raw, obs, M, T, N_sample, ids, X_s, X_o, X_i, pstream__); @@ -1161,9 +1193,9 @@ class model_multichannel_nhmm final : public model_base_crtp::quiet_NaN(); current_statement__ = 6; ploglik_N = (prior + log_lik); - current_statement__ = 14; + current_statement__ = 16; if (stan::math::logical_gt(N, N_sample)) { - current_statement__ = 12; + current_statement__ = 14; ploglik_N = (prior + loglik_mc(beta_i_raw, beta_s_raw, beta_o_raw, obs, M, T, N, stan::math::linspaced_int_array(N, 1, N), X_s, X_o, X_i, diff --git a/src/stanExports_nhmm.h b/src/stanExports_nhmm.h index 8bbda928..2bb1be56 100644 --- a/src/stanExports_nhmm.h +++ b/src/stanExports_nhmm.h @@ -27,23 +27,26 @@ namespace model_nhmm_namespace { using stan::model::model_base_crtp; using namespace stan::math; stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = +static constexpr std::array locations_array__ = {" (found before start of program)", - " (in 'string', line 105, column 2 to column 32)", - " (in 'string', line 107, column 2 to column 41)", + " (in 'string', line 107, column 2 to column 32)", " (in 'string', line 109, column 2 to column 41)", - " (in 'string', line 113, column 0 to column 55)", - " (in 'string', line 118, column 2 to line 119, column 32)", - " (in 'string', line 126, column 2 to column 35)", - " (in 'string', line 115, column 2 to column 56)", - " (in 'string', line 116, column 2 to column 56)", - " (in 'string', line 114, column 14 to line 117, column 1)", - " (in 'string', line 114, column 0 to line 117, column 1)", - " (in 'string', line 128, column 4 to line 129, column 58)", - " (in 'string', line 127, column 20 to line 130, column 3)", - " (in 'string', line 127, column 2 to line 130, column 3)", - " (in 'string', line 122, column 2 to column 18)", - " (in 'string', line 123, column 2 to column 20)", + " (in 'string', line 111, column 2 to column 41)", + " (in 'string', line 115, column 0 to column 15)", + " (in 'string', line 123, column 2 to line 124, column 32)", + " (in 'string', line 131, column 2 to column 35)", + " (in 'string', line 117, column 2 to column 59)", + " (in 'string', line 119, column 4 to column 64)", + " (in 'string', line 120, column 4 to column 64)", + " (in 'string', line 118, column 16 to line 121, column 3)", + " (in 'string', line 118, column 2 to line 121, column 3)", + " (in 'string', line 116, column 19 to line 122, column 1)", + " (in 'string', line 116, column 0 to line 122, column 1)", + " (in 'string', line 133, column 4 to line 134, column 58)", + " (in 'string', line 132, column 20 to line 135, column 3)", + " (in 'string', line 132, column 2 to line 135, column 3)", + " (in 'string', line 127, column 2 to column 18)", + " (in 'string', line 128, column 2 to column 20)", " (in 'string', line 88, column 2 to column 17)", " (in 'string', line 89, column 2 to column 21)", " (in 'string', line 90, column 8 to column 9)", @@ -70,14 +73,16 @@ static constexpr std::array locations_array__ = " (in 'string', line 101, column 15 to column 16)", " (in 'string', line 101, column 25 to column 28)", " (in 'string', line 101, column 2 to column 34)", - " (in 'string', line 105, column 9 to column 14)", - " (in 'string', line 105, column 16 to column 19)", - " (in 'string', line 107, column 8 to column 9)", - " (in 'string', line 107, column 18 to column 23)", - " (in 'string', line 107, column 25 to column 28)", + " (in 'string', line 102, column 2 to column 32)", + " (in 'string', line 103, column 2 to column 24)", + " (in 'string', line 107, column 9 to column 14)", + " (in 'string', line 107, column 16 to column 19)", " (in 'string', line 109, column 8 to column 9)", " (in 'string', line 109, column 18 to column 23)", " (in 'string', line 109, column 25 to column 28)", + " (in 'string', line 111, column 8 to column 9)", + " (in 'string', line 111, column 18 to column 23)", + " (in 'string', line 111, column 25 to column 28)", " (in 'string', line 8, column 4 to column 25)", " (in 'string', line 9, column 10 to column 16)", " (in 'string', line 9, column 4 to column 24)", @@ -215,21 +220,21 @@ add(const std::vector& x, const std::vector& y, std::ostream* (void) DUMMY_VAR__; try { int x_size = std::numeric_limits::min(); - current_statement__ = 50; + current_statement__ = 55; x_size = stan::math::size(x); - current_statement__ = 51; + current_statement__ = 56; stan::math::validate_non_negative_index("z", "x_size", x_size); std::vector z = std::vector(x_size, std::numeric_limits::min()); - current_statement__ = 55; + current_statement__ = 60; for (int i = 1; i <= x_size; ++i) { - current_statement__ = 53; + current_statement__ = 58; stan::model::assign(z, (stan::model::rvalue(x, "x", stan::model::index_uni(i)) + stan::model::rvalue(y, "y", stan::model::index_uni(i))), "assigning variable z", stan::model::index_uni(i)); } - current_statement__ = 56; + current_statement__ = 61; return z; } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -247,20 +252,20 @@ add(const int& x, const std::vector& y, std::ostream* pstream__) { (void) DUMMY_VAR__; try { int y_size = std::numeric_limits::min(); - current_statement__ = 58; + current_statement__ = 63; y_size = stan::math::size(y); - current_statement__ = 59; + current_statement__ = 64; stan::math::validate_non_negative_index("z", "y_size", y_size); std::vector z = std::vector(y_size, std::numeric_limits::min()); - current_statement__ = 63; + current_statement__ = 68; for (int i = 1; i <= y_size; ++i) { - current_statement__ = 61; + current_statement__ = 66; stan::model::assign(z, (x + stan::model::rvalue(y, "y", stan::model::index_uni(i))), "assigning variable z", stan::model::index_uni(i)); } - current_statement__ = 64; + current_statement__ = 69; return z; } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -278,20 +283,20 @@ add(const std::vector& x, const int& y, std::ostream* pstream__) { (void) DUMMY_VAR__; try { int x_size = std::numeric_limits::min(); - current_statement__ = 66; + current_statement__ = 71; x_size = stan::math::size(x); - current_statement__ = 67; + current_statement__ = 72; stan::math::validate_non_negative_index("z", "x_size", x_size); std::vector z = std::vector(x_size, std::numeric_limits::min()); - current_statement__ = 71; + current_statement__ = 76; for (int i = 1; i <= x_size; ++i) { - current_statement__ = 69; + current_statement__ = 74; stan::model::assign(z, (stan::model::rvalue(x, "x", stan::model::index_uni(i)) + y), "assigning variable z", stan::model::index_uni(i)); } - current_statement__ = 72; + current_statement__ = 77; return z; } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -331,143 +336,143 @@ loglik_sc(const T0__& beta_i_raw_arg__, (void) DUMMY_VAR__; try { int S = std::numeric_limits::min(); - current_statement__ = 74; + current_statement__ = 79; S = (stan::math::rows(beta_i_raw) + 1); int N = std::numeric_limits::min(); - current_statement__ = 75; + current_statement__ = 80; N = stan::math::size(X_i); int K_i = std::numeric_limits::min(); - current_statement__ = 76; + current_statement__ = 81; K_i = stan::math::num_elements( stan::model::rvalue(X_i, "X_i", stan::model::index_uni(1))); int K_s = std::numeric_limits::min(); - current_statement__ = 77; + current_statement__ = 82; K_s = stan::math::num_elements( stan::model::rvalue(X_s, "X_s", stan::model::index_uni(1), stan::model::index_uni(1))); int K_o = std::numeric_limits::min(); - current_statement__ = 78; + current_statement__ = 83; K_o = stan::math::num_elements( stan::model::rvalue(X_o, "X_o", stan::model::index_uni(1), stan::model::index_uni(1))); - current_statement__ = 79; + current_statement__ = 84; stan::math::validate_non_negative_index("zeros_row_K_i", "K_i", K_i); Eigen::Matrix zeros_row_K_i = Eigen::Matrix::Constant(K_i, DUMMY_VAR__); - current_statement__ = 80; + current_statement__ = 85; stan::model::assign(zeros_row_K_i, stan::math::rep_row_vector(0, K_i), "assigning variable zeros_row_K_i"); - current_statement__ = 81; + current_statement__ = 86; stan::math::validate_non_negative_index("zeros_row_K_s", "K_s", K_s); Eigen::Matrix zeros_row_K_s = Eigen::Matrix::Constant(K_s, DUMMY_VAR__); - current_statement__ = 82; + current_statement__ = 87; stan::model::assign(zeros_row_K_s, stan::math::rep_row_vector(0, K_s), "assigning variable zeros_row_K_s"); - current_statement__ = 83; + current_statement__ = 88; stan::math::validate_non_negative_index("zeros_row_K_o", "K_o", K_o); Eigen::Matrix zeros_row_K_o = Eigen::Matrix::Constant(K_o, DUMMY_VAR__); - current_statement__ = 84; + current_statement__ = 89; stan::model::assign(zeros_row_K_o, stan::math::rep_row_vector(0, K_o), "assigning variable zeros_row_K_o"); - current_statement__ = 85; + current_statement__ = 90; stan::math::validate_non_negative_index("zeros_S", "S", S); Eigen::Matrix zeros_S = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 86; + current_statement__ = 91; stan::model::assign(zeros_S, stan::math::rep_vector(0, S), "assigning variable zeros_S"); - current_statement__ = 87; + current_statement__ = 92; stan::math::validate_non_negative_index("ll", "N", N); Eigen::Matrix ll = Eigen::Matrix::Constant(N, DUMMY_VAR__); - current_statement__ = 89; + current_statement__ = 94; stan::math::validate_non_negative_index("log_Pi", "S", S); Eigen::Matrix log_Pi = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 91; + current_statement__ = 96; stan::math::validate_non_negative_index("log_A", "S", S); - current_statement__ = 92; + current_statement__ = 97; stan::math::validate_non_negative_index("log_A", "S", S); Eigen::Matrix log_A = Eigen::Matrix::Constant(S, S, DUMMY_VAR__); - current_statement__ = 94; + current_statement__ = 99; stan::math::validate_non_negative_index("log_B", "S", S); - current_statement__ = 95; + current_statement__ = 100; stan::math::validate_non_negative_index("log_B", "M + 1", (M + 1)); Eigen::Matrix log_B = Eigen::Matrix::Constant(S, (M + 1), DUMMY_VAR__); - current_statement__ = 97; + current_statement__ = 102; stan::math::validate_non_negative_index("log_py", "S", S); Eigen::Matrix log_py = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 99; + current_statement__ = 104; stan::math::validate_non_negative_index("log_alpha", "S", S); Eigen::Matrix log_alpha = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 101; + current_statement__ = 106; stan::math::validate_non_negative_index("log_alpha_new", "S", S); Eigen::Matrix log_alpha_new = Eigen::Matrix::Constant(S, DUMMY_VAR__); - current_statement__ = 103; + current_statement__ = 108; stan::math::validate_non_negative_index("beta_i", "S", S); - current_statement__ = 104; + current_statement__ = 109; stan::math::validate_non_negative_index("beta_i", "K_i", K_i); Eigen::Matrix beta_i = Eigen::Matrix::Constant(S, K_i, DUMMY_VAR__); - current_statement__ = 106; + current_statement__ = 111; stan::math::validate_non_negative_index("beta_s", "S", S); - current_statement__ = 107; + current_statement__ = 112; stan::math::validate_non_negative_index("beta_s", "S", S); - current_statement__ = 108; + current_statement__ = 113; stan::math::validate_non_negative_index("beta_s", "K_s", K_s); std::vector> beta_s = std::vector>(S, Eigen::Matrix::Constant(S, K_s, DUMMY_VAR__)); - current_statement__ = 110; + current_statement__ = 115; stan::math::validate_non_negative_index("beta_o", "S", S); - current_statement__ = 111; + current_statement__ = 116; stan::math::validate_non_negative_index("beta_o", "M", M); - current_statement__ = 112; + current_statement__ = 117; stan::math::validate_non_negative_index("beta_o", "K_o", K_o); std::vector> beta_o = std::vector>(S, Eigen::Matrix::Constant(M, K_o, DUMMY_VAR__)); - current_statement__ = 114; + current_statement__ = 119; stan::model::assign(beta_i, stan::math::append_row(zeros_row_K_i, beta_i_raw), "assigning variable beta_i"); - current_statement__ = 118; + current_statement__ = 123; for (int s = 1; s <= S; ++s) { - current_statement__ = 115; + current_statement__ = 120; stan::model::assign(beta_s, stan::math::append_row(zeros_row_K_s, stan::model::rvalue(beta_s_raw, "beta_s_raw", stan::model::index_uni(s))), "assigning variable beta_s", stan::model::index_uni(s)); - current_statement__ = 116; + current_statement__ = 121; stan::model::assign(beta_o, stan::math::append_row(zeros_row_K_o, stan::model::rvalue(beta_o_raw, "beta_o_raw", stan::model::index_uni(s))), "assigning variable beta_o", stan::model::index_uni(s)); } - current_statement__ = 143; + current_statement__ = 148; for (int ii = 1; ii <= N_sample; ++ii) { int i = std::numeric_limits::min(); - current_statement__ = 119; + current_statement__ = 124; i = stan::model::rvalue(ids, "ids", stan::model::index_uni(ii)); - current_statement__ = 120; + current_statement__ = 125; stan::model::assign(log_Pi, stan::math::log_softmax( stan::math::multiply(beta_i, stan::model::rvalue(X_i, "X_i", stan::model::index_uni(i)))), "assigning variable log_Pi"); - current_statement__ = 124; + current_statement__ = 129; for (int s = 1; s <= S; ++s) { - current_statement__ = 121; + current_statement__ = 126; stan::model::assign(log_B, stan::math::transpose( stan::math::log_softmax( @@ -477,25 +482,25 @@ loglik_sc(const T0__& beta_i_raw_arg__, stan::model::rvalue(X_o, "X_o", stan::model::index_uni(1), stan::model::index_uni(i))))), "assigning variable log_B", stan::model::index_uni(s), stan::model::index_min_max(1, M)); - current_statement__ = 122; + current_statement__ = 127; stan::model::assign(log_B, 0, "assigning variable log_B", stan::model::index_uni(s), stan::model::index_uni((M + 1))); } - current_statement__ = 125; + current_statement__ = 130; stan::model::assign(log_py, stan::model::rvalue(log_B, "log_B", stan::model::index_omni(), stan::model::index_uni( stan::model::rvalue(obs, "obs", stan::model::index_uni(1), stan::model::index_uni(i)))), "assigning variable log_py"); - current_statement__ = 126; + current_statement__ = 131; stan::model::assign(log_alpha, stan::math::add(log_Pi, log_py), "assigning variable log_alpha"); - current_statement__ = 140; + current_statement__ = 145; for (int t = 2; t <= stan::model::rvalue(T, "T", stan::model::index_uni(i)); ++t) { - current_statement__ = 130; + current_statement__ = 135; for (int s = 1; s <= S; ++s) { - current_statement__ = 127; + current_statement__ = 132; stan::model::assign(log_B, stan::math::transpose( stan::math::log_softmax( @@ -506,19 +511,19 @@ loglik_sc(const T0__& beta_i_raw_arg__, stan::model::index_uni(i))))), "assigning variable log_B", stan::model::index_uni(s), stan::model::index_min_max(1, M)); - current_statement__ = 128; + current_statement__ = 133; stan::model::assign(log_B, 0, "assigning variable log_B", stan::model::index_uni(s), stan::model::index_uni((M + 1))); } - current_statement__ = 131; + current_statement__ = 136; stan::model::assign(log_py, stan::model::rvalue(log_B, "log_B", stan::model::index_omni(), stan::model::index_uni( stan::model::rvalue(obs, "obs", stan::model::index_uni(t), stan::model::index_uni(i)))), "assigning variable log_py"); - current_statement__ = 134; + current_statement__ = 139; for (int s = 1; s <= S; ++s) { - current_statement__ = 132; + current_statement__ = 137; stan::model::assign(log_A, stan::math::transpose( stan::math::log_softmax( @@ -531,9 +536,9 @@ loglik_sc(const T0__& beta_i_raw_arg__, "assigning variable log_A", stan::model::index_uni(s), stan::model::index_omni()); } - current_statement__ = 137; + current_statement__ = 142; for (int k = 1; k <= S; ++k) { - current_statement__ = 135; + current_statement__ = 140; stan::model::assign(log_alpha_new, stan::math::log_sum_exp( stan::math::add( @@ -544,15 +549,15 @@ loglik_sc(const T0__& beta_i_raw_arg__, stan::model::index_uni(k)))), "assigning variable log_alpha_new", stan::model::index_uni(k)); } - current_statement__ = 138; + current_statement__ = 143; stan::model::assign(log_alpha, log_alpha_new, "assigning variable log_alpha"); } - current_statement__ = 141; + current_statement__ = 146; stan::model::assign(ll, stan::math::log_sum_exp(log_alpha), "assigning variable ll", stan::model::index_uni(i)); } - current_statement__ = 144; + current_statement__ = 149; return stan::math::sum(ll); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -575,6 +580,8 @@ class model_nhmm final : public model_base_crtp { std::vector>> X_s; int K_o; std::vector>> X_o; + int penalize; + double penalty; int beta_i_raw_1dim__; int beta_s_raw_2dim__; int beta_o_raw_2dim__; @@ -599,55 +606,55 @@ class model_nhmm final : public model_base_crtp { try { int pos__ = std::numeric_limits::min(); pos__ = 1; - current_statement__ = 16; + current_statement__ = 19; context__.validate_dims("data initialization", "N", "int", std::vector{}); N = std::numeric_limits::min(); - current_statement__ = 16; + current_statement__ = 19; N = context__.vals_i("N")[(1 - 1)]; - current_statement__ = 16; + current_statement__ = 19; stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 17; + current_statement__ = 20; context__.validate_dims("data initialization", "max_T", "int", std::vector{}); max_T = std::numeric_limits::min(); - current_statement__ = 17; + current_statement__ = 20; max_T = context__.vals_i("max_T")[(1 - 1)]; - current_statement__ = 17; + current_statement__ = 20; stan::math::check_greater_or_equal(function__, "max_T", max_T, 2); - current_statement__ = 18; + current_statement__ = 21; stan::math::validate_non_negative_index("T", "N", N); - current_statement__ = 19; + current_statement__ = 22; context__.validate_dims("data initialization", "T", "int", std::vector{static_cast(N)}); T = std::vector(N, std::numeric_limits::min()); - current_statement__ = 19; + current_statement__ = 22; T = context__.vals_i("T"); - current_statement__ = 19; + current_statement__ = 22; stan::math::check_greater_or_equal(function__, "T", T, 2); - current_statement__ = 19; + current_statement__ = 22; stan::math::check_less_or_equal(function__, "T", T, max_T); - current_statement__ = 20; + current_statement__ = 23; context__.validate_dims("data initialization", "M", "int", std::vector{}); M = std::numeric_limits::min(); - current_statement__ = 20; + current_statement__ = 23; M = context__.vals_i("M")[(1 - 1)]; - current_statement__ = 20; + current_statement__ = 23; stan::math::check_greater_or_equal(function__, "M", M, 2); - current_statement__ = 21; + current_statement__ = 24; context__.validate_dims("data initialization", "S", "int", std::vector{}); S = std::numeric_limits::min(); - current_statement__ = 21; + current_statement__ = 24; S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 21; + current_statement__ = 24; stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 22; + current_statement__ = 25; stan::math::validate_non_negative_index("obs", "max_T", max_T); - current_statement__ = 23; + current_statement__ = 26; stan::math::validate_non_negative_index("obs", "N", N); - current_statement__ = 24; + current_statement__ = 27; context__.validate_dims("data initialization", "obs", "int", std::vector{static_cast(max_T), static_cast(N)}); @@ -655,56 +662,56 @@ class model_nhmm final : public model_base_crtp { std::vector(N, std::numeric_limits::min())); { std::vector obs_flat__; - current_statement__ = 24; + current_statement__ = 27; obs_flat__ = context__.vals_i("obs"); - current_statement__ = 24; + current_statement__ = 27; pos__ = 1; - current_statement__ = 24; + current_statement__ = 27; for (int sym1__ = 1; sym1__ <= N; ++sym1__) { - current_statement__ = 24; + current_statement__ = 27; for (int sym2__ = 1; sym2__ <= max_T; ++sym2__) { - current_statement__ = 24; + current_statement__ = 27; stan::model::assign(obs, obs_flat__[(pos__ - 1)], "assigning variable obs", stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 24; + current_statement__ = 27; pos__ = (pos__ + 1); } } } - current_statement__ = 24; + current_statement__ = 27; stan::math::check_greater_or_equal(function__, "obs", obs, 0); - current_statement__ = 24; + current_statement__ = 27; stan::math::check_less_or_equal(function__, "obs", obs, (M + 1)); - current_statement__ = 25; + current_statement__ = 28; context__.validate_dims("data initialization", "N_sample", "int", std::vector{}); N_sample = std::numeric_limits::min(); - current_statement__ = 25; + current_statement__ = 28; N_sample = context__.vals_i("N_sample")[(1 - 1)]; - current_statement__ = 25; + current_statement__ = 28; stan::math::check_less_or_equal(function__, "N_sample", N_sample, N); - current_statement__ = 26; + current_statement__ = 29; stan::math::validate_non_negative_index("ids", "N_sample", N_sample); - current_statement__ = 27; + current_statement__ = 30; context__.validate_dims("data initialization", "ids", "int", std::vector{static_cast(N_sample)}); ids = std::vector(N_sample, std::numeric_limits::min()); - current_statement__ = 27; + current_statement__ = 30; ids = context__.vals_i("ids"); - current_statement__ = 28; + current_statement__ = 31; context__.validate_dims("data initialization", "K_i", "int", std::vector{}); K_i = std::numeric_limits::min(); - current_statement__ = 28; + current_statement__ = 31; K_i = context__.vals_i("K_i")[(1 - 1)]; - current_statement__ = 28; + current_statement__ = 31; stan::math::check_greater_or_equal(function__, "K_i", K_i, 1); - current_statement__ = 29; + current_statement__ = 32; stan::math::validate_non_negative_index("X_i", "N", N); - current_statement__ = 30; + current_statement__ = 33; stan::math::validate_non_negative_index("X_i", "K_i", K_i); - current_statement__ = 31; + current_statement__ = 34; context__.validate_dims("data initialization", "X_i", "double", std::vector{static_cast(N), static_cast(K_i)}); X_i = std::vector>(N, @@ -712,38 +719,38 @@ class model_nhmm final : public model_base_crtp { std::numeric_limits::quiet_NaN())); { std::vector X_i_flat__; - current_statement__ = 31; + current_statement__ = 34; X_i_flat__ = context__.vals_r("X_i"); - current_statement__ = 31; + current_statement__ = 34; pos__ = 1; - current_statement__ = 31; + current_statement__ = 34; for (int sym1__ = 1; sym1__ <= K_i; ++sym1__) { - current_statement__ = 31; + current_statement__ = 34; for (int sym2__ = 1; sym2__ <= N; ++sym2__) { - current_statement__ = 31; + current_statement__ = 34; stan::model::assign(X_i, X_i_flat__[(pos__ - 1)], "assigning variable X_i", stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 31; + current_statement__ = 34; pos__ = (pos__ + 1); } } } - current_statement__ = 32; + current_statement__ = 35; context__.validate_dims("data initialization", "K_s", "int", std::vector{}); K_s = std::numeric_limits::min(); - current_statement__ = 32; + current_statement__ = 35; K_s = context__.vals_i("K_s")[(1 - 1)]; - current_statement__ = 32; + current_statement__ = 35; stan::math::check_greater_or_equal(function__, "K_s", K_s, 1); - current_statement__ = 33; + current_statement__ = 36; stan::math::validate_non_negative_index("X_s", "max_T", max_T); - current_statement__ = 34; + current_statement__ = 37; stan::math::validate_non_negative_index("X_s", "N", N); - current_statement__ = 35; + current_statement__ = 38; stan::math::validate_non_negative_index("X_s", "K_s", K_s); - current_statement__ = 36; + current_statement__ = 39; context__.validate_dims("data initialization", "X_s", "double", std::vector{static_cast(max_T), static_cast(N), static_cast(K_s)}); @@ -753,42 +760,42 @@ class model_nhmm final : public model_base_crtp { std::numeric_limits::quiet_NaN()))); { std::vector X_s_flat__; - current_statement__ = 36; + current_statement__ = 39; X_s_flat__ = context__.vals_r("X_s"); - current_statement__ = 36; + current_statement__ = 39; pos__ = 1; - current_statement__ = 36; + current_statement__ = 39; for (int sym1__ = 1; sym1__ <= K_s; ++sym1__) { - current_statement__ = 36; + current_statement__ = 39; for (int sym2__ = 1; sym2__ <= N; ++sym2__) { - current_statement__ = 36; + current_statement__ = 39; for (int sym3__ = 1; sym3__ <= max_T; ++sym3__) { - current_statement__ = 36; + current_statement__ = 39; stan::model::assign(X_s, X_s_flat__[(pos__ - 1)], "assigning variable X_s", stan::model::index_uni(sym3__), stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 36; + current_statement__ = 39; pos__ = (pos__ + 1); } } } } - current_statement__ = 37; + current_statement__ = 40; context__.validate_dims("data initialization", "K_o", "int", std::vector{}); K_o = std::numeric_limits::min(); - current_statement__ = 37; + current_statement__ = 40; K_o = context__.vals_i("K_o")[(1 - 1)]; - current_statement__ = 37; + current_statement__ = 40; stan::math::check_greater_or_equal(function__, "K_o", K_o, 1); - current_statement__ = 38; + current_statement__ = 41; stan::math::validate_non_negative_index("X_o", "max_T", max_T); - current_statement__ = 39; + current_statement__ = 42; stan::math::validate_non_negative_index("X_o", "N", N); - current_statement__ = 40; + current_statement__ = 43; stan::math::validate_non_negative_index("X_o", "K_o", K_o); - current_statement__ = 41; + current_statement__ = 44; context__.validate_dims("data initialization", "X_o", "double", std::vector{static_cast(max_T), static_cast(N), static_cast(K_o)}); @@ -798,57 +805,75 @@ class model_nhmm final : public model_base_crtp { std::numeric_limits::quiet_NaN()))); { std::vector X_o_flat__; - current_statement__ = 41; + current_statement__ = 44; X_o_flat__ = context__.vals_r("X_o"); - current_statement__ = 41; + current_statement__ = 44; pos__ = 1; - current_statement__ = 41; + current_statement__ = 44; for (int sym1__ = 1; sym1__ <= K_o; ++sym1__) { - current_statement__ = 41; + current_statement__ = 44; for (int sym2__ = 1; sym2__ <= N; ++sym2__) { - current_statement__ = 41; + current_statement__ = 44; for (int sym3__ = 1; sym3__ <= max_T; ++sym3__) { - current_statement__ = 41; + current_statement__ = 44; stan::model::assign(X_o, X_o_flat__[(pos__ - 1)], "assigning variable X_o", stan::model::index_uni(sym3__), stan::model::index_uni(sym2__), stan::model::index_uni(sym1__)); - current_statement__ = 41; + current_statement__ = 44; pos__ = (pos__ + 1); } } } } - current_statement__ = 42; + current_statement__ = 45; + context__.validate_dims("data initialization", "penalize", "int", + std::vector{}); + penalize = std::numeric_limits::min(); + current_statement__ = 45; + penalize = context__.vals_i("penalize")[(1 - 1)]; + current_statement__ = 45; + stan::math::check_greater_or_equal(function__, "penalize", penalize, 0); + current_statement__ = 45; + stan::math::check_less_or_equal(function__, "penalize", penalize, 1); + current_statement__ = 46; + context__.validate_dims("data initialization", "penalty", "double", + std::vector{}); + penalty = std::numeric_limits::quiet_NaN(); + current_statement__ = 46; + penalty = context__.vals_r("penalty")[(1 - 1)]; + current_statement__ = 46; + stan::math::check_greater_or_equal(function__, "penalty", penalty, 0); + current_statement__ = 47; beta_i_raw_1dim__ = std::numeric_limits::min(); - current_statement__ = 42; + current_statement__ = 47; beta_i_raw_1dim__ = (S - 1); - current_statement__ = 42; + current_statement__ = 47; stan::math::validate_non_negative_index("beta_i_raw", "S - 1", beta_i_raw_1dim__); - current_statement__ = 43; + current_statement__ = 48; stan::math::validate_non_negative_index("beta_i_raw", "K_i", K_i); - current_statement__ = 44; + current_statement__ = 49; stan::math::validate_non_negative_index("beta_s_raw", "S", S); - current_statement__ = 45; + current_statement__ = 50; beta_s_raw_2dim__ = std::numeric_limits::min(); - current_statement__ = 45; + current_statement__ = 50; beta_s_raw_2dim__ = (S - 1); - current_statement__ = 45; + current_statement__ = 50; stan::math::validate_non_negative_index("beta_s_raw", "S - 1", beta_s_raw_2dim__); - current_statement__ = 46; + current_statement__ = 51; stan::math::validate_non_negative_index("beta_s_raw", "K_s", K_s); - current_statement__ = 47; + current_statement__ = 52; stan::math::validate_non_negative_index("beta_o_raw", "S", S); - current_statement__ = 48; + current_statement__ = 53; beta_o_raw_2dim__ = std::numeric_limits::min(); - current_statement__ = 48; + current_statement__ = 53; beta_o_raw_2dim__ = (M - 1); - current_statement__ = 48; + current_statement__ = 53; stan::math::validate_non_negative_index("beta_o_raw", "M - 1", beta_o_raw_2dim__); - current_statement__ = 49; + current_statement__ = 54; stan::math::validate_non_negative_index("beta_o_raw", "K_o", K_o); } catch (const std::exception& e) { stan::lang::rethrow_located(e, locations_array__[current_statement__]); @@ -908,31 +933,37 @@ class model_nhmm final : public model_base_crtp { beta_o_raw_2dim__, K_o); local_scalar_t__ prior = DUMMY_VAR__; current_statement__ = 4; - prior = stan::math::normal_lpdf( - stan::math::to_vector(beta_i_raw), 0, 5); - current_statement__ = 10; - for (int s = 1; s <= S; ++s) { + prior = 0; + current_statement__ = 13; + if (stan::math::logical_eq(penalize, 1)) { current_statement__ = 7; prior = (prior + - stan::math::normal_lpdf( - stan::math::to_vector( - stan::model::rvalue(beta_s_raw, "beta_s_raw", - stan::model::index_uni(s))), 0, 5)); - current_statement__ = 8; - prior = (prior + - stan::math::normal_lpdf( - stan::math::to_vector( - stan::model::rvalue(beta_o_raw, "beta_o_raw", - stan::model::index_uni(s))), 0, 5)); + stan::math::normal_lpdf(stan::math::to_vector(beta_i_raw), + 0, penalty)); + current_statement__ = 11; + for (int s = 1; s <= S; ++s) { + current_statement__ = 8; + prior = (prior + + stan::math::normal_lpdf( + stan::math::to_vector( + stan::model::rvalue(beta_s_raw, "beta_s_raw", + stan::model::index_uni(s))), 0, penalty)); + current_statement__ = 9; + prior = (prior + + stan::math::normal_lpdf( + stan::math::to_vector( + stan::model::rvalue(beta_o_raw, "beta_o_raw", + stan::model::index_uni(s))), 0, penalty)); + } } local_scalar_t__ log_lik = DUMMY_VAR__; current_statement__ = 5; log_lik = loglik_sc(beta_i_raw, beta_s_raw, beta_o_raw, obs, M, T, N_sample, ids, X_s, X_o, X_i, pstream__); { - current_statement__ = 14; + current_statement__ = 17; lp_accum__.add(prior); - current_statement__ = 15; + current_statement__ = 18; lp_accum__.add(log_lik); } } catch (const std::exception& e) { @@ -1024,22 +1055,28 @@ class model_nhmm final : public model_base_crtp { return ; } current_statement__ = 4; - prior = stan::math::normal_lpdf( - stan::math::to_vector(beta_i_raw), 0, 5); - current_statement__ = 10; - for (int s = 1; s <= S; ++s) { + prior = 0; + current_statement__ = 13; + if (stan::math::logical_eq(penalize, 1)) { current_statement__ = 7; prior = (prior + - stan::math::normal_lpdf( - stan::math::to_vector( - stan::model::rvalue(beta_s_raw, "beta_s_raw", - stan::model::index_uni(s))), 0, 5)); - current_statement__ = 8; - prior = (prior + - stan::math::normal_lpdf( - stan::math::to_vector( - stan::model::rvalue(beta_o_raw, "beta_o_raw", - stan::model::index_uni(s))), 0, 5)); + stan::math::normal_lpdf(stan::math::to_vector(beta_i_raw), + 0, penalty)); + current_statement__ = 11; + for (int s = 1; s <= S; ++s) { + current_statement__ = 8; + prior = (prior + + stan::math::normal_lpdf( + stan::math::to_vector( + stan::model::rvalue(beta_s_raw, "beta_s_raw", + stan::model::index_uni(s))), 0, penalty)); + current_statement__ = 9; + prior = (prior + + stan::math::normal_lpdf( + stan::math::to_vector( + stan::model::rvalue(beta_o_raw, "beta_o_raw", + stan::model::index_uni(s))), 0, penalty)); + } } current_statement__ = 5; log_lik = loglik_sc(beta_i_raw, beta_s_raw, beta_o_raw, obs, M, T, @@ -1054,9 +1091,9 @@ class model_nhmm final : public model_base_crtp { double ploglik_N = std::numeric_limits::quiet_NaN(); current_statement__ = 6; ploglik_N = (prior + log_lik); - current_statement__ = 13; + current_statement__ = 16; if (stan::math::logical_gt(N, N_sample)) { - current_statement__ = 11; + current_statement__ = 14; ploglik_N = (prior + loglik_sc(beta_i_raw, beta_s_raw, beta_o_raw, obs, M, T, N, stan::math::linspaced_int_array(N, 1, N), X_s, X_o, X_i, diff --git a/tests/testthat/test-simulate_mnhmm.R b/tests/testthat/test-simulate_mnhmm.R index ba9bef9d..0b02a996 100644 --- a/tests/testthat/test-simulate_mnhmm.R +++ b/tests/testthat/test-simulate_mnhmm.R @@ -49,7 +49,7 @@ test_that("simulate_mnhmm, coef and get_probs works", { expect_warning( cf <- coef(fit), paste0( - "Standard errors could not be computed due to singular Hessian.", + "Standard errors could not be computed due to negative variances. ", "Confidence intervals will not be provided." ) )