docstr: Prototype selection for dataset distillation and interpretable classification proposed by
  Bien and Tibshirani (2012): https://arxiv.org/abs/1202.5933
  
  Parameters
  ----------
  kernel_distance
      Kernel distance to be used. Expected to support computation in batches. Given an input `x` of
      size `Nx x f1 x f2 x ...` and an input `y` of size `Ny x f1 x f2 x ...`, the kernel distance
      should return a kernel matrix of size `Nx x Ny`.
  eps
      Epsilon ball size.
  lambda_penalty
      Penalty for each prototype. Encourages a lower number of prototypes to be selected. Corresponds to
      :math:`\lambda` in the paper notation. If not specified, the default value is set to `1 / N` where
      `N` is the size of the dataset to choose the prototype instances from, passed to the
      :py:meth:`alibi.prototypes.protoselect.ProtoSelect.fit` method.
  batch_size
      Batch size to be used for kernel matrix computation.
  preprocess_fn
      Preprocessing function used for kernel matrix computation. The preprocessing function takes the input as
      a `list` or a `numpy` array and transforms it into a `numpy` array which is then fed to the
      `kernel_distance` function. The use of `preprocess_fn` allows the method to be applied to any data modality.
  verbose
       Whether to display progression bar while computing prototype points.
docstr_tok: ["Prototype","selection","for","dataset","distillation","and","interpretable","classification","proposed","by","Bien","and","Tibshirani","(","2012",")",":","https",":","\/\/arxiv.org\/abs\/1202.5933","Parameters","--","--","--","--","--","kernel_distance","Kernel","distance","to","be","used",".","Expected","to","support","computation","in","batches",".","Given","an","input","`","x","`","of","size","`","Nx","x","f1","x","f2","x","...","`","and","an","input","`","y","`","of","size","`","Ny","x","f1","x","f2","x","...","`",",","the","kernel","distance","should","return","a","kernel","matrix","of","size","`","Nx","x","Ny","`",".","eps","Epsilon","ball","size",".","lambda_penalty","Penalty","for","each","prototype",".","Encourages","a","lower","number","of","prototypes","to","be","selected",".","Corresponds","to",":","math",":","`","\\lambda","`","in","the","paper","notation",".","If","not","specified",",","the","default","value","is","set","to","`","1","\/","N","`","where","`","N","`","is","the","size","of","the","dataset","to","choose","the","prototype","instances","from",",","passed","to","the",":","py",":","meth",":","`","alibi.prototypes.protoselect.ProtoSelect.fit","`","method",".","batch_size","Batch","size","to","be","used","for","kernel","matrix","computation",".","preprocess_fn","Preprocessing","function","used","for","kernel","matrix","computation",".","The","preprocessing","function","takes","the","input","as","a","`","list","`","or","a","`","numpy","`","array","and","transforms","it","into","a","`","numpy","`","array","which","is","then","fed","to","the","`","kernel_distance","`","function",".","The","use","of","`","preprocess_fn","`","allows","the","method","to","be","applied","to","any","data","modality",".","verbose","Whether","to","display","progression","bar","while","computing","prototype","points","."]
code: def __init__(
      self,
      kernel_distance: Callable[[np.ndarray, np.ndarray], np.ndarray],
      eps: float,
      lambda_penalty: Optional[float] = None,
      batch_size: int = int(1e10),
      preprocess_fn: Optional[
          Callable[[Union[list, np.ndarray]], np.ndarray]
      ] = None,
      verbose: bool = False,
  ):
      """
      Prototype selection for dataset distillation and interpretable classification proposed by
      Bien and Tibshirani (2012): https://arxiv.org/abs/1202.5933
  
      Parameters
      ----------
      kernel_distance
          Kernel distance to be used. Expected to support computation in batches. Given an input `x` of
          size `Nx x f1 x f2 x ...` and an input `y` of size `Ny x f1 x f2 x ...`, the kernel distance
          should return a kernel matrix of size `Nx x Ny`.
      eps
          Epsilon ball size.
      lambda_penalty
          Penalty for each prototype. Encourages a lower number of prototypes to be selected. Corresponds to
          :math:`\\lambda` in the paper notation. If not specified, the default value is set to `1 / N` where
          `N` is the size of the dataset to choose the prototype instances from, passed to the
          :py:meth:`alibi.prototypes.protoselect.ProtoSelect.fit` method.
      batch_size
          Batch size to be used for kernel matrix computation.
      preprocess_fn
          Preprocessing function used for kernel matrix computation. The preprocessing function takes the input as
          a `list` or a `numpy` array and transforms it into a `numpy` array which is then fed to the
          `kernel_distance` function. The use of `preprocess_fn` allows the method to be applied to any data modality.
      verbose
           Whether to display progression bar while computing prototype points.
      """
      super().__init__(meta=deepcopy(DEFAULT_META_PROTOSELECT))
      self.kernel_distance = kernel_distance
      self.eps = eps
      self.lambda_penalty = lambda_penalty
      self.batch_size = batch_size
      self.preprocess_fn = preprocess_fn
      self.verbose = verbose
  
      # get kernel tag
      if hasattr(self.kernel_distance, "__name__"):
          kernel_distance_tag = self.kernel_distance.__name__
      elif hasattr(self.kernel_distance, "__class__"):
          kernel_distance_tag = self.kernel_distance.__class__.__name__
      else:
          kernel_distance_tag = "unknown kernel distance"
  
      # update metadata
      self.meta["params"].update(
          {
              "kernel_distance": kernel_distance_tag,
              "eps": eps,
              "lambda_penalty": lambda_penalty,
              "batch_size": batch_size,
              "verbose": verbose,
          }
      )
  
imports: import logging
  from copy import deepcopy
  from typing import Callable, Dict, List, Optional, Tuple, Union
  import matplotlib.pyplot
  import numpy
  from matplotlib.offsetbox import AnnotationBbox, OffsetImage
  from skimage.transform import resize
  from sklearn.model_selection import KFold
  from sklearn.neighbors import KNeighborsClassifier
  from tqdm import tqdm
  from alibi.api.defaults import DEFAULT_DATA_PROTOSELECT, DEFAULT_META_PROTOSELECT
  from alibi.api.interfaces import Explanation, FitMixin, Summariser
  from alibi.utils.distance import batch_compute_kernel_matrix
  from alibi.utils.kernel import EuclideanDistance
label_desc: Use image node_id 1 to create a new ProtoSelect object from inherited base classes: Summariser, FitMixin with example: obj = ProtoSelect(kernel_distance, eps, lambda_penalty, batch_size, preprocess_fn, verbose)