R/RcppExports.R

Defines functions get_map minus_loglikeli_c samp_posts_c get_posts_c thetas_to_priors_c na_omit_c

Documented in get_map get_posts_c minus_loglikeli_c na_omit_c samp_posts_c thetas_to_priors_c

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

#' Remove NAs from a vector
#'
#' This function is needed for the direct translation of the R functions to C++. This function is 
#' taken from StackOverflow approximately: https://stackoverflow.com/questions/19156353/remove-na-values-efficiently
#'
#' @param x a vector (possibly with NAs)
#' 
#' @export
#' @examples
#' na_omit_c(c(NA,5,10,NA,303))
na_omit_c <- function(x) {
    .Call(`_NPVecchia_na_omit_c`, x)
}

#' Transforms hyperparameters to priors
#' 
#' This is the C++ version of \code{\link{thetas_to_priors}}. See there for further documentation.
#' 
#' @param thetas 3 real numbers representing the three hyperparameters
#' @param n the number of locations
#' @param thresh the threshold for determining the number of neighbors based on the third
#' hyperparameter, defaults to 1e-3
#' 
#' It is often about the same speed as the R version of this function due to little computational cost.
thetas_to_priors_c <- function(thetas, n, thresh = 1e-3) {
    .Call(`_NPVecchia_thetas_to_priors_c`, thetas, n, thresh)
}

#' Gets posteriors of Bayesian methodology
#' 
#' This is the C++ version of \code{\link{get_posts}}. See there for further documentation.
#' 
#' @param datum an N * n matrix of the data (N replications of n locations/variables)
#' @param priors a list of length 3 containing the priors for the shape of the IG prior,
#'    the scale of the IG prior, and the prior variances of the coefficients (i.e. the output from
#'    thetas_to_priors)
#' @param NNarray an n * m2 matrix giving the m nearest neighbors previous in the ordering (or
#'    outputting NAs if not available [i.e. there are not m previous points]) that are ordered
#'    from closest to furthest away. It is OK to have m2 > m, as it will be reduced to match the size
#'    of the matrix g, but never have m2 < 2.
#' 
get_posts_c <- function(datum, priors, NNarray) {
    .Call(`_NPVecchia_get_posts_c`, datum, priors, NNarray)
}

#' Creates posterior mean sparse matrix from posteriors
#' 
#' This is the C++ version of \code{\link{samp_posts}}. See there for further documentation. Currently,
#' this does not have the added Bayesian and uhat functionality of samp_posts.
#' 
#' @param posts a List of the posteriors from get_posts (or get_posts_c); alternatively it can be
#' custom values as long as the sizes match the output from get_posts.
#' @param NNarray an n * m2 matrix giving the m nearest neighbors previous in the ordering (or
#'    outputting NAs if not available [i.e. there are not m previous points]) that are ordered
#'    from closest to furthest away. It is OK to have m2 large, as it will be reduced to match the size
#'    of the posterior means (i.e. number of columns in the third element of the posteriors), but
#'    never have m2 < 2.
#'    
samp_posts_c <- function(posts, NNarray) {
    .Call(`_NPVecchia_samp_posts_c`, posts, NNarray)
}

#' Calculates the integrated log likelihood
#' 
#' This is the C++ version of \code{\link{minus_loglikeli}}. See there for further documentation.
#' 
#' This function is much faster than the R version, making it preferable.
#' 
#' @param thetas 3 real numbers representing the three hyperparameters
#' @param datum an N * n matrix of the data (N replications of n locations/variables)
#' @param NNarray an n * m2 matrix giving the m nearest neighbors previous in the ordering (or
#'   outputting NAs if not available [i.e. there are not m previous points]) that are ordered
#'   from closest to furthest away. It is OK to have m2 large, as it will be reduced to match the size
#'   of the posterior means (i.e. number of columns in the third element of the posteriors), but
#'   never have m2 < 2.
#' @param threshh threshold for number of neighbors (for thetas_to_priors); defaults
#'   to 1e-3
#' @param negativ boolean defaulting to true; if false, the positive log-likelihood is returned
#'   
minus_loglikeli_c <- function(thetas, datum, NNarray, threshh = 1e-3, negativ = TRUE) {
    .Call(`_NPVecchia_minus_loglikeli_c`, thetas, datum, NNarray, threshh, negativ)
}

#' Creates MAP (maximum a posteriori) sparse matrix from thetas
#' 
#' This is basically a combination of thetas_to_priors, get_posts, and samp_posts so one does not
#' have to store the posteriors in memory (that is more for Bayesian uses).
#' 
#' @param thetas 3 real numbers representing the three hyperparameters
#' @param datum an N * n matrix of the data (N replications of n locations/variables)
#' @param NNarray an n * m2 matrix giving the m nearest neighbors previous in the ordering (or
#'   outputting NAs if not available [i.e. there are not m previous points]) that are ordered
#'   from closest to furthest away. It is OK to have m2 large, as it will be reduced to match the size
#'   of the posterior means (i.e. number of columns in the third element of the posteriors), but
#'   never have m2 < 2.
#' @param threshh threshold for number of neighbors (for thetas_to_priors); defaults
#'   to 1e-3
#'   
get_map <- function(thetas, datum, NNarray, threshh = 1e-3) {
    .Call(`_NPVecchia_get_map`, thetas, datum, NNarray, threshh)
}
katzfuss-group/NPvecchia documentation built on April 15, 2022, 2:23 a.m.