R/RcppExports.R

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

#' This is an Rcpp implementation of the hc function from the mclust package. This will be used while implementing the Mclust function.
#' @param x    A (n x d) matrix of observed data 
#' @return A numeric two-column matrix in which the ith row gives the minimum index for observations in each of the two clusters merged at the ith stage of agglomerative hierarchical clustering.
hc_fn <- function(x) {
    .Call(`_nwREM_hc_fn`, x)
}

#' This is an Rcpp implementation of the emControl function from the mclust package. This will be used while implementing the Mclust function.
#' @param itmax  Maximum number of iterations for Mclust()
#' @return A named list in which the names are the names of the arguments and the values are the values supplied to the arguments.
emControl_fn <- function(itmax) {
    .Call(`_nwREM_emControl_fn`, itmax)
}

#' Implements the Mclust() function from library mclust.
#' @param x    A (n x d) matrix of observed data 
#' @param k    The number of mixing components
#' @return A list of parameter estimates that will be used for the initial parameter estimates in the EM algorithm.
Mclust_fn <- function(x, k) {
    .Call(`_nwREM_Mclust_fn`, x, k)
}

#' Function to evaluate likelihood or log-likelihood of multivariate normal using armadillo
#' @param x    (n x d) matrix of observed data 
#' @param mean  Row vector (d) of means   
#' @param sigma (d x d) matrix of covariance
#' @param logd boolean indicating log-likelihood (true) or likelihood (false) is returned
#' @return a size n vector of log-likelihoods
dmvnrm_arma <- function(x, mean, sigma, logd = FALSE) {
    .Call(`_nwREM_dmvnrm_arma`, x, mean, sigma, logd)
}

#' Function to calculate the Mahalanobis distance. Credit: Rcpp gallery.
#' @param x    (n x d) matrix of observed data 
#' @param center  Row vector (d) of means   
#' @param cov (d x d) matrix of covariance
Mahalanobis <- function(x, center, cov) {
    .Call(`_nwREM_Mahalanobis`, x, center, cov)
}

#' Implements the EM algorithm on mvGMM data
#' @param x        A (n x d) matrix of observed data 
#' @param k        The number of mixing components
#' @param lambda   Final value for regularization parameter - will go lambda^10 to lambda. Lambda will automatically equal infinity, if not specified. This is equivalent to a standard EM algorithm
#' @param max_it   Maximum number of iterations
#' @param tol      Relative tolerance of likelihood at convergence
#' @return A list containing the following values:
#' * llk     : Likelihood of final iteration
#' * mus     : (d x k) of estimated means
#' * mix_prop : size k vector of estimated mixing proportions
#' * covs    : (d x d x k) vectors of estimated standard deviations
#' * probs : Matrix (n x k) of the probabilties of observed values in each cluster
#' * classification Size n vector of most likely cluster for each observed value
#' * iter    : number of iterations
em_alg_GMM <- function(x, k, lambda, max_it, tol) {
    .Call(`_nwREM_em_alg_GMM`, x, k, lambda, max_it, tol)
}
nwakim/nwREM documentation built on May 22, 2019, 5:34 p.m.