R/generic_VB_aspect.R

Defines functions VB_aspectRcpp VB_aspect

Documented in VB_aspect

#' @title Collapsed VB for the Dirichlet-Bernoulli model
#' @description Collapsed Variational Inference under the Truncated Symmetric Dirichlet Prior
#' Instead of computing the real limit K -> inf, we keep the origial Dirichlet-Multinomial
#' with a large K and Dirichlet parameters alpha/K
VB_aspect <-function(V, Z, K, 
                               alpha = 1, beta =1, gamma=1, 
                               iter=100){
  
  res <- algo_VB_aspect(V, Z, K, alpha=alpha, beta=beta, gamma=gamma, iter=iter)
  if(!all(res$E_W>=0)) {stop("E_W contains negative values")}
  if(!all(res$E_H>=0)) {stop("E_W contains negative values")}
  class(res) <- c("VBaspect", "VBBernoulli", "Bernoulli")

  res
}

#' @title Collapsed VB for the Dirichlet-Bernoulli model
#' @description Collapsed Variational Inference under the Truncated Symmetric Dirichlet Prior
#' Instead of computing the real limit K -> inf, we keep the origial Dirichlet-Multinomial
#' with a large K and Dirichlet parameters alpha/K
VB_aspectRcpp <-function(V, Z, K, 
                     alpha = 1, beta =1, gamma=1, 
                     iter=100){
  
  # In Rcpp, the first label is 0
  Z <- Z - min(Z, na.rm=TRUE)
  
  #res <- algo_VB_aspect(V, Z, K, alpha=alpha, beta=beta, gamma=gamma, iter=iter)
  res <- VB_Aspect_Rcpp(V, Z, K, alpha = alpha, beta=beta, gamma=gamma, iter=iter)  
  if(!all(res$E_W>=0)) {stop("E_W contains negative values")}
  if(!all(res$E_H>=0)) {stop("E_W contains negative values")}
  class(res) <- c("VBaspect", "VBBernoulli", "Bernoulli")
  
  res
}
alumbreras/NBMF documentation built on July 28, 2020, 9:58 a.m.