KMeansModel

class pycave.clustering.kmeans.KMeansModel(config)[source]

Bases: lightkit.nn.configurable.Configurable[pycave.clustering.kmeans.model.KMeansModelConfig], torch.nn.modules.module.Module

PyTorch module for the K-Means model. The centroids managed by this model are non-trainable parameters.

Parameters

config (KMeansModelConfig) -- The configuration to use for initializing the module's buffers.

Methods

forward

Computes the distance of each datapoint to each centroid as well as the "inertia", the squared distance of each datapoint to its closest centroid.

reset_parameters

Resets the parameters of the KMeans model.

Inherited Methods

load

Loads the module's configurations and parameters from files in the specified directory at first.

save

Saves the module's configuration and parameters to files in the specified directory.

Attributes

centroids

The centers of all clusters, buffer of shape [num_clusters, num_features].