class_docstr: Class for k-means clustering on manifolds.
  
  K-means algorithm using Riemannian manifolds.
  
  Parameters
  ----------
  space : Manifold
      Equipped manifold.
  n_clusters : int
      Number of clusters (k value of the k-means).
      Optional, default: 8.
  init : str or callable or array-like, shape=[n_clusters, n_features]
      How to initialize cluster centers at the beginning of the algorithm. The
      choice 'random' will select training points as initial cluster centers
      uniformly at random. The choice 'kmeans++' selects cluster centers
      heuristically to improve the convergence rate. When providing an array
      of shape ``(n_clusters, n_features)``, the cluster centers are chosen as the
      rows of that array. When providing a callable, it receives as arguments
      the argument ``X`` to :meth:`fit` and the number of cluster centers
      ``n_clusters`` and is expected to return an array as above.
      Optional, default: 'random'.
  tol : float
      Convergence factor. Convergence is achieved when the difference of mean
      distance between two steps is lower than tol.
      Optional, default: 1e-2.
  max_iter : int
      Maximum number of iterations.
      Optional, default: 100
  verbose : int
      If verbose > 0, information will be printed during learning.
      Optional, default: 0.
  
  Notes
  -----
  * Required metric methods: `dist`.
  
  Example
  -------
  Available example on the Poincaré Ball and Hypersphere manifolds
  :mod:`examples.plot_kmeans_manifolds`
class_docstr_tok: ["Class","for","k-means","clustering","on","manifolds",".","K-means","algorithm","using","Riemannian","manifolds",".","Parameters","--","--","--","--","--","space",":","Manifold","Equipped","manifold",".","n_clusters",":","int","Number","of","clusters","(","k","value","of","the","k-means",")",".","Optional",",","default",":","8.","init",":","str","or","callable","or","array-like",",","shape=","[","n_clusters",",","n_features","]","How","to","initialize","cluster","centers","at","the","beginning","of","the","algorithm",".","The","choice","'random","'","will","select","training","points","as","initial","cluster","centers","uniformly","at","random",".","The","choice","'kmeans++","'","selects","cluster","centers","heuristically","to","improve","the","convergence","rate",".","When","providing","an","array","of","shape","``","(","n_clusters",",","n_features",")","``",",","the","cluster","centers","are","chosen","as","the","rows","of","that","array",".","When","providing","a","callable",",","it","receives","as","arguments","the","argument","``","X","``","to",":","meth",":","`","fit","`","and","the","number","of","cluster","centers","``","n_clusters","``","and","is","expected","to","return","an","array","as","above",".","Optional",",","default",":","'random","'",".","tol",":","float","Convergence","factor",".","Convergence","is","achieved","when","the","difference","of","mean","distance","between","two","steps","is","lower","than","tol",".","Optional",",","default",":","1e-2",".","max_iter",":","int","Maximum","number","of","iterations",".","Optional",",","default",":","100","verbose",":","int","If","verbose",">","0",",","information","will","be","printed","during","learning",".","Optional",",","default",":","0",".","Notes","--","--","-","*","Required","metric","methods",":","`","dist","`",".","Example","--","--","--","-","Available","example","on","the","Poincar\u00e9","Ball","and","Hypersphere","manifolds",":","mod",":","`","examples.plot_kmeans_manifolds","`"]
code: def _pick_init_cluster_centers(self, X):
      n_samples = X.shape[0]
  
      if isinstance(self.init, str):
          if self.init == "kmeans++":
              cluster_centers = [X[randint(0, n_samples - 1)]]
              for i in range(self.n_clusters - 1):
                  dists = gs.array(
                      [
                          self.space.metric.dist(cluster_centers[j], X)
                          for j in range(i + 1)
                      ]
                  )
                  dists_to_closest_cluster_center = gs.amin(
                      dists, axis=0
                  )
                  indices = gs.arange(n_samples)
                  weights = dists_to_closest_cluster_center / gs.sum(
                      dists_to_closest_cluster_center
                  )
                  index = rv_discrete(
                      values=(
                          gs.to_numpy(indices),
                          gs.to_numpy(weights),
                      )
                  ).rvs()
                  cluster_centers.append(X[index])
          elif self.init == "random":
              cluster_centers = [
                  X[randint(0, n_samples - 1)]
                  for i in range(self.n_clusters)
              ]
          else:
              raise ValueError(
                  f"Unknown initial cluster centers method '{self.init}'."
              )
  
          cluster_centers = gs.stack(cluster_centers, axis=0)
      else:
          if callable(self.init):
              cluster_centers = self.init(X, self.n_clusters)
          else:
              cluster_centers = self.init
  
          if cluster_centers.shape[0] != self.n_clusters:
              raise ValueError(
                  "Need as many initial cluster centers as clusters."
              )
  
          if cluster_centers.shape[1] != X.shape[1]:
              raise ValueError(
                  "Dimensions of initial cluster centers and "
                  "training data do not match."
              )
  
      return cluster_centers
  
file_path: geomstats/geomstats/learning/kmeans.py
imports: import logging
  from random import randint
  from scipy.stats import rv_discrete
  from sklearn.base import BaseEstimator, ClusterMixin
  import geomstats.backend
  from geomstats.learning._template import TransformerMixin
  from geomstats.learning.frechet_mean import FrechetMean
label_desc: Use image node_id 2 for calling the RiemannianKMeans obj's underlying member method code with example usage: obj._pick_init_cluster_centers(X) and returns: cluster_centers