// Generated by rstantools.  Do not edit by hand.

/*
    ForceChoice is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ForceChoice is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ForceChoice.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MODELS_HPP
#define MODELS_HPP
#define STAN__SERVICES__COMMAND_HPP
#ifndef USE_STANC3
#define USE_STANC3
#endif
#include <rstan/rstaninc.hpp>
// Code generated by stanc v2.32.2
#include <stan/model/model_header.hpp>
namespace model_TIRT_namespace {
using stan::model::model_base_crtp;
using namespace stan::math;
stan::math::profile_map profiles__;
static constexpr std::array<const char*, 123> locations_array__ =
  {" (found before start of program)",
  " (in 'string', line 54, column 2 to column 30)",
  " (in 'string', line 55, column 2 to column 34)",
  " (in 'string', line 56, column 2 to column 73)",
  " (in 'string', line 57, column 2 to column 37)",
  " (in 'string', line 58, column 2 to column 32)",
  " (in 'string', line 61, column 2 to column 28)",
  " (in 'string', line 62, column 2 to column 35)",
  " (in 'string', line 63, column 2 to column 32)",
  " (in 'string', line 70, column 2 to column 23)",
  " (in 'string', line 100, column 2 to column 22)",
  " (in 'string', line 101, column 2 to column 24)",
  " (in 'string', line 64, column 2 to column 31)",
  " (in 'string', line 65, column 2 to column 38)",
  " (in 'string', line 66, column 2 to column 42)",
  " (in 'string', line 67, column 2 to column 33)",
  " (in 'string', line 68, column 2 to column 29)",
  " (in 'string', line 69, column 2 to column 41)",
  " (in 'string', line 71, column 2 to column 39)",
  " (in 'string', line 72, column 2 to column 35)",
  " (in 'string', line 102, column 2 to column 52)",
  " (in 'string', line 104, column 4 to line 105, column 102)",
  " (in 'string', line 106, column 4 to column 77)",
  " (in 'string', line 107, column 4 to column 54)",
  " (in 'string', line 111, column 6 to column 42)",
  " (in 'string', line 110, column 11 to line 112, column 5)",
  " (in 'string', line 109, column 6 to column 41)",
  " (in 'string', line 108, column 26 to line 110, column 5)",
  " (in 'string', line 108, column 4 to line 112, column 5)",
  " (in 'string', line 103, column 21 to line 113, column 3)",
  " (in 'string', line 103, column 2 to line 113, column 3)",
  " (in 'string', line 75, column 2 to column 36)",
  " (in 'string', line 76, column 2 to column 33)",
  " (in 'string', line 77, column 2 to column 50)",
  " (in 'string', line 78, column 2 to column 38)",
  " (in 'string', line 79, column 2 to column 44)",
  " (in 'string', line 80, column 9 to column 14)",
  " (in 'string', line 80, column 2 to column 24)",
  " (in 'string', line 81, column 9 to column 14)",
  " (in 'string', line 81, column 2 to column 24)",
  " (in 'string', line 83, column 4 to column 26)",
  " (in 'string', line 84, column 4 to column 26)",
  " (in 'string', line 85, column 4 to column 26)",
  " (in 'string', line 86, column 4 to line 87, column 64)",
  " (in 'string', line 88, column 4 to column 51)",
  " (in 'string', line 82, column 21 to line 89, column 3)",
  " (in 'string', line 82, column 2 to line 89, column 3)",
  " (in 'string', line 91, column 4 to column 60)",
  " (in 'string', line 95, column 6 to column 39)",
  " (in 'string', line 94, column 11 to line 96, column 5)",
  " (in 'string', line 93, column 6 to column 38)",
  " (in 'string', line 92, column 26 to line 94, column 5)",
  " (in 'string', line 92, column 4 to line 96, column 5)",
  " (in 'string', line 90, column 21 to line 97, column 3)",
  " (in 'string', line 90, column 2 to line 97, column 3)",
  " (in 'string', line 16, column 2 to column 21)",
  " (in 'string', line 17, column 2 to column 22)",
  " (in 'string', line 18, column 2 to column 24)",
  " (in 'string', line 19, column 2 to column 24)",
  " (in 'string', line 20, column 2 to column 17)",
  " (in 'string', line 21, column 8 to column 13)",
  " (in 'string', line 21, column 2 to column 46)",
  " (in 'string', line 22, column 8 to column 13)",
  " (in 'string', line 22, column 2 to column 55)",
  " (in 'string', line 23, column 8 to column 13)",
  " (in 'string', line 23, column 2 to column 55)",
  " (in 'string', line 24, column 8 to column 13)",
  " (in 'string', line 24, column 2 to column 55)",
  " (in 'string', line 25, column 8 to column 13)",
  " (in 'string', line 25, column 2 to column 51)",
  " (in 'string', line 26, column 9 to column 17)",
  " (in 'string', line 26, column 19 to column 20)",
  " (in 'string', line 26, column 2 to column 31)",
  " (in 'string', line 27, column 2 to column 14)",
  " (in 'string', line 28, column 2 to column 26)",
  " (in 'string', line 29, column 2 to column 16)",
  " (in 'string', line 30, column 2 to column 28)",
  " (in 'string', line 31, column 9 to column 10)",
  " (in 'string', line 31, column 2 to column 21)",
  " (in 'string', line 32, column 2 to column 29)",
  " (in 'string', line 33, column 2 to column 28)",
  " (in 'string', line 34, column 2 to column 28)",
  " (in 'string', line 35, column 8 to column 20)",
  " (in 'string', line 35, column 2 to column 66)",
  " (in 'string', line 36, column 2 to column 28)",
  " (in 'string', line 37, column 8 to column 20)",
  " (in 'string', line 37, column 2 to column 66)",
  " (in 'string', line 38, column 9 to column 21)",
  " (in 'string', line 38, column 2 to column 38)",
  " (in 'string', line 39, column 2 to column 25)",
  " (in 'string', line 40, column 8 to column 17)",
  " (in 'string', line 40, column 2 to column 60)",
  " (in 'string', line 41, column 18 to column 27)",
  " (in 'string', line 41, column 2 to column 41)",
  " (in 'string', line 42, column 2 to column 25)",
  " (in 'string', line 43, column 8 to column 17)",
  " (in 'string', line 43, column 2 to column 60)",
  " (in 'string', line 44, column 2 to column 27)",
  " (in 'string', line 45, column 8 to column 19)",
  " (in 'string', line 45, column 2 to column 64)",
  " (in 'string', line 46, column 8 to column 19)",
  " (in 'string', line 46, column 2 to column 63)",
  " (in 'string', line 47, column 2 to column 27)",
  " (in 'string', line 48, column 8 to column 19)",
  " (in 'string', line 48, column 2 to column 62)",
  " (in 'string', line 49, column 9 to column 20)",
  " (in 'string', line 49, column 2 to column 36)",
  " (in 'string', line 50, column 2 to column 27)",
  " (in 'string', line 51, column 8 to column 19)",
  " (in 'string', line 51, column 2 to column 62)",
  " (in 'string', line 54, column 9 to column 10)",
  " (in 'string', line 54, column 12 to column 20)",
  " (in 'string', line 55, column 23 to column 24)",
  " (in 'string', line 56, column 48 to column 60)",
  " (in 'string', line 57, column 18 to column 27)",
  " (in 'string', line 58, column 9 to column 20)",
  " (in 'string', line 61, column 9 to column 17)",
  " (in 'string', line 61, column 19 to column 20)",
  " (in 'string', line 62, column 18 to column 26)",
  " (in 'string', line 63, column 18 to column 26)",
  " (in 'string', line 70, column 9 to column 15)",
  " (in 'string', line 100, column 14 to column 15)",
  " (in 'string', line 101, column 9 to column 14)"};
#include <stan_meta_header.hpp>
class model_TIRT final : public model_base_crtp<model_TIRT> {
private:
  int N_obs;
  int N_pair;
  int N_person;
  int I_states;
  int D;
  std::vector<int> response;
  std::vector<int> Idx_person;
  std::vector<int> Idx_item_i;
  std::vector<int> Idx_item_k;
  std::vector<int> Idx_pair;
  Eigen::Matrix<double,-1,-1> Q_matrix_data__;
  double psi_mu;
  double psi_sigma;
  double gamma_mu;
  double gamma_sigma;
  Eigen::Matrix<double,-1,1> theta_mu_data__;
  double lambda_alpha;
  double lambda_beta;
  int N_lambda_est;
  std::vector<int> Idx_lambda_est;
  int N_lambda_fix;
  std::vector<int> Idx_lambda_fix;
  Eigen::Matrix<double,-1,1> lambda_fix_val_data__;
  int N_psi_fix;
  std::vector<int> Idx_psi_fix;
  Eigen::Matrix<double,-1,1> psi_fix_val_data__;
  int N_psi_est;
  std::vector<int> Idx_psi_est;
  int N_psi_equal;
  std::vector<int> Idx_psi_equal;
  std::vector<int> Idx_psi_orig;
  int N_gamma_fix;
  std::vector<int> Idx_gamma_fix;
  Eigen::Matrix<double,-1,1> gamma_fix_val_data__;
  int N_gamma_est;
  std::vector<int> Idx_gamma_est;
  Eigen::Map<Eigen::Matrix<double,-1,-1>> Q_matrix{nullptr, 0, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> theta_mu{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> lambda_fix_val{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> psi_fix_val{nullptr, 0};
  Eigen::Map<Eigen::Matrix<double,-1,1>> gamma_fix_val{nullptr, 0};
public:
  ~model_TIRT() {}
  model_TIRT(stan::io::var_context& context__, unsigned int
             random_seed__ = 0, std::ostream* pstream__ = nullptr)
      : model_base_crtp(0) {
    int current_statement__ = 0;
    using local_scalar_t__ = double;
    boost::ecuyer1988 base_rng__ =
      stan::services::util::create_rng(random_seed__, 0);
    // suppress unused var warning
    (void) base_rng__;
    static constexpr const char* function__ =
      "model_TIRT_namespace::model_TIRT";
    // suppress unused var warning
    (void) function__;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    try {
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      current_statement__ = 55;
      context__.validate_dims("data initialization", "N_obs", "int",
        std::vector<size_t>{});
      N_obs = std::numeric_limits<int>::min();
      current_statement__ = 55;
      N_obs = context__.vals_i("N_obs")[(1 - 1)];
      current_statement__ = 55;
      stan::math::check_greater_or_equal(function__, "N_obs", N_obs, 1);
      current_statement__ = 56;
      context__.validate_dims("data initialization", "N_pair", "int",
        std::vector<size_t>{});
      N_pair = std::numeric_limits<int>::min();
      current_statement__ = 56;
      N_pair = context__.vals_i("N_pair")[(1 - 1)];
      current_statement__ = 56;
      stan::math::check_greater_or_equal(function__, "N_pair", N_pair, 1);
      current_statement__ = 57;
      context__.validate_dims("data initialization", "N_person", "int",
        std::vector<size_t>{});
      N_person = std::numeric_limits<int>::min();
      current_statement__ = 57;
      N_person = context__.vals_i("N_person")[(1 - 1)];
      current_statement__ = 57;
      stan::math::check_greater_or_equal(function__, "N_person", N_person, 1);
      current_statement__ = 58;
      context__.validate_dims("data initialization", "I_states", "int",
        std::vector<size_t>{});
      I_states = std::numeric_limits<int>::min();
      current_statement__ = 58;
      I_states = context__.vals_i("I_states")[(1 - 1)];
      current_statement__ = 58;
      stan::math::check_greater_or_equal(function__, "I_states", I_states, 2);
      current_statement__ = 59;
      context__.validate_dims("data initialization", "D", "int",
        std::vector<size_t>{});
      D = std::numeric_limits<int>::min();
      current_statement__ = 59;
      D = context__.vals_i("D")[(1 - 1)];
      current_statement__ = 59;
      stan::math::check_greater_or_equal(function__, "D", D, 2);
      current_statement__ = 60;
      stan::math::validate_non_negative_index("response", "N_obs", N_obs);
      current_statement__ = 61;
      context__.validate_dims("data initialization", "response", "int",
        std::vector<size_t>{static_cast<size_t>(N_obs)});
      response = std::vector<int>(N_obs, std::numeric_limits<int>::min());
      current_statement__ = 61;
      response = context__.vals_i("response");
      current_statement__ = 61;
      stan::math::check_greater_or_equal(function__, "response", response, 0);
      current_statement__ = 61;
      stan::math::check_less_or_equal(function__, "response", response, 1);
      current_statement__ = 62;
      stan::math::validate_non_negative_index("Idx_person", "N_obs", N_obs);
      current_statement__ = 63;
      context__.validate_dims("data initialization", "Idx_person", "int",
        std::vector<size_t>{static_cast<size_t>(N_obs)});
      Idx_person = std::vector<int>(N_obs, std::numeric_limits<int>::min());
      current_statement__ = 63;
      Idx_person = context__.vals_i("Idx_person");
      current_statement__ = 63;
      stan::math::check_greater_or_equal(function__, "Idx_person",
        Idx_person, 1);
      current_statement__ = 63;
      stan::math::check_less_or_equal(function__, "Idx_person", Idx_person,
        N_person);
      current_statement__ = 64;
      stan::math::validate_non_negative_index("Idx_item_i", "N_obs", N_obs);
      current_statement__ = 65;
      context__.validate_dims("data initialization", "Idx_item_i", "int",
        std::vector<size_t>{static_cast<size_t>(N_obs)});
      Idx_item_i = std::vector<int>(N_obs, std::numeric_limits<int>::min());
      current_statement__ = 65;
      Idx_item_i = context__.vals_i("Idx_item_i");
      current_statement__ = 65;
      stan::math::check_greater_or_equal(function__, "Idx_item_i",
        Idx_item_i, 1);
      current_statement__ = 65;
      stan::math::check_less_or_equal(function__, "Idx_item_i", Idx_item_i,
        I_states);
      current_statement__ = 66;
      stan::math::validate_non_negative_index("Idx_item_k", "N_obs", N_obs);
      current_statement__ = 67;
      context__.validate_dims("data initialization", "Idx_item_k", "int",
        std::vector<size_t>{static_cast<size_t>(N_obs)});
      Idx_item_k = std::vector<int>(N_obs, std::numeric_limits<int>::min());
      current_statement__ = 67;
      Idx_item_k = context__.vals_i("Idx_item_k");
      current_statement__ = 67;
      stan::math::check_greater_or_equal(function__, "Idx_item_k",
        Idx_item_k, 1);
      current_statement__ = 67;
      stan::math::check_less_or_equal(function__, "Idx_item_k", Idx_item_k,
        I_states);
      current_statement__ = 68;
      stan::math::validate_non_negative_index("Idx_pair", "N_obs", N_obs);
      current_statement__ = 69;
      context__.validate_dims("data initialization", "Idx_pair", "int",
        std::vector<size_t>{static_cast<size_t>(N_obs)});
      Idx_pair = std::vector<int>(N_obs, std::numeric_limits<int>::min());
      current_statement__ = 69;
      Idx_pair = context__.vals_i("Idx_pair");
      current_statement__ = 69;
      stan::math::check_greater_or_equal(function__, "Idx_pair", Idx_pair, 1);
      current_statement__ = 69;
      stan::math::check_less_or_equal(function__, "Idx_pair", Idx_pair,
        N_pair);
      current_statement__ = 70;
      stan::math::validate_non_negative_index("Q_matrix", "I_states",
        I_states);
      current_statement__ = 71;
      stan::math::validate_non_negative_index("Q_matrix", "D", D);
      current_statement__ = 72;
      context__.validate_dims("data initialization", "Q_matrix", "double",
        std::vector<size_t>{static_cast<size_t>(I_states),
          static_cast<size_t>(D)});
      Q_matrix_data__ = Eigen::Matrix<double,-1,-1>::Constant(I_states, D,
                          std::numeric_limits<double>::quiet_NaN());
      new (&Q_matrix)
        Eigen::Map<Eigen::Matrix<double,-1,-1>>(Q_matrix_data__.data(),
        I_states, D);
      {
        std::vector<local_scalar_t__> Q_matrix_flat__;
        current_statement__ = 72;
        Q_matrix_flat__ = context__.vals_r("Q_matrix");
        current_statement__ = 72;
        pos__ = 1;
        current_statement__ = 72;
        for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
          current_statement__ = 72;
          for (int sym2__ = 1; sym2__ <= I_states; ++sym2__) {
            current_statement__ = 72;
            stan::model::assign(Q_matrix, Q_matrix_flat__[(pos__ - 1)],
              "assigning variable Q_matrix", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 72;
            pos__ = (pos__ + 1);
          }
        }
      }
      current_statement__ = 73;
      context__.validate_dims("data initialization", "psi_mu", "double",
        std::vector<size_t>{});
      psi_mu = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 73;
      psi_mu = context__.vals_r("psi_mu")[(1 - 1)];
      current_statement__ = 74;
      context__.validate_dims("data initialization", "psi_sigma", "double",
        std::vector<size_t>{});
      psi_sigma = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 74;
      psi_sigma = context__.vals_r("psi_sigma")[(1 - 1)];
      current_statement__ = 74;
      stan::math::check_greater_or_equal(function__, "psi_sigma", psi_sigma,
        0);
      current_statement__ = 75;
      context__.validate_dims("data initialization", "gamma_mu", "double",
        std::vector<size_t>{});
      gamma_mu = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 75;
      gamma_mu = context__.vals_r("gamma_mu")[(1 - 1)];
      current_statement__ = 76;
      context__.validate_dims("data initialization", "gamma_sigma", "double",
        std::vector<size_t>{});
      gamma_sigma = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 76;
      gamma_sigma = context__.vals_r("gamma_sigma")[(1 - 1)];
      current_statement__ = 76;
      stan::math::check_greater_or_equal(function__, "gamma_sigma",
        gamma_sigma, 0);
      current_statement__ = 77;
      stan::math::validate_non_negative_index("theta_mu", "D", D);
      current_statement__ = 78;
      context__.validate_dims("data initialization", "theta_mu", "double",
        std::vector<size_t>{static_cast<size_t>(D)});
      theta_mu_data__ = Eigen::Matrix<double,-1,1>::Constant(D,
                          std::numeric_limits<double>::quiet_NaN());
      new (&theta_mu)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(theta_mu_data__.data(), D);
      {
        std::vector<local_scalar_t__> theta_mu_flat__;
        current_statement__ = 78;
        theta_mu_flat__ = context__.vals_r("theta_mu");
        current_statement__ = 78;
        pos__ = 1;
        current_statement__ = 78;
        for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
          current_statement__ = 78;
          stan::model::assign(theta_mu, theta_mu_flat__[(pos__ - 1)],
            "assigning variable theta_mu", stan::model::index_uni(sym1__));
          current_statement__ = 78;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 79;
      context__.validate_dims("data initialization", "lambda_alpha",
        "double", std::vector<size_t>{});
      lambda_alpha = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 79;
      lambda_alpha = context__.vals_r("lambda_alpha")[(1 - 1)];
      current_statement__ = 79;
      stan::math::check_greater_or_equal(function__, "lambda_alpha",
        lambda_alpha, 0);
      current_statement__ = 80;
      context__.validate_dims("data initialization", "lambda_beta", "double",
        std::vector<size_t>{});
      lambda_beta = std::numeric_limits<double>::quiet_NaN();
      current_statement__ = 80;
      lambda_beta = context__.vals_r("lambda_beta")[(1 - 1)];
      current_statement__ = 80;
      stan::math::check_greater_or_equal(function__, "lambda_beta",
        lambda_beta, 0);
      current_statement__ = 81;
      context__.validate_dims("data initialization", "N_lambda_est", "int",
        std::vector<size_t>{});
      N_lambda_est = std::numeric_limits<int>::min();
      current_statement__ = 81;
      N_lambda_est = context__.vals_i("N_lambda_est")[(1 - 1)];
      current_statement__ = 81;
      stan::math::check_greater_or_equal(function__, "N_lambda_est",
        N_lambda_est, 0);
      current_statement__ = 82;
      stan::math::validate_non_negative_index("Idx_lambda_est",
        "N_lambda_est", N_lambda_est);
      current_statement__ = 83;
      context__.validate_dims("data initialization", "Idx_lambda_est", "int",
        std::vector<size_t>{static_cast<size_t>(N_lambda_est)});
      Idx_lambda_est = std::vector<int>(N_lambda_est,
                         std::numeric_limits<int>::min());
      current_statement__ = 83;
      Idx_lambda_est = context__.vals_i("Idx_lambda_est");
      current_statement__ = 83;
      stan::math::check_greater_or_equal(function__, "Idx_lambda_est",
        Idx_lambda_est, 1);
      current_statement__ = 83;
      stan::math::check_less_or_equal(function__, "Idx_lambda_est",
        Idx_lambda_est, I_states);
      current_statement__ = 84;
      context__.validate_dims("data initialization", "N_lambda_fix", "int",
        std::vector<size_t>{});
      N_lambda_fix = std::numeric_limits<int>::min();
      current_statement__ = 84;
      N_lambda_fix = context__.vals_i("N_lambda_fix")[(1 - 1)];
      current_statement__ = 84;
      stan::math::check_greater_or_equal(function__, "N_lambda_fix",
        N_lambda_fix, 0);
      current_statement__ = 85;
      stan::math::validate_non_negative_index("Idx_lambda_fix",
        "N_lambda_fix", N_lambda_fix);
      current_statement__ = 86;
      context__.validate_dims("data initialization", "Idx_lambda_fix", "int",
        std::vector<size_t>{static_cast<size_t>(N_lambda_fix)});
      Idx_lambda_fix = std::vector<int>(N_lambda_fix,
                         std::numeric_limits<int>::min());
      current_statement__ = 86;
      Idx_lambda_fix = context__.vals_i("Idx_lambda_fix");
      current_statement__ = 86;
      stan::math::check_greater_or_equal(function__, "Idx_lambda_fix",
        Idx_lambda_fix, 1);
      current_statement__ = 86;
      stan::math::check_less_or_equal(function__, "Idx_lambda_fix",
        Idx_lambda_fix, I_states);
      current_statement__ = 87;
      stan::math::validate_non_negative_index("lambda_fix_val",
        "N_lambda_fix", N_lambda_fix);
      current_statement__ = 88;
      context__.validate_dims("data initialization", "lambda_fix_val",
        "double", std::vector<size_t>{static_cast<size_t>(N_lambda_fix)});
      lambda_fix_val_data__ = Eigen::Matrix<double,-1,1>::Constant(N_lambda_fix,
                                std::numeric_limits<double>::quiet_NaN());
      new (&lambda_fix_val)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(lambda_fix_val_data__.data(),
        N_lambda_fix);
      {
        std::vector<local_scalar_t__> lambda_fix_val_flat__;
        current_statement__ = 88;
        lambda_fix_val_flat__ = context__.vals_r("lambda_fix_val");
        current_statement__ = 88;
        pos__ = 1;
        current_statement__ = 88;
        for (int sym1__ = 1; sym1__ <= N_lambda_fix; ++sym1__) {
          current_statement__ = 88;
          stan::model::assign(lambda_fix_val, lambda_fix_val_flat__[(pos__ -
            1)], "assigning variable lambda_fix_val",
            stan::model::index_uni(sym1__));
          current_statement__ = 88;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 89;
      context__.validate_dims("data initialization", "N_psi_fix", "int",
        std::vector<size_t>{});
      N_psi_fix = std::numeric_limits<int>::min();
      current_statement__ = 89;
      N_psi_fix = context__.vals_i("N_psi_fix")[(1 - 1)];
      current_statement__ = 89;
      stan::math::check_greater_or_equal(function__, "N_psi_fix", N_psi_fix,
        0);
      current_statement__ = 90;
      stan::math::validate_non_negative_index("Idx_psi_fix", "N_psi_fix",
        N_psi_fix);
      current_statement__ = 91;
      context__.validate_dims("data initialization", "Idx_psi_fix", "int",
        std::vector<size_t>{static_cast<size_t>(N_psi_fix)});
      Idx_psi_fix = std::vector<int>(N_psi_fix,
                      std::numeric_limits<int>::min());
      current_statement__ = 91;
      Idx_psi_fix = context__.vals_i("Idx_psi_fix");
      current_statement__ = 91;
      stan::math::check_greater_or_equal(function__, "Idx_psi_fix",
        Idx_psi_fix, 1);
      current_statement__ = 91;
      stan::math::check_less_or_equal(function__, "Idx_psi_fix", Idx_psi_fix,
        I_states);
      current_statement__ = 92;
      stan::math::validate_non_negative_index("psi_fix_val", "N_psi_fix",
        N_psi_fix);
      current_statement__ = 93;
      context__.validate_dims("data initialization", "psi_fix_val", "double",
        std::vector<size_t>{static_cast<size_t>(N_psi_fix)});
      psi_fix_val_data__ = Eigen::Matrix<double,-1,1>::Constant(N_psi_fix,
                             std::numeric_limits<double>::quiet_NaN());
      new (&psi_fix_val)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(psi_fix_val_data__.data(),
        N_psi_fix);
      {
        std::vector<local_scalar_t__> psi_fix_val_flat__;
        current_statement__ = 93;
        psi_fix_val_flat__ = context__.vals_r("psi_fix_val");
        current_statement__ = 93;
        pos__ = 1;
        current_statement__ = 93;
        for (int sym1__ = 1; sym1__ <= N_psi_fix; ++sym1__) {
          current_statement__ = 93;
          stan::model::assign(psi_fix_val, psi_fix_val_flat__[(pos__ - 1)],
            "assigning variable psi_fix_val", stan::model::index_uni(sym1__));
          current_statement__ = 93;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 93;
      stan::math::check_greater_or_equal(function__, "psi_fix_val",
        psi_fix_val, 0);
      current_statement__ = 94;
      context__.validate_dims("data initialization", "N_psi_est", "int",
        std::vector<size_t>{});
      N_psi_est = std::numeric_limits<int>::min();
      current_statement__ = 94;
      N_psi_est = context__.vals_i("N_psi_est")[(1 - 1)];
      current_statement__ = 94;
      stan::math::check_greater_or_equal(function__, "N_psi_est", N_psi_est,
        0);
      current_statement__ = 95;
      stan::math::validate_non_negative_index("Idx_psi_est", "N_psi_est",
        N_psi_est);
      current_statement__ = 96;
      context__.validate_dims("data initialization", "Idx_psi_est", "int",
        std::vector<size_t>{static_cast<size_t>(N_psi_est)});
      Idx_psi_est = std::vector<int>(N_psi_est,
                      std::numeric_limits<int>::min());
      current_statement__ = 96;
      Idx_psi_est = context__.vals_i("Idx_psi_est");
      current_statement__ = 96;
      stan::math::check_greater_or_equal(function__, "Idx_psi_est",
        Idx_psi_est, 1);
      current_statement__ = 96;
      stan::math::check_less_or_equal(function__, "Idx_psi_est", Idx_psi_est,
        I_states);
      current_statement__ = 97;
      context__.validate_dims("data initialization", "N_psi_equal", "int",
        std::vector<size_t>{});
      N_psi_equal = std::numeric_limits<int>::min();
      current_statement__ = 97;
      N_psi_equal = context__.vals_i("N_psi_equal")[(1 - 1)];
      current_statement__ = 97;
      stan::math::check_greater_or_equal(function__, "N_psi_equal",
        N_psi_equal, 0);
      current_statement__ = 98;
      stan::math::validate_non_negative_index("Idx_psi_equal", "N_psi_equal",
        N_psi_equal);
      current_statement__ = 99;
      context__.validate_dims("data initialization", "Idx_psi_equal", "int",
        std::vector<size_t>{static_cast<size_t>(N_psi_equal)});
      Idx_psi_equal = std::vector<int>(N_psi_equal,
                        std::numeric_limits<int>::min());
      current_statement__ = 99;
      Idx_psi_equal = context__.vals_i("Idx_psi_equal");
      current_statement__ = 99;
      stan::math::check_greater_or_equal(function__, "Idx_psi_equal",
        Idx_psi_equal, 1);
      current_statement__ = 99;
      stan::math::check_less_or_equal(function__, "Idx_psi_equal",
        Idx_psi_equal, I_states);
      current_statement__ = 100;
      stan::math::validate_non_negative_index("Idx_psi_orig", "N_psi_equal",
        N_psi_equal);
      current_statement__ = 101;
      context__.validate_dims("data initialization", "Idx_psi_orig", "int",
        std::vector<size_t>{static_cast<size_t>(N_psi_equal)});
      Idx_psi_orig = std::vector<int>(N_psi_equal,
                       std::numeric_limits<int>::min());
      current_statement__ = 101;
      Idx_psi_orig = context__.vals_i("Idx_psi_orig");
      current_statement__ = 101;
      stan::math::check_greater_or_equal(function__, "Idx_psi_orig",
        Idx_psi_orig, 1);
      current_statement__ = 101;
      stan::math::check_less_or_equal(function__, "Idx_psi_orig",
        Idx_psi_orig, I_states);
      current_statement__ = 102;
      context__.validate_dims("data initialization", "N_gamma_fix", "int",
        std::vector<size_t>{});
      N_gamma_fix = std::numeric_limits<int>::min();
      current_statement__ = 102;
      N_gamma_fix = context__.vals_i("N_gamma_fix")[(1 - 1)];
      current_statement__ = 102;
      stan::math::check_greater_or_equal(function__, "N_gamma_fix",
        N_gamma_fix, 0);
      current_statement__ = 103;
      stan::math::validate_non_negative_index("Idx_gamma_fix", "N_gamma_fix",
        N_gamma_fix);
      current_statement__ = 104;
      context__.validate_dims("data initialization", "Idx_gamma_fix", "int",
        std::vector<size_t>{static_cast<size_t>(N_gamma_fix)});
      Idx_gamma_fix = std::vector<int>(N_gamma_fix,
                        std::numeric_limits<int>::min());
      current_statement__ = 104;
      Idx_gamma_fix = context__.vals_i("Idx_gamma_fix");
      current_statement__ = 104;
      stan::math::check_greater_or_equal(function__, "Idx_gamma_fix",
        Idx_gamma_fix, 1);
      current_statement__ = 104;
      stan::math::check_less_or_equal(function__, "Idx_gamma_fix",
        Idx_gamma_fix, N_pair);
      current_statement__ = 105;
      stan::math::validate_non_negative_index("gamma_fix_val", "N_gamma_fix",
        N_gamma_fix);
      current_statement__ = 106;
      context__.validate_dims("data initialization", "gamma_fix_val",
        "double", std::vector<size_t>{static_cast<size_t>(N_gamma_fix)});
      gamma_fix_val_data__ = Eigen::Matrix<double,-1,1>::Constant(N_gamma_fix,
                               std::numeric_limits<double>::quiet_NaN());
      new (&gamma_fix_val)
        Eigen::Map<Eigen::Matrix<double,-1,1>>(gamma_fix_val_data__.data(),
        N_gamma_fix);
      {
        std::vector<local_scalar_t__> gamma_fix_val_flat__;
        current_statement__ = 106;
        gamma_fix_val_flat__ = context__.vals_r("gamma_fix_val");
        current_statement__ = 106;
        pos__ = 1;
        current_statement__ = 106;
        for (int sym1__ = 1; sym1__ <= N_gamma_fix; ++sym1__) {
          current_statement__ = 106;
          stan::model::assign(gamma_fix_val, gamma_fix_val_flat__[(pos__ -
            1)], "assigning variable gamma_fix_val",
            stan::model::index_uni(sym1__));
          current_statement__ = 106;
          pos__ = (pos__ + 1);
        }
      }
      current_statement__ = 107;
      context__.validate_dims("data initialization", "N_gamma_est", "int",
        std::vector<size_t>{});
      N_gamma_est = std::numeric_limits<int>::min();
      current_statement__ = 107;
      N_gamma_est = context__.vals_i("N_gamma_est")[(1 - 1)];
      current_statement__ = 107;
      stan::math::check_greater_or_equal(function__, "N_gamma_est",
        N_gamma_est, 0);
      current_statement__ = 108;
      stan::math::validate_non_negative_index("Idx_gamma_est", "N_gamma_est",
        N_gamma_est);
      current_statement__ = 109;
      context__.validate_dims("data initialization", "Idx_gamma_est", "int",
        std::vector<size_t>{static_cast<size_t>(N_gamma_est)});
      Idx_gamma_est = std::vector<int>(N_gamma_est,
                        std::numeric_limits<int>::min());
      current_statement__ = 109;
      Idx_gamma_est = context__.vals_i("Idx_gamma_est");
      current_statement__ = 109;
      stan::math::check_greater_or_equal(function__, "Idx_gamma_est",
        Idx_gamma_est, 1);
      current_statement__ = 109;
      stan::math::check_less_or_equal(function__, "Idx_gamma_est",
        Idx_gamma_est, N_pair);
      current_statement__ = 110;
      stan::math::validate_non_negative_index("z_theta", "D", D);
      current_statement__ = 111;
      stan::math::validate_non_negative_index("z_theta", "N_person", N_person);
      current_statement__ = 112;
      stan::math::validate_non_negative_index("L_theta", "D", D);
      current_statement__ = 112;
      stan::math::validate_non_negative_index("L_theta", "D", D);
      current_statement__ = 113;
      stan::math::validate_non_negative_index("lambda_est", "N_lambda_est",
        N_lambda_est);
      current_statement__ = 114;
      stan::math::validate_non_negative_index("psi_est", "N_psi_est",
        N_psi_est);
      current_statement__ = 115;
      stan::math::validate_non_negative_index("gamma_est", "N_gamma_est",
        N_gamma_est);
      current_statement__ = 116;
      stan::math::validate_non_negative_index("theta", "N_person", N_person);
      current_statement__ = 117;
      stan::math::validate_non_negative_index("theta", "D", D);
      current_statement__ = 118;
      stan::math::validate_non_negative_index("lambda", "I_states", I_states);
      current_statement__ = 119;
      stan::math::validate_non_negative_index("psi", "I_states", I_states);
      current_statement__ = 120;
      stan::math::validate_non_negative_index("gamma", "N_pair", N_pair);
      current_statement__ = 121;
      stan::math::validate_non_negative_index("Corr", "D", D);
      current_statement__ = 121;
      stan::math::validate_non_negative_index("Corr", "D", D);
      current_statement__ = 122;
      stan::math::validate_non_negative_index("log_lik", "N_obs", N_obs);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    num_params_r__ = (D * N_person) + ((D * (D - 1)) / 2) + N_lambda_est +
      N_psi_est + N_gamma_est;
  }
  inline std::string model_name() const final {
    return "model_TIRT";
  }
  inline std::vector<std::string> model_compile_info() const noexcept {
    return std::vector<std::string>{"stanc_version = stanc3 v2.32.2",
             "stancflags = --allow-undefined"};
  }
  template <bool propto__, bool jacobian__, typename VecR, typename VecI,
            stan::require_vector_like_t<VecR>* = nullptr,
            stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
  inline stan::scalar_type_t<VecR>
  log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream*
                pstream__ = nullptr) const {
    using T__ = stan::scalar_type_t<VecR>;
    using local_scalar_t__ = T__;
    T__ lp__(0.0);
    stan::math::accumulator<T__> lp_accum__;
    stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
    int current_statement__ = 0;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    static constexpr const char* function__ =
      "model_TIRT_namespace::log_prob";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<local_scalar_t__,-1,-1> z_theta =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(D, N_person,
          DUMMY_VAR__);
      current_statement__ = 1;
      z_theta = in__.template read<Eigen::Matrix<local_scalar_t__,-1,-1>>(D,
                  N_person);
      Eigen::Matrix<local_scalar_t__,-1,-1> L_theta =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(D, D, DUMMY_VAR__);
      current_statement__ = 2;
      L_theta = in__.template read_constrain_cholesky_factor_corr<
                  Eigen::Matrix<local_scalar_t__,-1,-1>, jacobian__>(lp__, D);
      Eigen::Matrix<local_scalar_t__,-1,1> lambda_est =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_lambda_est,
          DUMMY_VAR__);
      current_statement__ = 3;
      lambda_est = in__.template read_constrain_lub<
                     Eigen::Matrix<local_scalar_t__,-1,1>,
                     jacobian__>(lambda_alpha, lambda_beta, lp__,
                     N_lambda_est);
      Eigen::Matrix<local_scalar_t__,-1,1> psi_est =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_psi_est,
          DUMMY_VAR__);
      current_statement__ = 4;
      psi_est = in__.template read_constrain_lb<
                  Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(0, lp__,
                  N_psi_est);
      Eigen::Matrix<local_scalar_t__,-1,1> gamma_est =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_gamma_est,
          DUMMY_VAR__);
      current_statement__ = 5;
      gamma_est = in__.template read<
                    Eigen::Matrix<local_scalar_t__,-1,1>>(N_gamma_est);
      Eigen::Matrix<local_scalar_t__,-1,-1> theta =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(N_person, D,
          DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> lambda =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(I_states, DUMMY_VAR__);
      Eigen::Matrix<local_scalar_t__,-1,1> psi =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(I_states, DUMMY_VAR__);
      current_statement__ = 12;
      stan::model::assign(theta,
        stan::math::transpose(stan::math::multiply(L_theta, z_theta)),
        "assigning variable theta");
      current_statement__ = 13;
      stan::model::assign(lambda, lambda_est, "assigning variable lambda",
        stan::model::index_multi(Idx_lambda_est));
      current_statement__ = 14;
      stan::model::assign(lambda, lambda_fix_val,
        "assigning variable lambda", stan::model::index_multi(Idx_lambda_fix));
      current_statement__ = 15;
      stan::model::assign(psi, psi_fix_val, "assigning variable psi",
        stan::model::index_multi(Idx_psi_fix));
      current_statement__ = 16;
      stan::model::assign(psi, psi_est, "assigning variable psi",
        stan::model::index_multi(Idx_psi_est));
      current_statement__ = 17;
      stan::model::assign(psi,
        stan::model::deep_copy(
          stan::model::rvalue(psi, "psi",
            stan::model::index_multi(Idx_psi_orig))),
        "assigning variable psi", stan::model::index_multi(Idx_psi_equal));
      Eigen::Matrix<local_scalar_t__,-1,1> gamma =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_pair, DUMMY_VAR__);
      current_statement__ = 18;
      stan::model::assign(gamma, gamma_fix_val, "assigning variable gamma",
        stan::model::index_multi(Idx_gamma_fix));
      current_statement__ = 19;
      stan::model::assign(gamma, gamma_est, "assigning variable gamma",
        stan::model::index_multi(Idx_gamma_est));
      current_statement__ = 7;
      stan::math::check_greater_or_equal(function__, "lambda", lambda, 0);
      current_statement__ = 8;
      stan::math::check_greater_or_equal(function__, "psi", psi, 0);
      {
        current_statement__ = 31;
        lp_accum__.add(stan::math::std_normal_lpdf<propto__>(
                         stan::math::to_vector(z_theta)));
        current_statement__ = 32;
        lp_accum__.add(stan::math::lkj_corr_cholesky_lpdf<propto__>(L_theta,
                         1));
        current_statement__ = 33;
        lp_accum__.add(stan::math::uniform_lpdf<propto__>(lambda_est,
                         lambda_alpha, lambda_beta));
        current_statement__ = 34;
        lp_accum__.add(stan::math::normal_lpdf<propto__>(psi_est, psi_mu,
                         psi_sigma));
        current_statement__ = 35;
        lp_accum__.add(stan::math::normal_lpdf<propto__>(gamma_est, gamma_mu,
                         gamma_sigma));
        current_statement__ = 36;
        stan::math::validate_non_negative_index("mu_diff", "N_obs", N_obs);
        Eigen::Matrix<local_scalar_t__,-1,1> mu_diff =
          Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_obs, DUMMY_VAR__);
        current_statement__ = 38;
        stan::math::validate_non_negative_index("sum_psi", "N_obs", N_obs);
        Eigen::Matrix<local_scalar_t__,-1,1> sum_psi =
          Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_obs, DUMMY_VAR__);
        current_statement__ = 46;
        for (int n = 1; n <= N_obs; ++n) {
          int i = std::numeric_limits<int>::min();
          current_statement__ = 40;
          i = stan::model::rvalue(Idx_item_i, "Idx_item_i",
                stan::model::index_uni(n));
          int k = std::numeric_limits<int>::min();
          current_statement__ = 41;
          k = stan::model::rvalue(Idx_item_k, "Idx_item_k",
                stan::model::index_uni(n));
          int p = std::numeric_limits<int>::min();
          current_statement__ = 42;
          p = stan::model::rvalue(Idx_person, "Idx_person",
                stan::model::index_uni(n));
          current_statement__ = 43;
          stan::model::assign(mu_diff,
            ((stan::model::rvalue(lambda, "lambda", stan::model::index_uni(i))
            *
            stan::math::dot_product(
              stan::model::rvalue(Q_matrix, "Q_matrix",
                stan::model::index_uni(i)),
              stan::model::rvalue(theta, "theta", stan::model::index_uni(p))))
            -
            (stan::model::rvalue(lambda, "lambda", stan::model::index_uni(k))
            *
            stan::math::dot_product(
              stan::model::rvalue(Q_matrix, "Q_matrix",
                stan::model::index_uni(k)),
              stan::model::rvalue(theta, "theta", stan::model::index_uni(p))))),
            "assigning variable mu_diff", stan::model::index_uni(n));
          current_statement__ = 44;
          stan::model::assign(sum_psi,
            stan::math::sqrt(
              ((stan::math::pow(
                  stan::model::rvalue(psi, "psi", stan::model::index_uni(i)),
                  2) +
              stan::math::pow(
                stan::model::rvalue(psi, "psi", stan::model::index_uni(k)), 2))
              + 1e-12)), "assigning variable sum_psi",
            stan::model::index_uni(n));
        }
        current_statement__ = 54;
        for (int n = 1; n <= N_obs; ++n) {
          local_scalar_t__ z = DUMMY_VAR__;
          current_statement__ = 47;
          z = ((stan::model::rvalue(mu_diff, "mu_diff",
                  stan::model::index_uni(n))
            -
            stan::model::rvalue(gamma, "gamma",
              stan::model::index_uni(
                stan::model::rvalue(Idx_pair, "Idx_pair",
                  stan::model::index_uni(n)))))
            /
            stan::model::rvalue(sum_psi, "sum_psi", stan::model::index_uni(n)));
          current_statement__ = 52;
          if (stan::math::logical_eq(
                stan::model::rvalue(response, "response",
                  stan::model::index_uni(n)), 1)) {
            current_statement__ = 50;
            lp_accum__.add(stan::math::normal_lcdf(z, 0, 1));
          } else {
            current_statement__ = 48;
            lp_accum__.add(stan::math::normal_lccdf(z, 0, 1));
          }
        }
      }
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
    lp_accum__.add(lp__);
    return lp_accum__.sum();
  }
  template <typename RNG, typename VecR, typename VecI, typename VecVar,
            stan::require_vector_like_vt<std::is_floating_point,
            VecR>* = nullptr, stan::require_vector_like_vt<std::is_integral,
            VecI>* = nullptr, stan::require_vector_vt<std::is_floating_point,
            VecVar>* = nullptr>
  inline void
  write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__,
                   VecVar& vars__, const bool
                   emit_transformed_parameters__ = true, const bool
                   emit_generated_quantities__ = true, std::ostream*
                   pstream__ = nullptr) const {
    using local_scalar_t__ = double;
    stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
    stan::io::serializer<local_scalar_t__> out__(vars__);
    static constexpr bool propto__ = true;
    // suppress unused var warning
    (void) propto__;
    double lp__ = 0.0;
    // suppress unused var warning
    (void) lp__;
    int current_statement__ = 0;
    stan::math::accumulator<double> lp_accum__;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    constexpr bool jacobian__ = false;
    static constexpr const char* function__ =
      "model_TIRT_namespace::write_array";
    // suppress unused var warning
    (void) function__;
    try {
      Eigen::Matrix<double,-1,-1> z_theta =
        Eigen::Matrix<double,-1,-1>::Constant(D, N_person,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 1;
      z_theta = in__.template read<Eigen::Matrix<local_scalar_t__,-1,-1>>(D,
                  N_person);
      Eigen::Matrix<double,-1,-1> L_theta =
        Eigen::Matrix<double,-1,-1>::Constant(D, D,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 2;
      L_theta = in__.template read_constrain_cholesky_factor_corr<
                  Eigen::Matrix<local_scalar_t__,-1,-1>, jacobian__>(lp__, D);
      Eigen::Matrix<double,-1,1> lambda_est =
        Eigen::Matrix<double,-1,1>::Constant(N_lambda_est,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 3;
      lambda_est = in__.template read_constrain_lub<
                     Eigen::Matrix<local_scalar_t__,-1,1>,
                     jacobian__>(lambda_alpha, lambda_beta, lp__,
                     N_lambda_est);
      Eigen::Matrix<double,-1,1> psi_est =
        Eigen::Matrix<double,-1,1>::Constant(N_psi_est,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 4;
      psi_est = in__.template read_constrain_lb<
                  Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(0, lp__,
                  N_psi_est);
      Eigen::Matrix<double,-1,1> gamma_est =
        Eigen::Matrix<double,-1,1>::Constant(N_gamma_est,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 5;
      gamma_est = in__.template read<
                    Eigen::Matrix<local_scalar_t__,-1,1>>(N_gamma_est);
      Eigen::Matrix<double,-1,-1> theta =
        Eigen::Matrix<double,-1,-1>::Constant(N_person, D,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> lambda =
        Eigen::Matrix<double,-1,1>::Constant(I_states,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> psi =
        Eigen::Matrix<double,-1,1>::Constant(I_states,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> gamma =
        Eigen::Matrix<double,-1,1>::Constant(N_pair,
          std::numeric_limits<double>::quiet_NaN());
      out__.write(z_theta);
      out__.write(L_theta);
      out__.write(lambda_est);
      out__.write(psi_est);
      out__.write(gamma_est);
      if (stan::math::logical_negation(
            (stan::math::primitive_value(emit_transformed_parameters__) ||
            stan::math::primitive_value(emit_generated_quantities__)))) {
        return ;
      }
      current_statement__ = 12;
      stan::model::assign(theta,
        stan::math::transpose(stan::math::multiply(L_theta, z_theta)),
        "assigning variable theta");
      current_statement__ = 13;
      stan::model::assign(lambda, lambda_est, "assigning variable lambda",
        stan::model::index_multi(Idx_lambda_est));
      current_statement__ = 14;
      stan::model::assign(lambda, lambda_fix_val,
        "assigning variable lambda", stan::model::index_multi(Idx_lambda_fix));
      current_statement__ = 15;
      stan::model::assign(psi, psi_fix_val, "assigning variable psi",
        stan::model::index_multi(Idx_psi_fix));
      current_statement__ = 16;
      stan::model::assign(psi, psi_est, "assigning variable psi",
        stan::model::index_multi(Idx_psi_est));
      current_statement__ = 17;
      stan::model::assign(psi,
        stan::model::deep_copy(
          stan::model::rvalue(psi, "psi",
            stan::model::index_multi(Idx_psi_orig))),
        "assigning variable psi", stan::model::index_multi(Idx_psi_equal));
      current_statement__ = 18;
      stan::model::assign(gamma, gamma_fix_val, "assigning variable gamma",
        stan::model::index_multi(Idx_gamma_fix));
      current_statement__ = 19;
      stan::model::assign(gamma, gamma_est, "assigning variable gamma",
        stan::model::index_multi(Idx_gamma_est));
      current_statement__ = 7;
      stan::math::check_greater_or_equal(function__, "lambda", lambda, 0);
      current_statement__ = 8;
      stan::math::check_greater_or_equal(function__, "psi", psi, 0);
      if (emit_transformed_parameters__) {
        out__.write(theta);
        out__.write(lambda);
        out__.write(psi);
        out__.write(gamma);
      }
      if (stan::math::logical_negation(emit_generated_quantities__)) {
        return ;
      }
      Eigen::Matrix<double,-1,-1> Corr =
        Eigen::Matrix<double,-1,-1>::Constant(D, D,
          std::numeric_limits<double>::quiet_NaN());
      Eigen::Matrix<double,-1,1> log_lik =
        Eigen::Matrix<double,-1,1>::Constant(N_obs,
          std::numeric_limits<double>::quiet_NaN());
      current_statement__ = 20;
      stan::model::assign(Corr,
        stan::math::multiply_lower_tri_self_transpose(L_theta),
        "assigning variable Corr");
      current_statement__ = 30;
      for (int n = 1; n <= N_obs; ++n) {
        double mu_diff = std::numeric_limits<double>::quiet_NaN();
        current_statement__ = 21;
        mu_diff = ((stan::model::rvalue(lambda, "lambda",
                      stan::model::index_uni(
                        stan::model::rvalue(Idx_item_i, "Idx_item_i",
                          stan::model::index_uni(n))))
          *
          stan::math::dot_product(
            stan::model::rvalue(Q_matrix, "Q_matrix",
              stan::model::index_uni(
                stan::model::rvalue(Idx_item_i, "Idx_item_i",
                  stan::model::index_uni(n)))),
            stan::model::rvalue(theta, "theta",
              stan::model::index_uni(
                stan::model::rvalue(Idx_person, "Idx_person",
                  stan::model::index_uni(n))))))
          -
          (stan::model::rvalue(lambda, "lambda",
             stan::model::index_uni(
               stan::model::rvalue(Idx_item_k, "Idx_item_k",
                 stan::model::index_uni(n))))
          *
          stan::math::dot_product(
            stan::model::rvalue(Q_matrix, "Q_matrix",
              stan::model::index_uni(
                stan::model::rvalue(Idx_item_k, "Idx_item_k",
                  stan::model::index_uni(n)))),
            stan::model::rvalue(theta, "theta",
              stan::model::index_uni(
                stan::model::rvalue(Idx_person, "Idx_person",
                  stan::model::index_uni(n)))))));
        double sum_psi = std::numeric_limits<double>::quiet_NaN();
        current_statement__ = 22;
        sum_psi = stan::math::sqrt(
                    ((stan::math::pow(
                        stan::model::rvalue(psi, "psi",
                          stan::model::index_uni(
                            stan::model::rvalue(Idx_item_i, "Idx_item_i",
                              stan::model::index_uni(n)))), 2) +
                    stan::math::pow(
                      stan::model::rvalue(psi, "psi",
                        stan::model::index_uni(
                          stan::model::rvalue(Idx_item_k, "Idx_item_k",
                            stan::model::index_uni(n)))), 2)) + 1e-12));
        double z = std::numeric_limits<double>::quiet_NaN();
        current_statement__ = 23;
        z = ((mu_diff -
          stan::model::rvalue(gamma, "gamma",
            stan::model::index_uni(
              stan::model::rvalue(Idx_pair, "Idx_pair",
                stan::model::index_uni(n)))))
          / sum_psi);
        current_statement__ = 28;
        if (stan::math::logical_eq(
              stan::model::rvalue(response, "response",
                stan::model::index_uni(n)), 1)) {
          current_statement__ = 26;
          stan::model::assign(log_lik, stan::math::normal_lcdf(z, 0, 1),
            "assigning variable log_lik", stan::model::index_uni(n));
        } else {
          current_statement__ = 24;
          stan::model::assign(log_lik, stan::math::normal_lccdf(z, 0, 1),
            "assigning variable log_lik", stan::model::index_uni(n));
        }
      }
      current_statement__ = 10;
      stan::math::check_corr_matrix(function__, "Corr", Corr);
      out__.write(Corr);
      out__.write(log_lik);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
  }
  template <typename VecVar, typename VecI,
            stan::require_vector_t<VecVar>* = nullptr,
            stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
  inline void
  unconstrain_array_impl(const VecVar& params_r__, const VecI& params_i__,
                         VecVar& vars__, std::ostream* pstream__ = nullptr) const {
    using local_scalar_t__ = double;
    stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
    stan::io::serializer<local_scalar_t__> out__(vars__);
    int current_statement__ = 0;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    try {
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      Eigen::Matrix<local_scalar_t__,-1,-1> z_theta =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(D, N_person,
          DUMMY_VAR__);
      current_statement__ = 1;
      stan::model::assign(z_theta,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,-1>>(D, N_person),
        "assigning variable z_theta");
      out__.write(z_theta);
      Eigen::Matrix<local_scalar_t__,-1,-1> L_theta =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(D, D, DUMMY_VAR__);
      current_statement__ = 2;
      stan::model::assign(L_theta,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,-1>>(D, D),
        "assigning variable L_theta");
      out__.write_free_cholesky_factor_corr(L_theta);
      Eigen::Matrix<local_scalar_t__,-1,1> lambda_est =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_lambda_est,
          DUMMY_VAR__);
      current_statement__ = 3;
      stan::model::assign(lambda_est,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(N_lambda_est),
        "assigning variable lambda_est");
      out__.write_free_lub(lambda_alpha, lambda_beta, lambda_est);
      Eigen::Matrix<local_scalar_t__,-1,1> psi_est =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_psi_est,
          DUMMY_VAR__);
      current_statement__ = 4;
      stan::model::assign(psi_est,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(N_psi_est),
        "assigning variable psi_est");
      out__.write_free_lb(0, psi_est);
      Eigen::Matrix<local_scalar_t__,-1,1> gamma_est =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_gamma_est,
          DUMMY_VAR__);
      current_statement__ = 5;
      stan::model::assign(gamma_est,
        in__.read<Eigen::Matrix<local_scalar_t__,-1,1>>(N_gamma_est),
        "assigning variable gamma_est");
      out__.write(gamma_est);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
  }
  template <typename VecVar, stan::require_vector_t<VecVar>* = nullptr>
  inline void
  transform_inits_impl(const stan::io::var_context& context__, VecVar&
                       vars__, std::ostream* pstream__ = nullptr) const {
    using local_scalar_t__ = double;
    stan::io::serializer<local_scalar_t__> out__(vars__);
    int current_statement__ = 0;
    local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
    // suppress unused var warning
    (void) DUMMY_VAR__;
    try {
      current_statement__ = 1;
      context__.validate_dims("parameter initialization", "z_theta",
        "double",
        std::vector<size_t>{static_cast<size_t>(D),
          static_cast<size_t>(N_person)});
      current_statement__ = 2;
      context__.validate_dims("parameter initialization", "L_theta",
        "double",
        std::vector<size_t>{static_cast<size_t>(D), static_cast<size_t>(D)});
      current_statement__ = 3;
      context__.validate_dims("parameter initialization", "lambda_est",
        "double", std::vector<size_t>{static_cast<size_t>(N_lambda_est)});
      current_statement__ = 4;
      context__.validate_dims("parameter initialization", "psi_est",
        "double", std::vector<size_t>{static_cast<size_t>(N_psi_est)});
      current_statement__ = 5;
      context__.validate_dims("parameter initialization", "gamma_est",
        "double", std::vector<size_t>{static_cast<size_t>(N_gamma_est)});
      int pos__ = std::numeric_limits<int>::min();
      pos__ = 1;
      Eigen::Matrix<local_scalar_t__,-1,-1> z_theta =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(D, N_person,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> z_theta_flat__;
        current_statement__ = 1;
        z_theta_flat__ = context__.vals_r("z_theta");
        current_statement__ = 1;
        pos__ = 1;
        current_statement__ = 1;
        for (int sym1__ = 1; sym1__ <= N_person; ++sym1__) {
          current_statement__ = 1;
          for (int sym2__ = 1; sym2__ <= D; ++sym2__) {
            current_statement__ = 1;
            stan::model::assign(z_theta, z_theta_flat__[(pos__ - 1)],
              "assigning variable z_theta", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 1;
            pos__ = (pos__ + 1);
          }
        }
      }
      out__.write(z_theta);
      Eigen::Matrix<local_scalar_t__,-1,-1> L_theta =
        Eigen::Matrix<local_scalar_t__,-1,-1>::Constant(D, D, DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> L_theta_flat__;
        current_statement__ = 2;
        L_theta_flat__ = context__.vals_r("L_theta");
        current_statement__ = 2;
        pos__ = 1;
        current_statement__ = 2;
        for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
          current_statement__ = 2;
          for (int sym2__ = 1; sym2__ <= D; ++sym2__) {
            current_statement__ = 2;
            stan::model::assign(L_theta, L_theta_flat__[(pos__ - 1)],
              "assigning variable L_theta", stan::model::index_uni(sym2__),
              stan::model::index_uni(sym1__));
            current_statement__ = 2;
            pos__ = (pos__ + 1);
          }
        }
      }
      out__.write_free_cholesky_factor_corr(L_theta);
      Eigen::Matrix<local_scalar_t__,-1,1> lambda_est =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_lambda_est,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> lambda_est_flat__;
        current_statement__ = 3;
        lambda_est_flat__ = context__.vals_r("lambda_est");
        current_statement__ = 3;
        pos__ = 1;
        current_statement__ = 3;
        for (int sym1__ = 1; sym1__ <= N_lambda_est; ++sym1__) {
          current_statement__ = 3;
          stan::model::assign(lambda_est, lambda_est_flat__[(pos__ - 1)],
            "assigning variable lambda_est", stan::model::index_uni(sym1__));
          current_statement__ = 3;
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_lub(lambda_alpha, lambda_beta, lambda_est);
      Eigen::Matrix<local_scalar_t__,-1,1> psi_est =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_psi_est,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> psi_est_flat__;
        current_statement__ = 4;
        psi_est_flat__ = context__.vals_r("psi_est");
        current_statement__ = 4;
        pos__ = 1;
        current_statement__ = 4;
        for (int sym1__ = 1; sym1__ <= N_psi_est; ++sym1__) {
          current_statement__ = 4;
          stan::model::assign(psi_est, psi_est_flat__[(pos__ - 1)],
            "assigning variable psi_est", stan::model::index_uni(sym1__));
          current_statement__ = 4;
          pos__ = (pos__ + 1);
        }
      }
      out__.write_free_lb(0, psi_est);
      Eigen::Matrix<local_scalar_t__,-1,1> gamma_est =
        Eigen::Matrix<local_scalar_t__,-1,1>::Constant(N_gamma_est,
          DUMMY_VAR__);
      {
        std::vector<local_scalar_t__> gamma_est_flat__;
        current_statement__ = 5;
        gamma_est_flat__ = context__.vals_r("gamma_est");
        current_statement__ = 5;
        pos__ = 1;
        current_statement__ = 5;
        for (int sym1__ = 1; sym1__ <= N_gamma_est; ++sym1__) {
          current_statement__ = 5;
          stan::model::assign(gamma_est, gamma_est_flat__[(pos__ - 1)],
            "assigning variable gamma_est", stan::model::index_uni(sym1__));
          current_statement__ = 5;
          pos__ = (pos__ + 1);
        }
      }
      out__.write(gamma_est);
    } catch (const std::exception& e) {
      stan::lang::rethrow_located(e, locations_array__[current_statement__]);
    }
  }
  inline void
  get_param_names(std::vector<std::string>& names__, const bool
                  emit_transformed_parameters__ = true, const bool
                  emit_generated_quantities__ = true) const {
    names__ = std::vector<std::string>{"z_theta", "L_theta", "lambda_est",
                "psi_est", "gamma_est"};
    if (emit_transformed_parameters__) {
      std::vector<std::string> temp{"theta", "lambda", "psi", "gamma"};
      names__.reserve(names__.size() + temp.size());
      names__.insert(names__.end(), temp.begin(), temp.end());
    }
    if (emit_generated_quantities__) {
      std::vector<std::string> temp{"Corr", "log_lik"};
      names__.reserve(names__.size() + temp.size());
      names__.insert(names__.end(), temp.begin(), temp.end());
    }
  }
  inline void
  get_dims(std::vector<std::vector<size_t>>& dimss__, const bool
           emit_transformed_parameters__ = true, const bool
           emit_generated_quantities__ = true) const {
    dimss__ = std::vector<std::vector<size_t>>{std::vector<size_t>{static_cast<
                                                                    size_t>(D),
                                                 static_cast<size_t>(N_person)},
                std::vector<size_t>{static_cast<size_t>(D),
                  static_cast<size_t>(D)},
                std::vector<size_t>{static_cast<size_t>(N_lambda_est)},
                std::vector<size_t>{static_cast<size_t>(N_psi_est)},
                std::vector<size_t>{static_cast<size_t>(N_gamma_est)}};
    if (emit_transformed_parameters__) {
      std::vector<std::vector<size_t>>
        temp{std::vector<size_t>{static_cast<size_t>(N_person),
               static_cast<size_t>(D)},
             std::vector<size_t>{static_cast<size_t>(I_states)},
             std::vector<size_t>{static_cast<size_t>(I_states)},
             std::vector<size_t>{static_cast<size_t>(N_pair)}};
      dimss__.reserve(dimss__.size() + temp.size());
      dimss__.insert(dimss__.end(), temp.begin(), temp.end());
    }
    if (emit_generated_quantities__) {
      std::vector<std::vector<size_t>>
        temp{std::vector<size_t>{static_cast<size_t>(D),
               static_cast<size_t>(D)},
             std::vector<size_t>{static_cast<size_t>(N_obs)}};
      dimss__.reserve(dimss__.size() + temp.size());
      dimss__.insert(dimss__.end(), temp.begin(), temp.end());
    }
  }
  inline void
  constrained_param_names(std::vector<std::string>& param_names__, bool
                          emit_transformed_parameters__ = true, bool
                          emit_generated_quantities__ = true) const final {
    for (int sym1__ = 1; sym1__ <= N_person; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= D; ++sym2__) {
        param_names__.emplace_back(std::string() + "z_theta" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= D; ++sym2__) {
        param_names__.emplace_back(std::string() + "L_theta" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    for (int sym1__ = 1; sym1__ <= N_lambda_est; ++sym1__) {
      param_names__.emplace_back(std::string() + "lambda_est" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= N_psi_est; ++sym1__) {
      param_names__.emplace_back(std::string() + "psi_est" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= N_gamma_est; ++sym1__) {
      param_names__.emplace_back(std::string() + "gamma_est" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {
      for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= N_person; ++sym2__) {
          param_names__.emplace_back(std::string() + "theta" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= I_states; ++sym1__) {
        param_names__.emplace_back(std::string() + "lambda" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= I_states; ++sym1__) {
        param_names__.emplace_back(std::string() + "psi" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= N_pair; ++sym1__) {
        param_names__.emplace_back(std::string() + "gamma" + '.' +
          std::to_string(sym1__));
      }
    }
    if (emit_generated_quantities__) {
      for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= D; ++sym2__) {
          param_names__.emplace_back(std::string() + "Corr" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= N_obs; ++sym1__) {
        param_names__.emplace_back(std::string() + "log_lik" + '.' +
          std::to_string(sym1__));
      }
    }
  }
  inline void
  unconstrained_param_names(std::vector<std::string>& param_names__, bool
                            emit_transformed_parameters__ = true, bool
                            emit_generated_quantities__ = true) const final {
    for (int sym1__ = 1; sym1__ <= N_person; ++sym1__) {
      for (int sym2__ = 1; sym2__ <= D; ++sym2__) {
        param_names__.emplace_back(std::string() + "z_theta" + '.' +
          std::to_string(sym2__) + '.' + std::to_string(sym1__));
      }
    }
    for (int sym1__ = 1; sym1__ <= ((D * (D - 1)) / 2); ++sym1__) {
      param_names__.emplace_back(std::string() + "L_theta" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= N_lambda_est; ++sym1__) {
      param_names__.emplace_back(std::string() + "lambda_est" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= N_psi_est; ++sym1__) {
      param_names__.emplace_back(std::string() + "psi_est" + '.' +
        std::to_string(sym1__));
    }
    for (int sym1__ = 1; sym1__ <= N_gamma_est; ++sym1__) {
      param_names__.emplace_back(std::string() + "gamma_est" + '.' +
        std::to_string(sym1__));
    }
    if (emit_transformed_parameters__) {
      for (int sym1__ = 1; sym1__ <= D; ++sym1__) {
        for (int sym2__ = 1; sym2__ <= N_person; ++sym2__) {
          param_names__.emplace_back(std::string() + "theta" + '.' +
            std::to_string(sym2__) + '.' + std::to_string(sym1__));
        }
      }
      for (int sym1__ = 1; sym1__ <= I_states; ++sym1__) {
        param_names__.emplace_back(std::string() + "lambda" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= I_states; ++sym1__) {
        param_names__.emplace_back(std::string() + "psi" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= N_pair; ++sym1__) {
        param_names__.emplace_back(std::string() + "gamma" + '.' +
          std::to_string(sym1__));
      }
    }
    if (emit_generated_quantities__) {
      for (int sym1__ = 1; sym1__ <= ((D * (D - 1)) / 2); ++sym1__) {
        param_names__.emplace_back(std::string() + "Corr" + '.' +
          std::to_string(sym1__));
      }
      for (int sym1__ = 1; sym1__ <= N_obs; ++sym1__) {
        param_names__.emplace_back(std::string() + "log_lik" + '.' +
          std::to_string(sym1__));
      }
    }
  }
  inline std::string get_constrained_sizedtypes() const {
    return std::string("[{\"name\":\"z_theta\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(D) + ",\"cols\":" + std::to_string(N_person) + "},\"block\":\"parameters\"},{\"name\":\"L_theta\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(D) + ",\"cols\":" + std::to_string(D) + "},\"block\":\"parameters\"},{\"name\":\"lambda_est\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_lambda_est) + "},\"block\":\"parameters\"},{\"name\":\"psi_est\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_psi_est) + "},\"block\":\"parameters\"},{\"name\":\"gamma_est\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_gamma_est) + "},\"block\":\"parameters\"},{\"name\":\"theta\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(N_person) + ",\"cols\":" + std::to_string(D) + "},\"block\":\"transformed_parameters\"},{\"name\":\"lambda\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(I_states) + "},\"block\":\"transformed_parameters\"},{\"name\":\"psi\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(I_states) + "},\"block\":\"transformed_parameters\"},{\"name\":\"gamma\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_pair) + "},\"block\":\"transformed_parameters\"},{\"name\":\"Corr\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(D) + ",\"cols\":" + std::to_string(D) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_obs) + "},\"block\":\"generated_quantities\"}]");
  }
  inline std::string get_unconstrained_sizedtypes() const {
    return std::string("[{\"name\":\"z_theta\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(D) + ",\"cols\":" + std::to_string(N_person) + "},\"block\":\"parameters\"},{\"name\":\"L_theta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(((D * (D - 1)) /2)) + "},\"block\":\"parameters\"},{\"name\":\"lambda_est\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_lambda_est) + "},\"block\":\"parameters\"},{\"name\":\"psi_est\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_psi_est) + "},\"block\":\"parameters\"},{\"name\":\"gamma_est\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_gamma_est) + "},\"block\":\"parameters\"},{\"name\":\"theta\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(N_person) + ",\"cols\":" + std::to_string(D) + "},\"block\":\"transformed_parameters\"},{\"name\":\"lambda\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(I_states) + "},\"block\":\"transformed_parameters\"},{\"name\":\"psi\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(I_states) + "},\"block\":\"transformed_parameters\"},{\"name\":\"gamma\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_pair) + "},\"block\":\"transformed_parameters\"},{\"name\":\"Corr\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(((D * (D - 1)) /2)) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(N_obs) + "},\"block\":\"generated_quantities\"}]");
  }
  // Begin method overload boilerplate
  template <typename RNG> inline void
  write_array(RNG& base_rng, Eigen::Matrix<double,-1,1>& params_r,
              Eigen::Matrix<double,-1,1>& vars, const bool
              emit_transformed_parameters = true, const bool
              emit_generated_quantities = true, std::ostream*
              pstream = nullptr) const {
    const size_t num_params__ = (((((D * N_person) + (D * D)) + N_lambda_est)
      + N_psi_est) + N_gamma_est);
    const size_t num_transformed = emit_transformed_parameters *
      (((((N_person * D) + I_states) + I_states) + N_pair));
    const size_t num_gen_quantities = emit_generated_quantities * (((D * D) +
      N_obs));
    const size_t num_to_write = num_params__ + num_transformed +
      num_gen_quantities;
    std::vector<int> params_i;
    vars = Eigen::Matrix<double,-1,1>::Constant(num_to_write,
             std::numeric_limits<double>::quiet_NaN());
    write_array_impl(base_rng, params_r, params_i, vars,
      emit_transformed_parameters, emit_generated_quantities, pstream);
  }
  template <typename RNG> inline void
  write_array(RNG& base_rng, std::vector<double>& params_r, std::vector<int>&
              params_i, std::vector<double>& vars, bool
              emit_transformed_parameters = true, bool
              emit_generated_quantities = true, std::ostream*
              pstream = nullptr) const {
    const size_t num_params__ = (((((D * N_person) + (D * D)) + N_lambda_est)
      + N_psi_est) + N_gamma_est);
    const size_t num_transformed = emit_transformed_parameters *
      (((((N_person * D) + I_states) + I_states) + N_pair));
    const size_t num_gen_quantities = emit_generated_quantities * (((D * D) +
      N_obs));
    const size_t num_to_write = num_params__ + num_transformed +
      num_gen_quantities;
    vars = std::vector<double>(num_to_write,
             std::numeric_limits<double>::quiet_NaN());
    write_array_impl(base_rng, params_r, params_i, vars,
      emit_transformed_parameters, emit_generated_quantities, pstream);
  }
  template <bool propto__, bool jacobian__, typename T_> inline T_
  log_prob(Eigen::Matrix<T_,-1,1>& params_r, std::ostream* pstream = nullptr) const {
    Eigen::Matrix<int,-1,1> params_i;
    return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
  }
  template <bool propto__, bool jacobian__, typename T_> inline T_
  log_prob(std::vector<T_>& params_r, std::vector<int>& params_i,
           std::ostream* pstream = nullptr) const {
    return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
  }
  inline void
  transform_inits(const stan::io::var_context& context,
                  Eigen::Matrix<double,-1,1>& params_r, std::ostream*
                  pstream = nullptr) const final {
    std::vector<double> params_r_vec(params_r.size());
    std::vector<int> params_i;
    transform_inits(context, params_i, params_r_vec, pstream);
    params_r = Eigen::Map<Eigen::Matrix<double,-1,1>>(params_r_vec.data(),
                 params_r_vec.size());
  }
  inline void
  transform_inits(const stan::io::var_context& context, std::vector<int>&
                  params_i, std::vector<double>& vars, std::ostream*
                  pstream__ = nullptr) const {
    vars.resize(num_params_r__);
    transform_inits_impl(context, vars, pstream__);
  }
  inline void
  unconstrain_array(const std::vector<double>& params_constrained,
                    std::vector<double>& params_unconstrained, std::ostream*
                    pstream = nullptr) const {
    const std::vector<int> params_i;
    params_unconstrained = std::vector<double>(num_params_r__,
                             std::numeric_limits<double>::quiet_NaN());
    unconstrain_array_impl(params_constrained, params_i,
      params_unconstrained, pstream);
  }
  inline void
  unconstrain_array(const Eigen::Matrix<double,-1,1>& params_constrained,
                    Eigen::Matrix<double,-1,1>& params_unconstrained,
                    std::ostream* pstream = nullptr) const {
    const std::vector<int> params_i;
    params_unconstrained = Eigen::Matrix<double,-1,1>::Constant(num_params_r__,
                             std::numeric_limits<double>::quiet_NaN());
    unconstrain_array_impl(params_constrained, params_i,
      params_unconstrained, pstream);
  }
};
}
using stan_model = model_TIRT_namespace::model_TIRT;
#ifndef USING_R
// Boilerplate
stan::model::model_base&
new_model(stan::io::var_context& data_context, unsigned int seed,
          std::ostream* msg_stream) {
  stan_model* m = new stan_model(data_context, seed, msg_stream);
  return *m;
}
stan::math::profile_map& get_stan_profile_data() {
  return model_TIRT_namespace::profiles__;
}
#endif
#endif
