class_docstr: Implement the total variance minimization defence approach.
  
  | Paper link: https://openreview.net/forum?id=SyJ7ClWCb
  
  | Please keep in mind the limitations of defences. For more information on the limitations of this
      defence, see https://arxiv.org/abs/1802.00420 . For details on how to evaluate classifier security in general,
      see https://arxiv.org/abs/1902.06705
class_docstr_tok: ["Implement","the","total","variance","minimization","defence","approach",".","|","Paper","link",":","https",":","\/\/openreview.net\/forum","?","id=SyJ7ClWCb","|","Please","keep","in","mind","the","limitations","of","defences",".","For","more","information","on","the","limitations","of","this","defence",",","see","https",":","\/\/arxiv.org\/abs\/1802.00420",".","For","details","on","how","to","evaluate","classifier","security","in","general",",","see","https",":","\/\/arxiv.org\/abs\/1902.06705"]
docstr: Apply total variance minimization to sample `x`.
  
  :param x: Sample to compress with shape `(batch_size, width, height, depth)`.
  :param y: Labels of the sample `x`. This function does not affect them in any way.
  :return: Similar samples.
docstr_tok: ["Apply","total","variance","minimization","to","sample","`","x","`",".",":","param","x",":","Sample","to","compress","with","shape","`","(","batch_size",",","width",",","height",",","depth",")","`",".",":","param","y",":","Labels","of","the","sample","`","x","`",".","This","function","does","not","affect","them","in","any","way",".",":","return",":","Similar","samples","."]
code: def __call__(
      self, x: np.ndarray, y: Optional[np.ndarray] = None
  ) -> Tuple[np.ndarray, Optional[np.ndarray]]:
      """
      Apply total variance minimization to sample `x`.
  
      :param x: Sample to compress with shape `(batch_size, width, height, depth)`.
      :param y: Labels of the sample `x`. This function does not affect them in any way.
      :return: Similar samples.
      """
      if len(x.shape) == 2:
          raise ValueError(
              "Feature vectors detected. Variance minimization can only be applied to data with spatial dimensions."
          )
      x_preproc = x.copy()
  
      # Minimize one input at a time
      for i, x_i in enumerate(
          tqdm(
              x_preproc,
              desc="Variance minimization",
              disable=not self.verbose,
          )
      ):
          mask = (np.random.rand(*x_i.shape) < self.prob).astype("int")
          x_preproc[i] = self._minimize(x_i, mask)
  
      if self.clip_values is not None:
          np.clip(
              x_preproc,
              self.clip_values[0],
              self.clip_values[1],
              out=x_preproc,
          )
  
      return x_preproc.astype(ART_NUMPY_DTYPE), y
  
file_path: adversarial-robustness-toolbox/art/defences/preprocessor/variance_minimization.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, Tuple, TYPE_CHECKING
  import numpy
  from scipy.optimize import minimize
  from tqdm.auto import tqdm
  from art.config import ART_NUMPY_DTYPE
  from art.defences.preprocessor.preprocessor import Preprocessor
label_desc: Use image node_id 2 for calling the TotalVarMin obj's underlying member method code with example usage: obj.__call__(x, y) and returns: x_preproc,  y