R/objective_clustering.R

Defines functions objective_clustering

Documented in objective_clustering

#' objective clustering cost
#'
#' Auxiliary function to calculate a cost function for clustering. Modified
#' version of \code{Cost_func()} from \code{Khorshidi et al., 2019}.
#'
#' @keywords internal
#'
#' @param Alloc_Dist list with Distance to cluster centers and allocation
#'   matrix, as obtained with \code{Allocation_Distance()}.
#'
#' @return matrix
objective_clustering <- function(Alloc_Dist){
  tmp <- Alloc_Dist$Allocation * Alloc_Dist$Distance
  A <-
    sum(colSums(tmp) / apply(
      tmp,
      2,
      FUN = function(x) {
        length(x[x != 0])
      }
    ), na.rm = TRUE)
  return(A)
}

Try the doMIsaul package in your browser

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

doMIsaul documentation built on Oct. 19, 2021, 1:07 a.m.