R/ClusterPBMIndex.R

Defines functions ClusterPBMIndex

Documented in ClusterPBMIndex

ClusterPBMIndex = function(Cls, Data) {
  # V=ClusterPBMIndex(Cls,Data)
  #
  # Crisp Pakhira-Bandyopadhyay-Maulik Index [Pakhira et al., 2004]
  #
  # INPUT
  # Cls[1:n]                 Numeric, character or factor cluster labels; no missing labels
  # Data[1:n,1:d]            Finite numeric matrix/data.frame; rows match Cls
  #
  # OUTPUT
  # List V with
  #   PBMIndex                 Crisp PBM index; larger values are better
  #   Object                   List of E1, Ek, Dk, Centers and ClusterLabels
  #
  # DETAILS
  # PBM = (E1 * Dk / (k * Ek))^2. E1 sums Euclidean distances to
  # the overall mean; Ek sums distances to the assigned centroid;
  # Dk is the largest distance between cluster centroids. Distances
  # in E1 and Ek are NOT squared. No scaling is done; multiplying
  # Data by a multiplies PBM by a^2. All labels including zero are
  # ordinary clusters. Requires k >= 2. Ek = 0 yields Inf if E1 * Dk
  # > 0, otherwise NaN, with a warning.
  #
  # Author: Michael Thrun, 11/2026
  #
  # [Pakhira et al., 2004] Pakhira, M. K., Bandyopadhyay, S., & Maulik, U.: Validity index for crisp and fuzzy clusters, Pattern Recognition, Vol. 37(3), pp. 487-501, DOI:10.1016/j.patcog.2003.06.005, 2004.
  #
  Input = internalClusterValidation(Cls, Data, "ClusterPBMIndex")
  Data = Input$Data
  Cls = Input$Cls
  Labels = Input$Labels
  ClusterNo = length(Labels)
  if (ClusterNo < 2L) {
    warning("ClusterPBMIndex: requires at least two clusters")
    return(list(PBMIndex = NaN, Object = NULL))
  }
  Centers = do.call(rbind, lapply(seq_len(ClusterNo), function(i)
    colMeans(Data[Cls == i, , drop = FALSE])))
  rownames(Centers) = as.character(Labels)
  E1 = sum(sqrt(rowSums(sweep(Data, 2L, colMeans(Data))^2)))
  Ek = sum(sqrt(rowSums((Data - Centers[Cls, , drop = FALSE])^2)))
  Dk = max(stats::dist(Centers))
  Score = (E1 / Ek * Dk / ClusterNo)^2
  if (Ek == 0) warning("ClusterPBMIndex: within-cluster dispersion is zero")
  return(list(PBMIndex = Score,
              Object = list(E1 = E1, Ek = Ek, Dk = Dk, Centers = Centers,
                            ClusterLabels = Labels)))
}

Try the FCPS package in your browser

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

FCPS documentation built on Nov. 28, 2026, 9:08 a.m.