class_docstr: A KMeans clustering object.
  
  Although K-means clustering is not a probabilistic model by itself,
  necessarily, it can be a useful initialization for many probabilistic
  methods, and can also be thought of as a specific formulation of a mixture
  model. Specifically, if you have a Gaussian mixture model with diagonal
  covariances set to 1/inf, in theory you will get the exact same results
  as k-means clustering.
  
  The implementation is provided here not necessarily to compete with other
  implementations, but simply to use as a consistent initialization.
  
  
  Parameters
  ----------
  k: int or None, optional
          The number of clusters to initialize. Default is None
  
  centroids: list, numpy.ndarray, torch.Tensor, or None, optional
          A set of centroids to use to initialize the algorithm. Default is None.
  
  init: str, optional
          The initialization to use if `centroids` are not provided. Default is
          'first-k'. Must be one of:
  
                  'first-k': Use the first k examples from the data set
                  'random': Use a random set of k examples from the data set
                  'submodular-facility-location': Use a facility location submodular
                          objective to initialize the k-means algorithm
                  'submodular-feature-based': Use a feature-based submodular objective
                          to initialize the k-means algorithm.
  
  max_iter: int, optional
          The number of iterations to do in the EM step of fitting the
          distribution. Default is 10.
  
  tol: float, optional
          The threshold at which to stop during fitting when the improvement
          goes under. Default is 0.1.
  
  inertia: float, [0, 1], optional
          Indicates the proportion of the update to apply to the parameters
          during training. When the inertia is 0.0, the update is applied in
          its entirety and the previous parameters are ignored. When the
          inertia is 1.0, the update is entirely ignored and the previous
          parameters are kept, equivalently to if the parameters were frozen.
  
  frozen: bool, optional
          Whether all the parameters associated with this distribution are frozen.
          If you want to freeze individual pameters, or individual values in those
          parameters, you must modify the `frozen` attribute of the tensor or
          parameter directly. Default is False.
  
  verbose: bool, optional
          Whether to print the improvement and timings during training.
class_docstr_tok: ["A","KMeans","clustering","object",".","Although","K-means","clustering","is","not","a","probabilistic","model","by","itself",",","necessarily",",","it","can","be","a","useful","initialization","for","many","probabilistic","methods",",","and","can","also","be","thought","of","as","a","specific","formulation","of","a","mixture","model",".","Specifically",",","if","you","have","a","Gaussian","mixture","model","with","diagonal","covariances","set","to","1\/inf",",","in","theory","you","will","get","the","exact","same","results","as","k-means","clustering",".","The","implementation","is","provided","here","not","necessarily","to","compete","with","other","implementations",",","but","simply","to","use","as","a","consistent","initialization",".","Parameters","--","--","--","--","--","k",":","int","or","None",",","optional","The","number","of","clusters","to","initialize",".","Default","is","None","centroids",":","list",",","numpy.ndarray",",","torch.Tensor",",","or","None",",","optional","A","set","of","centroids","to","use","to","initialize","the","algorithm",".","Default","is","None",".","init",":","str",",","optional","The","initialization","to","use","if","`","centroids","`","are","not","provided",".","Default","is","'first-k","'",".","Must","be","one","of",":","'first-k","'",":","Use","the","first","k","examples","from","the","data","set","'random","'",":","Use","a","random","set","of","k","examples","from","the","data","set","'submodular-facility-location","'",":","Use","a","facility","location","submodular","objective","to","initialize","the","k-means","algorithm","'submodular-feature-based","'",":","Use","a","feature-based","submodular","objective","to","initialize","the","k-means","algorithm",".","max_iter",":","int",",","optional","The","number","of","iterations","to","do","in","the","EM","step","of","fitting","the","distribution",".","Default","is","10.","tol",":","float",",","optional","The","threshold","at","which","to","stop","during","fitting","when","the","improvement","goes","under",".","Default","is","0.1.","inertia",":","float",",","[","0",",","1","]",",","optional","Indicates","the","proportion","of","the","update","to","apply","to","the","parameters","during","training",".","When","the","inertia","is","0.0",",","the","update","is","applied","in","its","entirety","and","the","previous","parameters","are","ignored",".","When","the","inertia","is","1.0",",","the","update","is","entirely","ignored","and","the","previous","parameters","are","kept",",","equivalently","to","if","the","parameters","were","frozen",".","frozen",":","bool",",","optional","Whether","all","the","parameters","associated","with","this","distribution","are","frozen",".","If","you","want","to","freeze","individual","pameters",",","or","individual","values","in","those","parameters",",","you","must","modify","the","`","frozen","`","attribute","of","the","tensor","or","parameter","directly",".","Default","is","False",".","verbose",":","bool",",","optional","Whether","to","print","the","improvement","and","timings","during","training","."]
code: def __init__(
      self,
      k=None,
      centroids=None,
      init="first-k",
      max_iter=10,
      tol=0.1,
      inertia=0.0,
      frozen=False,
      random_state=None,
      verbose=False,
  ):
      super().__init__()
      self.name = "KMeans"
      self._device = _cast_as_parameter([0.0])
  
      self.centroids = _check_parameter(
          _cast_as_parameter(centroids, dtype=torch.float32),
          "centroids",
          ndim=2,
      )
  
      self.k = _check_parameter(
          _cast_as_parameter(k),
          "k",
          ndim=0,
          min_value=2,
          dtypes=(int, torch.int32, torch.int64),
      )
  
      self.init = _check_parameter(
          init,
          "init",
          value_set=(
              "random",
              "first-k",
              "submodular-facility-location",
              "submodular-feature-based",
          ),
          ndim=0,
          dtypes=(str,),
      )
      self.max_iter = _check_parameter(
          _cast_as_tensor(max_iter),
          "max_iter",
          ndim=0,
          min_value=1,
          dtypes=(int, torch.int32, torch.int64),
      )
      self.tol = _check_parameter(
          _cast_as_tensor(tol), "tol", ndim=0, min_value=0
      )
      self.inertia = _check_parameter(
          _cast_as_tensor(inertia),
          "inertia",
          ndim=0,
          min_value=0.0,
          max_value=1.0,
      )
      self.frozen = _check_parameter(
          _cast_as_tensor(frozen),
          "frozen",
          ndim=0,
          value_set=(True, False),
      )
      self.random_state = random_state
      self.verbose = _check_parameter(
          verbose, "verbose", value_set=(True, False)
      )
  
      if self.k is None and self.centroids is None:
          raise ValueError("Must specify one of `k` or `centroids`.")
  
      self.k = len(centroids) if centroids is not None else self.k
      self.d = len(centroids[0]) if centroids is not None else None
      self._initialized = centroids is not None
      self._reset_cache()
  
imports: import time
  import torch
  from ._utils import _cast_as_tensor
  from ._utils import _cast_as_parameter
  from ._utils import _update_parameter
  from ._utils import _check_parameter
  from ._utils import _reshape_weights
  from ._utils import _initialize_centroids
  from ._utils import eps
label_desc: Use image node_id 1 to create a new KMeans object from inherited base classes: torch.nn with example: obj = KMeans(k, centroids, init, max_iter, tol, inertia, frozen, random_state, verbose)