torch_kmeans.utils.utils module

class torch_kmeans.utils.utils.ClusterResult(labels: LongTensor, centers: Tensor, inertia: Tensor, x_org: Tensor, x_norm: Tensor, k: LongTensor, soft_assignment: Optional[Tensor] = None)[source]

Bases: tuple

Named and typed result tuple for kmeans algorithms

Parameters
  • labels (LongTensor) – label for each sample in x

  • centers (Tensor) – corresponding coordinates of cluster centers

  • inertia (Tensor) – sum of squared distances of samples to their closest cluster center

  • x_org (Tensor) – original x

  • x_norm (Tensor) – normalized x which was used for cluster centers and labels

  • k (LongTensor) – number of clusters

  • soft_assignment (Optional[Tensor]) – assignment probabilities of soft kmeans

Create new instance of ClusterResult(labels, centers, inertia, x_org, x_norm, k, soft_assignment)

labels: LongTensor

Alias for field number 0

centers: Tensor

Alias for field number 1

inertia: Tensor

Alias for field number 2

x_org: Tensor

Alias for field number 3

x_norm: Tensor

Alias for field number 4

k: LongTensor

Alias for field number 5

soft_assignment: Optional[Tensor]

Alias for field number 6

torch_kmeans.utils.utils.rm_kwargs(kwargs: Dict, keys: List)[source]

Remove items corresponding to keys specified in ‘keys’ from kwargs dict.

Parameters