#include #include #include "distprob.h" #include "distr.h" #include "utils.h" #ifdef _OPENMP #include #endif using namespace Rcpp; using namespace arma; // [[Rcpp::export]] double nll_gdistsamp(arma::vec beta, arma::uvec n_param, arma::vec y, int mixture, std::string keyfun, std::string survey, arma::mat Xlam, arma::vec Xlam_offset, arma::vec A, arma::mat Xphi, arma::vec Xphi_offset, arma::mat Xdet, arma::vec Xdet_offset, arma::vec db, arma::mat a, arma::mat u, arma::vec w, arma::vec k, arma::vec lfac_k, arma::vec lfac_kmyt, arma::vec kmyt, arma::uvec Kmin, int threads){ #ifdef _OPENMP omp_set_num_threads(threads); #endif int M = Xlam.n_rows; int T = Xphi.n_rows / M; int R = y.size() / M; unsigned J = R / T; int lk = k.size(); int K = lk - 1; //Abundance const vec lambda = exp(Xlam * beta_sub(beta, n_param, 0) + Xlam_offset) % A; double log_alpha = beta_sub(beta, n_param, 4)(0); //length 1 vector //Availability vec phi = ones(M*T); if(T > 1){ phi = inv_logit(Xphi * beta_sub(beta, n_param, 1) + Xphi_offset); } //Detection vec det_param(M*T); if(keyfun != "uniform"){ det_param = exp(Xdet * beta_sub(beta, n_param, 2) + Xdet_offset); } double scale = exp(beta_sub(beta, n_param, 3)(0)); double loglik = 0.0; #pragma omp parallel for reduction(+: loglik) if(threads > 1) for (int i=0; i