Clustering Module¶
This module defines abstractions and implementations for clustering algorithms used by a few of the strategies.
Bases: ABC
Abstract base class for clustering algorithms.
Source code in cogitator/clustering.py
cluster(embeddings, n_clusters, **kwargs)
abstractmethod
¶
Clusters the given embeddings into a specified number of clusters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embeddings
|
ndarray
|
A NumPy array where each row is an embedding vector. |
required |
n_clusters
|
int
|
The desired number of clusters. |
required |
**kwargs
|
Any
|
Additional keyword arguments specific to the clustering implementation. |
{}
|
Returns:
Type | Description |
---|---|
Tuple[ndarray, ndarray]
|
A tuple containing: - A NumPy array of cluster labels assigned to each embedding. - A NumPy array of cluster centers. |
Source code in cogitator/clustering.py
Bases: BaseClusterer
A clustering implementation using the K-Means algorithm from scikit-learn.
Source code in cogitator/clustering.py
cluster(embeddings, n_clusters, **kwargs)
¶
Clusters embeddings using K-Means.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embeddings
|
ndarray
|
The embeddings to cluster (shape: [n_samples, n_features]). |
required |
n_clusters
|
int
|
The number of clusters to form. |
required |
**kwargs
|
Any
|
Additional arguments for |
{}
|
Returns:
Type | Description |
---|---|
Tuple[ndarray, ndarray]
|
A tuple containing: - labels (np.ndarray): Integer labels array (shape: [n_samples,]). - centers (np.ndarray): Coordinates of cluster centers (shape: [n_clusters, n_features]). |
Raises:
Type | Description |
---|---|
ValueError
|
If |