Clustering
PyTorch-based clustering utilities used by highFIS.
This module provides lightweight, dependency-free implementations of K-means and Fuzzy C-Means clustering. These estimators are used internally for membership-function initialization and fuzzy rule construction without requiring external clustering libraries.
The implementations accept array-like inputs and return PyTorch tensors, allowing smooth integration with the rest of the highFIS model pipeline.
FuzzyCMeans
PyTorch implementation of Fuzzy C-Means clustering.
This estimator produces soft cluster memberships and updates centroids using the weighted membership matrix generated by FCM.
Initialize the FuzzyCMeans estimator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_clusters
|
int
|
Number of clusters. |
8
|
m
|
float
|
Fuzziness parameter. Values > 1 produce fuzzier membership. |
2.0
|
max_iter
|
int
|
Maximum number of iterations. |
300
|
tol
|
float
|
Convergence tolerance on centroid movement. |
0.0001
|
random_state
|
int | None
|
Optional seed for reproducible initialization. |
None
|
eps
|
float
|
Small constant to avoid division by zero. |
1e-06
|
Source code in highfis/clustering.py
fit
Fit the Fuzzy C-Means model to the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
Input samples of shape (n_samples, n_features). |
required |
Returns:
| Type | Description |
|---|---|
FuzzyCMeans
|
The fitted estimator. |
Source code in highfis/clustering.py
fit_predict
Fit the model and return the predicted labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
Input samples of shape (n_samples, n_features). |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Hard cluster labels for each sample. |
Source code in highfis/clustering.py
predict
Predict cluster labels for new samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
New samples of shape (n_samples, n_features). |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Hard cluster labels derived from the current membership matrix. |
Source code in highfis/clustering.py
KMeans
PyTorch implementation of K-means clustering.
This estimator runs multiple random restarts and supports empty-cluster handling by reassigning a fallback sample when a cluster becomes empty.
Initialize the KMeans estimator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_clusters
|
int
|
Number of clusters to find. |
8
|
n_init
|
int
|
Number of random initializations to try. |
1
|
max_iter
|
int
|
Maximum number of iterations per run. |
100
|
tol
|
float
|
Convergence tolerance for centroid movement. |
0.0001
|
random_state
|
int | None
|
Optional random seed for reproducibility. |
None
|
Source code in highfis/clustering.py
fit
Fit the KMeans model to the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
Input samples of shape (n_samples, n_features). |
required |
Returns:
| Type | Description |
|---|---|
KMeans
|
The fitted estimator. |
Source code in highfis/clustering.py
fit_predict
Fit the model and return the predicted labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
Input samples of shape (n_samples, n_features). |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Cluster labels for each sample. |
Source code in highfis/clustering.py
predict
Predict cluster labels for new samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
New samples of shape (n_samples, n_features). |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Cluster labels for each sample. |
Source code in highfis/clustering.py
MiniBatchKMeans
PyTorch implementation of Mini-Batch K-Means clustering.
Processes random mini-batches at each iteration instead of the full dataset, making it significantly faster than standard K-Means for large datasets while producing similar cluster quality.
Initialise a :class:MiniBatchKMeans instance.
Source code in highfis/clustering.py
fit
Fit the Mini-Batch K-Means model to the input data.
Source code in highfis/clustering.py
predict
Predict cluster labels for new samples.