From 87de4bbee820fda41e1f8e6d61efd273ae6f5953 Mon Sep 17 00:00:00 2001 From: Abby Date: Fri, 29 Mar 2024 18:22:46 -0700 Subject: [PATCH] added github workflows --- .Rhistory | 3 + .github/workflows/R-CMD-check.yaml | 49 + .github/workflows/test-coverage.yaml | 50 + src/Makevars.win | 10 + src/RcppExports.cpp | 118 +- ...nExports_joint_binary_catchability_gamma.h | 2118 +++++++-------- ...Exports_joint_binary_catchability_negbin.h | 1926 +++++++------- ...anExports_joint_binary_catchability_pois.h | 1844 ++++++------- ...orts_joint_binary_cov_catchability_gamma.h | 2348 ++++++++--------- ...rts_joint_binary_cov_catchability_negbin.h | 2156 +++++++-------- ...ports_joint_binary_cov_catchability_pois.h | 2074 +++++++-------- src/stanExports_joint_binary_cov_gamma.h | 1920 +++++++------- src/stanExports_joint_binary_cov_negbin.h | 1722 ++++++------ src/stanExports_joint_binary_cov_pois.h | 1644 ++++++------ src/stanExports_joint_binary_gamma.h | 1694 ++++++------ src/stanExports_joint_binary_negbin.h | 1498 +++++------ src/stanExports_joint_binary_pois.h | 1418 +++++----- ...anExports_traditional_catchability_gamma.h | 1564 +++++------ ...nExports_traditional_catchability_negbin.h | 1436 +++++----- ...tanExports_traditional_catchability_pois.h | 1356 +++++----- src/stanExports_traditional_gamma.h | 1168 ++++---- src/stanExports_traditional_negbin.h | 976 +++---- src/stanExports_traditional_pois.h | 896 +++---- 23 files changed, 15050 insertions(+), 14938 deletions(-) create mode 100644 .github/workflows/R-CMD-check.yaml create mode 100644 .github/workflows/test-coverage.yaml create mode 100644 src/Makevars.win diff --git a/.Rhistory b/.Rhistory index b9c6f05..e8007bc 100644 --- a/.Rhistory +++ b/.Rhistory @@ -1 +1,4 @@ roxygen2::roxygenise() +install.packages("codemetar") +codemetar::write_codemeta() +codemetar::give_opinions('C:\\Users\\abiga\\Documents\\WSG\\eDNAjoint') diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..a3ac618 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,49 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: macos-latest, r: 'release'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..21b8a93 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,50 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: test-coverage + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr + needs: coverage + + - name: Test coverage + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") + ) + shell: Rscript {0} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/src/Makevars.win b/src/Makevars.win new file mode 100644 index 0000000..8be992a --- /dev/null +++ b/src/Makevars.win @@ -0,0 +1,10 @@ +# Generated by rstantools. Do not edit by hand. + +STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "message()" -e "cat(system.file('include', 'src', package = 'StanHeaders', mustWork = TRUE))" -e "message()" | grep "StanHeaders") + +STANC_FLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "cat(ifelse(utils::packageVersion('rstan') >= '2.26', '-DUSE_STANC3',''))") +PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DRCPP_PARALLEL_USE_TBB=1 $(STANC_FLAGS) -D_HAS_AUTO_PTR_ETC=0 +PKG_CXXFLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::CxxFlags()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::CxxFlags()") +PKG_LIBS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::RcppParallelLibs()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::LdFlags()") + +CXX_STD = CXX17 diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 4fcd9d2..14491ef 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -1,59 +1,59 @@ -// Generated by using Rcpp::compileAttributes() -> do not edit by hand -// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 - -#include -#include - -using namespace Rcpp; - -#ifdef RCPP_USE_GLOBAL_ROSTREAM -Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); -Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); -#endif - - -RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_catchability_gamma_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_catchability_negbin_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_catchability_pois_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_cov_catchability_gamma_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_cov_catchability_negbin_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_cov_catchability_pois_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_cov_gamma_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_cov_negbin_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_cov_pois_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_gamma_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_negbin_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_pois_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4traditional_catchability_gamma_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4traditional_catchability_negbin_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4traditional_catchability_pois_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4traditional_gamma_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4traditional_negbin_mod(); -RcppExport SEXP _rcpp_module_boot_stan_fit4traditional_pois_mod(); - -static const R_CallMethodDef CallEntries[] = { - {"_rcpp_module_boot_stan_fit4joint_binary_catchability_gamma_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_catchability_gamma_mod, 0}, - {"_rcpp_module_boot_stan_fit4joint_binary_catchability_negbin_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_catchability_negbin_mod, 0}, - {"_rcpp_module_boot_stan_fit4joint_binary_catchability_pois_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_catchability_pois_mod, 0}, - {"_rcpp_module_boot_stan_fit4joint_binary_cov_catchability_gamma_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_cov_catchability_gamma_mod, 0}, - {"_rcpp_module_boot_stan_fit4joint_binary_cov_catchability_negbin_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_cov_catchability_negbin_mod, 0}, - {"_rcpp_module_boot_stan_fit4joint_binary_cov_catchability_pois_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_cov_catchability_pois_mod, 0}, - {"_rcpp_module_boot_stan_fit4joint_binary_cov_gamma_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_cov_gamma_mod, 0}, - {"_rcpp_module_boot_stan_fit4joint_binary_cov_negbin_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_cov_negbin_mod, 0}, - {"_rcpp_module_boot_stan_fit4joint_binary_cov_pois_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_cov_pois_mod, 0}, - {"_rcpp_module_boot_stan_fit4joint_binary_gamma_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_gamma_mod, 0}, - {"_rcpp_module_boot_stan_fit4joint_binary_negbin_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_negbin_mod, 0}, - {"_rcpp_module_boot_stan_fit4joint_binary_pois_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_pois_mod, 0}, - {"_rcpp_module_boot_stan_fit4traditional_catchability_gamma_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4traditional_catchability_gamma_mod, 0}, - {"_rcpp_module_boot_stan_fit4traditional_catchability_negbin_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4traditional_catchability_negbin_mod, 0}, - {"_rcpp_module_boot_stan_fit4traditional_catchability_pois_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4traditional_catchability_pois_mod, 0}, - {"_rcpp_module_boot_stan_fit4traditional_gamma_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4traditional_gamma_mod, 0}, - {"_rcpp_module_boot_stan_fit4traditional_negbin_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4traditional_negbin_mod, 0}, - {"_rcpp_module_boot_stan_fit4traditional_pois_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4traditional_pois_mod, 0}, - {NULL, NULL, 0} -}; - -RcppExport void R_init_eDNAjoint(DllInfo *dll) { - R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); - R_useDynamicSymbols(dll, FALSE); -} +// Generated by using Rcpp::compileAttributes() -> do not edit by hand +// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 + +#include +#include + +using namespace Rcpp; + +#ifdef RCPP_USE_GLOBAL_ROSTREAM +Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); +Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); +#endif + + +RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_catchability_gamma_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_catchability_negbin_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_catchability_pois_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_cov_catchability_gamma_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_cov_catchability_negbin_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_cov_catchability_pois_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_cov_gamma_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_cov_negbin_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_cov_pois_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_gamma_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_negbin_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4joint_binary_pois_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4traditional_catchability_gamma_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4traditional_catchability_negbin_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4traditional_catchability_pois_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4traditional_gamma_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4traditional_negbin_mod(); +RcppExport SEXP _rcpp_module_boot_stan_fit4traditional_pois_mod(); + +static const R_CallMethodDef CallEntries[] = { + {"_rcpp_module_boot_stan_fit4joint_binary_catchability_gamma_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_catchability_gamma_mod, 0}, + {"_rcpp_module_boot_stan_fit4joint_binary_catchability_negbin_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_catchability_negbin_mod, 0}, + {"_rcpp_module_boot_stan_fit4joint_binary_catchability_pois_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_catchability_pois_mod, 0}, + {"_rcpp_module_boot_stan_fit4joint_binary_cov_catchability_gamma_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_cov_catchability_gamma_mod, 0}, + {"_rcpp_module_boot_stan_fit4joint_binary_cov_catchability_negbin_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_cov_catchability_negbin_mod, 0}, + {"_rcpp_module_boot_stan_fit4joint_binary_cov_catchability_pois_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_cov_catchability_pois_mod, 0}, + {"_rcpp_module_boot_stan_fit4joint_binary_cov_gamma_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_cov_gamma_mod, 0}, + {"_rcpp_module_boot_stan_fit4joint_binary_cov_negbin_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_cov_negbin_mod, 0}, + {"_rcpp_module_boot_stan_fit4joint_binary_cov_pois_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_cov_pois_mod, 0}, + {"_rcpp_module_boot_stan_fit4joint_binary_gamma_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_gamma_mod, 0}, + {"_rcpp_module_boot_stan_fit4joint_binary_negbin_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_negbin_mod, 0}, + {"_rcpp_module_boot_stan_fit4joint_binary_pois_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4joint_binary_pois_mod, 0}, + {"_rcpp_module_boot_stan_fit4traditional_catchability_gamma_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4traditional_catchability_gamma_mod, 0}, + {"_rcpp_module_boot_stan_fit4traditional_catchability_negbin_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4traditional_catchability_negbin_mod, 0}, + {"_rcpp_module_boot_stan_fit4traditional_catchability_pois_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4traditional_catchability_pois_mod, 0}, + {"_rcpp_module_boot_stan_fit4traditional_gamma_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4traditional_gamma_mod, 0}, + {"_rcpp_module_boot_stan_fit4traditional_negbin_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4traditional_negbin_mod, 0}, + {"_rcpp_module_boot_stan_fit4traditional_pois_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4traditional_pois_mod, 0}, + {NULL, NULL, 0} +}; + +RcppExport void R_init_eDNAjoint(DllInfo *dll) { + R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); + R_useDynamicSymbols(dll, FALSE); +} diff --git a/src/stanExports_joint_binary_catchability_gamma.h b/src/stanExports_joint_binary_catchability_gamma.h index f2f28c2..74a9890 100644 --- a/src/stanExports_joint_binary_catchability_gamma.h +++ b/src/stanExports_joint_binary_catchability_gamma.h @@ -1,1059 +1,1059 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_joint_binary_catchability_gamma_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'joint_binary_catchability_gamma', line 15, column 4 to column 42)", - " (in 'joint_binary_catchability_gamma', line 16, column 4 to column 45)", - " (in 'joint_binary_catchability_gamma', line 17, column 4 to column 14)", - " (in 'joint_binary_catchability_gamma', line 18, column 4 to column 26)", - " (in 'joint_binary_catchability_gamma', line 19, column 4 to column 44)", - " (in 'joint_binary_catchability_gamma', line 22, column 2 to column 43)", - " (in 'joint_binary_catchability_gamma', line 23, column 2 to column 40)", - " (in 'joint_binary_catchability_gamma', line 24, column 2 to column 26)", - " (in 'joint_binary_catchability_gamma', line 25, column 2 to column 33)", - " (in 'joint_binary_catchability_gamma', line 26, column 2 to column 33)", - " (in 'joint_binary_catchability_gamma', line 53, column 2 to column 20)", - " (in 'joint_binary_catchability_gamma', line 54, column 2 to column 22)", - " (in 'joint_binary_catchability_gamma', line 55, column 2 to column 28)", - " (in 'joint_binary_catchability_gamma', line 56, column 2 to column 11)", - " (in 'joint_binary_catchability_gamma', line 28, column 4 to column 43)", - " (in 'joint_binary_catchability_gamma', line 29, column 4 to column 45)", - " (in 'joint_binary_catchability_gamma', line 30, column 4 to column 33)", - " (in 'joint_binary_catchability_gamma', line 27, column 19 to line 31, column 3)", - " (in 'joint_binary_catchability_gamma', line 27, column 2 to line 31, column 3)", - " (in 'joint_binary_catchability_gamma', line 33, column 6 to column 48)", - " (in 'joint_binary_catchability_gamma', line 32, column 15 to line 34, column 5)", - " (in 'joint_binary_catchability_gamma', line 32, column 2 to line 34, column 5)", - " (in 'joint_binary_catchability_gamma', line 36, column 6 to column 42)", - " (in 'joint_binary_catchability_gamma', line 35, column 17 to line 37, column 5)", - " (in 'joint_binary_catchability_gamma', line 35, column 4 to line 37, column 5)", - " (in 'joint_binary_catchability_gamma', line 57, column 2 to column 21)", - " (in 'joint_binary_catchability_gamma', line 58, column 2 to column 18)", - " (in 'joint_binary_catchability_gamma', line 59, column 2 to column 27)", - " (in 'joint_binary_catchability_gamma', line 61, column 4 to column 36)", - " (in 'joint_binary_catchability_gamma', line 60, column 21 to line 62, column 3)", - " (in 'joint_binary_catchability_gamma', line 60, column 2 to line 62, column 3)", - " (in 'joint_binary_catchability_gamma', line 64, column 10 to column 92)", - " (in 'joint_binary_catchability_gamma', line 63, column 17 to line 65, column 7)", - " (in 'joint_binary_catchability_gamma', line 63, column 4 to line 65, column 7)", - " (in 'joint_binary_catchability_gamma', line 67, column 10 to column 61)", - " (in 'joint_binary_catchability_gamma', line 66, column 19 to line 68, column 7)", - " (in 'joint_binary_catchability_gamma', line 66, column 6 to line 68, column 7)", - " (in 'joint_binary_catchability_gamma', line 41, column 8 to column 71)", - " (in 'joint_binary_catchability_gamma', line 40, column 18 to line 42, column 5)", - " (in 'joint_binary_catchability_gamma', line 40, column 4 to line 42, column 5)", - " (in 'joint_binary_catchability_gamma', line 44, column 8 to column 39)", - " (in 'joint_binary_catchability_gamma', line 43, column 18 to line 45, column 5)", - " (in 'joint_binary_catchability_gamma', line 43, column 4 to line 45, column 5)", - " (in 'joint_binary_catchability_gamma', line 47, column 2 to column 47)", - " (in 'joint_binary_catchability_gamma', line 48, column 2 to column 22)", - " (in 'joint_binary_catchability_gamma', line 49, column 2 to column 32)", - " (in 'joint_binary_catchability_gamma', line 50, column 2 to column 33)", - " (in 'joint_binary_catchability_gamma', line 2, column 4 to column 19)", - " (in 'joint_binary_catchability_gamma', line 3, column 4 to column 19)", - " (in 'joint_binary_catchability_gamma', line 4, column 10 to column 11)", - " (in 'joint_binary_catchability_gamma', line 4, column 4 to column 28)", - " (in 'joint_binary_catchability_gamma', line 5, column 10 to column 11)", - " (in 'joint_binary_catchability_gamma', line 5, column 4 to column 28)", - " (in 'joint_binary_catchability_gamma', line 6, column 4 to column 22)", - " (in 'joint_binary_catchability_gamma', line 7, column 10 to column 11)", - " (in 'joint_binary_catchability_gamma', line 7, column 4 to column 29)", - " (in 'joint_binary_catchability_gamma', line 8, column 10 to column 11)", - " (in 'joint_binary_catchability_gamma', line 8, column 4 to column 28)", - " (in 'joint_binary_catchability_gamma', line 9, column 10 to column 11)", - " (in 'joint_binary_catchability_gamma', line 9, column 4 to column 28)", - " (in 'joint_binary_catchability_gamma', line 10, column 4 to column 28)", - " (in 'joint_binary_catchability_gamma', line 11, column 4 to column 25)", - " (in 'joint_binary_catchability_gamma', line 12, column 11 to column 12)", - " (in 'joint_binary_catchability_gamma', line 12, column 13 to column 20)", - " (in 'joint_binary_catchability_gamma', line 12, column 4 to column 26)", - " (in 'joint_binary_catchability_gamma', line 15, column 10 to column 14)", - " (in 'joint_binary_catchability_gamma', line 16, column 10 to column 14)", - " (in 'joint_binary_catchability_gamma', line 19, column 27 to column 34)", - " (in 'joint_binary_catchability_gamma', line 22, column 8 to column 12)", - " (in 'joint_binary_catchability_gamma', line 23, column 8 to column 12)", - " (in 'joint_binary_catchability_gamma', line 24, column 18 to column 19)", - " (in 'joint_binary_catchability_gamma', line 25, column 8 to column 12)", - " (in 'joint_binary_catchability_gamma', line 26, column 8 to column 9)", - " (in 'joint_binary_catchability_gamma', line 53, column 9 to column 16)", - " (in 'joint_binary_catchability_gamma', line 54, column 9 to column 12)", - " (in 'joint_binary_catchability_gamma', line 55, column 9 to column 13)", - " (in 'joint_binary_catchability_gamma', line 55, column 14 to column 23)"}; -#include -class model_joint_binary_catchability_gamma final : public model_base_crtp { -private: - int S; - int C; - std::vector L; - std::vector R; - int Nloc; - std::vector E; - std::vector N; - std::vector K; - std::vector p10priors; - int nparams; - Eigen::Matrix mat_data__; - int log_lik_1dim__; - int mu_2dim__; - Eigen::Map> mat{nullptr, 0, 0}; -public: - ~model_joint_binary_catchability_gamma() {} - model_joint_binary_catchability_gamma(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_joint_binary_catchability_gamma_namespace::model_joint_binary_catchability_gamma"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 48; - context__.validate_dims("data initialization", "S", "int", - std::vector{}); - S = std::numeric_limits::min(); - current_statement__ = 48; - S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 48; - stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 49; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 49; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 49; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 50; - stan::math::validate_non_negative_index("L", "S", S); - current_statement__ = 51; - context__.validate_dims("data initialization", "L", "int", - std::vector{static_cast(S)}); - L = std::vector(S, std::numeric_limits::min()); - current_statement__ = 51; - L = context__.vals_i("L"); - current_statement__ = 51; - stan::math::check_greater_or_equal(function__, "L", L, 1); - current_statement__ = 52; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 53; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 53; - R = context__.vals_i("R"); - current_statement__ = 53; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 54; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 54; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 54; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 55; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 56; - context__.validate_dims("data initialization", "E", "double", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::quiet_NaN()); - current_statement__ = 56; - E = context__.vals_r("E"); - current_statement__ = 56; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 57; - stan::math::validate_non_negative_index("N", "S", S); - current_statement__ = 58; - context__.validate_dims("data initialization", "N", "int", - std::vector{static_cast(S)}); - N = std::vector(S, std::numeric_limits::min()); - current_statement__ = 58; - N = context__.vals_i("N"); - current_statement__ = 58; - stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 59; - stan::math::validate_non_negative_index("K", "S", S); - current_statement__ = 60; - context__.validate_dims("data initialization", "K", "int", - std::vector{static_cast(S)}); - K = std::vector(S, std::numeric_limits::min()); - current_statement__ = 60; - K = context__.vals_i("K"); - current_statement__ = 60; - stan::math::check_greater_or_equal(function__, "K", K, 0); - current_statement__ = 61; - context__.validate_dims("data initialization", "p10priors", "double", - std::vector{static_cast(2)}); - p10priors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 61; - p10priors = context__.vals_r("p10priors"); - current_statement__ = 62; - context__.validate_dims("data initialization", "nparams", "int", - std::vector{}); - nparams = std::numeric_limits::min(); - current_statement__ = 62; - nparams = context__.vals_i("nparams")[(1 - 1)]; - current_statement__ = 62; - stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); - current_statement__ = 63; - stan::math::validate_non_negative_index("mat", "C", C); - current_statement__ = 64; - stan::math::validate_non_negative_index("mat", "nparams", nparams); - current_statement__ = 65; - context__.validate_dims("data initialization", "mat", "double", - std::vector{static_cast(C), - static_cast(nparams)}); - mat_data__ = Eigen::Matrix::Constant(C, nparams, - std::numeric_limits::quiet_NaN()); - new (&mat) Eigen::Map>(mat_data__.data(), - C, nparams); - { - std::vector mat_flat__; - current_statement__ = 65; - mat_flat__ = context__.vals_r("mat"); - current_statement__ = 65; - pos__ = 1; - current_statement__ = 65; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 65; - for (int sym2__ = 1; sym2__ <= C; ++sym2__) { - current_statement__ = 65; - stan::model::assign(mat, mat_flat__[(pos__ - 1)], - "assigning variable mat", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 65; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 66; - stan::math::validate_non_negative_index("alpha_gamma", "Nloc", Nloc); - current_statement__ = 67; - stan::math::validate_non_negative_index("beta_gamma", "Nloc", Nloc); - current_statement__ = 68; - stan::math::validate_non_negative_index("q_trans", "nparams", nparams); - current_statement__ = 69; - stan::math::validate_non_negative_index("p11", "Nloc", Nloc); - current_statement__ = 70; - stan::math::validate_non_negative_index("p", "Nloc", Nloc); - current_statement__ = 71; - stan::math::validate_non_negative_index("coef", "C", C); - current_statement__ = 72; - stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); - current_statement__ = 73; - stan::math::validate_non_negative_index("E_trans", "C", C); - current_statement__ = 74; - stan::math::validate_non_negative_index("q", "nparams", nparams); - current_statement__ = 75; - log_lik_1dim__ = std::numeric_limits::min(); - current_statement__ = 75; - log_lik_1dim__ = (C + S); - current_statement__ = 75; - stan::math::validate_non_negative_index("log_lik", "C + S", - log_lik_1dim__); - current_statement__ = 76; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 77; - mu_2dim__ = std::numeric_limits::min(); - current_statement__ = 77; - mu_2dim__ = (nparams + 1); - current_statement__ = 77; - stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + Nloc + 1 + 1 + nparams; - } - inline std::string model_name() const final { - return "model_joint_binary_catchability_gamma"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_joint_binary_catchability_gamma_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector alpha_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - alpha_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0, lp__, - Nloc); - std::vector beta_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - beta_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0.01, lp__, - Nloc); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 3; - beta = in__.template read(); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 4; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 5; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - std::vector p11 = - std::vector(Nloc, DUMMY_VAR__); - std::vector p = - std::vector(Nloc, DUMMY_VAR__); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, DUMMY_VAR__); - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - std::vector E_trans = - std::vector(C, DUMMY_VAR__); - current_statement__ = 19; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 15; - stan::model::assign(mu_1, - (stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni(i)) / - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni(i))), "assigning variable mu_1", - stan::model::index_uni(i)); - current_statement__ = 16; - stan::model::assign(p11, - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + - stan::math::exp(beta))), "assigning variable p11", - stan::model::index_uni(i)); - current_statement__ = 17; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 22; - for (int k = 1; k <= C; ++k) { - current_statement__ = 20; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), - q_trans)), "assigning variable coef", stan::model::index_uni(k)); - } - current_statement__ = 25; - for (int j = 1; j <= C; ++j) { - current_statement__ = 23; - stan::model::assign(E_trans, - (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + - 0.0000000000001), "assigning variable E_trans", - stan::model::index_uni(j)); - } - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 7; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 8; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - current_statement__ = 9; - stan::math::check_greater_or_equal(function__, "mu_1", mu_1, 0); - current_statement__ = 10; - stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); - { - current_statement__ = 40; - for (int j = 1; j <= C; ++j) { - current_statement__ = 38; - lp_accum__.add(stan::math::gamma_lpdf( - stan::model::rvalue(E_trans, "E_trans", - stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", - stan::model::index_uni(j)) * - stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j))))), - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))))); - } - current_statement__ = 43; - for (int i = 1; i <= S; ++i) { - current_statement__ = 41; - lp_accum__.add(stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", - stan::model::index_uni(i)), - stan::model::rvalue(N, "N", - stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", - stan::model::index_uni(i)))))); - } - current_statement__ = 44; - lp_accum__.add(stan::math::normal_lpdf(log_p10, - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(1)), - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(2)))); - current_statement__ = 45; - lp_accum__.add(stan::math::normal_lpdf(beta, 0, 10)); - current_statement__ = 46; - lp_accum__.add(stan::math::gamma_lpdf(beta_gamma, 0.25, - 0.25)); - current_statement__ = 47; - lp_accum__.add(stan::math::gamma_lpdf(alpha_gamma, 0.01, - 0.01)); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_joint_binary_catchability_gamma_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector alpha_gamma = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - alpha_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0, lp__, - Nloc); - std::vector beta_gamma = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 2; - beta_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0.01, lp__, - Nloc); - double beta = std::numeric_limits::quiet_NaN(); - current_statement__ = 3; - beta = in__.template read(); - double log_p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 4; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - current_statement__ = 5; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - std::vector p11 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector p = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - std::vector mu_1 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector E_trans = - std::vector(C, std::numeric_limits::quiet_NaN()); - out__.write(alpha_gamma); - out__.write(beta_gamma); - out__.write(beta); - out__.write(log_p10); - out__.write(q_trans); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 19; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 15; - stan::model::assign(mu_1, - (stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni(i)) / - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni(i))), "assigning variable mu_1", - stan::model::index_uni(i)); - current_statement__ = 16; - stan::model::assign(p11, - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + - stan::math::exp(beta))), "assigning variable p11", - stan::model::index_uni(i)); - current_statement__ = 17; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 22; - for (int k = 1; k <= C; ++k) { - current_statement__ = 20; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), - q_trans)), "assigning variable coef", stan::model::index_uni(k)); - } - current_statement__ = 25; - for (int j = 1; j <= C; ++j) { - current_statement__ = 23; - stan::model::assign(E_trans, - (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + - 0.0000000000001), "assigning variable E_trans", - stan::model::index_uni(j)); - } - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 7; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 8; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - current_statement__ = 9; - stan::math::check_greater_or_equal(function__, "mu_1", mu_1, 0); - current_statement__ = 10; - stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); - if (emit_transformed_parameters__) { - out__.write(p11); - out__.write(p); - out__.write(coef); - out__.write(mu_1); - out__.write(E_trans); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix q = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(log_lik_1dim__, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix mu = - Eigen::Matrix::Constant(Nloc, mu_2dim__, - std::numeric_limits::quiet_NaN()); - double p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 26; - p10 = stan::math::exp(log_p10); - current_statement__ = 27; - stan::model::assign(q, stan::math::add(q_trans, 1), - "assigning variable q"); - current_statement__ = 28; - stan::model::assign(mu, stan::math::to_vector(mu_1), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni(1)); - current_statement__ = 31; - for (int i = 1; i <= nparams; ++i) { - current_statement__ = 29; - stan::model::assign(mu, - stan::math::multiply(stan::math::to_vector(mu_1), - stan::model::rvalue(q, "q", stan::model::index_uni(i))), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni((i + 1))); - } - current_statement__ = 34; - for (int j = 1; j <= C; ++j) { - current_statement__ = 32; - stan::model::assign(log_lik, - stan::math::gamma_lpdf( - stan::model::rvalue(E_trans, "E_trans", stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * - stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - "assigning variable log_lik", stan::model::index_uni(j)); - } - current_statement__ = 37; - for (int i = 1; i <= S; ++i) { - current_statement__ = 35; - stan::model::assign(log_lik, - stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", stan::model::index_uni(i)), - stan::model::rvalue(N, "N", stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", stan::model::index_uni(i))))), - "assigning variable log_lik", stan::model::index_uni((C + i))); - } - out__.write(q); - out__.write(log_lik); - out__.write(mu); - out__.write(p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector alpha_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(alpha_gamma, - in__.read>(Nloc), - "assigning variable alpha_gamma"); - out__.write_free_lb(0, alpha_gamma); - std::vector beta_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - stan::model::assign(beta_gamma, - in__.read>(Nloc), - "assigning variable beta_gamma"); - out__.write_free_lb(0.01, beta_gamma); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 3; - beta = in__.read(); - out__.write(beta); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 4; - log_p10 = in__.read(); - out__.write_free_ub(0, log_p10); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 5; - stan::model::assign(q_trans, - in__.read>(nparams), - "assigning variable q_trans"); - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "alpha_gamma", - "double", std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "beta_gamma", - "double", std::vector{static_cast(Nloc)}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "beta", "double", - std::vector{}); - current_statement__ = 4; - context__.validate_dims("parameter initialization", "log_p10", - "double", std::vector{}); - current_statement__ = 5; - context__.validate_dims("parameter initialization", "q_trans", - "double", std::vector{static_cast(nparams)}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector alpha_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - alpha_gamma = context__.vals_r("alpha_gamma"); - out__.write_free_lb(0, alpha_gamma); - std::vector beta_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - beta_gamma = context__.vals_r("beta_gamma"); - out__.write_free_lb(0.01, beta_gamma); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 3; - beta = context__.vals_r("beta")[(1 - 1)]; - out__.write(beta); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 4; - log_p10 = context__.vals_r("log_p10")[(1 - 1)]; - out__.write_free_ub(0, log_p10); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - { - std::vector q_trans_flat__; - current_statement__ = 5; - q_trans_flat__ = context__.vals_r("q_trans"); - current_statement__ = 5; - pos__ = 1; - current_statement__ = 5; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 5; - stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], - "assigning variable q_trans", stan::model::index_uni(sym1__)); - current_statement__ = 5; - pos__ = (pos__ + 1); - } - } - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"alpha_gamma", "beta_gamma", "beta", - "log_p10", "q_trans"}; - if (emit_transformed_parameters__) { - std::vector temp{"p11", "p", "coef", "mu_1", "E_trans"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"q", "log_lik", "mu", "p10"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{}, std::vector{}, - std::vector{static_cast(nparams)}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(C)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(C)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(nparams)}, - std::vector{static_cast(log_lik_1dim__)}, - std::vector{static_cast(Nloc), - static_cast(mu_2dim__)}, std::vector{}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta_gamma" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "beta"); - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "E_trans" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta_gamma" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "beta"); - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "E_trans" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((((Nloc + Nloc) + 1) + 1) + nparams); - const size_t num_transformed = emit_transformed_parameters * (((((Nloc + - Nloc) + C) + Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * ((((nparams - + log_lik_1dim__) + (Nloc * mu_2dim__)) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((((Nloc + Nloc) + 1) + 1) + nparams); - const size_t num_transformed = emit_transformed_parameters * (((((Nloc + - Nloc) + C) + Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * ((((nparams - + log_lik_1dim__) + (Nloc * mu_2dim__)) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_joint_binary_catchability_gamma_namespace::model_joint_binary_catchability_gamma; -#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_joint_binary_catchability_gamma_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_joint_binary_catchability_gamma_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 15, column 4 to column 42)", + " (in 'string', line 16, column 4 to column 45)", + " (in 'string', line 17, column 4 to column 14)", + " (in 'string', line 18, column 4 to column 26)", + " (in 'string', line 19, column 4 to column 44)", + " (in 'string', line 22, column 2 to column 43)", + " (in 'string', line 23, column 2 to column 40)", + " (in 'string', line 24, column 2 to column 26)", + " (in 'string', line 25, column 2 to column 33)", + " (in 'string', line 26, column 2 to column 33)", + " (in 'string', line 53, column 2 to column 20)", + " (in 'string', line 54, column 2 to column 22)", + " (in 'string', line 55, column 2 to column 28)", + " (in 'string', line 56, column 2 to column 11)", + " (in 'string', line 28, column 4 to column 43)", + " (in 'string', line 29, column 4 to column 45)", + " (in 'string', line 30, column 4 to column 33)", + " (in 'string', line 27, column 19 to line 31, column 3)", + " (in 'string', line 27, column 2 to line 31, column 3)", + " (in 'string', line 33, column 6 to column 48)", + " (in 'string', line 32, column 15 to line 34, column 5)", + " (in 'string', line 32, column 2 to line 34, column 5)", + " (in 'string', line 36, column 6 to column 42)", + " (in 'string', line 35, column 17 to line 37, column 5)", + " (in 'string', line 35, column 4 to line 37, column 5)", + " (in 'string', line 57, column 2 to column 21)", + " (in 'string', line 58, column 2 to column 18)", + " (in 'string', line 59, column 2 to column 27)", + " (in 'string', line 61, column 4 to column 36)", + " (in 'string', line 60, column 21 to line 62, column 3)", + " (in 'string', line 60, column 2 to line 62, column 3)", + " (in 'string', line 64, column 10 to column 92)", + " (in 'string', line 63, column 17 to line 65, column 7)", + " (in 'string', line 63, column 4 to line 65, column 7)", + " (in 'string', line 67, column 10 to column 61)", + " (in 'string', line 66, column 19 to line 68, column 7)", + " (in 'string', line 66, column 6 to line 68, column 7)", + " (in 'string', line 41, column 8 to column 71)", + " (in 'string', line 40, column 18 to line 42, column 5)", + " (in 'string', line 40, column 4 to line 42, column 5)", + " (in 'string', line 44, column 8 to column 39)", + " (in 'string', line 43, column 18 to line 45, column 5)", + " (in 'string', line 43, column 4 to line 45, column 5)", + " (in 'string', line 47, column 2 to column 47)", + " (in 'string', line 48, column 2 to column 22)", + " (in 'string', line 49, column 2 to column 32)", + " (in 'string', line 50, column 2 to column 33)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 4 to column 19)", + " (in 'string', line 4, column 10 to column 11)", + " (in 'string', line 4, column 4 to column 28)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 22)", + " (in 'string', line 7, column 10 to column 11)", + " (in 'string', line 7, column 4 to column 29)", + " (in 'string', line 8, column 10 to column 11)", + " (in 'string', line 8, column 4 to column 28)", + " (in 'string', line 9, column 10 to column 11)", + " (in 'string', line 9, column 4 to column 28)", + " (in 'string', line 10, column 4 to column 28)", + " (in 'string', line 11, column 4 to column 25)", + " (in 'string', line 12, column 11 to column 12)", + " (in 'string', line 12, column 13 to column 20)", + " (in 'string', line 12, column 4 to column 26)", + " (in 'string', line 15, column 10 to column 14)", + " (in 'string', line 16, column 10 to column 14)", + " (in 'string', line 19, column 27 to column 34)", + " (in 'string', line 22, column 8 to column 12)", + " (in 'string', line 23, column 8 to column 12)", + " (in 'string', line 24, column 18 to column 19)", + " (in 'string', line 25, column 8 to column 12)", + " (in 'string', line 26, column 8 to column 9)", + " (in 'string', line 53, column 9 to column 16)", + " (in 'string', line 54, column 9 to column 12)", + " (in 'string', line 55, column 9 to column 13)", + " (in 'string', line 55, column 14 to column 23)"}; +#include +class model_joint_binary_catchability_gamma final : public model_base_crtp { +private: + int S; + int C; + std::vector L; + std::vector R; + int Nloc; + std::vector E; + std::vector N; + std::vector K; + std::vector p10priors; + int nparams; + Eigen::Matrix mat_data__; + int log_lik_1dim__; + int mu_2dim__; + Eigen::Map> mat{nullptr, 0, 0}; +public: + ~model_joint_binary_catchability_gamma() {} + model_joint_binary_catchability_gamma(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_joint_binary_catchability_gamma_namespace::model_joint_binary_catchability_gamma"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 48; + context__.validate_dims("data initialization", "S", "int", + std::vector{}); + S = std::numeric_limits::min(); + current_statement__ = 48; + S = context__.vals_i("S")[(1 - 1)]; + current_statement__ = 48; + stan::math::check_greater_or_equal(function__, "S", S, 1); + current_statement__ = 49; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 49; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 49; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 50; + stan::math::validate_non_negative_index("L", "S", S); + current_statement__ = 51; + context__.validate_dims("data initialization", "L", "int", + std::vector{static_cast(S)}); + L = std::vector(S, std::numeric_limits::min()); + current_statement__ = 51; + L = context__.vals_i("L"); + current_statement__ = 51; + stan::math::check_greater_or_equal(function__, "L", L, 1); + current_statement__ = 52; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 53; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 53; + R = context__.vals_i("R"); + current_statement__ = 53; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 54; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 54; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 54; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 55; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 56; + context__.validate_dims("data initialization", "E", "double", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::quiet_NaN()); + current_statement__ = 56; + E = context__.vals_r("E"); + current_statement__ = 56; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 57; + stan::math::validate_non_negative_index("N", "S", S); + current_statement__ = 58; + context__.validate_dims("data initialization", "N", "int", + std::vector{static_cast(S)}); + N = std::vector(S, std::numeric_limits::min()); + current_statement__ = 58; + N = context__.vals_i("N"); + current_statement__ = 58; + stan::math::check_greater_or_equal(function__, "N", N, 1); + current_statement__ = 59; + stan::math::validate_non_negative_index("K", "S", S); + current_statement__ = 60; + context__.validate_dims("data initialization", "K", "int", + std::vector{static_cast(S)}); + K = std::vector(S, std::numeric_limits::min()); + current_statement__ = 60; + K = context__.vals_i("K"); + current_statement__ = 60; + stan::math::check_greater_or_equal(function__, "K", K, 0); + current_statement__ = 61; + context__.validate_dims("data initialization", "p10priors", "double", + std::vector{static_cast(2)}); + p10priors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 61; + p10priors = context__.vals_r("p10priors"); + current_statement__ = 62; + context__.validate_dims("data initialization", "nparams", "int", + std::vector{}); + nparams = std::numeric_limits::min(); + current_statement__ = 62; + nparams = context__.vals_i("nparams")[(1 - 1)]; + current_statement__ = 62; + stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); + current_statement__ = 63; + stan::math::validate_non_negative_index("mat", "C", C); + current_statement__ = 64; + stan::math::validate_non_negative_index("mat", "nparams", nparams); + current_statement__ = 65; + context__.validate_dims("data initialization", "mat", "double", + std::vector{static_cast(C), + static_cast(nparams)}); + mat_data__ = Eigen::Matrix::Constant(C, nparams, + std::numeric_limits::quiet_NaN()); + new (&mat) Eigen::Map>(mat_data__.data(), + C, nparams); + { + std::vector mat_flat__; + current_statement__ = 65; + mat_flat__ = context__.vals_r("mat"); + current_statement__ = 65; + pos__ = 1; + current_statement__ = 65; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 65; + for (int sym2__ = 1; sym2__ <= C; ++sym2__) { + current_statement__ = 65; + stan::model::assign(mat, mat_flat__[(pos__ - 1)], + "assigning variable mat", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 65; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 66; + stan::math::validate_non_negative_index("alpha_gamma", "Nloc", Nloc); + current_statement__ = 67; + stan::math::validate_non_negative_index("beta_gamma", "Nloc", Nloc); + current_statement__ = 68; + stan::math::validate_non_negative_index("q_trans", "nparams", nparams); + current_statement__ = 69; + stan::math::validate_non_negative_index("p11", "Nloc", Nloc); + current_statement__ = 70; + stan::math::validate_non_negative_index("p", "Nloc", Nloc); + current_statement__ = 71; + stan::math::validate_non_negative_index("coef", "C", C); + current_statement__ = 72; + stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); + current_statement__ = 73; + stan::math::validate_non_negative_index("E_trans", "C", C); + current_statement__ = 74; + stan::math::validate_non_negative_index("q", "nparams", nparams); + current_statement__ = 75; + log_lik_1dim__ = std::numeric_limits::min(); + current_statement__ = 75; + log_lik_1dim__ = (C + S); + current_statement__ = 75; + stan::math::validate_non_negative_index("log_lik", "C + S", + log_lik_1dim__); + current_statement__ = 76; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 77; + mu_2dim__ = std::numeric_limits::min(); + current_statement__ = 77; + mu_2dim__ = (nparams + 1); + current_statement__ = 77; + stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + Nloc + 1 + 1 + nparams; + } + inline std::string model_name() const final { + return "model_joint_binary_catchability_gamma"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_joint_binary_catchability_gamma_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector alpha_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + alpha_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0, lp__, + Nloc); + std::vector beta_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + beta_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0.01, lp__, + Nloc); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 3; + beta = in__.template read(); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 4; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 5; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + std::vector p11 = + std::vector(Nloc, DUMMY_VAR__); + std::vector p = + std::vector(Nloc, DUMMY_VAR__); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, DUMMY_VAR__); + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + std::vector E_trans = + std::vector(C, DUMMY_VAR__); + current_statement__ = 19; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 15; + stan::model::assign(mu_1, + (stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni(i)) / + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni(i))), "assigning variable mu_1", + stan::model::index_uni(i)); + current_statement__ = 16; + stan::model::assign(p11, + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + + stan::math::exp(beta))), "assigning variable p11", + stan::model::index_uni(i)); + current_statement__ = 17; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 22; + for (int k = 1; k <= C; ++k) { + current_statement__ = 20; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), + q_trans)), "assigning variable coef", stan::model::index_uni(k)); + } + current_statement__ = 25; + for (int j = 1; j <= C; ++j) { + current_statement__ = 23; + stan::model::assign(E_trans, + (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + + 0.0000000000001), "assigning variable E_trans", + stan::model::index_uni(j)); + } + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 7; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 8; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + current_statement__ = 9; + stan::math::check_greater_or_equal(function__, "mu_1", mu_1, 0); + current_statement__ = 10; + stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); + { + current_statement__ = 40; + for (int j = 1; j <= C; ++j) { + current_statement__ = 38; + lp_accum__.add(stan::math::gamma_lpdf( + stan::model::rvalue(E_trans, "E_trans", + stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", + stan::model::index_uni(j)) * + stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j))))), + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))))); + } + current_statement__ = 43; + for (int i = 1; i <= S; ++i) { + current_statement__ = 41; + lp_accum__.add(stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", + stan::model::index_uni(i)), + stan::model::rvalue(N, "N", + stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", + stan::model::index_uni(i)))))); + } + current_statement__ = 44; + lp_accum__.add(stan::math::normal_lpdf(log_p10, + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(1)), + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(2)))); + current_statement__ = 45; + lp_accum__.add(stan::math::normal_lpdf(beta, 0, 10)); + current_statement__ = 46; + lp_accum__.add(stan::math::gamma_lpdf(beta_gamma, 0.25, + 0.25)); + current_statement__ = 47; + lp_accum__.add(stan::math::gamma_lpdf(alpha_gamma, 0.01, + 0.01)); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_joint_binary_catchability_gamma_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector alpha_gamma = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + alpha_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0, lp__, + Nloc); + std::vector beta_gamma = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 2; + beta_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0.01, lp__, + Nloc); + double beta = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; + beta = in__.template read(); + double log_p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 4; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + current_statement__ = 5; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + std::vector p11 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector p = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + std::vector mu_1 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector E_trans = + std::vector(C, std::numeric_limits::quiet_NaN()); + out__.write(alpha_gamma); + out__.write(beta_gamma); + out__.write(beta); + out__.write(log_p10); + out__.write(q_trans); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 19; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 15; + stan::model::assign(mu_1, + (stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni(i)) / + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni(i))), "assigning variable mu_1", + stan::model::index_uni(i)); + current_statement__ = 16; + stan::model::assign(p11, + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + + stan::math::exp(beta))), "assigning variable p11", + stan::model::index_uni(i)); + current_statement__ = 17; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 22; + for (int k = 1; k <= C; ++k) { + current_statement__ = 20; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), + q_trans)), "assigning variable coef", stan::model::index_uni(k)); + } + current_statement__ = 25; + for (int j = 1; j <= C; ++j) { + current_statement__ = 23; + stan::model::assign(E_trans, + (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + + 0.0000000000001), "assigning variable E_trans", + stan::model::index_uni(j)); + } + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 7; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 8; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + current_statement__ = 9; + stan::math::check_greater_or_equal(function__, "mu_1", mu_1, 0); + current_statement__ = 10; + stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); + if (emit_transformed_parameters__) { + out__.write(p11); + out__.write(p); + out__.write(coef); + out__.write(mu_1); + out__.write(E_trans); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix q = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(log_lik_1dim__, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix mu = + Eigen::Matrix::Constant(Nloc, mu_2dim__, + std::numeric_limits::quiet_NaN()); + double p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 26; + p10 = stan::math::exp(log_p10); + current_statement__ = 27; + stan::model::assign(q, stan::math::add(q_trans, 1), + "assigning variable q"); + current_statement__ = 28; + stan::model::assign(mu, stan::math::to_vector(mu_1), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni(1)); + current_statement__ = 31; + for (int i = 1; i <= nparams; ++i) { + current_statement__ = 29; + stan::model::assign(mu, + stan::math::multiply(stan::math::to_vector(mu_1), + stan::model::rvalue(q, "q", stan::model::index_uni(i))), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni((i + 1))); + } + current_statement__ = 34; + for (int j = 1; j <= C; ++j) { + current_statement__ = 32; + stan::model::assign(log_lik, + stan::math::gamma_lpdf( + stan::model::rvalue(E_trans, "E_trans", stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * + stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + "assigning variable log_lik", stan::model::index_uni(j)); + } + current_statement__ = 37; + for (int i = 1; i <= S; ++i) { + current_statement__ = 35; + stan::model::assign(log_lik, + stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", stan::model::index_uni(i)), + stan::model::rvalue(N, "N", stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", stan::model::index_uni(i))))), + "assigning variable log_lik", stan::model::index_uni((C + i))); + } + out__.write(q); + out__.write(log_lik); + out__.write(mu); + out__.write(p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector alpha_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(alpha_gamma, + in__.read>(Nloc), + "assigning variable alpha_gamma"); + out__.write_free_lb(0, alpha_gamma); + std::vector beta_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + stan::model::assign(beta_gamma, + in__.read>(Nloc), + "assigning variable beta_gamma"); + out__.write_free_lb(0.01, beta_gamma); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 3; + beta = in__.read(); + out__.write(beta); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 4; + log_p10 = in__.read(); + out__.write_free_ub(0, log_p10); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 5; + stan::model::assign(q_trans, + in__.read>(nparams), + "assigning variable q_trans"); + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "alpha_gamma", + "double", std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "beta_gamma", + "double", std::vector{static_cast(Nloc)}); + current_statement__ = 3; + context__.validate_dims("parameter initialization", "beta", "double", + std::vector{}); + current_statement__ = 4; + context__.validate_dims("parameter initialization", "log_p10", + "double", std::vector{}); + current_statement__ = 5; + context__.validate_dims("parameter initialization", "q_trans", + "double", std::vector{static_cast(nparams)}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector alpha_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + alpha_gamma = context__.vals_r("alpha_gamma"); + out__.write_free_lb(0, alpha_gamma); + std::vector beta_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + beta_gamma = context__.vals_r("beta_gamma"); + out__.write_free_lb(0.01, beta_gamma); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 3; + beta = context__.vals_r("beta")[(1 - 1)]; + out__.write(beta); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 4; + log_p10 = context__.vals_r("log_p10")[(1 - 1)]; + out__.write_free_ub(0, log_p10); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + { + std::vector q_trans_flat__; + current_statement__ = 5; + q_trans_flat__ = context__.vals_r("q_trans"); + current_statement__ = 5; + pos__ = 1; + current_statement__ = 5; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 5; + stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], + "assigning variable q_trans", stan::model::index_uni(sym1__)); + current_statement__ = 5; + pos__ = (pos__ + 1); + } + } + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"alpha_gamma", "beta_gamma", "beta", + "log_p10", "q_trans"}; + if (emit_transformed_parameters__) { + std::vector temp{"p11", "p", "coef", "mu_1", "E_trans"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"q", "log_lik", "mu", "p10"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{}, std::vector{}, + std::vector{static_cast(nparams)}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(C)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(C)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(nparams)}, + std::vector{static_cast(log_lik_1dim__)}, + std::vector{static_cast(Nloc), + static_cast(mu_2dim__)}, std::vector{}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta_gamma" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "beta"); + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "E_trans" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta_gamma" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "beta"); + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "E_trans" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((((Nloc + Nloc) + 1) + 1) + nparams); + const size_t num_transformed = emit_transformed_parameters * (((((Nloc + + Nloc) + C) + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * ((((nparams + + log_lik_1dim__) + (Nloc * mu_2dim__)) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((((Nloc + Nloc) + 1) + 1) + nparams); + const size_t num_transformed = emit_transformed_parameters * (((((Nloc + + Nloc) + C) + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * ((((nparams + + log_lik_1dim__) + (Nloc * mu_2dim__)) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_joint_binary_catchability_gamma_namespace::model_joint_binary_catchability_gamma; +#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_joint_binary_catchability_gamma_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_joint_binary_catchability_negbin.h b/src/stanExports_joint_binary_catchability_negbin.h index 73f8de7..ea62db4 100644 --- a/src/stanExports_joint_binary_catchability_negbin.h +++ b/src/stanExports_joint_binary_catchability_negbin.h @@ -1,963 +1,963 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_joint_binary_catchability_negbin_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'joint_binary_catchability_negbin', line 16, column 4 to column 35)", - " (in 'joint_binary_catchability_negbin', line 17, column 4 to column 22)", - " (in 'joint_binary_catchability_negbin', line 18, column 4 to column 14)", - " (in 'joint_binary_catchability_negbin', line 19, column 4 to column 26)", - " (in 'joint_binary_catchability_negbin', line 20, column 4 to column 44)", - " (in 'joint_binary_catchability_negbin', line 23, column 2 to column 43)", - " (in 'joint_binary_catchability_negbin', line 24, column 2 to column 40)", - " (in 'joint_binary_catchability_negbin', line 25, column 2 to column 26)", - " (in 'joint_binary_catchability_negbin', line 47, column 2 to column 20)", - " (in 'joint_binary_catchability_negbin', line 48, column 2 to column 22)", - " (in 'joint_binary_catchability_negbin', line 49, column 2 to column 28)", - " (in 'joint_binary_catchability_negbin', line 50, column 2 to column 11)", - " (in 'joint_binary_catchability_negbin', line 27, column 4 to column 45)", - " (in 'joint_binary_catchability_negbin', line 28, column 4 to column 33)", - " (in 'joint_binary_catchability_negbin', line 26, column 19 to line 29, column 3)", - " (in 'joint_binary_catchability_negbin', line 26, column 2 to line 29, column 3)", - " (in 'joint_binary_catchability_negbin', line 31, column 6 to column 48)", - " (in 'joint_binary_catchability_negbin', line 30, column 15 to line 32, column 5)", - " (in 'joint_binary_catchability_negbin', line 30, column 2 to line 32, column 5)", - " (in 'joint_binary_catchability_negbin', line 51, column 2 to column 21)", - " (in 'joint_binary_catchability_negbin', line 52, column 2 to column 18)", - " (in 'joint_binary_catchability_negbin', line 53, column 2 to column 27)", - " (in 'joint_binary_catchability_negbin', line 55, column 4 to column 36)", - " (in 'joint_binary_catchability_negbin', line 54, column 21 to line 56, column 3)", - " (in 'joint_binary_catchability_negbin', line 54, column 2 to line 56, column 3)", - " (in 'joint_binary_catchability_negbin', line 58, column 10 to column 75)", - " (in 'joint_binary_catchability_negbin', line 57, column 17 to line 59, column 7)", - " (in 'joint_binary_catchability_negbin', line 57, column 4 to line 59, column 7)", - " (in 'joint_binary_catchability_negbin', line 61, column 10 to column 61)", - " (in 'joint_binary_catchability_negbin', line 60, column 19 to line 62, column 7)", - " (in 'joint_binary_catchability_negbin', line 60, column 6 to line 62, column 7)", - " (in 'joint_binary_catchability_negbin', line 36, column 8 to column 55)", - " (in 'joint_binary_catchability_negbin', line 35, column 18 to line 37, column 5)", - " (in 'joint_binary_catchability_negbin', line 35, column 4 to line 37, column 5)", - " (in 'joint_binary_catchability_negbin', line 39, column 8 to column 39)", - " (in 'joint_binary_catchability_negbin', line 38, column 18 to line 40, column 5)", - " (in 'joint_binary_catchability_negbin', line 38, column 4 to line 40, column 5)", - " (in 'joint_binary_catchability_negbin', line 42, column 2 to column 47)", - " (in 'joint_binary_catchability_negbin', line 43, column 2 to column 22)", - " (in 'joint_binary_catchability_negbin', line 44, column 2 to column 42)", - " (in 'joint_binary_catchability_negbin', line 2, column 4 to column 19)", - " (in 'joint_binary_catchability_negbin', line 3, column 4 to column 19)", - " (in 'joint_binary_catchability_negbin', line 4, column 10 to column 11)", - " (in 'joint_binary_catchability_negbin', line 4, column 4 to column 28)", - " (in 'joint_binary_catchability_negbin', line 5, column 10 to column 11)", - " (in 'joint_binary_catchability_negbin', line 5, column 4 to column 28)", - " (in 'joint_binary_catchability_negbin', line 6, column 4 to column 22)", - " (in 'joint_binary_catchability_negbin', line 7, column 10 to column 11)", - " (in 'joint_binary_catchability_negbin', line 7, column 4 to column 28)", - " (in 'joint_binary_catchability_negbin', line 8, column 10 to column 11)", - " (in 'joint_binary_catchability_negbin', line 8, column 4 to column 28)", - " (in 'joint_binary_catchability_negbin', line 9, column 10 to column 11)", - " (in 'joint_binary_catchability_negbin', line 9, column 4 to column 28)", - " (in 'joint_binary_catchability_negbin', line 10, column 4 to column 28)", - " (in 'joint_binary_catchability_negbin', line 11, column 4 to column 28)", - " (in 'joint_binary_catchability_negbin', line 12, column 4 to column 25)", - " (in 'joint_binary_catchability_negbin', line 13, column 11 to column 12)", - " (in 'joint_binary_catchability_negbin', line 13, column 13 to column 20)", - " (in 'joint_binary_catchability_negbin', line 13, column 4 to column 26)", - " (in 'joint_binary_catchability_negbin', line 16, column 10 to column 14)", - " (in 'joint_binary_catchability_negbin', line 20, column 27 to column 34)", - " (in 'joint_binary_catchability_negbin', line 23, column 8 to column 12)", - " (in 'joint_binary_catchability_negbin', line 24, column 8 to column 12)", - " (in 'joint_binary_catchability_negbin', line 25, column 18 to column 19)", - " (in 'joint_binary_catchability_negbin', line 47, column 9 to column 16)", - " (in 'joint_binary_catchability_negbin', line 48, column 9 to column 12)", - " (in 'joint_binary_catchability_negbin', line 49, column 9 to column 13)", - " (in 'joint_binary_catchability_negbin', line 49, column 14 to column 23)"}; -#include -class model_joint_binary_catchability_negbin final : public model_base_crtp { -private: - int S; - int C; - std::vector L; - std::vector R; - int Nloc; - std::vector E; - std::vector N; - std::vector K; - std::vector p10priors; - std::vector phipriors; - int nparams; - Eigen::Matrix mat_data__; - int log_lik_1dim__; - int mu_2dim__; - Eigen::Map> mat{nullptr, 0, 0}; -public: - ~model_joint_binary_catchability_negbin() {} - model_joint_binary_catchability_negbin(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_joint_binary_catchability_negbin_namespace::model_joint_binary_catchability_negbin"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 41; - context__.validate_dims("data initialization", "S", "int", - std::vector{}); - S = std::numeric_limits::min(); - current_statement__ = 41; - S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 41; - stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 42; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 42; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 42; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 43; - stan::math::validate_non_negative_index("L", "S", S); - current_statement__ = 44; - context__.validate_dims("data initialization", "L", "int", - std::vector{static_cast(S)}); - L = std::vector(S, std::numeric_limits::min()); - current_statement__ = 44; - L = context__.vals_i("L"); - current_statement__ = 44; - stan::math::check_greater_or_equal(function__, "L", L, 1); - current_statement__ = 45; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 46; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 46; - R = context__.vals_i("R"); - current_statement__ = 46; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 47; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 47; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 47; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 48; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 49; - context__.validate_dims("data initialization", "E", "int", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::min()); - current_statement__ = 49; - E = context__.vals_i("E"); - current_statement__ = 49; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 50; - stan::math::validate_non_negative_index("N", "S", S); - current_statement__ = 51; - context__.validate_dims("data initialization", "N", "int", - std::vector{static_cast(S)}); - N = std::vector(S, std::numeric_limits::min()); - current_statement__ = 51; - N = context__.vals_i("N"); - current_statement__ = 51; - stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 52; - stan::math::validate_non_negative_index("K", "S", S); - current_statement__ = 53; - context__.validate_dims("data initialization", "K", "int", - std::vector{static_cast(S)}); - K = std::vector(S, std::numeric_limits::min()); - current_statement__ = 53; - K = context__.vals_i("K"); - current_statement__ = 53; - stan::math::check_greater_or_equal(function__, "K", K, 0); - current_statement__ = 54; - context__.validate_dims("data initialization", "p10priors", "double", - std::vector{static_cast(2)}); - p10priors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 54; - p10priors = context__.vals_r("p10priors"); - current_statement__ = 55; - context__.validate_dims("data initialization", "phipriors", "double", - std::vector{static_cast(2)}); - phipriors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 55; - phipriors = context__.vals_r("phipriors"); - current_statement__ = 56; - context__.validate_dims("data initialization", "nparams", "int", - std::vector{}); - nparams = std::numeric_limits::min(); - current_statement__ = 56; - nparams = context__.vals_i("nparams")[(1 - 1)]; - current_statement__ = 56; - stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); - current_statement__ = 57; - stan::math::validate_non_negative_index("mat", "C", C); - current_statement__ = 58; - stan::math::validate_non_negative_index("mat", "nparams", nparams); - current_statement__ = 59; - context__.validate_dims("data initialization", "mat", "double", - std::vector{static_cast(C), - static_cast(nparams)}); - mat_data__ = Eigen::Matrix::Constant(C, nparams, - std::numeric_limits::quiet_NaN()); - new (&mat) Eigen::Map>(mat_data__.data(), - C, nparams); - { - std::vector mat_flat__; - current_statement__ = 59; - mat_flat__ = context__.vals_r("mat"); - current_statement__ = 59; - pos__ = 1; - current_statement__ = 59; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 59; - for (int sym2__ = 1; sym2__ <= C; ++sym2__) { - current_statement__ = 59; - stan::model::assign(mat, mat_flat__[(pos__ - 1)], - "assigning variable mat", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 59; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 60; - stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); - current_statement__ = 61; - stan::math::validate_non_negative_index("q_trans", "nparams", nparams); - current_statement__ = 62; - stan::math::validate_non_negative_index("p11", "Nloc", Nloc); - current_statement__ = 63; - stan::math::validate_non_negative_index("p", "Nloc", Nloc); - current_statement__ = 64; - stan::math::validate_non_negative_index("coef", "C", C); - current_statement__ = 65; - stan::math::validate_non_negative_index("q", "nparams", nparams); - current_statement__ = 66; - log_lik_1dim__ = std::numeric_limits::min(); - current_statement__ = 66; - log_lik_1dim__ = (C + S); - current_statement__ = 66; - stan::math::validate_non_negative_index("log_lik", "C + S", - log_lik_1dim__); - current_statement__ = 67; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 68; - mu_2dim__ = std::numeric_limits::min(); - current_statement__ = 68; - mu_2dim__ = (nparams + 1); - current_statement__ = 68; - stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + 1 + 1 + 1 + nparams; - } - inline std::string model_name() const final { - return "model_joint_binary_catchability_negbin"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_joint_binary_catchability_negbin_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu_1 = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = in__.template read_constrain_lb(0, - lp__); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 3; - beta = in__.template read(); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 4; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 5; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - std::vector p11 = - std::vector(Nloc, DUMMY_VAR__); - std::vector p = - std::vector(Nloc, DUMMY_VAR__); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, DUMMY_VAR__); - current_statement__ = 16; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 13; - stan::model::assign(p11, - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + - stan::math::exp(beta))), "assigning variable p11", - stan::model::index_uni(i)); - current_statement__ = 14; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 19; - for (int k = 1; k <= C; ++k) { - current_statement__ = 17; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), - q_trans)), "assigning variable coef", stan::model::index_uni(k)); - } - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 7; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 8; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - { - current_statement__ = 34; - for (int j = 1; j <= C; ++j) { - current_statement__ = 32; - lp_accum__.add(stan::math::neg_binomial_2_lpmf( - stan::model::rvalue(E, "E", - stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", - stan::model::index_uni(j)) * - stan::model::rvalue(mu_1, "mu_1", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j))))), phi)); - } - current_statement__ = 37; - for (int i = 1; i <= S; ++i) { - current_statement__ = 35; - lp_accum__.add(stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", - stan::model::index_uni(i)), - stan::model::rvalue(N, "N", - stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", - stan::model::index_uni(i)))))); - } - current_statement__ = 38; - lp_accum__.add(stan::math::normal_lpdf(log_p10, - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(1)), - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(2)))); - current_statement__ = 39; - lp_accum__.add(stan::math::normal_lpdf(beta, 0, 10)); - current_statement__ = 40; - lp_accum__.add(stan::math::gamma_lpdf(phi, - stan::model::rvalue(phipriors, "phipriors", - stan::model::index_uni(1)), - stan::model::rvalue(phipriors, "phipriors", - stan::model::index_uni(2)))); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_joint_binary_catchability_negbin_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector mu_1 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - mu_1 = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - double phi = std::numeric_limits::quiet_NaN(); - current_statement__ = 2; - phi = in__.template read_constrain_lb(0, - lp__); - double beta = std::numeric_limits::quiet_NaN(); - current_statement__ = 3; - beta = in__.template read(); - double log_p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 4; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - current_statement__ = 5; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - std::vector p11 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector p = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - out__.write(mu_1); - out__.write(phi); - out__.write(beta); - out__.write(log_p10); - out__.write(q_trans); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 16; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 13; - stan::model::assign(p11, - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + - stan::math::exp(beta))), "assigning variable p11", - stan::model::index_uni(i)); - current_statement__ = 14; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 19; - for (int k = 1; k <= C; ++k) { - current_statement__ = 17; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), - q_trans)), "assigning variable coef", stan::model::index_uni(k)); - } - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 7; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 8; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - if (emit_transformed_parameters__) { - out__.write(p11); - out__.write(p); - out__.write(coef); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix q = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(log_lik_1dim__, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix mu = - Eigen::Matrix::Constant(Nloc, mu_2dim__, - std::numeric_limits::quiet_NaN()); - double p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 20; - p10 = stan::math::exp(log_p10); - current_statement__ = 21; - stan::model::assign(q, stan::math::add(q_trans, 1), - "assigning variable q"); - current_statement__ = 22; - stan::model::assign(mu, stan::math::to_vector(mu_1), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni(1)); - current_statement__ = 25; - for (int i = 1; i <= nparams; ++i) { - current_statement__ = 23; - stan::model::assign(mu, - stan::math::multiply(stan::math::to_vector(mu_1), - stan::model::rvalue(q, "q", stan::model::index_uni(i))), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni((i + 1))); - } - current_statement__ = 28; - for (int j = 1; j <= C; ++j) { - current_statement__ = 26; - stan::model::assign(log_lik, - stan::math::neg_binomial_2_lpmf( - stan::model::rvalue(E, "E", stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * - stan::model::rvalue(mu_1, "mu_1", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - phi), "assigning variable log_lik", stan::model::index_uni(j)); - } - current_statement__ = 31; - for (int i = 1; i <= S; ++i) { - current_statement__ = 29; - stan::model::assign(log_lik, - stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", stan::model::index_uni(i)), - stan::model::rvalue(N, "N", stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", stan::model::index_uni(i))))), - "assigning variable log_lik", stan::model::index_uni((C + i))); - } - out__.write(q); - out__.write(log_lik); - out__.write(mu); - out__.write(p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(mu_1, - in__.read>(Nloc), - "assigning variable mu_1"); - out__.write_free_lb(0, mu_1); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = in__.read(); - out__.write_free_lb(0, phi); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 3; - beta = in__.read(); - out__.write(beta); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 4; - log_p10 = in__.read(); - out__.write_free_ub(0, log_p10); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 5; - stan::model::assign(q_trans, - in__.read>(nparams), - "assigning variable q_trans"); - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "mu_1", "double", - std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "phi", "double", - std::vector{}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "beta", "double", - std::vector{}); - current_statement__ = 4; - context__.validate_dims("parameter initialization", "log_p10", - "double", std::vector{}); - current_statement__ = 5; - context__.validate_dims("parameter initialization", "q_trans", - "double", std::vector{static_cast(nparams)}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu_1 = context__.vals_r("mu_1"); - out__.write_free_lb(0, mu_1); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = context__.vals_r("phi")[(1 - 1)]; - out__.write_free_lb(0, phi); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 3; - beta = context__.vals_r("beta")[(1 - 1)]; - out__.write(beta); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 4; - log_p10 = context__.vals_r("log_p10")[(1 - 1)]; - out__.write_free_ub(0, log_p10); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - { - std::vector q_trans_flat__; - current_statement__ = 5; - q_trans_flat__ = context__.vals_r("q_trans"); - current_statement__ = 5; - pos__ = 1; - current_statement__ = 5; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 5; - stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], - "assigning variable q_trans", stan::model::index_uni(sym1__)); - current_statement__ = 5; - pos__ = (pos__ + 1); - } - } - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"mu_1", "phi", "beta", "log_p10", - "q_trans"}; - if (emit_transformed_parameters__) { - std::vector temp{"p11", "p", "coef"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"q", "log_lik", "mu", "p10"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{}, std::vector{}, - std::vector{}, - std::vector{static_cast(nparams)}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(C)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(nparams)}, - std::vector{static_cast(log_lik_1dim__)}, - std::vector{static_cast(Nloc), - static_cast(mu_2dim__)}, std::vector{}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "phi"); - param_names__.emplace_back(std::string() + "beta"); - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "phi"); - param_names__.emplace_back(std::string() + "beta"); - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((((Nloc + 1) + 1) + 1) + nparams); - const size_t num_transformed = emit_transformed_parameters * (((Nloc + - Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * ((((nparams - + log_lik_1dim__) + (Nloc * mu_2dim__)) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((((Nloc + 1) + 1) + 1) + nparams); - const size_t num_transformed = emit_transformed_parameters * (((Nloc + - Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * ((((nparams - + log_lik_1dim__) + (Nloc * mu_2dim__)) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_joint_binary_catchability_negbin_namespace::model_joint_binary_catchability_negbin; -#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_joint_binary_catchability_negbin_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_joint_binary_catchability_negbin_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 16, column 4 to column 35)", + " (in 'string', line 17, column 4 to column 22)", + " (in 'string', line 18, column 4 to column 14)", + " (in 'string', line 19, column 4 to column 26)", + " (in 'string', line 20, column 4 to column 44)", + " (in 'string', line 23, column 2 to column 43)", + " (in 'string', line 24, column 2 to column 40)", + " (in 'string', line 25, column 2 to column 26)", + " (in 'string', line 47, column 2 to column 20)", + " (in 'string', line 48, column 2 to column 22)", + " (in 'string', line 49, column 2 to column 28)", + " (in 'string', line 50, column 2 to column 11)", + " (in 'string', line 27, column 4 to column 45)", + " (in 'string', line 28, column 4 to column 33)", + " (in 'string', line 26, column 19 to line 29, column 3)", + " (in 'string', line 26, column 2 to line 29, column 3)", + " (in 'string', line 31, column 6 to column 48)", + " (in 'string', line 30, column 15 to line 32, column 5)", + " (in 'string', line 30, column 2 to line 32, column 5)", + " (in 'string', line 51, column 2 to column 21)", + " (in 'string', line 52, column 2 to column 18)", + " (in 'string', line 53, column 2 to column 27)", + " (in 'string', line 55, column 4 to column 36)", + " (in 'string', line 54, column 21 to line 56, column 3)", + " (in 'string', line 54, column 2 to line 56, column 3)", + " (in 'string', line 58, column 10 to column 75)", + " (in 'string', line 57, column 17 to line 59, column 7)", + " (in 'string', line 57, column 4 to line 59, column 7)", + " (in 'string', line 61, column 10 to column 61)", + " (in 'string', line 60, column 19 to line 62, column 7)", + " (in 'string', line 60, column 6 to line 62, column 7)", + " (in 'string', line 36, column 8 to column 55)", + " (in 'string', line 35, column 18 to line 37, column 5)", + " (in 'string', line 35, column 4 to line 37, column 5)", + " (in 'string', line 39, column 8 to column 39)", + " (in 'string', line 38, column 18 to line 40, column 5)", + " (in 'string', line 38, column 4 to line 40, column 5)", + " (in 'string', line 42, column 2 to column 47)", + " (in 'string', line 43, column 2 to column 22)", + " (in 'string', line 44, column 2 to column 42)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 4 to column 19)", + " (in 'string', line 4, column 10 to column 11)", + " (in 'string', line 4, column 4 to column 28)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 22)", + " (in 'string', line 7, column 10 to column 11)", + " (in 'string', line 7, column 4 to column 28)", + " (in 'string', line 8, column 10 to column 11)", + " (in 'string', line 8, column 4 to column 28)", + " (in 'string', line 9, column 10 to column 11)", + " (in 'string', line 9, column 4 to column 28)", + " (in 'string', line 10, column 4 to column 28)", + " (in 'string', line 11, column 4 to column 28)", + " (in 'string', line 12, column 4 to column 25)", + " (in 'string', line 13, column 11 to column 12)", + " (in 'string', line 13, column 13 to column 20)", + " (in 'string', line 13, column 4 to column 26)", + " (in 'string', line 16, column 10 to column 14)", + " (in 'string', line 20, column 27 to column 34)", + " (in 'string', line 23, column 8 to column 12)", + " (in 'string', line 24, column 8 to column 12)", + " (in 'string', line 25, column 18 to column 19)", + " (in 'string', line 47, column 9 to column 16)", + " (in 'string', line 48, column 9 to column 12)", + " (in 'string', line 49, column 9 to column 13)", + " (in 'string', line 49, column 14 to column 23)"}; +#include +class model_joint_binary_catchability_negbin final : public model_base_crtp { +private: + int S; + int C; + std::vector L; + std::vector R; + int Nloc; + std::vector E; + std::vector N; + std::vector K; + std::vector p10priors; + std::vector phipriors; + int nparams; + Eigen::Matrix mat_data__; + int log_lik_1dim__; + int mu_2dim__; + Eigen::Map> mat{nullptr, 0, 0}; +public: + ~model_joint_binary_catchability_negbin() {} + model_joint_binary_catchability_negbin(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_joint_binary_catchability_negbin_namespace::model_joint_binary_catchability_negbin"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 41; + context__.validate_dims("data initialization", "S", "int", + std::vector{}); + S = std::numeric_limits::min(); + current_statement__ = 41; + S = context__.vals_i("S")[(1 - 1)]; + current_statement__ = 41; + stan::math::check_greater_or_equal(function__, "S", S, 1); + current_statement__ = 42; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 42; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 42; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 43; + stan::math::validate_non_negative_index("L", "S", S); + current_statement__ = 44; + context__.validate_dims("data initialization", "L", "int", + std::vector{static_cast(S)}); + L = std::vector(S, std::numeric_limits::min()); + current_statement__ = 44; + L = context__.vals_i("L"); + current_statement__ = 44; + stan::math::check_greater_or_equal(function__, "L", L, 1); + current_statement__ = 45; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 46; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 46; + R = context__.vals_i("R"); + current_statement__ = 46; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 47; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 47; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 47; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 48; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 49; + context__.validate_dims("data initialization", "E", "int", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::min()); + current_statement__ = 49; + E = context__.vals_i("E"); + current_statement__ = 49; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 50; + stan::math::validate_non_negative_index("N", "S", S); + current_statement__ = 51; + context__.validate_dims("data initialization", "N", "int", + std::vector{static_cast(S)}); + N = std::vector(S, std::numeric_limits::min()); + current_statement__ = 51; + N = context__.vals_i("N"); + current_statement__ = 51; + stan::math::check_greater_or_equal(function__, "N", N, 1); + current_statement__ = 52; + stan::math::validate_non_negative_index("K", "S", S); + current_statement__ = 53; + context__.validate_dims("data initialization", "K", "int", + std::vector{static_cast(S)}); + K = std::vector(S, std::numeric_limits::min()); + current_statement__ = 53; + K = context__.vals_i("K"); + current_statement__ = 53; + stan::math::check_greater_or_equal(function__, "K", K, 0); + current_statement__ = 54; + context__.validate_dims("data initialization", "p10priors", "double", + std::vector{static_cast(2)}); + p10priors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 54; + p10priors = context__.vals_r("p10priors"); + current_statement__ = 55; + context__.validate_dims("data initialization", "phipriors", "double", + std::vector{static_cast(2)}); + phipriors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 55; + phipriors = context__.vals_r("phipriors"); + current_statement__ = 56; + context__.validate_dims("data initialization", "nparams", "int", + std::vector{}); + nparams = std::numeric_limits::min(); + current_statement__ = 56; + nparams = context__.vals_i("nparams")[(1 - 1)]; + current_statement__ = 56; + stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); + current_statement__ = 57; + stan::math::validate_non_negative_index("mat", "C", C); + current_statement__ = 58; + stan::math::validate_non_negative_index("mat", "nparams", nparams); + current_statement__ = 59; + context__.validate_dims("data initialization", "mat", "double", + std::vector{static_cast(C), + static_cast(nparams)}); + mat_data__ = Eigen::Matrix::Constant(C, nparams, + std::numeric_limits::quiet_NaN()); + new (&mat) Eigen::Map>(mat_data__.data(), + C, nparams); + { + std::vector mat_flat__; + current_statement__ = 59; + mat_flat__ = context__.vals_r("mat"); + current_statement__ = 59; + pos__ = 1; + current_statement__ = 59; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 59; + for (int sym2__ = 1; sym2__ <= C; ++sym2__) { + current_statement__ = 59; + stan::model::assign(mat, mat_flat__[(pos__ - 1)], + "assigning variable mat", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 59; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 60; + stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); + current_statement__ = 61; + stan::math::validate_non_negative_index("q_trans", "nparams", nparams); + current_statement__ = 62; + stan::math::validate_non_negative_index("p11", "Nloc", Nloc); + current_statement__ = 63; + stan::math::validate_non_negative_index("p", "Nloc", Nloc); + current_statement__ = 64; + stan::math::validate_non_negative_index("coef", "C", C); + current_statement__ = 65; + stan::math::validate_non_negative_index("q", "nparams", nparams); + current_statement__ = 66; + log_lik_1dim__ = std::numeric_limits::min(); + current_statement__ = 66; + log_lik_1dim__ = (C + S); + current_statement__ = 66; + stan::math::validate_non_negative_index("log_lik", "C + S", + log_lik_1dim__); + current_statement__ = 67; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 68; + mu_2dim__ = std::numeric_limits::min(); + current_statement__ = 68; + mu_2dim__ = (nparams + 1); + current_statement__ = 68; + stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + 1 + 1 + 1 + nparams; + } + inline std::string model_name() const final { + return "model_joint_binary_catchability_negbin"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_joint_binary_catchability_negbin_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu_1 = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = in__.template read_constrain_lb(0, + lp__); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 3; + beta = in__.template read(); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 4; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 5; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + std::vector p11 = + std::vector(Nloc, DUMMY_VAR__); + std::vector p = + std::vector(Nloc, DUMMY_VAR__); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, DUMMY_VAR__); + current_statement__ = 16; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 13; + stan::model::assign(p11, + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + + stan::math::exp(beta))), "assigning variable p11", + stan::model::index_uni(i)); + current_statement__ = 14; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 19; + for (int k = 1; k <= C; ++k) { + current_statement__ = 17; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), + q_trans)), "assigning variable coef", stan::model::index_uni(k)); + } + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 7; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 8; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + { + current_statement__ = 34; + for (int j = 1; j <= C; ++j) { + current_statement__ = 32; + lp_accum__.add(stan::math::neg_binomial_2_lpmf( + stan::model::rvalue(E, "E", + stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", + stan::model::index_uni(j)) * + stan::model::rvalue(mu_1, "mu_1", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j))))), phi)); + } + current_statement__ = 37; + for (int i = 1; i <= S; ++i) { + current_statement__ = 35; + lp_accum__.add(stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", + stan::model::index_uni(i)), + stan::model::rvalue(N, "N", + stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", + stan::model::index_uni(i)))))); + } + current_statement__ = 38; + lp_accum__.add(stan::math::normal_lpdf(log_p10, + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(1)), + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(2)))); + current_statement__ = 39; + lp_accum__.add(stan::math::normal_lpdf(beta, 0, 10)); + current_statement__ = 40; + lp_accum__.add(stan::math::gamma_lpdf(phi, + stan::model::rvalue(phipriors, "phipriors", + stan::model::index_uni(1)), + stan::model::rvalue(phipriors, "phipriors", + stan::model::index_uni(2)))); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_joint_binary_catchability_negbin_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector mu_1 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + mu_1 = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + double phi = std::numeric_limits::quiet_NaN(); + current_statement__ = 2; + phi = in__.template read_constrain_lb(0, + lp__); + double beta = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; + beta = in__.template read(); + double log_p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 4; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + current_statement__ = 5; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + std::vector p11 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector p = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + out__.write(mu_1); + out__.write(phi); + out__.write(beta); + out__.write(log_p10); + out__.write(q_trans); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 16; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 13; + stan::model::assign(p11, + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + + stan::math::exp(beta))), "assigning variable p11", + stan::model::index_uni(i)); + current_statement__ = 14; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 19; + for (int k = 1; k <= C; ++k) { + current_statement__ = 17; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), + q_trans)), "assigning variable coef", stan::model::index_uni(k)); + } + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 7; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 8; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + if (emit_transformed_parameters__) { + out__.write(p11); + out__.write(p); + out__.write(coef); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix q = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(log_lik_1dim__, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix mu = + Eigen::Matrix::Constant(Nloc, mu_2dim__, + std::numeric_limits::quiet_NaN()); + double p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 20; + p10 = stan::math::exp(log_p10); + current_statement__ = 21; + stan::model::assign(q, stan::math::add(q_trans, 1), + "assigning variable q"); + current_statement__ = 22; + stan::model::assign(mu, stan::math::to_vector(mu_1), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni(1)); + current_statement__ = 25; + for (int i = 1; i <= nparams; ++i) { + current_statement__ = 23; + stan::model::assign(mu, + stan::math::multiply(stan::math::to_vector(mu_1), + stan::model::rvalue(q, "q", stan::model::index_uni(i))), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni((i + 1))); + } + current_statement__ = 28; + for (int j = 1; j <= C; ++j) { + current_statement__ = 26; + stan::model::assign(log_lik, + stan::math::neg_binomial_2_lpmf( + stan::model::rvalue(E, "E", stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * + stan::model::rvalue(mu_1, "mu_1", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + phi), "assigning variable log_lik", stan::model::index_uni(j)); + } + current_statement__ = 31; + for (int i = 1; i <= S; ++i) { + current_statement__ = 29; + stan::model::assign(log_lik, + stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", stan::model::index_uni(i)), + stan::model::rvalue(N, "N", stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", stan::model::index_uni(i))))), + "assigning variable log_lik", stan::model::index_uni((C + i))); + } + out__.write(q); + out__.write(log_lik); + out__.write(mu); + out__.write(p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(mu_1, + in__.read>(Nloc), + "assigning variable mu_1"); + out__.write_free_lb(0, mu_1); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = in__.read(); + out__.write_free_lb(0, phi); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 3; + beta = in__.read(); + out__.write(beta); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 4; + log_p10 = in__.read(); + out__.write_free_ub(0, log_p10); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 5; + stan::model::assign(q_trans, + in__.read>(nparams), + "assigning variable q_trans"); + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "mu_1", "double", + std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "phi", "double", + std::vector{}); + current_statement__ = 3; + context__.validate_dims("parameter initialization", "beta", "double", + std::vector{}); + current_statement__ = 4; + context__.validate_dims("parameter initialization", "log_p10", + "double", std::vector{}); + current_statement__ = 5; + context__.validate_dims("parameter initialization", "q_trans", + "double", std::vector{static_cast(nparams)}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu_1 = context__.vals_r("mu_1"); + out__.write_free_lb(0, mu_1); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = context__.vals_r("phi")[(1 - 1)]; + out__.write_free_lb(0, phi); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 3; + beta = context__.vals_r("beta")[(1 - 1)]; + out__.write(beta); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 4; + log_p10 = context__.vals_r("log_p10")[(1 - 1)]; + out__.write_free_ub(0, log_p10); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + { + std::vector q_trans_flat__; + current_statement__ = 5; + q_trans_flat__ = context__.vals_r("q_trans"); + current_statement__ = 5; + pos__ = 1; + current_statement__ = 5; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 5; + stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], + "assigning variable q_trans", stan::model::index_uni(sym1__)); + current_statement__ = 5; + pos__ = (pos__ + 1); + } + } + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"mu_1", "phi", "beta", "log_p10", + "q_trans"}; + if (emit_transformed_parameters__) { + std::vector temp{"p11", "p", "coef"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"q", "log_lik", "mu", "p10"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{}, std::vector{}, + std::vector{}, + std::vector{static_cast(nparams)}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(C)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(nparams)}, + std::vector{static_cast(log_lik_1dim__)}, + std::vector{static_cast(Nloc), + static_cast(mu_2dim__)}, std::vector{}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "phi"); + param_names__.emplace_back(std::string() + "beta"); + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "phi"); + param_names__.emplace_back(std::string() + "beta"); + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((((Nloc + 1) + 1) + 1) + nparams); + const size_t num_transformed = emit_transformed_parameters * (((Nloc + + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * ((((nparams + + log_lik_1dim__) + (Nloc * mu_2dim__)) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((((Nloc + 1) + 1) + 1) + nparams); + const size_t num_transformed = emit_transformed_parameters * (((Nloc + + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * ((((nparams + + log_lik_1dim__) + (Nloc * mu_2dim__)) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_joint_binary_catchability_negbin_namespace::model_joint_binary_catchability_negbin; +#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_joint_binary_catchability_negbin_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_joint_binary_catchability_pois.h b/src/stanExports_joint_binary_catchability_pois.h index 246bd36..945db74 100644 --- a/src/stanExports_joint_binary_catchability_pois.h +++ b/src/stanExports_joint_binary_catchability_pois.h @@ -1,922 +1,922 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_joint_binary_catchability_pois_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'joint_binary_catchability_pois', line 15, column 4 to column 35)", - " (in 'joint_binary_catchability_pois', line 16, column 4 to column 14)", - " (in 'joint_binary_catchability_pois', line 17, column 4 to column 26)", - " (in 'joint_binary_catchability_pois', line 18, column 4 to column 44)", - " (in 'joint_binary_catchability_pois', line 21, column 2 to column 43)", - " (in 'joint_binary_catchability_pois', line 22, column 2 to column 40)", - " (in 'joint_binary_catchability_pois', line 23, column 2 to column 26)", - " (in 'joint_binary_catchability_pois', line 44, column 2 to column 20)", - " (in 'joint_binary_catchability_pois', line 45, column 2 to column 22)", - " (in 'joint_binary_catchability_pois', line 46, column 2 to column 28)", - " (in 'joint_binary_catchability_pois', line 47, column 2 to column 11)", - " (in 'joint_binary_catchability_pois', line 25, column 4 to column 45)", - " (in 'joint_binary_catchability_pois', line 26, column 4 to column 33)", - " (in 'joint_binary_catchability_pois', line 24, column 19 to line 27, column 3)", - " (in 'joint_binary_catchability_pois', line 24, column 2 to line 27, column 3)", - " (in 'joint_binary_catchability_pois', line 29, column 6 to column 48)", - " (in 'joint_binary_catchability_pois', line 28, column 15 to line 30, column 5)", - " (in 'joint_binary_catchability_pois', line 28, column 2 to line 30, column 5)", - " (in 'joint_binary_catchability_pois', line 48, column 2 to column 21)", - " (in 'joint_binary_catchability_pois', line 49, column 2 to column 18)", - " (in 'joint_binary_catchability_pois', line 50, column 2 to column 27)", - " (in 'joint_binary_catchability_pois', line 52, column 4 to column 36)", - " (in 'joint_binary_catchability_pois', line 51, column 21 to line 53, column 3)", - " (in 'joint_binary_catchability_pois', line 51, column 2 to line 53, column 3)", - " (in 'joint_binary_catchability_pois', line 55, column 10 to column 63)", - " (in 'joint_binary_catchability_pois', line 54, column 17 to line 56, column 7)", - " (in 'joint_binary_catchability_pois', line 54, column 4 to line 56, column 7)", - " (in 'joint_binary_catchability_pois', line 58, column 10 to column 61)", - " (in 'joint_binary_catchability_pois', line 57, column 19 to line 59, column 7)", - " (in 'joint_binary_catchability_pois', line 57, column 6 to line 59, column 7)", - " (in 'joint_binary_catchability_pois', line 34, column 8 to column 43)", - " (in 'joint_binary_catchability_pois', line 33, column 17 to line 35, column 5)", - " (in 'joint_binary_catchability_pois', line 33, column 4 to line 35, column 5)", - " (in 'joint_binary_catchability_pois', line 37, column 8 to column 39)", - " (in 'joint_binary_catchability_pois', line 36, column 18 to line 38, column 5)", - " (in 'joint_binary_catchability_pois', line 36, column 4 to line 38, column 5)", - " (in 'joint_binary_catchability_pois', line 40, column 2 to column 47)", - " (in 'joint_binary_catchability_pois', line 41, column 2 to column 22)", - " (in 'joint_binary_catchability_pois', line 2, column 4 to column 19)", - " (in 'joint_binary_catchability_pois', line 3, column 4 to column 19)", - " (in 'joint_binary_catchability_pois', line 4, column 10 to column 11)", - " (in 'joint_binary_catchability_pois', line 4, column 4 to column 28)", - " (in 'joint_binary_catchability_pois', line 5, column 10 to column 11)", - " (in 'joint_binary_catchability_pois', line 5, column 4 to column 28)", - " (in 'joint_binary_catchability_pois', line 6, column 4 to column 22)", - " (in 'joint_binary_catchability_pois', line 7, column 10 to column 11)", - " (in 'joint_binary_catchability_pois', line 7, column 4 to column 28)", - " (in 'joint_binary_catchability_pois', line 8, column 10 to column 11)", - " (in 'joint_binary_catchability_pois', line 8, column 4 to column 28)", - " (in 'joint_binary_catchability_pois', line 9, column 10 to column 11)", - " (in 'joint_binary_catchability_pois', line 9, column 4 to column 28)", - " (in 'joint_binary_catchability_pois', line 10, column 4 to column 28)", - " (in 'joint_binary_catchability_pois', line 11, column 4 to column 25)", - " (in 'joint_binary_catchability_pois', line 12, column 11 to column 12)", - " (in 'joint_binary_catchability_pois', line 12, column 13 to column 20)", - " (in 'joint_binary_catchability_pois', line 12, column 4 to column 26)", - " (in 'joint_binary_catchability_pois', line 15, column 10 to column 14)", - " (in 'joint_binary_catchability_pois', line 18, column 27 to column 34)", - " (in 'joint_binary_catchability_pois', line 21, column 8 to column 12)", - " (in 'joint_binary_catchability_pois', line 22, column 8 to column 12)", - " (in 'joint_binary_catchability_pois', line 23, column 18 to column 19)", - " (in 'joint_binary_catchability_pois', line 44, column 9 to column 16)", - " (in 'joint_binary_catchability_pois', line 45, column 9 to column 12)", - " (in 'joint_binary_catchability_pois', line 46, column 9 to column 13)", - " (in 'joint_binary_catchability_pois', line 46, column 14 to column 23)"}; -#include -class model_joint_binary_catchability_pois final : public model_base_crtp { -private: - int S; - int C; - std::vector L; - std::vector R; - int Nloc; - std::vector E; - std::vector N; - std::vector K; - std::vector p10priors; - int nparams; - Eigen::Matrix mat_data__; - int log_lik_1dim__; - int mu_2dim__; - Eigen::Map> mat{nullptr, 0, 0}; -public: - ~model_joint_binary_catchability_pois() {} - model_joint_binary_catchability_pois(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_joint_binary_catchability_pois_namespace::model_joint_binary_catchability_pois"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 39; - context__.validate_dims("data initialization", "S", "int", - std::vector{}); - S = std::numeric_limits::min(); - current_statement__ = 39; - S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 39; - stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 40; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 40; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 40; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 41; - stan::math::validate_non_negative_index("L", "S", S); - current_statement__ = 42; - context__.validate_dims("data initialization", "L", "int", - std::vector{static_cast(S)}); - L = std::vector(S, std::numeric_limits::min()); - current_statement__ = 42; - L = context__.vals_i("L"); - current_statement__ = 42; - stan::math::check_greater_or_equal(function__, "L", L, 1); - current_statement__ = 43; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 44; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 44; - R = context__.vals_i("R"); - current_statement__ = 44; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 45; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 45; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 45; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 46; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 47; - context__.validate_dims("data initialization", "E", "int", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::min()); - current_statement__ = 47; - E = context__.vals_i("E"); - current_statement__ = 47; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 48; - stan::math::validate_non_negative_index("N", "S", S); - current_statement__ = 49; - context__.validate_dims("data initialization", "N", "int", - std::vector{static_cast(S)}); - N = std::vector(S, std::numeric_limits::min()); - current_statement__ = 49; - N = context__.vals_i("N"); - current_statement__ = 49; - stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 50; - stan::math::validate_non_negative_index("K", "S", S); - current_statement__ = 51; - context__.validate_dims("data initialization", "K", "int", - std::vector{static_cast(S)}); - K = std::vector(S, std::numeric_limits::min()); - current_statement__ = 51; - K = context__.vals_i("K"); - current_statement__ = 51; - stan::math::check_greater_or_equal(function__, "K", K, 0); - current_statement__ = 52; - context__.validate_dims("data initialization", "p10priors", "double", - std::vector{static_cast(2)}); - p10priors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 52; - p10priors = context__.vals_r("p10priors"); - current_statement__ = 53; - context__.validate_dims("data initialization", "nparams", "int", - std::vector{}); - nparams = std::numeric_limits::min(); - current_statement__ = 53; - nparams = context__.vals_i("nparams")[(1 - 1)]; - current_statement__ = 53; - stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); - current_statement__ = 54; - stan::math::validate_non_negative_index("mat", "C", C); - current_statement__ = 55; - stan::math::validate_non_negative_index("mat", "nparams", nparams); - current_statement__ = 56; - context__.validate_dims("data initialization", "mat", "double", - std::vector{static_cast(C), - static_cast(nparams)}); - mat_data__ = Eigen::Matrix::Constant(C, nparams, - std::numeric_limits::quiet_NaN()); - new (&mat) Eigen::Map>(mat_data__.data(), - C, nparams); - { - std::vector mat_flat__; - current_statement__ = 56; - mat_flat__ = context__.vals_r("mat"); - current_statement__ = 56; - pos__ = 1; - current_statement__ = 56; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 56; - for (int sym2__ = 1; sym2__ <= C; ++sym2__) { - current_statement__ = 56; - stan::model::assign(mat, mat_flat__[(pos__ - 1)], - "assigning variable mat", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 56; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 57; - stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); - current_statement__ = 58; - stan::math::validate_non_negative_index("q_trans", "nparams", nparams); - current_statement__ = 59; - stan::math::validate_non_negative_index("p11", "Nloc", Nloc); - current_statement__ = 60; - stan::math::validate_non_negative_index("p", "Nloc", Nloc); - current_statement__ = 61; - stan::math::validate_non_negative_index("coef", "C", C); - current_statement__ = 62; - stan::math::validate_non_negative_index("q", "nparams", nparams); - current_statement__ = 63; - log_lik_1dim__ = std::numeric_limits::min(); - current_statement__ = 63; - log_lik_1dim__ = (C + S); - current_statement__ = 63; - stan::math::validate_non_negative_index("log_lik", "C + S", - log_lik_1dim__); - current_statement__ = 64; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 65; - mu_2dim__ = std::numeric_limits::min(); - current_statement__ = 65; - mu_2dim__ = (nparams + 1); - current_statement__ = 65; - stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + 1 + 1 + nparams; - } - inline std::string model_name() const final { - return "model_joint_binary_catchability_pois"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_joint_binary_catchability_pois_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu_1 = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 2; - beta = in__.template read(); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 4; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - std::vector p11 = - std::vector(Nloc, DUMMY_VAR__); - std::vector p = - std::vector(Nloc, DUMMY_VAR__); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, DUMMY_VAR__); - current_statement__ = 15; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 12; - stan::model::assign(p11, - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + - stan::math::exp(beta))), "assigning variable p11", - stan::model::index_uni(i)); - current_statement__ = 13; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 18; - for (int k = 1; k <= C; ++k) { - current_statement__ = 16; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), - q_trans)), "assigning variable coef", stan::model::index_uni(k)); - } - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 5; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - { - current_statement__ = 33; - for (int j = 1; j <= C; ++j) { - current_statement__ = 31; - lp_accum__.add(stan::math::poisson_lpmf( - stan::model::rvalue(E, "E", - stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", - stan::model::index_uni(j)) * - stan::model::rvalue(mu_1, "mu_1", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j))))))); - } - current_statement__ = 36; - for (int i = 1; i <= S; ++i) { - current_statement__ = 34; - lp_accum__.add(stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", - stan::model::index_uni(i)), - stan::model::rvalue(N, "N", - stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", - stan::model::index_uni(i)))))); - } - current_statement__ = 37; - lp_accum__.add(stan::math::normal_lpdf(log_p10, - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(1)), - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(2)))); - current_statement__ = 38; - lp_accum__.add(stan::math::normal_lpdf(beta, 0, 10)); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_joint_binary_catchability_pois_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector mu_1 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - mu_1 = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - double beta = std::numeric_limits::quiet_NaN(); - current_statement__ = 2; - beta = in__.template read(); - double log_p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 3; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - current_statement__ = 4; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - std::vector p11 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector p = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - out__.write(mu_1); - out__.write(beta); - out__.write(log_p10); - out__.write(q_trans); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 15; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 12; - stan::model::assign(p11, - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + - stan::math::exp(beta))), "assigning variable p11", - stan::model::index_uni(i)); - current_statement__ = 13; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 18; - for (int k = 1; k <= C; ++k) { - current_statement__ = 16; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), - q_trans)), "assigning variable coef", stan::model::index_uni(k)); - } - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 5; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - if (emit_transformed_parameters__) { - out__.write(p11); - out__.write(p); - out__.write(coef); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix q = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(log_lik_1dim__, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix mu = - Eigen::Matrix::Constant(Nloc, mu_2dim__, - std::numeric_limits::quiet_NaN()); - double p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 19; - p10 = stan::math::exp(log_p10); - current_statement__ = 20; - stan::model::assign(q, stan::math::add(q_trans, 1), - "assigning variable q"); - current_statement__ = 21; - stan::model::assign(mu, stan::math::to_vector(mu_1), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni(1)); - current_statement__ = 24; - for (int i = 1; i <= nparams; ++i) { - current_statement__ = 22; - stan::model::assign(mu, - stan::math::multiply(stan::math::to_vector(mu_1), - stan::model::rvalue(q, "q", stan::model::index_uni(i))), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni((i + 1))); - } - current_statement__ = 27; - for (int j = 1; j <= C; ++j) { - current_statement__ = 25; - stan::model::assign(log_lik, - stan::math::poisson_lpmf( - stan::model::rvalue(E, "E", stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * - stan::model::rvalue(mu_1, "mu_1", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j)))))), - "assigning variable log_lik", stan::model::index_uni(j)); - } - current_statement__ = 30; - for (int i = 1; i <= S; ++i) { - current_statement__ = 28; - stan::model::assign(log_lik, - stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", stan::model::index_uni(i)), - stan::model::rvalue(N, "N", stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", stan::model::index_uni(i))))), - "assigning variable log_lik", stan::model::index_uni((C + i))); - } - out__.write(q); - out__.write(log_lik); - out__.write(mu); - out__.write(p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(mu_1, - in__.read>(Nloc), - "assigning variable mu_1"); - out__.write_free_lb(0, mu_1); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 2; - beta = in__.read(); - out__.write(beta); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = in__.read(); - out__.write_free_ub(0, log_p10); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 4; - stan::model::assign(q_trans, - in__.read>(nparams), - "assigning variable q_trans"); - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "mu_1", "double", - std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "beta", "double", - std::vector{}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "log_p10", - "double", std::vector{}); - current_statement__ = 4; - context__.validate_dims("parameter initialization", "q_trans", - "double", std::vector{static_cast(nparams)}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu_1 = context__.vals_r("mu_1"); - out__.write_free_lb(0, mu_1); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 2; - beta = context__.vals_r("beta")[(1 - 1)]; - out__.write(beta); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = context__.vals_r("log_p10")[(1 - 1)]; - out__.write_free_ub(0, log_p10); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - { - std::vector q_trans_flat__; - current_statement__ = 4; - q_trans_flat__ = context__.vals_r("q_trans"); - current_statement__ = 4; - pos__ = 1; - current_statement__ = 4; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 4; - stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], - "assigning variable q_trans", stan::model::index_uni(sym1__)); - current_statement__ = 4; - pos__ = (pos__ + 1); - } - } - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"mu_1", "beta", "log_p10", "q_trans"}; - if (emit_transformed_parameters__) { - std::vector temp{"p11", "p", "coef"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"q", "log_lik", "mu", "p10"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{}, std::vector{}, - std::vector{static_cast(nparams)}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(C)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(nparams)}, - std::vector{static_cast(log_lik_1dim__)}, - std::vector{static_cast(Nloc), - static_cast(mu_2dim__)}, std::vector{}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "beta"); - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "beta"); - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (((Nloc + 1) + 1) + nparams); - const size_t num_transformed = emit_transformed_parameters * (((Nloc + - Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * ((((nparams - + log_lik_1dim__) + (Nloc * mu_2dim__)) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (((Nloc + 1) + 1) + nparams); - const size_t num_transformed = emit_transformed_parameters * (((Nloc + - Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * ((((nparams - + log_lik_1dim__) + (Nloc * mu_2dim__)) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_joint_binary_catchability_pois_namespace::model_joint_binary_catchability_pois; -#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_joint_binary_catchability_pois_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_joint_binary_catchability_pois_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 15, column 4 to column 35)", + " (in 'string', line 16, column 4 to column 14)", + " (in 'string', line 17, column 4 to column 26)", + " (in 'string', line 18, column 4 to column 44)", + " (in 'string', line 21, column 2 to column 43)", + " (in 'string', line 22, column 2 to column 40)", + " (in 'string', line 23, column 2 to column 26)", + " (in 'string', line 44, column 2 to column 20)", + " (in 'string', line 45, column 2 to column 22)", + " (in 'string', line 46, column 2 to column 28)", + " (in 'string', line 47, column 2 to column 11)", + " (in 'string', line 25, column 4 to column 45)", + " (in 'string', line 26, column 4 to column 33)", + " (in 'string', line 24, column 19 to line 27, column 3)", + " (in 'string', line 24, column 2 to line 27, column 3)", + " (in 'string', line 29, column 6 to column 48)", + " (in 'string', line 28, column 15 to line 30, column 5)", + " (in 'string', line 28, column 2 to line 30, column 5)", + " (in 'string', line 48, column 2 to column 21)", + " (in 'string', line 49, column 2 to column 18)", + " (in 'string', line 50, column 2 to column 27)", + " (in 'string', line 52, column 4 to column 36)", + " (in 'string', line 51, column 21 to line 53, column 3)", + " (in 'string', line 51, column 2 to line 53, column 3)", + " (in 'string', line 55, column 10 to column 63)", + " (in 'string', line 54, column 17 to line 56, column 7)", + " (in 'string', line 54, column 4 to line 56, column 7)", + " (in 'string', line 58, column 10 to column 61)", + " (in 'string', line 57, column 19 to line 59, column 7)", + " (in 'string', line 57, column 6 to line 59, column 7)", + " (in 'string', line 34, column 8 to column 43)", + " (in 'string', line 33, column 17 to line 35, column 5)", + " (in 'string', line 33, column 4 to line 35, column 5)", + " (in 'string', line 37, column 8 to column 39)", + " (in 'string', line 36, column 18 to line 38, column 5)", + " (in 'string', line 36, column 4 to line 38, column 5)", + " (in 'string', line 40, column 2 to column 47)", + " (in 'string', line 41, column 2 to column 22)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 4 to column 19)", + " (in 'string', line 4, column 10 to column 11)", + " (in 'string', line 4, column 4 to column 28)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 22)", + " (in 'string', line 7, column 10 to column 11)", + " (in 'string', line 7, column 4 to column 28)", + " (in 'string', line 8, column 10 to column 11)", + " (in 'string', line 8, column 4 to column 28)", + " (in 'string', line 9, column 10 to column 11)", + " (in 'string', line 9, column 4 to column 28)", + " (in 'string', line 10, column 4 to column 28)", + " (in 'string', line 11, column 4 to column 25)", + " (in 'string', line 12, column 11 to column 12)", + " (in 'string', line 12, column 13 to column 20)", + " (in 'string', line 12, column 4 to column 26)", + " (in 'string', line 15, column 10 to column 14)", + " (in 'string', line 18, column 27 to column 34)", + " (in 'string', line 21, column 8 to column 12)", + " (in 'string', line 22, column 8 to column 12)", + " (in 'string', line 23, column 18 to column 19)", + " (in 'string', line 44, column 9 to column 16)", + " (in 'string', line 45, column 9 to column 12)", + " (in 'string', line 46, column 9 to column 13)", + " (in 'string', line 46, column 14 to column 23)"}; +#include +class model_joint_binary_catchability_pois final : public model_base_crtp { +private: + int S; + int C; + std::vector L; + std::vector R; + int Nloc; + std::vector E; + std::vector N; + std::vector K; + std::vector p10priors; + int nparams; + Eigen::Matrix mat_data__; + int log_lik_1dim__; + int mu_2dim__; + Eigen::Map> mat{nullptr, 0, 0}; +public: + ~model_joint_binary_catchability_pois() {} + model_joint_binary_catchability_pois(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_joint_binary_catchability_pois_namespace::model_joint_binary_catchability_pois"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 39; + context__.validate_dims("data initialization", "S", "int", + std::vector{}); + S = std::numeric_limits::min(); + current_statement__ = 39; + S = context__.vals_i("S")[(1 - 1)]; + current_statement__ = 39; + stan::math::check_greater_or_equal(function__, "S", S, 1); + current_statement__ = 40; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 40; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 40; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 41; + stan::math::validate_non_negative_index("L", "S", S); + current_statement__ = 42; + context__.validate_dims("data initialization", "L", "int", + std::vector{static_cast(S)}); + L = std::vector(S, std::numeric_limits::min()); + current_statement__ = 42; + L = context__.vals_i("L"); + current_statement__ = 42; + stan::math::check_greater_or_equal(function__, "L", L, 1); + current_statement__ = 43; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 44; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 44; + R = context__.vals_i("R"); + current_statement__ = 44; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 45; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 45; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 45; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 46; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 47; + context__.validate_dims("data initialization", "E", "int", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::min()); + current_statement__ = 47; + E = context__.vals_i("E"); + current_statement__ = 47; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 48; + stan::math::validate_non_negative_index("N", "S", S); + current_statement__ = 49; + context__.validate_dims("data initialization", "N", "int", + std::vector{static_cast(S)}); + N = std::vector(S, std::numeric_limits::min()); + current_statement__ = 49; + N = context__.vals_i("N"); + current_statement__ = 49; + stan::math::check_greater_or_equal(function__, "N", N, 1); + current_statement__ = 50; + stan::math::validate_non_negative_index("K", "S", S); + current_statement__ = 51; + context__.validate_dims("data initialization", "K", "int", + std::vector{static_cast(S)}); + K = std::vector(S, std::numeric_limits::min()); + current_statement__ = 51; + K = context__.vals_i("K"); + current_statement__ = 51; + stan::math::check_greater_or_equal(function__, "K", K, 0); + current_statement__ = 52; + context__.validate_dims("data initialization", "p10priors", "double", + std::vector{static_cast(2)}); + p10priors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 52; + p10priors = context__.vals_r("p10priors"); + current_statement__ = 53; + context__.validate_dims("data initialization", "nparams", "int", + std::vector{}); + nparams = std::numeric_limits::min(); + current_statement__ = 53; + nparams = context__.vals_i("nparams")[(1 - 1)]; + current_statement__ = 53; + stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); + current_statement__ = 54; + stan::math::validate_non_negative_index("mat", "C", C); + current_statement__ = 55; + stan::math::validate_non_negative_index("mat", "nparams", nparams); + current_statement__ = 56; + context__.validate_dims("data initialization", "mat", "double", + std::vector{static_cast(C), + static_cast(nparams)}); + mat_data__ = Eigen::Matrix::Constant(C, nparams, + std::numeric_limits::quiet_NaN()); + new (&mat) Eigen::Map>(mat_data__.data(), + C, nparams); + { + std::vector mat_flat__; + current_statement__ = 56; + mat_flat__ = context__.vals_r("mat"); + current_statement__ = 56; + pos__ = 1; + current_statement__ = 56; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 56; + for (int sym2__ = 1; sym2__ <= C; ++sym2__) { + current_statement__ = 56; + stan::model::assign(mat, mat_flat__[(pos__ - 1)], + "assigning variable mat", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 56; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 57; + stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); + current_statement__ = 58; + stan::math::validate_non_negative_index("q_trans", "nparams", nparams); + current_statement__ = 59; + stan::math::validate_non_negative_index("p11", "Nloc", Nloc); + current_statement__ = 60; + stan::math::validate_non_negative_index("p", "Nloc", Nloc); + current_statement__ = 61; + stan::math::validate_non_negative_index("coef", "C", C); + current_statement__ = 62; + stan::math::validate_non_negative_index("q", "nparams", nparams); + current_statement__ = 63; + log_lik_1dim__ = std::numeric_limits::min(); + current_statement__ = 63; + log_lik_1dim__ = (C + S); + current_statement__ = 63; + stan::math::validate_non_negative_index("log_lik", "C + S", + log_lik_1dim__); + current_statement__ = 64; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 65; + mu_2dim__ = std::numeric_limits::min(); + current_statement__ = 65; + mu_2dim__ = (nparams + 1); + current_statement__ = 65; + stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + 1 + 1 + nparams; + } + inline std::string model_name() const final { + return "model_joint_binary_catchability_pois"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_joint_binary_catchability_pois_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu_1 = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 2; + beta = in__.template read(); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 4; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + std::vector p11 = + std::vector(Nloc, DUMMY_VAR__); + std::vector p = + std::vector(Nloc, DUMMY_VAR__); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, DUMMY_VAR__); + current_statement__ = 15; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 12; + stan::model::assign(p11, + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + + stan::math::exp(beta))), "assigning variable p11", + stan::model::index_uni(i)); + current_statement__ = 13; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 18; + for (int k = 1; k <= C; ++k) { + current_statement__ = 16; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), + q_trans)), "assigning variable coef", stan::model::index_uni(k)); + } + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 5; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + { + current_statement__ = 33; + for (int j = 1; j <= C; ++j) { + current_statement__ = 31; + lp_accum__.add(stan::math::poisson_lpmf( + stan::model::rvalue(E, "E", + stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", + stan::model::index_uni(j)) * + stan::model::rvalue(mu_1, "mu_1", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j))))))); + } + current_statement__ = 36; + for (int i = 1; i <= S; ++i) { + current_statement__ = 34; + lp_accum__.add(stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", + stan::model::index_uni(i)), + stan::model::rvalue(N, "N", + stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", + stan::model::index_uni(i)))))); + } + current_statement__ = 37; + lp_accum__.add(stan::math::normal_lpdf(log_p10, + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(1)), + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(2)))); + current_statement__ = 38; + lp_accum__.add(stan::math::normal_lpdf(beta, 0, 10)); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_joint_binary_catchability_pois_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector mu_1 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + mu_1 = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + double beta = std::numeric_limits::quiet_NaN(); + current_statement__ = 2; + beta = in__.template read(); + double log_p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + current_statement__ = 4; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + std::vector p11 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector p = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + out__.write(mu_1); + out__.write(beta); + out__.write(log_p10); + out__.write(q_trans); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 15; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 12; + stan::model::assign(p11, + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + + stan::math::exp(beta))), "assigning variable p11", + stan::model::index_uni(i)); + current_statement__ = 13; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 18; + for (int k = 1; k <= C; ++k) { + current_statement__ = 16; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), + q_trans)), "assigning variable coef", stan::model::index_uni(k)); + } + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 5; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + if (emit_transformed_parameters__) { + out__.write(p11); + out__.write(p); + out__.write(coef); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix q = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(log_lik_1dim__, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix mu = + Eigen::Matrix::Constant(Nloc, mu_2dim__, + std::numeric_limits::quiet_NaN()); + double p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 19; + p10 = stan::math::exp(log_p10); + current_statement__ = 20; + stan::model::assign(q, stan::math::add(q_trans, 1), + "assigning variable q"); + current_statement__ = 21; + stan::model::assign(mu, stan::math::to_vector(mu_1), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni(1)); + current_statement__ = 24; + for (int i = 1; i <= nparams; ++i) { + current_statement__ = 22; + stan::model::assign(mu, + stan::math::multiply(stan::math::to_vector(mu_1), + stan::model::rvalue(q, "q", stan::model::index_uni(i))), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni((i + 1))); + } + current_statement__ = 27; + for (int j = 1; j <= C; ++j) { + current_statement__ = 25; + stan::model::assign(log_lik, + stan::math::poisson_lpmf( + stan::model::rvalue(E, "E", stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * + stan::model::rvalue(mu_1, "mu_1", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j)))))), + "assigning variable log_lik", stan::model::index_uni(j)); + } + current_statement__ = 30; + for (int i = 1; i <= S; ++i) { + current_statement__ = 28; + stan::model::assign(log_lik, + stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", stan::model::index_uni(i)), + stan::model::rvalue(N, "N", stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", stan::model::index_uni(i))))), + "assigning variable log_lik", stan::model::index_uni((C + i))); + } + out__.write(q); + out__.write(log_lik); + out__.write(mu); + out__.write(p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(mu_1, + in__.read>(Nloc), + "assigning variable mu_1"); + out__.write_free_lb(0, mu_1); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 2; + beta = in__.read(); + out__.write(beta); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = in__.read(); + out__.write_free_ub(0, log_p10); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 4; + stan::model::assign(q_trans, + in__.read>(nparams), + "assigning variable q_trans"); + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "mu_1", "double", + std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "beta", "double", + std::vector{}); + current_statement__ = 3; + context__.validate_dims("parameter initialization", "log_p10", + "double", std::vector{}); + current_statement__ = 4; + context__.validate_dims("parameter initialization", "q_trans", + "double", std::vector{static_cast(nparams)}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu_1 = context__.vals_r("mu_1"); + out__.write_free_lb(0, mu_1); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 2; + beta = context__.vals_r("beta")[(1 - 1)]; + out__.write(beta); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = context__.vals_r("log_p10")[(1 - 1)]; + out__.write_free_ub(0, log_p10); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + { + std::vector q_trans_flat__; + current_statement__ = 4; + q_trans_flat__ = context__.vals_r("q_trans"); + current_statement__ = 4; + pos__ = 1; + current_statement__ = 4; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 4; + stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], + "assigning variable q_trans", stan::model::index_uni(sym1__)); + current_statement__ = 4; + pos__ = (pos__ + 1); + } + } + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"mu_1", "beta", "log_p10", "q_trans"}; + if (emit_transformed_parameters__) { + std::vector temp{"p11", "p", "coef"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"q", "log_lik", "mu", "p10"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{}, std::vector{}, + std::vector{static_cast(nparams)}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(C)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(nparams)}, + std::vector{static_cast(log_lik_1dim__)}, + std::vector{static_cast(Nloc), + static_cast(mu_2dim__)}, std::vector{}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "beta"); + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "beta"); + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (((Nloc + 1) + 1) + nparams); + const size_t num_transformed = emit_transformed_parameters * (((Nloc + + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * ((((nparams + + log_lik_1dim__) + (Nloc * mu_2dim__)) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (((Nloc + 1) + 1) + nparams); + const size_t num_transformed = emit_transformed_parameters * (((Nloc + + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * ((((nparams + + log_lik_1dim__) + (Nloc * mu_2dim__)) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_joint_binary_catchability_pois_namespace::model_joint_binary_catchability_pois; +#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_joint_binary_catchability_pois_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_joint_binary_cov_catchability_gamma.h b/src/stanExports_joint_binary_cov_catchability_gamma.h index 378e81b..8fa5186 100644 --- a/src/stanExports_joint_binary_cov_catchability_gamma.h +++ b/src/stanExports_joint_binary_cov_catchability_gamma.h @@ -1,1174 +1,1174 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_joint_binary_cov_catchability_gamma_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'joint_binary_cov_catchability_gamma', line 17, column 4 to column 42)", - " (in 'joint_binary_cov_catchability_gamma', line 18, column 4 to column 45)", - " (in 'joint_binary_cov_catchability_gamma', line 19, column 4 to column 26)", - " (in 'joint_binary_cov_catchability_gamma', line 20, column 4 to column 27)", - " (in 'joint_binary_cov_catchability_gamma', line 21, column 4 to column 44)", - " (in 'joint_binary_cov_catchability_gamma', line 24, column 2 to column 43)", - " (in 'joint_binary_cov_catchability_gamma', line 25, column 2 to column 41)", - " (in 'joint_binary_cov_catchability_gamma', line 26, column 2 to column 26)", - " (in 'joint_binary_cov_catchability_gamma', line 27, column 2 to column 33)", - " (in 'joint_binary_cov_catchability_gamma', line 28, column 2 to column 33)", - " (in 'joint_binary_cov_catchability_gamma', line 55, column 2 to column 20)", - " (in 'joint_binary_cov_catchability_gamma', line 56, column 2 to column 22)", - " (in 'joint_binary_cov_catchability_gamma', line 57, column 2 to column 20)", - " (in 'joint_binary_cov_catchability_gamma', line 58, column 2 to column 28)", - " (in 'joint_binary_cov_catchability_gamma', line 59, column 2 to column 11)", - " (in 'joint_binary_cov_catchability_gamma', line 30, column 4 to column 43)", - " (in 'joint_binary_cov_catchability_gamma', line 31, column 4 to column 71)", - " (in 'joint_binary_cov_catchability_gamma', line 32, column 4 to column 33)", - " (in 'joint_binary_cov_catchability_gamma', line 29, column 19 to line 33, column 3)", - " (in 'joint_binary_cov_catchability_gamma', line 29, column 2 to line 33, column 3)", - " (in 'joint_binary_cov_catchability_gamma', line 35, column 6 to column 48)", - " (in 'joint_binary_cov_catchability_gamma', line 34, column 15 to line 36, column 5)", - " (in 'joint_binary_cov_catchability_gamma', line 34, column 2 to line 36, column 5)", - " (in 'joint_binary_cov_catchability_gamma', line 38, column 6 to column 42)", - " (in 'joint_binary_cov_catchability_gamma', line 37, column 17 to line 39, column 5)", - " (in 'joint_binary_cov_catchability_gamma', line 37, column 4 to line 39, column 5)", - " (in 'joint_binary_cov_catchability_gamma', line 60, column 2 to column 21)", - " (in 'joint_binary_cov_catchability_gamma', line 62, column 4 to column 45)", - " (in 'joint_binary_cov_catchability_gamma', line 61, column 19 to line 63, column 3)", - " (in 'joint_binary_cov_catchability_gamma', line 61, column 2 to line 63, column 3)", - " (in 'joint_binary_cov_catchability_gamma', line 64, column 2 to column 18)", - " (in 'joint_binary_cov_catchability_gamma', line 65, column 2 to column 27)", - " (in 'joint_binary_cov_catchability_gamma', line 67, column 4 to column 36)", - " (in 'joint_binary_cov_catchability_gamma', line 66, column 21 to line 68, column 3)", - " (in 'joint_binary_cov_catchability_gamma', line 66, column 2 to line 68, column 3)", - " (in 'joint_binary_cov_catchability_gamma', line 70, column 10 to column 92)", - " (in 'joint_binary_cov_catchability_gamma', line 69, column 17 to line 71, column 7)", - " (in 'joint_binary_cov_catchability_gamma', line 69, column 4 to line 71, column 7)", - " (in 'joint_binary_cov_catchability_gamma', line 73, column 10 to column 61)", - " (in 'joint_binary_cov_catchability_gamma', line 72, column 19 to line 74, column 7)", - " (in 'joint_binary_cov_catchability_gamma', line 72, column 6 to line 74, column 7)", - " (in 'joint_binary_cov_catchability_gamma', line 43, column 6 to column 69)", - " (in 'joint_binary_cov_catchability_gamma', line 42, column 18 to line 44, column 5)", - " (in 'joint_binary_cov_catchability_gamma', line 42, column 4 to line 44, column 5)", - " (in 'joint_binary_cov_catchability_gamma', line 46, column 8 to column 39)", - " (in 'joint_binary_cov_catchability_gamma', line 45, column 18 to line 47, column 5)", - " (in 'joint_binary_cov_catchability_gamma', line 45, column 4 to line 47, column 5)", - " (in 'joint_binary_cov_catchability_gamma', line 49, column 2 to column 47)", - " (in 'joint_binary_cov_catchability_gamma', line 50, column 2 to column 23)", - " (in 'joint_binary_cov_catchability_gamma', line 51, column 2 to column 32)", - " (in 'joint_binary_cov_catchability_gamma', line 52, column 2 to column 33)", - " (in 'joint_binary_cov_catchability_gamma', line 2, column 4 to column 19)", - " (in 'joint_binary_cov_catchability_gamma', line 3, column 4 to column 19)", - " (in 'joint_binary_cov_catchability_gamma', line 4, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_gamma', line 4, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_gamma', line 5, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_gamma', line 5, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_gamma', line 6, column 4 to column 22)", - " (in 'joint_binary_cov_catchability_gamma', line 7, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_gamma', line 7, column 4 to column 29)", - " (in 'joint_binary_cov_catchability_gamma', line 8, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_gamma', line 8, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_gamma', line 9, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_gamma', line 9, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_gamma', line 10, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_gamma', line 11, column 4 to column 26)", - " (in 'joint_binary_cov_catchability_gamma', line 12, column 11 to column 15)", - " (in 'joint_binary_cov_catchability_gamma', line 12, column 16 to column 24)", - " (in 'joint_binary_cov_catchability_gamma', line 12, column 4 to column 35)", - " (in 'joint_binary_cov_catchability_gamma', line 13, column 4 to column 25)", - " (in 'joint_binary_cov_catchability_gamma', line 14, column 11 to column 12)", - " (in 'joint_binary_cov_catchability_gamma', line 14, column 13 to column 20)", - " (in 'joint_binary_cov_catchability_gamma', line 14, column 4 to column 26)", - " (in 'joint_binary_cov_catchability_gamma', line 17, column 10 to column 14)", - " (in 'joint_binary_cov_catchability_gamma', line 18, column 10 to column 14)", - " (in 'joint_binary_cov_catchability_gamma', line 20, column 11 to column 19)", - " (in 'joint_binary_cov_catchability_gamma', line 21, column 27 to column 34)", - " (in 'joint_binary_cov_catchability_gamma', line 24, column 8 to column 12)", - " (in 'joint_binary_cov_catchability_gamma', line 25, column 8 to column 12)", - " (in 'joint_binary_cov_catchability_gamma', line 26, column 18 to column 19)", - " (in 'joint_binary_cov_catchability_gamma', line 27, column 8 to column 12)", - " (in 'joint_binary_cov_catchability_gamma', line 28, column 8 to column 9)", - " (in 'joint_binary_cov_catchability_gamma', line 55, column 9 to column 16)", - " (in 'joint_binary_cov_catchability_gamma', line 56, column 9 to column 12)", - " (in 'joint_binary_cov_catchability_gamma', line 57, column 9 to column 13)", - " (in 'joint_binary_cov_catchability_gamma', line 58, column 9 to column 13)", - " (in 'joint_binary_cov_catchability_gamma', line 58, column 14 to column 23)"}; -#include -class model_joint_binary_cov_catchability_gamma final : public model_base_crtp { -private: - int S; - int C; - std::vector L; - std::vector R; - int Nloc; - std::vector E; - std::vector N; - std::vector K; - std::vector p10priors; - int nsitecov; - Eigen::Matrix mat_site_data__; - int nparams; - Eigen::Matrix mat_data__; - int log_lik_1dim__; - int mu_2dim__; - Eigen::Map> mat_site{nullptr, 0, 0}; - Eigen::Map> mat{nullptr, 0, 0}; -public: - ~model_joint_binary_cov_catchability_gamma() {} - model_joint_binary_cov_catchability_gamma(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_joint_binary_cov_catchability_gamma_namespace::model_joint_binary_cov_catchability_gamma"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 52; - context__.validate_dims("data initialization", "S", "int", - std::vector{}); - S = std::numeric_limits::min(); - current_statement__ = 52; - S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 52; - stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 53; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 53; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 53; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 54; - stan::math::validate_non_negative_index("L", "S", S); - current_statement__ = 55; - context__.validate_dims("data initialization", "L", "int", - std::vector{static_cast(S)}); - L = std::vector(S, std::numeric_limits::min()); - current_statement__ = 55; - L = context__.vals_i("L"); - current_statement__ = 55; - stan::math::check_greater_or_equal(function__, "L", L, 1); - current_statement__ = 56; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 57; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 57; - R = context__.vals_i("R"); - current_statement__ = 57; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 58; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 58; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 58; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 59; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 60; - context__.validate_dims("data initialization", "E", "double", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::quiet_NaN()); - current_statement__ = 60; - E = context__.vals_r("E"); - current_statement__ = 60; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 61; - stan::math::validate_non_negative_index("N", "S", S); - current_statement__ = 62; - context__.validate_dims("data initialization", "N", "int", - std::vector{static_cast(S)}); - N = std::vector(S, std::numeric_limits::min()); - current_statement__ = 62; - N = context__.vals_i("N"); - current_statement__ = 62; - stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 63; - stan::math::validate_non_negative_index("K", "S", S); - current_statement__ = 64; - context__.validate_dims("data initialization", "K", "int", - std::vector{static_cast(S)}); - K = std::vector(S, std::numeric_limits::min()); - current_statement__ = 64; - K = context__.vals_i("K"); - current_statement__ = 64; - stan::math::check_greater_or_equal(function__, "K", K, 0); - current_statement__ = 65; - context__.validate_dims("data initialization", "p10priors", "double", - std::vector{static_cast(2)}); - p10priors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 65; - p10priors = context__.vals_r("p10priors"); - current_statement__ = 66; - context__.validate_dims("data initialization", "nsitecov", "int", - std::vector{}); - nsitecov = std::numeric_limits::min(); - current_statement__ = 66; - nsitecov = context__.vals_i("nsitecov")[(1 - 1)]; - current_statement__ = 66; - stan::math::check_greater_or_equal(function__, "nsitecov", nsitecov, 0); - current_statement__ = 67; - stan::math::validate_non_negative_index("mat_site", "Nloc", Nloc); - current_statement__ = 68; - stan::math::validate_non_negative_index("mat_site", "nsitecov", - nsitecov); - current_statement__ = 69; - context__.validate_dims("data initialization", "mat_site", "double", - std::vector{static_cast(Nloc), - static_cast(nsitecov)}); - mat_site_data__ = Eigen::Matrix::Constant(Nloc, nsitecov, - std::numeric_limits::quiet_NaN()); - new (&mat_site) - Eigen::Map>(mat_site_data__.data(), Nloc, - nsitecov); - { - std::vector mat_site_flat__; - current_statement__ = 69; - mat_site_flat__ = context__.vals_r("mat_site"); - current_statement__ = 69; - pos__ = 1; - current_statement__ = 69; - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - current_statement__ = 69; - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - current_statement__ = 69; - stan::model::assign(mat_site, mat_site_flat__[(pos__ - 1)], - "assigning variable mat_site", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 69; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 70; - context__.validate_dims("data initialization", "nparams", "int", - std::vector{}); - nparams = std::numeric_limits::min(); - current_statement__ = 70; - nparams = context__.vals_i("nparams")[(1 - 1)]; - current_statement__ = 70; - stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); - current_statement__ = 71; - stan::math::validate_non_negative_index("mat", "C", C); - current_statement__ = 72; - stan::math::validate_non_negative_index("mat", "nparams", nparams); - current_statement__ = 73; - context__.validate_dims("data initialization", "mat", "double", - std::vector{static_cast(C), - static_cast(nparams)}); - mat_data__ = Eigen::Matrix::Constant(C, nparams, - std::numeric_limits::quiet_NaN()); - new (&mat) Eigen::Map>(mat_data__.data(), - C, nparams); - { - std::vector mat_flat__; - current_statement__ = 73; - mat_flat__ = context__.vals_r("mat"); - current_statement__ = 73; - pos__ = 1; - current_statement__ = 73; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 73; - for (int sym2__ = 1; sym2__ <= C; ++sym2__) { - current_statement__ = 73; - stan::model::assign(mat, mat_flat__[(pos__ - 1)], - "assigning variable mat", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 73; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 74; - stan::math::validate_non_negative_index("alpha_gamma", "Nloc", Nloc); - current_statement__ = 75; - stan::math::validate_non_negative_index("beta_gamma", "Nloc", Nloc); - current_statement__ = 76; - stan::math::validate_non_negative_index("alpha", "nsitecov", nsitecov); - current_statement__ = 77; - stan::math::validate_non_negative_index("q_trans", "nparams", nparams); - current_statement__ = 78; - stan::math::validate_non_negative_index("p11", "Nloc", Nloc); - current_statement__ = 79; - stan::math::validate_non_negative_index("p", "Nloc", Nloc); - current_statement__ = 80; - stan::math::validate_non_negative_index("coef", "C", C); - current_statement__ = 81; - stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); - current_statement__ = 82; - stan::math::validate_non_negative_index("E_trans", "C", C); - current_statement__ = 83; - stan::math::validate_non_negative_index("q", "nparams", nparams); - current_statement__ = 84; - log_lik_1dim__ = std::numeric_limits::min(); - current_statement__ = 84; - log_lik_1dim__ = (C + S); - current_statement__ = 84; - stan::math::validate_non_negative_index("log_lik", "C + S", - log_lik_1dim__); - current_statement__ = 85; - stan::math::validate_non_negative_index("beta", "Nloc", Nloc); - current_statement__ = 86; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 87; - mu_2dim__ = std::numeric_limits::min(); - current_statement__ = 87; - mu_2dim__ = (nparams + 1); - current_statement__ = 87; - stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + Nloc + 1 + nsitecov + nparams; - } - inline std::string model_name() const final { - return "model_joint_binary_cov_catchability_gamma"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_joint_binary_cov_catchability_gamma_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector alpha_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - alpha_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0, lp__, - Nloc); - std::vector beta_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - beta_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0.01, lp__, - Nloc); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - current_statement__ = 4; - alpha = in__.template read< - Eigen::Matrix>(nsitecov); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 5; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - std::vector p11 = - std::vector(Nloc, DUMMY_VAR__); - std::vector p = - std::vector(Nloc, DUMMY_VAR__); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, DUMMY_VAR__); - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - std::vector E_trans = - std::vector(C, DUMMY_VAR__); - current_statement__ = 20; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 16; - stan::model::assign(mu_1, - (stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni(i)) / - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni(i))), "assigning variable mu_1", - stan::model::index_uni(i)); - current_statement__ = 17; - stan::model::assign(p11, - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + - stan::math::exp( - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha)))), - "assigning variable p11", stan::model::index_uni(i)); - current_statement__ = 18; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 23; - for (int k = 1; k <= C; ++k) { - current_statement__ = 21; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), - q_trans)), "assigning variable coef", stan::model::index_uni(k)); - } - current_statement__ = 26; - for (int j = 1; j <= C; ++j) { - current_statement__ = 24; - stan::model::assign(E_trans, - (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + - 0.0000000000001), "assigning variable E_trans", - stan::model::index_uni(j)); - } - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 7; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 8; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - current_statement__ = 9; - stan::math::check_greater_or_equal(function__, "mu_1", mu_1, 0); - current_statement__ = 10; - stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); - { - current_statement__ = 44; - for (int j = 1; j <= C; ++j) { - current_statement__ = 42; - lp_accum__.add(stan::math::gamma_lpdf( - stan::model::rvalue(E_trans, "E_trans", - stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", - stan::model::index_uni(j)) * - stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j))))), - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))))); - } - current_statement__ = 47; - for (int i = 1; i <= S; ++i) { - current_statement__ = 45; - lp_accum__.add(stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", - stan::model::index_uni(i)), - stan::model::rvalue(N, "N", - stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", - stan::model::index_uni(i)))))); - } - current_statement__ = 48; - lp_accum__.add(stan::math::normal_lpdf(log_p10, - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(1)), - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(2)))); - current_statement__ = 49; - lp_accum__.add(stan::math::normal_lpdf(alpha, 0, 10)); - current_statement__ = 50; - lp_accum__.add(stan::math::gamma_lpdf(beta_gamma, 0.25, - 0.25)); - current_statement__ = 51; - lp_accum__.add(stan::math::gamma_lpdf(alpha_gamma, 0.01, - 0.01)); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_joint_binary_cov_catchability_gamma_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector alpha_gamma = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - alpha_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0, lp__, - Nloc); - std::vector beta_gamma = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 2; - beta_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0.01, lp__, - Nloc); - double log_p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 3; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, - std::numeric_limits::quiet_NaN()); - current_statement__ = 4; - alpha = in__.template read< - Eigen::Matrix>(nsitecov); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - current_statement__ = 5; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - std::vector p11 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector p = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - std::vector mu_1 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector E_trans = - std::vector(C, std::numeric_limits::quiet_NaN()); - out__.write(alpha_gamma); - out__.write(beta_gamma); - out__.write(log_p10); - out__.write(alpha); - out__.write(q_trans); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 20; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 16; - stan::model::assign(mu_1, - (stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni(i)) / - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni(i))), "assigning variable mu_1", - stan::model::index_uni(i)); - current_statement__ = 17; - stan::model::assign(p11, - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + - stan::math::exp( - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha)))), - "assigning variable p11", stan::model::index_uni(i)); - current_statement__ = 18; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 23; - for (int k = 1; k <= C; ++k) { - current_statement__ = 21; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), - q_trans)), "assigning variable coef", stan::model::index_uni(k)); - } - current_statement__ = 26; - for (int j = 1; j <= C; ++j) { - current_statement__ = 24; - stan::model::assign(E_trans, - (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + - 0.0000000000001), "assigning variable E_trans", - stan::model::index_uni(j)); - } - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 7; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 8; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - current_statement__ = 9; - stan::math::check_greater_or_equal(function__, "mu_1", mu_1, 0); - current_statement__ = 10; - stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); - if (emit_transformed_parameters__) { - out__.write(p11); - out__.write(p); - out__.write(coef); - out__.write(mu_1); - out__.write(E_trans); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix q = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(log_lik_1dim__, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix beta = - Eigen::Matrix::Constant(Nloc, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix mu = - Eigen::Matrix::Constant(Nloc, mu_2dim__, - std::numeric_limits::quiet_NaN()); - double p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 27; - p10 = stan::math::exp(log_p10); - current_statement__ = 30; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 28; - stan::model::assign(beta, - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha), "assigning variable beta", - stan::model::index_uni(i)); - } - current_statement__ = 31; - stan::model::assign(q, stan::math::add(q_trans, 1), - "assigning variable q"); - current_statement__ = 32; - stan::model::assign(mu, stan::math::to_vector(mu_1), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni(1)); - current_statement__ = 35; - for (int i = 1; i <= nparams; ++i) { - current_statement__ = 33; - stan::model::assign(mu, - stan::math::multiply(stan::math::to_vector(mu_1), - stan::model::rvalue(q, "q", stan::model::index_uni(i))), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni((i + 1))); - } - current_statement__ = 38; - for (int j = 1; j <= C; ++j) { - current_statement__ = 36; - stan::model::assign(log_lik, - stan::math::gamma_lpdf( - stan::model::rvalue(E_trans, "E_trans", stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * - stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - "assigning variable log_lik", stan::model::index_uni(j)); - } - current_statement__ = 41; - for (int i = 1; i <= S; ++i) { - current_statement__ = 39; - stan::model::assign(log_lik, - stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", stan::model::index_uni(i)), - stan::model::rvalue(N, "N", stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", stan::model::index_uni(i))))), - "assigning variable log_lik", stan::model::index_uni((C + i))); - } - out__.write(q); - out__.write(log_lik); - out__.write(beta); - out__.write(mu); - out__.write(p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector alpha_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(alpha_gamma, - in__.read>(Nloc), - "assigning variable alpha_gamma"); - out__.write_free_lb(0, alpha_gamma); - std::vector beta_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - stan::model::assign(beta_gamma, - in__.read>(Nloc), - "assigning variable beta_gamma"); - out__.write_free_lb(0.01, beta_gamma); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = in__.read(); - out__.write_free_ub(0, log_p10); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - current_statement__ = 4; - stan::model::assign(alpha, - in__.read>(nsitecov), - "assigning variable alpha"); - out__.write(alpha); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 5; - stan::model::assign(q_trans, - in__.read>(nparams), - "assigning variable q_trans"); - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "alpha_gamma", - "double", std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "beta_gamma", - "double", std::vector{static_cast(Nloc)}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "log_p10", - "double", std::vector{}); - current_statement__ = 4; - context__.validate_dims("parameter initialization", "alpha", "double", - std::vector{static_cast(nsitecov)}); - current_statement__ = 5; - context__.validate_dims("parameter initialization", "q_trans", - "double", std::vector{static_cast(nparams)}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector alpha_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - alpha_gamma = context__.vals_r("alpha_gamma"); - out__.write_free_lb(0, alpha_gamma); - std::vector beta_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - beta_gamma = context__.vals_r("beta_gamma"); - out__.write_free_lb(0.01, beta_gamma); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = context__.vals_r("log_p10")[(1 - 1)]; - out__.write_free_ub(0, log_p10); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - { - std::vector alpha_flat__; - current_statement__ = 4; - alpha_flat__ = context__.vals_r("alpha"); - current_statement__ = 4; - pos__ = 1; - current_statement__ = 4; - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - current_statement__ = 4; - stan::model::assign(alpha, alpha_flat__[(pos__ - 1)], - "assigning variable alpha", stan::model::index_uni(sym1__)); - current_statement__ = 4; - pos__ = (pos__ + 1); - } - } - out__.write(alpha); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - { - std::vector q_trans_flat__; - current_statement__ = 5; - q_trans_flat__ = context__.vals_r("q_trans"); - current_statement__ = 5; - pos__ = 1; - current_statement__ = 5; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 5; - stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], - "assigning variable q_trans", stan::model::index_uni(sym1__)); - current_statement__ = 5; - pos__ = (pos__ + 1); - } - } - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"alpha_gamma", "beta_gamma", - "log_p10", "alpha", "q_trans"}; - if (emit_transformed_parameters__) { - std::vector temp{"p11", "p", "coef", "mu_1", "E_trans"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"q", "log_lik", "beta", "mu", "p10"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{}, - std::vector{static_cast(nsitecov)}, - std::vector{static_cast(nparams)}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(C)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(C)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(nparams)}, - std::vector{static_cast(log_lik_1dim__)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc), - static_cast(mu_2dim__)}, std::vector{}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta_gamma" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "E_trans" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta_gamma" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "E_trans" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((((Nloc + Nloc) + 1) + nsitecov) + nparams); - const size_t num_transformed = emit_transformed_parameters * (((((Nloc + - Nloc) + C) + Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * - (((((nparams + log_lik_1dim__) + Nloc) + (Nloc * mu_2dim__)) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((((Nloc + Nloc) + 1) + nsitecov) + nparams); - const size_t num_transformed = emit_transformed_parameters * (((((Nloc + - Nloc) + C) + Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * - (((((nparams + log_lik_1dim__) + Nloc) + (Nloc * mu_2dim__)) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_joint_binary_cov_catchability_gamma_namespace::model_joint_binary_cov_catchability_gamma; -#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_joint_binary_cov_catchability_gamma_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_joint_binary_cov_catchability_gamma_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 17, column 4 to column 42)", + " (in 'string', line 18, column 4 to column 45)", + " (in 'string', line 19, column 4 to column 26)", + " (in 'string', line 20, column 4 to column 27)", + " (in 'string', line 21, column 4 to column 44)", + " (in 'string', line 24, column 2 to column 43)", + " (in 'string', line 25, column 2 to column 41)", + " (in 'string', line 26, column 2 to column 26)", + " (in 'string', line 27, column 2 to column 33)", + " (in 'string', line 28, column 2 to column 33)", + " (in 'string', line 55, column 2 to column 20)", + " (in 'string', line 56, column 2 to column 22)", + " (in 'string', line 57, column 2 to column 20)", + " (in 'string', line 58, column 2 to column 28)", + " (in 'string', line 59, column 2 to column 11)", + " (in 'string', line 30, column 4 to column 43)", + " (in 'string', line 31, column 4 to column 71)", + " (in 'string', line 32, column 4 to column 33)", + " (in 'string', line 29, column 19 to line 33, column 3)", + " (in 'string', line 29, column 2 to line 33, column 3)", + " (in 'string', line 35, column 6 to column 48)", + " (in 'string', line 34, column 15 to line 36, column 5)", + " (in 'string', line 34, column 2 to line 36, column 5)", + " (in 'string', line 38, column 6 to column 42)", + " (in 'string', line 37, column 17 to line 39, column 5)", + " (in 'string', line 37, column 4 to line 39, column 5)", + " (in 'string', line 60, column 2 to column 21)", + " (in 'string', line 62, column 4 to column 45)", + " (in 'string', line 61, column 19 to line 63, column 3)", + " (in 'string', line 61, column 2 to line 63, column 3)", + " (in 'string', line 64, column 2 to column 18)", + " (in 'string', line 65, column 2 to column 27)", + " (in 'string', line 67, column 4 to column 36)", + " (in 'string', line 66, column 21 to line 68, column 3)", + " (in 'string', line 66, column 2 to line 68, column 3)", + " (in 'string', line 70, column 10 to column 92)", + " (in 'string', line 69, column 17 to line 71, column 7)", + " (in 'string', line 69, column 4 to line 71, column 7)", + " (in 'string', line 73, column 10 to column 61)", + " (in 'string', line 72, column 19 to line 74, column 7)", + " (in 'string', line 72, column 6 to line 74, column 7)", + " (in 'string', line 43, column 6 to column 69)", + " (in 'string', line 42, column 18 to line 44, column 5)", + " (in 'string', line 42, column 4 to line 44, column 5)", + " (in 'string', line 46, column 8 to column 39)", + " (in 'string', line 45, column 18 to line 47, column 5)", + " (in 'string', line 45, column 4 to line 47, column 5)", + " (in 'string', line 49, column 2 to column 47)", + " (in 'string', line 50, column 2 to column 23)", + " (in 'string', line 51, column 2 to column 32)", + " (in 'string', line 52, column 2 to column 33)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 4 to column 19)", + " (in 'string', line 4, column 10 to column 11)", + " (in 'string', line 4, column 4 to column 28)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 22)", + " (in 'string', line 7, column 10 to column 11)", + " (in 'string', line 7, column 4 to column 29)", + " (in 'string', line 8, column 10 to column 11)", + " (in 'string', line 8, column 4 to column 28)", + " (in 'string', line 9, column 10 to column 11)", + " (in 'string', line 9, column 4 to column 28)", + " (in 'string', line 10, column 4 to column 28)", + " (in 'string', line 11, column 4 to column 26)", + " (in 'string', line 12, column 11 to column 15)", + " (in 'string', line 12, column 16 to column 24)", + " (in 'string', line 12, column 4 to column 35)", + " (in 'string', line 13, column 4 to column 25)", + " (in 'string', line 14, column 11 to column 12)", + " (in 'string', line 14, column 13 to column 20)", + " (in 'string', line 14, column 4 to column 26)", + " (in 'string', line 17, column 10 to column 14)", + " (in 'string', line 18, column 10 to column 14)", + " (in 'string', line 20, column 11 to column 19)", + " (in 'string', line 21, column 27 to column 34)", + " (in 'string', line 24, column 8 to column 12)", + " (in 'string', line 25, column 8 to column 12)", + " (in 'string', line 26, column 18 to column 19)", + " (in 'string', line 27, column 8 to column 12)", + " (in 'string', line 28, column 8 to column 9)", + " (in 'string', line 55, column 9 to column 16)", + " (in 'string', line 56, column 9 to column 12)", + " (in 'string', line 57, column 9 to column 13)", + " (in 'string', line 58, column 9 to column 13)", + " (in 'string', line 58, column 14 to column 23)"}; +#include +class model_joint_binary_cov_catchability_gamma final : public model_base_crtp { +private: + int S; + int C; + std::vector L; + std::vector R; + int Nloc; + std::vector E; + std::vector N; + std::vector K; + std::vector p10priors; + int nsitecov; + Eigen::Matrix mat_site_data__; + int nparams; + Eigen::Matrix mat_data__; + int log_lik_1dim__; + int mu_2dim__; + Eigen::Map> mat_site{nullptr, 0, 0}; + Eigen::Map> mat{nullptr, 0, 0}; +public: + ~model_joint_binary_cov_catchability_gamma() {} + model_joint_binary_cov_catchability_gamma(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_joint_binary_cov_catchability_gamma_namespace::model_joint_binary_cov_catchability_gamma"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 52; + context__.validate_dims("data initialization", "S", "int", + std::vector{}); + S = std::numeric_limits::min(); + current_statement__ = 52; + S = context__.vals_i("S")[(1 - 1)]; + current_statement__ = 52; + stan::math::check_greater_or_equal(function__, "S", S, 1); + current_statement__ = 53; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 53; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 53; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 54; + stan::math::validate_non_negative_index("L", "S", S); + current_statement__ = 55; + context__.validate_dims("data initialization", "L", "int", + std::vector{static_cast(S)}); + L = std::vector(S, std::numeric_limits::min()); + current_statement__ = 55; + L = context__.vals_i("L"); + current_statement__ = 55; + stan::math::check_greater_or_equal(function__, "L", L, 1); + current_statement__ = 56; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 57; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 57; + R = context__.vals_i("R"); + current_statement__ = 57; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 58; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 58; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 58; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 59; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 60; + context__.validate_dims("data initialization", "E", "double", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::quiet_NaN()); + current_statement__ = 60; + E = context__.vals_r("E"); + current_statement__ = 60; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 61; + stan::math::validate_non_negative_index("N", "S", S); + current_statement__ = 62; + context__.validate_dims("data initialization", "N", "int", + std::vector{static_cast(S)}); + N = std::vector(S, std::numeric_limits::min()); + current_statement__ = 62; + N = context__.vals_i("N"); + current_statement__ = 62; + stan::math::check_greater_or_equal(function__, "N", N, 1); + current_statement__ = 63; + stan::math::validate_non_negative_index("K", "S", S); + current_statement__ = 64; + context__.validate_dims("data initialization", "K", "int", + std::vector{static_cast(S)}); + K = std::vector(S, std::numeric_limits::min()); + current_statement__ = 64; + K = context__.vals_i("K"); + current_statement__ = 64; + stan::math::check_greater_or_equal(function__, "K", K, 0); + current_statement__ = 65; + context__.validate_dims("data initialization", "p10priors", "double", + std::vector{static_cast(2)}); + p10priors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 65; + p10priors = context__.vals_r("p10priors"); + current_statement__ = 66; + context__.validate_dims("data initialization", "nsitecov", "int", + std::vector{}); + nsitecov = std::numeric_limits::min(); + current_statement__ = 66; + nsitecov = context__.vals_i("nsitecov")[(1 - 1)]; + current_statement__ = 66; + stan::math::check_greater_or_equal(function__, "nsitecov", nsitecov, 0); + current_statement__ = 67; + stan::math::validate_non_negative_index("mat_site", "Nloc", Nloc); + current_statement__ = 68; + stan::math::validate_non_negative_index("mat_site", "nsitecov", + nsitecov); + current_statement__ = 69; + context__.validate_dims("data initialization", "mat_site", "double", + std::vector{static_cast(Nloc), + static_cast(nsitecov)}); + mat_site_data__ = Eigen::Matrix::Constant(Nloc, nsitecov, + std::numeric_limits::quiet_NaN()); + new (&mat_site) + Eigen::Map>(mat_site_data__.data(), Nloc, + nsitecov); + { + std::vector mat_site_flat__; + current_statement__ = 69; + mat_site_flat__ = context__.vals_r("mat_site"); + current_statement__ = 69; + pos__ = 1; + current_statement__ = 69; + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + current_statement__ = 69; + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + current_statement__ = 69; + stan::model::assign(mat_site, mat_site_flat__[(pos__ - 1)], + "assigning variable mat_site", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 69; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 70; + context__.validate_dims("data initialization", "nparams", "int", + std::vector{}); + nparams = std::numeric_limits::min(); + current_statement__ = 70; + nparams = context__.vals_i("nparams")[(1 - 1)]; + current_statement__ = 70; + stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); + current_statement__ = 71; + stan::math::validate_non_negative_index("mat", "C", C); + current_statement__ = 72; + stan::math::validate_non_negative_index("mat", "nparams", nparams); + current_statement__ = 73; + context__.validate_dims("data initialization", "mat", "double", + std::vector{static_cast(C), + static_cast(nparams)}); + mat_data__ = Eigen::Matrix::Constant(C, nparams, + std::numeric_limits::quiet_NaN()); + new (&mat) Eigen::Map>(mat_data__.data(), + C, nparams); + { + std::vector mat_flat__; + current_statement__ = 73; + mat_flat__ = context__.vals_r("mat"); + current_statement__ = 73; + pos__ = 1; + current_statement__ = 73; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 73; + for (int sym2__ = 1; sym2__ <= C; ++sym2__) { + current_statement__ = 73; + stan::model::assign(mat, mat_flat__[(pos__ - 1)], + "assigning variable mat", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 73; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 74; + stan::math::validate_non_negative_index("alpha_gamma", "Nloc", Nloc); + current_statement__ = 75; + stan::math::validate_non_negative_index("beta_gamma", "Nloc", Nloc); + current_statement__ = 76; + stan::math::validate_non_negative_index("alpha", "nsitecov", nsitecov); + current_statement__ = 77; + stan::math::validate_non_negative_index("q_trans", "nparams", nparams); + current_statement__ = 78; + stan::math::validate_non_negative_index("p11", "Nloc", Nloc); + current_statement__ = 79; + stan::math::validate_non_negative_index("p", "Nloc", Nloc); + current_statement__ = 80; + stan::math::validate_non_negative_index("coef", "C", C); + current_statement__ = 81; + stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); + current_statement__ = 82; + stan::math::validate_non_negative_index("E_trans", "C", C); + current_statement__ = 83; + stan::math::validate_non_negative_index("q", "nparams", nparams); + current_statement__ = 84; + log_lik_1dim__ = std::numeric_limits::min(); + current_statement__ = 84; + log_lik_1dim__ = (C + S); + current_statement__ = 84; + stan::math::validate_non_negative_index("log_lik", "C + S", + log_lik_1dim__); + current_statement__ = 85; + stan::math::validate_non_negative_index("beta", "Nloc", Nloc); + current_statement__ = 86; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 87; + mu_2dim__ = std::numeric_limits::min(); + current_statement__ = 87; + mu_2dim__ = (nparams + 1); + current_statement__ = 87; + stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + Nloc + 1 + nsitecov + nparams; + } + inline std::string model_name() const final { + return "model_joint_binary_cov_catchability_gamma"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_joint_binary_cov_catchability_gamma_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector alpha_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + alpha_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0, lp__, + Nloc); + std::vector beta_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + beta_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0.01, lp__, + Nloc); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + current_statement__ = 4; + alpha = in__.template read< + Eigen::Matrix>(nsitecov); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 5; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + std::vector p11 = + std::vector(Nloc, DUMMY_VAR__); + std::vector p = + std::vector(Nloc, DUMMY_VAR__); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, DUMMY_VAR__); + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + std::vector E_trans = + std::vector(C, DUMMY_VAR__); + current_statement__ = 20; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 16; + stan::model::assign(mu_1, + (stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni(i)) / + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni(i))), "assigning variable mu_1", + stan::model::index_uni(i)); + current_statement__ = 17; + stan::model::assign(p11, + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + + stan::math::exp( + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha)))), + "assigning variable p11", stan::model::index_uni(i)); + current_statement__ = 18; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 23; + for (int k = 1; k <= C; ++k) { + current_statement__ = 21; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), + q_trans)), "assigning variable coef", stan::model::index_uni(k)); + } + current_statement__ = 26; + for (int j = 1; j <= C; ++j) { + current_statement__ = 24; + stan::model::assign(E_trans, + (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + + 0.0000000000001), "assigning variable E_trans", + stan::model::index_uni(j)); + } + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 7; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 8; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + current_statement__ = 9; + stan::math::check_greater_or_equal(function__, "mu_1", mu_1, 0); + current_statement__ = 10; + stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); + { + current_statement__ = 44; + for (int j = 1; j <= C; ++j) { + current_statement__ = 42; + lp_accum__.add(stan::math::gamma_lpdf( + stan::model::rvalue(E_trans, "E_trans", + stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", + stan::model::index_uni(j)) * + stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j))))), + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))))); + } + current_statement__ = 47; + for (int i = 1; i <= S; ++i) { + current_statement__ = 45; + lp_accum__.add(stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", + stan::model::index_uni(i)), + stan::model::rvalue(N, "N", + stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", + stan::model::index_uni(i)))))); + } + current_statement__ = 48; + lp_accum__.add(stan::math::normal_lpdf(log_p10, + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(1)), + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(2)))); + current_statement__ = 49; + lp_accum__.add(stan::math::normal_lpdf(alpha, 0, 10)); + current_statement__ = 50; + lp_accum__.add(stan::math::gamma_lpdf(beta_gamma, 0.25, + 0.25)); + current_statement__ = 51; + lp_accum__.add(stan::math::gamma_lpdf(alpha_gamma, 0.01, + 0.01)); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_joint_binary_cov_catchability_gamma_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector alpha_gamma = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + alpha_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0, lp__, + Nloc); + std::vector beta_gamma = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 2; + beta_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0.01, lp__, + Nloc); + double log_p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, + std::numeric_limits::quiet_NaN()); + current_statement__ = 4; + alpha = in__.template read< + Eigen::Matrix>(nsitecov); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + current_statement__ = 5; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + std::vector p11 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector p = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + std::vector mu_1 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector E_trans = + std::vector(C, std::numeric_limits::quiet_NaN()); + out__.write(alpha_gamma); + out__.write(beta_gamma); + out__.write(log_p10); + out__.write(alpha); + out__.write(q_trans); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 20; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 16; + stan::model::assign(mu_1, + (stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni(i)) / + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni(i))), "assigning variable mu_1", + stan::model::index_uni(i)); + current_statement__ = 17; + stan::model::assign(p11, + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + + stan::math::exp( + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha)))), + "assigning variable p11", stan::model::index_uni(i)); + current_statement__ = 18; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 23; + for (int k = 1; k <= C; ++k) { + current_statement__ = 21; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), + q_trans)), "assigning variable coef", stan::model::index_uni(k)); + } + current_statement__ = 26; + for (int j = 1; j <= C; ++j) { + current_statement__ = 24; + stan::model::assign(E_trans, + (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + + 0.0000000000001), "assigning variable E_trans", + stan::model::index_uni(j)); + } + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 7; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 8; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + current_statement__ = 9; + stan::math::check_greater_or_equal(function__, "mu_1", mu_1, 0); + current_statement__ = 10; + stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); + if (emit_transformed_parameters__) { + out__.write(p11); + out__.write(p); + out__.write(coef); + out__.write(mu_1); + out__.write(E_trans); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix q = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(log_lik_1dim__, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix beta = + Eigen::Matrix::Constant(Nloc, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix mu = + Eigen::Matrix::Constant(Nloc, mu_2dim__, + std::numeric_limits::quiet_NaN()); + double p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 27; + p10 = stan::math::exp(log_p10); + current_statement__ = 30; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 28; + stan::model::assign(beta, + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha), "assigning variable beta", + stan::model::index_uni(i)); + } + current_statement__ = 31; + stan::model::assign(q, stan::math::add(q_trans, 1), + "assigning variable q"); + current_statement__ = 32; + stan::model::assign(mu, stan::math::to_vector(mu_1), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni(1)); + current_statement__ = 35; + for (int i = 1; i <= nparams; ++i) { + current_statement__ = 33; + stan::model::assign(mu, + stan::math::multiply(stan::math::to_vector(mu_1), + stan::model::rvalue(q, "q", stan::model::index_uni(i))), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni((i + 1))); + } + current_statement__ = 38; + for (int j = 1; j <= C; ++j) { + current_statement__ = 36; + stan::model::assign(log_lik, + stan::math::gamma_lpdf( + stan::model::rvalue(E_trans, "E_trans", stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * + stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + "assigning variable log_lik", stan::model::index_uni(j)); + } + current_statement__ = 41; + for (int i = 1; i <= S; ++i) { + current_statement__ = 39; + stan::model::assign(log_lik, + stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", stan::model::index_uni(i)), + stan::model::rvalue(N, "N", stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", stan::model::index_uni(i))))), + "assigning variable log_lik", stan::model::index_uni((C + i))); + } + out__.write(q); + out__.write(log_lik); + out__.write(beta); + out__.write(mu); + out__.write(p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector alpha_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(alpha_gamma, + in__.read>(Nloc), + "assigning variable alpha_gamma"); + out__.write_free_lb(0, alpha_gamma); + std::vector beta_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + stan::model::assign(beta_gamma, + in__.read>(Nloc), + "assigning variable beta_gamma"); + out__.write_free_lb(0.01, beta_gamma); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = in__.read(); + out__.write_free_ub(0, log_p10); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + current_statement__ = 4; + stan::model::assign(alpha, + in__.read>(nsitecov), + "assigning variable alpha"); + out__.write(alpha); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 5; + stan::model::assign(q_trans, + in__.read>(nparams), + "assigning variable q_trans"); + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "alpha_gamma", + "double", std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "beta_gamma", + "double", std::vector{static_cast(Nloc)}); + current_statement__ = 3; + context__.validate_dims("parameter initialization", "log_p10", + "double", std::vector{}); + current_statement__ = 4; + context__.validate_dims("parameter initialization", "alpha", "double", + std::vector{static_cast(nsitecov)}); + current_statement__ = 5; + context__.validate_dims("parameter initialization", "q_trans", + "double", std::vector{static_cast(nparams)}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector alpha_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + alpha_gamma = context__.vals_r("alpha_gamma"); + out__.write_free_lb(0, alpha_gamma); + std::vector beta_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + beta_gamma = context__.vals_r("beta_gamma"); + out__.write_free_lb(0.01, beta_gamma); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = context__.vals_r("log_p10")[(1 - 1)]; + out__.write_free_ub(0, log_p10); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + { + std::vector alpha_flat__; + current_statement__ = 4; + alpha_flat__ = context__.vals_r("alpha"); + current_statement__ = 4; + pos__ = 1; + current_statement__ = 4; + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + current_statement__ = 4; + stan::model::assign(alpha, alpha_flat__[(pos__ - 1)], + "assigning variable alpha", stan::model::index_uni(sym1__)); + current_statement__ = 4; + pos__ = (pos__ + 1); + } + } + out__.write(alpha); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + { + std::vector q_trans_flat__; + current_statement__ = 5; + q_trans_flat__ = context__.vals_r("q_trans"); + current_statement__ = 5; + pos__ = 1; + current_statement__ = 5; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 5; + stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], + "assigning variable q_trans", stan::model::index_uni(sym1__)); + current_statement__ = 5; + pos__ = (pos__ + 1); + } + } + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"alpha_gamma", "beta_gamma", + "log_p10", "alpha", "q_trans"}; + if (emit_transformed_parameters__) { + std::vector temp{"p11", "p", "coef", "mu_1", "E_trans"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"q", "log_lik", "beta", "mu", "p10"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{}, + std::vector{static_cast(nsitecov)}, + std::vector{static_cast(nparams)}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(C)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(C)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(nparams)}, + std::vector{static_cast(log_lik_1dim__)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc), + static_cast(mu_2dim__)}, std::vector{}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta_gamma" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "E_trans" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta_gamma" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "E_trans" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((((Nloc + Nloc) + 1) + nsitecov) + nparams); + const size_t num_transformed = emit_transformed_parameters * (((((Nloc + + Nloc) + C) + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * + (((((nparams + log_lik_1dim__) + Nloc) + (Nloc * mu_2dim__)) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((((Nloc + Nloc) + 1) + nsitecov) + nparams); + const size_t num_transformed = emit_transformed_parameters * (((((Nloc + + Nloc) + C) + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * + (((((nparams + log_lik_1dim__) + Nloc) + (Nloc * mu_2dim__)) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_joint_binary_cov_catchability_gamma_namespace::model_joint_binary_cov_catchability_gamma; +#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_joint_binary_cov_catchability_gamma_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_joint_binary_cov_catchability_negbin.h b/src/stanExports_joint_binary_cov_catchability_negbin.h index 28edf2a..81fc617 100644 --- a/src/stanExports_joint_binary_cov_catchability_negbin.h +++ b/src/stanExports_joint_binary_cov_catchability_negbin.h @@ -1,1078 +1,1078 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_joint_binary_cov_catchability_negbin_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'joint_binary_cov_catchability_negbin', line 18, column 4 to column 35)", - " (in 'joint_binary_cov_catchability_negbin', line 19, column 4 to column 22)", - " (in 'joint_binary_cov_catchability_negbin', line 20, column 4 to column 26)", - " (in 'joint_binary_cov_catchability_negbin', line 21, column 4 to column 27)", - " (in 'joint_binary_cov_catchability_negbin', line 22, column 4 to column 44)", - " (in 'joint_binary_cov_catchability_negbin', line 25, column 2 to column 43)", - " (in 'joint_binary_cov_catchability_negbin', line 26, column 2 to column 41)", - " (in 'joint_binary_cov_catchability_negbin', line 27, column 2 to column 26)", - " (in 'joint_binary_cov_catchability_negbin', line 49, column 2 to column 20)", - " (in 'joint_binary_cov_catchability_negbin', line 50, column 2 to column 22)", - " (in 'joint_binary_cov_catchability_negbin', line 51, column 2 to column 20)", - " (in 'joint_binary_cov_catchability_negbin', line 52, column 2 to column 28)", - " (in 'joint_binary_cov_catchability_negbin', line 53, column 2 to column 11)", - " (in 'joint_binary_cov_catchability_negbin', line 29, column 4 to column 71)", - " (in 'joint_binary_cov_catchability_negbin', line 30, column 4 to column 33)", - " (in 'joint_binary_cov_catchability_negbin', line 28, column 19 to line 31, column 3)", - " (in 'joint_binary_cov_catchability_negbin', line 28, column 2 to line 31, column 3)", - " (in 'joint_binary_cov_catchability_negbin', line 33, column 6 to column 48)", - " (in 'joint_binary_cov_catchability_negbin', line 32, column 15 to line 34, column 5)", - " (in 'joint_binary_cov_catchability_negbin', line 32, column 2 to line 34, column 5)", - " (in 'joint_binary_cov_catchability_negbin', line 54, column 2 to column 21)", - " (in 'joint_binary_cov_catchability_negbin', line 56, column 4 to column 45)", - " (in 'joint_binary_cov_catchability_negbin', line 55, column 19 to line 57, column 3)", - " (in 'joint_binary_cov_catchability_negbin', line 55, column 2 to line 57, column 3)", - " (in 'joint_binary_cov_catchability_negbin', line 58, column 2 to column 18)", - " (in 'joint_binary_cov_catchability_negbin', line 59, column 2 to column 27)", - " (in 'joint_binary_cov_catchability_negbin', line 61, column 4 to column 36)", - " (in 'joint_binary_cov_catchability_negbin', line 60, column 21 to line 62, column 3)", - " (in 'joint_binary_cov_catchability_negbin', line 60, column 2 to line 62, column 3)", - " (in 'joint_binary_cov_catchability_negbin', line 64, column 10 to column 75)", - " (in 'joint_binary_cov_catchability_negbin', line 63, column 17 to line 65, column 7)", - " (in 'joint_binary_cov_catchability_negbin', line 63, column 4 to line 65, column 7)", - " (in 'joint_binary_cov_catchability_negbin', line 67, column 10 to column 61)", - " (in 'joint_binary_cov_catchability_negbin', line 66, column 19 to line 68, column 7)", - " (in 'joint_binary_cov_catchability_negbin', line 66, column 6 to line 68, column 7)", - " (in 'joint_binary_cov_catchability_negbin', line 38, column 8 to column 55)", - " (in 'joint_binary_cov_catchability_negbin', line 37, column 18 to line 39, column 5)", - " (in 'joint_binary_cov_catchability_negbin', line 37, column 4 to line 39, column 5)", - " (in 'joint_binary_cov_catchability_negbin', line 41, column 8 to column 39)", - " (in 'joint_binary_cov_catchability_negbin', line 40, column 18 to line 42, column 5)", - " (in 'joint_binary_cov_catchability_negbin', line 40, column 4 to line 42, column 5)", - " (in 'joint_binary_cov_catchability_negbin', line 44, column 2 to column 47)", - " (in 'joint_binary_cov_catchability_negbin', line 45, column 2 to column 23)", - " (in 'joint_binary_cov_catchability_negbin', line 46, column 2 to column 42)", - " (in 'joint_binary_cov_catchability_negbin', line 2, column 4 to column 19)", - " (in 'joint_binary_cov_catchability_negbin', line 3, column 4 to column 19)", - " (in 'joint_binary_cov_catchability_negbin', line 4, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_negbin', line 4, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_negbin', line 5, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_negbin', line 5, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_negbin', line 6, column 4 to column 22)", - " (in 'joint_binary_cov_catchability_negbin', line 7, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_negbin', line 7, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_negbin', line 8, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_negbin', line 8, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_negbin', line 9, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_negbin', line 9, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_negbin', line 10, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_negbin', line 11, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_negbin', line 12, column 4 to column 26)", - " (in 'joint_binary_cov_catchability_negbin', line 13, column 11 to column 15)", - " (in 'joint_binary_cov_catchability_negbin', line 13, column 16 to column 24)", - " (in 'joint_binary_cov_catchability_negbin', line 13, column 4 to column 35)", - " (in 'joint_binary_cov_catchability_negbin', line 14, column 4 to column 25)", - " (in 'joint_binary_cov_catchability_negbin', line 15, column 11 to column 12)", - " (in 'joint_binary_cov_catchability_negbin', line 15, column 13 to column 20)", - " (in 'joint_binary_cov_catchability_negbin', line 15, column 4 to column 26)", - " (in 'joint_binary_cov_catchability_negbin', line 18, column 10 to column 14)", - " (in 'joint_binary_cov_catchability_negbin', line 21, column 11 to column 19)", - " (in 'joint_binary_cov_catchability_negbin', line 22, column 27 to column 34)", - " (in 'joint_binary_cov_catchability_negbin', line 25, column 8 to column 12)", - " (in 'joint_binary_cov_catchability_negbin', line 26, column 8 to column 12)", - " (in 'joint_binary_cov_catchability_negbin', line 27, column 18 to column 19)", - " (in 'joint_binary_cov_catchability_negbin', line 49, column 9 to column 16)", - " (in 'joint_binary_cov_catchability_negbin', line 50, column 9 to column 12)", - " (in 'joint_binary_cov_catchability_negbin', line 51, column 9 to column 13)", - " (in 'joint_binary_cov_catchability_negbin', line 52, column 9 to column 13)", - " (in 'joint_binary_cov_catchability_negbin', line 52, column 14 to column 23)"}; -#include -class model_joint_binary_cov_catchability_negbin final : public model_base_crtp { -private: - int S; - int C; - std::vector L; - std::vector R; - int Nloc; - std::vector E; - std::vector N; - std::vector K; - std::vector p10priors; - std::vector phipriors; - int nsitecov; - Eigen::Matrix mat_site_data__; - int nparams; - Eigen::Matrix mat_data__; - int log_lik_1dim__; - int mu_2dim__; - Eigen::Map> mat_site{nullptr, 0, 0}; - Eigen::Map> mat{nullptr, 0, 0}; -public: - ~model_joint_binary_cov_catchability_negbin() {} - model_joint_binary_cov_catchability_negbin(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_joint_binary_cov_catchability_negbin_namespace::model_joint_binary_cov_catchability_negbin"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 45; - context__.validate_dims("data initialization", "S", "int", - std::vector{}); - S = std::numeric_limits::min(); - current_statement__ = 45; - S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 45; - stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 46; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 46; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 46; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 47; - stan::math::validate_non_negative_index("L", "S", S); - current_statement__ = 48; - context__.validate_dims("data initialization", "L", "int", - std::vector{static_cast(S)}); - L = std::vector(S, std::numeric_limits::min()); - current_statement__ = 48; - L = context__.vals_i("L"); - current_statement__ = 48; - stan::math::check_greater_or_equal(function__, "L", L, 1); - current_statement__ = 49; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 50; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 50; - R = context__.vals_i("R"); - current_statement__ = 50; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 51; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 51; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 51; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 52; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 53; - context__.validate_dims("data initialization", "E", "int", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::min()); - current_statement__ = 53; - E = context__.vals_i("E"); - current_statement__ = 53; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 54; - stan::math::validate_non_negative_index("N", "S", S); - current_statement__ = 55; - context__.validate_dims("data initialization", "N", "int", - std::vector{static_cast(S)}); - N = std::vector(S, std::numeric_limits::min()); - current_statement__ = 55; - N = context__.vals_i("N"); - current_statement__ = 55; - stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 56; - stan::math::validate_non_negative_index("K", "S", S); - current_statement__ = 57; - context__.validate_dims("data initialization", "K", "int", - std::vector{static_cast(S)}); - K = std::vector(S, std::numeric_limits::min()); - current_statement__ = 57; - K = context__.vals_i("K"); - current_statement__ = 57; - stan::math::check_greater_or_equal(function__, "K", K, 0); - current_statement__ = 58; - context__.validate_dims("data initialization", "p10priors", "double", - std::vector{static_cast(2)}); - p10priors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 58; - p10priors = context__.vals_r("p10priors"); - current_statement__ = 59; - context__.validate_dims("data initialization", "phipriors", "double", - std::vector{static_cast(2)}); - phipriors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 59; - phipriors = context__.vals_r("phipriors"); - current_statement__ = 60; - context__.validate_dims("data initialization", "nsitecov", "int", - std::vector{}); - nsitecov = std::numeric_limits::min(); - current_statement__ = 60; - nsitecov = context__.vals_i("nsitecov")[(1 - 1)]; - current_statement__ = 60; - stan::math::check_greater_or_equal(function__, "nsitecov", nsitecov, 0); - current_statement__ = 61; - stan::math::validate_non_negative_index("mat_site", "Nloc", Nloc); - current_statement__ = 62; - stan::math::validate_non_negative_index("mat_site", "nsitecov", - nsitecov); - current_statement__ = 63; - context__.validate_dims("data initialization", "mat_site", "double", - std::vector{static_cast(Nloc), - static_cast(nsitecov)}); - mat_site_data__ = Eigen::Matrix::Constant(Nloc, nsitecov, - std::numeric_limits::quiet_NaN()); - new (&mat_site) - Eigen::Map>(mat_site_data__.data(), Nloc, - nsitecov); - { - std::vector mat_site_flat__; - current_statement__ = 63; - mat_site_flat__ = context__.vals_r("mat_site"); - current_statement__ = 63; - pos__ = 1; - current_statement__ = 63; - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - current_statement__ = 63; - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - current_statement__ = 63; - stan::model::assign(mat_site, mat_site_flat__[(pos__ - 1)], - "assigning variable mat_site", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 63; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 64; - context__.validate_dims("data initialization", "nparams", "int", - std::vector{}); - nparams = std::numeric_limits::min(); - current_statement__ = 64; - nparams = context__.vals_i("nparams")[(1 - 1)]; - current_statement__ = 64; - stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); - current_statement__ = 65; - stan::math::validate_non_negative_index("mat", "C", C); - current_statement__ = 66; - stan::math::validate_non_negative_index("mat", "nparams", nparams); - current_statement__ = 67; - context__.validate_dims("data initialization", "mat", "double", - std::vector{static_cast(C), - static_cast(nparams)}); - mat_data__ = Eigen::Matrix::Constant(C, nparams, - std::numeric_limits::quiet_NaN()); - new (&mat) Eigen::Map>(mat_data__.data(), - C, nparams); - { - std::vector mat_flat__; - current_statement__ = 67; - mat_flat__ = context__.vals_r("mat"); - current_statement__ = 67; - pos__ = 1; - current_statement__ = 67; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 67; - for (int sym2__ = 1; sym2__ <= C; ++sym2__) { - current_statement__ = 67; - stan::model::assign(mat, mat_flat__[(pos__ - 1)], - "assigning variable mat", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 67; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 68; - stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); - current_statement__ = 69; - stan::math::validate_non_negative_index("alpha", "nsitecov", nsitecov); - current_statement__ = 70; - stan::math::validate_non_negative_index("q_trans", "nparams", nparams); - current_statement__ = 71; - stan::math::validate_non_negative_index("p11", "Nloc", Nloc); - current_statement__ = 72; - stan::math::validate_non_negative_index("p", "Nloc", Nloc); - current_statement__ = 73; - stan::math::validate_non_negative_index("coef", "C", C); - current_statement__ = 74; - stan::math::validate_non_negative_index("q", "nparams", nparams); - current_statement__ = 75; - log_lik_1dim__ = std::numeric_limits::min(); - current_statement__ = 75; - log_lik_1dim__ = (C + S); - current_statement__ = 75; - stan::math::validate_non_negative_index("log_lik", "C + S", - log_lik_1dim__); - current_statement__ = 76; - stan::math::validate_non_negative_index("beta", "Nloc", Nloc); - current_statement__ = 77; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 78; - mu_2dim__ = std::numeric_limits::min(); - current_statement__ = 78; - mu_2dim__ = (nparams + 1); - current_statement__ = 78; - stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + 1 + 1 + nsitecov + nparams; - } - inline std::string model_name() const final { - return "model_joint_binary_cov_catchability_negbin"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_joint_binary_cov_catchability_negbin_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu_1 = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = in__.template read_constrain_lb(0, - lp__); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - current_statement__ = 4; - alpha = in__.template read< - Eigen::Matrix>(nsitecov); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 5; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - std::vector p11 = - std::vector(Nloc, DUMMY_VAR__); - std::vector p = - std::vector(Nloc, DUMMY_VAR__); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, DUMMY_VAR__); - current_statement__ = 17; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 14; - stan::model::assign(p11, - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + - stan::math::exp( - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha)))), - "assigning variable p11", stan::model::index_uni(i)); - current_statement__ = 15; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 20; - for (int k = 1; k <= C; ++k) { - current_statement__ = 18; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), - q_trans)), "assigning variable coef", stan::model::index_uni(k)); - } - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 7; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 8; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - { - current_statement__ = 38; - for (int j = 1; j <= C; ++j) { - current_statement__ = 36; - lp_accum__.add(stan::math::neg_binomial_2_lpmf( - stan::model::rvalue(E, "E", - stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", - stan::model::index_uni(j)) * - stan::model::rvalue(mu_1, "mu_1", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j))))), phi)); - } - current_statement__ = 41; - for (int i = 1; i <= S; ++i) { - current_statement__ = 39; - lp_accum__.add(stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", - stan::model::index_uni(i)), - stan::model::rvalue(N, "N", - stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", - stan::model::index_uni(i)))))); - } - current_statement__ = 42; - lp_accum__.add(stan::math::normal_lpdf(log_p10, - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(1)), - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(2)))); - current_statement__ = 43; - lp_accum__.add(stan::math::normal_lpdf(alpha, 0, 10)); - current_statement__ = 44; - lp_accum__.add(stan::math::gamma_lpdf(phi, - stan::model::rvalue(phipriors, "phipriors", - stan::model::index_uni(1)), - stan::model::rvalue(phipriors, "phipriors", - stan::model::index_uni(2)))); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_joint_binary_cov_catchability_negbin_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector mu_1 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - mu_1 = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - double phi = std::numeric_limits::quiet_NaN(); - current_statement__ = 2; - phi = in__.template read_constrain_lb(0, - lp__); - double log_p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 3; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, - std::numeric_limits::quiet_NaN()); - current_statement__ = 4; - alpha = in__.template read< - Eigen::Matrix>(nsitecov); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - current_statement__ = 5; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - std::vector p11 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector p = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - out__.write(mu_1); - out__.write(phi); - out__.write(log_p10); - out__.write(alpha); - out__.write(q_trans); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 17; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 14; - stan::model::assign(p11, - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + - stan::math::exp( - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha)))), - "assigning variable p11", stan::model::index_uni(i)); - current_statement__ = 15; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 20; - for (int k = 1; k <= C; ++k) { - current_statement__ = 18; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), - q_trans)), "assigning variable coef", stan::model::index_uni(k)); - } - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 7; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 8; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - if (emit_transformed_parameters__) { - out__.write(p11); - out__.write(p); - out__.write(coef); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix q = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(log_lik_1dim__, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix beta = - Eigen::Matrix::Constant(Nloc, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix mu = - Eigen::Matrix::Constant(Nloc, mu_2dim__, - std::numeric_limits::quiet_NaN()); - double p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 21; - p10 = stan::math::exp(log_p10); - current_statement__ = 24; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 22; - stan::model::assign(beta, - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha), "assigning variable beta", - stan::model::index_uni(i)); - } - current_statement__ = 25; - stan::model::assign(q, stan::math::add(q_trans, 1), - "assigning variable q"); - current_statement__ = 26; - stan::model::assign(mu, stan::math::to_vector(mu_1), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni(1)); - current_statement__ = 29; - for (int i = 1; i <= nparams; ++i) { - current_statement__ = 27; - stan::model::assign(mu, - stan::math::multiply(stan::math::to_vector(mu_1), - stan::model::rvalue(q, "q", stan::model::index_uni(i))), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni((i + 1))); - } - current_statement__ = 32; - for (int j = 1; j <= C; ++j) { - current_statement__ = 30; - stan::model::assign(log_lik, - stan::math::neg_binomial_2_lpmf( - stan::model::rvalue(E, "E", stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * - stan::model::rvalue(mu_1, "mu_1", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - phi), "assigning variable log_lik", stan::model::index_uni(j)); - } - current_statement__ = 35; - for (int i = 1; i <= S; ++i) { - current_statement__ = 33; - stan::model::assign(log_lik, - stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", stan::model::index_uni(i)), - stan::model::rvalue(N, "N", stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", stan::model::index_uni(i))))), - "assigning variable log_lik", stan::model::index_uni((C + i))); - } - out__.write(q); - out__.write(log_lik); - out__.write(beta); - out__.write(mu); - out__.write(p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(mu_1, - in__.read>(Nloc), - "assigning variable mu_1"); - out__.write_free_lb(0, mu_1); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = in__.read(); - out__.write_free_lb(0, phi); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = in__.read(); - out__.write_free_ub(0, log_p10); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - current_statement__ = 4; - stan::model::assign(alpha, - in__.read>(nsitecov), - "assigning variable alpha"); - out__.write(alpha); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 5; - stan::model::assign(q_trans, - in__.read>(nparams), - "assigning variable q_trans"); - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "mu_1", "double", - std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "phi", "double", - std::vector{}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "log_p10", - "double", std::vector{}); - current_statement__ = 4; - context__.validate_dims("parameter initialization", "alpha", "double", - std::vector{static_cast(nsitecov)}); - current_statement__ = 5; - context__.validate_dims("parameter initialization", "q_trans", - "double", std::vector{static_cast(nparams)}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu_1 = context__.vals_r("mu_1"); - out__.write_free_lb(0, mu_1); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = context__.vals_r("phi")[(1 - 1)]; - out__.write_free_lb(0, phi); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = context__.vals_r("log_p10")[(1 - 1)]; - out__.write_free_ub(0, log_p10); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - { - std::vector alpha_flat__; - current_statement__ = 4; - alpha_flat__ = context__.vals_r("alpha"); - current_statement__ = 4; - pos__ = 1; - current_statement__ = 4; - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - current_statement__ = 4; - stan::model::assign(alpha, alpha_flat__[(pos__ - 1)], - "assigning variable alpha", stan::model::index_uni(sym1__)); - current_statement__ = 4; - pos__ = (pos__ + 1); - } - } - out__.write(alpha); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - { - std::vector q_trans_flat__; - current_statement__ = 5; - q_trans_flat__ = context__.vals_r("q_trans"); - current_statement__ = 5; - pos__ = 1; - current_statement__ = 5; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 5; - stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], - "assigning variable q_trans", stan::model::index_uni(sym1__)); - current_statement__ = 5; - pos__ = (pos__ + 1); - } - } - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"mu_1", "phi", "log_p10", "alpha", - "q_trans"}; - if (emit_transformed_parameters__) { - std::vector temp{"p11", "p", "coef"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"q", "log_lik", "beta", "mu", "p10"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{}, std::vector{}, - std::vector{static_cast(nsitecov)}, - std::vector{static_cast(nparams)}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(C)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(nparams)}, - std::vector{static_cast(log_lik_1dim__)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc), - static_cast(mu_2dim__)}, std::vector{}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "phi"); - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "phi"); - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((((Nloc + 1) + 1) + nsitecov) + nparams); - const size_t num_transformed = emit_transformed_parameters * (((Nloc + - Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * - (((((nparams + log_lik_1dim__) + Nloc) + (Nloc * mu_2dim__)) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((((Nloc + 1) + 1) + nsitecov) + nparams); - const size_t num_transformed = emit_transformed_parameters * (((Nloc + - Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * - (((((nparams + log_lik_1dim__) + Nloc) + (Nloc * mu_2dim__)) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_joint_binary_cov_catchability_negbin_namespace::model_joint_binary_cov_catchability_negbin; -#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_joint_binary_cov_catchability_negbin_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_joint_binary_cov_catchability_negbin_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 18, column 4 to column 35)", + " (in 'string', line 19, column 4 to column 22)", + " (in 'string', line 20, column 4 to column 26)", + " (in 'string', line 21, column 4 to column 27)", + " (in 'string', line 22, column 4 to column 44)", + " (in 'string', line 25, column 2 to column 43)", + " (in 'string', line 26, column 2 to column 41)", + " (in 'string', line 27, column 2 to column 26)", + " (in 'string', line 49, column 2 to column 20)", + " (in 'string', line 50, column 2 to column 22)", + " (in 'string', line 51, column 2 to column 20)", + " (in 'string', line 52, column 2 to column 28)", + " (in 'string', line 53, column 2 to column 11)", + " (in 'string', line 29, column 4 to column 71)", + " (in 'string', line 30, column 4 to column 33)", + " (in 'string', line 28, column 19 to line 31, column 3)", + " (in 'string', line 28, column 2 to line 31, column 3)", + " (in 'string', line 33, column 6 to column 48)", + " (in 'string', line 32, column 15 to line 34, column 5)", + " (in 'string', line 32, column 2 to line 34, column 5)", + " (in 'string', line 54, column 2 to column 21)", + " (in 'string', line 56, column 4 to column 45)", + " (in 'string', line 55, column 19 to line 57, column 3)", + " (in 'string', line 55, column 2 to line 57, column 3)", + " (in 'string', line 58, column 2 to column 18)", + " (in 'string', line 59, column 2 to column 27)", + " (in 'string', line 61, column 4 to column 36)", + " (in 'string', line 60, column 21 to line 62, column 3)", + " (in 'string', line 60, column 2 to line 62, column 3)", + " (in 'string', line 64, column 10 to column 75)", + " (in 'string', line 63, column 17 to line 65, column 7)", + " (in 'string', line 63, column 4 to line 65, column 7)", + " (in 'string', line 67, column 10 to column 61)", + " (in 'string', line 66, column 19 to line 68, column 7)", + " (in 'string', line 66, column 6 to line 68, column 7)", + " (in 'string', line 38, column 8 to column 55)", + " (in 'string', line 37, column 18 to line 39, column 5)", + " (in 'string', line 37, column 4 to line 39, column 5)", + " (in 'string', line 41, column 8 to column 39)", + " (in 'string', line 40, column 18 to line 42, column 5)", + " (in 'string', line 40, column 4 to line 42, column 5)", + " (in 'string', line 44, column 2 to column 47)", + " (in 'string', line 45, column 2 to column 23)", + " (in 'string', line 46, column 2 to column 42)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 4 to column 19)", + " (in 'string', line 4, column 10 to column 11)", + " (in 'string', line 4, column 4 to column 28)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 22)", + " (in 'string', line 7, column 10 to column 11)", + " (in 'string', line 7, column 4 to column 28)", + " (in 'string', line 8, column 10 to column 11)", + " (in 'string', line 8, column 4 to column 28)", + " (in 'string', line 9, column 10 to column 11)", + " (in 'string', line 9, column 4 to column 28)", + " (in 'string', line 10, column 4 to column 28)", + " (in 'string', line 11, column 4 to column 28)", + " (in 'string', line 12, column 4 to column 26)", + " (in 'string', line 13, column 11 to column 15)", + " (in 'string', line 13, column 16 to column 24)", + " (in 'string', line 13, column 4 to column 35)", + " (in 'string', line 14, column 4 to column 25)", + " (in 'string', line 15, column 11 to column 12)", + " (in 'string', line 15, column 13 to column 20)", + " (in 'string', line 15, column 4 to column 26)", + " (in 'string', line 18, column 10 to column 14)", + " (in 'string', line 21, column 11 to column 19)", + " (in 'string', line 22, column 27 to column 34)", + " (in 'string', line 25, column 8 to column 12)", + " (in 'string', line 26, column 8 to column 12)", + " (in 'string', line 27, column 18 to column 19)", + " (in 'string', line 49, column 9 to column 16)", + " (in 'string', line 50, column 9 to column 12)", + " (in 'string', line 51, column 9 to column 13)", + " (in 'string', line 52, column 9 to column 13)", + " (in 'string', line 52, column 14 to column 23)"}; +#include +class model_joint_binary_cov_catchability_negbin final : public model_base_crtp { +private: + int S; + int C; + std::vector L; + std::vector R; + int Nloc; + std::vector E; + std::vector N; + std::vector K; + std::vector p10priors; + std::vector phipriors; + int nsitecov; + Eigen::Matrix mat_site_data__; + int nparams; + Eigen::Matrix mat_data__; + int log_lik_1dim__; + int mu_2dim__; + Eigen::Map> mat_site{nullptr, 0, 0}; + Eigen::Map> mat{nullptr, 0, 0}; +public: + ~model_joint_binary_cov_catchability_negbin() {} + model_joint_binary_cov_catchability_negbin(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_joint_binary_cov_catchability_negbin_namespace::model_joint_binary_cov_catchability_negbin"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 45; + context__.validate_dims("data initialization", "S", "int", + std::vector{}); + S = std::numeric_limits::min(); + current_statement__ = 45; + S = context__.vals_i("S")[(1 - 1)]; + current_statement__ = 45; + stan::math::check_greater_or_equal(function__, "S", S, 1); + current_statement__ = 46; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 46; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 46; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 47; + stan::math::validate_non_negative_index("L", "S", S); + current_statement__ = 48; + context__.validate_dims("data initialization", "L", "int", + std::vector{static_cast(S)}); + L = std::vector(S, std::numeric_limits::min()); + current_statement__ = 48; + L = context__.vals_i("L"); + current_statement__ = 48; + stan::math::check_greater_or_equal(function__, "L", L, 1); + current_statement__ = 49; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 50; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 50; + R = context__.vals_i("R"); + current_statement__ = 50; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 51; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 51; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 51; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 52; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 53; + context__.validate_dims("data initialization", "E", "int", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::min()); + current_statement__ = 53; + E = context__.vals_i("E"); + current_statement__ = 53; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 54; + stan::math::validate_non_negative_index("N", "S", S); + current_statement__ = 55; + context__.validate_dims("data initialization", "N", "int", + std::vector{static_cast(S)}); + N = std::vector(S, std::numeric_limits::min()); + current_statement__ = 55; + N = context__.vals_i("N"); + current_statement__ = 55; + stan::math::check_greater_or_equal(function__, "N", N, 1); + current_statement__ = 56; + stan::math::validate_non_negative_index("K", "S", S); + current_statement__ = 57; + context__.validate_dims("data initialization", "K", "int", + std::vector{static_cast(S)}); + K = std::vector(S, std::numeric_limits::min()); + current_statement__ = 57; + K = context__.vals_i("K"); + current_statement__ = 57; + stan::math::check_greater_or_equal(function__, "K", K, 0); + current_statement__ = 58; + context__.validate_dims("data initialization", "p10priors", "double", + std::vector{static_cast(2)}); + p10priors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 58; + p10priors = context__.vals_r("p10priors"); + current_statement__ = 59; + context__.validate_dims("data initialization", "phipriors", "double", + std::vector{static_cast(2)}); + phipriors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 59; + phipriors = context__.vals_r("phipriors"); + current_statement__ = 60; + context__.validate_dims("data initialization", "nsitecov", "int", + std::vector{}); + nsitecov = std::numeric_limits::min(); + current_statement__ = 60; + nsitecov = context__.vals_i("nsitecov")[(1 - 1)]; + current_statement__ = 60; + stan::math::check_greater_or_equal(function__, "nsitecov", nsitecov, 0); + current_statement__ = 61; + stan::math::validate_non_negative_index("mat_site", "Nloc", Nloc); + current_statement__ = 62; + stan::math::validate_non_negative_index("mat_site", "nsitecov", + nsitecov); + current_statement__ = 63; + context__.validate_dims("data initialization", "mat_site", "double", + std::vector{static_cast(Nloc), + static_cast(nsitecov)}); + mat_site_data__ = Eigen::Matrix::Constant(Nloc, nsitecov, + std::numeric_limits::quiet_NaN()); + new (&mat_site) + Eigen::Map>(mat_site_data__.data(), Nloc, + nsitecov); + { + std::vector mat_site_flat__; + current_statement__ = 63; + mat_site_flat__ = context__.vals_r("mat_site"); + current_statement__ = 63; + pos__ = 1; + current_statement__ = 63; + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + current_statement__ = 63; + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + current_statement__ = 63; + stan::model::assign(mat_site, mat_site_flat__[(pos__ - 1)], + "assigning variable mat_site", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 63; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 64; + context__.validate_dims("data initialization", "nparams", "int", + std::vector{}); + nparams = std::numeric_limits::min(); + current_statement__ = 64; + nparams = context__.vals_i("nparams")[(1 - 1)]; + current_statement__ = 64; + stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); + current_statement__ = 65; + stan::math::validate_non_negative_index("mat", "C", C); + current_statement__ = 66; + stan::math::validate_non_negative_index("mat", "nparams", nparams); + current_statement__ = 67; + context__.validate_dims("data initialization", "mat", "double", + std::vector{static_cast(C), + static_cast(nparams)}); + mat_data__ = Eigen::Matrix::Constant(C, nparams, + std::numeric_limits::quiet_NaN()); + new (&mat) Eigen::Map>(mat_data__.data(), + C, nparams); + { + std::vector mat_flat__; + current_statement__ = 67; + mat_flat__ = context__.vals_r("mat"); + current_statement__ = 67; + pos__ = 1; + current_statement__ = 67; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 67; + for (int sym2__ = 1; sym2__ <= C; ++sym2__) { + current_statement__ = 67; + stan::model::assign(mat, mat_flat__[(pos__ - 1)], + "assigning variable mat", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 67; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 68; + stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); + current_statement__ = 69; + stan::math::validate_non_negative_index("alpha", "nsitecov", nsitecov); + current_statement__ = 70; + stan::math::validate_non_negative_index("q_trans", "nparams", nparams); + current_statement__ = 71; + stan::math::validate_non_negative_index("p11", "Nloc", Nloc); + current_statement__ = 72; + stan::math::validate_non_negative_index("p", "Nloc", Nloc); + current_statement__ = 73; + stan::math::validate_non_negative_index("coef", "C", C); + current_statement__ = 74; + stan::math::validate_non_negative_index("q", "nparams", nparams); + current_statement__ = 75; + log_lik_1dim__ = std::numeric_limits::min(); + current_statement__ = 75; + log_lik_1dim__ = (C + S); + current_statement__ = 75; + stan::math::validate_non_negative_index("log_lik", "C + S", + log_lik_1dim__); + current_statement__ = 76; + stan::math::validate_non_negative_index("beta", "Nloc", Nloc); + current_statement__ = 77; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 78; + mu_2dim__ = std::numeric_limits::min(); + current_statement__ = 78; + mu_2dim__ = (nparams + 1); + current_statement__ = 78; + stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + 1 + 1 + nsitecov + nparams; + } + inline std::string model_name() const final { + return "model_joint_binary_cov_catchability_negbin"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_joint_binary_cov_catchability_negbin_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu_1 = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = in__.template read_constrain_lb(0, + lp__); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + current_statement__ = 4; + alpha = in__.template read< + Eigen::Matrix>(nsitecov); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 5; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + std::vector p11 = + std::vector(Nloc, DUMMY_VAR__); + std::vector p = + std::vector(Nloc, DUMMY_VAR__); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, DUMMY_VAR__); + current_statement__ = 17; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 14; + stan::model::assign(p11, + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + + stan::math::exp( + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha)))), + "assigning variable p11", stan::model::index_uni(i)); + current_statement__ = 15; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 20; + for (int k = 1; k <= C; ++k) { + current_statement__ = 18; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), + q_trans)), "assigning variable coef", stan::model::index_uni(k)); + } + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 7; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 8; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + { + current_statement__ = 38; + for (int j = 1; j <= C; ++j) { + current_statement__ = 36; + lp_accum__.add(stan::math::neg_binomial_2_lpmf( + stan::model::rvalue(E, "E", + stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", + stan::model::index_uni(j)) * + stan::model::rvalue(mu_1, "mu_1", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j))))), phi)); + } + current_statement__ = 41; + for (int i = 1; i <= S; ++i) { + current_statement__ = 39; + lp_accum__.add(stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", + stan::model::index_uni(i)), + stan::model::rvalue(N, "N", + stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", + stan::model::index_uni(i)))))); + } + current_statement__ = 42; + lp_accum__.add(stan::math::normal_lpdf(log_p10, + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(1)), + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(2)))); + current_statement__ = 43; + lp_accum__.add(stan::math::normal_lpdf(alpha, 0, 10)); + current_statement__ = 44; + lp_accum__.add(stan::math::gamma_lpdf(phi, + stan::model::rvalue(phipriors, "phipriors", + stan::model::index_uni(1)), + stan::model::rvalue(phipriors, "phipriors", + stan::model::index_uni(2)))); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_joint_binary_cov_catchability_negbin_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector mu_1 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + mu_1 = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + double phi = std::numeric_limits::quiet_NaN(); + current_statement__ = 2; + phi = in__.template read_constrain_lb(0, + lp__); + double log_p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, + std::numeric_limits::quiet_NaN()); + current_statement__ = 4; + alpha = in__.template read< + Eigen::Matrix>(nsitecov); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + current_statement__ = 5; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + std::vector p11 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector p = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + out__.write(mu_1); + out__.write(phi); + out__.write(log_p10); + out__.write(alpha); + out__.write(q_trans); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 17; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 14; + stan::model::assign(p11, + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + + stan::math::exp( + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha)))), + "assigning variable p11", stan::model::index_uni(i)); + current_statement__ = 15; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 20; + for (int k = 1; k <= C; ++k) { + current_statement__ = 18; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), + q_trans)), "assigning variable coef", stan::model::index_uni(k)); + } + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 7; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 8; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + if (emit_transformed_parameters__) { + out__.write(p11); + out__.write(p); + out__.write(coef); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix q = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(log_lik_1dim__, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix beta = + Eigen::Matrix::Constant(Nloc, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix mu = + Eigen::Matrix::Constant(Nloc, mu_2dim__, + std::numeric_limits::quiet_NaN()); + double p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 21; + p10 = stan::math::exp(log_p10); + current_statement__ = 24; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 22; + stan::model::assign(beta, + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha), "assigning variable beta", + stan::model::index_uni(i)); + } + current_statement__ = 25; + stan::model::assign(q, stan::math::add(q_trans, 1), + "assigning variable q"); + current_statement__ = 26; + stan::model::assign(mu, stan::math::to_vector(mu_1), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni(1)); + current_statement__ = 29; + for (int i = 1; i <= nparams; ++i) { + current_statement__ = 27; + stan::model::assign(mu, + stan::math::multiply(stan::math::to_vector(mu_1), + stan::model::rvalue(q, "q", stan::model::index_uni(i))), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni((i + 1))); + } + current_statement__ = 32; + for (int j = 1; j <= C; ++j) { + current_statement__ = 30; + stan::model::assign(log_lik, + stan::math::neg_binomial_2_lpmf( + stan::model::rvalue(E, "E", stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * + stan::model::rvalue(mu_1, "mu_1", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + phi), "assigning variable log_lik", stan::model::index_uni(j)); + } + current_statement__ = 35; + for (int i = 1; i <= S; ++i) { + current_statement__ = 33; + stan::model::assign(log_lik, + stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", stan::model::index_uni(i)), + stan::model::rvalue(N, "N", stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", stan::model::index_uni(i))))), + "assigning variable log_lik", stan::model::index_uni((C + i))); + } + out__.write(q); + out__.write(log_lik); + out__.write(beta); + out__.write(mu); + out__.write(p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(mu_1, + in__.read>(Nloc), + "assigning variable mu_1"); + out__.write_free_lb(0, mu_1); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = in__.read(); + out__.write_free_lb(0, phi); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = in__.read(); + out__.write_free_ub(0, log_p10); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + current_statement__ = 4; + stan::model::assign(alpha, + in__.read>(nsitecov), + "assigning variable alpha"); + out__.write(alpha); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 5; + stan::model::assign(q_trans, + in__.read>(nparams), + "assigning variable q_trans"); + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "mu_1", "double", + std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "phi", "double", + std::vector{}); + current_statement__ = 3; + context__.validate_dims("parameter initialization", "log_p10", + "double", std::vector{}); + current_statement__ = 4; + context__.validate_dims("parameter initialization", "alpha", "double", + std::vector{static_cast(nsitecov)}); + current_statement__ = 5; + context__.validate_dims("parameter initialization", "q_trans", + "double", std::vector{static_cast(nparams)}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu_1 = context__.vals_r("mu_1"); + out__.write_free_lb(0, mu_1); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = context__.vals_r("phi")[(1 - 1)]; + out__.write_free_lb(0, phi); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = context__.vals_r("log_p10")[(1 - 1)]; + out__.write_free_ub(0, log_p10); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + { + std::vector alpha_flat__; + current_statement__ = 4; + alpha_flat__ = context__.vals_r("alpha"); + current_statement__ = 4; + pos__ = 1; + current_statement__ = 4; + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + current_statement__ = 4; + stan::model::assign(alpha, alpha_flat__[(pos__ - 1)], + "assigning variable alpha", stan::model::index_uni(sym1__)); + current_statement__ = 4; + pos__ = (pos__ + 1); + } + } + out__.write(alpha); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + { + std::vector q_trans_flat__; + current_statement__ = 5; + q_trans_flat__ = context__.vals_r("q_trans"); + current_statement__ = 5; + pos__ = 1; + current_statement__ = 5; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 5; + stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], + "assigning variable q_trans", stan::model::index_uni(sym1__)); + current_statement__ = 5; + pos__ = (pos__ + 1); + } + } + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"mu_1", "phi", "log_p10", "alpha", + "q_trans"}; + if (emit_transformed_parameters__) { + std::vector temp{"p11", "p", "coef"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"q", "log_lik", "beta", "mu", "p10"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{}, std::vector{}, + std::vector{static_cast(nsitecov)}, + std::vector{static_cast(nparams)}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(C)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(nparams)}, + std::vector{static_cast(log_lik_1dim__)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc), + static_cast(mu_2dim__)}, std::vector{}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "phi"); + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "phi"); + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((((Nloc + 1) + 1) + nsitecov) + nparams); + const size_t num_transformed = emit_transformed_parameters * (((Nloc + + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * + (((((nparams + log_lik_1dim__) + Nloc) + (Nloc * mu_2dim__)) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((((Nloc + 1) + 1) + nsitecov) + nparams); + const size_t num_transformed = emit_transformed_parameters * (((Nloc + + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * + (((((nparams + log_lik_1dim__) + Nloc) + (Nloc * mu_2dim__)) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_joint_binary_cov_catchability_negbin_namespace::model_joint_binary_cov_catchability_negbin; +#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_joint_binary_cov_catchability_negbin_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_joint_binary_cov_catchability_pois.h b/src/stanExports_joint_binary_cov_catchability_pois.h index 8e2673d..a6244b6 100644 --- a/src/stanExports_joint_binary_cov_catchability_pois.h +++ b/src/stanExports_joint_binary_cov_catchability_pois.h @@ -1,1037 +1,1037 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_joint_binary_cov_catchability_pois_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'joint_binary_cov_catchability_pois', line 17, column 4 to column 35)", - " (in 'joint_binary_cov_catchability_pois', line 18, column 4 to column 26)", - " (in 'joint_binary_cov_catchability_pois', line 19, column 4 to column 27)", - " (in 'joint_binary_cov_catchability_pois', line 20, column 4 to column 44)", - " (in 'joint_binary_cov_catchability_pois', line 23, column 2 to column 43)", - " (in 'joint_binary_cov_catchability_pois', line 24, column 2 to column 41)", - " (in 'joint_binary_cov_catchability_pois', line 25, column 2 to column 26)", - " (in 'joint_binary_cov_catchability_pois', line 46, column 2 to column 20)", - " (in 'joint_binary_cov_catchability_pois', line 47, column 2 to column 22)", - " (in 'joint_binary_cov_catchability_pois', line 48, column 2 to column 20)", - " (in 'joint_binary_cov_catchability_pois', line 49, column 2 to column 28)", - " (in 'joint_binary_cov_catchability_pois', line 50, column 2 to column 11)", - " (in 'joint_binary_cov_catchability_pois', line 27, column 4 to column 71)", - " (in 'joint_binary_cov_catchability_pois', line 28, column 4 to column 33)", - " (in 'joint_binary_cov_catchability_pois', line 26, column 19 to line 29, column 3)", - " (in 'joint_binary_cov_catchability_pois', line 26, column 2 to line 29, column 3)", - " (in 'joint_binary_cov_catchability_pois', line 31, column 6 to column 48)", - " (in 'joint_binary_cov_catchability_pois', line 30, column 15 to line 32, column 5)", - " (in 'joint_binary_cov_catchability_pois', line 30, column 2 to line 32, column 5)", - " (in 'joint_binary_cov_catchability_pois', line 51, column 2 to column 21)", - " (in 'joint_binary_cov_catchability_pois', line 53, column 4 to column 45)", - " (in 'joint_binary_cov_catchability_pois', line 52, column 19 to line 54, column 3)", - " (in 'joint_binary_cov_catchability_pois', line 52, column 2 to line 54, column 3)", - " (in 'joint_binary_cov_catchability_pois', line 55, column 2 to column 18)", - " (in 'joint_binary_cov_catchability_pois', line 56, column 2 to column 27)", - " (in 'joint_binary_cov_catchability_pois', line 58, column 4 to column 36)", - " (in 'joint_binary_cov_catchability_pois', line 57, column 21 to line 59, column 3)", - " (in 'joint_binary_cov_catchability_pois', line 57, column 2 to line 59, column 3)", - " (in 'joint_binary_cov_catchability_pois', line 61, column 10 to column 63)", - " (in 'joint_binary_cov_catchability_pois', line 60, column 17 to line 62, column 7)", - " (in 'joint_binary_cov_catchability_pois', line 60, column 4 to line 62, column 7)", - " (in 'joint_binary_cov_catchability_pois', line 64, column 10 to column 61)", - " (in 'joint_binary_cov_catchability_pois', line 63, column 19 to line 65, column 7)", - " (in 'joint_binary_cov_catchability_pois', line 63, column 6 to line 65, column 7)", - " (in 'joint_binary_cov_catchability_pois', line 36, column 8 to column 43)", - " (in 'joint_binary_cov_catchability_pois', line 35, column 18 to line 37, column 5)", - " (in 'joint_binary_cov_catchability_pois', line 35, column 4 to line 37, column 5)", - " (in 'joint_binary_cov_catchability_pois', line 39, column 8 to column 39)", - " (in 'joint_binary_cov_catchability_pois', line 38, column 18 to line 40, column 5)", - " (in 'joint_binary_cov_catchability_pois', line 38, column 4 to line 40, column 5)", - " (in 'joint_binary_cov_catchability_pois', line 42, column 2 to column 47)", - " (in 'joint_binary_cov_catchability_pois', line 43, column 2 to column 23)", - " (in 'joint_binary_cov_catchability_pois', line 2, column 4 to column 19)", - " (in 'joint_binary_cov_catchability_pois', line 3, column 4 to column 19)", - " (in 'joint_binary_cov_catchability_pois', line 4, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_pois', line 4, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_pois', line 5, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_pois', line 5, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_pois', line 6, column 4 to column 22)", - " (in 'joint_binary_cov_catchability_pois', line 7, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_pois', line 7, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_pois', line 8, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_pois', line 8, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_pois', line 9, column 10 to column 11)", - " (in 'joint_binary_cov_catchability_pois', line 9, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_pois', line 10, column 4 to column 28)", - " (in 'joint_binary_cov_catchability_pois', line 11, column 4 to column 26)", - " (in 'joint_binary_cov_catchability_pois', line 12, column 11 to column 15)", - " (in 'joint_binary_cov_catchability_pois', line 12, column 16 to column 24)", - " (in 'joint_binary_cov_catchability_pois', line 12, column 4 to column 35)", - " (in 'joint_binary_cov_catchability_pois', line 13, column 4 to column 25)", - " (in 'joint_binary_cov_catchability_pois', line 14, column 11 to column 12)", - " (in 'joint_binary_cov_catchability_pois', line 14, column 13 to column 20)", - " (in 'joint_binary_cov_catchability_pois', line 14, column 4 to column 26)", - " (in 'joint_binary_cov_catchability_pois', line 17, column 10 to column 14)", - " (in 'joint_binary_cov_catchability_pois', line 19, column 11 to column 19)", - " (in 'joint_binary_cov_catchability_pois', line 20, column 27 to column 34)", - " (in 'joint_binary_cov_catchability_pois', line 23, column 8 to column 12)", - " (in 'joint_binary_cov_catchability_pois', line 24, column 8 to column 12)", - " (in 'joint_binary_cov_catchability_pois', line 25, column 18 to column 19)", - " (in 'joint_binary_cov_catchability_pois', line 46, column 9 to column 16)", - " (in 'joint_binary_cov_catchability_pois', line 47, column 9 to column 12)", - " (in 'joint_binary_cov_catchability_pois', line 48, column 9 to column 13)", - " (in 'joint_binary_cov_catchability_pois', line 49, column 9 to column 13)", - " (in 'joint_binary_cov_catchability_pois', line 49, column 14 to column 23)"}; -#include -class model_joint_binary_cov_catchability_pois final : public model_base_crtp { -private: - int S; - int C; - std::vector L; - std::vector R; - int Nloc; - std::vector E; - std::vector N; - std::vector K; - std::vector p10priors; - int nsitecov; - Eigen::Matrix mat_site_data__; - int nparams; - Eigen::Matrix mat_data__; - int log_lik_1dim__; - int mu_2dim__; - Eigen::Map> mat_site{nullptr, 0, 0}; - Eigen::Map> mat{nullptr, 0, 0}; -public: - ~model_joint_binary_cov_catchability_pois() {} - model_joint_binary_cov_catchability_pois(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_joint_binary_cov_catchability_pois_namespace::model_joint_binary_cov_catchability_pois"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 43; - context__.validate_dims("data initialization", "S", "int", - std::vector{}); - S = std::numeric_limits::min(); - current_statement__ = 43; - S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 43; - stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 44; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 44; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 44; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 45; - stan::math::validate_non_negative_index("L", "S", S); - current_statement__ = 46; - context__.validate_dims("data initialization", "L", "int", - std::vector{static_cast(S)}); - L = std::vector(S, std::numeric_limits::min()); - current_statement__ = 46; - L = context__.vals_i("L"); - current_statement__ = 46; - stan::math::check_greater_or_equal(function__, "L", L, 1); - current_statement__ = 47; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 48; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 48; - R = context__.vals_i("R"); - current_statement__ = 48; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 49; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 49; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 49; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 50; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 51; - context__.validate_dims("data initialization", "E", "int", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::min()); - current_statement__ = 51; - E = context__.vals_i("E"); - current_statement__ = 51; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 52; - stan::math::validate_non_negative_index("N", "S", S); - current_statement__ = 53; - context__.validate_dims("data initialization", "N", "int", - std::vector{static_cast(S)}); - N = std::vector(S, std::numeric_limits::min()); - current_statement__ = 53; - N = context__.vals_i("N"); - current_statement__ = 53; - stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 54; - stan::math::validate_non_negative_index("K", "S", S); - current_statement__ = 55; - context__.validate_dims("data initialization", "K", "int", - std::vector{static_cast(S)}); - K = std::vector(S, std::numeric_limits::min()); - current_statement__ = 55; - K = context__.vals_i("K"); - current_statement__ = 55; - stan::math::check_greater_or_equal(function__, "K", K, 0); - current_statement__ = 56; - context__.validate_dims("data initialization", "p10priors", "double", - std::vector{static_cast(2)}); - p10priors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 56; - p10priors = context__.vals_r("p10priors"); - current_statement__ = 57; - context__.validate_dims("data initialization", "nsitecov", "int", - std::vector{}); - nsitecov = std::numeric_limits::min(); - current_statement__ = 57; - nsitecov = context__.vals_i("nsitecov")[(1 - 1)]; - current_statement__ = 57; - stan::math::check_greater_or_equal(function__, "nsitecov", nsitecov, 0); - current_statement__ = 58; - stan::math::validate_non_negative_index("mat_site", "Nloc", Nloc); - current_statement__ = 59; - stan::math::validate_non_negative_index("mat_site", "nsitecov", - nsitecov); - current_statement__ = 60; - context__.validate_dims("data initialization", "mat_site", "double", - std::vector{static_cast(Nloc), - static_cast(nsitecov)}); - mat_site_data__ = Eigen::Matrix::Constant(Nloc, nsitecov, - std::numeric_limits::quiet_NaN()); - new (&mat_site) - Eigen::Map>(mat_site_data__.data(), Nloc, - nsitecov); - { - std::vector mat_site_flat__; - current_statement__ = 60; - mat_site_flat__ = context__.vals_r("mat_site"); - current_statement__ = 60; - pos__ = 1; - current_statement__ = 60; - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - current_statement__ = 60; - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - current_statement__ = 60; - stan::model::assign(mat_site, mat_site_flat__[(pos__ - 1)], - "assigning variable mat_site", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 60; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 61; - context__.validate_dims("data initialization", "nparams", "int", - std::vector{}); - nparams = std::numeric_limits::min(); - current_statement__ = 61; - nparams = context__.vals_i("nparams")[(1 - 1)]; - current_statement__ = 61; - stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); - current_statement__ = 62; - stan::math::validate_non_negative_index("mat", "C", C); - current_statement__ = 63; - stan::math::validate_non_negative_index("mat", "nparams", nparams); - current_statement__ = 64; - context__.validate_dims("data initialization", "mat", "double", - std::vector{static_cast(C), - static_cast(nparams)}); - mat_data__ = Eigen::Matrix::Constant(C, nparams, - std::numeric_limits::quiet_NaN()); - new (&mat) Eigen::Map>(mat_data__.data(), - C, nparams); - { - std::vector mat_flat__; - current_statement__ = 64; - mat_flat__ = context__.vals_r("mat"); - current_statement__ = 64; - pos__ = 1; - current_statement__ = 64; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 64; - for (int sym2__ = 1; sym2__ <= C; ++sym2__) { - current_statement__ = 64; - stan::model::assign(mat, mat_flat__[(pos__ - 1)], - "assigning variable mat", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 64; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 65; - stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); - current_statement__ = 66; - stan::math::validate_non_negative_index("alpha", "nsitecov", nsitecov); - current_statement__ = 67; - stan::math::validate_non_negative_index("q_trans", "nparams", nparams); - current_statement__ = 68; - stan::math::validate_non_negative_index("p11", "Nloc", Nloc); - current_statement__ = 69; - stan::math::validate_non_negative_index("p", "Nloc", Nloc); - current_statement__ = 70; - stan::math::validate_non_negative_index("coef", "C", C); - current_statement__ = 71; - stan::math::validate_non_negative_index("q", "nparams", nparams); - current_statement__ = 72; - log_lik_1dim__ = std::numeric_limits::min(); - current_statement__ = 72; - log_lik_1dim__ = (C + S); - current_statement__ = 72; - stan::math::validate_non_negative_index("log_lik", "C + S", - log_lik_1dim__); - current_statement__ = 73; - stan::math::validate_non_negative_index("beta", "Nloc", Nloc); - current_statement__ = 74; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 75; - mu_2dim__ = std::numeric_limits::min(); - current_statement__ = 75; - mu_2dim__ = (nparams + 1); - current_statement__ = 75; - stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + 1 + nsitecov + nparams; - } - inline std::string model_name() const final { - return "model_joint_binary_cov_catchability_pois"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_joint_binary_cov_catchability_pois_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu_1 = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 2; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - current_statement__ = 3; - alpha = in__.template read< - Eigen::Matrix>(nsitecov); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 4; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - std::vector p11 = - std::vector(Nloc, DUMMY_VAR__); - std::vector p = - std::vector(Nloc, DUMMY_VAR__); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, DUMMY_VAR__); - current_statement__ = 16; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 13; - stan::model::assign(p11, - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + - stan::math::exp( - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha)))), - "assigning variable p11", stan::model::index_uni(i)); - current_statement__ = 14; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 19; - for (int k = 1; k <= C; ++k) { - current_statement__ = 17; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), - q_trans)), "assigning variable coef", stan::model::index_uni(k)); - } - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 5; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - { - current_statement__ = 37; - for (int j = 1; j <= C; ++j) { - current_statement__ = 35; - lp_accum__.add(stan::math::poisson_lpmf( - stan::model::rvalue(E, "E", - stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", - stan::model::index_uni(j)) * - stan::model::rvalue(mu_1, "mu_1", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j))))))); - } - current_statement__ = 40; - for (int i = 1; i <= S; ++i) { - current_statement__ = 38; - lp_accum__.add(stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", - stan::model::index_uni(i)), - stan::model::rvalue(N, "N", - stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", - stan::model::index_uni(i)))))); - } - current_statement__ = 41; - lp_accum__.add(stan::math::normal_lpdf(log_p10, - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(1)), - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(2)))); - current_statement__ = 42; - lp_accum__.add(stan::math::normal_lpdf(alpha, 0, 10)); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_joint_binary_cov_catchability_pois_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector mu_1 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - mu_1 = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - double log_p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 2; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, - std::numeric_limits::quiet_NaN()); - current_statement__ = 3; - alpha = in__.template read< - Eigen::Matrix>(nsitecov); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - current_statement__ = 4; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - std::vector p11 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector p = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - out__.write(mu_1); - out__.write(log_p10); - out__.write(alpha); - out__.write(q_trans); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 16; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 13; - stan::model::assign(p11, - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / - (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + - stan::math::exp( - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha)))), - "assigning variable p11", stan::model::index_uni(i)); - current_statement__ = 14; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 19; - for (int k = 1; k <= C; ++k) { - current_statement__ = 17; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), - q_trans)), "assigning variable coef", stan::model::index_uni(k)); - } - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 5; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - if (emit_transformed_parameters__) { - out__.write(p11); - out__.write(p); - out__.write(coef); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix q = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(log_lik_1dim__, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix beta = - Eigen::Matrix::Constant(Nloc, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix mu = - Eigen::Matrix::Constant(Nloc, mu_2dim__, - std::numeric_limits::quiet_NaN()); - double p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 20; - p10 = stan::math::exp(log_p10); - current_statement__ = 23; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 21; - stan::model::assign(beta, - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha), "assigning variable beta", - stan::model::index_uni(i)); - } - current_statement__ = 24; - stan::model::assign(q, stan::math::add(q_trans, 1), - "assigning variable q"); - current_statement__ = 25; - stan::model::assign(mu, stan::math::to_vector(mu_1), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni(1)); - current_statement__ = 28; - for (int i = 1; i <= nparams; ++i) { - current_statement__ = 26; - stan::model::assign(mu, - stan::math::multiply(stan::math::to_vector(mu_1), - stan::model::rvalue(q, "q", stan::model::index_uni(i))), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni((i + 1))); - } - current_statement__ = 31; - for (int j = 1; j <= C; ++j) { - current_statement__ = 29; - stan::model::assign(log_lik, - stan::math::poisson_lpmf( - stan::model::rvalue(E, "E", stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * - stan::model::rvalue(mu_1, "mu_1", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j)))))), - "assigning variable log_lik", stan::model::index_uni(j)); - } - current_statement__ = 34; - for (int i = 1; i <= S; ++i) { - current_statement__ = 32; - stan::model::assign(log_lik, - stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", stan::model::index_uni(i)), - stan::model::rvalue(N, "N", stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", stan::model::index_uni(i))))), - "assigning variable log_lik", stan::model::index_uni((C + i))); - } - out__.write(q); - out__.write(log_lik); - out__.write(beta); - out__.write(mu); - out__.write(p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(mu_1, - in__.read>(Nloc), - "assigning variable mu_1"); - out__.write_free_lb(0, mu_1); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 2; - log_p10 = in__.read(); - out__.write_free_ub(0, log_p10); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - current_statement__ = 3; - stan::model::assign(alpha, - in__.read>(nsitecov), - "assigning variable alpha"); - out__.write(alpha); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 4; - stan::model::assign(q_trans, - in__.read>(nparams), - "assigning variable q_trans"); - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "mu_1", "double", - std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "log_p10", - "double", std::vector{}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "alpha", "double", - std::vector{static_cast(nsitecov)}); - current_statement__ = 4; - context__.validate_dims("parameter initialization", "q_trans", - "double", std::vector{static_cast(nparams)}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu_1 = context__.vals_r("mu_1"); - out__.write_free_lb(0, mu_1); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 2; - log_p10 = context__.vals_r("log_p10")[(1 - 1)]; - out__.write_free_ub(0, log_p10); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - { - std::vector alpha_flat__; - current_statement__ = 3; - alpha_flat__ = context__.vals_r("alpha"); - current_statement__ = 3; - pos__ = 1; - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - current_statement__ = 3; - stan::model::assign(alpha, alpha_flat__[(pos__ - 1)], - "assigning variable alpha", stan::model::index_uni(sym1__)); - current_statement__ = 3; - pos__ = (pos__ + 1); - } - } - out__.write(alpha); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - { - std::vector q_trans_flat__; - current_statement__ = 4; - q_trans_flat__ = context__.vals_r("q_trans"); - current_statement__ = 4; - pos__ = 1; - current_statement__ = 4; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 4; - stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], - "assigning variable q_trans", stan::model::index_uni(sym1__)); - current_statement__ = 4; - pos__ = (pos__ + 1); - } - } - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"mu_1", "log_p10", "alpha", "q_trans"}; - if (emit_transformed_parameters__) { - std::vector temp{"p11", "p", "coef"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"q", "log_lik", "beta", "mu", "p10"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{}, - std::vector{static_cast(nsitecov)}, - std::vector{static_cast(nparams)}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(C)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(nparams)}, - std::vector{static_cast(log_lik_1dim__)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc), - static_cast(mu_2dim__)}, std::vector{}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (((Nloc + 1) + nsitecov) + nparams); - const size_t num_transformed = emit_transformed_parameters * (((Nloc + - Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * - (((((nparams + log_lik_1dim__) + Nloc) + (Nloc * mu_2dim__)) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (((Nloc + 1) + nsitecov) + nparams); - const size_t num_transformed = emit_transformed_parameters * (((Nloc + - Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * - (((((nparams + log_lik_1dim__) + Nloc) + (Nloc * mu_2dim__)) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_joint_binary_cov_catchability_pois_namespace::model_joint_binary_cov_catchability_pois; -#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_joint_binary_cov_catchability_pois_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_joint_binary_cov_catchability_pois_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 17, column 4 to column 35)", + " (in 'string', line 18, column 4 to column 26)", + " (in 'string', line 19, column 4 to column 27)", + " (in 'string', line 20, column 4 to column 44)", + " (in 'string', line 23, column 2 to column 43)", + " (in 'string', line 24, column 2 to column 41)", + " (in 'string', line 25, column 2 to column 26)", + " (in 'string', line 46, column 2 to column 20)", + " (in 'string', line 47, column 2 to column 22)", + " (in 'string', line 48, column 2 to column 20)", + " (in 'string', line 49, column 2 to column 28)", + " (in 'string', line 50, column 2 to column 11)", + " (in 'string', line 27, column 4 to column 71)", + " (in 'string', line 28, column 4 to column 33)", + " (in 'string', line 26, column 19 to line 29, column 3)", + " (in 'string', line 26, column 2 to line 29, column 3)", + " (in 'string', line 31, column 6 to column 48)", + " (in 'string', line 30, column 15 to line 32, column 5)", + " (in 'string', line 30, column 2 to line 32, column 5)", + " (in 'string', line 51, column 2 to column 21)", + " (in 'string', line 53, column 4 to column 45)", + " (in 'string', line 52, column 19 to line 54, column 3)", + " (in 'string', line 52, column 2 to line 54, column 3)", + " (in 'string', line 55, column 2 to column 18)", + " (in 'string', line 56, column 2 to column 27)", + " (in 'string', line 58, column 4 to column 36)", + " (in 'string', line 57, column 21 to line 59, column 3)", + " (in 'string', line 57, column 2 to line 59, column 3)", + " (in 'string', line 61, column 10 to column 63)", + " (in 'string', line 60, column 17 to line 62, column 7)", + " (in 'string', line 60, column 4 to line 62, column 7)", + " (in 'string', line 64, column 10 to column 61)", + " (in 'string', line 63, column 19 to line 65, column 7)", + " (in 'string', line 63, column 6 to line 65, column 7)", + " (in 'string', line 36, column 8 to column 43)", + " (in 'string', line 35, column 18 to line 37, column 5)", + " (in 'string', line 35, column 4 to line 37, column 5)", + " (in 'string', line 39, column 8 to column 39)", + " (in 'string', line 38, column 18 to line 40, column 5)", + " (in 'string', line 38, column 4 to line 40, column 5)", + " (in 'string', line 42, column 2 to column 47)", + " (in 'string', line 43, column 2 to column 23)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 4 to column 19)", + " (in 'string', line 4, column 10 to column 11)", + " (in 'string', line 4, column 4 to column 28)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 22)", + " (in 'string', line 7, column 10 to column 11)", + " (in 'string', line 7, column 4 to column 28)", + " (in 'string', line 8, column 10 to column 11)", + " (in 'string', line 8, column 4 to column 28)", + " (in 'string', line 9, column 10 to column 11)", + " (in 'string', line 9, column 4 to column 28)", + " (in 'string', line 10, column 4 to column 28)", + " (in 'string', line 11, column 4 to column 26)", + " (in 'string', line 12, column 11 to column 15)", + " (in 'string', line 12, column 16 to column 24)", + " (in 'string', line 12, column 4 to column 35)", + " (in 'string', line 13, column 4 to column 25)", + " (in 'string', line 14, column 11 to column 12)", + " (in 'string', line 14, column 13 to column 20)", + " (in 'string', line 14, column 4 to column 26)", + " (in 'string', line 17, column 10 to column 14)", + " (in 'string', line 19, column 11 to column 19)", + " (in 'string', line 20, column 27 to column 34)", + " (in 'string', line 23, column 8 to column 12)", + " (in 'string', line 24, column 8 to column 12)", + " (in 'string', line 25, column 18 to column 19)", + " (in 'string', line 46, column 9 to column 16)", + " (in 'string', line 47, column 9 to column 12)", + " (in 'string', line 48, column 9 to column 13)", + " (in 'string', line 49, column 9 to column 13)", + " (in 'string', line 49, column 14 to column 23)"}; +#include +class model_joint_binary_cov_catchability_pois final : public model_base_crtp { +private: + int S; + int C; + std::vector L; + std::vector R; + int Nloc; + std::vector E; + std::vector N; + std::vector K; + std::vector p10priors; + int nsitecov; + Eigen::Matrix mat_site_data__; + int nparams; + Eigen::Matrix mat_data__; + int log_lik_1dim__; + int mu_2dim__; + Eigen::Map> mat_site{nullptr, 0, 0}; + Eigen::Map> mat{nullptr, 0, 0}; +public: + ~model_joint_binary_cov_catchability_pois() {} + model_joint_binary_cov_catchability_pois(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_joint_binary_cov_catchability_pois_namespace::model_joint_binary_cov_catchability_pois"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 43; + context__.validate_dims("data initialization", "S", "int", + std::vector{}); + S = std::numeric_limits::min(); + current_statement__ = 43; + S = context__.vals_i("S")[(1 - 1)]; + current_statement__ = 43; + stan::math::check_greater_or_equal(function__, "S", S, 1); + current_statement__ = 44; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 44; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 44; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 45; + stan::math::validate_non_negative_index("L", "S", S); + current_statement__ = 46; + context__.validate_dims("data initialization", "L", "int", + std::vector{static_cast(S)}); + L = std::vector(S, std::numeric_limits::min()); + current_statement__ = 46; + L = context__.vals_i("L"); + current_statement__ = 46; + stan::math::check_greater_or_equal(function__, "L", L, 1); + current_statement__ = 47; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 48; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 48; + R = context__.vals_i("R"); + current_statement__ = 48; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 49; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 49; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 49; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 50; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 51; + context__.validate_dims("data initialization", "E", "int", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::min()); + current_statement__ = 51; + E = context__.vals_i("E"); + current_statement__ = 51; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 52; + stan::math::validate_non_negative_index("N", "S", S); + current_statement__ = 53; + context__.validate_dims("data initialization", "N", "int", + std::vector{static_cast(S)}); + N = std::vector(S, std::numeric_limits::min()); + current_statement__ = 53; + N = context__.vals_i("N"); + current_statement__ = 53; + stan::math::check_greater_or_equal(function__, "N", N, 1); + current_statement__ = 54; + stan::math::validate_non_negative_index("K", "S", S); + current_statement__ = 55; + context__.validate_dims("data initialization", "K", "int", + std::vector{static_cast(S)}); + K = std::vector(S, std::numeric_limits::min()); + current_statement__ = 55; + K = context__.vals_i("K"); + current_statement__ = 55; + stan::math::check_greater_or_equal(function__, "K", K, 0); + current_statement__ = 56; + context__.validate_dims("data initialization", "p10priors", "double", + std::vector{static_cast(2)}); + p10priors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 56; + p10priors = context__.vals_r("p10priors"); + current_statement__ = 57; + context__.validate_dims("data initialization", "nsitecov", "int", + std::vector{}); + nsitecov = std::numeric_limits::min(); + current_statement__ = 57; + nsitecov = context__.vals_i("nsitecov")[(1 - 1)]; + current_statement__ = 57; + stan::math::check_greater_or_equal(function__, "nsitecov", nsitecov, 0); + current_statement__ = 58; + stan::math::validate_non_negative_index("mat_site", "Nloc", Nloc); + current_statement__ = 59; + stan::math::validate_non_negative_index("mat_site", "nsitecov", + nsitecov); + current_statement__ = 60; + context__.validate_dims("data initialization", "mat_site", "double", + std::vector{static_cast(Nloc), + static_cast(nsitecov)}); + mat_site_data__ = Eigen::Matrix::Constant(Nloc, nsitecov, + std::numeric_limits::quiet_NaN()); + new (&mat_site) + Eigen::Map>(mat_site_data__.data(), Nloc, + nsitecov); + { + std::vector mat_site_flat__; + current_statement__ = 60; + mat_site_flat__ = context__.vals_r("mat_site"); + current_statement__ = 60; + pos__ = 1; + current_statement__ = 60; + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + current_statement__ = 60; + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + current_statement__ = 60; + stan::model::assign(mat_site, mat_site_flat__[(pos__ - 1)], + "assigning variable mat_site", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 60; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 61; + context__.validate_dims("data initialization", "nparams", "int", + std::vector{}); + nparams = std::numeric_limits::min(); + current_statement__ = 61; + nparams = context__.vals_i("nparams")[(1 - 1)]; + current_statement__ = 61; + stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); + current_statement__ = 62; + stan::math::validate_non_negative_index("mat", "C", C); + current_statement__ = 63; + stan::math::validate_non_negative_index("mat", "nparams", nparams); + current_statement__ = 64; + context__.validate_dims("data initialization", "mat", "double", + std::vector{static_cast(C), + static_cast(nparams)}); + mat_data__ = Eigen::Matrix::Constant(C, nparams, + std::numeric_limits::quiet_NaN()); + new (&mat) Eigen::Map>(mat_data__.data(), + C, nparams); + { + std::vector mat_flat__; + current_statement__ = 64; + mat_flat__ = context__.vals_r("mat"); + current_statement__ = 64; + pos__ = 1; + current_statement__ = 64; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 64; + for (int sym2__ = 1; sym2__ <= C; ++sym2__) { + current_statement__ = 64; + stan::model::assign(mat, mat_flat__[(pos__ - 1)], + "assigning variable mat", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 64; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 65; + stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); + current_statement__ = 66; + stan::math::validate_non_negative_index("alpha", "nsitecov", nsitecov); + current_statement__ = 67; + stan::math::validate_non_negative_index("q_trans", "nparams", nparams); + current_statement__ = 68; + stan::math::validate_non_negative_index("p11", "Nloc", Nloc); + current_statement__ = 69; + stan::math::validate_non_negative_index("p", "Nloc", Nloc); + current_statement__ = 70; + stan::math::validate_non_negative_index("coef", "C", C); + current_statement__ = 71; + stan::math::validate_non_negative_index("q", "nparams", nparams); + current_statement__ = 72; + log_lik_1dim__ = std::numeric_limits::min(); + current_statement__ = 72; + log_lik_1dim__ = (C + S); + current_statement__ = 72; + stan::math::validate_non_negative_index("log_lik", "C + S", + log_lik_1dim__); + current_statement__ = 73; + stan::math::validate_non_negative_index("beta", "Nloc", Nloc); + current_statement__ = 74; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 75; + mu_2dim__ = std::numeric_limits::min(); + current_statement__ = 75; + mu_2dim__ = (nparams + 1); + current_statement__ = 75; + stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + 1 + nsitecov + nparams; + } + inline std::string model_name() const final { + return "model_joint_binary_cov_catchability_pois"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_joint_binary_cov_catchability_pois_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu_1 = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 2; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + current_statement__ = 3; + alpha = in__.template read< + Eigen::Matrix>(nsitecov); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 4; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + std::vector p11 = + std::vector(Nloc, DUMMY_VAR__); + std::vector p = + std::vector(Nloc, DUMMY_VAR__); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, DUMMY_VAR__); + current_statement__ = 16; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 13; + stan::model::assign(p11, + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + + stan::math::exp( + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha)))), + "assigning variable p11", stan::model::index_uni(i)); + current_statement__ = 14; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 19; + for (int k = 1; k <= C; ++k) { + current_statement__ = 17; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), + q_trans)), "assigning variable coef", stan::model::index_uni(k)); + } + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 5; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + { + current_statement__ = 37; + for (int j = 1; j <= C; ++j) { + current_statement__ = 35; + lp_accum__.add(stan::math::poisson_lpmf( + stan::model::rvalue(E, "E", + stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", + stan::model::index_uni(j)) * + stan::model::rvalue(mu_1, "mu_1", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j))))))); + } + current_statement__ = 40; + for (int i = 1; i <= S; ++i) { + current_statement__ = 38; + lp_accum__.add(stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", + stan::model::index_uni(i)), + stan::model::rvalue(N, "N", + stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", + stan::model::index_uni(i)))))); + } + current_statement__ = 41; + lp_accum__.add(stan::math::normal_lpdf(log_p10, + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(1)), + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(2)))); + current_statement__ = 42; + lp_accum__.add(stan::math::normal_lpdf(alpha, 0, 10)); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_joint_binary_cov_catchability_pois_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector mu_1 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + mu_1 = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + double log_p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 2; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, + std::numeric_limits::quiet_NaN()); + current_statement__ = 3; + alpha = in__.template read< + Eigen::Matrix>(nsitecov); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + current_statement__ = 4; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + std::vector p11 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector p = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + out__.write(mu_1); + out__.write(log_p10); + out__.write(alpha); + out__.write(q_trans); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 16; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 13; + stan::model::assign(p11, + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) / + (stan::model::rvalue(mu_1, "mu_1", stan::model::index_uni(i)) + + stan::math::exp( + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha)))), + "assigning variable p11", stan::model::index_uni(i)); + current_statement__ = 14; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 19; + for (int k = 1; k <= C; ++k) { + current_statement__ = 17; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(k)), + q_trans)), "assigning variable coef", stan::model::index_uni(k)); + } + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 5; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + if (emit_transformed_parameters__) { + out__.write(p11); + out__.write(p); + out__.write(coef); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix q = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(log_lik_1dim__, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix beta = + Eigen::Matrix::Constant(Nloc, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix mu = + Eigen::Matrix::Constant(Nloc, mu_2dim__, + std::numeric_limits::quiet_NaN()); + double p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 20; + p10 = stan::math::exp(log_p10); + current_statement__ = 23; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 21; + stan::model::assign(beta, + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha), "assigning variable beta", + stan::model::index_uni(i)); + } + current_statement__ = 24; + stan::model::assign(q, stan::math::add(q_trans, 1), + "assigning variable q"); + current_statement__ = 25; + stan::model::assign(mu, stan::math::to_vector(mu_1), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni(1)); + current_statement__ = 28; + for (int i = 1; i <= nparams; ++i) { + current_statement__ = 26; + stan::model::assign(mu, + stan::math::multiply(stan::math::to_vector(mu_1), + stan::model::rvalue(q, "q", stan::model::index_uni(i))), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni((i + 1))); + } + current_statement__ = 31; + for (int j = 1; j <= C; ++j) { + current_statement__ = 29; + stan::model::assign(log_lik, + stan::math::poisson_lpmf( + stan::model::rvalue(E, "E", stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * + stan::model::rvalue(mu_1, "mu_1", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j)))))), + "assigning variable log_lik", stan::model::index_uni(j)); + } + current_statement__ = 34; + for (int i = 1; i <= S; ++i) { + current_statement__ = 32; + stan::model::assign(log_lik, + stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", stan::model::index_uni(i)), + stan::model::rvalue(N, "N", stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", stan::model::index_uni(i))))), + "assigning variable log_lik", stan::model::index_uni((C + i))); + } + out__.write(q); + out__.write(log_lik); + out__.write(beta); + out__.write(mu); + out__.write(p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(mu_1, + in__.read>(Nloc), + "assigning variable mu_1"); + out__.write_free_lb(0, mu_1); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 2; + log_p10 = in__.read(); + out__.write_free_ub(0, log_p10); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + current_statement__ = 3; + stan::model::assign(alpha, + in__.read>(nsitecov), + "assigning variable alpha"); + out__.write(alpha); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 4; + stan::model::assign(q_trans, + in__.read>(nparams), + "assigning variable q_trans"); + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "mu_1", "double", + std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "log_p10", + "double", std::vector{}); + current_statement__ = 3; + context__.validate_dims("parameter initialization", "alpha", "double", + std::vector{static_cast(nsitecov)}); + current_statement__ = 4; + context__.validate_dims("parameter initialization", "q_trans", + "double", std::vector{static_cast(nparams)}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu_1 = context__.vals_r("mu_1"); + out__.write_free_lb(0, mu_1); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 2; + log_p10 = context__.vals_r("log_p10")[(1 - 1)]; + out__.write_free_ub(0, log_p10); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + { + std::vector alpha_flat__; + current_statement__ = 3; + alpha_flat__ = context__.vals_r("alpha"); + current_statement__ = 3; + pos__ = 1; + current_statement__ = 3; + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + current_statement__ = 3; + stan::model::assign(alpha, alpha_flat__[(pos__ - 1)], + "assigning variable alpha", stan::model::index_uni(sym1__)); + current_statement__ = 3; + pos__ = (pos__ + 1); + } + } + out__.write(alpha); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + { + std::vector q_trans_flat__; + current_statement__ = 4; + q_trans_flat__ = context__.vals_r("q_trans"); + current_statement__ = 4; + pos__ = 1; + current_statement__ = 4; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 4; + stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], + "assigning variable q_trans", stan::model::index_uni(sym1__)); + current_statement__ = 4; + pos__ = (pos__ + 1); + } + } + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"mu_1", "log_p10", "alpha", "q_trans"}; + if (emit_transformed_parameters__) { + std::vector temp{"p11", "p", "coef"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"q", "log_lik", "beta", "mu", "p10"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{}, + std::vector{static_cast(nsitecov)}, + std::vector{static_cast(nparams)}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(C)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(nparams)}, + std::vector{static_cast(log_lik_1dim__)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc), + static_cast(mu_2dim__)}, std::vector{}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (((Nloc + 1) + nsitecov) + nparams); + const size_t num_transformed = emit_transformed_parameters * (((Nloc + + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * + (((((nparams + log_lik_1dim__) + Nloc) + (Nloc * mu_2dim__)) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (((Nloc + 1) + nsitecov) + nparams); + const size_t num_transformed = emit_transformed_parameters * (((Nloc + + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * + (((((nparams + log_lik_1dim__) + Nloc) + (Nloc * mu_2dim__)) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_joint_binary_cov_catchability_pois_namespace::model_joint_binary_cov_catchability_pois; +#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_joint_binary_cov_catchability_pois_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_joint_binary_cov_gamma.h b/src/stanExports_joint_binary_cov_gamma.h index 77b1bcb..a82f755 100644 --- a/src/stanExports_joint_binary_cov_gamma.h +++ b/src/stanExports_joint_binary_cov_gamma.h @@ -1,960 +1,960 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_joint_binary_cov_gamma_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'joint_binary_cov_gamma', line 15, column 4 to column 42)", - " (in 'joint_binary_cov_gamma', line 16, column 4 to column 45)", - " (in 'joint_binary_cov_gamma', line 17, column 4 to column 26)", - " (in 'joint_binary_cov_gamma', line 18, column 4 to column 27)", - " (in 'joint_binary_cov_gamma', line 21, column 2 to column 43)", - " (in 'joint_binary_cov_gamma', line 22, column 2 to column 41)", - " (in 'joint_binary_cov_gamma', line 23, column 2 to column 31)", - " (in 'joint_binary_cov_gamma', line 24, column 2 to column 33)", - " (in 'joint_binary_cov_gamma', line 48, column 2 to column 22)", - " (in 'joint_binary_cov_gamma', line 49, column 2 to column 20)", - " (in 'joint_binary_cov_gamma', line 50, column 2 to column 11)", - " (in 'joint_binary_cov_gamma', line 26, column 4 to column 41)", - " (in 'joint_binary_cov_gamma', line 27, column 4 to column 67)", - " (in 'joint_binary_cov_gamma', line 28, column 4 to column 33)", - " (in 'joint_binary_cov_gamma', line 25, column 19 to line 29, column 3)", - " (in 'joint_binary_cov_gamma', line 25, column 2 to line 29, column 3)", - " (in 'joint_binary_cov_gamma', line 31, column 6 to column 42)", - " (in 'joint_binary_cov_gamma', line 30, column 15 to line 32, column 5)", - " (in 'joint_binary_cov_gamma', line 30, column 2 to line 32, column 5)", - " (in 'joint_binary_cov_gamma', line 51, column 2 to column 21)", - " (in 'joint_binary_cov_gamma', line 53, column 4 to column 45)", - " (in 'joint_binary_cov_gamma', line 52, column 19 to line 54, column 3)", - " (in 'joint_binary_cov_gamma', line 52, column 2 to line 54, column 3)", - " (in 'joint_binary_cov_gamma', line 56, column 10 to column 84)", - " (in 'joint_binary_cov_gamma', line 55, column 17 to line 57, column 7)", - " (in 'joint_binary_cov_gamma', line 55, column 4 to line 57, column 7)", - " (in 'joint_binary_cov_gamma', line 59, column 10 to column 61)", - " (in 'joint_binary_cov_gamma', line 58, column 19 to line 60, column 7)", - " (in 'joint_binary_cov_gamma', line 58, column 6 to line 60, column 7)", - " (in 'joint_binary_cov_gamma', line 36, column 8 to column 63)", - " (in 'joint_binary_cov_gamma', line 35, column 18 to line 37, column 5)", - " (in 'joint_binary_cov_gamma', line 35, column 4 to line 37, column 5)", - " (in 'joint_binary_cov_gamma', line 39, column 8 to column 39)", - " (in 'joint_binary_cov_gamma', line 38, column 18 to line 40, column 5)", - " (in 'joint_binary_cov_gamma', line 38, column 4 to line 40, column 5)", - " (in 'joint_binary_cov_gamma', line 42, column 2 to column 47)", - " (in 'joint_binary_cov_gamma', line 43, column 2 to column 23)", - " (in 'joint_binary_cov_gamma', line 44, column 2 to column 32)", - " (in 'joint_binary_cov_gamma', line 45, column 2 to column 33)", - " (in 'joint_binary_cov_gamma', line 2, column 4 to column 19)", - " (in 'joint_binary_cov_gamma', line 3, column 4 to column 19)", - " (in 'joint_binary_cov_gamma', line 4, column 10 to column 11)", - " (in 'joint_binary_cov_gamma', line 4, column 4 to column 28)", - " (in 'joint_binary_cov_gamma', line 5, column 10 to column 11)", - " (in 'joint_binary_cov_gamma', line 5, column 4 to column 28)", - " (in 'joint_binary_cov_gamma', line 6, column 4 to column 22)", - " (in 'joint_binary_cov_gamma', line 7, column 10 to column 11)", - " (in 'joint_binary_cov_gamma', line 7, column 4 to column 29)", - " (in 'joint_binary_cov_gamma', line 8, column 10 to column 11)", - " (in 'joint_binary_cov_gamma', line 8, column 4 to column 28)", - " (in 'joint_binary_cov_gamma', line 9, column 10 to column 11)", - " (in 'joint_binary_cov_gamma', line 9, column 4 to column 28)", - " (in 'joint_binary_cov_gamma', line 10, column 4 to column 28)", - " (in 'joint_binary_cov_gamma', line 11, column 4 to column 26)", - " (in 'joint_binary_cov_gamma', line 12, column 11 to column 15)", - " (in 'joint_binary_cov_gamma', line 12, column 16 to column 24)", - " (in 'joint_binary_cov_gamma', line 12, column 4 to column 35)", - " (in 'joint_binary_cov_gamma', line 15, column 10 to column 14)", - " (in 'joint_binary_cov_gamma', line 16, column 10 to column 14)", - " (in 'joint_binary_cov_gamma', line 18, column 11 to column 19)", - " (in 'joint_binary_cov_gamma', line 21, column 8 to column 12)", - " (in 'joint_binary_cov_gamma', line 22, column 8 to column 12)", - " (in 'joint_binary_cov_gamma', line 23, column 8 to column 12)", - " (in 'joint_binary_cov_gamma', line 24, column 8 to column 9)", - " (in 'joint_binary_cov_gamma', line 48, column 9 to column 12)", - " (in 'joint_binary_cov_gamma', line 49, column 9 to column 13)"}; -#include -class model_joint_binary_cov_gamma final : public model_base_crtp { -private: - int S; - int C; - std::vector L; - std::vector R; - int Nloc; - std::vector E; - std::vector N; - std::vector K; - std::vector p10priors; - int nsitecov; - Eigen::Matrix mat_site_data__; - int log_lik_1dim__; - Eigen::Map> mat_site{nullptr, 0, 0}; -public: - ~model_joint_binary_cov_gamma() {} - model_joint_binary_cov_gamma(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_joint_binary_cov_gamma_namespace::model_joint_binary_cov_gamma"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 40; - context__.validate_dims("data initialization", "S", "int", - std::vector{}); - S = std::numeric_limits::min(); - current_statement__ = 40; - S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 40; - stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 41; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 41; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 41; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 42; - stan::math::validate_non_negative_index("L", "S", S); - current_statement__ = 43; - context__.validate_dims("data initialization", "L", "int", - std::vector{static_cast(S)}); - L = std::vector(S, std::numeric_limits::min()); - current_statement__ = 43; - L = context__.vals_i("L"); - current_statement__ = 43; - stan::math::check_greater_or_equal(function__, "L", L, 1); - current_statement__ = 44; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 45; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 45; - R = context__.vals_i("R"); - current_statement__ = 45; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 46; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 46; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 46; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 47; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 48; - context__.validate_dims("data initialization", "E", "double", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::quiet_NaN()); - current_statement__ = 48; - E = context__.vals_r("E"); - current_statement__ = 48; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 49; - stan::math::validate_non_negative_index("N", "S", S); - current_statement__ = 50; - context__.validate_dims("data initialization", "N", "int", - std::vector{static_cast(S)}); - N = std::vector(S, std::numeric_limits::min()); - current_statement__ = 50; - N = context__.vals_i("N"); - current_statement__ = 50; - stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 51; - stan::math::validate_non_negative_index("K", "S", S); - current_statement__ = 52; - context__.validate_dims("data initialization", "K", "int", - std::vector{static_cast(S)}); - K = std::vector(S, std::numeric_limits::min()); - current_statement__ = 52; - K = context__.vals_i("K"); - current_statement__ = 52; - stan::math::check_greater_or_equal(function__, "K", K, 0); - current_statement__ = 53; - context__.validate_dims("data initialization", "p10priors", "double", - std::vector{static_cast(2)}); - p10priors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 53; - p10priors = context__.vals_r("p10priors"); - current_statement__ = 54; - context__.validate_dims("data initialization", "nsitecov", "int", - std::vector{}); - nsitecov = std::numeric_limits::min(); - current_statement__ = 54; - nsitecov = context__.vals_i("nsitecov")[(1 - 1)]; - current_statement__ = 54; - stan::math::check_greater_or_equal(function__, "nsitecov", nsitecov, 0); - current_statement__ = 55; - stan::math::validate_non_negative_index("mat_site", "Nloc", Nloc); - current_statement__ = 56; - stan::math::validate_non_negative_index("mat_site", "nsitecov", - nsitecov); - current_statement__ = 57; - context__.validate_dims("data initialization", "mat_site", "double", - std::vector{static_cast(Nloc), - static_cast(nsitecov)}); - mat_site_data__ = Eigen::Matrix::Constant(Nloc, nsitecov, - std::numeric_limits::quiet_NaN()); - new (&mat_site) - Eigen::Map>(mat_site_data__.data(), Nloc, - nsitecov); - { - std::vector mat_site_flat__; - current_statement__ = 57; - mat_site_flat__ = context__.vals_r("mat_site"); - current_statement__ = 57; - pos__ = 1; - current_statement__ = 57; - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - current_statement__ = 57; - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - current_statement__ = 57; - stan::model::assign(mat_site, mat_site_flat__[(pos__ - 1)], - "assigning variable mat_site", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 57; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 58; - stan::math::validate_non_negative_index("alpha_gamma", "Nloc", Nloc); - current_statement__ = 59; - stan::math::validate_non_negative_index("beta_gamma", "Nloc", Nloc); - current_statement__ = 60; - stan::math::validate_non_negative_index("alpha", "nsitecov", nsitecov); - current_statement__ = 61; - stan::math::validate_non_negative_index("p11", "Nloc", Nloc); - current_statement__ = 62; - stan::math::validate_non_negative_index("p", "Nloc", Nloc); - current_statement__ = 63; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 64; - stan::math::validate_non_negative_index("E_trans", "C", C); - current_statement__ = 65; - log_lik_1dim__ = std::numeric_limits::min(); - current_statement__ = 65; - log_lik_1dim__ = (C + S); - current_statement__ = 65; - stan::math::validate_non_negative_index("log_lik", "C + S", - log_lik_1dim__); - current_statement__ = 66; - stan::math::validate_non_negative_index("beta", "Nloc", Nloc); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + Nloc + 1 + nsitecov; - } - inline std::string model_name() const final { - return "model_joint_binary_cov_gamma"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_joint_binary_cov_gamma_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector alpha_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - alpha_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0, lp__, - Nloc); - std::vector beta_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - beta_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0.01, lp__, - Nloc); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - current_statement__ = 4; - alpha = in__.template read< - Eigen::Matrix>(nsitecov); - std::vector p11 = - std::vector(Nloc, DUMMY_VAR__); - std::vector p = - std::vector(Nloc, DUMMY_VAR__); - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - std::vector E_trans = - std::vector(C, DUMMY_VAR__); - current_statement__ = 16; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 12; - stan::model::assign(mu, - (stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni(i)) / - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni(i))), "assigning variable mu", - stan::model::index_uni(i)); - current_statement__ = 13; - stan::model::assign(p11, - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + - stan::math::exp( - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha)))), - "assigning variable p11", stan::model::index_uni(i)); - current_statement__ = 14; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 19; - for (int j = 1; j <= C; ++j) { - current_statement__ = 17; - stan::model::assign(E_trans, - (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + - 0.0000000000001), "assigning variable E_trans", - stan::model::index_uni(j)); - } - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 5; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "mu", mu, 0); - current_statement__ = 8; - stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); - { - current_statement__ = 32; - for (int j = 1; j <= C; ++j) { - current_statement__ = 30; - lp_accum__.add(stan::math::gamma_lpdf( - stan::model::rvalue(E_trans, "E_trans", - stan::model::index_uni(j)), - stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))), - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))))); - } - current_statement__ = 35; - for (int i = 1; i <= S; ++i) { - current_statement__ = 33; - lp_accum__.add(stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", - stan::model::index_uni(i)), - stan::model::rvalue(N, "N", - stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", - stan::model::index_uni(i)))))); - } - current_statement__ = 36; - lp_accum__.add(stan::math::normal_lpdf(log_p10, - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(1)), - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(2)))); - current_statement__ = 37; - lp_accum__.add(stan::math::normal_lpdf(alpha, 0, 10)); - current_statement__ = 38; - lp_accum__.add(stan::math::gamma_lpdf(beta_gamma, 0.25, - 0.25)); - current_statement__ = 39; - lp_accum__.add(stan::math::gamma_lpdf(alpha_gamma, 0.01, - 0.01)); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_joint_binary_cov_gamma_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector alpha_gamma = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - alpha_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0, lp__, - Nloc); - std::vector beta_gamma = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 2; - beta_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0.01, lp__, - Nloc); - double log_p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 3; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, - std::numeric_limits::quiet_NaN()); - current_statement__ = 4; - alpha = in__.template read< - Eigen::Matrix>(nsitecov); - std::vector p11 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector p = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector mu = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector E_trans = - std::vector(C, std::numeric_limits::quiet_NaN()); - out__.write(alpha_gamma); - out__.write(beta_gamma); - out__.write(log_p10); - out__.write(alpha); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 16; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 12; - stan::model::assign(mu, - (stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni(i)) / - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni(i))), "assigning variable mu", - stan::model::index_uni(i)); - current_statement__ = 13; - stan::model::assign(p11, - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + - stan::math::exp( - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha)))), - "assigning variable p11", stan::model::index_uni(i)); - current_statement__ = 14; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 19; - for (int j = 1; j <= C; ++j) { - current_statement__ = 17; - stan::model::assign(E_trans, - (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + - 0.0000000000001), "assigning variable E_trans", - stan::model::index_uni(j)); - } - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 5; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "mu", mu, 0); - current_statement__ = 8; - stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); - if (emit_transformed_parameters__) { - out__.write(p11); - out__.write(p); - out__.write(mu); - out__.write(E_trans); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(log_lik_1dim__, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix beta = - Eigen::Matrix::Constant(Nloc, - std::numeric_limits::quiet_NaN()); - double p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 20; - p10 = stan::math::exp(log_p10); - current_statement__ = 23; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 21; - stan::model::assign(beta, - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha), "assigning variable beta", - stan::model::index_uni(i)); - } - current_statement__ = 26; - for (int j = 1; j <= C; ++j) { - current_statement__ = 24; - stan::model::assign(log_lik, - stan::math::gamma_lpdf( - stan::model::rvalue(E_trans, "E_trans", stan::model::index_uni(j)), - stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j)))), - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - "assigning variable log_lik", stan::model::index_uni(j)); - } - current_statement__ = 29; - for (int i = 1; i <= S; ++i) { - current_statement__ = 27; - stan::model::assign(log_lik, - stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", stan::model::index_uni(i)), - stan::model::rvalue(N, "N", stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", stan::model::index_uni(i))))), - "assigning variable log_lik", stan::model::index_uni((C + i))); - } - out__.write(log_lik); - out__.write(beta); - out__.write(p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector alpha_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(alpha_gamma, - in__.read>(Nloc), - "assigning variable alpha_gamma"); - out__.write_free_lb(0, alpha_gamma); - std::vector beta_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - stan::model::assign(beta_gamma, - in__.read>(Nloc), - "assigning variable beta_gamma"); - out__.write_free_lb(0.01, beta_gamma); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = in__.read(); - out__.write_free_ub(0, log_p10); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - current_statement__ = 4; - stan::model::assign(alpha, - in__.read>(nsitecov), - "assigning variable alpha"); - out__.write(alpha); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "alpha_gamma", - "double", std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "beta_gamma", - "double", std::vector{static_cast(Nloc)}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "log_p10", - "double", std::vector{}); - current_statement__ = 4; - context__.validate_dims("parameter initialization", "alpha", "double", - std::vector{static_cast(nsitecov)}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector alpha_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - alpha_gamma = context__.vals_r("alpha_gamma"); - out__.write_free_lb(0, alpha_gamma); - std::vector beta_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - beta_gamma = context__.vals_r("beta_gamma"); - out__.write_free_lb(0.01, beta_gamma); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = context__.vals_r("log_p10")[(1 - 1)]; - out__.write_free_ub(0, log_p10); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - { - std::vector alpha_flat__; - current_statement__ = 4; - alpha_flat__ = context__.vals_r("alpha"); - current_statement__ = 4; - pos__ = 1; - current_statement__ = 4; - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - current_statement__ = 4; - stan::model::assign(alpha, alpha_flat__[(pos__ - 1)], - "assigning variable alpha", stan::model::index_uni(sym1__)); - current_statement__ = 4; - pos__ = (pos__ + 1); - } - } - out__.write(alpha); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"alpha_gamma", "beta_gamma", - "log_p10", "alpha"}; - if (emit_transformed_parameters__) { - std::vector temp{"p11", "p", "mu", "E_trans"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"log_lik", "beta", "p10"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{}, - std::vector{static_cast(nsitecov)}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(C)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(log_lik_1dim__)}, - std::vector{static_cast(Nloc)}, - std::vector{}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta_gamma" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "E_trans" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta_gamma" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "E_trans" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (((Nloc + Nloc) + 1) + nsitecov); - const size_t num_transformed = emit_transformed_parameters * ((((Nloc + - Nloc) + Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * - (((log_lik_1dim__ + Nloc) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (((Nloc + Nloc) + 1) + nsitecov); - const size_t num_transformed = emit_transformed_parameters * ((((Nloc + - Nloc) + Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * - (((log_lik_1dim__ + Nloc) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_joint_binary_cov_gamma_namespace::model_joint_binary_cov_gamma; -#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_joint_binary_cov_gamma_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_joint_binary_cov_gamma_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 15, column 4 to column 42)", + " (in 'string', line 16, column 4 to column 45)", + " (in 'string', line 17, column 4 to column 26)", + " (in 'string', line 18, column 4 to column 27)", + " (in 'string', line 21, column 2 to column 43)", + " (in 'string', line 22, column 2 to column 41)", + " (in 'string', line 23, column 2 to column 31)", + " (in 'string', line 24, column 2 to column 33)", + " (in 'string', line 48, column 2 to column 22)", + " (in 'string', line 49, column 2 to column 20)", + " (in 'string', line 50, column 2 to column 11)", + " (in 'string', line 26, column 4 to column 41)", + " (in 'string', line 27, column 4 to column 67)", + " (in 'string', line 28, column 4 to column 33)", + " (in 'string', line 25, column 19 to line 29, column 3)", + " (in 'string', line 25, column 2 to line 29, column 3)", + " (in 'string', line 31, column 6 to column 42)", + " (in 'string', line 30, column 15 to line 32, column 5)", + " (in 'string', line 30, column 2 to line 32, column 5)", + " (in 'string', line 51, column 2 to column 21)", + " (in 'string', line 53, column 4 to column 45)", + " (in 'string', line 52, column 19 to line 54, column 3)", + " (in 'string', line 52, column 2 to line 54, column 3)", + " (in 'string', line 56, column 10 to column 84)", + " (in 'string', line 55, column 17 to line 57, column 7)", + " (in 'string', line 55, column 4 to line 57, column 7)", + " (in 'string', line 59, column 10 to column 61)", + " (in 'string', line 58, column 19 to line 60, column 7)", + " (in 'string', line 58, column 6 to line 60, column 7)", + " (in 'string', line 36, column 8 to column 63)", + " (in 'string', line 35, column 18 to line 37, column 5)", + " (in 'string', line 35, column 4 to line 37, column 5)", + " (in 'string', line 39, column 8 to column 39)", + " (in 'string', line 38, column 18 to line 40, column 5)", + " (in 'string', line 38, column 4 to line 40, column 5)", + " (in 'string', line 42, column 2 to column 47)", + " (in 'string', line 43, column 2 to column 23)", + " (in 'string', line 44, column 2 to column 32)", + " (in 'string', line 45, column 2 to column 33)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 4 to column 19)", + " (in 'string', line 4, column 10 to column 11)", + " (in 'string', line 4, column 4 to column 28)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 22)", + " (in 'string', line 7, column 10 to column 11)", + " (in 'string', line 7, column 4 to column 29)", + " (in 'string', line 8, column 10 to column 11)", + " (in 'string', line 8, column 4 to column 28)", + " (in 'string', line 9, column 10 to column 11)", + " (in 'string', line 9, column 4 to column 28)", + " (in 'string', line 10, column 4 to column 28)", + " (in 'string', line 11, column 4 to column 26)", + " (in 'string', line 12, column 11 to column 15)", + " (in 'string', line 12, column 16 to column 24)", + " (in 'string', line 12, column 4 to column 35)", + " (in 'string', line 15, column 10 to column 14)", + " (in 'string', line 16, column 10 to column 14)", + " (in 'string', line 18, column 11 to column 19)", + " (in 'string', line 21, column 8 to column 12)", + " (in 'string', line 22, column 8 to column 12)", + " (in 'string', line 23, column 8 to column 12)", + " (in 'string', line 24, column 8 to column 9)", + " (in 'string', line 48, column 9 to column 12)", + " (in 'string', line 49, column 9 to column 13)"}; +#include +class model_joint_binary_cov_gamma final : public model_base_crtp { +private: + int S; + int C; + std::vector L; + std::vector R; + int Nloc; + std::vector E; + std::vector N; + std::vector K; + std::vector p10priors; + int nsitecov; + Eigen::Matrix mat_site_data__; + int log_lik_1dim__; + Eigen::Map> mat_site{nullptr, 0, 0}; +public: + ~model_joint_binary_cov_gamma() {} + model_joint_binary_cov_gamma(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_joint_binary_cov_gamma_namespace::model_joint_binary_cov_gamma"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 40; + context__.validate_dims("data initialization", "S", "int", + std::vector{}); + S = std::numeric_limits::min(); + current_statement__ = 40; + S = context__.vals_i("S")[(1 - 1)]; + current_statement__ = 40; + stan::math::check_greater_or_equal(function__, "S", S, 1); + current_statement__ = 41; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 41; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 41; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 42; + stan::math::validate_non_negative_index("L", "S", S); + current_statement__ = 43; + context__.validate_dims("data initialization", "L", "int", + std::vector{static_cast(S)}); + L = std::vector(S, std::numeric_limits::min()); + current_statement__ = 43; + L = context__.vals_i("L"); + current_statement__ = 43; + stan::math::check_greater_or_equal(function__, "L", L, 1); + current_statement__ = 44; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 45; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 45; + R = context__.vals_i("R"); + current_statement__ = 45; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 46; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 46; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 46; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 47; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 48; + context__.validate_dims("data initialization", "E", "double", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::quiet_NaN()); + current_statement__ = 48; + E = context__.vals_r("E"); + current_statement__ = 48; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 49; + stan::math::validate_non_negative_index("N", "S", S); + current_statement__ = 50; + context__.validate_dims("data initialization", "N", "int", + std::vector{static_cast(S)}); + N = std::vector(S, std::numeric_limits::min()); + current_statement__ = 50; + N = context__.vals_i("N"); + current_statement__ = 50; + stan::math::check_greater_or_equal(function__, "N", N, 1); + current_statement__ = 51; + stan::math::validate_non_negative_index("K", "S", S); + current_statement__ = 52; + context__.validate_dims("data initialization", "K", "int", + std::vector{static_cast(S)}); + K = std::vector(S, std::numeric_limits::min()); + current_statement__ = 52; + K = context__.vals_i("K"); + current_statement__ = 52; + stan::math::check_greater_or_equal(function__, "K", K, 0); + current_statement__ = 53; + context__.validate_dims("data initialization", "p10priors", "double", + std::vector{static_cast(2)}); + p10priors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 53; + p10priors = context__.vals_r("p10priors"); + current_statement__ = 54; + context__.validate_dims("data initialization", "nsitecov", "int", + std::vector{}); + nsitecov = std::numeric_limits::min(); + current_statement__ = 54; + nsitecov = context__.vals_i("nsitecov")[(1 - 1)]; + current_statement__ = 54; + stan::math::check_greater_or_equal(function__, "nsitecov", nsitecov, 0); + current_statement__ = 55; + stan::math::validate_non_negative_index("mat_site", "Nloc", Nloc); + current_statement__ = 56; + stan::math::validate_non_negative_index("mat_site", "nsitecov", + nsitecov); + current_statement__ = 57; + context__.validate_dims("data initialization", "mat_site", "double", + std::vector{static_cast(Nloc), + static_cast(nsitecov)}); + mat_site_data__ = Eigen::Matrix::Constant(Nloc, nsitecov, + std::numeric_limits::quiet_NaN()); + new (&mat_site) + Eigen::Map>(mat_site_data__.data(), Nloc, + nsitecov); + { + std::vector mat_site_flat__; + current_statement__ = 57; + mat_site_flat__ = context__.vals_r("mat_site"); + current_statement__ = 57; + pos__ = 1; + current_statement__ = 57; + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + current_statement__ = 57; + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + current_statement__ = 57; + stan::model::assign(mat_site, mat_site_flat__[(pos__ - 1)], + "assigning variable mat_site", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 57; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 58; + stan::math::validate_non_negative_index("alpha_gamma", "Nloc", Nloc); + current_statement__ = 59; + stan::math::validate_non_negative_index("beta_gamma", "Nloc", Nloc); + current_statement__ = 60; + stan::math::validate_non_negative_index("alpha", "nsitecov", nsitecov); + current_statement__ = 61; + stan::math::validate_non_negative_index("p11", "Nloc", Nloc); + current_statement__ = 62; + stan::math::validate_non_negative_index("p", "Nloc", Nloc); + current_statement__ = 63; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 64; + stan::math::validate_non_negative_index("E_trans", "C", C); + current_statement__ = 65; + log_lik_1dim__ = std::numeric_limits::min(); + current_statement__ = 65; + log_lik_1dim__ = (C + S); + current_statement__ = 65; + stan::math::validate_non_negative_index("log_lik", "C + S", + log_lik_1dim__); + current_statement__ = 66; + stan::math::validate_non_negative_index("beta", "Nloc", Nloc); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + Nloc + 1 + nsitecov; + } + inline std::string model_name() const final { + return "model_joint_binary_cov_gamma"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_joint_binary_cov_gamma_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector alpha_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + alpha_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0, lp__, + Nloc); + std::vector beta_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + beta_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0.01, lp__, + Nloc); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + current_statement__ = 4; + alpha = in__.template read< + Eigen::Matrix>(nsitecov); + std::vector p11 = + std::vector(Nloc, DUMMY_VAR__); + std::vector p = + std::vector(Nloc, DUMMY_VAR__); + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + std::vector E_trans = + std::vector(C, DUMMY_VAR__); + current_statement__ = 16; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 12; + stan::model::assign(mu, + (stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni(i)) / + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni(i))), "assigning variable mu", + stan::model::index_uni(i)); + current_statement__ = 13; + stan::model::assign(p11, + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + + stan::math::exp( + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha)))), + "assigning variable p11", stan::model::index_uni(i)); + current_statement__ = 14; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 19; + for (int j = 1; j <= C; ++j) { + current_statement__ = 17; + stan::model::assign(E_trans, + (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + + 0.0000000000001), "assigning variable E_trans", + stan::model::index_uni(j)); + } + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 5; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "mu", mu, 0); + current_statement__ = 8; + stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); + { + current_statement__ = 32; + for (int j = 1; j <= C; ++j) { + current_statement__ = 30; + lp_accum__.add(stan::math::gamma_lpdf( + stan::model::rvalue(E_trans, "E_trans", + stan::model::index_uni(j)), + stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))), + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))))); + } + current_statement__ = 35; + for (int i = 1; i <= S; ++i) { + current_statement__ = 33; + lp_accum__.add(stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", + stan::model::index_uni(i)), + stan::model::rvalue(N, "N", + stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", + stan::model::index_uni(i)))))); + } + current_statement__ = 36; + lp_accum__.add(stan::math::normal_lpdf(log_p10, + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(1)), + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(2)))); + current_statement__ = 37; + lp_accum__.add(stan::math::normal_lpdf(alpha, 0, 10)); + current_statement__ = 38; + lp_accum__.add(stan::math::gamma_lpdf(beta_gamma, 0.25, + 0.25)); + current_statement__ = 39; + lp_accum__.add(stan::math::gamma_lpdf(alpha_gamma, 0.01, + 0.01)); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_joint_binary_cov_gamma_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector alpha_gamma = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + alpha_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0, lp__, + Nloc); + std::vector beta_gamma = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 2; + beta_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0.01, lp__, + Nloc); + double log_p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, + std::numeric_limits::quiet_NaN()); + current_statement__ = 4; + alpha = in__.template read< + Eigen::Matrix>(nsitecov); + std::vector p11 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector p = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector mu = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector E_trans = + std::vector(C, std::numeric_limits::quiet_NaN()); + out__.write(alpha_gamma); + out__.write(beta_gamma); + out__.write(log_p10); + out__.write(alpha); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 16; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 12; + stan::model::assign(mu, + (stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni(i)) / + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni(i))), "assigning variable mu", + stan::model::index_uni(i)); + current_statement__ = 13; + stan::model::assign(p11, + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + + stan::math::exp( + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha)))), + "assigning variable p11", stan::model::index_uni(i)); + current_statement__ = 14; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 19; + for (int j = 1; j <= C; ++j) { + current_statement__ = 17; + stan::model::assign(E_trans, + (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + + 0.0000000000001), "assigning variable E_trans", + stan::model::index_uni(j)); + } + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 5; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "mu", mu, 0); + current_statement__ = 8; + stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); + if (emit_transformed_parameters__) { + out__.write(p11); + out__.write(p); + out__.write(mu); + out__.write(E_trans); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(log_lik_1dim__, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix beta = + Eigen::Matrix::Constant(Nloc, + std::numeric_limits::quiet_NaN()); + double p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 20; + p10 = stan::math::exp(log_p10); + current_statement__ = 23; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 21; + stan::model::assign(beta, + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha), "assigning variable beta", + stan::model::index_uni(i)); + } + current_statement__ = 26; + for (int j = 1; j <= C; ++j) { + current_statement__ = 24; + stan::model::assign(log_lik, + stan::math::gamma_lpdf( + stan::model::rvalue(E_trans, "E_trans", stan::model::index_uni(j)), + stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j)))), + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + "assigning variable log_lik", stan::model::index_uni(j)); + } + current_statement__ = 29; + for (int i = 1; i <= S; ++i) { + current_statement__ = 27; + stan::model::assign(log_lik, + stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", stan::model::index_uni(i)), + stan::model::rvalue(N, "N", stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", stan::model::index_uni(i))))), + "assigning variable log_lik", stan::model::index_uni((C + i))); + } + out__.write(log_lik); + out__.write(beta); + out__.write(p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector alpha_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(alpha_gamma, + in__.read>(Nloc), + "assigning variable alpha_gamma"); + out__.write_free_lb(0, alpha_gamma); + std::vector beta_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + stan::model::assign(beta_gamma, + in__.read>(Nloc), + "assigning variable beta_gamma"); + out__.write_free_lb(0.01, beta_gamma); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = in__.read(); + out__.write_free_ub(0, log_p10); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + current_statement__ = 4; + stan::model::assign(alpha, + in__.read>(nsitecov), + "assigning variable alpha"); + out__.write(alpha); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "alpha_gamma", + "double", std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "beta_gamma", + "double", std::vector{static_cast(Nloc)}); + current_statement__ = 3; + context__.validate_dims("parameter initialization", "log_p10", + "double", std::vector{}); + current_statement__ = 4; + context__.validate_dims("parameter initialization", "alpha", "double", + std::vector{static_cast(nsitecov)}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector alpha_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + alpha_gamma = context__.vals_r("alpha_gamma"); + out__.write_free_lb(0, alpha_gamma); + std::vector beta_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + beta_gamma = context__.vals_r("beta_gamma"); + out__.write_free_lb(0.01, beta_gamma); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = context__.vals_r("log_p10")[(1 - 1)]; + out__.write_free_ub(0, log_p10); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + { + std::vector alpha_flat__; + current_statement__ = 4; + alpha_flat__ = context__.vals_r("alpha"); + current_statement__ = 4; + pos__ = 1; + current_statement__ = 4; + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + current_statement__ = 4; + stan::model::assign(alpha, alpha_flat__[(pos__ - 1)], + "assigning variable alpha", stan::model::index_uni(sym1__)); + current_statement__ = 4; + pos__ = (pos__ + 1); + } + } + out__.write(alpha); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"alpha_gamma", "beta_gamma", + "log_p10", "alpha"}; + if (emit_transformed_parameters__) { + std::vector temp{"p11", "p", "mu", "E_trans"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"log_lik", "beta", "p10"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{}, + std::vector{static_cast(nsitecov)}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(C)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(log_lik_1dim__)}, + std::vector{static_cast(Nloc)}, + std::vector{}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta_gamma" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "E_trans" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta_gamma" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "E_trans" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (((Nloc + Nloc) + 1) + nsitecov); + const size_t num_transformed = emit_transformed_parameters * ((((Nloc + + Nloc) + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * + (((log_lik_1dim__ + Nloc) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (((Nloc + Nloc) + 1) + nsitecov); + const size_t num_transformed = emit_transformed_parameters * ((((Nloc + + Nloc) + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * + (((log_lik_1dim__ + Nloc) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_joint_binary_cov_gamma_namespace::model_joint_binary_cov_gamma; +#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_joint_binary_cov_gamma_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_joint_binary_cov_negbin.h b/src/stanExports_joint_binary_cov_negbin.h index dec3fba..4deb32f 100644 --- a/src/stanExports_joint_binary_cov_negbin.h +++ b/src/stanExports_joint_binary_cov_negbin.h @@ -1,861 +1,861 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_joint_binary_cov_negbin_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'joint_binary_cov_negbin', line 16, column 4 to column 33)", - " (in 'joint_binary_cov_negbin', line 17, column 4 to column 22)", - " (in 'joint_binary_cov_negbin', line 18, column 4 to column 26)", - " (in 'joint_binary_cov_negbin', line 19, column 4 to column 27)", - " (in 'joint_binary_cov_negbin', line 22, column 2 to column 43)", - " (in 'joint_binary_cov_negbin', line 23, column 2 to column 41)", - " (in 'joint_binary_cov_negbin', line 42, column 2 to column 22)", - " (in 'joint_binary_cov_negbin', line 43, column 2 to column 20)", - " (in 'joint_binary_cov_negbin', line 44, column 2 to column 11)", - " (in 'joint_binary_cov_negbin', line 25, column 4 to column 67)", - " (in 'joint_binary_cov_negbin', line 26, column 4 to column 33)", - " (in 'joint_binary_cov_negbin', line 24, column 19 to line 27, column 3)", - " (in 'joint_binary_cov_negbin', line 24, column 2 to line 27, column 3)", - " (in 'joint_binary_cov_negbin', line 45, column 2 to column 21)", - " (in 'joint_binary_cov_negbin', line 47, column 4 to column 45)", - " (in 'joint_binary_cov_negbin', line 46, column 19 to line 48, column 3)", - " (in 'joint_binary_cov_negbin', line 46, column 2 to line 48, column 3)", - " (in 'joint_binary_cov_negbin', line 50, column 10 to column 65)", - " (in 'joint_binary_cov_negbin', line 49, column 17 to line 51, column 7)", - " (in 'joint_binary_cov_negbin', line 49, column 4 to line 51, column 7)", - " (in 'joint_binary_cov_negbin', line 53, column 10 to column 61)", - " (in 'joint_binary_cov_negbin', line 52, column 19 to line 54, column 7)", - " (in 'joint_binary_cov_negbin', line 52, column 6 to line 54, column 7)", - " (in 'joint_binary_cov_negbin', line 31, column 8 to column 45)", - " (in 'joint_binary_cov_negbin', line 30, column 18 to line 32, column 5)", - " (in 'joint_binary_cov_negbin', line 30, column 4 to line 32, column 5)", - " (in 'joint_binary_cov_negbin', line 34, column 8 to column 39)", - " (in 'joint_binary_cov_negbin', line 33, column 18 to line 35, column 5)", - " (in 'joint_binary_cov_negbin', line 33, column 4 to line 35, column 5)", - " (in 'joint_binary_cov_negbin', line 37, column 2 to column 47)", - " (in 'joint_binary_cov_negbin', line 38, column 2 to column 23)", - " (in 'joint_binary_cov_negbin', line 39, column 2 to column 42)", - " (in 'joint_binary_cov_negbin', line 2, column 4 to column 19)", - " (in 'joint_binary_cov_negbin', line 3, column 4 to column 19)", - " (in 'joint_binary_cov_negbin', line 4, column 10 to column 11)", - " (in 'joint_binary_cov_negbin', line 4, column 4 to column 28)", - " (in 'joint_binary_cov_negbin', line 5, column 10 to column 11)", - " (in 'joint_binary_cov_negbin', line 5, column 4 to column 28)", - " (in 'joint_binary_cov_negbin', line 6, column 4 to column 22)", - " (in 'joint_binary_cov_negbin', line 7, column 10 to column 11)", - " (in 'joint_binary_cov_negbin', line 7, column 4 to column 28)", - " (in 'joint_binary_cov_negbin', line 8, column 10 to column 11)", - " (in 'joint_binary_cov_negbin', line 8, column 4 to column 28)", - " (in 'joint_binary_cov_negbin', line 9, column 10 to column 11)", - " (in 'joint_binary_cov_negbin', line 9, column 4 to column 28)", - " (in 'joint_binary_cov_negbin', line 10, column 4 to column 28)", - " (in 'joint_binary_cov_negbin', line 11, column 4 to column 28)", - " (in 'joint_binary_cov_negbin', line 12, column 4 to column 26)", - " (in 'joint_binary_cov_negbin', line 13, column 11 to column 15)", - " (in 'joint_binary_cov_negbin', line 13, column 16 to column 24)", - " (in 'joint_binary_cov_negbin', line 13, column 4 to column 35)", - " (in 'joint_binary_cov_negbin', line 16, column 10 to column 14)", - " (in 'joint_binary_cov_negbin', line 19, column 11 to column 19)", - " (in 'joint_binary_cov_negbin', line 22, column 8 to column 12)", - " (in 'joint_binary_cov_negbin', line 23, column 8 to column 12)", - " (in 'joint_binary_cov_negbin', line 42, column 9 to column 12)", - " (in 'joint_binary_cov_negbin', line 43, column 9 to column 13)"}; -#include -class model_joint_binary_cov_negbin final : public model_base_crtp { -private: - int S; - int C; - std::vector L; - std::vector R; - int Nloc; - std::vector E; - std::vector N; - std::vector K; - std::vector p10priors; - std::vector phipriors; - int nsitecov; - Eigen::Matrix mat_site_data__; - int log_lik_1dim__; - Eigen::Map> mat_site{nullptr, 0, 0}; -public: - ~model_joint_binary_cov_negbin() {} - model_joint_binary_cov_negbin(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_joint_binary_cov_negbin_namespace::model_joint_binary_cov_negbin"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 33; - context__.validate_dims("data initialization", "S", "int", - std::vector{}); - S = std::numeric_limits::min(); - current_statement__ = 33; - S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 33; - stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 34; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 34; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 34; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 35; - stan::math::validate_non_negative_index("L", "S", S); - current_statement__ = 36; - context__.validate_dims("data initialization", "L", "int", - std::vector{static_cast(S)}); - L = std::vector(S, std::numeric_limits::min()); - current_statement__ = 36; - L = context__.vals_i("L"); - current_statement__ = 36; - stan::math::check_greater_or_equal(function__, "L", L, 1); - current_statement__ = 37; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 38; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 38; - R = context__.vals_i("R"); - current_statement__ = 38; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 39; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 39; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 39; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 40; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 41; - context__.validate_dims("data initialization", "E", "int", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::min()); - current_statement__ = 41; - E = context__.vals_i("E"); - current_statement__ = 41; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 42; - stan::math::validate_non_negative_index("N", "S", S); - current_statement__ = 43; - context__.validate_dims("data initialization", "N", "int", - std::vector{static_cast(S)}); - N = std::vector(S, std::numeric_limits::min()); - current_statement__ = 43; - N = context__.vals_i("N"); - current_statement__ = 43; - stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 44; - stan::math::validate_non_negative_index("K", "S", S); - current_statement__ = 45; - context__.validate_dims("data initialization", "K", "int", - std::vector{static_cast(S)}); - K = std::vector(S, std::numeric_limits::min()); - current_statement__ = 45; - K = context__.vals_i("K"); - current_statement__ = 45; - stan::math::check_greater_or_equal(function__, "K", K, 0); - current_statement__ = 46; - context__.validate_dims("data initialization", "p10priors", "double", - std::vector{static_cast(2)}); - p10priors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 46; - p10priors = context__.vals_r("p10priors"); - current_statement__ = 47; - context__.validate_dims("data initialization", "phipriors", "double", - std::vector{static_cast(2)}); - phipriors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 47; - phipriors = context__.vals_r("phipriors"); - current_statement__ = 48; - context__.validate_dims("data initialization", "nsitecov", "int", - std::vector{}); - nsitecov = std::numeric_limits::min(); - current_statement__ = 48; - nsitecov = context__.vals_i("nsitecov")[(1 - 1)]; - current_statement__ = 48; - stan::math::check_greater_or_equal(function__, "nsitecov", nsitecov, 0); - current_statement__ = 49; - stan::math::validate_non_negative_index("mat_site", "Nloc", Nloc); - current_statement__ = 50; - stan::math::validate_non_negative_index("mat_site", "nsitecov", - nsitecov); - current_statement__ = 51; - context__.validate_dims("data initialization", "mat_site", "double", - std::vector{static_cast(Nloc), - static_cast(nsitecov)}); - mat_site_data__ = Eigen::Matrix::Constant(Nloc, nsitecov, - std::numeric_limits::quiet_NaN()); - new (&mat_site) - Eigen::Map>(mat_site_data__.data(), Nloc, - nsitecov); - { - std::vector mat_site_flat__; - current_statement__ = 51; - mat_site_flat__ = context__.vals_r("mat_site"); - current_statement__ = 51; - pos__ = 1; - current_statement__ = 51; - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - current_statement__ = 51; - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - current_statement__ = 51; - stan::model::assign(mat_site, mat_site_flat__[(pos__ - 1)], - "assigning variable mat_site", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 51; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 52; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 53; - stan::math::validate_non_negative_index("alpha", "nsitecov", nsitecov); - current_statement__ = 54; - stan::math::validate_non_negative_index("p11", "Nloc", Nloc); - current_statement__ = 55; - stan::math::validate_non_negative_index("p", "Nloc", Nloc); - current_statement__ = 56; - log_lik_1dim__ = std::numeric_limits::min(); - current_statement__ = 56; - log_lik_1dim__ = (C + S); - current_statement__ = 56; - stan::math::validate_non_negative_index("log_lik", "C + S", - log_lik_1dim__); - current_statement__ = 57; - stan::math::validate_non_negative_index("beta", "Nloc", Nloc); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + 1 + 1 + nsitecov; - } - inline std::string model_name() const final { - return "model_joint_binary_cov_negbin"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_joint_binary_cov_negbin_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = in__.template read_constrain_lb(0, - lp__); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - current_statement__ = 4; - alpha = in__.template read< - Eigen::Matrix>(nsitecov); - std::vector p11 = - std::vector(Nloc, DUMMY_VAR__); - std::vector p = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 13; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 10; - stan::model::assign(p11, - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + - stan::math::exp( - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha)))), - "assigning variable p11", stan::model::index_uni(i)); - current_statement__ = 11; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 5; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p", p, 1); - { - current_statement__ = 26; - for (int j = 1; j <= C; ++j) { - current_statement__ = 24; - lp_accum__.add(stan::math::neg_binomial_2_lpmf( - stan::model::rvalue(E, "E", - stan::model::index_uni(j)), - stan::model::rvalue(mu, "mu", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))), phi)); - } - current_statement__ = 29; - for (int i = 1; i <= S; ++i) { - current_statement__ = 27; - lp_accum__.add(stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", - stan::model::index_uni(i)), - stan::model::rvalue(N, "N", - stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", - stan::model::index_uni(i)))))); - } - current_statement__ = 30; - lp_accum__.add(stan::math::normal_lpdf(log_p10, - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(1)), - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(2)))); - current_statement__ = 31; - lp_accum__.add(stan::math::normal_lpdf(alpha, 0, 10)); - current_statement__ = 32; - lp_accum__.add(stan::math::gamma_lpdf(phi, - stan::model::rvalue(phipriors, "phipriors", - stan::model::index_uni(1)), - stan::model::rvalue(phipriors, "phipriors", - stan::model::index_uni(2)))); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_joint_binary_cov_negbin_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector mu = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - mu = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - double phi = std::numeric_limits::quiet_NaN(); - current_statement__ = 2; - phi = in__.template read_constrain_lb(0, - lp__); - double log_p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 3; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, - std::numeric_limits::quiet_NaN()); - current_statement__ = 4; - alpha = in__.template read< - Eigen::Matrix>(nsitecov); - std::vector p11 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector p = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - out__.write(mu); - out__.write(phi); - out__.write(log_p10); - out__.write(alpha); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 13; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 10; - stan::model::assign(p11, - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + - stan::math::exp( - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha)))), - "assigning variable p11", stan::model::index_uni(i)); - current_statement__ = 11; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 5; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p", p, 1); - if (emit_transformed_parameters__) { - out__.write(p11); - out__.write(p); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(log_lik_1dim__, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix beta = - Eigen::Matrix::Constant(Nloc, - std::numeric_limits::quiet_NaN()); - double p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 14; - p10 = stan::math::exp(log_p10); - current_statement__ = 17; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 15; - stan::model::assign(beta, - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha), "assigning variable beta", - stan::model::index_uni(i)); - } - current_statement__ = 20; - for (int j = 1; j <= C; ++j) { - current_statement__ = 18; - stan::model::assign(log_lik, - stan::math::neg_binomial_2_lpmf( - stan::model::rvalue(E, "E", stan::model::index_uni(j)), - stan::model::rvalue(mu, "mu", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j)))), phi), - "assigning variable log_lik", stan::model::index_uni(j)); - } - current_statement__ = 23; - for (int i = 1; i <= S; ++i) { - current_statement__ = 21; - stan::model::assign(log_lik, - stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", stan::model::index_uni(i)), - stan::model::rvalue(N, "N", stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", stan::model::index_uni(i))))), - "assigning variable log_lik", stan::model::index_uni((C + i))); - } - out__.write(log_lik); - out__.write(beta); - out__.write(p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(mu, in__.read>(Nloc), - "assigning variable mu"); - out__.write_free_lb(0, mu); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = in__.read(); - out__.write_free_lb(0, phi); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = in__.read(); - out__.write_free_ub(0, log_p10); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - current_statement__ = 4; - stan::model::assign(alpha, - in__.read>(nsitecov), - "assigning variable alpha"); - out__.write(alpha); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "mu", "double", - std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "phi", "double", - std::vector{}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "log_p10", - "double", std::vector{}); - current_statement__ = 4; - context__.validate_dims("parameter initialization", "alpha", "double", - std::vector{static_cast(nsitecov)}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu = context__.vals_r("mu"); - out__.write_free_lb(0, mu); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = context__.vals_r("phi")[(1 - 1)]; - out__.write_free_lb(0, phi); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = context__.vals_r("log_p10")[(1 - 1)]; - out__.write_free_ub(0, log_p10); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - { - std::vector alpha_flat__; - current_statement__ = 4; - alpha_flat__ = context__.vals_r("alpha"); - current_statement__ = 4; - pos__ = 1; - current_statement__ = 4; - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - current_statement__ = 4; - stan::model::assign(alpha, alpha_flat__[(pos__ - 1)], - "assigning variable alpha", stan::model::index_uni(sym1__)); - current_statement__ = 4; - pos__ = (pos__ + 1); - } - } - out__.write(alpha); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"mu", "phi", "log_p10", "alpha"}; - if (emit_transformed_parameters__) { - std::vector temp{"p11", "p"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"log_lik", "beta", "p10"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{}, std::vector{}, - std::vector{static_cast(nsitecov)}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(log_lik_1dim__)}, - std::vector{static_cast(Nloc)}, - std::vector{}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "phi"); - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "phi"); - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (((Nloc + 1) + 1) + nsitecov); - const size_t num_transformed = emit_transformed_parameters * ((Nloc + - Nloc)); - const size_t num_gen_quantities = emit_generated_quantities * - (((log_lik_1dim__ + Nloc) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (((Nloc + 1) + 1) + nsitecov); - const size_t num_transformed = emit_transformed_parameters * ((Nloc + - Nloc)); - const size_t num_gen_quantities = emit_generated_quantities * - (((log_lik_1dim__ + Nloc) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_joint_binary_cov_negbin_namespace::model_joint_binary_cov_negbin; -#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_joint_binary_cov_negbin_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_joint_binary_cov_negbin_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 16, column 4 to column 33)", + " (in 'string', line 17, column 4 to column 22)", + " (in 'string', line 18, column 4 to column 26)", + " (in 'string', line 19, column 4 to column 27)", + " (in 'string', line 22, column 2 to column 43)", + " (in 'string', line 23, column 2 to column 41)", + " (in 'string', line 42, column 2 to column 22)", + " (in 'string', line 43, column 2 to column 20)", + " (in 'string', line 44, column 2 to column 11)", + " (in 'string', line 25, column 4 to column 67)", + " (in 'string', line 26, column 4 to column 33)", + " (in 'string', line 24, column 19 to line 27, column 3)", + " (in 'string', line 24, column 2 to line 27, column 3)", + " (in 'string', line 45, column 2 to column 21)", + " (in 'string', line 47, column 4 to column 45)", + " (in 'string', line 46, column 19 to line 48, column 3)", + " (in 'string', line 46, column 2 to line 48, column 3)", + " (in 'string', line 50, column 10 to column 65)", + " (in 'string', line 49, column 17 to line 51, column 7)", + " (in 'string', line 49, column 4 to line 51, column 7)", + " (in 'string', line 53, column 10 to column 61)", + " (in 'string', line 52, column 19 to line 54, column 7)", + " (in 'string', line 52, column 6 to line 54, column 7)", + " (in 'string', line 31, column 8 to column 45)", + " (in 'string', line 30, column 18 to line 32, column 5)", + " (in 'string', line 30, column 4 to line 32, column 5)", + " (in 'string', line 34, column 8 to column 39)", + " (in 'string', line 33, column 18 to line 35, column 5)", + " (in 'string', line 33, column 4 to line 35, column 5)", + " (in 'string', line 37, column 2 to column 47)", + " (in 'string', line 38, column 2 to column 23)", + " (in 'string', line 39, column 2 to column 42)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 4 to column 19)", + " (in 'string', line 4, column 10 to column 11)", + " (in 'string', line 4, column 4 to column 28)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 22)", + " (in 'string', line 7, column 10 to column 11)", + " (in 'string', line 7, column 4 to column 28)", + " (in 'string', line 8, column 10 to column 11)", + " (in 'string', line 8, column 4 to column 28)", + " (in 'string', line 9, column 10 to column 11)", + " (in 'string', line 9, column 4 to column 28)", + " (in 'string', line 10, column 4 to column 28)", + " (in 'string', line 11, column 4 to column 28)", + " (in 'string', line 12, column 4 to column 26)", + " (in 'string', line 13, column 11 to column 15)", + " (in 'string', line 13, column 16 to column 24)", + " (in 'string', line 13, column 4 to column 35)", + " (in 'string', line 16, column 10 to column 14)", + " (in 'string', line 19, column 11 to column 19)", + " (in 'string', line 22, column 8 to column 12)", + " (in 'string', line 23, column 8 to column 12)", + " (in 'string', line 42, column 9 to column 12)", + " (in 'string', line 43, column 9 to column 13)"}; +#include +class model_joint_binary_cov_negbin final : public model_base_crtp { +private: + int S; + int C; + std::vector L; + std::vector R; + int Nloc; + std::vector E; + std::vector N; + std::vector K; + std::vector p10priors; + std::vector phipriors; + int nsitecov; + Eigen::Matrix mat_site_data__; + int log_lik_1dim__; + Eigen::Map> mat_site{nullptr, 0, 0}; +public: + ~model_joint_binary_cov_negbin() {} + model_joint_binary_cov_negbin(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_joint_binary_cov_negbin_namespace::model_joint_binary_cov_negbin"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 33; + context__.validate_dims("data initialization", "S", "int", + std::vector{}); + S = std::numeric_limits::min(); + current_statement__ = 33; + S = context__.vals_i("S")[(1 - 1)]; + current_statement__ = 33; + stan::math::check_greater_or_equal(function__, "S", S, 1); + current_statement__ = 34; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 34; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 34; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 35; + stan::math::validate_non_negative_index("L", "S", S); + current_statement__ = 36; + context__.validate_dims("data initialization", "L", "int", + std::vector{static_cast(S)}); + L = std::vector(S, std::numeric_limits::min()); + current_statement__ = 36; + L = context__.vals_i("L"); + current_statement__ = 36; + stan::math::check_greater_or_equal(function__, "L", L, 1); + current_statement__ = 37; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 38; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 38; + R = context__.vals_i("R"); + current_statement__ = 38; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 39; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 39; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 39; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 40; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 41; + context__.validate_dims("data initialization", "E", "int", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::min()); + current_statement__ = 41; + E = context__.vals_i("E"); + current_statement__ = 41; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 42; + stan::math::validate_non_negative_index("N", "S", S); + current_statement__ = 43; + context__.validate_dims("data initialization", "N", "int", + std::vector{static_cast(S)}); + N = std::vector(S, std::numeric_limits::min()); + current_statement__ = 43; + N = context__.vals_i("N"); + current_statement__ = 43; + stan::math::check_greater_or_equal(function__, "N", N, 1); + current_statement__ = 44; + stan::math::validate_non_negative_index("K", "S", S); + current_statement__ = 45; + context__.validate_dims("data initialization", "K", "int", + std::vector{static_cast(S)}); + K = std::vector(S, std::numeric_limits::min()); + current_statement__ = 45; + K = context__.vals_i("K"); + current_statement__ = 45; + stan::math::check_greater_or_equal(function__, "K", K, 0); + current_statement__ = 46; + context__.validate_dims("data initialization", "p10priors", "double", + std::vector{static_cast(2)}); + p10priors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 46; + p10priors = context__.vals_r("p10priors"); + current_statement__ = 47; + context__.validate_dims("data initialization", "phipriors", "double", + std::vector{static_cast(2)}); + phipriors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 47; + phipriors = context__.vals_r("phipriors"); + current_statement__ = 48; + context__.validate_dims("data initialization", "nsitecov", "int", + std::vector{}); + nsitecov = std::numeric_limits::min(); + current_statement__ = 48; + nsitecov = context__.vals_i("nsitecov")[(1 - 1)]; + current_statement__ = 48; + stan::math::check_greater_or_equal(function__, "nsitecov", nsitecov, 0); + current_statement__ = 49; + stan::math::validate_non_negative_index("mat_site", "Nloc", Nloc); + current_statement__ = 50; + stan::math::validate_non_negative_index("mat_site", "nsitecov", + nsitecov); + current_statement__ = 51; + context__.validate_dims("data initialization", "mat_site", "double", + std::vector{static_cast(Nloc), + static_cast(nsitecov)}); + mat_site_data__ = Eigen::Matrix::Constant(Nloc, nsitecov, + std::numeric_limits::quiet_NaN()); + new (&mat_site) + Eigen::Map>(mat_site_data__.data(), Nloc, + nsitecov); + { + std::vector mat_site_flat__; + current_statement__ = 51; + mat_site_flat__ = context__.vals_r("mat_site"); + current_statement__ = 51; + pos__ = 1; + current_statement__ = 51; + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + current_statement__ = 51; + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + current_statement__ = 51; + stan::model::assign(mat_site, mat_site_flat__[(pos__ - 1)], + "assigning variable mat_site", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 51; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 52; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 53; + stan::math::validate_non_negative_index("alpha", "nsitecov", nsitecov); + current_statement__ = 54; + stan::math::validate_non_negative_index("p11", "Nloc", Nloc); + current_statement__ = 55; + stan::math::validate_non_negative_index("p", "Nloc", Nloc); + current_statement__ = 56; + log_lik_1dim__ = std::numeric_limits::min(); + current_statement__ = 56; + log_lik_1dim__ = (C + S); + current_statement__ = 56; + stan::math::validate_non_negative_index("log_lik", "C + S", + log_lik_1dim__); + current_statement__ = 57; + stan::math::validate_non_negative_index("beta", "Nloc", Nloc); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + 1 + 1 + nsitecov; + } + inline std::string model_name() const final { + return "model_joint_binary_cov_negbin"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_joint_binary_cov_negbin_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = in__.template read_constrain_lb(0, + lp__); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + current_statement__ = 4; + alpha = in__.template read< + Eigen::Matrix>(nsitecov); + std::vector p11 = + std::vector(Nloc, DUMMY_VAR__); + std::vector p = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 13; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 10; + stan::model::assign(p11, + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + + stan::math::exp( + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha)))), + "assigning variable p11", stan::model::index_uni(i)); + current_statement__ = 11; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 5; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p", p, 1); + { + current_statement__ = 26; + for (int j = 1; j <= C; ++j) { + current_statement__ = 24; + lp_accum__.add(stan::math::neg_binomial_2_lpmf( + stan::model::rvalue(E, "E", + stan::model::index_uni(j)), + stan::model::rvalue(mu, "mu", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))), phi)); + } + current_statement__ = 29; + for (int i = 1; i <= S; ++i) { + current_statement__ = 27; + lp_accum__.add(stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", + stan::model::index_uni(i)), + stan::model::rvalue(N, "N", + stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", + stan::model::index_uni(i)))))); + } + current_statement__ = 30; + lp_accum__.add(stan::math::normal_lpdf(log_p10, + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(1)), + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(2)))); + current_statement__ = 31; + lp_accum__.add(stan::math::normal_lpdf(alpha, 0, 10)); + current_statement__ = 32; + lp_accum__.add(stan::math::gamma_lpdf(phi, + stan::model::rvalue(phipriors, "phipriors", + stan::model::index_uni(1)), + stan::model::rvalue(phipriors, "phipriors", + stan::model::index_uni(2)))); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_joint_binary_cov_negbin_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector mu = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + mu = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + double phi = std::numeric_limits::quiet_NaN(); + current_statement__ = 2; + phi = in__.template read_constrain_lb(0, + lp__); + double log_p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, + std::numeric_limits::quiet_NaN()); + current_statement__ = 4; + alpha = in__.template read< + Eigen::Matrix>(nsitecov); + std::vector p11 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector p = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + out__.write(mu); + out__.write(phi); + out__.write(log_p10); + out__.write(alpha); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 13; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 10; + stan::model::assign(p11, + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + + stan::math::exp( + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha)))), + "assigning variable p11", stan::model::index_uni(i)); + current_statement__ = 11; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 5; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p", p, 1); + if (emit_transformed_parameters__) { + out__.write(p11); + out__.write(p); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(log_lik_1dim__, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix beta = + Eigen::Matrix::Constant(Nloc, + std::numeric_limits::quiet_NaN()); + double p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 14; + p10 = stan::math::exp(log_p10); + current_statement__ = 17; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 15; + stan::model::assign(beta, + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha), "assigning variable beta", + stan::model::index_uni(i)); + } + current_statement__ = 20; + for (int j = 1; j <= C; ++j) { + current_statement__ = 18; + stan::model::assign(log_lik, + stan::math::neg_binomial_2_lpmf( + stan::model::rvalue(E, "E", stan::model::index_uni(j)), + stan::model::rvalue(mu, "mu", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j)))), phi), + "assigning variable log_lik", stan::model::index_uni(j)); + } + current_statement__ = 23; + for (int i = 1; i <= S; ++i) { + current_statement__ = 21; + stan::model::assign(log_lik, + stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", stan::model::index_uni(i)), + stan::model::rvalue(N, "N", stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", stan::model::index_uni(i))))), + "assigning variable log_lik", stan::model::index_uni((C + i))); + } + out__.write(log_lik); + out__.write(beta); + out__.write(p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(mu, in__.read>(Nloc), + "assigning variable mu"); + out__.write_free_lb(0, mu); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = in__.read(); + out__.write_free_lb(0, phi); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = in__.read(); + out__.write_free_ub(0, log_p10); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + current_statement__ = 4; + stan::model::assign(alpha, + in__.read>(nsitecov), + "assigning variable alpha"); + out__.write(alpha); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "mu", "double", + std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "phi", "double", + std::vector{}); + current_statement__ = 3; + context__.validate_dims("parameter initialization", "log_p10", + "double", std::vector{}); + current_statement__ = 4; + context__.validate_dims("parameter initialization", "alpha", "double", + std::vector{static_cast(nsitecov)}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu = context__.vals_r("mu"); + out__.write_free_lb(0, mu); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = context__.vals_r("phi")[(1 - 1)]; + out__.write_free_lb(0, phi); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = context__.vals_r("log_p10")[(1 - 1)]; + out__.write_free_ub(0, log_p10); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + { + std::vector alpha_flat__; + current_statement__ = 4; + alpha_flat__ = context__.vals_r("alpha"); + current_statement__ = 4; + pos__ = 1; + current_statement__ = 4; + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + current_statement__ = 4; + stan::model::assign(alpha, alpha_flat__[(pos__ - 1)], + "assigning variable alpha", stan::model::index_uni(sym1__)); + current_statement__ = 4; + pos__ = (pos__ + 1); + } + } + out__.write(alpha); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"mu", "phi", "log_p10", "alpha"}; + if (emit_transformed_parameters__) { + std::vector temp{"p11", "p"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"log_lik", "beta", "p10"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{}, std::vector{}, + std::vector{static_cast(nsitecov)}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(log_lik_1dim__)}, + std::vector{static_cast(Nloc)}, + std::vector{}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "phi"); + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "phi"); + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (((Nloc + 1) + 1) + nsitecov); + const size_t num_transformed = emit_transformed_parameters * ((Nloc + + Nloc)); + const size_t num_gen_quantities = emit_generated_quantities * + (((log_lik_1dim__ + Nloc) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (((Nloc + 1) + 1) + nsitecov); + const size_t num_transformed = emit_transformed_parameters * ((Nloc + + Nloc)); + const size_t num_gen_quantities = emit_generated_quantities * + (((log_lik_1dim__ + Nloc) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_joint_binary_cov_negbin_namespace::model_joint_binary_cov_negbin; +#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_joint_binary_cov_negbin_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_joint_binary_cov_pois.h b/src/stanExports_joint_binary_cov_pois.h index 51a1838..f4ad8e4 100644 --- a/src/stanExports_joint_binary_cov_pois.h +++ b/src/stanExports_joint_binary_cov_pois.h @@ -1,822 +1,822 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_joint_binary_cov_pois_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'joint_binary_cov_pois', line 15, column 4 to column 33)", - " (in 'joint_binary_cov_pois', line 16, column 4 to column 26)", - " (in 'joint_binary_cov_pois', line 17, column 4 to column 27)", - " (in 'joint_binary_cov_pois', line 20, column 2 to column 43)", - " (in 'joint_binary_cov_pois', line 21, column 2 to column 40)", - " (in 'joint_binary_cov_pois', line 39, column 2 to column 22)", - " (in 'joint_binary_cov_pois', line 40, column 2 to column 20)", - " (in 'joint_binary_cov_pois', line 41, column 2 to column 11)", - " (in 'joint_binary_cov_pois', line 23, column 4 to column 67)", - " (in 'joint_binary_cov_pois', line 24, column 4 to column 33)", - " (in 'joint_binary_cov_pois', line 22, column 19 to line 25, column 3)", - " (in 'joint_binary_cov_pois', line 22, column 2 to line 25, column 3)", - " (in 'joint_binary_cov_pois', line 42, column 2 to column 21)", - " (in 'joint_binary_cov_pois', line 44, column 4 to column 45)", - " (in 'joint_binary_cov_pois', line 43, column 19 to line 45, column 3)", - " (in 'joint_binary_cov_pois', line 43, column 2 to line 45, column 3)", - " (in 'joint_binary_cov_pois', line 47, column 10 to column 53)", - " (in 'joint_binary_cov_pois', line 46, column 17 to line 48, column 7)", - " (in 'joint_binary_cov_pois', line 46, column 4 to line 48, column 7)", - " (in 'joint_binary_cov_pois', line 50, column 10 to column 61)", - " (in 'joint_binary_cov_pois', line 49, column 19 to line 51, column 7)", - " (in 'joint_binary_cov_pois', line 49, column 6 to line 51, column 7)", - " (in 'joint_binary_cov_pois', line 29, column 8 to column 33)", - " (in 'joint_binary_cov_pois', line 28, column 18 to line 30, column 5)", - " (in 'joint_binary_cov_pois', line 28, column 4 to line 30, column 5)", - " (in 'joint_binary_cov_pois', line 32, column 8 to column 39)", - " (in 'joint_binary_cov_pois', line 31, column 18 to line 33, column 5)", - " (in 'joint_binary_cov_pois', line 31, column 4 to line 33, column 5)", - " (in 'joint_binary_cov_pois', line 35, column 2 to column 47)", - " (in 'joint_binary_cov_pois', line 36, column 2 to column 23)", - " (in 'joint_binary_cov_pois', line 2, column 4 to column 19)", - " (in 'joint_binary_cov_pois', line 3, column 4 to column 19)", - " (in 'joint_binary_cov_pois', line 4, column 10 to column 11)", - " (in 'joint_binary_cov_pois', line 4, column 4 to column 28)", - " (in 'joint_binary_cov_pois', line 5, column 10 to column 11)", - " (in 'joint_binary_cov_pois', line 5, column 4 to column 28)", - " (in 'joint_binary_cov_pois', line 6, column 4 to column 22)", - " (in 'joint_binary_cov_pois', line 7, column 10 to column 11)", - " (in 'joint_binary_cov_pois', line 7, column 4 to column 28)", - " (in 'joint_binary_cov_pois', line 8, column 10 to column 11)", - " (in 'joint_binary_cov_pois', line 8, column 4 to column 28)", - " (in 'joint_binary_cov_pois', line 9, column 10 to column 11)", - " (in 'joint_binary_cov_pois', line 9, column 4 to column 28)", - " (in 'joint_binary_cov_pois', line 10, column 4 to column 28)", - " (in 'joint_binary_cov_pois', line 11, column 4 to column 26)", - " (in 'joint_binary_cov_pois', line 12, column 11 to column 15)", - " (in 'joint_binary_cov_pois', line 12, column 16 to column 24)", - " (in 'joint_binary_cov_pois', line 12, column 4 to column 35)", - " (in 'joint_binary_cov_pois', line 15, column 10 to column 14)", - " (in 'joint_binary_cov_pois', line 17, column 11 to column 19)", - " (in 'joint_binary_cov_pois', line 20, column 8 to column 12)", - " (in 'joint_binary_cov_pois', line 21, column 8 to column 12)", - " (in 'joint_binary_cov_pois', line 39, column 9 to column 12)", - " (in 'joint_binary_cov_pois', line 40, column 9 to column 13)"}; -#include -class model_joint_binary_cov_pois final : public model_base_crtp { -private: - int S; - int C; - std::vector L; - std::vector R; - int Nloc; - std::vector E; - std::vector N; - std::vector K; - std::vector p10priors; - int nsitecov; - Eigen::Matrix mat_site_data__; - int log_lik_1dim__; - Eigen::Map> mat_site{nullptr, 0, 0}; -public: - ~model_joint_binary_cov_pois() {} - model_joint_binary_cov_pois(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_joint_binary_cov_pois_namespace::model_joint_binary_cov_pois"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 31; - context__.validate_dims("data initialization", "S", "int", - std::vector{}); - S = std::numeric_limits::min(); - current_statement__ = 31; - S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 31; - stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 32; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 32; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 32; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 33; - stan::math::validate_non_negative_index("L", "S", S); - current_statement__ = 34; - context__.validate_dims("data initialization", "L", "int", - std::vector{static_cast(S)}); - L = std::vector(S, std::numeric_limits::min()); - current_statement__ = 34; - L = context__.vals_i("L"); - current_statement__ = 34; - stan::math::check_greater_or_equal(function__, "L", L, 1); - current_statement__ = 35; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 36; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 36; - R = context__.vals_i("R"); - current_statement__ = 36; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 37; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 37; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 37; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 38; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 39; - context__.validate_dims("data initialization", "E", "int", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::min()); - current_statement__ = 39; - E = context__.vals_i("E"); - current_statement__ = 39; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 40; - stan::math::validate_non_negative_index("N", "S", S); - current_statement__ = 41; - context__.validate_dims("data initialization", "N", "int", - std::vector{static_cast(S)}); - N = std::vector(S, std::numeric_limits::min()); - current_statement__ = 41; - N = context__.vals_i("N"); - current_statement__ = 41; - stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 42; - stan::math::validate_non_negative_index("K", "S", S); - current_statement__ = 43; - context__.validate_dims("data initialization", "K", "int", - std::vector{static_cast(S)}); - K = std::vector(S, std::numeric_limits::min()); - current_statement__ = 43; - K = context__.vals_i("K"); - current_statement__ = 43; - stan::math::check_greater_or_equal(function__, "K", K, 0); - current_statement__ = 44; - context__.validate_dims("data initialization", "p10priors", "double", - std::vector{static_cast(2)}); - p10priors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 44; - p10priors = context__.vals_r("p10priors"); - current_statement__ = 45; - context__.validate_dims("data initialization", "nsitecov", "int", - std::vector{}); - nsitecov = std::numeric_limits::min(); - current_statement__ = 45; - nsitecov = context__.vals_i("nsitecov")[(1 - 1)]; - current_statement__ = 45; - stan::math::check_greater_or_equal(function__, "nsitecov", nsitecov, 0); - current_statement__ = 46; - stan::math::validate_non_negative_index("mat_site", "Nloc", Nloc); - current_statement__ = 47; - stan::math::validate_non_negative_index("mat_site", "nsitecov", - nsitecov); - current_statement__ = 48; - context__.validate_dims("data initialization", "mat_site", "double", - std::vector{static_cast(Nloc), - static_cast(nsitecov)}); - mat_site_data__ = Eigen::Matrix::Constant(Nloc, nsitecov, - std::numeric_limits::quiet_NaN()); - new (&mat_site) - Eigen::Map>(mat_site_data__.data(), Nloc, - nsitecov); - { - std::vector mat_site_flat__; - current_statement__ = 48; - mat_site_flat__ = context__.vals_r("mat_site"); - current_statement__ = 48; - pos__ = 1; - current_statement__ = 48; - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - current_statement__ = 48; - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - current_statement__ = 48; - stan::model::assign(mat_site, mat_site_flat__[(pos__ - 1)], - "assigning variable mat_site", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 48; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 49; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 50; - stan::math::validate_non_negative_index("alpha", "nsitecov", nsitecov); - current_statement__ = 51; - stan::math::validate_non_negative_index("p11", "Nloc", Nloc); - current_statement__ = 52; - stan::math::validate_non_negative_index("p", "Nloc", Nloc); - current_statement__ = 53; - log_lik_1dim__ = std::numeric_limits::min(); - current_statement__ = 53; - log_lik_1dim__ = (C + S); - current_statement__ = 53; - stan::math::validate_non_negative_index("log_lik", "C + S", - log_lik_1dim__); - current_statement__ = 54; - stan::math::validate_non_negative_index("beta", "Nloc", Nloc); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + 1 + nsitecov; - } - inline std::string model_name() const final { - return "model_joint_binary_cov_pois"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_joint_binary_cov_pois_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 2; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - current_statement__ = 3; - alpha = in__.template read< - Eigen::Matrix>(nsitecov); - std::vector p11 = - std::vector(Nloc, DUMMY_VAR__); - std::vector p = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 12; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 9; - stan::model::assign(p11, - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + - stan::math::exp( - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha)))), - "assigning variable p11", stan::model::index_uni(i)); - current_statement__ = 10; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 4; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 4; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 5; - stan::math::check_less_or_equal(function__, "p", p, 1); - { - current_statement__ = 25; - for (int j = 1; j <= C; ++j) { - current_statement__ = 23; - lp_accum__.add(stan::math::poisson_lpmf( - stan::model::rvalue(E, "E", - stan::model::index_uni(j)), - stan::model::rvalue(mu, "mu", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))))); - } - current_statement__ = 28; - for (int i = 1; i <= S; ++i) { - current_statement__ = 26; - lp_accum__.add(stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", - stan::model::index_uni(i)), - stan::model::rvalue(N, "N", - stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", - stan::model::index_uni(i)))))); - } - current_statement__ = 29; - lp_accum__.add(stan::math::normal_lpdf(log_p10, - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(1)), - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(2)))); - current_statement__ = 30; - lp_accum__.add(stan::math::normal_lpdf(alpha, 0, 10)); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_joint_binary_cov_pois_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector mu = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - mu = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - double log_p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 2; - log_p10 = in__.template read_constrain_ub(0, lp__); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, - std::numeric_limits::quiet_NaN()); - current_statement__ = 3; - alpha = in__.template read< - Eigen::Matrix>(nsitecov); - std::vector p11 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector p = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - out__.write(mu); - out__.write(log_p10); - out__.write(alpha); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 12; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 9; - stan::model::assign(p11, - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + - stan::math::exp( - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha)))), - "assigning variable p11", stan::model::index_uni(i)); - current_statement__ = 10; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 4; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 4; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 5; - stan::math::check_less_or_equal(function__, "p", p, 1); - if (emit_transformed_parameters__) { - out__.write(p11); - out__.write(p); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(log_lik_1dim__, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix beta = - Eigen::Matrix::Constant(Nloc, - std::numeric_limits::quiet_NaN()); - double p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 13; - p10 = stan::math::exp(log_p10); - current_statement__ = 16; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 14; - stan::model::assign(beta, - stan::math::dot_product( - stan::model::rvalue(mat_site, "mat_site", - stan::model::index_uni(i)), alpha), "assigning variable beta", - stan::model::index_uni(i)); - } - current_statement__ = 19; - for (int j = 1; j <= C; ++j) { - current_statement__ = 17; - stan::model::assign(log_lik, - stan::math::poisson_lpmf( - stan::model::rvalue(E, "E", stan::model::index_uni(j)), - stan::model::rvalue(mu, "mu", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - "assigning variable log_lik", stan::model::index_uni(j)); - } - current_statement__ = 22; - for (int i = 1; i <= S; ++i) { - current_statement__ = 20; - stan::model::assign(log_lik, - stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", stan::model::index_uni(i)), - stan::model::rvalue(N, "N", stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", stan::model::index_uni(i))))), - "assigning variable log_lik", stan::model::index_uni((C + i))); - } - out__.write(log_lik); - out__.write(beta); - out__.write(p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(mu, in__.read>(Nloc), - "assigning variable mu"); - out__.write_free_lb(0, mu); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 2; - log_p10 = in__.read(); - out__.write_free_ub(0, log_p10); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - current_statement__ = 3; - stan::model::assign(alpha, - in__.read>(nsitecov), - "assigning variable alpha"); - out__.write(alpha); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "mu", "double", - std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "log_p10", - "double", std::vector{}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "alpha", "double", - std::vector{static_cast(nsitecov)}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu = context__.vals_r("mu"); - out__.write_free_lb(0, mu); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 2; - log_p10 = context__.vals_r("log_p10")[(1 - 1)]; - out__.write_free_ub(0, log_p10); - Eigen::Matrix alpha = - Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); - { - std::vector alpha_flat__; - current_statement__ = 3; - alpha_flat__ = context__.vals_r("alpha"); - current_statement__ = 3; - pos__ = 1; - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - current_statement__ = 3; - stan::model::assign(alpha, alpha_flat__[(pos__ - 1)], - "assigning variable alpha", stan::model::index_uni(sym1__)); - current_statement__ = 3; - pos__ = (pos__ + 1); - } - } - out__.write(alpha); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"mu", "log_p10", "alpha"}; - if (emit_transformed_parameters__) { - std::vector temp{"p11", "p"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"log_lik", "beta", "p10"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{}, - std::vector{static_cast(nsitecov)}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(log_lik_1dim__)}, - std::vector{static_cast(Nloc)}, - std::vector{}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "log_p10"); - for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((Nloc + 1) + nsitecov); - const size_t num_transformed = emit_transformed_parameters * ((Nloc + - Nloc)); - const size_t num_gen_quantities = emit_generated_quantities * - (((log_lik_1dim__ + Nloc) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((Nloc + 1) + nsitecov); - const size_t num_transformed = emit_transformed_parameters * ((Nloc + - Nloc)); - const size_t num_gen_quantities = emit_generated_quantities * - (((log_lik_1dim__ + Nloc) + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_joint_binary_cov_pois_namespace::model_joint_binary_cov_pois; -#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_joint_binary_cov_pois_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_joint_binary_cov_pois_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 15, column 4 to column 33)", + " (in 'string', line 16, column 4 to column 26)", + " (in 'string', line 17, column 4 to column 27)", + " (in 'string', line 20, column 2 to column 43)", + " (in 'string', line 21, column 2 to column 40)", + " (in 'string', line 39, column 2 to column 22)", + " (in 'string', line 40, column 2 to column 20)", + " (in 'string', line 41, column 2 to column 11)", + " (in 'string', line 23, column 4 to column 67)", + " (in 'string', line 24, column 4 to column 33)", + " (in 'string', line 22, column 19 to line 25, column 3)", + " (in 'string', line 22, column 2 to line 25, column 3)", + " (in 'string', line 42, column 2 to column 21)", + " (in 'string', line 44, column 4 to column 45)", + " (in 'string', line 43, column 19 to line 45, column 3)", + " (in 'string', line 43, column 2 to line 45, column 3)", + " (in 'string', line 47, column 10 to column 53)", + " (in 'string', line 46, column 17 to line 48, column 7)", + " (in 'string', line 46, column 4 to line 48, column 7)", + " (in 'string', line 50, column 10 to column 61)", + " (in 'string', line 49, column 19 to line 51, column 7)", + " (in 'string', line 49, column 6 to line 51, column 7)", + " (in 'string', line 29, column 8 to column 33)", + " (in 'string', line 28, column 18 to line 30, column 5)", + " (in 'string', line 28, column 4 to line 30, column 5)", + " (in 'string', line 32, column 8 to column 39)", + " (in 'string', line 31, column 18 to line 33, column 5)", + " (in 'string', line 31, column 4 to line 33, column 5)", + " (in 'string', line 35, column 2 to column 47)", + " (in 'string', line 36, column 2 to column 23)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 4 to column 19)", + " (in 'string', line 4, column 10 to column 11)", + " (in 'string', line 4, column 4 to column 28)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 22)", + " (in 'string', line 7, column 10 to column 11)", + " (in 'string', line 7, column 4 to column 28)", + " (in 'string', line 8, column 10 to column 11)", + " (in 'string', line 8, column 4 to column 28)", + " (in 'string', line 9, column 10 to column 11)", + " (in 'string', line 9, column 4 to column 28)", + " (in 'string', line 10, column 4 to column 28)", + " (in 'string', line 11, column 4 to column 26)", + " (in 'string', line 12, column 11 to column 15)", + " (in 'string', line 12, column 16 to column 24)", + " (in 'string', line 12, column 4 to column 35)", + " (in 'string', line 15, column 10 to column 14)", + " (in 'string', line 17, column 11 to column 19)", + " (in 'string', line 20, column 8 to column 12)", + " (in 'string', line 21, column 8 to column 12)", + " (in 'string', line 39, column 9 to column 12)", + " (in 'string', line 40, column 9 to column 13)"}; +#include +class model_joint_binary_cov_pois final : public model_base_crtp { +private: + int S; + int C; + std::vector L; + std::vector R; + int Nloc; + std::vector E; + std::vector N; + std::vector K; + std::vector p10priors; + int nsitecov; + Eigen::Matrix mat_site_data__; + int log_lik_1dim__; + Eigen::Map> mat_site{nullptr, 0, 0}; +public: + ~model_joint_binary_cov_pois() {} + model_joint_binary_cov_pois(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_joint_binary_cov_pois_namespace::model_joint_binary_cov_pois"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 31; + context__.validate_dims("data initialization", "S", "int", + std::vector{}); + S = std::numeric_limits::min(); + current_statement__ = 31; + S = context__.vals_i("S")[(1 - 1)]; + current_statement__ = 31; + stan::math::check_greater_or_equal(function__, "S", S, 1); + current_statement__ = 32; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 32; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 32; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 33; + stan::math::validate_non_negative_index("L", "S", S); + current_statement__ = 34; + context__.validate_dims("data initialization", "L", "int", + std::vector{static_cast(S)}); + L = std::vector(S, std::numeric_limits::min()); + current_statement__ = 34; + L = context__.vals_i("L"); + current_statement__ = 34; + stan::math::check_greater_or_equal(function__, "L", L, 1); + current_statement__ = 35; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 36; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 36; + R = context__.vals_i("R"); + current_statement__ = 36; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 37; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 37; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 37; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 38; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 39; + context__.validate_dims("data initialization", "E", "int", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::min()); + current_statement__ = 39; + E = context__.vals_i("E"); + current_statement__ = 39; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 40; + stan::math::validate_non_negative_index("N", "S", S); + current_statement__ = 41; + context__.validate_dims("data initialization", "N", "int", + std::vector{static_cast(S)}); + N = std::vector(S, std::numeric_limits::min()); + current_statement__ = 41; + N = context__.vals_i("N"); + current_statement__ = 41; + stan::math::check_greater_or_equal(function__, "N", N, 1); + current_statement__ = 42; + stan::math::validate_non_negative_index("K", "S", S); + current_statement__ = 43; + context__.validate_dims("data initialization", "K", "int", + std::vector{static_cast(S)}); + K = std::vector(S, std::numeric_limits::min()); + current_statement__ = 43; + K = context__.vals_i("K"); + current_statement__ = 43; + stan::math::check_greater_or_equal(function__, "K", K, 0); + current_statement__ = 44; + context__.validate_dims("data initialization", "p10priors", "double", + std::vector{static_cast(2)}); + p10priors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 44; + p10priors = context__.vals_r("p10priors"); + current_statement__ = 45; + context__.validate_dims("data initialization", "nsitecov", "int", + std::vector{}); + nsitecov = std::numeric_limits::min(); + current_statement__ = 45; + nsitecov = context__.vals_i("nsitecov")[(1 - 1)]; + current_statement__ = 45; + stan::math::check_greater_or_equal(function__, "nsitecov", nsitecov, 0); + current_statement__ = 46; + stan::math::validate_non_negative_index("mat_site", "Nloc", Nloc); + current_statement__ = 47; + stan::math::validate_non_negative_index("mat_site", "nsitecov", + nsitecov); + current_statement__ = 48; + context__.validate_dims("data initialization", "mat_site", "double", + std::vector{static_cast(Nloc), + static_cast(nsitecov)}); + mat_site_data__ = Eigen::Matrix::Constant(Nloc, nsitecov, + std::numeric_limits::quiet_NaN()); + new (&mat_site) + Eigen::Map>(mat_site_data__.data(), Nloc, + nsitecov); + { + std::vector mat_site_flat__; + current_statement__ = 48; + mat_site_flat__ = context__.vals_r("mat_site"); + current_statement__ = 48; + pos__ = 1; + current_statement__ = 48; + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + current_statement__ = 48; + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + current_statement__ = 48; + stan::model::assign(mat_site, mat_site_flat__[(pos__ - 1)], + "assigning variable mat_site", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 48; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 49; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 50; + stan::math::validate_non_negative_index("alpha", "nsitecov", nsitecov); + current_statement__ = 51; + stan::math::validate_non_negative_index("p11", "Nloc", Nloc); + current_statement__ = 52; + stan::math::validate_non_negative_index("p", "Nloc", Nloc); + current_statement__ = 53; + log_lik_1dim__ = std::numeric_limits::min(); + current_statement__ = 53; + log_lik_1dim__ = (C + S); + current_statement__ = 53; + stan::math::validate_non_negative_index("log_lik", "C + S", + log_lik_1dim__); + current_statement__ = 54; + stan::math::validate_non_negative_index("beta", "Nloc", Nloc); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + 1 + nsitecov; + } + inline std::string model_name() const final { + return "model_joint_binary_cov_pois"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_joint_binary_cov_pois_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 2; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + current_statement__ = 3; + alpha = in__.template read< + Eigen::Matrix>(nsitecov); + std::vector p11 = + std::vector(Nloc, DUMMY_VAR__); + std::vector p = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 12; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 9; + stan::model::assign(p11, + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + + stan::math::exp( + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha)))), + "assigning variable p11", stan::model::index_uni(i)); + current_statement__ = 10; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 4; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 4; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 5; + stan::math::check_less_or_equal(function__, "p", p, 1); + { + current_statement__ = 25; + for (int j = 1; j <= C; ++j) { + current_statement__ = 23; + lp_accum__.add(stan::math::poisson_lpmf( + stan::model::rvalue(E, "E", + stan::model::index_uni(j)), + stan::model::rvalue(mu, "mu", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))))); + } + current_statement__ = 28; + for (int i = 1; i <= S; ++i) { + current_statement__ = 26; + lp_accum__.add(stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", + stan::model::index_uni(i)), + stan::model::rvalue(N, "N", + stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", + stan::model::index_uni(i)))))); + } + current_statement__ = 29; + lp_accum__.add(stan::math::normal_lpdf(log_p10, + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(1)), + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(2)))); + current_statement__ = 30; + lp_accum__.add(stan::math::normal_lpdf(alpha, 0, 10)); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_joint_binary_cov_pois_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector mu = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + mu = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + double log_p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 2; + log_p10 = in__.template read_constrain_ub(0, lp__); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, + std::numeric_limits::quiet_NaN()); + current_statement__ = 3; + alpha = in__.template read< + Eigen::Matrix>(nsitecov); + std::vector p11 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector p = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + out__.write(mu); + out__.write(log_p10); + out__.write(alpha); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 12; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 9; + stan::model::assign(p11, + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + + stan::math::exp( + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha)))), + "assigning variable p11", stan::model::index_uni(i)); + current_statement__ = 10; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 4; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 4; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 5; + stan::math::check_less_or_equal(function__, "p", p, 1); + if (emit_transformed_parameters__) { + out__.write(p11); + out__.write(p); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(log_lik_1dim__, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix beta = + Eigen::Matrix::Constant(Nloc, + std::numeric_limits::quiet_NaN()); + double p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 13; + p10 = stan::math::exp(log_p10); + current_statement__ = 16; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 14; + stan::model::assign(beta, + stan::math::dot_product( + stan::model::rvalue(mat_site, "mat_site", + stan::model::index_uni(i)), alpha), "assigning variable beta", + stan::model::index_uni(i)); + } + current_statement__ = 19; + for (int j = 1; j <= C; ++j) { + current_statement__ = 17; + stan::model::assign(log_lik, + stan::math::poisson_lpmf( + stan::model::rvalue(E, "E", stan::model::index_uni(j)), + stan::model::rvalue(mu, "mu", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + "assigning variable log_lik", stan::model::index_uni(j)); + } + current_statement__ = 22; + for (int i = 1; i <= S; ++i) { + current_statement__ = 20; + stan::model::assign(log_lik, + stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", stan::model::index_uni(i)), + stan::model::rvalue(N, "N", stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", stan::model::index_uni(i))))), + "assigning variable log_lik", stan::model::index_uni((C + i))); + } + out__.write(log_lik); + out__.write(beta); + out__.write(p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(mu, in__.read>(Nloc), + "assigning variable mu"); + out__.write_free_lb(0, mu); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 2; + log_p10 = in__.read(); + out__.write_free_ub(0, log_p10); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + current_statement__ = 3; + stan::model::assign(alpha, + in__.read>(nsitecov), + "assigning variable alpha"); + out__.write(alpha); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "mu", "double", + std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "log_p10", + "double", std::vector{}); + current_statement__ = 3; + context__.validate_dims("parameter initialization", "alpha", "double", + std::vector{static_cast(nsitecov)}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu = context__.vals_r("mu"); + out__.write_free_lb(0, mu); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 2; + log_p10 = context__.vals_r("log_p10")[(1 - 1)]; + out__.write_free_ub(0, log_p10); + Eigen::Matrix alpha = + Eigen::Matrix::Constant(nsitecov, DUMMY_VAR__); + { + std::vector alpha_flat__; + current_statement__ = 3; + alpha_flat__ = context__.vals_r("alpha"); + current_statement__ = 3; + pos__ = 1; + current_statement__ = 3; + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + current_statement__ = 3; + stan::model::assign(alpha, alpha_flat__[(pos__ - 1)], + "assigning variable alpha", stan::model::index_uni(sym1__)); + current_statement__ = 3; + pos__ = (pos__ + 1); + } + } + out__.write(alpha); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"mu", "log_p10", "alpha"}; + if (emit_transformed_parameters__) { + std::vector temp{"p11", "p"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"log_lik", "beta", "p10"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{}, + std::vector{static_cast(nsitecov)}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(log_lik_1dim__)}, + std::vector{static_cast(Nloc)}, + std::vector{}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "log_p10"); + for (int sym1__ = 1; sym1__ <= nsitecov; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"alpha\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nsitecov) + "},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"beta\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((Nloc + 1) + nsitecov); + const size_t num_transformed = emit_transformed_parameters * ((Nloc + + Nloc)); + const size_t num_gen_quantities = emit_generated_quantities * + (((log_lik_1dim__ + Nloc) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((Nloc + 1) + nsitecov); + const size_t num_transformed = emit_transformed_parameters * ((Nloc + + Nloc)); + const size_t num_gen_quantities = emit_generated_quantities * + (((log_lik_1dim__ + Nloc) + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_joint_binary_cov_pois_namespace::model_joint_binary_cov_pois; +#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_joint_binary_cov_pois_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_joint_binary_gamma.h b/src/stanExports_joint_binary_gamma.h index 65f8499..ed93f26 100644 --- a/src/stanExports_joint_binary_gamma.h +++ b/src/stanExports_joint_binary_gamma.h @@ -1,847 +1,847 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_joint_binary_gamma_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'joint_binary_gamma', line 13, column 4 to column 42)", - " (in 'joint_binary_gamma', line 14, column 4 to column 45)", - " (in 'joint_binary_gamma', line 15, column 4 to column 23)", - " (in 'joint_binary_gamma', line 16, column 4 to column 26)", - " (in 'joint_binary_gamma', line 19, column 2 to column 31)", - " (in 'joint_binary_gamma', line 20, column 2 to column 43)", - " (in 'joint_binary_gamma', line 21, column 2 to column 40)", - " (in 'joint_binary_gamma', line 22, column 2 to column 33)", - " (in 'joint_binary_gamma', line 46, column 2 to column 22)", - " (in 'joint_binary_gamma', line 47, column 2 to column 11)", - " (in 'joint_binary_gamma', line 24, column 4 to column 41)", - " (in 'joint_binary_gamma', line 25, column 4 to column 41)", - " (in 'joint_binary_gamma', line 26, column 4 to column 33)", - " (in 'joint_binary_gamma', line 23, column 19 to line 27, column 3)", - " (in 'joint_binary_gamma', line 23, column 2 to line 27, column 3)", - " (in 'joint_binary_gamma', line 29, column 6 to column 42)", - " (in 'joint_binary_gamma', line 28, column 15 to line 30, column 5)", - " (in 'joint_binary_gamma', line 28, column 2 to line 30, column 5)", - " (in 'joint_binary_gamma', line 48, column 2 to column 21)", - " (in 'joint_binary_gamma', line 50, column 10 to column 84)", - " (in 'joint_binary_gamma', line 49, column 17 to line 51, column 7)", - " (in 'joint_binary_gamma', line 49, column 4 to line 51, column 7)", - " (in 'joint_binary_gamma', line 53, column 10 to column 61)", - " (in 'joint_binary_gamma', line 52, column 19 to line 54, column 7)", - " (in 'joint_binary_gamma', line 52, column 6 to line 54, column 7)", - " (in 'joint_binary_gamma', line 34, column 6 to column 61)", - " (in 'joint_binary_gamma', line 33, column 17 to line 35, column 5)", - " (in 'joint_binary_gamma', line 33, column 4 to line 35, column 5)", - " (in 'joint_binary_gamma', line 37, column 8 to column 39)", - " (in 'joint_binary_gamma', line 36, column 18 to line 38, column 5)", - " (in 'joint_binary_gamma', line 36, column 4 to line 38, column 5)", - " (in 'joint_binary_gamma', line 40, column 2 to column 47)", - " (in 'joint_binary_gamma', line 41, column 2 to column 22)", - " (in 'joint_binary_gamma', line 42, column 2 to column 32)", - " (in 'joint_binary_gamma', line 43, column 2 to column 33)", - " (in 'joint_binary_gamma', line 2, column 4 to column 19)", - " (in 'joint_binary_gamma', line 3, column 4 to column 19)", - " (in 'joint_binary_gamma', line 4, column 10 to column 11)", - " (in 'joint_binary_gamma', line 4, column 4 to column 28)", - " (in 'joint_binary_gamma', line 5, column 10 to column 11)", - " (in 'joint_binary_gamma', line 5, column 4 to column 28)", - " (in 'joint_binary_gamma', line 6, column 4 to column 22)", - " (in 'joint_binary_gamma', line 7, column 10 to column 11)", - " (in 'joint_binary_gamma', line 7, column 4 to column 29)", - " (in 'joint_binary_gamma', line 8, column 10 to column 11)", - " (in 'joint_binary_gamma', line 8, column 4 to column 28)", - " (in 'joint_binary_gamma', line 9, column 10 to column 11)", - " (in 'joint_binary_gamma', line 9, column 4 to column 28)", - " (in 'joint_binary_gamma', line 10, column 4 to column 28)", - " (in 'joint_binary_gamma', line 13, column 10 to column 14)", - " (in 'joint_binary_gamma', line 14, column 10 to column 14)", - " (in 'joint_binary_gamma', line 19, column 8 to column 12)", - " (in 'joint_binary_gamma', line 20, column 8 to column 12)", - " (in 'joint_binary_gamma', line 21, column 8 to column 12)", - " (in 'joint_binary_gamma', line 22, column 8 to column 9)", - " (in 'joint_binary_gamma', line 46, column 9 to column 12)"}; -#include -class model_joint_binary_gamma final : public model_base_crtp { -private: - int S; - int C; - std::vector L; - std::vector R; - int Nloc; - std::vector E; - std::vector N; - std::vector K; - std::vector p10priors; - int log_lik_1dim__; -public: - ~model_joint_binary_gamma() {} - model_joint_binary_gamma(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_joint_binary_gamma_namespace::model_joint_binary_gamma"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 36; - context__.validate_dims("data initialization", "S", "int", - std::vector{}); - S = std::numeric_limits::min(); - current_statement__ = 36; - S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 36; - stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 37; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 37; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 37; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 38; - stan::math::validate_non_negative_index("L", "S", S); - current_statement__ = 39; - context__.validate_dims("data initialization", "L", "int", - std::vector{static_cast(S)}); - L = std::vector(S, std::numeric_limits::min()); - current_statement__ = 39; - L = context__.vals_i("L"); - current_statement__ = 39; - stan::math::check_greater_or_equal(function__, "L", L, 1); - current_statement__ = 40; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 41; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 41; - R = context__.vals_i("R"); - current_statement__ = 41; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 42; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 42; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 42; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 43; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 44; - context__.validate_dims("data initialization", "E", "double", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::quiet_NaN()); - current_statement__ = 44; - E = context__.vals_r("E"); - current_statement__ = 44; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 45; - stan::math::validate_non_negative_index("N", "S", S); - current_statement__ = 46; - context__.validate_dims("data initialization", "N", "int", - std::vector{static_cast(S)}); - N = std::vector(S, std::numeric_limits::min()); - current_statement__ = 46; - N = context__.vals_i("N"); - current_statement__ = 46; - stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 47; - stan::math::validate_non_negative_index("K", "S", S); - current_statement__ = 48; - context__.validate_dims("data initialization", "K", "int", - std::vector{static_cast(S)}); - K = std::vector(S, std::numeric_limits::min()); - current_statement__ = 48; - K = context__.vals_i("K"); - current_statement__ = 48; - stan::math::check_greater_or_equal(function__, "K", K, 0); - current_statement__ = 49; - context__.validate_dims("data initialization", "p10priors", "double", - std::vector{static_cast(2)}); - p10priors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 49; - p10priors = context__.vals_r("p10priors"); - current_statement__ = 50; - stan::math::validate_non_negative_index("alpha_gamma", "Nloc", Nloc); - current_statement__ = 51; - stan::math::validate_non_negative_index("beta_gamma", "Nloc", Nloc); - current_statement__ = 52; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 53; - stan::math::validate_non_negative_index("p11", "Nloc", Nloc); - current_statement__ = 54; - stan::math::validate_non_negative_index("p", "Nloc", Nloc); - current_statement__ = 55; - stan::math::validate_non_negative_index("E_trans", "C", C); - current_statement__ = 56; - log_lik_1dim__ = std::numeric_limits::min(); - current_statement__ = 56; - log_lik_1dim__ = (C + S); - current_statement__ = 56; - stan::math::validate_non_negative_index("log_lik", "C + S", - log_lik_1dim__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + Nloc + 1 + 1; - } - inline std::string model_name() const final { - return "model_joint_binary_gamma"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_joint_binary_gamma_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector alpha_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - alpha_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0, lp__, - Nloc); - std::vector beta_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - beta_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0.01, lp__, - Nloc); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 3; - beta = in__.template read_constrain_lb(0, - lp__); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 4; - log_p10 = in__.template read_constrain_ub(0, lp__); - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - std::vector p11 = - std::vector(Nloc, DUMMY_VAR__); - std::vector p = - std::vector(Nloc, DUMMY_VAR__); - std::vector E_trans = - std::vector(C, DUMMY_VAR__); - current_statement__ = 15; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 11; - stan::model::assign(mu, - (stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni(i)) / - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni(i))), "assigning variable mu", - stan::model::index_uni(i)); - current_statement__ = 12; - stan::model::assign(p11, - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + - stan::math::exp(beta))), "assigning variable p11", - stan::model::index_uni(i)); - current_statement__ = 13; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 18; - for (int j = 1; j <= C; ++j) { - current_statement__ = 16; - stan::model::assign(E_trans, - (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + - 0.0000000000001), "assigning variable E_trans", - stan::model::index_uni(j)); - } - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "mu", mu, 0); - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 7; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 8; - stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); - { - current_statement__ = 28; - for (int j = 1; j <= C; ++j) { - current_statement__ = 26; - lp_accum__.add(stan::math::gamma_lpdf( - stan::model::rvalue(E_trans, "E_trans", - stan::model::index_uni(j)), - stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))), - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))))); - } - current_statement__ = 31; - for (int i = 1; i <= S; ++i) { - current_statement__ = 29; - lp_accum__.add(stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", - stan::model::index_uni(i)), - stan::model::rvalue(N, "N", - stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", - stan::model::index_uni(i)))))); - } - current_statement__ = 32; - lp_accum__.add(stan::math::normal_lpdf(log_p10, - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(1)), - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(2)))); - current_statement__ = 33; - lp_accum__.add(stan::math::normal_lpdf(beta, 0, 10)); - current_statement__ = 34; - lp_accum__.add(stan::math::gamma_lpdf(beta_gamma, 0.25, - 0.25)); - current_statement__ = 35; - lp_accum__.add(stan::math::gamma_lpdf(alpha_gamma, 0.01, - 0.01)); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_joint_binary_gamma_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector alpha_gamma = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - alpha_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0, lp__, - Nloc); - std::vector beta_gamma = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 2; - beta_gamma = in__.template read_constrain_lb< - std::vector, jacobian__>(0.01, lp__, - Nloc); - double beta = std::numeric_limits::quiet_NaN(); - current_statement__ = 3; - beta = in__.template read_constrain_lb(0, - lp__); - double log_p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 4; - log_p10 = in__.template read_constrain_ub(0, lp__); - std::vector mu = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector p11 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector p = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector E_trans = - std::vector(C, std::numeric_limits::quiet_NaN()); - out__.write(alpha_gamma); - out__.write(beta_gamma); - out__.write(beta); - out__.write(log_p10); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 15; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 11; - stan::model::assign(mu, - (stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni(i)) / - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni(i))), "assigning variable mu", - stan::model::index_uni(i)); - current_statement__ = 12; - stan::model::assign(p11, - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + - stan::math::exp(beta))), "assigning variable p11", - stan::model::index_uni(i)); - current_statement__ = 13; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 18; - for (int j = 1; j <= C; ++j) { - current_statement__ = 16; - stan::model::assign(E_trans, - (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + - 0.0000000000001), "assigning variable E_trans", - stan::model::index_uni(j)); - } - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "mu", mu, 0); - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 7; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 7; - stan::math::check_less_or_equal(function__, "p", p, 1); - current_statement__ = 8; - stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); - if (emit_transformed_parameters__) { - out__.write(mu); - out__.write(p11); - out__.write(p); - out__.write(E_trans); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(log_lik_1dim__, - std::numeric_limits::quiet_NaN()); - double p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 19; - p10 = stan::math::exp(log_p10); - current_statement__ = 22; - for (int j = 1; j <= C; ++j) { - current_statement__ = 20; - stan::model::assign(log_lik, - stan::math::gamma_lpdf( - stan::model::rvalue(E_trans, "E_trans", stan::model::index_uni(j)), - stan::model::rvalue(alpha_gamma, "alpha_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j)))), - stan::model::rvalue(beta_gamma, "beta_gamma", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - "assigning variable log_lik", stan::model::index_uni(j)); - } - current_statement__ = 25; - for (int i = 1; i <= S; ++i) { - current_statement__ = 23; - stan::model::assign(log_lik, - stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", stan::model::index_uni(i)), - stan::model::rvalue(N, "N", stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", stan::model::index_uni(i))))), - "assigning variable log_lik", stan::model::index_uni((C + i))); - } - out__.write(log_lik); - out__.write(p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector alpha_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(alpha_gamma, - in__.read>(Nloc), - "assigning variable alpha_gamma"); - out__.write_free_lb(0, alpha_gamma); - std::vector beta_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - stan::model::assign(beta_gamma, - in__.read>(Nloc), - "assigning variable beta_gamma"); - out__.write_free_lb(0.01, beta_gamma); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 3; - beta = in__.read(); - out__.write_free_lb(0, beta); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 4; - log_p10 = in__.read(); - out__.write_free_ub(0, log_p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "alpha_gamma", - "double", std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "beta_gamma", - "double", std::vector{static_cast(Nloc)}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "beta", "double", - std::vector{}); - current_statement__ = 4; - context__.validate_dims("parameter initialization", "log_p10", - "double", std::vector{}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector alpha_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - alpha_gamma = context__.vals_r("alpha_gamma"); - out__.write_free_lb(0, alpha_gamma); - std::vector beta_gamma = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - beta_gamma = context__.vals_r("beta_gamma"); - out__.write_free_lb(0.01, beta_gamma); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 3; - beta = context__.vals_r("beta")[(1 - 1)]; - out__.write_free_lb(0, beta); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 4; - log_p10 = context__.vals_r("log_p10")[(1 - 1)]; - out__.write_free_ub(0, log_p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"alpha_gamma", "beta_gamma", "beta", - "log_p10"}; - if (emit_transformed_parameters__) { - std::vector temp{"mu", "p11", "p", "E_trans"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"log_lik", "p10"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{}, std::vector{}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(C)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(log_lik_1dim__)}, - std::vector{}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta_gamma" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "beta"); - param_names__.emplace_back(std::string() + "log_p10"); - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "E_trans" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta_gamma" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "beta"); - param_names__.emplace_back(std::string() + "log_p10"); - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "E_trans" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (((Nloc + Nloc) + 1) + 1); - const size_t num_transformed = emit_transformed_parameters * ((((Nloc + - Nloc) + Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * - ((log_lik_1dim__ + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (((Nloc + Nloc) + 1) + 1); - const size_t num_transformed = emit_transformed_parameters * ((((Nloc + - Nloc) + Nloc) + C)); - const size_t num_gen_quantities = emit_generated_quantities * - ((log_lik_1dim__ + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_joint_binary_gamma_namespace::model_joint_binary_gamma; -#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_joint_binary_gamma_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_joint_binary_gamma_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 13, column 4 to column 42)", + " (in 'string', line 14, column 4 to column 45)", + " (in 'string', line 15, column 4 to column 23)", + " (in 'string', line 16, column 4 to column 26)", + " (in 'string', line 19, column 2 to column 31)", + " (in 'string', line 20, column 2 to column 43)", + " (in 'string', line 21, column 2 to column 40)", + " (in 'string', line 22, column 2 to column 33)", + " (in 'string', line 46, column 2 to column 22)", + " (in 'string', line 47, column 2 to column 11)", + " (in 'string', line 24, column 4 to column 41)", + " (in 'string', line 25, column 4 to column 41)", + " (in 'string', line 26, column 4 to column 33)", + " (in 'string', line 23, column 19 to line 27, column 3)", + " (in 'string', line 23, column 2 to line 27, column 3)", + " (in 'string', line 29, column 6 to column 42)", + " (in 'string', line 28, column 15 to line 30, column 5)", + " (in 'string', line 28, column 2 to line 30, column 5)", + " (in 'string', line 48, column 2 to column 21)", + " (in 'string', line 50, column 10 to column 84)", + " (in 'string', line 49, column 17 to line 51, column 7)", + " (in 'string', line 49, column 4 to line 51, column 7)", + " (in 'string', line 53, column 10 to column 61)", + " (in 'string', line 52, column 19 to line 54, column 7)", + " (in 'string', line 52, column 6 to line 54, column 7)", + " (in 'string', line 34, column 6 to column 61)", + " (in 'string', line 33, column 17 to line 35, column 5)", + " (in 'string', line 33, column 4 to line 35, column 5)", + " (in 'string', line 37, column 8 to column 39)", + " (in 'string', line 36, column 18 to line 38, column 5)", + " (in 'string', line 36, column 4 to line 38, column 5)", + " (in 'string', line 40, column 2 to column 47)", + " (in 'string', line 41, column 2 to column 22)", + " (in 'string', line 42, column 2 to column 32)", + " (in 'string', line 43, column 2 to column 33)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 4 to column 19)", + " (in 'string', line 4, column 10 to column 11)", + " (in 'string', line 4, column 4 to column 28)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 22)", + " (in 'string', line 7, column 10 to column 11)", + " (in 'string', line 7, column 4 to column 29)", + " (in 'string', line 8, column 10 to column 11)", + " (in 'string', line 8, column 4 to column 28)", + " (in 'string', line 9, column 10 to column 11)", + " (in 'string', line 9, column 4 to column 28)", + " (in 'string', line 10, column 4 to column 28)", + " (in 'string', line 13, column 10 to column 14)", + " (in 'string', line 14, column 10 to column 14)", + " (in 'string', line 19, column 8 to column 12)", + " (in 'string', line 20, column 8 to column 12)", + " (in 'string', line 21, column 8 to column 12)", + " (in 'string', line 22, column 8 to column 9)", + " (in 'string', line 46, column 9 to column 12)"}; +#include +class model_joint_binary_gamma final : public model_base_crtp { +private: + int S; + int C; + std::vector L; + std::vector R; + int Nloc; + std::vector E; + std::vector N; + std::vector K; + std::vector p10priors; + int log_lik_1dim__; +public: + ~model_joint_binary_gamma() {} + model_joint_binary_gamma(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_joint_binary_gamma_namespace::model_joint_binary_gamma"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 36; + context__.validate_dims("data initialization", "S", "int", + std::vector{}); + S = std::numeric_limits::min(); + current_statement__ = 36; + S = context__.vals_i("S")[(1 - 1)]; + current_statement__ = 36; + stan::math::check_greater_or_equal(function__, "S", S, 1); + current_statement__ = 37; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 37; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 37; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 38; + stan::math::validate_non_negative_index("L", "S", S); + current_statement__ = 39; + context__.validate_dims("data initialization", "L", "int", + std::vector{static_cast(S)}); + L = std::vector(S, std::numeric_limits::min()); + current_statement__ = 39; + L = context__.vals_i("L"); + current_statement__ = 39; + stan::math::check_greater_or_equal(function__, "L", L, 1); + current_statement__ = 40; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 41; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 41; + R = context__.vals_i("R"); + current_statement__ = 41; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 42; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 42; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 42; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 43; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 44; + context__.validate_dims("data initialization", "E", "double", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::quiet_NaN()); + current_statement__ = 44; + E = context__.vals_r("E"); + current_statement__ = 44; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 45; + stan::math::validate_non_negative_index("N", "S", S); + current_statement__ = 46; + context__.validate_dims("data initialization", "N", "int", + std::vector{static_cast(S)}); + N = std::vector(S, std::numeric_limits::min()); + current_statement__ = 46; + N = context__.vals_i("N"); + current_statement__ = 46; + stan::math::check_greater_or_equal(function__, "N", N, 1); + current_statement__ = 47; + stan::math::validate_non_negative_index("K", "S", S); + current_statement__ = 48; + context__.validate_dims("data initialization", "K", "int", + std::vector{static_cast(S)}); + K = std::vector(S, std::numeric_limits::min()); + current_statement__ = 48; + K = context__.vals_i("K"); + current_statement__ = 48; + stan::math::check_greater_or_equal(function__, "K", K, 0); + current_statement__ = 49; + context__.validate_dims("data initialization", "p10priors", "double", + std::vector{static_cast(2)}); + p10priors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 49; + p10priors = context__.vals_r("p10priors"); + current_statement__ = 50; + stan::math::validate_non_negative_index("alpha_gamma", "Nloc", Nloc); + current_statement__ = 51; + stan::math::validate_non_negative_index("beta_gamma", "Nloc", Nloc); + current_statement__ = 52; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 53; + stan::math::validate_non_negative_index("p11", "Nloc", Nloc); + current_statement__ = 54; + stan::math::validate_non_negative_index("p", "Nloc", Nloc); + current_statement__ = 55; + stan::math::validate_non_negative_index("E_trans", "C", C); + current_statement__ = 56; + log_lik_1dim__ = std::numeric_limits::min(); + current_statement__ = 56; + log_lik_1dim__ = (C + S); + current_statement__ = 56; + stan::math::validate_non_negative_index("log_lik", "C + S", + log_lik_1dim__); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + Nloc + 1 + 1; + } + inline std::string model_name() const final { + return "model_joint_binary_gamma"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_joint_binary_gamma_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector alpha_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + alpha_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0, lp__, + Nloc); + std::vector beta_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + beta_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0.01, lp__, + Nloc); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 3; + beta = in__.template read_constrain_lb(0, + lp__); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 4; + log_p10 = in__.template read_constrain_ub(0, lp__); + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + std::vector p11 = + std::vector(Nloc, DUMMY_VAR__); + std::vector p = + std::vector(Nloc, DUMMY_VAR__); + std::vector E_trans = + std::vector(C, DUMMY_VAR__); + current_statement__ = 15; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 11; + stan::model::assign(mu, + (stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni(i)) / + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni(i))), "assigning variable mu", + stan::model::index_uni(i)); + current_statement__ = 12; + stan::model::assign(p11, + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + + stan::math::exp(beta))), "assigning variable p11", + stan::model::index_uni(i)); + current_statement__ = 13; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 18; + for (int j = 1; j <= C; ++j) { + current_statement__ = 16; + stan::model::assign(E_trans, + (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + + 0.0000000000001), "assigning variable E_trans", + stan::model::index_uni(j)); + } + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "mu", mu, 0); + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 7; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 8; + stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); + { + current_statement__ = 28; + for (int j = 1; j <= C; ++j) { + current_statement__ = 26; + lp_accum__.add(stan::math::gamma_lpdf( + stan::model::rvalue(E_trans, "E_trans", + stan::model::index_uni(j)), + stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))), + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))))); + } + current_statement__ = 31; + for (int i = 1; i <= S; ++i) { + current_statement__ = 29; + lp_accum__.add(stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", + stan::model::index_uni(i)), + stan::model::rvalue(N, "N", + stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", + stan::model::index_uni(i)))))); + } + current_statement__ = 32; + lp_accum__.add(stan::math::normal_lpdf(log_p10, + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(1)), + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(2)))); + current_statement__ = 33; + lp_accum__.add(stan::math::normal_lpdf(beta, 0, 10)); + current_statement__ = 34; + lp_accum__.add(stan::math::gamma_lpdf(beta_gamma, 0.25, + 0.25)); + current_statement__ = 35; + lp_accum__.add(stan::math::gamma_lpdf(alpha_gamma, 0.01, + 0.01)); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_joint_binary_gamma_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector alpha_gamma = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + alpha_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0, lp__, + Nloc); + std::vector beta_gamma = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 2; + beta_gamma = in__.template read_constrain_lb< + std::vector, jacobian__>(0.01, lp__, + Nloc); + double beta = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; + beta = in__.template read_constrain_lb(0, + lp__); + double log_p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 4; + log_p10 = in__.template read_constrain_ub(0, lp__); + std::vector mu = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector p11 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector p = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector E_trans = + std::vector(C, std::numeric_limits::quiet_NaN()); + out__.write(alpha_gamma); + out__.write(beta_gamma); + out__.write(beta); + out__.write(log_p10); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 15; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 11; + stan::model::assign(mu, + (stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni(i)) / + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni(i))), "assigning variable mu", + stan::model::index_uni(i)); + current_statement__ = 12; + stan::model::assign(p11, + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + + stan::math::exp(beta))), "assigning variable p11", + stan::model::index_uni(i)); + current_statement__ = 13; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 18; + for (int j = 1; j <= C; ++j) { + current_statement__ = 16; + stan::model::assign(E_trans, + (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + + 0.0000000000001), "assigning variable E_trans", + stan::model::index_uni(j)); + } + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "mu", mu, 0); + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 7; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 7; + stan::math::check_less_or_equal(function__, "p", p, 1); + current_statement__ = 8; + stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); + if (emit_transformed_parameters__) { + out__.write(mu); + out__.write(p11); + out__.write(p); + out__.write(E_trans); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(log_lik_1dim__, + std::numeric_limits::quiet_NaN()); + double p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 19; + p10 = stan::math::exp(log_p10); + current_statement__ = 22; + for (int j = 1; j <= C; ++j) { + current_statement__ = 20; + stan::model::assign(log_lik, + stan::math::gamma_lpdf( + stan::model::rvalue(E_trans, "E_trans", stan::model::index_uni(j)), + stan::model::rvalue(alpha_gamma, "alpha_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j)))), + stan::model::rvalue(beta_gamma, "beta_gamma", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + "assigning variable log_lik", stan::model::index_uni(j)); + } + current_statement__ = 25; + for (int i = 1; i <= S; ++i) { + current_statement__ = 23; + stan::model::assign(log_lik, + stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", stan::model::index_uni(i)), + stan::model::rvalue(N, "N", stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", stan::model::index_uni(i))))), + "assigning variable log_lik", stan::model::index_uni((C + i))); + } + out__.write(log_lik); + out__.write(p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector alpha_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(alpha_gamma, + in__.read>(Nloc), + "assigning variable alpha_gamma"); + out__.write_free_lb(0, alpha_gamma); + std::vector beta_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + stan::model::assign(beta_gamma, + in__.read>(Nloc), + "assigning variable beta_gamma"); + out__.write_free_lb(0.01, beta_gamma); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 3; + beta = in__.read(); + out__.write_free_lb(0, beta); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 4; + log_p10 = in__.read(); + out__.write_free_ub(0, log_p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "alpha_gamma", + "double", std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "beta_gamma", + "double", std::vector{static_cast(Nloc)}); + current_statement__ = 3; + context__.validate_dims("parameter initialization", "beta", "double", + std::vector{}); + current_statement__ = 4; + context__.validate_dims("parameter initialization", "log_p10", + "double", std::vector{}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector alpha_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + alpha_gamma = context__.vals_r("alpha_gamma"); + out__.write_free_lb(0, alpha_gamma); + std::vector beta_gamma = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + beta_gamma = context__.vals_r("beta_gamma"); + out__.write_free_lb(0.01, beta_gamma); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 3; + beta = context__.vals_r("beta")[(1 - 1)]; + out__.write_free_lb(0, beta); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 4; + log_p10 = context__.vals_r("log_p10")[(1 - 1)]; + out__.write_free_ub(0, log_p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"alpha_gamma", "beta_gamma", "beta", + "log_p10"}; + if (emit_transformed_parameters__) { + std::vector temp{"mu", "p11", "p", "E_trans"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"log_lik", "p10"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{}, std::vector{}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(C)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(log_lik_1dim__)}, + std::vector{}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta_gamma" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "beta"); + param_names__.emplace_back(std::string() + "log_p10"); + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "E_trans" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha_gamma" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta_gamma" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "beta"); + param_names__.emplace_back(std::string() + "log_p10"); + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "E_trans" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"alpha_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta_gamma\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (((Nloc + Nloc) + 1) + 1); + const size_t num_transformed = emit_transformed_parameters * ((((Nloc + + Nloc) + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * + ((log_lik_1dim__ + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (((Nloc + Nloc) + 1) + 1); + const size_t num_transformed = emit_transformed_parameters * ((((Nloc + + Nloc) + Nloc) + C)); + const size_t num_gen_quantities = emit_generated_quantities * + ((log_lik_1dim__ + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_joint_binary_gamma_namespace::model_joint_binary_gamma; +#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_joint_binary_gamma_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_joint_binary_negbin.h b/src/stanExports_joint_binary_negbin.h index 733f121..ca25a28 100644 --- a/src/stanExports_joint_binary_negbin.h +++ b/src/stanExports_joint_binary_negbin.h @@ -1,749 +1,749 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_joint_binary_negbin_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'joint_binary_negbin', line 14, column 4 to column 33)", - " (in 'joint_binary_negbin', line 15, column 4 to column 22)", - " (in 'joint_binary_negbin', line 16, column 4 to column 23)", - " (in 'joint_binary_negbin', line 17, column 4 to column 26)", - " (in 'joint_binary_negbin', line 20, column 2 to column 43)", - " (in 'joint_binary_negbin', line 21, column 2 to column 40)", - " (in 'joint_binary_negbin', line 40, column 2 to column 22)", - " (in 'joint_binary_negbin', line 41, column 2 to column 11)", - " (in 'joint_binary_negbin', line 23, column 4 to column 41)", - " (in 'joint_binary_negbin', line 24, column 4 to column 33)", - " (in 'joint_binary_negbin', line 22, column 19 to line 25, column 3)", - " (in 'joint_binary_negbin', line 22, column 2 to line 25, column 3)", - " (in 'joint_binary_negbin', line 42, column 2 to column 21)", - " (in 'joint_binary_negbin', line 44, column 10 to column 65)", - " (in 'joint_binary_negbin', line 43, column 17 to line 45, column 7)", - " (in 'joint_binary_negbin', line 43, column 4 to line 45, column 7)", - " (in 'joint_binary_negbin', line 47, column 10 to column 61)", - " (in 'joint_binary_negbin', line 46, column 19 to line 48, column 7)", - " (in 'joint_binary_negbin', line 46, column 6 to line 48, column 7)", - " (in 'joint_binary_negbin', line 29, column 8 to column 45)", - " (in 'joint_binary_negbin', line 28, column 18 to line 30, column 5)", - " (in 'joint_binary_negbin', line 28, column 4 to line 30, column 5)", - " (in 'joint_binary_negbin', line 32, column 8 to column 39)", - " (in 'joint_binary_negbin', line 31, column 18 to line 33, column 5)", - " (in 'joint_binary_negbin', line 31, column 4 to line 33, column 5)", - " (in 'joint_binary_negbin', line 35, column 2 to column 47)", - " (in 'joint_binary_negbin', line 36, column 2 to column 22)", - " (in 'joint_binary_negbin', line 37, column 2 to column 42)", - " (in 'joint_binary_negbin', line 2, column 4 to column 19)", - " (in 'joint_binary_negbin', line 3, column 4 to column 19)", - " (in 'joint_binary_negbin', line 4, column 10 to column 11)", - " (in 'joint_binary_negbin', line 4, column 4 to column 28)", - " (in 'joint_binary_negbin', line 5, column 10 to column 11)", - " (in 'joint_binary_negbin', line 5, column 4 to column 28)", - " (in 'joint_binary_negbin', line 6, column 4 to column 22)", - " (in 'joint_binary_negbin', line 7, column 10 to column 11)", - " (in 'joint_binary_negbin', line 7, column 4 to column 28)", - " (in 'joint_binary_negbin', line 8, column 10 to column 11)", - " (in 'joint_binary_negbin', line 8, column 4 to column 28)", - " (in 'joint_binary_negbin', line 9, column 10 to column 11)", - " (in 'joint_binary_negbin', line 9, column 4 to column 28)", - " (in 'joint_binary_negbin', line 10, column 4 to column 28)", - " (in 'joint_binary_negbin', line 11, column 4 to column 28)", - " (in 'joint_binary_negbin', line 14, column 10 to column 14)", - " (in 'joint_binary_negbin', line 20, column 8 to column 12)", - " (in 'joint_binary_negbin', line 21, column 8 to column 12)", - " (in 'joint_binary_negbin', line 40, column 9 to column 12)"}; -#include -class model_joint_binary_negbin final : public model_base_crtp { -private: - int S; - int C; - std::vector L; - std::vector R; - int Nloc; - std::vector E; - std::vector N; - std::vector K; - std::vector p10priors; - std::vector phipriors; - int log_lik_1dim__; -public: - ~model_joint_binary_negbin() {} - model_joint_binary_negbin(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_joint_binary_negbin_namespace::model_joint_binary_negbin"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 29; - context__.validate_dims("data initialization", "S", "int", - std::vector{}); - S = std::numeric_limits::min(); - current_statement__ = 29; - S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 29; - stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 30; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 30; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 30; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 31; - stan::math::validate_non_negative_index("L", "S", S); - current_statement__ = 32; - context__.validate_dims("data initialization", "L", "int", - std::vector{static_cast(S)}); - L = std::vector(S, std::numeric_limits::min()); - current_statement__ = 32; - L = context__.vals_i("L"); - current_statement__ = 32; - stan::math::check_greater_or_equal(function__, "L", L, 1); - current_statement__ = 33; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 34; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 34; - R = context__.vals_i("R"); - current_statement__ = 34; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 35; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 35; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 35; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 36; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 37; - context__.validate_dims("data initialization", "E", "int", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::min()); - current_statement__ = 37; - E = context__.vals_i("E"); - current_statement__ = 37; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 38; - stan::math::validate_non_negative_index("N", "S", S); - current_statement__ = 39; - context__.validate_dims("data initialization", "N", "int", - std::vector{static_cast(S)}); - N = std::vector(S, std::numeric_limits::min()); - current_statement__ = 39; - N = context__.vals_i("N"); - current_statement__ = 39; - stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 40; - stan::math::validate_non_negative_index("K", "S", S); - current_statement__ = 41; - context__.validate_dims("data initialization", "K", "int", - std::vector{static_cast(S)}); - K = std::vector(S, std::numeric_limits::min()); - current_statement__ = 41; - K = context__.vals_i("K"); - current_statement__ = 41; - stan::math::check_greater_or_equal(function__, "K", K, 0); - current_statement__ = 42; - context__.validate_dims("data initialization", "p10priors", "double", - std::vector{static_cast(2)}); - p10priors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 42; - p10priors = context__.vals_r("p10priors"); - current_statement__ = 43; - context__.validate_dims("data initialization", "phipriors", "double", - std::vector{static_cast(2)}); - phipriors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 43; - phipriors = context__.vals_r("phipriors"); - current_statement__ = 44; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 45; - stan::math::validate_non_negative_index("p11", "Nloc", Nloc); - current_statement__ = 46; - stan::math::validate_non_negative_index("p", "Nloc", Nloc); - current_statement__ = 47; - log_lik_1dim__ = std::numeric_limits::min(); - current_statement__ = 47; - log_lik_1dim__ = (C + S); - current_statement__ = 47; - stan::math::validate_non_negative_index("log_lik", "C + S", - log_lik_1dim__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + 1 + 1 + 1; - } - inline std::string model_name() const final { - return "model_joint_binary_negbin"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_joint_binary_negbin_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = in__.template read_constrain_lb(0, - lp__); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 3; - beta = in__.template read_constrain_lb(0, - lp__); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 4; - log_p10 = in__.template read_constrain_ub(0, lp__); - std::vector p11 = - std::vector(Nloc, DUMMY_VAR__); - std::vector p = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 12; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 9; - stan::model::assign(p11, - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + - stan::math::exp(beta))), "assigning variable p11", - stan::model::index_uni(i)); - current_statement__ = 10; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 5; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p", p, 1); - { - current_statement__ = 22; - for (int j = 1; j <= C; ++j) { - current_statement__ = 20; - lp_accum__.add(stan::math::neg_binomial_2_lpmf( - stan::model::rvalue(E, "E", - stan::model::index_uni(j)), - stan::model::rvalue(mu, "mu", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))), phi)); - } - current_statement__ = 25; - for (int i = 1; i <= S; ++i) { - current_statement__ = 23; - lp_accum__.add(stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", - stan::model::index_uni(i)), - stan::model::rvalue(N, "N", - stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", - stan::model::index_uni(i)))))); - } - current_statement__ = 26; - lp_accum__.add(stan::math::normal_lpdf(log_p10, - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(1)), - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(2)))); - current_statement__ = 27; - lp_accum__.add(stan::math::normal_lpdf(beta, 0, 10)); - current_statement__ = 28; - lp_accum__.add(stan::math::gamma_lpdf(phi, - stan::model::rvalue(phipriors, "phipriors", - stan::model::index_uni(1)), - stan::model::rvalue(phipriors, "phipriors", - stan::model::index_uni(2)))); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_joint_binary_negbin_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector mu = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - mu = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - double phi = std::numeric_limits::quiet_NaN(); - current_statement__ = 2; - phi = in__.template read_constrain_lb(0, - lp__); - double beta = std::numeric_limits::quiet_NaN(); - current_statement__ = 3; - beta = in__.template read_constrain_lb(0, - lp__); - double log_p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 4; - log_p10 = in__.template read_constrain_ub(0, lp__); - std::vector p11 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector p = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - out__.write(mu); - out__.write(phi); - out__.write(beta); - out__.write(log_p10); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 12; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 9; - stan::model::assign(p11, - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + - stan::math::exp(beta))), "assigning variable p11", - stan::model::index_uni(i)); - current_statement__ = 10; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 5; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 6; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 6; - stan::math::check_less_or_equal(function__, "p", p, 1); - if (emit_transformed_parameters__) { - out__.write(p11); - out__.write(p); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(log_lik_1dim__, - std::numeric_limits::quiet_NaN()); - double p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 13; - p10 = stan::math::exp(log_p10); - current_statement__ = 16; - for (int j = 1; j <= C; ++j) { - current_statement__ = 14; - stan::model::assign(log_lik, - stan::math::neg_binomial_2_lpmf( - stan::model::rvalue(E, "E", stan::model::index_uni(j)), - stan::model::rvalue(mu, "mu", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j)))), phi), - "assigning variable log_lik", stan::model::index_uni(j)); - } - current_statement__ = 19; - for (int i = 1; i <= S; ++i) { - current_statement__ = 17; - stan::model::assign(log_lik, - stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", stan::model::index_uni(i)), - stan::model::rvalue(N, "N", stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", stan::model::index_uni(i))))), - "assigning variable log_lik", stan::model::index_uni((C + i))); - } - out__.write(log_lik); - out__.write(p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(mu, in__.read>(Nloc), - "assigning variable mu"); - out__.write_free_lb(0, mu); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = in__.read(); - out__.write_free_lb(0, phi); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 3; - beta = in__.read(); - out__.write_free_lb(0, beta); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 4; - log_p10 = in__.read(); - out__.write_free_ub(0, log_p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "mu", "double", - std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "phi", "double", - std::vector{}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "beta", "double", - std::vector{}); - current_statement__ = 4; - context__.validate_dims("parameter initialization", "log_p10", - "double", std::vector{}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu = context__.vals_r("mu"); - out__.write_free_lb(0, mu); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = context__.vals_r("phi")[(1 - 1)]; - out__.write_free_lb(0, phi); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 3; - beta = context__.vals_r("beta")[(1 - 1)]; - out__.write_free_lb(0, beta); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 4; - log_p10 = context__.vals_r("log_p10")[(1 - 1)]; - out__.write_free_ub(0, log_p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"mu", "phi", "beta", "log_p10"}; - if (emit_transformed_parameters__) { - std::vector temp{"p11", "p"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"log_lik", "p10"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{}, std::vector{}, - std::vector{}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(log_lik_1dim__)}, - std::vector{}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "phi"); - param_names__.emplace_back(std::string() + "beta"); - param_names__.emplace_back(std::string() + "log_p10"); - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "phi"); - param_names__.emplace_back(std::string() + "beta"); - param_names__.emplace_back(std::string() + "log_p10"); - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (((Nloc + 1) + 1) + 1); - const size_t num_transformed = emit_transformed_parameters * ((Nloc + - Nloc)); - const size_t num_gen_quantities = emit_generated_quantities * - ((log_lik_1dim__ + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (((Nloc + 1) + 1) + 1); - const size_t num_transformed = emit_transformed_parameters * ((Nloc + - Nloc)); - const size_t num_gen_quantities = emit_generated_quantities * - ((log_lik_1dim__ + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_joint_binary_negbin_namespace::model_joint_binary_negbin; -#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_joint_binary_negbin_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_joint_binary_negbin_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 14, column 4 to column 33)", + " (in 'string', line 15, column 4 to column 22)", + " (in 'string', line 16, column 4 to column 23)", + " (in 'string', line 17, column 4 to column 26)", + " (in 'string', line 20, column 2 to column 43)", + " (in 'string', line 21, column 2 to column 40)", + " (in 'string', line 40, column 2 to column 22)", + " (in 'string', line 41, column 2 to column 11)", + " (in 'string', line 23, column 4 to column 41)", + " (in 'string', line 24, column 4 to column 33)", + " (in 'string', line 22, column 19 to line 25, column 3)", + " (in 'string', line 22, column 2 to line 25, column 3)", + " (in 'string', line 42, column 2 to column 21)", + " (in 'string', line 44, column 10 to column 65)", + " (in 'string', line 43, column 17 to line 45, column 7)", + " (in 'string', line 43, column 4 to line 45, column 7)", + " (in 'string', line 47, column 10 to column 61)", + " (in 'string', line 46, column 19 to line 48, column 7)", + " (in 'string', line 46, column 6 to line 48, column 7)", + " (in 'string', line 29, column 8 to column 45)", + " (in 'string', line 28, column 18 to line 30, column 5)", + " (in 'string', line 28, column 4 to line 30, column 5)", + " (in 'string', line 32, column 8 to column 39)", + " (in 'string', line 31, column 18 to line 33, column 5)", + " (in 'string', line 31, column 4 to line 33, column 5)", + " (in 'string', line 35, column 2 to column 47)", + " (in 'string', line 36, column 2 to column 22)", + " (in 'string', line 37, column 2 to column 42)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 4 to column 19)", + " (in 'string', line 4, column 10 to column 11)", + " (in 'string', line 4, column 4 to column 28)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 22)", + " (in 'string', line 7, column 10 to column 11)", + " (in 'string', line 7, column 4 to column 28)", + " (in 'string', line 8, column 10 to column 11)", + " (in 'string', line 8, column 4 to column 28)", + " (in 'string', line 9, column 10 to column 11)", + " (in 'string', line 9, column 4 to column 28)", + " (in 'string', line 10, column 4 to column 28)", + " (in 'string', line 11, column 4 to column 28)", + " (in 'string', line 14, column 10 to column 14)", + " (in 'string', line 20, column 8 to column 12)", + " (in 'string', line 21, column 8 to column 12)", + " (in 'string', line 40, column 9 to column 12)"}; +#include +class model_joint_binary_negbin final : public model_base_crtp { +private: + int S; + int C; + std::vector L; + std::vector R; + int Nloc; + std::vector E; + std::vector N; + std::vector K; + std::vector p10priors; + std::vector phipriors; + int log_lik_1dim__; +public: + ~model_joint_binary_negbin() {} + model_joint_binary_negbin(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_joint_binary_negbin_namespace::model_joint_binary_negbin"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 29; + context__.validate_dims("data initialization", "S", "int", + std::vector{}); + S = std::numeric_limits::min(); + current_statement__ = 29; + S = context__.vals_i("S")[(1 - 1)]; + current_statement__ = 29; + stan::math::check_greater_or_equal(function__, "S", S, 1); + current_statement__ = 30; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 30; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 30; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 31; + stan::math::validate_non_negative_index("L", "S", S); + current_statement__ = 32; + context__.validate_dims("data initialization", "L", "int", + std::vector{static_cast(S)}); + L = std::vector(S, std::numeric_limits::min()); + current_statement__ = 32; + L = context__.vals_i("L"); + current_statement__ = 32; + stan::math::check_greater_or_equal(function__, "L", L, 1); + current_statement__ = 33; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 34; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 34; + R = context__.vals_i("R"); + current_statement__ = 34; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 35; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 35; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 35; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 36; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 37; + context__.validate_dims("data initialization", "E", "int", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::min()); + current_statement__ = 37; + E = context__.vals_i("E"); + current_statement__ = 37; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 38; + stan::math::validate_non_negative_index("N", "S", S); + current_statement__ = 39; + context__.validate_dims("data initialization", "N", "int", + std::vector{static_cast(S)}); + N = std::vector(S, std::numeric_limits::min()); + current_statement__ = 39; + N = context__.vals_i("N"); + current_statement__ = 39; + stan::math::check_greater_or_equal(function__, "N", N, 1); + current_statement__ = 40; + stan::math::validate_non_negative_index("K", "S", S); + current_statement__ = 41; + context__.validate_dims("data initialization", "K", "int", + std::vector{static_cast(S)}); + K = std::vector(S, std::numeric_limits::min()); + current_statement__ = 41; + K = context__.vals_i("K"); + current_statement__ = 41; + stan::math::check_greater_or_equal(function__, "K", K, 0); + current_statement__ = 42; + context__.validate_dims("data initialization", "p10priors", "double", + std::vector{static_cast(2)}); + p10priors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 42; + p10priors = context__.vals_r("p10priors"); + current_statement__ = 43; + context__.validate_dims("data initialization", "phipriors", "double", + std::vector{static_cast(2)}); + phipriors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 43; + phipriors = context__.vals_r("phipriors"); + current_statement__ = 44; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 45; + stan::math::validate_non_negative_index("p11", "Nloc", Nloc); + current_statement__ = 46; + stan::math::validate_non_negative_index("p", "Nloc", Nloc); + current_statement__ = 47; + log_lik_1dim__ = std::numeric_limits::min(); + current_statement__ = 47; + log_lik_1dim__ = (C + S); + current_statement__ = 47; + stan::math::validate_non_negative_index("log_lik", "C + S", + log_lik_1dim__); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + 1 + 1 + 1; + } + inline std::string model_name() const final { + return "model_joint_binary_negbin"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_joint_binary_negbin_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = in__.template read_constrain_lb(0, + lp__); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 3; + beta = in__.template read_constrain_lb(0, + lp__); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 4; + log_p10 = in__.template read_constrain_ub(0, lp__); + std::vector p11 = + std::vector(Nloc, DUMMY_VAR__); + std::vector p = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 12; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 9; + stan::model::assign(p11, + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + + stan::math::exp(beta))), "assigning variable p11", + stan::model::index_uni(i)); + current_statement__ = 10; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 5; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p", p, 1); + { + current_statement__ = 22; + for (int j = 1; j <= C; ++j) { + current_statement__ = 20; + lp_accum__.add(stan::math::neg_binomial_2_lpmf( + stan::model::rvalue(E, "E", + stan::model::index_uni(j)), + stan::model::rvalue(mu, "mu", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))), phi)); + } + current_statement__ = 25; + for (int i = 1; i <= S; ++i) { + current_statement__ = 23; + lp_accum__.add(stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", + stan::model::index_uni(i)), + stan::model::rvalue(N, "N", + stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", + stan::model::index_uni(i)))))); + } + current_statement__ = 26; + lp_accum__.add(stan::math::normal_lpdf(log_p10, + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(1)), + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(2)))); + current_statement__ = 27; + lp_accum__.add(stan::math::normal_lpdf(beta, 0, 10)); + current_statement__ = 28; + lp_accum__.add(stan::math::gamma_lpdf(phi, + stan::model::rvalue(phipriors, "phipriors", + stan::model::index_uni(1)), + stan::model::rvalue(phipriors, "phipriors", + stan::model::index_uni(2)))); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_joint_binary_negbin_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector mu = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + mu = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + double phi = std::numeric_limits::quiet_NaN(); + current_statement__ = 2; + phi = in__.template read_constrain_lb(0, + lp__); + double beta = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; + beta = in__.template read_constrain_lb(0, + lp__); + double log_p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 4; + log_p10 = in__.template read_constrain_ub(0, lp__); + std::vector p11 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector p = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + out__.write(mu); + out__.write(phi); + out__.write(beta); + out__.write(log_p10); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 12; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 9; + stan::model::assign(p11, + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + + stan::math::exp(beta))), "assigning variable p11", + stan::model::index_uni(i)); + current_statement__ = 10; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 5; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 6; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 6; + stan::math::check_less_or_equal(function__, "p", p, 1); + if (emit_transformed_parameters__) { + out__.write(p11); + out__.write(p); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(log_lik_1dim__, + std::numeric_limits::quiet_NaN()); + double p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 13; + p10 = stan::math::exp(log_p10); + current_statement__ = 16; + for (int j = 1; j <= C; ++j) { + current_statement__ = 14; + stan::model::assign(log_lik, + stan::math::neg_binomial_2_lpmf( + stan::model::rvalue(E, "E", stan::model::index_uni(j)), + stan::model::rvalue(mu, "mu", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j)))), phi), + "assigning variable log_lik", stan::model::index_uni(j)); + } + current_statement__ = 19; + for (int i = 1; i <= S; ++i) { + current_statement__ = 17; + stan::model::assign(log_lik, + stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", stan::model::index_uni(i)), + stan::model::rvalue(N, "N", stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", stan::model::index_uni(i))))), + "assigning variable log_lik", stan::model::index_uni((C + i))); + } + out__.write(log_lik); + out__.write(p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(mu, in__.read>(Nloc), + "assigning variable mu"); + out__.write_free_lb(0, mu); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = in__.read(); + out__.write_free_lb(0, phi); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 3; + beta = in__.read(); + out__.write_free_lb(0, beta); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 4; + log_p10 = in__.read(); + out__.write_free_ub(0, log_p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "mu", "double", + std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "phi", "double", + std::vector{}); + current_statement__ = 3; + context__.validate_dims("parameter initialization", "beta", "double", + std::vector{}); + current_statement__ = 4; + context__.validate_dims("parameter initialization", "log_p10", + "double", std::vector{}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu = context__.vals_r("mu"); + out__.write_free_lb(0, mu); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = context__.vals_r("phi")[(1 - 1)]; + out__.write_free_lb(0, phi); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 3; + beta = context__.vals_r("beta")[(1 - 1)]; + out__.write_free_lb(0, beta); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 4; + log_p10 = context__.vals_r("log_p10")[(1 - 1)]; + out__.write_free_ub(0, log_p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"mu", "phi", "beta", "log_p10"}; + if (emit_transformed_parameters__) { + std::vector temp{"p11", "p"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"log_lik", "p10"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{}, std::vector{}, + std::vector{}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(log_lik_1dim__)}, + std::vector{}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "phi"); + param_names__.emplace_back(std::string() + "beta"); + param_names__.emplace_back(std::string() + "log_p10"); + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "phi"); + param_names__.emplace_back(std::string() + "beta"); + param_names__.emplace_back(std::string() + "log_p10"); + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (((Nloc + 1) + 1) + 1); + const size_t num_transformed = emit_transformed_parameters * ((Nloc + + Nloc)); + const size_t num_gen_quantities = emit_generated_quantities * + ((log_lik_1dim__ + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (((Nloc + 1) + 1) + 1); + const size_t num_transformed = emit_transformed_parameters * ((Nloc + + Nloc)); + const size_t num_gen_quantities = emit_generated_quantities * + ((log_lik_1dim__ + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_joint_binary_negbin_namespace::model_joint_binary_negbin; +#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_joint_binary_negbin_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_joint_binary_pois.h b/src/stanExports_joint_binary_pois.h index 03f159b..9b0a4ff 100644 --- a/src/stanExports_joint_binary_pois.h +++ b/src/stanExports_joint_binary_pois.h @@ -1,709 +1,709 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_joint_binary_pois_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'joint_binary_pois', line 13, column 4 to column 33)", - " (in 'joint_binary_pois', line 14, column 4 to column 23)", - " (in 'joint_binary_pois', line 15, column 4 to column 26)", - " (in 'joint_binary_pois', line 18, column 2 to column 43)", - " (in 'joint_binary_pois', line 19, column 2 to column 41)", - " (in 'joint_binary_pois', line 37, column 2 to column 22)", - " (in 'joint_binary_pois', line 38, column 2 to column 11)", - " (in 'joint_binary_pois', line 21, column 4 to column 41)", - " (in 'joint_binary_pois', line 22, column 4 to column 33)", - " (in 'joint_binary_pois', line 20, column 19 to line 23, column 3)", - " (in 'joint_binary_pois', line 20, column 2 to line 23, column 3)", - " (in 'joint_binary_pois', line 39, column 2 to column 21)", - " (in 'joint_binary_pois', line 41, column 10 to column 53)", - " (in 'joint_binary_pois', line 40, column 17 to line 42, column 7)", - " (in 'joint_binary_pois', line 40, column 4 to line 42, column 7)", - " (in 'joint_binary_pois', line 44, column 10 to column 61)", - " (in 'joint_binary_pois', line 43, column 19 to line 45, column 7)", - " (in 'joint_binary_pois', line 43, column 6 to line 45, column 7)", - " (in 'joint_binary_pois', line 27, column 8 to column 33)", - " (in 'joint_binary_pois', line 26, column 17 to line 28, column 5)", - " (in 'joint_binary_pois', line 26, column 4 to line 28, column 5)", - " (in 'joint_binary_pois', line 30, column 8 to column 39)", - " (in 'joint_binary_pois', line 29, column 18 to line 31, column 5)", - " (in 'joint_binary_pois', line 29, column 4 to line 31, column 5)", - " (in 'joint_binary_pois', line 33, column 2 to column 47)", - " (in 'joint_binary_pois', line 34, column 2 to column 22)", - " (in 'joint_binary_pois', line 2, column 4 to column 19)", - " (in 'joint_binary_pois', line 3, column 4 to column 19)", - " (in 'joint_binary_pois', line 4, column 10 to column 11)", - " (in 'joint_binary_pois', line 4, column 4 to column 28)", - " (in 'joint_binary_pois', line 5, column 10 to column 11)", - " (in 'joint_binary_pois', line 5, column 4 to column 28)", - " (in 'joint_binary_pois', line 6, column 4 to column 22)", - " (in 'joint_binary_pois', line 7, column 10 to column 11)", - " (in 'joint_binary_pois', line 7, column 4 to column 28)", - " (in 'joint_binary_pois', line 8, column 10 to column 11)", - " (in 'joint_binary_pois', line 8, column 4 to column 28)", - " (in 'joint_binary_pois', line 9, column 10 to column 11)", - " (in 'joint_binary_pois', line 9, column 4 to column 28)", - " (in 'joint_binary_pois', line 10, column 4 to column 28)", - " (in 'joint_binary_pois', line 13, column 10 to column 14)", - " (in 'joint_binary_pois', line 18, column 8 to column 12)", - " (in 'joint_binary_pois', line 19, column 8 to column 12)", - " (in 'joint_binary_pois', line 37, column 9 to column 12)"}; -#include -class model_joint_binary_pois final : public model_base_crtp { -private: - int S; - int C; - std::vector L; - std::vector R; - int Nloc; - std::vector E; - std::vector N; - std::vector K; - std::vector p10priors; - int log_lik_1dim__; -public: - ~model_joint_binary_pois() {} - model_joint_binary_pois(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_joint_binary_pois_namespace::model_joint_binary_pois"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 27; - context__.validate_dims("data initialization", "S", "int", - std::vector{}); - S = std::numeric_limits::min(); - current_statement__ = 27; - S = context__.vals_i("S")[(1 - 1)]; - current_statement__ = 27; - stan::math::check_greater_or_equal(function__, "S", S, 1); - current_statement__ = 28; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 28; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 28; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 29; - stan::math::validate_non_negative_index("L", "S", S); - current_statement__ = 30; - context__.validate_dims("data initialization", "L", "int", - std::vector{static_cast(S)}); - L = std::vector(S, std::numeric_limits::min()); - current_statement__ = 30; - L = context__.vals_i("L"); - current_statement__ = 30; - stan::math::check_greater_or_equal(function__, "L", L, 1); - current_statement__ = 31; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 32; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 32; - R = context__.vals_i("R"); - current_statement__ = 32; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 33; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 33; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 33; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 34; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 35; - context__.validate_dims("data initialization", "E", "int", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::min()); - current_statement__ = 35; - E = context__.vals_i("E"); - current_statement__ = 35; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 36; - stan::math::validate_non_negative_index("N", "S", S); - current_statement__ = 37; - context__.validate_dims("data initialization", "N", "int", - std::vector{static_cast(S)}); - N = std::vector(S, std::numeric_limits::min()); - current_statement__ = 37; - N = context__.vals_i("N"); - current_statement__ = 37; - stan::math::check_greater_or_equal(function__, "N", N, 1); - current_statement__ = 38; - stan::math::validate_non_negative_index("K", "S", S); - current_statement__ = 39; - context__.validate_dims("data initialization", "K", "int", - std::vector{static_cast(S)}); - K = std::vector(S, std::numeric_limits::min()); - current_statement__ = 39; - K = context__.vals_i("K"); - current_statement__ = 39; - stan::math::check_greater_or_equal(function__, "K", K, 0); - current_statement__ = 40; - context__.validate_dims("data initialization", "p10priors", "double", - std::vector{static_cast(2)}); - p10priors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 40; - p10priors = context__.vals_r("p10priors"); - current_statement__ = 41; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 42; - stan::math::validate_non_negative_index("p11", "Nloc", Nloc); - current_statement__ = 43; - stan::math::validate_non_negative_index("p", "Nloc", Nloc); - current_statement__ = 44; - log_lik_1dim__ = std::numeric_limits::min(); - current_statement__ = 44; - log_lik_1dim__ = (C + S); - current_statement__ = 44; - stan::math::validate_non_negative_index("log_lik", "C + S", - log_lik_1dim__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + 1 + 1; - } - inline std::string model_name() const final { - return "model_joint_binary_pois"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_joint_binary_pois_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 2; - beta = in__.template read_constrain_lb(0, - lp__); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = in__.template read_constrain_ub(0, lp__); - std::vector p11 = - std::vector(Nloc, DUMMY_VAR__); - std::vector p = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 11; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 8; - stan::model::assign(p11, - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + - stan::math::exp(beta))), "assigning variable p11", - stan::model::index_uni(i)); - current_statement__ = 9; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 4; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 4; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 5; - stan::math::check_less_or_equal(function__, "p", p, 1); - { - current_statement__ = 21; - for (int j = 1; j <= C; ++j) { - current_statement__ = 19; - lp_accum__.add(stan::math::poisson_lpmf( - stan::model::rvalue(E, "E", - stan::model::index_uni(j)), - stan::model::rvalue(mu, "mu", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))))); - } - current_statement__ = 24; - for (int i = 1; i <= S; ++i) { - current_statement__ = 22; - lp_accum__.add(stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", - stan::model::index_uni(i)), - stan::model::rvalue(N, "N", - stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", - stan::model::index_uni(i)))))); - } - current_statement__ = 25; - lp_accum__.add(stan::math::normal_lpdf(log_p10, - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(1)), - stan::model::rvalue(p10priors, "p10priors", - stan::model::index_uni(2)))); - current_statement__ = 26; - lp_accum__.add(stan::math::normal_lpdf(beta, 0, 10)); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_joint_binary_pois_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector mu = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - mu = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - double beta = std::numeric_limits::quiet_NaN(); - current_statement__ = 2; - beta = in__.template read_constrain_lb(0, - lp__); - double log_p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 3; - log_p10 = in__.template read_constrain_ub(0, lp__); - std::vector p11 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - std::vector p = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - out__.write(mu); - out__.write(beta); - out__.write(log_p10); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 11; - for (int i = 1; i <= Nloc; ++i) { - current_statement__ = 8; - stan::model::assign(p11, - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / - (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + - stan::math::exp(beta))), "assigning variable p11", - stan::model::index_uni(i)); - current_statement__ = 9; - stan::model::assign(p, - (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + - stan::math::exp(log_p10)), "assigning variable p", - stan::model::index_uni(i)); - } - current_statement__ = 4; - stan::math::check_greater_or_equal(function__, "p11", p11, 0); - current_statement__ = 4; - stan::math::check_less_or_equal(function__, "p11", p11, 1); - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "p", p, 0); - current_statement__ = 5; - stan::math::check_less_or_equal(function__, "p", p, 1); - if (emit_transformed_parameters__) { - out__.write(p11); - out__.write(p); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(log_lik_1dim__, - std::numeric_limits::quiet_NaN()); - double p10 = std::numeric_limits::quiet_NaN(); - current_statement__ = 12; - p10 = stan::math::exp(log_p10); - current_statement__ = 15; - for (int j = 1; j <= C; ++j) { - current_statement__ = 13; - stan::model::assign(log_lik, - stan::math::poisson_lpmf( - stan::model::rvalue(E, "E", stan::model::index_uni(j)), - stan::model::rvalue(mu, "mu", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - "assigning variable log_lik", stan::model::index_uni(j)); - } - current_statement__ = 18; - for (int i = 1; i <= S; ++i) { - current_statement__ = 16; - stan::model::assign(log_lik, - stan::math::binomial_lpmf( - stan::model::rvalue(K, "K", stan::model::index_uni(i)), - stan::model::rvalue(N, "N", stan::model::index_uni(i)), - stan::model::rvalue(p, "p", - stan::model::index_uni( - stan::model::rvalue(L, "L", stan::model::index_uni(i))))), - "assigning variable log_lik", stan::model::index_uni((C + i))); - } - out__.write(log_lik); - out__.write(p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(mu, in__.read>(Nloc), - "assigning variable mu"); - out__.write_free_lb(0, mu); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 2; - beta = in__.read(); - out__.write_free_lb(0, beta); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = in__.read(); - out__.write_free_ub(0, log_p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "mu", "double", - std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "beta", "double", - std::vector{}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "log_p10", - "double", std::vector{}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu = context__.vals_r("mu"); - out__.write_free_lb(0, mu); - local_scalar_t__ beta = DUMMY_VAR__; - current_statement__ = 2; - beta = context__.vals_r("beta")[(1 - 1)]; - out__.write_free_lb(0, beta); - local_scalar_t__ log_p10 = DUMMY_VAR__; - current_statement__ = 3; - log_p10 = context__.vals_r("log_p10")[(1 - 1)]; - out__.write_free_ub(0, log_p10); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"mu", "beta", "log_p10"}; - if (emit_transformed_parameters__) { - std::vector temp{"p11", "p"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"log_lik", "p10"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{}, std::vector{}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(Nloc)}, - std::vector{static_cast(Nloc)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(log_lik_1dim__)}, - std::vector{}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "beta"); - param_names__.emplace_back(std::string() + "log_p10"); - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "beta"); - param_names__.emplace_back(std::string() + "log_p10"); - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p11" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "p" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "p10"); - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((Nloc + 1) + 1); - const size_t num_transformed = emit_transformed_parameters * ((Nloc + - Nloc)); - const size_t num_gen_quantities = emit_generated_quantities * - ((log_lik_1dim__ + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((Nloc + 1) + 1); - const size_t num_transformed = emit_transformed_parameters * ((Nloc + - Nloc)); - const size_t num_gen_quantities = emit_generated_quantities * - ((log_lik_1dim__ + 1)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_joint_binary_pois_namespace::model_joint_binary_pois; -#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_joint_binary_pois_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_joint_binary_pois_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 13, column 4 to column 33)", + " (in 'string', line 14, column 4 to column 23)", + " (in 'string', line 15, column 4 to column 26)", + " (in 'string', line 18, column 2 to column 43)", + " (in 'string', line 19, column 2 to column 41)", + " (in 'string', line 37, column 2 to column 22)", + " (in 'string', line 38, column 2 to column 11)", + " (in 'string', line 21, column 4 to column 41)", + " (in 'string', line 22, column 4 to column 33)", + " (in 'string', line 20, column 19 to line 23, column 3)", + " (in 'string', line 20, column 2 to line 23, column 3)", + " (in 'string', line 39, column 2 to column 21)", + " (in 'string', line 41, column 10 to column 53)", + " (in 'string', line 40, column 17 to line 42, column 7)", + " (in 'string', line 40, column 4 to line 42, column 7)", + " (in 'string', line 44, column 10 to column 61)", + " (in 'string', line 43, column 19 to line 45, column 7)", + " (in 'string', line 43, column 6 to line 45, column 7)", + " (in 'string', line 27, column 8 to column 33)", + " (in 'string', line 26, column 17 to line 28, column 5)", + " (in 'string', line 26, column 4 to line 28, column 5)", + " (in 'string', line 30, column 8 to column 39)", + " (in 'string', line 29, column 18 to line 31, column 5)", + " (in 'string', line 29, column 4 to line 31, column 5)", + " (in 'string', line 33, column 2 to column 47)", + " (in 'string', line 34, column 2 to column 22)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 4 to column 19)", + " (in 'string', line 4, column 10 to column 11)", + " (in 'string', line 4, column 4 to column 28)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 22)", + " (in 'string', line 7, column 10 to column 11)", + " (in 'string', line 7, column 4 to column 28)", + " (in 'string', line 8, column 10 to column 11)", + " (in 'string', line 8, column 4 to column 28)", + " (in 'string', line 9, column 10 to column 11)", + " (in 'string', line 9, column 4 to column 28)", + " (in 'string', line 10, column 4 to column 28)", + " (in 'string', line 13, column 10 to column 14)", + " (in 'string', line 18, column 8 to column 12)", + " (in 'string', line 19, column 8 to column 12)", + " (in 'string', line 37, column 9 to column 12)"}; +#include +class model_joint_binary_pois final : public model_base_crtp { +private: + int S; + int C; + std::vector L; + std::vector R; + int Nloc; + std::vector E; + std::vector N; + std::vector K; + std::vector p10priors; + int log_lik_1dim__; +public: + ~model_joint_binary_pois() {} + model_joint_binary_pois(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_joint_binary_pois_namespace::model_joint_binary_pois"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 27; + context__.validate_dims("data initialization", "S", "int", + std::vector{}); + S = std::numeric_limits::min(); + current_statement__ = 27; + S = context__.vals_i("S")[(1 - 1)]; + current_statement__ = 27; + stan::math::check_greater_or_equal(function__, "S", S, 1); + current_statement__ = 28; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 28; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 28; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 29; + stan::math::validate_non_negative_index("L", "S", S); + current_statement__ = 30; + context__.validate_dims("data initialization", "L", "int", + std::vector{static_cast(S)}); + L = std::vector(S, std::numeric_limits::min()); + current_statement__ = 30; + L = context__.vals_i("L"); + current_statement__ = 30; + stan::math::check_greater_or_equal(function__, "L", L, 1); + current_statement__ = 31; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 32; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 32; + R = context__.vals_i("R"); + current_statement__ = 32; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 33; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 33; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 33; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 34; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 35; + context__.validate_dims("data initialization", "E", "int", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::min()); + current_statement__ = 35; + E = context__.vals_i("E"); + current_statement__ = 35; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 36; + stan::math::validate_non_negative_index("N", "S", S); + current_statement__ = 37; + context__.validate_dims("data initialization", "N", "int", + std::vector{static_cast(S)}); + N = std::vector(S, std::numeric_limits::min()); + current_statement__ = 37; + N = context__.vals_i("N"); + current_statement__ = 37; + stan::math::check_greater_or_equal(function__, "N", N, 1); + current_statement__ = 38; + stan::math::validate_non_negative_index("K", "S", S); + current_statement__ = 39; + context__.validate_dims("data initialization", "K", "int", + std::vector{static_cast(S)}); + K = std::vector(S, std::numeric_limits::min()); + current_statement__ = 39; + K = context__.vals_i("K"); + current_statement__ = 39; + stan::math::check_greater_or_equal(function__, "K", K, 0); + current_statement__ = 40; + context__.validate_dims("data initialization", "p10priors", "double", + std::vector{static_cast(2)}); + p10priors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 40; + p10priors = context__.vals_r("p10priors"); + current_statement__ = 41; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 42; + stan::math::validate_non_negative_index("p11", "Nloc", Nloc); + current_statement__ = 43; + stan::math::validate_non_negative_index("p", "Nloc", Nloc); + current_statement__ = 44; + log_lik_1dim__ = std::numeric_limits::min(); + current_statement__ = 44; + log_lik_1dim__ = (C + S); + current_statement__ = 44; + stan::math::validate_non_negative_index("log_lik", "C + S", + log_lik_1dim__); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + 1 + 1; + } + inline std::string model_name() const final { + return "model_joint_binary_pois"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_joint_binary_pois_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 2; + beta = in__.template read_constrain_lb(0, + lp__); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = in__.template read_constrain_ub(0, lp__); + std::vector p11 = + std::vector(Nloc, DUMMY_VAR__); + std::vector p = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 11; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 8; + stan::model::assign(p11, + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + + stan::math::exp(beta))), "assigning variable p11", + stan::model::index_uni(i)); + current_statement__ = 9; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 4; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 4; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 5; + stan::math::check_less_or_equal(function__, "p", p, 1); + { + current_statement__ = 21; + for (int j = 1; j <= C; ++j) { + current_statement__ = 19; + lp_accum__.add(stan::math::poisson_lpmf( + stan::model::rvalue(E, "E", + stan::model::index_uni(j)), + stan::model::rvalue(mu, "mu", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))))); + } + current_statement__ = 24; + for (int i = 1; i <= S; ++i) { + current_statement__ = 22; + lp_accum__.add(stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", + stan::model::index_uni(i)), + stan::model::rvalue(N, "N", + stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", + stan::model::index_uni(i)))))); + } + current_statement__ = 25; + lp_accum__.add(stan::math::normal_lpdf(log_p10, + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(1)), + stan::model::rvalue(p10priors, "p10priors", + stan::model::index_uni(2)))); + current_statement__ = 26; + lp_accum__.add(stan::math::normal_lpdf(beta, 0, 10)); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_joint_binary_pois_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector mu = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + mu = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + double beta = std::numeric_limits::quiet_NaN(); + current_statement__ = 2; + beta = in__.template read_constrain_lb(0, + lp__); + double log_p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 3; + log_p10 = in__.template read_constrain_ub(0, lp__); + std::vector p11 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + std::vector p = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + out__.write(mu); + out__.write(beta); + out__.write(log_p10); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 11; + for (int i = 1; i <= Nloc; ++i) { + current_statement__ = 8; + stan::model::assign(p11, + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) / + (stan::model::rvalue(mu, "mu", stan::model::index_uni(i)) + + stan::math::exp(beta))), "assigning variable p11", + stan::model::index_uni(i)); + current_statement__ = 9; + stan::model::assign(p, + (stan::model::rvalue(p11, "p11", stan::model::index_uni(i)) + + stan::math::exp(log_p10)), "assigning variable p", + stan::model::index_uni(i)); + } + current_statement__ = 4; + stan::math::check_greater_or_equal(function__, "p11", p11, 0); + current_statement__ = 4; + stan::math::check_less_or_equal(function__, "p11", p11, 1); + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "p", p, 0); + current_statement__ = 5; + stan::math::check_less_or_equal(function__, "p", p, 1); + if (emit_transformed_parameters__) { + out__.write(p11); + out__.write(p); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(log_lik_1dim__, + std::numeric_limits::quiet_NaN()); + double p10 = std::numeric_limits::quiet_NaN(); + current_statement__ = 12; + p10 = stan::math::exp(log_p10); + current_statement__ = 15; + for (int j = 1; j <= C; ++j) { + current_statement__ = 13; + stan::model::assign(log_lik, + stan::math::poisson_lpmf( + stan::model::rvalue(E, "E", stan::model::index_uni(j)), + stan::model::rvalue(mu, "mu", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + "assigning variable log_lik", stan::model::index_uni(j)); + } + current_statement__ = 18; + for (int i = 1; i <= S; ++i) { + current_statement__ = 16; + stan::model::assign(log_lik, + stan::math::binomial_lpmf( + stan::model::rvalue(K, "K", stan::model::index_uni(i)), + stan::model::rvalue(N, "N", stan::model::index_uni(i)), + stan::model::rvalue(p, "p", + stan::model::index_uni( + stan::model::rvalue(L, "L", stan::model::index_uni(i))))), + "assigning variable log_lik", stan::model::index_uni((C + i))); + } + out__.write(log_lik); + out__.write(p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(mu, in__.read>(Nloc), + "assigning variable mu"); + out__.write_free_lb(0, mu); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 2; + beta = in__.read(); + out__.write_free_lb(0, beta); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = in__.read(); + out__.write_free_ub(0, log_p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "mu", "double", + std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "beta", "double", + std::vector{}); + current_statement__ = 3; + context__.validate_dims("parameter initialization", "log_p10", + "double", std::vector{}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu = context__.vals_r("mu"); + out__.write_free_lb(0, mu); + local_scalar_t__ beta = DUMMY_VAR__; + current_statement__ = 2; + beta = context__.vals_r("beta")[(1 - 1)]; + out__.write_free_lb(0, beta); + local_scalar_t__ log_p10 = DUMMY_VAR__; + current_statement__ = 3; + log_p10 = context__.vals_r("log_p10")[(1 - 1)]; + out__.write_free_ub(0, log_p10); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"mu", "beta", "log_p10"}; + if (emit_transformed_parameters__) { + std::vector temp{"p11", "p"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"log_lik", "p10"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{}, std::vector{}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(Nloc)}, + std::vector{static_cast(Nloc)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(log_lik_1dim__)}, + std::vector{}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "beta"); + param_names__.emplace_back(std::string() + "log_p10"); + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "beta"); + param_names__.emplace_back(std::string() + "log_p10"); + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p11" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "p" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= log_lik_1dim__; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "p10"); + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_p10\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"p11\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"p\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(log_lik_1dim__) + "},\"block\":\"generated_quantities\"},{\"name\":\"p10\",\"type\":{\"name\":\"real\"},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((Nloc + 1) + 1); + const size_t num_transformed = emit_transformed_parameters * ((Nloc + + Nloc)); + const size_t num_gen_quantities = emit_generated_quantities * + ((log_lik_1dim__ + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((Nloc + 1) + 1); + const size_t num_transformed = emit_transformed_parameters * ((Nloc + + Nloc)); + const size_t num_gen_quantities = emit_generated_quantities * + ((log_lik_1dim__ + 1)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_joint_binary_pois_namespace::model_joint_binary_pois; +#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_joint_binary_pois_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_traditional_catchability_gamma.h b/src/stanExports_traditional_catchability_gamma.h index a8383f8..f76fe22 100644 --- a/src/stanExports_traditional_catchability_gamma.h +++ b/src/stanExports_traditional_catchability_gamma.h @@ -1,782 +1,782 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_traditional_catchability_gamma_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'traditional_catchability_gamma', line 10, column 4 to column 36)", - " (in 'traditional_catchability_gamma', line 11, column 4 to column 39)", - " (in 'traditional_catchability_gamma', line 12, column 4 to column 44)", - " (in 'traditional_catchability_gamma', line 15, column 4 to column 28)", - " (in 'traditional_catchability_gamma', line 16, column 4 to column 35)", - " (in 'traditional_catchability_gamma', line 32, column 2 to column 20)", - " (in 'traditional_catchability_gamma', line 33, column 2 to column 20)", - " (in 'traditional_catchability_gamma', line 34, column 2 to column 28)", - " (in 'traditional_catchability_gamma', line 18, column 6 to column 48)", - " (in 'traditional_catchability_gamma', line 17, column 17 to line 19, column 5)", - " (in 'traditional_catchability_gamma', line 17, column 4 to line 19, column 5)", - " (in 'traditional_catchability_gamma', line 21, column 6 to column 42)", - " (in 'traditional_catchability_gamma', line 20, column 17 to line 22, column 5)", - " (in 'traditional_catchability_gamma', line 20, column 4 to line 22, column 5)", - " (in 'traditional_catchability_gamma', line 35, column 2 to column 18)", - " (in 'traditional_catchability_gamma', line 37, column 4 to column 31)", - " (in 'traditional_catchability_gamma', line 36, column 18 to line 38, column 3)", - " (in 'traditional_catchability_gamma', line 36, column 2 to line 38, column 3)", - " (in 'traditional_catchability_gamma', line 40, column 4 to column 38)", - " (in 'traditional_catchability_gamma', line 39, column 21 to line 41, column 3)", - " (in 'traditional_catchability_gamma', line 39, column 2 to line 41, column 3)", - " (in 'traditional_catchability_gamma', line 43, column 10 to column 80)", - " (in 'traditional_catchability_gamma', line 42, column 17 to line 44, column 7)", - " (in 'traditional_catchability_gamma', line 42, column 4 to line 44, column 7)", - " (in 'traditional_catchability_gamma', line 26, column 6 to column 57)", - " (in 'traditional_catchability_gamma', line 25, column 17 to line 27, column 5)", - " (in 'traditional_catchability_gamma', line 25, column 4 to line 27, column 5)", - " (in 'traditional_catchability_gamma', line 28, column 4 to column 28)", - " (in 'traditional_catchability_gamma', line 29, column 4 to column 29)", - " (in 'traditional_catchability_gamma', line 2, column 4 to column 19)", - " (in 'traditional_catchability_gamma', line 3, column 10 to column 11)", - " (in 'traditional_catchability_gamma', line 3, column 4 to column 28)", - " (in 'traditional_catchability_gamma', line 4, column 4 to column 22)", - " (in 'traditional_catchability_gamma', line 5, column 10 to column 11)", - " (in 'traditional_catchability_gamma', line 5, column 4 to column 29)", - " (in 'traditional_catchability_gamma', line 6, column 4 to column 25)", - " (in 'traditional_catchability_gamma', line 7, column 11 to column 12)", - " (in 'traditional_catchability_gamma', line 7, column 13 to column 20)", - " (in 'traditional_catchability_gamma', line 7, column 4 to column 26)", - " (in 'traditional_catchability_gamma', line 10, column 10 to column 14)", - " (in 'traditional_catchability_gamma', line 11, column 10 to column 14)", - " (in 'traditional_catchability_gamma', line 12, column 27 to column 34)", - " (in 'traditional_catchability_gamma', line 15, column 20 to column 21)", - " (in 'traditional_catchability_gamma', line 16, column 10 to column 11)", - " (in 'traditional_catchability_gamma', line 32, column 9 to column 16)", - " (in 'traditional_catchability_gamma', line 33, column 9 to column 10)", - " (in 'traditional_catchability_gamma', line 34, column 9 to column 13)", - " (in 'traditional_catchability_gamma', line 34, column 14 to column 23)"}; -#include -class model_traditional_catchability_gamma final : public model_base_crtp { -private: - int C; - std::vector R; - int Nloc; - std::vector E; - int nparams; - Eigen::Matrix mat_data__; - int mu_2dim__; - Eigen::Map> mat{nullptr, 0, 0}; -public: - ~model_traditional_catchability_gamma() {} - model_traditional_catchability_gamma(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_traditional_catchability_gamma_namespace::model_traditional_catchability_gamma"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 30; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 30; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 30; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 31; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 32; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 32; - R = context__.vals_i("R"); - current_statement__ = 32; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 33; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 33; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 33; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 34; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 35; - context__.validate_dims("data initialization", "E", "double", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::quiet_NaN()); - current_statement__ = 35; - E = context__.vals_r("E"); - current_statement__ = 35; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 36; - context__.validate_dims("data initialization", "nparams", "int", - std::vector{}); - nparams = std::numeric_limits::min(); - current_statement__ = 36; - nparams = context__.vals_i("nparams")[(1 - 1)]; - current_statement__ = 36; - stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); - current_statement__ = 37; - stan::math::validate_non_negative_index("mat", "C", C); - current_statement__ = 38; - stan::math::validate_non_negative_index("mat", "nparams", nparams); - current_statement__ = 39; - context__.validate_dims("data initialization", "mat", "double", - std::vector{static_cast(C), - static_cast(nparams)}); - mat_data__ = Eigen::Matrix::Constant(C, nparams, - std::numeric_limits::quiet_NaN()); - new (&mat) Eigen::Map>(mat_data__.data(), - C, nparams); - { - std::vector mat_flat__; - current_statement__ = 39; - mat_flat__ = context__.vals_r("mat"); - current_statement__ = 39; - pos__ = 1; - current_statement__ = 39; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 39; - for (int sym2__ = 1; sym2__ <= C; ++sym2__) { - current_statement__ = 39; - stan::model::assign(mat, mat_flat__[(pos__ - 1)], - "assigning variable mat", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 39; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 40; - stan::math::validate_non_negative_index("alpha", "Nloc", Nloc); - current_statement__ = 41; - stan::math::validate_non_negative_index("beta", "Nloc", Nloc); - current_statement__ = 42; - stan::math::validate_non_negative_index("q_trans", "nparams", nparams); - current_statement__ = 43; - stan::math::validate_non_negative_index("coef", "C", C); - current_statement__ = 44; - stan::math::validate_non_negative_index("E_trans", "C", C); - current_statement__ = 45; - stan::math::validate_non_negative_index("q", "nparams", nparams); - current_statement__ = 46; - stan::math::validate_non_negative_index("log_lik", "C", C); - current_statement__ = 47; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 48; - mu_2dim__ = std::numeric_limits::min(); - current_statement__ = 48; - mu_2dim__ = (nparams + 1); - current_statement__ = 48; - stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + Nloc + nparams; - } - inline std::string model_name() const final { - return "model_traditional_catchability_gamma"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_traditional_catchability_gamma_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector alpha = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - alpha = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - std::vector beta = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - beta = in__.template read_constrain_lb, - jacobian__>(0.01, lp__, Nloc); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 3; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, DUMMY_VAR__); - std::vector E_trans = - std::vector(C, DUMMY_VAR__); - current_statement__ = 11; - for (int i = 1; i <= C; ++i) { - current_statement__ = 9; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(i)), - q_trans)), "assigning variable coef", stan::model::index_uni(i)); - } - current_statement__ = 14; - for (int j = 1; j <= C; ++j) { - current_statement__ = 12; - stan::model::assign(E_trans, - (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + - 0.0000000000001), "assigning variable E_trans", - stan::model::index_uni(j)); - } - current_statement__ = 4; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); - { - current_statement__ = 27; - for (int j = 1; j <= C; ++j) { - current_statement__ = 25; - lp_accum__.add(stan::math::gamma_lpdf( - stan::model::rvalue(E_trans, "E_trans", - stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", - stan::model::index_uni(j)) * - stan::model::rvalue(alpha, "alpha", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j))))), - stan::model::rvalue(beta, "beta", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))))); - } - current_statement__ = 28; - lp_accum__.add(stan::math::gamma_lpdf(beta, 0.25, 0.25)); - current_statement__ = 29; - lp_accum__.add(stan::math::gamma_lpdf(alpha, 0.01, 0.01)); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_traditional_catchability_gamma_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector alpha = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - alpha = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - std::vector beta = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 2; - beta = in__.template read_constrain_lb, - jacobian__>(0.01, lp__, Nloc); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - current_statement__ = 3; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - std::vector E_trans = - std::vector(C, std::numeric_limits::quiet_NaN()); - out__.write(alpha); - out__.write(beta); - out__.write(q_trans); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 11; - for (int i = 1; i <= C; ++i) { - current_statement__ = 9; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(i)), - q_trans)), "assigning variable coef", stan::model::index_uni(i)); - } - current_statement__ = 14; - for (int j = 1; j <= C; ++j) { - current_statement__ = 12; - stan::model::assign(E_trans, - (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + - 0.0000000000001), "assigning variable E_trans", - stan::model::index_uni(j)); - } - current_statement__ = 4; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - current_statement__ = 5; - stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); - if (emit_transformed_parameters__) { - out__.write(coef); - out__.write(E_trans); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix q = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix mu = - Eigen::Matrix::Constant(Nloc, mu_2dim__, - std::numeric_limits::quiet_NaN()); - current_statement__ = 15; - stan::model::assign(q, stan::math::add(q_trans, 1), - "assigning variable q"); - current_statement__ = 18; - for (int j = 1; j <= Nloc; ++j) { - current_statement__ = 16; - stan::model::assign(mu, - (stan::model::rvalue(alpha, "alpha", stan::model::index_uni(j)) / - stan::model::rvalue(beta, "beta", stan::model::index_uni(j))), - "assigning variable mu", stan::model::index_uni(j), - stan::model::index_uni(1)); - } - current_statement__ = 21; - for (int i = 1; i <= nparams; ++i) { - current_statement__ = 19; - stan::model::assign(mu, - stan::math::multiply( - stan::math::to_vector( - stan::model::deep_copy( - stan::model::rvalue(mu, "mu", stan::model::index_omni(), - stan::model::index_uni(1)))), - stan::model::rvalue(q, "q", stan::model::index_uni(i))), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni((i + 1))); - } - current_statement__ = 24; - for (int j = 1; j <= C; ++j) { - current_statement__ = 22; - stan::model::assign(log_lik, - stan::math::gamma_lpdf( - stan::model::rvalue(E_trans, "E_trans", stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * - stan::model::rvalue(alpha, "alpha", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - stan::model::rvalue(beta, "beta", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - "assigning variable log_lik", stan::model::index_uni(j)); - } - out__.write(q); - out__.write(log_lik); - out__.write(mu); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector alpha = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(alpha, - in__.read>(Nloc), - "assigning variable alpha"); - out__.write_free_lb(0, alpha); - std::vector beta = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - stan::model::assign(beta, - in__.read>(Nloc), - "assigning variable beta"); - out__.write_free_lb(0.01, beta); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 3; - stan::model::assign(q_trans, - in__.read>(nparams), - "assigning variable q_trans"); - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "alpha", "double", - std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "beta", "double", - std::vector{static_cast(Nloc)}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "q_trans", - "double", std::vector{static_cast(nparams)}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector alpha = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - alpha = context__.vals_r("alpha"); - out__.write_free_lb(0, alpha); - std::vector beta = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - beta = context__.vals_r("beta"); - out__.write_free_lb(0.01, beta); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - { - std::vector q_trans_flat__; - current_statement__ = 3; - q_trans_flat__ = context__.vals_r("q_trans"); - current_statement__ = 3; - pos__ = 1; - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 3; - stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], - "assigning variable q_trans", stan::model::index_uni(sym1__)); - current_statement__ = 3; - pos__ = (pos__ + 1); - } - } - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"alpha", "beta", "q_trans"}; - if (emit_transformed_parameters__) { - std::vector temp{"coef", "E_trans"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"q", "log_lik", "mu"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{static_cast(Nloc)}, - std::vector{static_cast(nparams)}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(C)}, - std::vector{static_cast(C)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(nparams)}, - std::vector{static_cast(C)}, - std::vector{static_cast(Nloc), - static_cast(mu_2dim__)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "E_trans" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "E_trans" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"alpha\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"alpha\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((Nloc + Nloc) + nparams); - const size_t num_transformed = emit_transformed_parameters * ((C + C)); - const size_t num_gen_quantities = emit_generated_quantities * (((nparams - + C) + (Nloc * mu_2dim__))); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((Nloc + Nloc) + nparams); - const size_t num_transformed = emit_transformed_parameters * ((C + C)); - const size_t num_gen_quantities = emit_generated_quantities * (((nparams - + C) + (Nloc * mu_2dim__))); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_traditional_catchability_gamma_namespace::model_traditional_catchability_gamma; -#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_traditional_catchability_gamma_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_traditional_catchability_gamma_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 10, column 4 to column 36)", + " (in 'string', line 11, column 4 to column 39)", + " (in 'string', line 12, column 4 to column 44)", + " (in 'string', line 15, column 4 to column 28)", + " (in 'string', line 16, column 4 to column 35)", + " (in 'string', line 32, column 2 to column 20)", + " (in 'string', line 33, column 2 to column 20)", + " (in 'string', line 34, column 2 to column 28)", + " (in 'string', line 18, column 6 to column 48)", + " (in 'string', line 17, column 17 to line 19, column 5)", + " (in 'string', line 17, column 4 to line 19, column 5)", + " (in 'string', line 21, column 6 to column 42)", + " (in 'string', line 20, column 17 to line 22, column 5)", + " (in 'string', line 20, column 4 to line 22, column 5)", + " (in 'string', line 35, column 2 to column 18)", + " (in 'string', line 37, column 4 to column 31)", + " (in 'string', line 36, column 18 to line 38, column 3)", + " (in 'string', line 36, column 2 to line 38, column 3)", + " (in 'string', line 40, column 4 to column 38)", + " (in 'string', line 39, column 21 to line 41, column 3)", + " (in 'string', line 39, column 2 to line 41, column 3)", + " (in 'string', line 43, column 10 to column 80)", + " (in 'string', line 42, column 17 to line 44, column 7)", + " (in 'string', line 42, column 4 to line 44, column 7)", + " (in 'string', line 26, column 6 to column 57)", + " (in 'string', line 25, column 17 to line 27, column 5)", + " (in 'string', line 25, column 4 to line 27, column 5)", + " (in 'string', line 28, column 4 to column 28)", + " (in 'string', line 29, column 4 to column 29)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 10 to column 11)", + " (in 'string', line 3, column 4 to column 28)", + " (in 'string', line 4, column 4 to column 22)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 29)", + " (in 'string', line 6, column 4 to column 25)", + " (in 'string', line 7, column 11 to column 12)", + " (in 'string', line 7, column 13 to column 20)", + " (in 'string', line 7, column 4 to column 26)", + " (in 'string', line 10, column 10 to column 14)", + " (in 'string', line 11, column 10 to column 14)", + " (in 'string', line 12, column 27 to column 34)", + " (in 'string', line 15, column 20 to column 21)", + " (in 'string', line 16, column 10 to column 11)", + " (in 'string', line 32, column 9 to column 16)", + " (in 'string', line 33, column 9 to column 10)", + " (in 'string', line 34, column 9 to column 13)", + " (in 'string', line 34, column 14 to column 23)"}; +#include +class model_traditional_catchability_gamma final : public model_base_crtp { +private: + int C; + std::vector R; + int Nloc; + std::vector E; + int nparams; + Eigen::Matrix mat_data__; + int mu_2dim__; + Eigen::Map> mat{nullptr, 0, 0}; +public: + ~model_traditional_catchability_gamma() {} + model_traditional_catchability_gamma(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_traditional_catchability_gamma_namespace::model_traditional_catchability_gamma"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 30; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 30; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 30; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 31; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 32; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 32; + R = context__.vals_i("R"); + current_statement__ = 32; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 33; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 33; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 33; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 34; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 35; + context__.validate_dims("data initialization", "E", "double", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::quiet_NaN()); + current_statement__ = 35; + E = context__.vals_r("E"); + current_statement__ = 35; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 36; + context__.validate_dims("data initialization", "nparams", "int", + std::vector{}); + nparams = std::numeric_limits::min(); + current_statement__ = 36; + nparams = context__.vals_i("nparams")[(1 - 1)]; + current_statement__ = 36; + stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); + current_statement__ = 37; + stan::math::validate_non_negative_index("mat", "C", C); + current_statement__ = 38; + stan::math::validate_non_negative_index("mat", "nparams", nparams); + current_statement__ = 39; + context__.validate_dims("data initialization", "mat", "double", + std::vector{static_cast(C), + static_cast(nparams)}); + mat_data__ = Eigen::Matrix::Constant(C, nparams, + std::numeric_limits::quiet_NaN()); + new (&mat) Eigen::Map>(mat_data__.data(), + C, nparams); + { + std::vector mat_flat__; + current_statement__ = 39; + mat_flat__ = context__.vals_r("mat"); + current_statement__ = 39; + pos__ = 1; + current_statement__ = 39; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 39; + for (int sym2__ = 1; sym2__ <= C; ++sym2__) { + current_statement__ = 39; + stan::model::assign(mat, mat_flat__[(pos__ - 1)], + "assigning variable mat", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 39; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 40; + stan::math::validate_non_negative_index("alpha", "Nloc", Nloc); + current_statement__ = 41; + stan::math::validate_non_negative_index("beta", "Nloc", Nloc); + current_statement__ = 42; + stan::math::validate_non_negative_index("q_trans", "nparams", nparams); + current_statement__ = 43; + stan::math::validate_non_negative_index("coef", "C", C); + current_statement__ = 44; + stan::math::validate_non_negative_index("E_trans", "C", C); + current_statement__ = 45; + stan::math::validate_non_negative_index("q", "nparams", nparams); + current_statement__ = 46; + stan::math::validate_non_negative_index("log_lik", "C", C); + current_statement__ = 47; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 48; + mu_2dim__ = std::numeric_limits::min(); + current_statement__ = 48; + mu_2dim__ = (nparams + 1); + current_statement__ = 48; + stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + Nloc + nparams; + } + inline std::string model_name() const final { + return "model_traditional_catchability_gamma"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_traditional_catchability_gamma_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector alpha = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + alpha = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + std::vector beta = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + beta = in__.template read_constrain_lb, + jacobian__>(0.01, lp__, Nloc); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 3; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, DUMMY_VAR__); + std::vector E_trans = + std::vector(C, DUMMY_VAR__); + current_statement__ = 11; + for (int i = 1; i <= C; ++i) { + current_statement__ = 9; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(i)), + q_trans)), "assigning variable coef", stan::model::index_uni(i)); + } + current_statement__ = 14; + for (int j = 1; j <= C; ++j) { + current_statement__ = 12; + stan::model::assign(E_trans, + (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + + 0.0000000000001), "assigning variable E_trans", + stan::model::index_uni(j)); + } + current_statement__ = 4; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); + { + current_statement__ = 27; + for (int j = 1; j <= C; ++j) { + current_statement__ = 25; + lp_accum__.add(stan::math::gamma_lpdf( + stan::model::rvalue(E_trans, "E_trans", + stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", + stan::model::index_uni(j)) * + stan::model::rvalue(alpha, "alpha", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j))))), + stan::model::rvalue(beta, "beta", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))))); + } + current_statement__ = 28; + lp_accum__.add(stan::math::gamma_lpdf(beta, 0.25, 0.25)); + current_statement__ = 29; + lp_accum__.add(stan::math::gamma_lpdf(alpha, 0.01, 0.01)); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_traditional_catchability_gamma_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector alpha = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + alpha = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + std::vector beta = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 2; + beta = in__.template read_constrain_lb, + jacobian__>(0.01, lp__, Nloc); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + current_statement__ = 3; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + std::vector E_trans = + std::vector(C, std::numeric_limits::quiet_NaN()); + out__.write(alpha); + out__.write(beta); + out__.write(q_trans); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 11; + for (int i = 1; i <= C; ++i) { + current_statement__ = 9; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(i)), + q_trans)), "assigning variable coef", stan::model::index_uni(i)); + } + current_statement__ = 14; + for (int j = 1; j <= C; ++j) { + current_statement__ = 12; + stan::model::assign(E_trans, + (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + + 0.0000000000001), "assigning variable E_trans", + stan::model::index_uni(j)); + } + current_statement__ = 4; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + current_statement__ = 5; + stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); + if (emit_transformed_parameters__) { + out__.write(coef); + out__.write(E_trans); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix q = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix mu = + Eigen::Matrix::Constant(Nloc, mu_2dim__, + std::numeric_limits::quiet_NaN()); + current_statement__ = 15; + stan::model::assign(q, stan::math::add(q_trans, 1), + "assigning variable q"); + current_statement__ = 18; + for (int j = 1; j <= Nloc; ++j) { + current_statement__ = 16; + stan::model::assign(mu, + (stan::model::rvalue(alpha, "alpha", stan::model::index_uni(j)) / + stan::model::rvalue(beta, "beta", stan::model::index_uni(j))), + "assigning variable mu", stan::model::index_uni(j), + stan::model::index_uni(1)); + } + current_statement__ = 21; + for (int i = 1; i <= nparams; ++i) { + current_statement__ = 19; + stan::model::assign(mu, + stan::math::multiply( + stan::math::to_vector( + stan::model::deep_copy( + stan::model::rvalue(mu, "mu", stan::model::index_omni(), + stan::model::index_uni(1)))), + stan::model::rvalue(q, "q", stan::model::index_uni(i))), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni((i + 1))); + } + current_statement__ = 24; + for (int j = 1; j <= C; ++j) { + current_statement__ = 22; + stan::model::assign(log_lik, + stan::math::gamma_lpdf( + stan::model::rvalue(E_trans, "E_trans", stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * + stan::model::rvalue(alpha, "alpha", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + stan::model::rvalue(beta, "beta", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + "assigning variable log_lik", stan::model::index_uni(j)); + } + out__.write(q); + out__.write(log_lik); + out__.write(mu); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector alpha = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(alpha, + in__.read>(Nloc), + "assigning variable alpha"); + out__.write_free_lb(0, alpha); + std::vector beta = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + stan::model::assign(beta, + in__.read>(Nloc), + "assigning variable beta"); + out__.write_free_lb(0.01, beta); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 3; + stan::model::assign(q_trans, + in__.read>(nparams), + "assigning variable q_trans"); + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "alpha", "double", + std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "beta", "double", + std::vector{static_cast(Nloc)}); + current_statement__ = 3; + context__.validate_dims("parameter initialization", "q_trans", + "double", std::vector{static_cast(nparams)}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector alpha = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + alpha = context__.vals_r("alpha"); + out__.write_free_lb(0, alpha); + std::vector beta = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + beta = context__.vals_r("beta"); + out__.write_free_lb(0.01, beta); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + { + std::vector q_trans_flat__; + current_statement__ = 3; + q_trans_flat__ = context__.vals_r("q_trans"); + current_statement__ = 3; + pos__ = 1; + current_statement__ = 3; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 3; + stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], + "assigning variable q_trans", stan::model::index_uni(sym1__)); + current_statement__ = 3; + pos__ = (pos__ + 1); + } + } + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"alpha", "beta", "q_trans"}; + if (emit_transformed_parameters__) { + std::vector temp{"coef", "E_trans"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"q", "log_lik", "mu"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{static_cast(Nloc)}, + std::vector{static_cast(nparams)}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(C)}, + std::vector{static_cast(C)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(nparams)}, + std::vector{static_cast(C)}, + std::vector{static_cast(Nloc), + static_cast(mu_2dim__)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "E_trans" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "E_trans" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"alpha\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"alpha\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((Nloc + Nloc) + nparams); + const size_t num_transformed = emit_transformed_parameters * ((C + C)); + const size_t num_gen_quantities = emit_generated_quantities * (((nparams + + C) + (Nloc * mu_2dim__))); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((Nloc + Nloc) + nparams); + const size_t num_transformed = emit_transformed_parameters * ((C + C)); + const size_t num_gen_quantities = emit_generated_quantities * (((nparams + + C) + (Nloc * mu_2dim__))); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_traditional_catchability_gamma_namespace::model_traditional_catchability_gamma; +#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_traditional_catchability_gamma_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_traditional_catchability_negbin.h b/src/stanExports_traditional_catchability_negbin.h index bb92172..deab015 100644 --- a/src/stanExports_traditional_catchability_negbin.h +++ b/src/stanExports_traditional_catchability_negbin.h @@ -1,718 +1,718 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_traditional_catchability_negbin_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'traditional_catchability_negbin', line 11, column 4 to column 35)", - " (in 'traditional_catchability_negbin', line 12, column 4 to column 22)", - " (in 'traditional_catchability_negbin', line 13, column 4 to column 44)", - " (in 'traditional_catchability_negbin', line 16, column 4 to column 28)", - " (in 'traditional_catchability_negbin', line 28, column 2 to column 20)", - " (in 'traditional_catchability_negbin', line 29, column 2 to column 20)", - " (in 'traditional_catchability_negbin', line 30, column 2 to column 28)", - " (in 'traditional_catchability_negbin', line 18, column 6 to column 48)", - " (in 'traditional_catchability_negbin', line 17, column 17 to line 19, column 5)", - " (in 'traditional_catchability_negbin', line 17, column 4 to line 19, column 5)", - " (in 'traditional_catchability_negbin', line 31, column 2 to column 18)", - " (in 'traditional_catchability_negbin', line 32, column 2 to column 27)", - " (in 'traditional_catchability_negbin', line 34, column 4 to column 36)", - " (in 'traditional_catchability_negbin', line 33, column 21 to line 35, column 3)", - " (in 'traditional_catchability_negbin', line 33, column 2 to line 35, column 3)", - " (in 'traditional_catchability_negbin', line 37, column 10 to column 75)", - " (in 'traditional_catchability_negbin', line 36, column 17 to line 38, column 7)", - " (in 'traditional_catchability_negbin', line 36, column 4 to line 38, column 7)", - " (in 'traditional_catchability_negbin', line 23, column 6 to column 52)", - " (in 'traditional_catchability_negbin', line 22, column 17 to line 24, column 5)", - " (in 'traditional_catchability_negbin', line 22, column 4 to line 24, column 5)", - " (in 'traditional_catchability_negbin', line 25, column 4 to column 44)", - " (in 'traditional_catchability_negbin', line 2, column 4 to column 19)", - " (in 'traditional_catchability_negbin', line 3, column 10 to column 11)", - " (in 'traditional_catchability_negbin', line 3, column 4 to column 28)", - " (in 'traditional_catchability_negbin', line 4, column 4 to column 22)", - " (in 'traditional_catchability_negbin', line 5, column 10 to column 11)", - " (in 'traditional_catchability_negbin', line 5, column 4 to column 28)", - " (in 'traditional_catchability_negbin', line 6, column 4 to column 25)", - " (in 'traditional_catchability_negbin', line 7, column 11 to column 12)", - " (in 'traditional_catchability_negbin', line 7, column 13 to column 20)", - " (in 'traditional_catchability_negbin', line 7, column 4 to column 26)", - " (in 'traditional_catchability_negbin', line 8, column 4 to column 28)", - " (in 'traditional_catchability_negbin', line 11, column 10 to column 14)", - " (in 'traditional_catchability_negbin', line 13, column 27 to column 34)", - " (in 'traditional_catchability_negbin', line 16, column 20 to column 21)", - " (in 'traditional_catchability_negbin', line 28, column 9 to column 16)", - " (in 'traditional_catchability_negbin', line 29, column 9 to column 10)", - " (in 'traditional_catchability_negbin', line 30, column 9 to column 13)", - " (in 'traditional_catchability_negbin', line 30, column 14 to column 23)"}; -#include -class model_traditional_catchability_negbin final : public model_base_crtp { -private: - int C; - std::vector R; - int Nloc; - std::vector E; - int nparams; - Eigen::Matrix mat_data__; - std::vector phipriors; - int mu_2dim__; - Eigen::Map> mat{nullptr, 0, 0}; -public: - ~model_traditional_catchability_negbin() {} - model_traditional_catchability_negbin(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_traditional_catchability_negbin_namespace::model_traditional_catchability_negbin"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 23; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 23; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 23; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 24; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 25; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 25; - R = context__.vals_i("R"); - current_statement__ = 25; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 26; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 26; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 26; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 27; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 28; - context__.validate_dims("data initialization", "E", "int", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::min()); - current_statement__ = 28; - E = context__.vals_i("E"); - current_statement__ = 28; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 29; - context__.validate_dims("data initialization", "nparams", "int", - std::vector{}); - nparams = std::numeric_limits::min(); - current_statement__ = 29; - nparams = context__.vals_i("nparams")[(1 - 1)]; - current_statement__ = 29; - stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); - current_statement__ = 30; - stan::math::validate_non_negative_index("mat", "C", C); - current_statement__ = 31; - stan::math::validate_non_negative_index("mat", "nparams", nparams); - current_statement__ = 32; - context__.validate_dims("data initialization", "mat", "double", - std::vector{static_cast(C), - static_cast(nparams)}); - mat_data__ = Eigen::Matrix::Constant(C, nparams, - std::numeric_limits::quiet_NaN()); - new (&mat) Eigen::Map>(mat_data__.data(), - C, nparams); - { - std::vector mat_flat__; - current_statement__ = 32; - mat_flat__ = context__.vals_r("mat"); - current_statement__ = 32; - pos__ = 1; - current_statement__ = 32; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 32; - for (int sym2__ = 1; sym2__ <= C; ++sym2__) { - current_statement__ = 32; - stan::model::assign(mat, mat_flat__[(pos__ - 1)], - "assigning variable mat", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 32; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 33; - context__.validate_dims("data initialization", "phipriors", "double", - std::vector{static_cast(2)}); - phipriors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 33; - phipriors = context__.vals_r("phipriors"); - current_statement__ = 34; - stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); - current_statement__ = 35; - stan::math::validate_non_negative_index("q_trans", "nparams", nparams); - current_statement__ = 36; - stan::math::validate_non_negative_index("coef", "C", C); - current_statement__ = 37; - stan::math::validate_non_negative_index("q", "nparams", nparams); - current_statement__ = 38; - stan::math::validate_non_negative_index("log_lik", "C", C); - current_statement__ = 39; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 40; - mu_2dim__ = std::numeric_limits::min(); - current_statement__ = 40; - mu_2dim__ = (nparams + 1); - current_statement__ = 40; - stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + 1 + nparams; - } - inline std::string model_name() const final { - return "model_traditional_catchability_negbin"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_traditional_catchability_negbin_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu_1 = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = in__.template read_constrain_lb(0, - lp__); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 3; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, DUMMY_VAR__); - current_statement__ = 10; - for (int i = 1; i <= C; ++i) { - current_statement__ = 8; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(i)), - q_trans)), "assigning variable coef", stan::model::index_uni(i)); - } - current_statement__ = 4; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - { - current_statement__ = 21; - for (int j = 1; j <= C; ++j) { - current_statement__ = 19; - lp_accum__.add(stan::math::neg_binomial_2_lpmf( - stan::model::rvalue(E, "E", - stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", - stan::model::index_uni(j)) * - stan::model::rvalue(mu_1, "mu_1", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j))))), phi)); - } - current_statement__ = 22; - lp_accum__.add(stan::math::gamma_lpdf(phi, - stan::model::rvalue(phipriors, "phipriors", - stan::model::index_uni(1)), - stan::model::rvalue(phipriors, "phipriors", - stan::model::index_uni(2)))); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_traditional_catchability_negbin_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector mu_1 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - mu_1 = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - double phi = std::numeric_limits::quiet_NaN(); - current_statement__ = 2; - phi = in__.template read_constrain_lb(0, - lp__); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - current_statement__ = 3; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - out__.write(mu_1); - out__.write(phi); - out__.write(q_trans); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 10; - for (int i = 1; i <= C; ++i) { - current_statement__ = 8; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(i)), - q_trans)), "assigning variable coef", stan::model::index_uni(i)); - } - current_statement__ = 4; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - if (emit_transformed_parameters__) { - out__.write(coef); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix q = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix mu = - Eigen::Matrix::Constant(Nloc, mu_2dim__, - std::numeric_limits::quiet_NaN()); - current_statement__ = 11; - stan::model::assign(q, stan::math::add(q_trans, 1), - "assigning variable q"); - current_statement__ = 12; - stan::model::assign(mu, stan::math::to_vector(mu_1), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni(1)); - current_statement__ = 15; - for (int i = 1; i <= nparams; ++i) { - current_statement__ = 13; - stan::model::assign(mu, - stan::math::multiply(stan::math::to_vector(mu_1), - stan::model::rvalue(q, "q", stan::model::index_uni(i))), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni((i + 1))); - } - current_statement__ = 18; - for (int j = 1; j <= C; ++j) { - current_statement__ = 16; - stan::model::assign(log_lik, - stan::math::neg_binomial_2_lpmf( - stan::model::rvalue(E, "E", stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * - stan::model::rvalue(mu_1, "mu_1", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - phi), "assigning variable log_lik", stan::model::index_uni(j)); - } - out__.write(q); - out__.write(log_lik); - out__.write(mu); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(mu_1, - in__.read>(Nloc), - "assigning variable mu_1"); - out__.write_free_lb(0, mu_1); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = in__.read(); - out__.write_free_lb(0, phi); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 3; - stan::model::assign(q_trans, - in__.read>(nparams), - "assigning variable q_trans"); - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "mu_1", "double", - std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "phi", "double", - std::vector{}); - current_statement__ = 3; - context__.validate_dims("parameter initialization", "q_trans", - "double", std::vector{static_cast(nparams)}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu_1 = context__.vals_r("mu_1"); - out__.write_free_lb(0, mu_1); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = context__.vals_r("phi")[(1 - 1)]; - out__.write_free_lb(0, phi); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - { - std::vector q_trans_flat__; - current_statement__ = 3; - q_trans_flat__ = context__.vals_r("q_trans"); - current_statement__ = 3; - pos__ = 1; - current_statement__ = 3; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 3; - stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], - "assigning variable q_trans", stan::model::index_uni(sym1__)); - current_statement__ = 3; - pos__ = (pos__ + 1); - } - } - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"mu_1", "phi", "q_trans"}; - if (emit_transformed_parameters__) { - std::vector temp{"coef"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"q", "log_lik", "mu"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{}, - std::vector{static_cast(nparams)}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(C)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(nparams)}, - std::vector{static_cast(C)}, - std::vector{static_cast(Nloc), - static_cast(mu_2dim__)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "phi"); - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "phi"); - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((Nloc + 1) + nparams); - const size_t num_transformed = emit_transformed_parameters * (C); - const size_t num_gen_quantities = emit_generated_quantities * (((nparams - + C) + (Nloc * mu_2dim__))); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = ((Nloc + 1) + nparams); - const size_t num_transformed = emit_transformed_parameters * (C); - const size_t num_gen_quantities = emit_generated_quantities * (((nparams - + C) + (Nloc * mu_2dim__))); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_traditional_catchability_negbin_namespace::model_traditional_catchability_negbin; -#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_traditional_catchability_negbin_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_traditional_catchability_negbin_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 11, column 4 to column 35)", + " (in 'string', line 12, column 4 to column 22)", + " (in 'string', line 13, column 4 to column 44)", + " (in 'string', line 16, column 4 to column 28)", + " (in 'string', line 28, column 2 to column 20)", + " (in 'string', line 29, column 2 to column 20)", + " (in 'string', line 30, column 2 to column 28)", + " (in 'string', line 18, column 6 to column 48)", + " (in 'string', line 17, column 17 to line 19, column 5)", + " (in 'string', line 17, column 4 to line 19, column 5)", + " (in 'string', line 31, column 2 to column 18)", + " (in 'string', line 32, column 2 to column 27)", + " (in 'string', line 34, column 4 to column 36)", + " (in 'string', line 33, column 21 to line 35, column 3)", + " (in 'string', line 33, column 2 to line 35, column 3)", + " (in 'string', line 37, column 10 to column 75)", + " (in 'string', line 36, column 17 to line 38, column 7)", + " (in 'string', line 36, column 4 to line 38, column 7)", + " (in 'string', line 23, column 6 to column 52)", + " (in 'string', line 22, column 17 to line 24, column 5)", + " (in 'string', line 22, column 4 to line 24, column 5)", + " (in 'string', line 25, column 4 to column 44)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 10 to column 11)", + " (in 'string', line 3, column 4 to column 28)", + " (in 'string', line 4, column 4 to column 22)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 25)", + " (in 'string', line 7, column 11 to column 12)", + " (in 'string', line 7, column 13 to column 20)", + " (in 'string', line 7, column 4 to column 26)", + " (in 'string', line 8, column 4 to column 28)", + " (in 'string', line 11, column 10 to column 14)", + " (in 'string', line 13, column 27 to column 34)", + " (in 'string', line 16, column 20 to column 21)", + " (in 'string', line 28, column 9 to column 16)", + " (in 'string', line 29, column 9 to column 10)", + " (in 'string', line 30, column 9 to column 13)", + " (in 'string', line 30, column 14 to column 23)"}; +#include +class model_traditional_catchability_negbin final : public model_base_crtp { +private: + int C; + std::vector R; + int Nloc; + std::vector E; + int nparams; + Eigen::Matrix mat_data__; + std::vector phipriors; + int mu_2dim__; + Eigen::Map> mat{nullptr, 0, 0}; +public: + ~model_traditional_catchability_negbin() {} + model_traditional_catchability_negbin(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_traditional_catchability_negbin_namespace::model_traditional_catchability_negbin"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 23; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 23; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 23; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 24; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 25; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 25; + R = context__.vals_i("R"); + current_statement__ = 25; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 26; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 26; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 26; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 27; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 28; + context__.validate_dims("data initialization", "E", "int", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::min()); + current_statement__ = 28; + E = context__.vals_i("E"); + current_statement__ = 28; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 29; + context__.validate_dims("data initialization", "nparams", "int", + std::vector{}); + nparams = std::numeric_limits::min(); + current_statement__ = 29; + nparams = context__.vals_i("nparams")[(1 - 1)]; + current_statement__ = 29; + stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); + current_statement__ = 30; + stan::math::validate_non_negative_index("mat", "C", C); + current_statement__ = 31; + stan::math::validate_non_negative_index("mat", "nparams", nparams); + current_statement__ = 32; + context__.validate_dims("data initialization", "mat", "double", + std::vector{static_cast(C), + static_cast(nparams)}); + mat_data__ = Eigen::Matrix::Constant(C, nparams, + std::numeric_limits::quiet_NaN()); + new (&mat) Eigen::Map>(mat_data__.data(), + C, nparams); + { + std::vector mat_flat__; + current_statement__ = 32; + mat_flat__ = context__.vals_r("mat"); + current_statement__ = 32; + pos__ = 1; + current_statement__ = 32; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 32; + for (int sym2__ = 1; sym2__ <= C; ++sym2__) { + current_statement__ = 32; + stan::model::assign(mat, mat_flat__[(pos__ - 1)], + "assigning variable mat", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 32; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 33; + context__.validate_dims("data initialization", "phipriors", "double", + std::vector{static_cast(2)}); + phipriors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 33; + phipriors = context__.vals_r("phipriors"); + current_statement__ = 34; + stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); + current_statement__ = 35; + stan::math::validate_non_negative_index("q_trans", "nparams", nparams); + current_statement__ = 36; + stan::math::validate_non_negative_index("coef", "C", C); + current_statement__ = 37; + stan::math::validate_non_negative_index("q", "nparams", nparams); + current_statement__ = 38; + stan::math::validate_non_negative_index("log_lik", "C", C); + current_statement__ = 39; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 40; + mu_2dim__ = std::numeric_limits::min(); + current_statement__ = 40; + mu_2dim__ = (nparams + 1); + current_statement__ = 40; + stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + 1 + nparams; + } + inline std::string model_name() const final { + return "model_traditional_catchability_negbin"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_traditional_catchability_negbin_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu_1 = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = in__.template read_constrain_lb(0, + lp__); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 3; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, DUMMY_VAR__); + current_statement__ = 10; + for (int i = 1; i <= C; ++i) { + current_statement__ = 8; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(i)), + q_trans)), "assigning variable coef", stan::model::index_uni(i)); + } + current_statement__ = 4; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + { + current_statement__ = 21; + for (int j = 1; j <= C; ++j) { + current_statement__ = 19; + lp_accum__.add(stan::math::neg_binomial_2_lpmf( + stan::model::rvalue(E, "E", + stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", + stan::model::index_uni(j)) * + stan::model::rvalue(mu_1, "mu_1", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j))))), phi)); + } + current_statement__ = 22; + lp_accum__.add(stan::math::gamma_lpdf(phi, + stan::model::rvalue(phipriors, "phipriors", + stan::model::index_uni(1)), + stan::model::rvalue(phipriors, "phipriors", + stan::model::index_uni(2)))); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_traditional_catchability_negbin_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector mu_1 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + mu_1 = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + double phi = std::numeric_limits::quiet_NaN(); + current_statement__ = 2; + phi = in__.template read_constrain_lb(0, + lp__); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + current_statement__ = 3; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + out__.write(mu_1); + out__.write(phi); + out__.write(q_trans); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 10; + for (int i = 1; i <= C; ++i) { + current_statement__ = 8; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(i)), + q_trans)), "assigning variable coef", stan::model::index_uni(i)); + } + current_statement__ = 4; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + if (emit_transformed_parameters__) { + out__.write(coef); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix q = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix mu = + Eigen::Matrix::Constant(Nloc, mu_2dim__, + std::numeric_limits::quiet_NaN()); + current_statement__ = 11; + stan::model::assign(q, stan::math::add(q_trans, 1), + "assigning variable q"); + current_statement__ = 12; + stan::model::assign(mu, stan::math::to_vector(mu_1), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni(1)); + current_statement__ = 15; + for (int i = 1; i <= nparams; ++i) { + current_statement__ = 13; + stan::model::assign(mu, + stan::math::multiply(stan::math::to_vector(mu_1), + stan::model::rvalue(q, "q", stan::model::index_uni(i))), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni((i + 1))); + } + current_statement__ = 18; + for (int j = 1; j <= C; ++j) { + current_statement__ = 16; + stan::model::assign(log_lik, + stan::math::neg_binomial_2_lpmf( + stan::model::rvalue(E, "E", stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * + stan::model::rvalue(mu_1, "mu_1", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + phi), "assigning variable log_lik", stan::model::index_uni(j)); + } + out__.write(q); + out__.write(log_lik); + out__.write(mu); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(mu_1, + in__.read>(Nloc), + "assigning variable mu_1"); + out__.write_free_lb(0, mu_1); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = in__.read(); + out__.write_free_lb(0, phi); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 3; + stan::model::assign(q_trans, + in__.read>(nparams), + "assigning variable q_trans"); + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "mu_1", "double", + std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "phi", "double", + std::vector{}); + current_statement__ = 3; + context__.validate_dims("parameter initialization", "q_trans", + "double", std::vector{static_cast(nparams)}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu_1 = context__.vals_r("mu_1"); + out__.write_free_lb(0, mu_1); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = context__.vals_r("phi")[(1 - 1)]; + out__.write_free_lb(0, phi); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + { + std::vector q_trans_flat__; + current_statement__ = 3; + q_trans_flat__ = context__.vals_r("q_trans"); + current_statement__ = 3; + pos__ = 1; + current_statement__ = 3; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 3; + stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], + "assigning variable q_trans", stan::model::index_uni(sym1__)); + current_statement__ = 3; + pos__ = (pos__ + 1); + } + } + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"mu_1", "phi", "q_trans"}; + if (emit_transformed_parameters__) { + std::vector temp{"coef"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"q", "log_lik", "mu"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{}, + std::vector{static_cast(nparams)}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(C)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(nparams)}, + std::vector{static_cast(C)}, + std::vector{static_cast(Nloc), + static_cast(mu_2dim__)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "phi"); + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "phi"); + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((Nloc + 1) + nparams); + const size_t num_transformed = emit_transformed_parameters * (C); + const size_t num_gen_quantities = emit_generated_quantities * (((nparams + + C) + (Nloc * mu_2dim__))); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = ((Nloc + 1) + nparams); + const size_t num_transformed = emit_transformed_parameters * (C); + const size_t num_gen_quantities = emit_generated_quantities * (((nparams + + C) + (Nloc * mu_2dim__))); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_traditional_catchability_negbin_namespace::model_traditional_catchability_negbin; +#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_traditional_catchability_negbin_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_traditional_catchability_pois.h b/src/stanExports_traditional_catchability_pois.h index 5961371..33052b2 100644 --- a/src/stanExports_traditional_catchability_pois.h +++ b/src/stanExports_traditional_catchability_pois.h @@ -1,678 +1,678 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_traditional_catchability_pois_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'traditional_catchability_pois', line 10, column 4 to column 35)", - " (in 'traditional_catchability_pois', line 11, column 4 to column 44)", - " (in 'traditional_catchability_pois', line 14, column 4 to column 28)", - " (in 'traditional_catchability_pois', line 25, column 2 to column 20)", - " (in 'traditional_catchability_pois', line 26, column 2 to column 20)", - " (in 'traditional_catchability_pois', line 27, column 2 to column 28)", - " (in 'traditional_catchability_pois', line 16, column 6 to column 48)", - " (in 'traditional_catchability_pois', line 15, column 17 to line 17, column 5)", - " (in 'traditional_catchability_pois', line 15, column 4 to line 17, column 5)", - " (in 'traditional_catchability_pois', line 28, column 2 to column 18)", - " (in 'traditional_catchability_pois', line 29, column 2 to column 27)", - " (in 'traditional_catchability_pois', line 31, column 4 to column 36)", - " (in 'traditional_catchability_pois', line 30, column 21 to line 32, column 3)", - " (in 'traditional_catchability_pois', line 30, column 2 to line 32, column 3)", - " (in 'traditional_catchability_pois', line 34, column 10 to column 63)", - " (in 'traditional_catchability_pois', line 33, column 17 to line 35, column 7)", - " (in 'traditional_catchability_pois', line 33, column 4 to line 35, column 7)", - " (in 'traditional_catchability_pois', line 21, column 6 to column 41)", - " (in 'traditional_catchability_pois', line 20, column 17 to line 22, column 5)", - " (in 'traditional_catchability_pois', line 20, column 4 to line 22, column 5)", - " (in 'traditional_catchability_pois', line 2, column 4 to column 19)", - " (in 'traditional_catchability_pois', line 3, column 10 to column 11)", - " (in 'traditional_catchability_pois', line 3, column 4 to column 28)", - " (in 'traditional_catchability_pois', line 4, column 4 to column 22)", - " (in 'traditional_catchability_pois', line 5, column 10 to column 11)", - " (in 'traditional_catchability_pois', line 5, column 4 to column 28)", - " (in 'traditional_catchability_pois', line 6, column 4 to column 25)", - " (in 'traditional_catchability_pois', line 7, column 11 to column 12)", - " (in 'traditional_catchability_pois', line 7, column 13 to column 20)", - " (in 'traditional_catchability_pois', line 7, column 4 to column 26)", - " (in 'traditional_catchability_pois', line 10, column 10 to column 14)", - " (in 'traditional_catchability_pois', line 11, column 27 to column 34)", - " (in 'traditional_catchability_pois', line 14, column 20 to column 21)", - " (in 'traditional_catchability_pois', line 25, column 9 to column 16)", - " (in 'traditional_catchability_pois', line 26, column 9 to column 10)", - " (in 'traditional_catchability_pois', line 27, column 9 to column 13)", - " (in 'traditional_catchability_pois', line 27, column 14 to column 23)"}; -#include -class model_traditional_catchability_pois final : public model_base_crtp { -private: - int C; - std::vector R; - int Nloc; - std::vector E; - int nparams; - Eigen::Matrix mat_data__; - int mu_2dim__; - Eigen::Map> mat{nullptr, 0, 0}; -public: - ~model_traditional_catchability_pois() {} - model_traditional_catchability_pois(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_traditional_catchability_pois_namespace::model_traditional_catchability_pois"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 21; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 21; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 21; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 22; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 23; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 23; - R = context__.vals_i("R"); - current_statement__ = 23; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 24; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 24; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 24; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 25; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 26; - context__.validate_dims("data initialization", "E", "int", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::min()); - current_statement__ = 26; - E = context__.vals_i("E"); - current_statement__ = 26; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 27; - context__.validate_dims("data initialization", "nparams", "int", - std::vector{}); - nparams = std::numeric_limits::min(); - current_statement__ = 27; - nparams = context__.vals_i("nparams")[(1 - 1)]; - current_statement__ = 27; - stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); - current_statement__ = 28; - stan::math::validate_non_negative_index("mat", "C", C); - current_statement__ = 29; - stan::math::validate_non_negative_index("mat", "nparams", nparams); - current_statement__ = 30; - context__.validate_dims("data initialization", "mat", "double", - std::vector{static_cast(C), - static_cast(nparams)}); - mat_data__ = Eigen::Matrix::Constant(C, nparams, - std::numeric_limits::quiet_NaN()); - new (&mat) Eigen::Map>(mat_data__.data(), - C, nparams); - { - std::vector mat_flat__; - current_statement__ = 30; - mat_flat__ = context__.vals_r("mat"); - current_statement__ = 30; - pos__ = 1; - current_statement__ = 30; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 30; - for (int sym2__ = 1; sym2__ <= C; ++sym2__) { - current_statement__ = 30; - stan::model::assign(mat, mat_flat__[(pos__ - 1)], - "assigning variable mat", stan::model::index_uni(sym2__), - stan::model::index_uni(sym1__)); - current_statement__ = 30; - pos__ = (pos__ + 1); - } - } - } - current_statement__ = 31; - stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); - current_statement__ = 32; - stan::math::validate_non_negative_index("q_trans", "nparams", nparams); - current_statement__ = 33; - stan::math::validate_non_negative_index("coef", "C", C); - current_statement__ = 34; - stan::math::validate_non_negative_index("q", "nparams", nparams); - current_statement__ = 35; - stan::math::validate_non_negative_index("log_lik", "C", C); - current_statement__ = 36; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 37; - mu_2dim__ = std::numeric_limits::min(); - current_statement__ = 37; - mu_2dim__ = (nparams + 1); - current_statement__ = 37; - stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + nparams; - } - inline std::string model_name() const final { - return "model_traditional_catchability_pois"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_traditional_catchability_pois_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu_1 = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 2; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, DUMMY_VAR__); - current_statement__ = 9; - for (int i = 1; i <= C; ++i) { - current_statement__ = 7; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(i)), - q_trans)), "assigning variable coef", stan::model::index_uni(i)); - } - current_statement__ = 3; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - { - current_statement__ = 20; - for (int j = 1; j <= C; ++j) { - current_statement__ = 18; - lp_accum__.add(stan::math::poisson_lpmf( - stan::model::rvalue(E, "E", - stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", - stan::model::index_uni(j)) * - stan::model::rvalue(mu_1, "mu_1", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j))))))); - } - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_traditional_catchability_pois_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector mu_1 = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - mu_1 = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - current_statement__ = 2; - q_trans = in__.template read_constrain_lb< - Eigen::Matrix, jacobian__>(-0.99999, - lp__, nparams); - Eigen::Matrix coef = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - out__.write(mu_1); - out__.write(q_trans); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 9; - for (int i = 1; i <= C; ++i) { - current_statement__ = 7; - stan::model::assign(coef, (1 + - stan::math::dot_product( - stan::model::rvalue(mat, "mat", stan::model::index_uni(i)), - q_trans)), "assigning variable coef", stan::model::index_uni(i)); - } - current_statement__ = 3; - stan::math::check_greater_or_equal(function__, "coef", coef, 0); - if (emit_transformed_parameters__) { - out__.write(coef); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix q = - Eigen::Matrix::Constant(nparams, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix mu = - Eigen::Matrix::Constant(Nloc, mu_2dim__, - std::numeric_limits::quiet_NaN()); - current_statement__ = 10; - stan::model::assign(q, stan::math::add(q_trans, 1), - "assigning variable q"); - current_statement__ = 11; - stan::model::assign(mu, stan::math::to_vector(mu_1), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni(1)); - current_statement__ = 14; - for (int i = 1; i <= nparams; ++i) { - current_statement__ = 12; - stan::model::assign(mu, - stan::math::multiply(stan::math::to_vector(mu_1), - stan::model::rvalue(q, "q", stan::model::index_uni(i))), - "assigning variable mu", stan::model::index_omni(), - stan::model::index_uni((i + 1))); - } - current_statement__ = 17; - for (int j = 1; j <= C; ++j) { - current_statement__ = 15; - stan::model::assign(log_lik, - stan::math::poisson_lpmf( - stan::model::rvalue(E, "E", stan::model::index_uni(j)), - (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * - stan::model::rvalue(mu_1, "mu_1", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j)))))), - "assigning variable log_lik", stan::model::index_uni(j)); - } - out__.write(q); - out__.write(log_lik); - out__.write(mu); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(mu_1, - in__.read>(Nloc), - "assigning variable mu_1"); - out__.write_free_lb(0, mu_1); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - current_statement__ = 2; - stan::model::assign(q_trans, - in__.read>(nparams), - "assigning variable q_trans"); - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "mu_1", "double", - std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "q_trans", - "double", std::vector{static_cast(nparams)}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu_1 = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu_1 = context__.vals_r("mu_1"); - out__.write_free_lb(0, mu_1); - Eigen::Matrix q_trans = - Eigen::Matrix::Constant(nparams, DUMMY_VAR__); - { - std::vector q_trans_flat__; - current_statement__ = 2; - q_trans_flat__ = context__.vals_r("q_trans"); - current_statement__ = 2; - pos__ = 1; - current_statement__ = 2; - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - current_statement__ = 2; - stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], - "assigning variable q_trans", stan::model::index_uni(sym1__)); - current_statement__ = 2; - pos__ = (pos__ + 1); - } - } - out__.write_free_lb(-0.99999, q_trans); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"mu_1", "q_trans"}; - if (emit_transformed_parameters__) { - std::vector temp{"coef"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"q", "log_lik", "mu"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{static_cast(nparams)}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(C)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(nparams)}, - std::vector{static_cast(C)}, - std::vector{static_cast(Nloc), - static_cast(mu_2dim__)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu_1" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q_trans" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "coef" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { - param_names__.emplace_back(std::string() + "q" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { - for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym2__) + '.' + std::to_string(sym1__)); - } - } - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (Nloc + nparams); - const size_t num_transformed = emit_transformed_parameters * (C); - const size_t num_gen_quantities = emit_generated_quantities * (((nparams - + C) + (Nloc * mu_2dim__))); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (Nloc + nparams); - const size_t num_transformed = emit_transformed_parameters * (C); - const size_t num_gen_quantities = emit_generated_quantities * (((nparams - + C) + (Nloc * mu_2dim__))); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_traditional_catchability_pois_namespace::model_traditional_catchability_pois; -#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_traditional_catchability_pois_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_traditional_catchability_pois_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 10, column 4 to column 35)", + " (in 'string', line 11, column 4 to column 44)", + " (in 'string', line 14, column 4 to column 28)", + " (in 'string', line 25, column 2 to column 20)", + " (in 'string', line 26, column 2 to column 20)", + " (in 'string', line 27, column 2 to column 28)", + " (in 'string', line 16, column 6 to column 48)", + " (in 'string', line 15, column 17 to line 17, column 5)", + " (in 'string', line 15, column 4 to line 17, column 5)", + " (in 'string', line 28, column 2 to column 18)", + " (in 'string', line 29, column 2 to column 27)", + " (in 'string', line 31, column 4 to column 36)", + " (in 'string', line 30, column 21 to line 32, column 3)", + " (in 'string', line 30, column 2 to line 32, column 3)", + " (in 'string', line 34, column 10 to column 63)", + " (in 'string', line 33, column 17 to line 35, column 7)", + " (in 'string', line 33, column 4 to line 35, column 7)", + " (in 'string', line 21, column 6 to column 41)", + " (in 'string', line 20, column 17 to line 22, column 5)", + " (in 'string', line 20, column 4 to line 22, column 5)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 10 to column 11)", + " (in 'string', line 3, column 4 to column 28)", + " (in 'string', line 4, column 4 to column 22)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 25)", + " (in 'string', line 7, column 11 to column 12)", + " (in 'string', line 7, column 13 to column 20)", + " (in 'string', line 7, column 4 to column 26)", + " (in 'string', line 10, column 10 to column 14)", + " (in 'string', line 11, column 27 to column 34)", + " (in 'string', line 14, column 20 to column 21)", + " (in 'string', line 25, column 9 to column 16)", + " (in 'string', line 26, column 9 to column 10)", + " (in 'string', line 27, column 9 to column 13)", + " (in 'string', line 27, column 14 to column 23)"}; +#include +class model_traditional_catchability_pois final : public model_base_crtp { +private: + int C; + std::vector R; + int Nloc; + std::vector E; + int nparams; + Eigen::Matrix mat_data__; + int mu_2dim__; + Eigen::Map> mat{nullptr, 0, 0}; +public: + ~model_traditional_catchability_pois() {} + model_traditional_catchability_pois(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_traditional_catchability_pois_namespace::model_traditional_catchability_pois"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 21; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 21; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 21; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 22; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 23; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 23; + R = context__.vals_i("R"); + current_statement__ = 23; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 24; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 24; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 24; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 25; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 26; + context__.validate_dims("data initialization", "E", "int", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::min()); + current_statement__ = 26; + E = context__.vals_i("E"); + current_statement__ = 26; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 27; + context__.validate_dims("data initialization", "nparams", "int", + std::vector{}); + nparams = std::numeric_limits::min(); + current_statement__ = 27; + nparams = context__.vals_i("nparams")[(1 - 1)]; + current_statement__ = 27; + stan::math::check_greater_or_equal(function__, "nparams", nparams, 0); + current_statement__ = 28; + stan::math::validate_non_negative_index("mat", "C", C); + current_statement__ = 29; + stan::math::validate_non_negative_index("mat", "nparams", nparams); + current_statement__ = 30; + context__.validate_dims("data initialization", "mat", "double", + std::vector{static_cast(C), + static_cast(nparams)}); + mat_data__ = Eigen::Matrix::Constant(C, nparams, + std::numeric_limits::quiet_NaN()); + new (&mat) Eigen::Map>(mat_data__.data(), + C, nparams); + { + std::vector mat_flat__; + current_statement__ = 30; + mat_flat__ = context__.vals_r("mat"); + current_statement__ = 30; + pos__ = 1; + current_statement__ = 30; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 30; + for (int sym2__ = 1; sym2__ <= C; ++sym2__) { + current_statement__ = 30; + stan::model::assign(mat, mat_flat__[(pos__ - 1)], + "assigning variable mat", stan::model::index_uni(sym2__), + stan::model::index_uni(sym1__)); + current_statement__ = 30; + pos__ = (pos__ + 1); + } + } + } + current_statement__ = 31; + stan::math::validate_non_negative_index("mu_1", "Nloc", Nloc); + current_statement__ = 32; + stan::math::validate_non_negative_index("q_trans", "nparams", nparams); + current_statement__ = 33; + stan::math::validate_non_negative_index("coef", "C", C); + current_statement__ = 34; + stan::math::validate_non_negative_index("q", "nparams", nparams); + current_statement__ = 35; + stan::math::validate_non_negative_index("log_lik", "C", C); + current_statement__ = 36; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 37; + mu_2dim__ = std::numeric_limits::min(); + current_statement__ = 37; + mu_2dim__ = (nparams + 1); + current_statement__ = 37; + stan::math::validate_non_negative_index("mu", "nparams + 1", mu_2dim__); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + nparams; + } + inline std::string model_name() const final { + return "model_traditional_catchability_pois"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_traditional_catchability_pois_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu_1 = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 2; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, DUMMY_VAR__); + current_statement__ = 9; + for (int i = 1; i <= C; ++i) { + current_statement__ = 7; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(i)), + q_trans)), "assigning variable coef", stan::model::index_uni(i)); + } + current_statement__ = 3; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + { + current_statement__ = 20; + for (int j = 1; j <= C; ++j) { + current_statement__ = 18; + lp_accum__.add(stan::math::poisson_lpmf( + stan::model::rvalue(E, "E", + stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", + stan::model::index_uni(j)) * + stan::model::rvalue(mu_1, "mu_1", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j))))))); + } + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_traditional_catchability_pois_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector mu_1 = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + mu_1 = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + current_statement__ = 2; + q_trans = in__.template read_constrain_lb< + Eigen::Matrix, jacobian__>(-0.99999, + lp__, nparams); + Eigen::Matrix coef = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + out__.write(mu_1); + out__.write(q_trans); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 9; + for (int i = 1; i <= C; ++i) { + current_statement__ = 7; + stan::model::assign(coef, (1 + + stan::math::dot_product( + stan::model::rvalue(mat, "mat", stan::model::index_uni(i)), + q_trans)), "assigning variable coef", stan::model::index_uni(i)); + } + current_statement__ = 3; + stan::math::check_greater_or_equal(function__, "coef", coef, 0); + if (emit_transformed_parameters__) { + out__.write(coef); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix q = + Eigen::Matrix::Constant(nparams, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix mu = + Eigen::Matrix::Constant(Nloc, mu_2dim__, + std::numeric_limits::quiet_NaN()); + current_statement__ = 10; + stan::model::assign(q, stan::math::add(q_trans, 1), + "assigning variable q"); + current_statement__ = 11; + stan::model::assign(mu, stan::math::to_vector(mu_1), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni(1)); + current_statement__ = 14; + for (int i = 1; i <= nparams; ++i) { + current_statement__ = 12; + stan::model::assign(mu, + stan::math::multiply(stan::math::to_vector(mu_1), + stan::model::rvalue(q, "q", stan::model::index_uni(i))), + "assigning variable mu", stan::model::index_omni(), + stan::model::index_uni((i + 1))); + } + current_statement__ = 17; + for (int j = 1; j <= C; ++j) { + current_statement__ = 15; + stan::model::assign(log_lik, + stan::math::poisson_lpmf( + stan::model::rvalue(E, "E", stan::model::index_uni(j)), + (stan::model::rvalue(coef, "coef", stan::model::index_uni(j)) * + stan::model::rvalue(mu_1, "mu_1", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j)))))), + "assigning variable log_lik", stan::model::index_uni(j)); + } + out__.write(q); + out__.write(log_lik); + out__.write(mu); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(mu_1, + in__.read>(Nloc), + "assigning variable mu_1"); + out__.write_free_lb(0, mu_1); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + current_statement__ = 2; + stan::model::assign(q_trans, + in__.read>(nparams), + "assigning variable q_trans"); + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "mu_1", "double", + std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "q_trans", + "double", std::vector{static_cast(nparams)}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu_1 = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu_1 = context__.vals_r("mu_1"); + out__.write_free_lb(0, mu_1); + Eigen::Matrix q_trans = + Eigen::Matrix::Constant(nparams, DUMMY_VAR__); + { + std::vector q_trans_flat__; + current_statement__ = 2; + q_trans_flat__ = context__.vals_r("q_trans"); + current_statement__ = 2; + pos__ = 1; + current_statement__ = 2; + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + current_statement__ = 2; + stan::model::assign(q_trans, q_trans_flat__[(pos__ - 1)], + "assigning variable q_trans", stan::model::index_uni(sym1__)); + current_statement__ = 2; + pos__ = (pos__ + 1); + } + } + out__.write_free_lb(-0.99999, q_trans); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"mu_1", "q_trans"}; + if (emit_transformed_parameters__) { + std::vector temp{"coef"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"q", "log_lik", "mu"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{static_cast(nparams)}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(C)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(nparams)}, + std::vector{static_cast(C)}, + std::vector{static_cast(Nloc), + static_cast(mu_2dim__)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu_1" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q_trans" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "coef" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= nparams; ++sym1__) { + param_names__.emplace_back(std::string() + "q" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= mu_2dim__; ++sym1__) { + for (int sym2__ = 1; sym2__ <= Nloc; ++sym2__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym2__) + '.' + std::to_string(sym1__)); + } + } + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"mu_1\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"q_trans\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"parameters\"},{\"name\":\"coef\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"transformed_parameters\"},{\"name\":\"q\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(nparams) + "},\"block\":\"generated_quantities\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"matrix\",\"rows\":" + std::to_string(Nloc) + ",\"cols\":" + std::to_string(mu_2dim__) + "},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (Nloc + nparams); + const size_t num_transformed = emit_transformed_parameters * (C); + const size_t num_gen_quantities = emit_generated_quantities * (((nparams + + C) + (Nloc * mu_2dim__))); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (Nloc + nparams); + const size_t num_transformed = emit_transformed_parameters * (C); + const size_t num_gen_quantities = emit_generated_quantities * (((nparams + + C) + (Nloc * mu_2dim__))); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_traditional_catchability_pois_namespace::model_traditional_catchability_pois; +#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_traditional_catchability_pois_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_traditional_gamma.h b/src/stanExports_traditional_gamma.h index 63792ac..5abe759 100644 --- a/src/stanExports_traditional_gamma.h +++ b/src/stanExports_traditional_gamma.h @@ -1,584 +1,584 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_traditional_gamma_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'traditional_gamma', line 8, column 4 to column 36)", - " (in 'traditional_gamma', line 9, column 4 to column 38)", - " (in 'traditional_gamma', line 12, column 4 to column 35)", - " (in 'traditional_gamma', line 25, column 2 to column 20)", - " (in 'traditional_gamma', line 26, column 2 to column 18)", - " (in 'traditional_gamma', line 14, column 6 to column 42)", - " (in 'traditional_gamma', line 13, column 17 to line 15, column 5)", - " (in 'traditional_gamma', line 13, column 4 to line 15, column 5)", - " (in 'traditional_gamma', line 28, column 4 to column 29)", - " (in 'traditional_gamma', line 27, column 18 to line 29, column 3)", - " (in 'traditional_gamma', line 27, column 2 to line 29, column 3)", - " (in 'traditional_gamma', line 31, column 10 to column 72)", - " (in 'traditional_gamma', line 30, column 17 to line 32, column 7)", - " (in 'traditional_gamma', line 30, column 4 to line 32, column 7)", - " (in 'traditional_gamma', line 19, column 6 to column 49)", - " (in 'traditional_gamma', line 18, column 17 to line 20, column 5)", - " (in 'traditional_gamma', line 18, column 4 to line 20, column 5)", - " (in 'traditional_gamma', line 21, column 3 to column 27)", - " (in 'traditional_gamma', line 22, column 3 to column 28)", - " (in 'traditional_gamma', line 2, column 4 to column 19)", - " (in 'traditional_gamma', line 3, column 10 to column 11)", - " (in 'traditional_gamma', line 3, column 4 to column 28)", - " (in 'traditional_gamma', line 4, column 4 to column 22)", - " (in 'traditional_gamma', line 5, column 10 to column 11)", - " (in 'traditional_gamma', line 5, column 4 to column 29)", - " (in 'traditional_gamma', line 8, column 10 to column 14)", - " (in 'traditional_gamma', line 9, column 10 to column 14)", - " (in 'traditional_gamma', line 12, column 10 to column 11)", - " (in 'traditional_gamma', line 25, column 9 to column 10)", - " (in 'traditional_gamma', line 26, column 9 to column 13)"}; -#include -class model_traditional_gamma final : public model_base_crtp { -private: - int C; - std::vector R; - int Nloc; - std::vector E; -public: - ~model_traditional_gamma() {} - model_traditional_gamma(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_traditional_gamma_namespace::model_traditional_gamma"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 20; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 20; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 20; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 21; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 22; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 22; - R = context__.vals_i("R"); - current_statement__ = 22; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 23; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 23; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 23; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 24; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 25; - context__.validate_dims("data initialization", "E", "double", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::quiet_NaN()); - current_statement__ = 25; - E = context__.vals_r("E"); - current_statement__ = 25; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 26; - stan::math::validate_non_negative_index("alpha", "Nloc", Nloc); - current_statement__ = 27; - stan::math::validate_non_negative_index("beta", "Nloc", Nloc); - current_statement__ = 28; - stan::math::validate_non_negative_index("E_trans", "C", C); - current_statement__ = 29; - stan::math::validate_non_negative_index("log_lik", "C", C); - current_statement__ = 30; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + Nloc; - } - inline std::string model_name() const final { - return "model_traditional_gamma"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_traditional_gamma_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector alpha = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - alpha = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - std::vector beta = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - beta = in__.template read_constrain_lb, - jacobian__>(0.01, lp__, Nloc); - std::vector E_trans = - std::vector(C, DUMMY_VAR__); - current_statement__ = 8; - for (int j = 1; j <= C; ++j) { - current_statement__ = 6; - stan::model::assign(E_trans, - (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + - 0.0000000000001), "assigning variable E_trans", - stan::model::index_uni(j)); - } - current_statement__ = 3; - stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); - { - current_statement__ = 17; - for (int j = 1; j <= C; ++j) { - current_statement__ = 15; - lp_accum__.add(stan::math::gamma_lpdf( - stan::model::rvalue(E_trans, "E_trans", - stan::model::index_uni(j)), - stan::model::rvalue(alpha, "alpha", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))), - stan::model::rvalue(beta, "beta", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))))); - } - current_statement__ = 18; - lp_accum__.add(stan::math::gamma_lpdf(beta, 0.25, 0.25)); - current_statement__ = 19; - lp_accum__.add(stan::math::gamma_lpdf(alpha, 0.01, 0.01)); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_traditional_gamma_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector alpha = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - alpha = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - std::vector beta = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 2; - beta = in__.template read_constrain_lb, - jacobian__>(0.01, lp__, Nloc); - std::vector E_trans = - std::vector(C, std::numeric_limits::quiet_NaN()); - out__.write(alpha); - out__.write(beta); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - current_statement__ = 8; - for (int j = 1; j <= C; ++j) { - current_statement__ = 6; - stan::model::assign(E_trans, - (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + - 0.0000000000001), "assigning variable E_trans", - stan::model::index_uni(j)); - } - current_statement__ = 3; - stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); - if (emit_transformed_parameters__) { - out__.write(E_trans); - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - Eigen::Matrix mu = - Eigen::Matrix::Constant(Nloc, - std::numeric_limits::quiet_NaN()); - current_statement__ = 11; - for (int j = 1; j <= Nloc; ++j) { - current_statement__ = 9; - stan::model::assign(mu, - (stan::model::rvalue(alpha, "alpha", stan::model::index_uni(j)) / - stan::model::rvalue(beta, "beta", stan::model::index_uni(j))), - "assigning variable mu", stan::model::index_uni(j)); - } - current_statement__ = 14; - for (int j = 1; j <= C; ++j) { - current_statement__ = 12; - stan::model::assign(log_lik, - stan::math::gamma_lpdf( - stan::model::rvalue(E_trans, "E_trans", stan::model::index_uni(j)), - stan::model::rvalue(alpha, "alpha", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j)))), - stan::model::rvalue(beta, "beta", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - "assigning variable log_lik", stan::model::index_uni(j)); - } - out__.write(log_lik); - out__.write(mu); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector alpha = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(alpha, - in__.read>(Nloc), - "assigning variable alpha"); - out__.write_free_lb(0, alpha); - std::vector beta = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - stan::model::assign(beta, - in__.read>(Nloc), - "assigning variable beta"); - out__.write_free_lb(0.01, beta); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "alpha", "double", - std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "beta", "double", - std::vector{static_cast(Nloc)}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector alpha = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - alpha = context__.vals_r("alpha"); - out__.write_free_lb(0, alpha); - std::vector beta = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 2; - beta = context__.vals_r("beta"); - out__.write_free_lb(0.01, beta); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"alpha", "beta"}; - if (emit_transformed_parameters__) { - std::vector temp{"E_trans"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector temp{"log_lik", "mu"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{static_cast(Nloc)}}; - if (emit_transformed_parameters__) { - std::vector> - temp{std::vector{static_cast(C)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(C)}, - std::vector{static_cast(Nloc)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "E_trans" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "alpha" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "beta" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) { - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "E_trans" + '.' + - std::to_string(sym1__)); - } - } - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"alpha\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"alpha\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (Nloc + Nloc); - const size_t num_transformed = emit_transformed_parameters * (C); - const size_t num_gen_quantities = emit_generated_quantities * ((C + - Nloc)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (Nloc + Nloc); - const size_t num_transformed = emit_transformed_parameters * (C); - const size_t num_gen_quantities = emit_generated_quantities * ((C + - Nloc)); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_traditional_gamma_namespace::model_traditional_gamma; -#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_traditional_gamma_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_traditional_gamma_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 8, column 4 to column 36)", + " (in 'string', line 9, column 4 to column 38)", + " (in 'string', line 12, column 4 to column 35)", + " (in 'string', line 25, column 2 to column 20)", + " (in 'string', line 26, column 2 to column 18)", + " (in 'string', line 14, column 6 to column 42)", + " (in 'string', line 13, column 17 to line 15, column 5)", + " (in 'string', line 13, column 4 to line 15, column 5)", + " (in 'string', line 28, column 4 to column 29)", + " (in 'string', line 27, column 18 to line 29, column 3)", + " (in 'string', line 27, column 2 to line 29, column 3)", + " (in 'string', line 31, column 10 to column 72)", + " (in 'string', line 30, column 17 to line 32, column 7)", + " (in 'string', line 30, column 4 to line 32, column 7)", + " (in 'string', line 19, column 6 to column 49)", + " (in 'string', line 18, column 17 to line 20, column 5)", + " (in 'string', line 18, column 4 to line 20, column 5)", + " (in 'string', line 21, column 3 to column 27)", + " (in 'string', line 22, column 3 to column 28)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 10 to column 11)", + " (in 'string', line 3, column 4 to column 28)", + " (in 'string', line 4, column 4 to column 22)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 29)", + " (in 'string', line 8, column 10 to column 14)", + " (in 'string', line 9, column 10 to column 14)", + " (in 'string', line 12, column 10 to column 11)", + " (in 'string', line 25, column 9 to column 10)", + " (in 'string', line 26, column 9 to column 13)"}; +#include +class model_traditional_gamma final : public model_base_crtp { +private: + int C; + std::vector R; + int Nloc; + std::vector E; +public: + ~model_traditional_gamma() {} + model_traditional_gamma(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_traditional_gamma_namespace::model_traditional_gamma"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 20; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 20; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 20; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 21; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 22; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 22; + R = context__.vals_i("R"); + current_statement__ = 22; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 23; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 23; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 23; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 24; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 25; + context__.validate_dims("data initialization", "E", "double", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::quiet_NaN()); + current_statement__ = 25; + E = context__.vals_r("E"); + current_statement__ = 25; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 26; + stan::math::validate_non_negative_index("alpha", "Nloc", Nloc); + current_statement__ = 27; + stan::math::validate_non_negative_index("beta", "Nloc", Nloc); + current_statement__ = 28; + stan::math::validate_non_negative_index("E_trans", "C", C); + current_statement__ = 29; + stan::math::validate_non_negative_index("log_lik", "C", C); + current_statement__ = 30; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + Nloc; + } + inline std::string model_name() const final { + return "model_traditional_gamma"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_traditional_gamma_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector alpha = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + alpha = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + std::vector beta = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + beta = in__.template read_constrain_lb, + jacobian__>(0.01, lp__, Nloc); + std::vector E_trans = + std::vector(C, DUMMY_VAR__); + current_statement__ = 8; + for (int j = 1; j <= C; ++j) { + current_statement__ = 6; + stan::model::assign(E_trans, + (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + + 0.0000000000001), "assigning variable E_trans", + stan::model::index_uni(j)); + } + current_statement__ = 3; + stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); + { + current_statement__ = 17; + for (int j = 1; j <= C; ++j) { + current_statement__ = 15; + lp_accum__.add(stan::math::gamma_lpdf( + stan::model::rvalue(E_trans, "E_trans", + stan::model::index_uni(j)), + stan::model::rvalue(alpha, "alpha", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))), + stan::model::rvalue(beta, "beta", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))))); + } + current_statement__ = 18; + lp_accum__.add(stan::math::gamma_lpdf(beta, 0.25, 0.25)); + current_statement__ = 19; + lp_accum__.add(stan::math::gamma_lpdf(alpha, 0.01, 0.01)); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_traditional_gamma_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector alpha = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + alpha = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + std::vector beta = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 2; + beta = in__.template read_constrain_lb, + jacobian__>(0.01, lp__, Nloc); + std::vector E_trans = + std::vector(C, std::numeric_limits::quiet_NaN()); + out__.write(alpha); + out__.write(beta); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + current_statement__ = 8; + for (int j = 1; j <= C; ++j) { + current_statement__ = 6; + stan::model::assign(E_trans, + (stan::model::rvalue(E, "E", stan::model::index_uni(j)) + + 0.0000000000001), "assigning variable E_trans", + stan::model::index_uni(j)); + } + current_statement__ = 3; + stan::math::check_greater_or_equal(function__, "E_trans", E_trans, 0); + if (emit_transformed_parameters__) { + out__.write(E_trans); + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + Eigen::Matrix mu = + Eigen::Matrix::Constant(Nloc, + std::numeric_limits::quiet_NaN()); + current_statement__ = 11; + for (int j = 1; j <= Nloc; ++j) { + current_statement__ = 9; + stan::model::assign(mu, + (stan::model::rvalue(alpha, "alpha", stan::model::index_uni(j)) / + stan::model::rvalue(beta, "beta", stan::model::index_uni(j))), + "assigning variable mu", stan::model::index_uni(j)); + } + current_statement__ = 14; + for (int j = 1; j <= C; ++j) { + current_statement__ = 12; + stan::model::assign(log_lik, + stan::math::gamma_lpdf( + stan::model::rvalue(E_trans, "E_trans", stan::model::index_uni(j)), + stan::model::rvalue(alpha, "alpha", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j)))), + stan::model::rvalue(beta, "beta", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + "assigning variable log_lik", stan::model::index_uni(j)); + } + out__.write(log_lik); + out__.write(mu); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector alpha = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(alpha, + in__.read>(Nloc), + "assigning variable alpha"); + out__.write_free_lb(0, alpha); + std::vector beta = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + stan::model::assign(beta, + in__.read>(Nloc), + "assigning variable beta"); + out__.write_free_lb(0.01, beta); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "alpha", "double", + std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "beta", "double", + std::vector{static_cast(Nloc)}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector alpha = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + alpha = context__.vals_r("alpha"); + out__.write_free_lb(0, alpha); + std::vector beta = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 2; + beta = context__.vals_r("beta"); + out__.write_free_lb(0.01, beta); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"alpha", "beta"}; + if (emit_transformed_parameters__) { + std::vector temp{"E_trans"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector temp{"log_lik", "mu"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{static_cast(Nloc)}}; + if (emit_transformed_parameters__) { + std::vector> + temp{std::vector{static_cast(C)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(C)}, + std::vector{static_cast(Nloc)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "E_trans" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "alpha" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "beta" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) { + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "E_trans" + '.' + + std::to_string(sym1__)); + } + } + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"alpha\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"alpha\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"beta\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"E_trans\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(C) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"transformed_parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"},{\"name\":\"mu\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(Nloc) + "},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (Nloc + Nloc); + const size_t num_transformed = emit_transformed_parameters * (C); + const size_t num_gen_quantities = emit_generated_quantities * ((C + + Nloc)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (Nloc + Nloc); + const size_t num_transformed = emit_transformed_parameters * (C); + const size_t num_gen_quantities = emit_generated_quantities * ((C + + Nloc)); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_traditional_gamma_namespace::model_traditional_gamma; +#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_traditional_gamma_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_traditional_negbin.h b/src/stanExports_traditional_negbin.h index 2c0a870..3058329 100644 --- a/src/stanExports_traditional_negbin.h +++ b/src/stanExports_traditional_negbin.h @@ -1,488 +1,488 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_traditional_negbin_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'traditional_negbin', line 9, column 4 to column 33)", - " (in 'traditional_negbin', line 10, column 4 to column 22)", - " (in 'traditional_negbin', line 21, column 2 to column 20)", - " (in 'traditional_negbin', line 23, column 10 to column 65)", - " (in 'traditional_negbin', line 22, column 17 to line 24, column 7)", - " (in 'traditional_negbin', line 22, column 4 to line 24, column 7)", - " (in 'traditional_negbin', line 16, column 6 to column 42)", - " (in 'traditional_negbin', line 15, column 17 to line 17, column 5)", - " (in 'traditional_negbin', line 15, column 4 to line 17, column 5)", - " (in 'traditional_negbin', line 18, column 4 to column 44)", - " (in 'traditional_negbin', line 2, column 4 to column 19)", - " (in 'traditional_negbin', line 3, column 10 to column 11)", - " (in 'traditional_negbin', line 3, column 4 to column 28)", - " (in 'traditional_negbin', line 4, column 4 to column 22)", - " (in 'traditional_negbin', line 5, column 10 to column 11)", - " (in 'traditional_negbin', line 5, column 4 to column 28)", - " (in 'traditional_negbin', line 6, column 4 to column 28)", - " (in 'traditional_negbin', line 9, column 10 to column 14)", - " (in 'traditional_negbin', line 21, column 9 to column 10)"}; -#include -class model_traditional_negbin final : public model_base_crtp { -private: - int C; - std::vector R; - int Nloc; - std::vector E; - std::vector phipriors; -public: - ~model_traditional_negbin() {} - model_traditional_negbin(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_traditional_negbin_namespace::model_traditional_negbin"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 11; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 11; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 11; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 12; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 13; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 13; - R = context__.vals_i("R"); - current_statement__ = 13; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 14; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 14; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 14; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 15; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 16; - context__.validate_dims("data initialization", "E", "int", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::min()); - current_statement__ = 16; - E = context__.vals_i("E"); - current_statement__ = 16; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 17; - context__.validate_dims("data initialization", "phipriors", "double", - std::vector{static_cast(2)}); - phipriors = std::vector(2, - std::numeric_limits::quiet_NaN()); - current_statement__ = 17; - phipriors = context__.vals_r("phipriors"); - current_statement__ = 18; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 19; - stan::math::validate_non_negative_index("log_lik", "C", C); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc + 1; - } - inline std::string model_name() const final { - return "model_traditional_negbin"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_traditional_negbin_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = in__.template read_constrain_lb(0, - lp__); - { - current_statement__ = 9; - for (int j = 1; j <= C; ++j) { - current_statement__ = 7; - lp_accum__.add(stan::math::neg_binomial_2_lpmf( - stan::model::rvalue(E, "E", - stan::model::index_uni(j)), - stan::model::rvalue(mu, "mu", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))), phi)); - } - current_statement__ = 10; - lp_accum__.add(stan::math::gamma_lpdf(phi, - stan::model::rvalue(phipriors, "phipriors", - stan::model::index_uni(1)), - stan::model::rvalue(phipriors, "phipriors", - stan::model::index_uni(2)))); - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_traditional_negbin_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector mu = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - mu = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - double phi = std::numeric_limits::quiet_NaN(); - current_statement__ = 2; - phi = in__.template read_constrain_lb(0, - lp__); - out__.write(mu); - out__.write(phi); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - current_statement__ = 6; - for (int j = 1; j <= C; ++j) { - current_statement__ = 4; - stan::model::assign(log_lik, - stan::math::neg_binomial_2_lpmf( - stan::model::rvalue(E, "E", stan::model::index_uni(j)), - stan::model::rvalue(mu, "mu", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j)))), phi), - "assigning variable log_lik", stan::model::index_uni(j)); - } - out__.write(log_lik); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(mu, in__.read>(Nloc), - "assigning variable mu"); - out__.write_free_lb(0, mu); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = in__.read(); - out__.write_free_lb(0, phi); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "mu", "double", - std::vector{static_cast(Nloc)}); - current_statement__ = 2; - context__.validate_dims("parameter initialization", "phi", "double", - std::vector{}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu = context__.vals_r("mu"); - out__.write_free_lb(0, mu); - local_scalar_t__ phi = DUMMY_VAR__; - current_statement__ = 2; - phi = context__.vals_r("phi")[(1 - 1)]; - out__.write_free_lb(0, phi); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"mu", "phi"}; - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) { - std::vector temp{"log_lik"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}, - std::vector{}}; - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(C)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "phi"); - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - param_names__.emplace_back(std::string() + "phi"); - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (Nloc + 1); - const size_t num_transformed = emit_transformed_parameters * (0); - const size_t num_gen_quantities = emit_generated_quantities * (C); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = (Nloc + 1); - const size_t num_transformed = emit_transformed_parameters * (0); - const size_t num_gen_quantities = emit_generated_quantities * (C); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_traditional_negbin_namespace::model_traditional_negbin; -#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_traditional_negbin_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_traditional_negbin_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 9, column 4 to column 33)", + " (in 'string', line 10, column 4 to column 22)", + " (in 'string', line 21, column 2 to column 20)", + " (in 'string', line 23, column 10 to column 65)", + " (in 'string', line 22, column 17 to line 24, column 7)", + " (in 'string', line 22, column 4 to line 24, column 7)", + " (in 'string', line 16, column 6 to column 42)", + " (in 'string', line 15, column 17 to line 17, column 5)", + " (in 'string', line 15, column 4 to line 17, column 5)", + " (in 'string', line 18, column 4 to column 44)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 10 to column 11)", + " (in 'string', line 3, column 4 to column 28)", + " (in 'string', line 4, column 4 to column 22)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 6, column 4 to column 28)", + " (in 'string', line 9, column 10 to column 14)", + " (in 'string', line 21, column 9 to column 10)"}; +#include +class model_traditional_negbin final : public model_base_crtp { +private: + int C; + std::vector R; + int Nloc; + std::vector E; + std::vector phipriors; +public: + ~model_traditional_negbin() {} + model_traditional_negbin(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_traditional_negbin_namespace::model_traditional_negbin"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 11; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 11; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 11; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 12; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 13; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 13; + R = context__.vals_i("R"); + current_statement__ = 13; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 14; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 14; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 14; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 15; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 16; + context__.validate_dims("data initialization", "E", "int", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::min()); + current_statement__ = 16; + E = context__.vals_i("E"); + current_statement__ = 16; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 17; + context__.validate_dims("data initialization", "phipriors", "double", + std::vector{static_cast(2)}); + phipriors = std::vector(2, + std::numeric_limits::quiet_NaN()); + current_statement__ = 17; + phipriors = context__.vals_r("phipriors"); + current_statement__ = 18; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 19; + stan::math::validate_non_negative_index("log_lik", "C", C); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc + 1; + } + inline std::string model_name() const final { + return "model_traditional_negbin"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_traditional_negbin_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = in__.template read_constrain_lb(0, + lp__); + { + current_statement__ = 9; + for (int j = 1; j <= C; ++j) { + current_statement__ = 7; + lp_accum__.add(stan::math::neg_binomial_2_lpmf( + stan::model::rvalue(E, "E", + stan::model::index_uni(j)), + stan::model::rvalue(mu, "mu", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))), phi)); + } + current_statement__ = 10; + lp_accum__.add(stan::math::gamma_lpdf(phi, + stan::model::rvalue(phipriors, "phipriors", + stan::model::index_uni(1)), + stan::model::rvalue(phipriors, "phipriors", + stan::model::index_uni(2)))); + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_traditional_negbin_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector mu = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + mu = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + double phi = std::numeric_limits::quiet_NaN(); + current_statement__ = 2; + phi = in__.template read_constrain_lb(0, + lp__); + out__.write(mu); + out__.write(phi); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + current_statement__ = 6; + for (int j = 1; j <= C; ++j) { + current_statement__ = 4; + stan::model::assign(log_lik, + stan::math::neg_binomial_2_lpmf( + stan::model::rvalue(E, "E", stan::model::index_uni(j)), + stan::model::rvalue(mu, "mu", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j)))), phi), + "assigning variable log_lik", stan::model::index_uni(j)); + } + out__.write(log_lik); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(mu, in__.read>(Nloc), + "assigning variable mu"); + out__.write_free_lb(0, mu); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = in__.read(); + out__.write_free_lb(0, phi); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "mu", "double", + std::vector{static_cast(Nloc)}); + current_statement__ = 2; + context__.validate_dims("parameter initialization", "phi", "double", + std::vector{}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu = context__.vals_r("mu"); + out__.write_free_lb(0, mu); + local_scalar_t__ phi = DUMMY_VAR__; + current_statement__ = 2; + phi = context__.vals_r("phi")[(1 - 1)]; + out__.write_free_lb(0, phi); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"mu", "phi"}; + if (emit_transformed_parameters__) {} + if (emit_generated_quantities__) { + std::vector temp{"log_lik"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}, + std::vector{}}; + if (emit_transformed_parameters__) {} + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(C)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "phi"); + if (emit_transformed_parameters__) {} + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + param_names__.emplace_back(std::string() + "phi"); + if (emit_transformed_parameters__) {} + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"phi\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (Nloc + 1); + const size_t num_transformed = emit_transformed_parameters * (0); + const size_t num_gen_quantities = emit_generated_quantities * (C); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = (Nloc + 1); + const size_t num_transformed = emit_transformed_parameters * (0); + const size_t num_gen_quantities = emit_generated_quantities * (C); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_traditional_negbin_namespace::model_traditional_negbin; +#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_traditional_negbin_namespace::profiles__; +} +#endif +#endif diff --git a/src/stanExports_traditional_pois.h b/src/stanExports_traditional_pois.h index 294046e..3439f44 100644 --- a/src/stanExports_traditional_pois.h +++ b/src/stanExports_traditional_pois.h @@ -1,448 +1,448 @@ -// Generated by rstantools. Do not edit by hand. - -/* - eDNAjoint 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. - - eDNAjoint 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 eDNAjoint. If not, see . -*/ -#ifndef MODELS_HPP -#define MODELS_HPP -#define STAN__SERVICES__COMMAND_HPP -#ifndef USE_STANC3 -#define USE_STANC3 -#endif -#include -// Code generated by stanc v2.32.2 -#include -namespace model_traditional_pois_namespace { -using stan::model::model_base_crtp; -using namespace stan::math; -stan::math::profile_map profiles__; -static constexpr std::array locations_array__ = - {" (found before start of program)", - " (in 'traditional_pois', line 8, column 4 to column 33)", - " (in 'traditional_pois', line 18, column 2 to column 20)", - " (in 'traditional_pois', line 20, column 10 to column 53)", - " (in 'traditional_pois', line 19, column 17 to line 21, column 7)", - " (in 'traditional_pois', line 19, column 4 to line 21, column 7)", - " (in 'traditional_pois', line 14, column 6 to column 31)", - " (in 'traditional_pois', line 13, column 17 to line 15, column 5)", - " (in 'traditional_pois', line 13, column 4 to line 15, column 5)", - " (in 'traditional_pois', line 2, column 4 to column 19)", - " (in 'traditional_pois', line 3, column 10 to column 11)", - " (in 'traditional_pois', line 3, column 4 to column 28)", - " (in 'traditional_pois', line 4, column 4 to column 22)", - " (in 'traditional_pois', line 5, column 10 to column 11)", - " (in 'traditional_pois', line 5, column 4 to column 28)", - " (in 'traditional_pois', line 8, column 10 to column 14)", - " (in 'traditional_pois', line 18, column 9 to column 10)"}; -#include -class model_traditional_pois final : public model_base_crtp { -private: - int C; - std::vector R; - int Nloc; - std::vector E; -public: - ~model_traditional_pois() {} - model_traditional_pois(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_traditional_pois_namespace::model_traditional_pois"; - // suppress unused var warning - (void) function__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - current_statement__ = 9; - context__.validate_dims("data initialization", "C", "int", - std::vector{}); - C = std::numeric_limits::min(); - current_statement__ = 9; - C = context__.vals_i("C")[(1 - 1)]; - current_statement__ = 9; - stan::math::check_greater_or_equal(function__, "C", C, 1); - current_statement__ = 10; - stan::math::validate_non_negative_index("R", "C", C); - current_statement__ = 11; - context__.validate_dims("data initialization", "R", "int", - std::vector{static_cast(C)}); - R = std::vector(C, std::numeric_limits::min()); - current_statement__ = 11; - R = context__.vals_i("R"); - current_statement__ = 11; - stan::math::check_greater_or_equal(function__, "R", R, 1); - current_statement__ = 12; - context__.validate_dims("data initialization", "Nloc", "int", - std::vector{}); - Nloc = std::numeric_limits::min(); - current_statement__ = 12; - Nloc = context__.vals_i("Nloc")[(1 - 1)]; - current_statement__ = 12; - stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); - current_statement__ = 13; - stan::math::validate_non_negative_index("E", "C", C); - current_statement__ = 14; - context__.validate_dims("data initialization", "E", "int", - std::vector{static_cast(C)}); - E = std::vector(C, std::numeric_limits::min()); - current_statement__ = 14; - E = context__.vals_i("E"); - current_statement__ = 14; - stan::math::check_greater_or_equal(function__, "E", E, 0); - current_statement__ = 15; - stan::math::validate_non_negative_index("mu", "Nloc", Nloc); - current_statement__ = 16; - stan::math::validate_non_negative_index("log_lik", "C", C); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - num_params_r__ = Nloc; - } - inline std::string model_name() const final { - return "model_traditional_pois"; - } - inline std::vector model_compile_info() const noexcept { - return std::vector{"stanc_version = stanc3 v2.32.2", - "stancflags = --allow-undefined"}; - } - template * = nullptr, - stan::require_vector_like_vt* = nullptr> - inline stan::scalar_type_t - log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* - pstream__ = nullptr) const { - using T__ = stan::scalar_type_t; - using local_scalar_t__ = T__; - T__ lp__(0.0); - stan::math::accumulator lp_accum__; - stan::io::deserializer in__(params_r__, params_i__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - static constexpr const char* function__ = - "model_traditional_pois_namespace::log_prob"; - // suppress unused var warning - (void) function__; - try { - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - { - current_statement__ = 8; - for (int j = 1; j <= C; ++j) { - current_statement__ = 6; - lp_accum__.add(stan::math::poisson_lpmf( - stan::model::rvalue(E, "E", - stan::model::index_uni(j)), - stan::model::rvalue(mu, "mu", - stan::model::index_uni( - stan::model::rvalue(R, "R", - stan::model::index_uni(j)))))); - } - } - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - lp_accum__.add(lp__); - return lp_accum__.sum(); - } - template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> - inline void - write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, - VecVar& vars__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true, std::ostream* - pstream__ = nullptr) const { - using local_scalar_t__ = double; - stan::io::deserializer in__(params_r__, params_i__); - stan::io::serializer 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 lp_accum__; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - constexpr bool jacobian__ = false; - static constexpr const char* function__ = - "model_traditional_pois_namespace::write_array"; - // suppress unused var warning - (void) function__; - try { - std::vector mu = - std::vector(Nloc, std::numeric_limits::quiet_NaN()); - current_statement__ = 1; - mu = in__.template read_constrain_lb, - jacobian__>(0, lp__, Nloc); - out__.write(mu); - if (stan::math::logical_negation( - (stan::math::primitive_value(emit_transformed_parameters__) || - stan::math::primitive_value(emit_generated_quantities__)))) { - return ; - } - if (stan::math::logical_negation(emit_generated_quantities__)) { - return ; - } - Eigen::Matrix log_lik = - Eigen::Matrix::Constant(C, - std::numeric_limits::quiet_NaN()); - current_statement__ = 5; - for (int j = 1; j <= C; ++j) { - current_statement__ = 3; - stan::model::assign(log_lik, - stan::math::poisson_lpmf( - stan::model::rvalue(E, "E", stan::model::index_uni(j)), - stan::model::rvalue(mu, "mu", - stan::model::index_uni( - stan::model::rvalue(R, "R", stan::model::index_uni(j))))), - "assigning variable log_lik", stan::model::index_uni(j)); - } - out__.write(log_lik); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = nullptr, - stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); - stan::io::serializer out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - stan::model::assign(mu, in__.read>(Nloc), - "assigning variable mu"); - out__.write_free_lb(0, mu); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - template * = 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 out__(vars__); - int current_statement__ = 0; - local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); - // suppress unused var warning - (void) DUMMY_VAR__; - try { - current_statement__ = 1; - context__.validate_dims("parameter initialization", "mu", "double", - std::vector{static_cast(Nloc)}); - int pos__ = std::numeric_limits::min(); - pos__ = 1; - std::vector mu = - std::vector(Nloc, DUMMY_VAR__); - current_statement__ = 1; - mu = context__.vals_r("mu"); - out__.write_free_lb(0, mu); - } catch (const std::exception& e) { - stan::lang::rethrow_located(e, locations_array__[current_statement__]); - } - } - inline void - get_param_names(std::vector& names__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - names__ = std::vector{"mu"}; - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) { - std::vector temp{"log_lik"}; - names__.reserve(names__.size() + temp.size()); - names__.insert(names__.end(), temp.begin(), temp.end()); - } - } - inline void - get_dims(std::vector>& dimss__, const bool - emit_transformed_parameters__ = true, const bool - emit_generated_quantities__ = true) const { - dimss__ = std::vector>{std::vector{static_cast< - size_t>( - Nloc)}}; - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) { - std::vector> - temp{std::vector{static_cast(C)}}; - dimss__.reserve(dimss__.size() + temp.size()); - dimss__.insert(dimss__.end(), temp.begin(), temp.end()); - } - } - inline void - constrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - } - } - inline void - unconstrained_param_names(std::vector& param_names__, bool - emit_transformed_parameters__ = true, bool - emit_generated_quantities__ = true) const final { - for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { - param_names__.emplace_back(std::string() + "mu" + '.' + - std::to_string(sym1__)); - } - if (emit_transformed_parameters__) {} - if (emit_generated_quantities__) { - for (int sym1__ = 1; sym1__ <= C; ++sym1__) { - param_names__.emplace_back(std::string() + "log_lik" + '.' + - std::to_string(sym1__)); - } - } - } - inline std::string get_constrained_sizedtypes() const { - return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"}]"); - } - inline std::string get_unconstrained_sizedtypes() const { - return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"}]"); - } - // Begin method overload boilerplate - template inline void - write_array(RNG& base_rng, Eigen::Matrix& params_r, - Eigen::Matrix& vars, const bool - emit_transformed_parameters = true, const bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = Nloc; - const size_t num_transformed = emit_transformed_parameters * (0); - const size_t num_gen_quantities = emit_generated_quantities * (C); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - std::vector params_i; - vars = Eigen::Matrix::Constant(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline void - write_array(RNG& base_rng, std::vector& params_r, std::vector& - params_i, std::vector& vars, bool - emit_transformed_parameters = true, bool - emit_generated_quantities = true, std::ostream* - pstream = nullptr) const { - const size_t num_params__ = Nloc; - const size_t num_transformed = emit_transformed_parameters * (0); - const size_t num_gen_quantities = emit_generated_quantities * (C); - const size_t num_to_write = num_params__ + num_transformed + - num_gen_quantities; - vars = std::vector(num_to_write, - std::numeric_limits::quiet_NaN()); - write_array_impl(base_rng, params_r, params_i, vars, - emit_transformed_parameters, emit_generated_quantities, pstream); - } - template inline T_ - log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { - Eigen::Matrix params_i; - return log_prob_impl(params_r, params_i, pstream); - } - template inline T_ - log_prob(std::vector& params_r, std::vector& params_i, - std::ostream* pstream = nullptr) const { - return log_prob_impl(params_r, params_i, pstream); - } - inline void - transform_inits(const stan::io::var_context& context, - Eigen::Matrix& params_r, std::ostream* - pstream = nullptr) const final { - std::vector params_r_vec(params_r.size()); - std::vector params_i; - transform_inits(context, params_i, params_r_vec, pstream); - params_r = Eigen::Map>(params_r_vec.data(), - params_r_vec.size()); - } - inline void - transform_inits(const stan::io::var_context& context, std::vector& - params_i, std::vector& vars, std::ostream* - pstream__ = nullptr) const { - vars.resize(num_params_r__); - transform_inits_impl(context, vars, pstream__); - } - inline void - unconstrain_array(const std::vector& params_constrained, - std::vector& params_unconstrained, std::ostream* - pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = std::vector(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } - inline void - unconstrain_array(const Eigen::Matrix& params_constrained, - Eigen::Matrix& params_unconstrained, - std::ostream* pstream = nullptr) const { - const std::vector params_i; - params_unconstrained = Eigen::Matrix::Constant(num_params_r__, - std::numeric_limits::quiet_NaN()); - unconstrain_array_impl(params_constrained, params_i, - params_unconstrained, pstream); - } -}; -} -using stan_model = model_traditional_pois_namespace::model_traditional_pois; -#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_traditional_pois_namespace::profiles__; -} -#endif -#endif +// Generated by rstantools. Do not edit by hand. + +/* + eDNAjoint 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. + + eDNAjoint 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 eDNAjoint. If not, see . +*/ +#ifndef MODELS_HPP +#define MODELS_HPP +#define STAN__SERVICES__COMMAND_HPP +#ifndef USE_STANC3 +#define USE_STANC3 +#endif +#include +// Code generated by stanc v2.32.2 +#include +namespace model_traditional_pois_namespace { +using stan::model::model_base_crtp; +using namespace stan::math; +stan::math::profile_map profiles__; +static constexpr std::array locations_array__ = + {" (found before start of program)", + " (in 'string', line 8, column 4 to column 33)", + " (in 'string', line 18, column 2 to column 20)", + " (in 'string', line 20, column 10 to column 53)", + " (in 'string', line 19, column 17 to line 21, column 7)", + " (in 'string', line 19, column 4 to line 21, column 7)", + " (in 'string', line 14, column 6 to column 31)", + " (in 'string', line 13, column 17 to line 15, column 5)", + " (in 'string', line 13, column 4 to line 15, column 5)", + " (in 'string', line 2, column 4 to column 19)", + " (in 'string', line 3, column 10 to column 11)", + " (in 'string', line 3, column 4 to column 28)", + " (in 'string', line 4, column 4 to column 22)", + " (in 'string', line 5, column 10 to column 11)", + " (in 'string', line 5, column 4 to column 28)", + " (in 'string', line 8, column 10 to column 14)", + " (in 'string', line 18, column 9 to column 10)"}; +#include +class model_traditional_pois final : public model_base_crtp { +private: + int C; + std::vector R; + int Nloc; + std::vector E; +public: + ~model_traditional_pois() {} + model_traditional_pois(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_traditional_pois_namespace::model_traditional_pois"; + // suppress unused var warning + (void) function__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + current_statement__ = 9; + context__.validate_dims("data initialization", "C", "int", + std::vector{}); + C = std::numeric_limits::min(); + current_statement__ = 9; + C = context__.vals_i("C")[(1 - 1)]; + current_statement__ = 9; + stan::math::check_greater_or_equal(function__, "C", C, 1); + current_statement__ = 10; + stan::math::validate_non_negative_index("R", "C", C); + current_statement__ = 11; + context__.validate_dims("data initialization", "R", "int", + std::vector{static_cast(C)}); + R = std::vector(C, std::numeric_limits::min()); + current_statement__ = 11; + R = context__.vals_i("R"); + current_statement__ = 11; + stan::math::check_greater_or_equal(function__, "R", R, 1); + current_statement__ = 12; + context__.validate_dims("data initialization", "Nloc", "int", + std::vector{}); + Nloc = std::numeric_limits::min(); + current_statement__ = 12; + Nloc = context__.vals_i("Nloc")[(1 - 1)]; + current_statement__ = 12; + stan::math::check_greater_or_equal(function__, "Nloc", Nloc, 1); + current_statement__ = 13; + stan::math::validate_non_negative_index("E", "C", C); + current_statement__ = 14; + context__.validate_dims("data initialization", "E", "int", + std::vector{static_cast(C)}); + E = std::vector(C, std::numeric_limits::min()); + current_statement__ = 14; + E = context__.vals_i("E"); + current_statement__ = 14; + stan::math::check_greater_or_equal(function__, "E", E, 0); + current_statement__ = 15; + stan::math::validate_non_negative_index("mu", "Nloc", Nloc); + current_statement__ = 16; + stan::math::validate_non_negative_index("log_lik", "C", C); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + num_params_r__ = Nloc; + } + inline std::string model_name() const final { + return "model_traditional_pois"; + } + inline std::vector model_compile_info() const noexcept { + return std::vector{"stanc_version = stanc3 v2.32.2", + "stancflags = --allow-undefined"}; + } + template * = nullptr, + stan::require_vector_like_vt* = nullptr> + inline stan::scalar_type_t + log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream* + pstream__ = nullptr) const { + using T__ = stan::scalar_type_t; + using local_scalar_t__ = T__; + T__ lp__(0.0); + stan::math::accumulator lp_accum__; + stan::io::deserializer in__(params_r__, params_i__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + static constexpr const char* function__ = + "model_traditional_pois_namespace::log_prob"; + // suppress unused var warning + (void) function__; + try { + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + { + current_statement__ = 8; + for (int j = 1; j <= C; ++j) { + current_statement__ = 6; + lp_accum__.add(stan::math::poisson_lpmf( + stan::model::rvalue(E, "E", + stan::model::index_uni(j)), + stan::model::rvalue(mu, "mu", + stan::model::index_uni( + stan::model::rvalue(R, "R", + stan::model::index_uni(j)))))); + } + } + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + lp_accum__.add(lp__); + return lp_accum__.sum(); + } + template * = nullptr, stan::require_vector_like_vt* = nullptr, stan::require_vector_vt* = nullptr> + inline void + write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__, + VecVar& vars__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true, std::ostream* + pstream__ = nullptr) const { + using local_scalar_t__ = double; + stan::io::deserializer in__(params_r__, params_i__); + stan::io::serializer 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 lp_accum__; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + constexpr bool jacobian__ = false; + static constexpr const char* function__ = + "model_traditional_pois_namespace::write_array"; + // suppress unused var warning + (void) function__; + try { + std::vector mu = + std::vector(Nloc, std::numeric_limits::quiet_NaN()); + current_statement__ = 1; + mu = in__.template read_constrain_lb, + jacobian__>(0, lp__, Nloc); + out__.write(mu); + if (stan::math::logical_negation( + (stan::math::primitive_value(emit_transformed_parameters__) || + stan::math::primitive_value(emit_generated_quantities__)))) { + return ; + } + if (stan::math::logical_negation(emit_generated_quantities__)) { + return ; + } + Eigen::Matrix log_lik = + Eigen::Matrix::Constant(C, + std::numeric_limits::quiet_NaN()); + current_statement__ = 5; + for (int j = 1; j <= C; ++j) { + current_statement__ = 3; + stan::model::assign(log_lik, + stan::math::poisson_lpmf( + stan::model::rvalue(E, "E", stan::model::index_uni(j)), + stan::model::rvalue(mu, "mu", + stan::model::index_uni( + stan::model::rvalue(R, "R", stan::model::index_uni(j))))), + "assigning variable log_lik", stan::model::index_uni(j)); + } + out__.write(log_lik); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = nullptr, + stan::require_vector_like_vt* = 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 in__(params_r__, params_i__); + stan::io::serializer out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + stan::model::assign(mu, in__.read>(Nloc), + "assigning variable mu"); + out__.write_free_lb(0, mu); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + template * = 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 out__(vars__); + int current_statement__ = 0; + local_scalar_t__ DUMMY_VAR__(std::numeric_limits::quiet_NaN()); + // suppress unused var warning + (void) DUMMY_VAR__; + try { + current_statement__ = 1; + context__.validate_dims("parameter initialization", "mu", "double", + std::vector{static_cast(Nloc)}); + int pos__ = std::numeric_limits::min(); + pos__ = 1; + std::vector mu = + std::vector(Nloc, DUMMY_VAR__); + current_statement__ = 1; + mu = context__.vals_r("mu"); + out__.write_free_lb(0, mu); + } catch (const std::exception& e) { + stan::lang::rethrow_located(e, locations_array__[current_statement__]); + } + } + inline void + get_param_names(std::vector& names__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + names__ = std::vector{"mu"}; + if (emit_transformed_parameters__) {} + if (emit_generated_quantities__) { + std::vector temp{"log_lik"}; + names__.reserve(names__.size() + temp.size()); + names__.insert(names__.end(), temp.begin(), temp.end()); + } + } + inline void + get_dims(std::vector>& dimss__, const bool + emit_transformed_parameters__ = true, const bool + emit_generated_quantities__ = true) const { + dimss__ = std::vector>{std::vector{static_cast< + size_t>( + Nloc)}}; + if (emit_transformed_parameters__) {} + if (emit_generated_quantities__) { + std::vector> + temp{std::vector{static_cast(C)}}; + dimss__.reserve(dimss__.size() + temp.size()); + dimss__.insert(dimss__.end(), temp.begin(), temp.end()); + } + } + inline void + constrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) {} + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + } + } + inline void + unconstrained_param_names(std::vector& param_names__, bool + emit_transformed_parameters__ = true, bool + emit_generated_quantities__ = true) const final { + for (int sym1__ = 1; sym1__ <= Nloc; ++sym1__) { + param_names__.emplace_back(std::string() + "mu" + '.' + + std::to_string(sym1__)); + } + if (emit_transformed_parameters__) {} + if (emit_generated_quantities__) { + for (int sym1__ = 1; sym1__ <= C; ++sym1__) { + param_names__.emplace_back(std::string() + "log_lik" + '.' + + std::to_string(sym1__)); + } + } + } + inline std::string get_constrained_sizedtypes() const { + return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"}]"); + } + inline std::string get_unconstrained_sizedtypes() const { + return std::string("[{\"name\":\"mu\",\"type\":{\"name\":\"array\",\"length\":" + std::to_string(Nloc) + ",\"element_type\":{\"name\":\"real\"}},\"block\":\"parameters\"},{\"name\":\"log_lik\",\"type\":{\"name\":\"vector\",\"length\":" + std::to_string(C) + "},\"block\":\"generated_quantities\"}]"); + } + // Begin method overload boilerplate + template inline void + write_array(RNG& base_rng, Eigen::Matrix& params_r, + Eigen::Matrix& vars, const bool + emit_transformed_parameters = true, const bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = Nloc; + const size_t num_transformed = emit_transformed_parameters * (0); + const size_t num_gen_quantities = emit_generated_quantities * (C); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + std::vector params_i; + vars = Eigen::Matrix::Constant(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline void + write_array(RNG& base_rng, std::vector& params_r, std::vector& + params_i, std::vector& vars, bool + emit_transformed_parameters = true, bool + emit_generated_quantities = true, std::ostream* + pstream = nullptr) const { + const size_t num_params__ = Nloc; + const size_t num_transformed = emit_transformed_parameters * (0); + const size_t num_gen_quantities = emit_generated_quantities * (C); + const size_t num_to_write = num_params__ + num_transformed + + num_gen_quantities; + vars = std::vector(num_to_write, + std::numeric_limits::quiet_NaN()); + write_array_impl(base_rng, params_r, params_i, vars, + emit_transformed_parameters, emit_generated_quantities, pstream); + } + template inline T_ + log_prob(Eigen::Matrix& params_r, std::ostream* pstream = nullptr) const { + Eigen::Matrix params_i; + return log_prob_impl(params_r, params_i, pstream); + } + template inline T_ + log_prob(std::vector& params_r, std::vector& params_i, + std::ostream* pstream = nullptr) const { + return log_prob_impl(params_r, params_i, pstream); + } + inline void + transform_inits(const stan::io::var_context& context, + Eigen::Matrix& params_r, std::ostream* + pstream = nullptr) const final { + std::vector params_r_vec(params_r.size()); + std::vector params_i; + transform_inits(context, params_i, params_r_vec, pstream); + params_r = Eigen::Map>(params_r_vec.data(), + params_r_vec.size()); + } + inline void + transform_inits(const stan::io::var_context& context, std::vector& + params_i, std::vector& vars, std::ostream* + pstream__ = nullptr) const { + vars.resize(num_params_r__); + transform_inits_impl(context, vars, pstream__); + } + inline void + unconstrain_array(const std::vector& params_constrained, + std::vector& params_unconstrained, std::ostream* + pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = std::vector(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } + inline void + unconstrain_array(const Eigen::Matrix& params_constrained, + Eigen::Matrix& params_unconstrained, + std::ostream* pstream = nullptr) const { + const std::vector params_i; + params_unconstrained = Eigen::Matrix::Constant(num_params_r__, + std::numeric_limits::quiet_NaN()); + unconstrain_array_impl(params_constrained, params_i, + params_unconstrained, pstream); + } +}; +} +using stan_model = model_traditional_pois_namespace::model_traditional_pois; +#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_traditional_pois_namespace::profiles__; +} +#endif +#endif