R/prior_clusters.R

Defines functions PriorClusters.dirichletprocess PriorClusters

Documented in PriorClusters

#' Draw prior clusters and weights from the Dirichlet process
#'
#' @param dpobj A Dirichlet process object
#' @return A list of weights and parameters of the prior distribution of the Dirichcet process

#' @export
PriorClusters <- function(dpobj) UseMethod("PriorClusters")

#' @export
PriorClusters.dirichletprocess <- function(dpobj){


  alpha <- rgamma(1, dpobj$alphaPriorParameters[1], dpobj$alphaPriorParameters[2])
  numBreaks <- ceiling(alpha) * 20 + 5
  sticks <- StickBreaking(alpha, numBreaks)


  priorParams <- PriorDraw(dpobj$mixingDistribution, numBreaks)

  returnList <- list(weights = sticks, params = priorParams)

  return(returnList)
}

Try the dirichletprocess package in your browser

Any scripts or data that you put into this service are public.

dirichletprocess documentation built on Aug. 25, 2023, 5:19 p.m.