// Generated by using Rcpp::compileAttributes() -> do not edit by hand
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#include "../inst/include/updog.h"
#include <RcppArmadillo.h>
#include <Rcpp.h>
#include <string>
#include <set>

using namespace Rcpp;

#ifdef RCPP_USE_GLOBAL_ROSTREAM
Rcpp::Rostream<true>&  Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// dbetabinom_alpha_beta_double
double dbetabinom_alpha_beta_double(int x, int size, double alpha, double beta, bool log);
static SEXP _updog_dbetabinom_alpha_beta_double_try(SEXP xSEXP, SEXP sizeSEXP, SEXP alphaSEXP, SEXP betaSEXP, SEXP logSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< int >::type x(xSEXP);
    Rcpp::traits::input_parameter< int >::type size(sizeSEXP);
    Rcpp::traits::input_parameter< double >::type alpha(alphaSEXP);
    Rcpp::traits::input_parameter< double >::type beta(betaSEXP);
    Rcpp::traits::input_parameter< bool >::type log(logSEXP);
    rcpp_result_gen = Rcpp::wrap(dbetabinom_alpha_beta_double(x, size, alpha, beta, log));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_dbetabinom_alpha_beta_double(SEXP xSEXP, SEXP sizeSEXP, SEXP alphaSEXP, SEXP betaSEXP, SEXP logSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_dbetabinom_alpha_beta_double_try(xSEXP, sizeSEXP, alphaSEXP, betaSEXP, logSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// dbernbinom
double dbernbinom(int x, int size, double mu, bool log);
static SEXP _updog_dbernbinom_try(SEXP xSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP logSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< int >::type x(xSEXP);
    Rcpp::traits::input_parameter< int >::type size(sizeSEXP);
    Rcpp::traits::input_parameter< double >::type mu(muSEXP);
    Rcpp::traits::input_parameter< bool >::type log(logSEXP);
    rcpp_result_gen = Rcpp::wrap(dbernbinom(x, size, mu, log));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_dbernbinom(SEXP xSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP logSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_dbernbinom_try(xSEXP, sizeSEXP, muSEXP, logSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// dbetabinom_double
double dbetabinom_double(int x, int size, double mu, double rho, bool log);
static SEXP _updog_dbetabinom_double_try(SEXP xSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP, SEXP logSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< int >::type x(xSEXP);
    Rcpp::traits::input_parameter< int >::type size(sizeSEXP);
    Rcpp::traits::input_parameter< double >::type mu(muSEXP);
    Rcpp::traits::input_parameter< double >::type rho(rhoSEXP);
    Rcpp::traits::input_parameter< bool >::type log(logSEXP);
    rcpp_result_gen = Rcpp::wrap(dbetabinom_double(x, size, mu, rho, log));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_dbetabinom_double(SEXP xSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP, SEXP logSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_dbetabinom_double_try(xSEXP, sizeSEXP, muSEXP, rhoSEXP, logSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// dbetabinom
NumericVector dbetabinom(IntegerVector x, IntegerVector size, NumericVector mu, NumericVector rho, LogicalVector log);
static SEXP _updog_dbetabinom_try(SEXP xSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP, SEXP logSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< IntegerVector >::type x(xSEXP);
    Rcpp::traits::input_parameter< IntegerVector >::type size(sizeSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type mu(muSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type rho(rhoSEXP);
    Rcpp::traits::input_parameter< LogicalVector >::type log(logSEXP);
    rcpp_result_gen = Rcpp::wrap(dbetabinom(x, size, mu, rho, log));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_dbetabinom(SEXP xSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP, SEXP logSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_dbetabinom_try(xSEXP, sizeSEXP, muSEXP, rhoSEXP, logSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// pbetabinom_double
double pbetabinom_double(int q, int size, double mu, double rho, bool log_p);
static SEXP _updog_pbetabinom_double_try(SEXP qSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP, SEXP log_pSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< int >::type q(qSEXP);
    Rcpp::traits::input_parameter< int >::type size(sizeSEXP);
    Rcpp::traits::input_parameter< double >::type mu(muSEXP);
    Rcpp::traits::input_parameter< double >::type rho(rhoSEXP);
    Rcpp::traits::input_parameter< bool >::type log_p(log_pSEXP);
    rcpp_result_gen = Rcpp::wrap(pbetabinom_double(q, size, mu, rho, log_p));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_pbetabinom_double(SEXP qSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP, SEXP log_pSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_pbetabinom_double_try(qSEXP, sizeSEXP, muSEXP, rhoSEXP, log_pSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// pbetabinom
NumericVector pbetabinom(IntegerVector q, IntegerVector size, NumericVector mu, NumericVector rho, LogicalVector log_p);
static SEXP _updog_pbetabinom_try(SEXP qSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP, SEXP log_pSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< IntegerVector >::type q(qSEXP);
    Rcpp::traits::input_parameter< IntegerVector >::type size(sizeSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type mu(muSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type rho(rhoSEXP);
    Rcpp::traits::input_parameter< LogicalVector >::type log_p(log_pSEXP);
    rcpp_result_gen = Rcpp::wrap(pbetabinom(q, size, mu, rho, log_p));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_pbetabinom(SEXP qSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP, SEXP log_pSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_pbetabinom_try(qSEXP, sizeSEXP, muSEXP, rhoSEXP, log_pSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// qbetabinom_double
int qbetabinom_double(double p, int size, double mu, double rho);
static SEXP _updog_qbetabinom_double_try(SEXP pSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< double >::type p(pSEXP);
    Rcpp::traits::input_parameter< int >::type size(sizeSEXP);
    Rcpp::traits::input_parameter< double >::type mu(muSEXP);
    Rcpp::traits::input_parameter< double >::type rho(rhoSEXP);
    rcpp_result_gen = Rcpp::wrap(qbetabinom_double(p, size, mu, rho));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_qbetabinom_double(SEXP pSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_qbetabinom_double_try(pSEXP, sizeSEXP, muSEXP, rhoSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// qbetabinom
IntegerVector qbetabinom(NumericVector p, IntegerVector size, NumericVector mu, NumericVector rho);
static SEXP _updog_qbetabinom_try(SEXP pSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< NumericVector >::type p(pSEXP);
    Rcpp::traits::input_parameter< IntegerVector >::type size(sizeSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type mu(muSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type rho(rhoSEXP);
    rcpp_result_gen = Rcpp::wrap(qbetabinom(p, size, mu, rho));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_qbetabinom(SEXP pSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_qbetabinom_try(pSEXP, sizeSEXP, muSEXP, rhoSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// rbetabinom_int
int rbetabinom_int(int size, double mu, double rho);
static SEXP _updog_rbetabinom_int_try(SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< int >::type size(sizeSEXP);
    Rcpp::traits::input_parameter< double >::type mu(muSEXP);
    Rcpp::traits::input_parameter< double >::type rho(rhoSEXP);
    rcpp_result_gen = Rcpp::wrap(rbetabinom_int(size, mu, rho));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_rbetabinom_int(SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_rbetabinom_int_try(sizeSEXP, muSEXP, rhoSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// rbetabinom
IntegerVector rbetabinom(int n, IntegerVector size, NumericVector mu, NumericVector rho);
static SEXP _updog_rbetabinom_try(SEXP nSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< int >::type n(nSEXP);
    Rcpp::traits::input_parameter< IntegerVector >::type size(sizeSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type mu(muSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type rho(rhoSEXP);
    rcpp_result_gen = Rcpp::wrap(rbetabinom(n, size, mu, rho));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_rbetabinom(SEXP nSEXP, SEXP sizeSEXP, SEXP muSEXP, SEXP rhoSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_rbetabinom_try(nSEXP, sizeSEXP, muSEXP, rhoSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// wem_fixp
void wem_fixp(arma::vec& pivec, const arma::mat& lmat, arma::mat& etamat, const int& nind, const int& nclass, const arma::vec& weight_vec, arma::vec& nvec, const long double& lambda);
RcppExport SEXP _updog_wem_fixp(SEXP pivecSEXP, SEXP lmatSEXP, SEXP etamatSEXP, SEXP nindSEXP, SEXP nclassSEXP, SEXP weight_vecSEXP, SEXP nvecSEXP, SEXP lambdaSEXP) {
BEGIN_RCPP
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< arma::vec& >::type pivec(pivecSEXP);
    Rcpp::traits::input_parameter< const arma::mat& >::type lmat(lmatSEXP);
    Rcpp::traits::input_parameter< arma::mat& >::type etamat(etamatSEXP);
    Rcpp::traits::input_parameter< const int& >::type nind(nindSEXP);
    Rcpp::traits::input_parameter< const int& >::type nclass(nclassSEXP);
    Rcpp::traits::input_parameter< const arma::vec& >::type weight_vec(weight_vecSEXP);
    Rcpp::traits::input_parameter< arma::vec& >::type nvec(nvecSEXP);
    Rcpp::traits::input_parameter< const long double& >::type lambda(lambdaSEXP);
    wem_fixp(pivec, lmat, etamat, nind, nclass, weight_vec, nvec, lambda);
    return R_NilValue;
END_RCPP
}
// wem_obj
double wem_obj(const arma::vec& pivec, const arma::vec& weight_vec, const arma::mat& lmat, const long double& lambda);
RcppExport SEXP _updog_wem_obj(SEXP pivecSEXP, SEXP weight_vecSEXP, SEXP lmatSEXP, SEXP lambdaSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< const arma::vec& >::type pivec(pivecSEXP);
    Rcpp::traits::input_parameter< const arma::vec& >::type weight_vec(weight_vecSEXP);
    Rcpp::traits::input_parameter< const arma::mat& >::type lmat(lmatSEXP);
    Rcpp::traits::input_parameter< const long double& >::type lambda(lambdaSEXP);
    rcpp_result_gen = Rcpp::wrap(wem_obj(pivec, weight_vec, lmat, lambda));
    return rcpp_result_gen;
END_RCPP
}
// wem
arma::vec wem(arma::vec weight_vec, arma::mat lmat, arma::vec pi_init, long double lambda, int itermax, double obj_tol);
RcppExport SEXP _updog_wem(SEXP weight_vecSEXP, SEXP lmatSEXP, SEXP pi_initSEXP, SEXP lambdaSEXP, SEXP itermaxSEXP, SEXP obj_tolSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< arma::vec >::type weight_vec(weight_vecSEXP);
    Rcpp::traits::input_parameter< arma::mat >::type lmat(lmatSEXP);
    Rcpp::traits::input_parameter< arma::vec >::type pi_init(pi_initSEXP);
    Rcpp::traits::input_parameter< long double >::type lambda(lambdaSEXP);
    Rcpp::traits::input_parameter< int >::type itermax(itermaxSEXP);
    Rcpp::traits::input_parameter< double >::type obj_tol(obj_tolSEXP);
    rcpp_result_gen = Rcpp::wrap(wem(weight_vec, lmat, pi_init, lambda, itermax, obj_tol));
    return rcpp_result_gen;
END_RCPP
}
// get_wik_mat
NumericMatrix get_wik_mat(NumericVector probk_vec, NumericVector refvec, NumericVector sizevec, int ploidy, double seq, double bias, double od);
RcppExport SEXP _updog_get_wik_mat(SEXP probk_vecSEXP, SEXP refvecSEXP, SEXP sizevecSEXP, SEXP ploidySEXP, SEXP seqSEXP, SEXP biasSEXP, SEXP odSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< NumericVector >::type probk_vec(probk_vecSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type refvec(refvecSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type sizevec(sizevecSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< double >::type seq(seqSEXP);
    Rcpp::traits::input_parameter< double >::type bias(biasSEXP);
    Rcpp::traits::input_parameter< double >::type od(odSEXP);
    rcpp_result_gen = Rcpp::wrap(get_wik_mat(probk_vec, refvec, sizevec, ploidy, seq, bias, od));
    return rcpp_result_gen;
END_RCPP
}
// get_genotype_likelihoods
NumericMatrix get_genotype_likelihoods(NumericVector refvec, NumericVector sizevec, int ploidy, double seq, double bias, double od);
RcppExport SEXP _updog_get_genotype_likelihoods(SEXP refvecSEXP, SEXP sizevecSEXP, SEXP ploidySEXP, SEXP seqSEXP, SEXP biasSEXP, SEXP odSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< NumericVector >::type refvec(refvecSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type sizevec(sizevecSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< double >::type seq(seqSEXP);
    Rcpp::traits::input_parameter< double >::type bias(biasSEXP);
    Rcpp::traits::input_parameter< double >::type od(odSEXP);
    rcpp_result_gen = Rcpp::wrap(get_genotype_likelihoods(refvec, sizevec, ploidy, seq, bias, od));
    return rcpp_result_gen;
END_RCPP
}
// flexdog_obj
double flexdog_obj(NumericVector probk_vec, NumericVector refvec, NumericVector sizevec, int ploidy, double seq, double bias, double od, double mean_bias, double var_bias, double mean_seq, double var_seq, double mean_od, double var_od);
RcppExport SEXP _updog_flexdog_obj(SEXP probk_vecSEXP, SEXP refvecSEXP, SEXP sizevecSEXP, SEXP ploidySEXP, SEXP seqSEXP, SEXP biasSEXP, SEXP odSEXP, SEXP mean_biasSEXP, SEXP var_biasSEXP, SEXP mean_seqSEXP, SEXP var_seqSEXP, SEXP mean_odSEXP, SEXP var_odSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< NumericVector >::type probk_vec(probk_vecSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type refvec(refvecSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type sizevec(sizevecSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< double >::type seq(seqSEXP);
    Rcpp::traits::input_parameter< double >::type bias(biasSEXP);
    Rcpp::traits::input_parameter< double >::type od(odSEXP);
    Rcpp::traits::input_parameter< double >::type mean_bias(mean_biasSEXP);
    Rcpp::traits::input_parameter< double >::type var_bias(var_biasSEXP);
    Rcpp::traits::input_parameter< double >::type mean_seq(mean_seqSEXP);
    Rcpp::traits::input_parameter< double >::type var_seq(var_seqSEXP);
    Rcpp::traits::input_parameter< double >::type mean_od(mean_odSEXP);
    Rcpp::traits::input_parameter< double >::type var_od(var_odSEXP);
    rcpp_result_gen = Rcpp::wrap(flexdog_obj(probk_vec, refvec, sizevec, ploidy, seq, bias, od, mean_bias, var_bias, mean_seq, var_seq, mean_od, var_od));
    return rcpp_result_gen;
END_RCPP
}
// f1_obj
double f1_obj(double alpha, arma::vec pvec, arma::vec weight_vec);
RcppExport SEXP _updog_f1_obj(SEXP alphaSEXP, SEXP pvecSEXP, SEXP weight_vecSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< double >::type alpha(alphaSEXP);
    Rcpp::traits::input_parameter< arma::vec >::type pvec(pvecSEXP);
    Rcpp::traits::input_parameter< arma::vec >::type weight_vec(weight_vecSEXP);
    rcpp_result_gen = Rcpp::wrap(f1_obj(alpha, pvec, weight_vec));
    return rcpp_result_gen;
END_RCPP
}
// grad_for_mu_sigma2
NumericVector grad_for_mu_sigma2(arma::Col<double> mu, arma::Col<double> sigma2, NumericMatrix phifk_mat, arma::Mat<double> cor_inv, NumericMatrix log_bb_dense);
RcppExport SEXP _updog_grad_for_mu_sigma2(SEXP muSEXP, SEXP sigma2SEXP, SEXP phifk_matSEXP, SEXP cor_invSEXP, SEXP log_bb_denseSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< arma::Col<double> >::type mu(muSEXP);
    Rcpp::traits::input_parameter< arma::Col<double> >::type sigma2(sigma2SEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type phifk_mat(phifk_matSEXP);
    Rcpp::traits::input_parameter< arma::Mat<double> >::type cor_inv(cor_invSEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type log_bb_dense(log_bb_denseSEXP);
    rcpp_result_gen = Rcpp::wrap(grad_for_mu_sigma2(mu, sigma2, phifk_mat, cor_inv, log_bb_dense));
    return rcpp_result_gen;
END_RCPP
}
// grad_for_mu_sigma2_wrapper
NumericVector grad_for_mu_sigma2_wrapper(arma::Col<double> muSigma2, NumericMatrix phifk_mat, arma::Mat<double> cor_inv, NumericMatrix log_bb_dense);
RcppExport SEXP _updog_grad_for_mu_sigma2_wrapper(SEXP muSigma2SEXP, SEXP phifk_matSEXP, SEXP cor_invSEXP, SEXP log_bb_denseSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< arma::Col<double> >::type muSigma2(muSigma2SEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type phifk_mat(phifk_matSEXP);
    Rcpp::traits::input_parameter< arma::Mat<double> >::type cor_inv(cor_invSEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type log_bb_dense(log_bb_denseSEXP);
    rcpp_result_gen = Rcpp::wrap(grad_for_mu_sigma2_wrapper(muSigma2, phifk_mat, cor_inv, log_bb_dense));
    return rcpp_result_gen;
END_RCPP
}
// dpen_dh
double dpen_dh(double h, double mu_h, double sigma2_h);
RcppExport SEXP _updog_dpen_dh(SEXP hSEXP, SEXP mu_hSEXP, SEXP sigma2_hSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< double >::type h(hSEXP);
    Rcpp::traits::input_parameter< double >::type mu_h(mu_hSEXP);
    Rcpp::traits::input_parameter< double >::type sigma2_h(sigma2_hSEXP);
    rcpp_result_gen = Rcpp::wrap(dpen_dh(h, mu_h, sigma2_h));
    return rcpp_result_gen;
END_RCPP
}
// dpen_deps
double dpen_deps(double eps, double mu_eps, double sigma2_eps);
RcppExport SEXP _updog_dpen_deps(SEXP epsSEXP, SEXP mu_epsSEXP, SEXP sigma2_epsSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< double >::type eps(epsSEXP);
    Rcpp::traits::input_parameter< double >::type mu_eps(mu_epsSEXP);
    Rcpp::traits::input_parameter< double >::type sigma2_eps(sigma2_epsSEXP);
    rcpp_result_gen = Rcpp::wrap(dpen_deps(eps, mu_eps, sigma2_eps));
    return rcpp_result_gen;
END_RCPP
}
// dlbeta_dc
double dlbeta_dc(int x, int n, double xi, double c);
RcppExport SEXP _updog_dlbeta_dc(SEXP xSEXP, SEXP nSEXP, SEXP xiSEXP, SEXP cSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< int >::type x(xSEXP);
    Rcpp::traits::input_parameter< int >::type n(nSEXP);
    Rcpp::traits::input_parameter< double >::type xi(xiSEXP);
    Rcpp::traits::input_parameter< double >::type c(cSEXP);
    rcpp_result_gen = Rcpp::wrap(dlbeta_dc(x, n, xi, c));
    return rcpp_result_gen;
END_RCPP
}
// dc_dtau
double dc_dtau(double tau);
RcppExport SEXP _updog_dc_dtau(SEXP tauSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< double >::type tau(tauSEXP);
    rcpp_result_gen = Rcpp::wrap(dc_dtau(tau));
    return rcpp_result_gen;
END_RCPP
}
// dlbeta_dtau
double dlbeta_dtau(int x, int n, double p, double eps, double h, double tau);
RcppExport SEXP _updog_dlbeta_dtau(SEXP xSEXP, SEXP nSEXP, SEXP pSEXP, SEXP epsSEXP, SEXP hSEXP, SEXP tauSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< int >::type x(xSEXP);
    Rcpp::traits::input_parameter< int >::type n(nSEXP);
    Rcpp::traits::input_parameter< double >::type p(pSEXP);
    Rcpp::traits::input_parameter< double >::type eps(epsSEXP);
    Rcpp::traits::input_parameter< double >::type h(hSEXP);
    Rcpp::traits::input_parameter< double >::type tau(tauSEXP);
    rcpp_result_gen = Rcpp::wrap(dlbeta_dtau(x, n, p, eps, h, tau));
    return rcpp_result_gen;
END_RCPP
}
// dlbeta_dxi
double dlbeta_dxi(int x, int n, double xi, double tau);
RcppExport SEXP _updog_dlbeta_dxi(SEXP xSEXP, SEXP nSEXP, SEXP xiSEXP, SEXP tauSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< int >::type x(xSEXP);
    Rcpp::traits::input_parameter< int >::type n(nSEXP);
    Rcpp::traits::input_parameter< double >::type xi(xiSEXP);
    Rcpp::traits::input_parameter< double >::type tau(tauSEXP);
    rcpp_result_gen = Rcpp::wrap(dlbeta_dxi(x, n, xi, tau));
    return rcpp_result_gen;
END_RCPP
}
// dxi_dh
double dxi_dh(double p, double eps, double h);
RcppExport SEXP _updog_dxi_dh(SEXP pSEXP, SEXP epsSEXP, SEXP hSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< double >::type p(pSEXP);
    Rcpp::traits::input_parameter< double >::type eps(epsSEXP);
    Rcpp::traits::input_parameter< double >::type h(hSEXP);
    rcpp_result_gen = Rcpp::wrap(dxi_dh(p, eps, h));
    return rcpp_result_gen;
END_RCPP
}
// dlbeta_dh
double dlbeta_dh(int x, int n, double p, double eps, double h, double tau);
RcppExport SEXP _updog_dlbeta_dh(SEXP xSEXP, SEXP nSEXP, SEXP pSEXP, SEXP epsSEXP, SEXP hSEXP, SEXP tauSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< int >::type x(xSEXP);
    Rcpp::traits::input_parameter< int >::type n(nSEXP);
    Rcpp::traits::input_parameter< double >::type p(pSEXP);
    Rcpp::traits::input_parameter< double >::type eps(epsSEXP);
    Rcpp::traits::input_parameter< double >::type h(hSEXP);
    Rcpp::traits::input_parameter< double >::type tau(tauSEXP);
    rcpp_result_gen = Rcpp::wrap(dlbeta_dh(x, n, p, eps, h, tau));
    return rcpp_result_gen;
END_RCPP
}
// dxi_df
double dxi_df(double h, double f);
RcppExport SEXP _updog_dxi_df(SEXP hSEXP, SEXP fSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< double >::type h(hSEXP);
    Rcpp::traits::input_parameter< double >::type f(fSEXP);
    rcpp_result_gen = Rcpp::wrap(dxi_df(h, f));
    return rcpp_result_gen;
END_RCPP
}
// df_deps
double df_deps(double p, double eps);
RcppExport SEXP _updog_df_deps(SEXP pSEXP, SEXP epsSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< double >::type p(pSEXP);
    Rcpp::traits::input_parameter< double >::type eps(epsSEXP);
    rcpp_result_gen = Rcpp::wrap(df_deps(p, eps));
    return rcpp_result_gen;
END_RCPP
}
// dlbeta_deps
double dlbeta_deps(int x, int n, double p, double eps, double h, double tau);
RcppExport SEXP _updog_dlbeta_deps(SEXP xSEXP, SEXP nSEXP, SEXP pSEXP, SEXP epsSEXP, SEXP hSEXP, SEXP tauSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< int >::type x(xSEXP);
    Rcpp::traits::input_parameter< int >::type n(nSEXP);
    Rcpp::traits::input_parameter< double >::type p(pSEXP);
    Rcpp::traits::input_parameter< double >::type eps(epsSEXP);
    Rcpp::traits::input_parameter< double >::type h(hSEXP);
    Rcpp::traits::input_parameter< double >::type tau(tauSEXP);
    rcpp_result_gen = Rcpp::wrap(dlbeta_deps(x, n, p, eps, h, tau));
    return rcpp_result_gen;
END_RCPP
}
// grad_for_eps
NumericVector grad_for_eps(NumericVector parvec, NumericVector refvec, NumericVector sizevec, int ploidy, double mean_bias, double var_bias, double mean_seq, double var_seq, double mean_od, double var_od, NumericMatrix wmat, bool update_bias, bool update_seq, bool update_od);
RcppExport SEXP _updog_grad_for_eps(SEXP parvecSEXP, SEXP refvecSEXP, SEXP sizevecSEXP, SEXP ploidySEXP, SEXP mean_biasSEXP, SEXP var_biasSEXP, SEXP mean_seqSEXP, SEXP var_seqSEXP, SEXP mean_odSEXP, SEXP var_odSEXP, SEXP wmatSEXP, SEXP update_biasSEXP, SEXP update_seqSEXP, SEXP update_odSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< NumericVector >::type parvec(parvecSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type refvec(refvecSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type sizevec(sizevecSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< double >::type mean_bias(mean_biasSEXP);
    Rcpp::traits::input_parameter< double >::type var_bias(var_biasSEXP);
    Rcpp::traits::input_parameter< double >::type mean_seq(mean_seqSEXP);
    Rcpp::traits::input_parameter< double >::type var_seq(var_seqSEXP);
    Rcpp::traits::input_parameter< double >::type mean_od(mean_odSEXP);
    Rcpp::traits::input_parameter< double >::type var_od(var_odSEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type wmat(wmatSEXP);
    Rcpp::traits::input_parameter< bool >::type update_bias(update_biasSEXP);
    Rcpp::traits::input_parameter< bool >::type update_seq(update_seqSEXP);
    Rcpp::traits::input_parameter< bool >::type update_od(update_odSEXP);
    rcpp_result_gen = Rcpp::wrap(grad_for_eps(parvec, refvec, sizevec, ploidy, mean_bias, var_bias, mean_seq, var_seq, mean_od, var_od, wmat, update_bias, update_seq, update_od));
    return rcpp_result_gen;
END_RCPP
}
// grad_for_weighted_lbb
NumericVector grad_for_weighted_lbb(NumericVector parvec, int ploidy, NumericVector weight_vec);
RcppExport SEXP _updog_grad_for_weighted_lbb(SEXP parvecSEXP, SEXP ploidySEXP, SEXP weight_vecSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< NumericVector >::type parvec(parvecSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< NumericVector >::type weight_vec(weight_vecSEXP);
    rcpp_result_gen = Rcpp::wrap(grad_for_weighted_lbb(parvec, ploidy, weight_vec));
    return rcpp_result_gen;
END_RCPP
}
// grad_for_weighted_lnorm
NumericVector grad_for_weighted_lnorm(NumericVector parvec, int ploidy, NumericVector weight_vec);
RcppExport SEXP _updog_grad_for_weighted_lnorm(SEXP parvecSEXP, SEXP ploidySEXP, SEXP weight_vecSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< NumericVector >::type parvec(parvecSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< NumericVector >::type weight_vec(weight_vecSEXP);
    rcpp_result_gen = Rcpp::wrap(grad_for_weighted_lnorm(parvec, ploidy, weight_vec));
    return rcpp_result_gen;
END_RCPP
}
// post_prob
double post_prob(int dosage, int ploidy, double mu, double sigma2, double alpha, double rho);
RcppExport SEXP _updog_post_prob(SEXP dosageSEXP, SEXP ploidySEXP, SEXP muSEXP, SEXP sigma2SEXP, SEXP alphaSEXP, SEXP rhoSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< int >::type dosage(dosageSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< double >::type mu(muSEXP);
    Rcpp::traits::input_parameter< double >::type sigma2(sigma2SEXP);
    Rcpp::traits::input_parameter< double >::type alpha(alphaSEXP);
    Rcpp::traits::input_parameter< double >::type rho(rhoSEXP);
    rcpp_result_gen = Rcpp::wrap(post_prob(dosage, ploidy, mu, sigma2, alpha, rho));
    return rcpp_result_gen;
END_RCPP
}
// compute_all_post_prob
arma::Cube<double> compute_all_post_prob(int ploidy, NumericMatrix mu, NumericMatrix sigma2, NumericVector alpha, NumericVector rho);
RcppExport SEXP _updog_compute_all_post_prob(SEXP ploidySEXP, SEXP muSEXP, SEXP sigma2SEXP, SEXP alphaSEXP, SEXP rhoSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type mu(muSEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type sigma2(sigma2SEXP);
    Rcpp::traits::input_parameter< NumericVector >::type alpha(alphaSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type rho(rhoSEXP);
    rcpp_result_gen = Rcpp::wrap(compute_all_post_prob(ploidy, mu, sigma2, alpha, rho));
    return rcpp_result_gen;
END_RCPP
}
// compute_all_log_bb
arma::Cube<double> compute_all_log_bb(NumericMatrix refmat, NumericMatrix sizemat, int ploidy, NumericVector seq, NumericVector bias, NumericVector od);
RcppExport SEXP _updog_compute_all_log_bb(SEXP refmatSEXP, SEXP sizematSEXP, SEXP ploidySEXP, SEXP seqSEXP, SEXP biasSEXP, SEXP odSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< NumericMatrix >::type refmat(refmatSEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type sizemat(sizematSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< NumericVector >::type seq(seqSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type bias(biasSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type od(odSEXP);
    rcpp_result_gen = Rcpp::wrap(compute_all_log_bb(refmat, sizemat, ploidy, seq, bias, od));
    return rcpp_result_gen;
END_RCPP
}
// compute_all_phifk
arma::Cube<double> compute_all_phifk(NumericVector alpha, NumericVector rho, int ploidy);
RcppExport SEXP _updog_compute_all_phifk(SEXP alphaSEXP, SEXP rhoSEXP, SEXP ploidySEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< NumericVector >::type alpha(alphaSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type rho(rhoSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    rcpp_result_gen = Rcpp::wrap(compute_all_phifk(alpha, rho, ploidy));
    return rcpp_result_gen;
END_RCPP
}
// pen_bias
double pen_bias(double h, double mu_h, double sigma2_h);
RcppExport SEXP _updog_pen_bias(SEXP hSEXP, SEXP mu_hSEXP, SEXP sigma2_hSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< double >::type h(hSEXP);
    Rcpp::traits::input_parameter< double >::type mu_h(mu_hSEXP);
    Rcpp::traits::input_parameter< double >::type sigma2_h(sigma2_hSEXP);
    rcpp_result_gen = Rcpp::wrap(pen_bias(h, mu_h, sigma2_h));
    return rcpp_result_gen;
END_RCPP
}
// pen_seq_error
double pen_seq_error(double eps, double mu_eps, double sigma2_eps);
RcppExport SEXP _updog_pen_seq_error(SEXP epsSEXP, SEXP mu_epsSEXP, SEXP sigma2_epsSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< double >::type eps(epsSEXP);
    Rcpp::traits::input_parameter< double >::type mu_eps(mu_epsSEXP);
    Rcpp::traits::input_parameter< double >::type sigma2_eps(sigma2_epsSEXP);
    rcpp_result_gen = Rcpp::wrap(pen_seq_error(eps, mu_eps, sigma2_eps));
    return rcpp_result_gen;
END_RCPP
}
// obj_for_rho
double obj_for_rho(double rho, NumericVector mu, NumericVector sigma2, NumericVector alpha, NumericMatrix log_bb_dense, int ploidy);
RcppExport SEXP _updog_obj_for_rho(SEXP rhoSEXP, SEXP muSEXP, SEXP sigma2SEXP, SEXP alphaSEXP, SEXP log_bb_denseSEXP, SEXP ploidySEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< double >::type rho(rhoSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type mu(muSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type sigma2(sigma2SEXP);
    Rcpp::traits::input_parameter< NumericVector >::type alpha(alphaSEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type log_bb_dense(log_bb_denseSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    rcpp_result_gen = Rcpp::wrap(obj_for_rho(rho, mu, sigma2, alpha, log_bb_dense, ploidy));
    return rcpp_result_gen;
END_RCPP
}
// obj_for_alpha
double obj_for_alpha(arma::Col<double> mu, arma::Col<double> sigma2, double alpha, NumericVector rho, NumericMatrix log_bb_dense, int ploidy);
RcppExport SEXP _updog_obj_for_alpha(SEXP muSEXP, SEXP sigma2SEXP, SEXP alphaSEXP, SEXP rhoSEXP, SEXP log_bb_denseSEXP, SEXP ploidySEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< arma::Col<double> >::type mu(muSEXP);
    Rcpp::traits::input_parameter< arma::Col<double> >::type sigma2(sigma2SEXP);
    Rcpp::traits::input_parameter< double >::type alpha(alphaSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type rho(rhoSEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type log_bb_dense(log_bb_denseSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    rcpp_result_gen = Rcpp::wrap(obj_for_alpha(mu, sigma2, alpha, rho, log_bb_dense, ploidy));
    return rcpp_result_gen;
END_RCPP
}
// obj_for_eps
double obj_for_eps(NumericVector parvec, NumericVector refvec, NumericVector sizevec, int ploidy, double mean_bias, double var_bias, double mean_seq, double var_seq, double mean_od, double var_od, NumericMatrix wmat, bool update_bias, bool update_seq, bool update_od);
RcppExport SEXP _updog_obj_for_eps(SEXP parvecSEXP, SEXP refvecSEXP, SEXP sizevecSEXP, SEXP ploidySEXP, SEXP mean_biasSEXP, SEXP var_biasSEXP, SEXP mean_seqSEXP, SEXP var_seqSEXP, SEXP mean_odSEXP, SEXP var_odSEXP, SEXP wmatSEXP, SEXP update_biasSEXP, SEXP update_seqSEXP, SEXP update_odSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< NumericVector >::type parvec(parvecSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type refvec(refvecSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type sizevec(sizevecSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< double >::type mean_bias(mean_biasSEXP);
    Rcpp::traits::input_parameter< double >::type var_bias(var_biasSEXP);
    Rcpp::traits::input_parameter< double >::type mean_seq(mean_seqSEXP);
    Rcpp::traits::input_parameter< double >::type var_seq(var_seqSEXP);
    Rcpp::traits::input_parameter< double >::type mean_od(mean_odSEXP);
    Rcpp::traits::input_parameter< double >::type var_od(var_odSEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type wmat(wmatSEXP);
    Rcpp::traits::input_parameter< bool >::type update_bias(update_biasSEXP);
    Rcpp::traits::input_parameter< bool >::type update_seq(update_seqSEXP);
    Rcpp::traits::input_parameter< bool >::type update_od(update_odSEXP);
    rcpp_result_gen = Rcpp::wrap(obj_for_eps(parvec, refvec, sizevec, ploidy, mean_bias, var_bias, mean_seq, var_seq, mean_od, var_od, wmat, update_bias, update_seq, update_od));
    return rcpp_result_gen;
END_RCPP
}
// obj_for_mu_sigma2
double obj_for_mu_sigma2(arma::Col<double> mu, arma::Col<double> sigma2, NumericMatrix phifk_mat, arma::Mat<double> cor_inv, NumericMatrix log_bb_dense);
RcppExport SEXP _updog_obj_for_mu_sigma2(SEXP muSEXP, SEXP sigma2SEXP, SEXP phifk_matSEXP, SEXP cor_invSEXP, SEXP log_bb_denseSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< arma::Col<double> >::type mu(muSEXP);
    Rcpp::traits::input_parameter< arma::Col<double> >::type sigma2(sigma2SEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type phifk_mat(phifk_matSEXP);
    Rcpp::traits::input_parameter< arma::Mat<double> >::type cor_inv(cor_invSEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type log_bb_dense(log_bb_denseSEXP);
    rcpp_result_gen = Rcpp::wrap(obj_for_mu_sigma2(mu, sigma2, phifk_mat, cor_inv, log_bb_dense));
    return rcpp_result_gen;
END_RCPP
}
// obj_for_mu_sigma2_wrapper
double obj_for_mu_sigma2_wrapper(arma::Col<double> muSigma2, NumericMatrix phifk_mat, arma::Mat<double> cor_inv, NumericMatrix log_bb_dense);
RcppExport SEXP _updog_obj_for_mu_sigma2_wrapper(SEXP muSigma2SEXP, SEXP phifk_matSEXP, SEXP cor_invSEXP, SEXP log_bb_denseSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< arma::Col<double> >::type muSigma2(muSigma2SEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type phifk_mat(phifk_matSEXP);
    Rcpp::traits::input_parameter< arma::Mat<double> >::type cor_inv(cor_invSEXP);
    Rcpp::traits::input_parameter< NumericMatrix >::type log_bb_dense(log_bb_denseSEXP);
    rcpp_result_gen = Rcpp::wrap(obj_for_mu_sigma2_wrapper(muSigma2, phifk_mat, cor_inv, log_bb_dense));
    return rcpp_result_gen;
END_RCPP
}
// elbo
double elbo(arma::Cube<double> warray, arma::Cube<double> lbeta_array, arma::Mat<double> cor_inv, arma::Mat<double> postmean, arma::Mat<double> postvar, NumericVector bias, NumericVector seq, double mean_bias, double var_bias, double mean_seq, double var_seq, int ploidy);
RcppExport SEXP _updog_elbo(SEXP warraySEXP, SEXP lbeta_arraySEXP, SEXP cor_invSEXP, SEXP postmeanSEXP, SEXP postvarSEXP, SEXP biasSEXP, SEXP seqSEXP, SEXP mean_biasSEXP, SEXP var_biasSEXP, SEXP mean_seqSEXP, SEXP var_seqSEXP, SEXP ploidySEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< arma::Cube<double> >::type warray(warraySEXP);
    Rcpp::traits::input_parameter< arma::Cube<double> >::type lbeta_array(lbeta_arraySEXP);
    Rcpp::traits::input_parameter< arma::Mat<double> >::type cor_inv(cor_invSEXP);
    Rcpp::traits::input_parameter< arma::Mat<double> >::type postmean(postmeanSEXP);
    Rcpp::traits::input_parameter< arma::Mat<double> >::type postvar(postvarSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type bias(biasSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type seq(seqSEXP);
    Rcpp::traits::input_parameter< double >::type mean_bias(mean_biasSEXP);
    Rcpp::traits::input_parameter< double >::type var_bias(var_biasSEXP);
    Rcpp::traits::input_parameter< double >::type mean_seq(mean_seqSEXP);
    Rcpp::traits::input_parameter< double >::type var_seq(var_seqSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    rcpp_result_gen = Rcpp::wrap(elbo(warray, lbeta_array, cor_inv, postmean, postvar, bias, seq, mean_bias, var_bias, mean_seq, var_seq, ploidy));
    return rcpp_result_gen;
END_RCPP
}
// obj_for_weighted_lbb
double obj_for_weighted_lbb(NumericVector parvec, int ploidy, NumericVector weight_vec);
RcppExport SEXP _updog_obj_for_weighted_lbb(SEXP parvecSEXP, SEXP ploidySEXP, SEXP weight_vecSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< NumericVector >::type parvec(parvecSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< NumericVector >::type weight_vec(weight_vecSEXP);
    rcpp_result_gen = Rcpp::wrap(obj_for_weighted_lbb(parvec, ploidy, weight_vec));
    return rcpp_result_gen;
END_RCPP
}
// obj_for_weighted_lnorm
double obj_for_weighted_lnorm(NumericVector parvec, int ploidy, NumericVector weight_vec);
RcppExport SEXP _updog_obj_for_weighted_lnorm(SEXP parvecSEXP, SEXP ploidySEXP, SEXP weight_vecSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< NumericVector >::type parvec(parvecSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< NumericVector >::type weight_vec(weight_vecSEXP);
    rcpp_result_gen = Rcpp::wrap(obj_for_weighted_lnorm(parvec, ploidy, weight_vec));
    return rcpp_result_gen;
END_RCPP
}
// oracle_mis
double oracle_mis(int n, int ploidy, double seq, double bias, double od, NumericVector dist);
static SEXP _updog_oracle_mis_try(SEXP nSEXP, SEXP ploidySEXP, SEXP seqSEXP, SEXP biasSEXP, SEXP odSEXP, SEXP distSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< int >::type n(nSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< double >::type seq(seqSEXP);
    Rcpp::traits::input_parameter< double >::type bias(biasSEXP);
    Rcpp::traits::input_parameter< double >::type od(odSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type dist(distSEXP);
    rcpp_result_gen = Rcpp::wrap(oracle_mis(n, ploidy, seq, bias, od, dist));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_oracle_mis(SEXP nSEXP, SEXP ploidySEXP, SEXP seqSEXP, SEXP biasSEXP, SEXP odSEXP, SEXP distSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_oracle_mis_try(nSEXP, ploidySEXP, seqSEXP, biasSEXP, odSEXP, distSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// oracle_mis_vec
NumericVector oracle_mis_vec(int n, int ploidy, double seq, double bias, double od, NumericVector dist);
static SEXP _updog_oracle_mis_vec_try(SEXP nSEXP, SEXP ploidySEXP, SEXP seqSEXP, SEXP biasSEXP, SEXP odSEXP, SEXP distSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< int >::type n(nSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< double >::type seq(seqSEXP);
    Rcpp::traits::input_parameter< double >::type bias(biasSEXP);
    Rcpp::traits::input_parameter< double >::type od(odSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type dist(distSEXP);
    rcpp_result_gen = Rcpp::wrap(oracle_mis_vec(n, ploidy, seq, bias, od, dist));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_oracle_mis_vec(SEXP nSEXP, SEXP ploidySEXP, SEXP seqSEXP, SEXP biasSEXP, SEXP odSEXP, SEXP distSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_oracle_mis_vec_try(nSEXP, ploidySEXP, seqSEXP, biasSEXP, odSEXP, distSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// oracle_joint
NumericMatrix oracle_joint(int n, int ploidy, double seq, double bias, double od, NumericVector dist);
static SEXP _updog_oracle_joint_try(SEXP nSEXP, SEXP ploidySEXP, SEXP seqSEXP, SEXP biasSEXP, SEXP odSEXP, SEXP distSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< int >::type n(nSEXP);
    Rcpp::traits::input_parameter< int >::type ploidy(ploidySEXP);
    Rcpp::traits::input_parameter< double >::type seq(seqSEXP);
    Rcpp::traits::input_parameter< double >::type bias(biasSEXP);
    Rcpp::traits::input_parameter< double >::type od(odSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type dist(distSEXP);
    rcpp_result_gen = Rcpp::wrap(oracle_joint(n, ploidy, seq, bias, od, dist));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_oracle_joint(SEXP nSEXP, SEXP ploidySEXP, SEXP seqSEXP, SEXP biasSEXP, SEXP odSEXP, SEXP distSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_oracle_joint_try(nSEXP, ploidySEXP, seqSEXP, biasSEXP, odSEXP, distSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// eta_double
double eta_double(double p, double eps);
static SEXP _updog_eta_double_try(SEXP pSEXP, SEXP epsSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< double >::type p(pSEXP);
    Rcpp::traits::input_parameter< double >::type eps(epsSEXP);
    rcpp_result_gen = Rcpp::wrap(eta_double(p, eps));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_eta_double(SEXP pSEXP, SEXP epsSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_eta_double_try(pSEXP, epsSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// eta_fun
NumericVector eta_fun(NumericVector p, NumericVector eps);
static SEXP _updog_eta_fun_try(SEXP pSEXP, SEXP epsSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< NumericVector >::type p(pSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type eps(epsSEXP);
    rcpp_result_gen = Rcpp::wrap(eta_fun(p, eps));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_eta_fun(SEXP pSEXP, SEXP epsSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_eta_fun_try(pSEXP, epsSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// xi_double
double xi_double(double p, double eps, double h);
static SEXP _updog_xi_double_try(SEXP pSEXP, SEXP epsSEXP, SEXP hSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< double >::type p(pSEXP);
    Rcpp::traits::input_parameter< double >::type eps(epsSEXP);
    Rcpp::traits::input_parameter< double >::type h(hSEXP);
    rcpp_result_gen = Rcpp::wrap(xi_double(p, eps, h));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_xi_double(SEXP pSEXP, SEXP epsSEXP, SEXP hSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_xi_double_try(pSEXP, epsSEXP, hSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// xi_fun
NumericVector xi_fun(NumericVector p, NumericVector eps, NumericVector h);
static SEXP _updog_xi_fun_try(SEXP pSEXP, SEXP epsSEXP, SEXP hSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< NumericVector >::type p(pSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type eps(epsSEXP);
    Rcpp::traits::input_parameter< NumericVector >::type h(hSEXP);
    rcpp_result_gen = Rcpp::wrap(xi_fun(p, eps, h));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_xi_fun(SEXP pSEXP, SEXP epsSEXP, SEXP hSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_xi_fun_try(pSEXP, epsSEXP, hSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// log_sum_exp
double log_sum_exp(NumericVector x);
static SEXP _updog_log_sum_exp_try(SEXP xSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< NumericVector >::type x(xSEXP);
    rcpp_result_gen = Rcpp::wrap(log_sum_exp(x));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_log_sum_exp(SEXP xSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_log_sum_exp_try(xSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// log_sum_exp_2
double log_sum_exp_2(double x, double y);
static SEXP _updog_log_sum_exp_2_try(SEXP xSEXP, SEXP ySEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< double >::type x(xSEXP);
    Rcpp::traits::input_parameter< double >::type y(ySEXP);
    rcpp_result_gen = Rcpp::wrap(log_sum_exp_2(x, y));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_log_sum_exp_2(SEXP xSEXP, SEXP ySEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_log_sum_exp_2_try(xSEXP, ySEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// logit
double logit(double x);
static SEXP _updog_logit_try(SEXP xSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< double >::type x(xSEXP);
    rcpp_result_gen = Rcpp::wrap(logit(x));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_logit(SEXP xSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_logit_try(xSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}
// expit
double expit(double x);
static SEXP _updog_expit_try(SEXP xSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::traits::input_parameter< double >::type x(xSEXP);
    rcpp_result_gen = Rcpp::wrap(expit(x));
    return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _updog_expit(SEXP xSEXP) {
    SEXP rcpp_result_gen;
    {
        Rcpp::RNGScope rcpp_rngScope_gen;
        rcpp_result_gen = PROTECT(_updog_expit_try(xSEXP));
    }
    Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
    if (rcpp_isInterrupt_gen) {
        UNPROTECT(1);
        Rf_onintr();
    }
    bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
    if (rcpp_isLongjump_gen) {
        Rcpp::internal::resumeJump(rcpp_result_gen);
    }
    Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
    if (rcpp_isError_gen) {
        SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
        UNPROTECT(1);
        (Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
    }
    UNPROTECT(1);
    return rcpp_result_gen;
}

// validate (ensure exported C++ functions exist before calling them)
static int _updog_RcppExport_validate(const char* sig) { 
    static std::set<std::string> signatures;
    if (signatures.empty()) {
        signatures.insert("double(*dbetabinom_alpha_beta_double)(int,int,double,double,bool)");
        signatures.insert("double(*dbernbinom)(int,int,double,bool)");
        signatures.insert("double(*dbetabinom_double)(int,int,double,double,bool)");
        signatures.insert("NumericVector(*dbetabinom)(IntegerVector,IntegerVector,NumericVector,NumericVector,LogicalVector)");
        signatures.insert("double(*pbetabinom_double)(int,int,double,double,bool)");
        signatures.insert("NumericVector(*pbetabinom)(IntegerVector,IntegerVector,NumericVector,NumericVector,LogicalVector)");
        signatures.insert("int(*qbetabinom_double)(double,int,double,double)");
        signatures.insert("IntegerVector(*qbetabinom)(NumericVector,IntegerVector,NumericVector,NumericVector)");
        signatures.insert("int(*rbetabinom_int)(int,double,double)");
        signatures.insert("IntegerVector(*rbetabinom)(int,IntegerVector,NumericVector,NumericVector)");
        signatures.insert("double(*oracle_mis)(int,int,double,double,double,NumericVector)");
        signatures.insert("NumericVector(*oracle_mis_vec)(int,int,double,double,double,NumericVector)");
        signatures.insert("NumericMatrix(*oracle_joint)(int,int,double,double,double,NumericVector)");
        signatures.insert("double(*eta_double)(double,double)");
        signatures.insert("NumericVector(*eta_fun)(NumericVector,NumericVector)");
        signatures.insert("double(*xi_double)(double,double,double)");
        signatures.insert("NumericVector(*xi_fun)(NumericVector,NumericVector,NumericVector)");
        signatures.insert("double(*log_sum_exp)(NumericVector)");
        signatures.insert("double(*log_sum_exp_2)(double,double)");
        signatures.insert("double(*logit)(double)");
        signatures.insert("double(*expit)(double)");
    }
    return signatures.find(sig) != signatures.end();
}

// registerCCallable (register entry points for exported C++ functions)
RcppExport SEXP _updog_RcppExport_registerCCallable() { 
    R_RegisterCCallable("updog", "_updog_dbetabinom_alpha_beta_double", (DL_FUNC)_updog_dbetabinom_alpha_beta_double_try);
    R_RegisterCCallable("updog", "_updog_dbernbinom", (DL_FUNC)_updog_dbernbinom_try);
    R_RegisterCCallable("updog", "_updog_dbetabinom_double", (DL_FUNC)_updog_dbetabinom_double_try);
    R_RegisterCCallable("updog", "_updog_dbetabinom", (DL_FUNC)_updog_dbetabinom_try);
    R_RegisterCCallable("updog", "_updog_pbetabinom_double", (DL_FUNC)_updog_pbetabinom_double_try);
    R_RegisterCCallable("updog", "_updog_pbetabinom", (DL_FUNC)_updog_pbetabinom_try);
    R_RegisterCCallable("updog", "_updog_qbetabinom_double", (DL_FUNC)_updog_qbetabinom_double_try);
    R_RegisterCCallable("updog", "_updog_qbetabinom", (DL_FUNC)_updog_qbetabinom_try);
    R_RegisterCCallable("updog", "_updog_rbetabinom_int", (DL_FUNC)_updog_rbetabinom_int_try);
    R_RegisterCCallable("updog", "_updog_rbetabinom", (DL_FUNC)_updog_rbetabinom_try);
    R_RegisterCCallable("updog", "_updog_oracle_mis", (DL_FUNC)_updog_oracle_mis_try);
    R_RegisterCCallable("updog", "_updog_oracle_mis_vec", (DL_FUNC)_updog_oracle_mis_vec_try);
    R_RegisterCCallable("updog", "_updog_oracle_joint", (DL_FUNC)_updog_oracle_joint_try);
    R_RegisterCCallable("updog", "_updog_eta_double", (DL_FUNC)_updog_eta_double_try);
    R_RegisterCCallable("updog", "_updog_eta_fun", (DL_FUNC)_updog_eta_fun_try);
    R_RegisterCCallable("updog", "_updog_xi_double", (DL_FUNC)_updog_xi_double_try);
    R_RegisterCCallable("updog", "_updog_xi_fun", (DL_FUNC)_updog_xi_fun_try);
    R_RegisterCCallable("updog", "_updog_log_sum_exp", (DL_FUNC)_updog_log_sum_exp_try);
    R_RegisterCCallable("updog", "_updog_log_sum_exp_2", (DL_FUNC)_updog_log_sum_exp_2_try);
    R_RegisterCCallable("updog", "_updog_logit", (DL_FUNC)_updog_logit_try);
    R_RegisterCCallable("updog", "_updog_expit", (DL_FUNC)_updog_expit_try);
    R_RegisterCCallable("updog", "_updog_RcppExport_validate", (DL_FUNC)_updog_RcppExport_validate);
    return R_NilValue;
}

static const R_CallMethodDef CallEntries[] = {
    {"_updog_dbetabinom_alpha_beta_double", (DL_FUNC) &_updog_dbetabinom_alpha_beta_double, 5},
    {"_updog_dbernbinom", (DL_FUNC) &_updog_dbernbinom, 4},
    {"_updog_dbetabinom_double", (DL_FUNC) &_updog_dbetabinom_double, 5},
    {"_updog_dbetabinom", (DL_FUNC) &_updog_dbetabinom, 5},
    {"_updog_pbetabinom_double", (DL_FUNC) &_updog_pbetabinom_double, 5},
    {"_updog_pbetabinom", (DL_FUNC) &_updog_pbetabinom, 5},
    {"_updog_qbetabinom_double", (DL_FUNC) &_updog_qbetabinom_double, 4},
    {"_updog_qbetabinom", (DL_FUNC) &_updog_qbetabinom, 4},
    {"_updog_rbetabinom_int", (DL_FUNC) &_updog_rbetabinom_int, 3},
    {"_updog_rbetabinom", (DL_FUNC) &_updog_rbetabinom, 4},
    {"_updog_wem_fixp", (DL_FUNC) &_updog_wem_fixp, 8},
    {"_updog_wem_obj", (DL_FUNC) &_updog_wem_obj, 4},
    {"_updog_wem", (DL_FUNC) &_updog_wem, 6},
    {"_updog_get_wik_mat", (DL_FUNC) &_updog_get_wik_mat, 7},
    {"_updog_get_genotype_likelihoods", (DL_FUNC) &_updog_get_genotype_likelihoods, 6},
    {"_updog_flexdog_obj", (DL_FUNC) &_updog_flexdog_obj, 13},
    {"_updog_f1_obj", (DL_FUNC) &_updog_f1_obj, 3},
    {"_updog_grad_for_mu_sigma2", (DL_FUNC) &_updog_grad_for_mu_sigma2, 5},
    {"_updog_grad_for_mu_sigma2_wrapper", (DL_FUNC) &_updog_grad_for_mu_sigma2_wrapper, 4},
    {"_updog_dpen_dh", (DL_FUNC) &_updog_dpen_dh, 3},
    {"_updog_dpen_deps", (DL_FUNC) &_updog_dpen_deps, 3},
    {"_updog_dlbeta_dc", (DL_FUNC) &_updog_dlbeta_dc, 4},
    {"_updog_dc_dtau", (DL_FUNC) &_updog_dc_dtau, 1},
    {"_updog_dlbeta_dtau", (DL_FUNC) &_updog_dlbeta_dtau, 6},
    {"_updog_dlbeta_dxi", (DL_FUNC) &_updog_dlbeta_dxi, 4},
    {"_updog_dxi_dh", (DL_FUNC) &_updog_dxi_dh, 3},
    {"_updog_dlbeta_dh", (DL_FUNC) &_updog_dlbeta_dh, 6},
    {"_updog_dxi_df", (DL_FUNC) &_updog_dxi_df, 2},
    {"_updog_df_deps", (DL_FUNC) &_updog_df_deps, 2},
    {"_updog_dlbeta_deps", (DL_FUNC) &_updog_dlbeta_deps, 6},
    {"_updog_grad_for_eps", (DL_FUNC) &_updog_grad_for_eps, 14},
    {"_updog_grad_for_weighted_lbb", (DL_FUNC) &_updog_grad_for_weighted_lbb, 3},
    {"_updog_grad_for_weighted_lnorm", (DL_FUNC) &_updog_grad_for_weighted_lnorm, 3},
    {"_updog_post_prob", (DL_FUNC) &_updog_post_prob, 6},
    {"_updog_compute_all_post_prob", (DL_FUNC) &_updog_compute_all_post_prob, 5},
    {"_updog_compute_all_log_bb", (DL_FUNC) &_updog_compute_all_log_bb, 6},
    {"_updog_compute_all_phifk", (DL_FUNC) &_updog_compute_all_phifk, 3},
    {"_updog_pen_bias", (DL_FUNC) &_updog_pen_bias, 3},
    {"_updog_pen_seq_error", (DL_FUNC) &_updog_pen_seq_error, 3},
    {"_updog_obj_for_rho", (DL_FUNC) &_updog_obj_for_rho, 6},
    {"_updog_obj_for_alpha", (DL_FUNC) &_updog_obj_for_alpha, 6},
    {"_updog_obj_for_eps", (DL_FUNC) &_updog_obj_for_eps, 14},
    {"_updog_obj_for_mu_sigma2", (DL_FUNC) &_updog_obj_for_mu_sigma2, 5},
    {"_updog_obj_for_mu_sigma2_wrapper", (DL_FUNC) &_updog_obj_for_mu_sigma2_wrapper, 4},
    {"_updog_elbo", (DL_FUNC) &_updog_elbo, 12},
    {"_updog_obj_for_weighted_lbb", (DL_FUNC) &_updog_obj_for_weighted_lbb, 3},
    {"_updog_obj_for_weighted_lnorm", (DL_FUNC) &_updog_obj_for_weighted_lnorm, 3},
    {"_updog_oracle_mis", (DL_FUNC) &_updog_oracle_mis, 6},
    {"_updog_oracle_mis_vec", (DL_FUNC) &_updog_oracle_mis_vec, 6},
    {"_updog_oracle_joint", (DL_FUNC) &_updog_oracle_joint, 6},
    {"_updog_eta_double", (DL_FUNC) &_updog_eta_double, 2},
    {"_updog_eta_fun", (DL_FUNC) &_updog_eta_fun, 2},
    {"_updog_xi_double", (DL_FUNC) &_updog_xi_double, 3},
    {"_updog_xi_fun", (DL_FUNC) &_updog_xi_fun, 3},
    {"_updog_log_sum_exp", (DL_FUNC) &_updog_log_sum_exp, 1},
    {"_updog_log_sum_exp_2", (DL_FUNC) &_updog_log_sum_exp_2, 2},
    {"_updog_logit", (DL_FUNC) &_updog_logit, 1},
    {"_updog_expit", (DL_FUNC) &_updog_expit, 1},
    {"_updog_RcppExport_registerCCallable", (DL_FUNC) &_updog_RcppExport_registerCCallable, 0},
    {NULL, NULL, 0}
};

RcppExport void R_init_updog(DllInfo *dll) {
    R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
    R_useDynamicSymbols(dll, FALSE);
}
