class_docstr: Implements k-center-greedy method.
  
  Args:
      embedding (Tensor): Embedding vector extracted from a CNN
      sampling_ratio (float): Ratio to choose coreset size from the embedding size.
  
  Example:
      >>> embedding.shape
      torch.Size([219520, 1536])
      >>> sampler = KCenterGreedy(embedding=embedding)
      >>> sampled_idxs = sampler.select_coreset_idxs()
      >>> coreset = embedding[sampled_idxs]
      >>> coreset.shape
      torch.Size([219, 1536])
class_docstr_tok: ["Implements","k-center-greedy","method",".","Args",":","embedding","(","Tensor",")",":","Embedding","vector","extracted","from","a","CNN","sampling_ratio","(","float",")",":","Ratio","to","choose","coreset","size","from","the","embedding","size",".","Example",":",">",">",">","embedding.shape","torch.Size","(","[","219520",",","1536","]",")",">",">",">","sampler","=","KCenterGreedy","(","embedding=embedding",")",">",">",">","sampled_idxs","=","sampler.select_coreset_idxs","(",")",">",">",">","coreset","=","embedding","[","sampled_idxs","]",">",">",">","coreset.shape","torch.Size","(","[","219",",","1536","]",")"]
docstr: Greedily form a coreset to minimize the maximum distance of a cluster.
  
  Args:
      selected_idxs: index of samples already selected. Defaults to an empty set.
  
  Returns:
    indices of samples selected to minimize distance to cluster centers
docstr_tok: ["Greedily","form","a","coreset","to","minimize","the","maximum","distance","of","a","cluster",".","Args",":","selected_idxs",":","index","of","samples","already","selected",".","Defaults","to","an","empty","set",".","Returns",":","indices","of","samples","selected","to","minimize","distance","to","cluster","centers"]
code: def select_coreset_idxs(
      self, selected_idxs: list[int] | None = None
  ) -> list[int]:
      """Greedily form a coreset to minimize the maximum distance of a cluster.
  
      Args:
          selected_idxs: index of samples already selected. Defaults to an empty set.
  
      Returns:
        indices of samples selected to minimize distance to cluster centers
      """
  
      if selected_idxs is None:
          selected_idxs = []
  
      if self.embedding.ndim == 2:
          self.model.fit(self.embedding)
          self.features = self.model.transform(self.embedding)
          self.reset_distances()
      else:
          self.features = self.embedding.reshape(
              self.embedding.shape[0], -1
          )
          self.update_distances(cluster_centers=selected_idxs)
  
      selected_coreset_idxs: list[int] = []
      idx = int(
          torch.randint(high=self.n_observations, size=(1,)).item()
      )
      for _ in tqdm(
          range(self.coreset_size), "Selecting Coreset Indices."
      ):
          self.update_distances(cluster_centers=[idx])
          idx = self.get_new_idx()
          if idx in selected_idxs:
              raise ValueError(
                  "New indices should not be in selected indices."
              )
          self.min_distances[idx] = 0
          selected_coreset_idxs.append(idx)
  
      return selected_coreset_idxs
  
file_path: anomalib/src/anomalib/models/components/sampling/k_center_greedy.py
imports: from __future__ import annotations
  import torch
  import torch.nn.functional
  from torch import Tensor
  from tqdm import tqdm
  from anomalib.models.components.dimensionality_reduction import SparseRandomProjection
label_desc: Use image node_id 5 for calling the KCenterGreedy obj's underlying member method code with example usage: obj.select_coreset_idxs(selected_idxs) and returns: selected_coreset_idxs