CAF-HFCM (Centroid Auto-Fused Hierarchical FCM) Documentationο
π Overviewο
CAFHFCM is a fuzzy clustering algorithm that integrates traditional FCM with a centroid fusion regularization. The method promotes centroid merging by minimizing both distance-to-centroid loss and an L2 penalty encouraging centroid similarity.
βοΈ Class Definitionο
Class Name: CAFHFCM
This class implements the Centroid Auto-Fused Hierarchical FCM clustering algorithm.
class CAFHFCM:
def __init__(self, c: int, m: float = 2.0, alpha: float = 0.1,
max_iter: int = 100, tol: float = 1e-5):
self.c = c
self.m = m
self.alpha = alpha
self.max_iter = max_iter
self.tol = tol
π Parametersο
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
int |
β |
Number of clusters |
|
float |
2.0 |
Fuzziness coefficient |
|
float |
0.1 |
Fusion regularization weight |
|
int |
100 |
Maximum number of iterations |
|
float |
1e-5 |
Tolerance for centroid convergence |
π Usage Examplesο
from soft_clustering._cafhfcm._cafhfcm import CAFHFCM
import numpy as np
X = np.vstack([
np.random.normal(loc=[1, 1], scale=0.5, size=(50, 2)),
np.random.normal(loc=[5, 5], scale=0.5, size=(50, 2))
])
model = CAFHFCM(c=2, m=2.0, alpha=0.1)
labels, memberships = model.fit_predict(X)
print("Labels:", labels)
print("Memberships:", memberships)
π₯ Input / π€ Outputο
Input to
fit_predict(X):X (np.ndarray): Input data of shape (N x D)
Returns:
labels (np.ndarray): Hard cluster labels (N,)U (np.ndarray): Soft membership matrix (N x C)
π οΈ Methodsο
__init__(...): Initializes the modelfit_predict(X): Runs the CAFHFCM algorithm and returns labels and memberships
π Implementation Notesο
The algorithm updates membership matrix and centroids iteratively
The centroid update includes a penalty for centroid differences
Promotes centroid fusion when data distribution is hierarchical
π Referenceο
This implementation is based on:
βA Centroid Auto-Fused Hierarchical Fuzzy c-Means Clusteringβ
by L. Yu, Y. Pan, J. Wu, and J. Zhao.