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

#' Compute the BPS weights by convex optimization
#'
#' @param scores [matrix] \eqn{N \times K} of expected predictive density evaluations for the K models considered
#'
#' @return conv_opt [function] to perform convex optimiazion with CVXR R package
#'
CVXR_opt <- function(scores) {
    .Call(`_spBPS_CVXR_opt`, scores)
}

#' Combine subset models wiht BPS
#'
#' @param fit_list [list] K fitted model outputs composed by two elements each: first named \eqn{epd}, second named \eqn{W}
#' @param K [integer] number of folds
#' @param rp [double] percentage of observations to take into account for optimization (\code{default=1})
#'
#' @return [matrix] posterior predictive density evaluations (each columns represent a different model)
#'
BPS_combine <- function(fit_list, K, rp) {
    .Call(`_spBPS_BPS_combine`, fit_list, K, rp)
}

#' Combine subset models wiht Pseudo-BMA
#'
#' @param fit_list [list] K fitted model outputs composed by two elements each: first named \eqn{epd}, second named \eqn{W}
#'
#' @return [matrix] posterior predictive density evaluations (each columns represent a different model)
#'
BPS_PseudoBMA <- function(fit_list) {
    .Call(`_spBPS_BPS_PseudoBMA`, fit_list)
}

#' Compute the parameters for the posteriors distribution of \eqn{\beta} and \eqn{\Sigma} (i.e. updated parameters)
#'
#' @param data [list] two elements: first named \eqn{Y}, second named \eqn{X}
#' @param priors [list] priors: named \eqn{\mu_B},\eqn{V_r},\eqn{\Psi},\eqn{\nu}
#' @param coords [matrix] sample coordinates for X and Y
#' @param hyperpar [list] two elemets: first named \eqn{\alpha}, second named \eqn{\phi}
#'
#' @return [list] posterior update parameters
#'
fit_cpp_MvT <- function(data, priors, coords, hyperpar) {
    .Call(`_spBPS_fit_cpp_MvT`, data, priors, coords, hyperpar)
}

#' Sample R draws from the posterior distributions
#'
#' @param poster [list] output from \code{fit_cpp} function
#' @param R [integer] number of posterior samples
#' @param par if \code{TRUE} only \eqn{\beta} and \eqn{\Sigma} are sampled (\eqn{\omega} is omitted)
#' @param p [integer] if \code{par = TRUE}, it specifies the column number of \eqn{X}
#'
#' @return [list] posterior samples
#'
post_draws_MvT <- function(poster, R, par, p) {
    .Call(`_spBPS_post_draws_MvT`, poster, R, par, p)
}

#' Draw from the joint posterior predictive for a set of unobserved covariates
#'
#' @param data [list] two elements: first named \eqn{Y}, second named \eqn{X}
#' @param X_u [matrix] unobserved instances covariate matrix
#' @param d_u [matrix] unobserved instances distance matrix
#' @param d_us [matrix] cross-distance between unobserved and observed instances matrix
#' @param hyperpar [list] two elemets: first named \eqn{\alpha}, second named \eqn{\phi}
#' @param poster [list] output from \code{fit_cpp} function
#' @param R [integer] number of posterior predictive samples
#'
#' @return [list] posterior predictive samples
#'
r_pred_joint_MvT <- function(data, X_u, d_u, d_us, hyperpar, poster, R) {
    .Call(`_spBPS_r_pred_joint_MvT`, data, X_u, d_u, d_us, hyperpar, poster, R)
}

#' Draw from the joint posterior predictive for a set of unobserved covariates
#'
#' @param data [list] two elements: first named \eqn{Y}, second named \eqn{X}
#' @param X_u [matrix] unobserved instances covariate matrix
#' @param d_u [matrix] unobserved instances distance matrix
#' @param d_us [matrix] cross-distance between unobserved and observed instances matrix
#' @param hyperpar [list] two elemets: first named \eqn{\alpha}, second named \eqn{\phi}
#' @param poster [list] output from \code{fit_cpp} function
#' @param R [integer] number of posterior predictive samples
#'
#' @return [list] posterior predictive samples
#'
r_pred_marg_MvT <- function(data, X_u, d_u, d_us, hyperpar, poster, R) {
    .Call(`_spBPS_r_pred_marg_MvT`, data, X_u, d_u, d_us, hyperpar, poster, R)
}

#' Draw from the conditional posterior predictive for a set of unobserved covariates
#'
#' @param data [list] two elements: first named \eqn{Y}, second named \eqn{X}
#' @param X_u [matrix] unobserved instances covariate matrix
#' @param d_u [matrix] unobserved instances distance matrix
#' @param d_us [matrix] cross-distance between unobserved and observed instances matrix
#' @param hyperpar [list] two elemets: first named \eqn{\alpha}, second named \eqn{\phi}
#' @param poster [list] output from \code{fit_cpp_MvT} function
#' @param post [list] output from \code{post_draws_MvT} function
#'
#' @return [list] posterior predictive samples
#'
r_pred_cond_MvT <- function(data, X_u, d_u, d_us, hyperpar, poster, post) {
    .Call(`_spBPS_r_pred_cond_MvT`, data, X_u, d_u, d_us, hyperpar, poster, post)
}

#' Evaluate the density of a set of unobserved response with respect to the conditional posterior predictive
#'
#' @param data [list] two elements: first named \eqn{Y}, second named \eqn{X}
#' @param X_u [matrix] unobserved instances covariate matrix
#' @param Y_u [matrix] unobserved instances response matrix
#' @param d_u [matrix] unobserved instances distance matrix
#' @param d_us [matrix] cross-distance between unobserved and observed instances matrix
#' @param hyperpar [list] two elemets: first named \eqn{\alpha}, second named \eqn{\phi}
#' @param poster [list] output from \code{fit_cpp} function
#'
#' @return [double] posterior predictive density evaluation
#'
d_pred_cpp_MvT <- function(data, X_u, Y_u, d_u, d_us, hyperpar, poster) {
    .Call(`_spBPS_d_pred_cpp_MvT`, data, X_u, Y_u, d_u, d_us, hyperpar, poster)
}

#' Compute the LOOCV of the density evaluations for fixed values of the hyperparameters
#'
#' @param data [list] two elements: first named \eqn{Y}, second named \eqn{X}
#' @param priors [list] priors: named \eqn{\mu_B},\eqn{V_r},\eqn{\Psi},\eqn{\nu}
#' @param coords [matrix] sample coordinates for X and Y
#' @param hyperpar [list] two elemets: first named \eqn{\alpha}, second named \eqn{\phi}
#'
#' @return [vector] posterior predictive density evaluations
#'
dens_loocv_MvT <- function(data, priors, coords, hyperpar) {
    .Call(`_spBPS_dens_loocv_MvT`, data, priors, coords, hyperpar)
}

#' Compute the KCV of the density evaluations for fixed values of the hyperparameters
#'
#' @param data [list] two elements: first named \eqn{Y}, second named \eqn{X}
#' @param priors [list] priors: named \eqn{\mu_B},\eqn{V_r},\eqn{\Psi},\eqn{\nu}
#' @param coords [matrix] sample coordinates for X and Y
#' @param hyperpar [list] two elemets: first named \eqn{\alpha}, second named \eqn{\phi}
#' @param K [integer] number of folds
#'
#' @return [vector] posterior predictive density evaluations
#'
dens_kcv_MvT <- function(data, priors, coords, hyperpar, K) {
    .Call(`_spBPS_dens_kcv_MvT`, data, priors, coords, hyperpar, K)
}

#' Return the CV predictive density evaluations for all the model combinations
#'
#' @param data [list] two elements: first named \eqn{Y}, second named \eqn{X}
#' @param priors [list] priors: named \eqn{\mu_B},\eqn{V_r},\eqn{\Psi},\eqn{\nu}
#' @param coords [matrix] sample coordinates for X and Y
#' @param hyperpar [list] two elemets: first named \eqn{\alpha}, second named \eqn{\phi}
#' @param useKCV if \code{TRUE} K-fold cross validation is used instead of LOOCV (no \code{default})
#' @param K [integer] number of folds
#'
#' @return [matrix] posterior predictive density evaluations (each columns represent a different model)
#'
models_dens_MvT <- function(data, priors, coords, hyperpar, useKCV, K) {
    .Call(`_spBPS_models_dens_MvT`, data, priors, coords, hyperpar, useKCV, K)
}

#' Compute the BPS weights by convex optimization
#'
#' @param data [list] two elements: first named \eqn{Y}, second named \eqn{X}
#' @param priors [list] priors: named \eqn{\mu_B},\eqn{V_r},\eqn{\Psi},\eqn{\nu}
#' @param coords [matrix] sample coordinates for X and Y
#' @param hyperpar [list] two elemets: first named \eqn{\alpha}, second named \eqn{\phi}
#' @param K [integer] number of folds
#'
#' @return [matrix] posterior predictive density evaluations (each columns represent a different model)
#'
BPS_weights_MvT <- function(data, priors, coords, hyperpar, K) {
    .Call(`_spBPS_BPS_weights_MvT`, data, priors, coords, hyperpar, K)
}

#' Compute the BPS spatial prediction given a set of stacking weights
#'
#' @param data [list] two elements: first named \eqn{Y}, second named \eqn{X}
#' @param X_u [matrix] unobserved instances covariate matrix
#' @param priors [list] priors: named \eqn{\mu_B},\eqn{V_r},\eqn{\Psi},\eqn{\nu}
#' @param coords [matrix] sample coordinates for X and Y
#' @param crd_u [matrix] unboserved instances coordinates
#' @param hyperpar [list] two elemets: first named \eqn{\alpha}, second named \eqn{\phi}
#' @param W [matrix] set of stacking weights
#' @param R [integer] number of desired samples
#'
#' @return [list] BPS posterior predictive samples
#'
BPS_pred_MvT <- function(data, X_u, priors, coords, crd_u, hyperpar, W, R) {
    .Call(`_spBPS_BPS_pred_MvT`, data, X_u, priors, coords, crd_u, hyperpar, W, R)
}

#' Perform the BPS sampling from posterior and posterior predictive given a set of stacking weights
#'
#' @param data [list] two elements: first named \eqn{Y}, second named \eqn{X}
#' @param X_u [matrix] unobserved instances covariate matrix
#' @param priors [list] priors: named \eqn{\mu_B},\eqn{V_r},\eqn{\Psi},\eqn{\nu}
#' @param coords [matrix] sample coordinates for X and Y
#' @param crd_u [matrix] unboserved instances coordinates
#' @param hyperpar [list] two elemets: first named \eqn{\alpha}, second named \eqn{\phi}
#' @param W [matrix] set of stacking weights
#' @param R [integer] number of desired samples
#'
#' @return [list] BPS posterior predictive samples
#'
BPS_post_MvT <- function(data, X_u, priors, coords, crd_u, hyperpar, W, R) {
    .Call(`_spBPS_BPS_post_MvT`, data, X_u, priors, coords, crd_u, hyperpar, W, R)
}

#' Compute the BPS posterior samples given a set of stacking weights
#'
#' @param data [list] two elements: first named \eqn{Y}, second named \eqn{X}
#' @param priors [list] priors: named \eqn{\mu_B},\eqn{V_r},\eqn{\Psi},\eqn{\nu}
#' @param coords [matrix] sample coordinates for X and Y
#' @param hyperpar [list] two elemets: first named \eqn{\alpha}, second named \eqn{\phi}
#' @param W [matrix] set of stacking weights
#' @param R [integer] number of desired samples
#' @param par if \code{TRUE} only \eqn{\beta} and \eqn{\Sigma} are sampled (\eqn{\omega} is omitted)
#'
#' @return [matrix] BPS posterior samples
#'
BPS_postdraws_MvT <- function(data, priors, coords, hyperpar, W, R, par) {
    .Call(`_spBPS_BPS_postdraws_MvT`, data, priors, coords, hyperpar, W, R, par)
}

#' @keywords internal
BPS_post_all_subsets_v2 <- function(Y_list, X_list, crd_list, W_local_list, subset_ind, priors, hyperpar, n_cores) {
    .Call(`_spBPS_BPS_post_all_subsets_v2`, Y_list, X_list, crd_list, W_local_list, subset_ind, priors, hyperpar, n_cores)
}

#' @keywords internal
BPS_pred_streaming_v2 <- function(Y_list, X_list, crd_list, W_local_list, subset_ind, crd_u, X_u, priors, hyperpar, pred_batch_size, n_cores, return_summary, prob_lo, prob_hi) {
    .Call(`_spBPS_BPS_pred_streaming_v2`, Y_list, X_list, crd_list, W_local_list, subset_ind, crd_u, X_u, priors, hyperpar, pred_batch_size, n_cores, return_summary, prob_lo, prob_hi)
}

#' @keywords internal
fit_cpp_MvT_v2 <- function(data, priors, coords, hyperpar, iVr_pre) {
    .Call(`_spBPS_fit_cpp_MvT_v2`, data, priors, coords, hyperpar, iVr_pre)
}

#' @keywords internal
post_draws_MvT_v2 <- function(poster, R, par, p) {
    .Call(`_spBPS_post_draws_MvT_v2`, poster, R, par, p)
}

#' @keywords internal
d_pred_cpp_MvT_v2 <- function(data, X_u, Y_u, cross_d, hyperpar, poster, Lc_Psi) {
    .Call(`_spBPS_d_pred_cpp_MvT_v2`, data, X_u, Y_u, cross_d, hyperpar, poster, Lc_Psi)
}

#' @keywords internal
dens_kcv_MvT_v2 <- function(data, priors, coords, hyperpar, K) {
    .Call(`_spBPS_dens_kcv_MvT_v2`, data, priors, coords, hyperpar, K)
}

#' @keywords internal
models_dens_MvT_v2 <- function(data, priors, coords, hyperpar, K) {
    .Call(`_spBPS_models_dens_MvT_v2`, data, priors, coords, hyperpar, K)
}

#' @keywords internal
BPS_weights_MvT_v2 <- function(data, priors, coords, hyperpar, K) {
    .Call(`_spBPS_BPS_weights_MvT_v2`, data, priors, coords, hyperpar, K)
}

#' @keywords internal
BPS_combine_v2 <- function(fit_list, K, rp) {
    .Call(`_spBPS_BPS_combine_v2`, fit_list, K, rp)
}

#' @keywords internal
compute_all_local_weights_v2 <- function(Y_list, X_list, crd_list, priors, hyperpar, cv_folds, n_cores) {
    .Call(`_spBPS_compute_all_local_weights_v2`, Y_list, X_list, crd_list, priors, hyperpar, cv_folds, n_cores)
}

#' @keywords internal
BPS_post_MvT_v2 <- function(data, X_u, priors, coords, crd_u, hyperpar, W, R, d_u, Rphi_u_list, n_cores) {
    .Call(`_spBPS_BPS_post_MvT_v2`, data, X_u, priors, coords, crd_u, hyperpar, W, R, d_u, Rphi_u_list, n_cores)
}

#' @keywords internal
BPS_post_MvT_v2_batch <- function(data, X_u, priors, coords, crd_u, hyperpar, W, R, d_u, Rphi_u_list, n_cores, pred_batch_size) {
    .Call(`_spBPS_BPS_post_MvT_v2_batch`, data, X_u, priors, coords, crd_u, hyperpar, W, R, d_u, Rphi_u_list, n_cores, pred_batch_size)
}

#' @keywords internal
BPS_pred_all_subsets_v2 <- function(Y_list, X_list, crd_list, W_local_list, subset_ind, d_u, Rphi_u_list, X_u, crd_u, priors, hyperpar, pred_batch_size, n_cores) {
    .Call(`_spBPS_BPS_pred_all_subsets_v2`, Y_list, X_list, crd_list, W_local_list, subset_ind, d_u, Rphi_u_list, X_u, crd_u, priors, hyperpar, pred_batch_size, n_cores)
}

#' @keywords internal
BPS_postdraws_MvT_v2 <- function(data, priors, coords, hyperpar, W, R, par) {
    .Call(`_spBPS_BPS_postdraws_MvT_v2`, data, priors, coords, hyperpar, W, R, par)
}

#' @keywords internal
BPS_PseudoBMA_v2 <- function(fit_list, n_cores = 1L) {
    .Call(`_spBPS_BPS_PseudoBMA_v2`, fit_list, n_cores)
}

#' @keywords internal
dmatrix_t_test <- function(X, Lambda, SigmaR, SigmaC, nu, log_d = FALSE) {
    .Call(`_spBPS_dmatrix_t_test`, X, Lambda, SigmaR, SigmaC, nu, log_d)
}

#' Compute the Euclidean distance matrix
#'
#' @param X [matrix] (tipically of \eqn{N} coordindates on \eqn{\mathbb{R}^2} )
#'
#' @return [matrix] distance matrix of the elements of \eqn{X}
#'
#'
arma_dist <- function(X) {
    .Call(`_spBPS_arma_dist`, X)
}

#' Build a grid from two vector (i.e. equivalent to \code{expand.grid()} in \code{R})
#'
#' @param x [vector] first vector of numeric elements
#' @param y [vector] second vector of numeric elements
#'
#' @return [matrix] expanded grid of combinations
#'
#'
expand_grid_cpp <- function(x, y) {
    .Call(`_spBPS_expand_grid_cpp`, x, y)
}

#' Function to sample integers (index)
#'
#' @param size [integer] dimension of the set to sample
#' @param length [integer] number of elements to sample
#' @param p [vector] sampling probabilities
#'
#' @return [vector] sample of integers
#'
sample_index <- function(size, length, p) {
    .Call(`_spBPS_sample_index`, size, length, p)
}

#' Function to subset data for meta-analysis
#'
#' @param data [list] three elements: first named \eqn{Y}, second named \eqn{X}, third named \eqn{crd}
#' @param K [integer] number of desired subsets
#'
#' @return [list] subsets of data, and the set of indexes
#'
#' @export
subset_data <- function(data, K) {
    .Call(`_spBPS_subset_data`, data, K)
}

#' Function to subset data for meta-analysis
#'
#' @param mat [matrix] not-symmetric matrix
#'
#' @return [matrix] symmetric matrix (lower triangular of \code{mat} is used)
#'
forceSymmetry_cpp <- function(mat) {
    .Call(`_spBPS_forceSymmetry_cpp`, mat)
}

