CAFCM (Collaborative Annealing FCM) Documentationο
π Overviewο
CAFCM (Collaborative Annealing Fuzzy C-Means) is a fuzzy clustering algorithm that gradually sharpens membership assignments through an annealing process. It starts from a high fuzziness level and iteratively cools down the fuzziness parameter to encourage more deterministic (harder) cluster assignments.
βοΈ Class Definitionο
Class Name: CAFCM
class CAFCM:
def __init__(self, c: int, m_start: float = 2.0, m_end: float = 1.01,
cooling_rate: float = 0.95, max_iter: int = 100, tol: float = 1e-5):
self.c = c
self.m_start = m_start
self.m_end = m_end
self.cooling_rate = cooling_rate
self.max_iter = max_iter
self.tol = tol
This class implements the collaborative annealing version of Fuzzy C-Means.
π Parametersο
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
int |
β |
Number of clusters |
|
float |
2.0 |
Initial fuzziness degree |
|
float |
1.01 |
Final fuzziness degree (closer to 1 = more deterministic) |
|
float |
0.95 |
Multiplicative decay rate for |
|
int |
100 |
Maximum iterations per fuzziness step |
|
float |
1e-5 |
Convergence threshold for centroid updates |
π» Using Exampleο
from soft_clustering._cafcm._cafcm import CAFCM
import numpy as np
X = np.vstack([
np.random.normal(loc=[0, 0], scale=0.5, size=(50, 2)),
np.random.normal(loc=[4, 4], scale=0.5, size=(50, 2)),
])
model = CAFCM(c=2, m_start=2.0, m_end=1.01, cooling_rate=0.95)
labels, U = model.fit_predict(X)
print("Labels:", labels)
print("Membership Matrix:", U)
π₯ Input / π€ Outputο
Input to
fit_predict(X):X (np.ndarray): Input data array of shape (N x D)
Returns:
labels (np.ndarray): Final hard labels for each data pointU (np.ndarray): Fuzzy membership matrix of shape (N x C)
π οΈ Methodsο
__init__(...): Initializes the model with cluster count and annealing settingsfit_predict(X): Runs the CAFCM algorithm and returns labels and membership matrix
π Implementation Notesο
Distance is calculated via Euclidean norm
Memberships are updated based on current fuzziness value
mAnnealing process decreases
mto push memberships toward binaryConverges when centroids are stable under tolerance
π Referenceο
This implementation is based on:
βFrom Soft Clustering to Hard Clustering: A Collaborative Annealing Strategyβ