Robust deep fuzzy πΎ-means clustering for image data (RD-FKC)ο
End-to-end deep fuzzy clustering with Laplacian regularization and adaptive robustness.
π Overviewο
The Robust deep fuzzy πΎ-means clustering (RD-FKC) algorithm combines deep representation learning and fuzzy clustering into a unified framework. It uses an encoder-decoder neural network to learn low-dimensional latent features from input images, while simultaneously optimizing cluster membership and cluster centers using an iterative strategy.
βοΈ Class Definitionο
class soft_clustering.RDFKC(
K: int = 10,
encoder: Optional[torch.nn.Module] = None,
decoder: Optional[torch.nn.Module] = None,
dataset: Optional[str] = None,
random_state: Optional[int] = None,
max_iter: int = 100,
batch_size: Optional[int] = None,
lr: float = 1e-4,
mu: float = 1.0,
gamma: float = 1e-4,
tau: float = 0.1):
π Parametersο
Parameter |
Type |
Default |
Description |
|---|---|---|---|
K |
|
β |
Number of fuzzy clusters. |
encoder |
|
|
Encoder model for feature learning. Required if |
decoder |
|
|
Decoder model for reconstruction. Required if |
dataset |
|
|
If provided ( |
random_state |
|
|
Seed for reproducible experiments. |
max_iter |
|
|
Maximum number of update iterations. |
batch_size |
|
|
Batch size for encoding. Auto-set based on dataset size if not provided. |
lr |
|
|
Learning rate for Adam optimizer. |
mu |
|
|
Laplacian regularization weight. |
gamma |
|
|
Weight regularization for encoder/decoder parameters. |
tau |
|
|
Robustness coefficient for adaptive clustering loss. |
π Usage Examplesο
import numpy as np
from rdfkc import RDFKC
# Set seed for reproducibility
np.random.seed(42)
# Create 100 grayscale images of size 32x32 (shape: N, C, H, W)
images = np.random.rand(100, 1, 32, 32).astype(np.float32)
# Initialize RDFKC model with 5 clusters
model = RDFKC(K=5, dataset="coil20", max_iter=5)
# Fit the model and predict cluster assignments
cluster_labels = model.fit_predict(images)
# Display the number of unique clusters assigned
print(f"Found {len(np.unique(cluster_labels))} clusters.")
π οΈ Methodsο
fit_predict(adjacency_matrix)ο
Train the RDFKC model on input images and return soft cluster assignments.
Parameters:
X(np.ndarrayortorch.Tensor, shape(N, C, H, W)): Input image data.
Returns:
labels(np.ndarray, shape(N,)): Soft cluster labels (argmax of membership matrix).
π Implementation Notesο
Input Format Input X must be a NumPy array or torch Tensor of shape (N, 1, H, W) with pixel values normalized to [0, 1].
Iterations Runs for a fixed max_iter; no convergence check is performed.
Encoder/Decoder If dataset=βcoil20β or βfashionβ, predefined architectures are used. Custom encoder and decoder can be provided.
π Referenceο
Wu, X., Yu, Y.-F., Chen, L., Ding, W., & Wang, Y. (2024). Robust deep fuzzy K-means clustering for image data. Pattern Recognition, 153, Article 110504. (https://doi.org/10.1016/j.patcog.2024.110504).