GOOD.utils.fast_pytorch_kmeans.multi_kmeans
Classes
|
Kmeans clustering algorithm implemented with PyTorch :param n_clusters: int, Number of clusters :param max_iter: int, default: 100 Maximum number of iterations :param tol: float, default: 0.0001 Tolerance :param verbose: int, default: 0 Verbosity :param mode: {'euclidean', 'cosine'}, default: 'euclidean' Type of distance measure :param init_method: {'gaussian', 'random', 'k-means++'} Type of initialization :param minibatch: {None, int}, default: None Batch size of MinibatchKmeans algorithm if None perform full KMeans algorithm |
- class GOOD.utils.fast_pytorch_kmeans.multi_kmeans.MultiKMeans(n_clusters, n_kmeans, max_iter=100, tol=0.0001, verbose=0, mode='euclidean', init_method='kmeans++', minibatch=None)[source]
Bases:
object
Kmeans clustering algorithm implemented with PyTorch :param n_clusters: int,
Number of clusters
- Parameters
max_iter – int, default: 100 Maximum number of iterations
tol – float, default: 0.0001 Tolerance
verbose – int, default: 0 Verbosity
mode – {‘euclidean’, ‘cosine’}, default: ‘euclidean’ Type of distance measure
init_method – {‘gaussian’, ‘random’, ‘k-means++’} Type of initialization
minibatch – {None, int}, default: None Batch size of MinibatchKmeans algorithm if None perform full KMeans algorithm
- centroids
torch.Tensor, shape: [n_clusters, n_features] cluster centroids
- static cos_sim(a, b)[source]
Compute cosine similarity of 2 sets of vectors Parameters: a: torch.Tensor, shape: [m, n_features] b: torch.Tensor, shape: [n, n_features]
- static euc_sim(a, b)[source]
Compute euclidean similarity of 2 sets of vectors Parameters: a: torch.Tensor, shape: [m, n_features] b: torch.Tensor, shape: [n, n_features]
- fit(X, centroids=None)[source]
Perform kmeans clustering Parameters: X: torch.Tensor, shape: [n_kmeans, n_samples, n_features]
- fit_predict(X, centroids=None)[source]
Combination of fit() and predict() methods. This is faster than calling fit() and predict() seperately. Parameters: X: torch.Tensor, shape: [n_samples, n_features] centroids: {torch.Tensor, None}, default: None
if given, centroids will be initialized with given tensor if None, centroids will be randomly chosen from X
Return: labels: torch.Tensor, shape: [n_samples]
- max_sim(a, b)[source]
Compute maximum similarity (or minimum distance) of each vector in a with all of the vectors in b Parameters: a: torch.Tensor, shape: [m, n_features] b: torch.Tensor, shape: [n, n_features]