class_docstr: Implementation of Randomized Smoothing applied to classifier predictions and gradients, as introduced
  in Cohen et al. (2019).
  
  | Paper link: https://arxiv.org/abs/1902.02918
class_docstr_tok: ["Implementation","of","Randomized","Smoothing","applied","to","classifier","predictions","and","gradients",",","as","introduced","in","Cohen","et","al",".","(","2019",")",".","|","Paper","link",":","https",":","\/\/arxiv.org\/abs\/1902.02918"]
docstr: Create a randomized smoothing classifier.
  
  :param model: PyTorch model. The output of the model can be logits, probabilities or anything else. Logits
         output should be preferred where possible to ensure attack efficiency.
  :param loss: The loss function for which to compute gradients for training. The target label must be raw
         categorical, i.e. not converted to one-hot encoding.
  :param input_shape: The shape of one input instance.
  :param nb_classes: The number of classes of the model.
  :param optimizer: The optimizer used to train the classifier.
  :param channels_first: Set channels first or last.
  :param clip_values: Tuple of the form `(min, max)` of floats or `np.ndarray` representing the minimum and
         maximum values allowed for features. If floats are provided, these will be used as the range of all
         features. If arrays are provided, each value will be considered the bound for a feature, thus
         the shape of clip values needs to match the total number of features.
  :param preprocessing_defences: Preprocessing defence(s) to be applied by the classifier.
  :param postprocessing_defences: Postprocessing defence(s) to be applied by the classifier.
  :param preprocessing: Tuple of the form `(subtrahend, divisor)` of floats or `np.ndarray` of values to be
         used for data preprocessing. The first value will be subtracted from the input. The input will then
         be divided by the second one.
  :param device_type: Type of device on which the classifier is run, either `gpu` or `cpu`.
  :param sample_size: Number of samples for smoothing.
  :param scale: Standard deviation of Gaussian noise added.
  :param alpha: The failure probability of smoothing.
docstr_tok: ["Create","a","randomized","smoothing","classifier",".",":","param","model",":","PyTorch","model",".","The","output","of","the","model","can","be","logits",",","probabilities","or","anything","else",".","Logits","output","should","be","preferred","where","possible","to","ensure","attack","efficiency",".",":","param","loss",":","The","loss","function","for","which","to","compute","gradients","for","training",".","The","target","label","must","be","raw","categorical",",","i.e",".","not","converted","to","one-hot","encoding",".",":","param","input_shape",":","The","shape","of","one","input","instance",".",":","param","nb_classes",":","The","number","of","classes","of","the","model",".",":","param","optimizer",":","The","optimizer","used","to","train","the","classifier",".",":","param","channels_first",":","Set","channels","first","or","last",".",":","param","clip_values",":","Tuple","of","the","form","`","(","min",",","max",")","`","of","floats","or","`","np.ndarray","`","representing","the","minimum","and","maximum","values","allowed","for","features",".","If","floats","are","provided",",","these","will","be","used","as","the","range","of","all","features",".","If","arrays","are","provided",",","each","value","will","be","considered","the","bound","for","a","feature",",","thus","the","shape","of","clip","values","needs","to","match","the","total","number","of","features",".",":","param","preprocessing_defences",":","Preprocessing","defence","(","s",")","to","be","applied","by","the","classifier",".",":","param","postprocessing_defences",":","Postprocessing","defence","(","s",")","to","be","applied","by","the","classifier",".",":","param","preprocessing",":","Tuple","of","the","form","`","(","subtrahend",",","divisor",")","`","of","floats","or","`","np.ndarray","`","of","values","to","be","used","for","data","preprocessing",".","The","first","value","will","be","subtracted","from","the","input",".","The","input","will","then","be","divided","by","the","second","one",".",":","param","device_type",":","Type","of","device","on","which","the","classifier","is","run",",","either","`","gpu","`","or","`","cpu","`",".",":","param","sample_size",":","Number","of","samples","for","smoothing",".",":","param","scale",":","Standard","deviation","of","Gaussian","noise","added",".",":","param","alpha",":","The","failure","probability","of","smoothing","."]
code: def __init__(
      self,
      model: "torch.nn.Module",
      loss: "torch.nn.modules.loss._Loss",
      input_shape: Tuple[int, ...],
      nb_classes: int,
      optimizer: Optional["torch.optim.Optimizer"] = None,
      channels_first: bool = True,
      clip_values: Optional["CLIP_VALUES_TYPE"] = None,
      preprocessing_defences: Union[
          "Preprocessor", List["Preprocessor"], None
      ] = None,
      postprocessing_defences: Union[
          "Postprocessor", List["Postprocessor"], None
      ] = None,
      preprocessing: "PREPROCESSING_TYPE" = (0.0, 1.0),
      device_type: str = "gpu",
      sample_size: int = 32,
      scale: float = 0.1,
      alpha: float = 0.001,
  ):
      """
      Create a randomized smoothing classifier.
  
      :param model: PyTorch model. The output of the model can be logits, probabilities or anything else. Logits
             output should be preferred where possible to ensure attack efficiency.
      :param loss: The loss function for which to compute gradients for training. The target label must be raw
             categorical, i.e. not converted to one-hot encoding.
      :param input_shape: The shape of one input instance.
      :param nb_classes: The number of classes of the model.
      :param optimizer: The optimizer used to train the classifier.
      :param channels_first: Set channels first or last.
      :param clip_values: Tuple of the form `(min, max)` of floats or `np.ndarray` representing the minimum and
             maximum values allowed for features. If floats are provided, these will be used as the range of all
             features. If arrays are provided, each value will be considered the bound for a feature, thus
             the shape of clip values needs to match the total number of features.
      :param preprocessing_defences: Preprocessing defence(s) to be applied by the classifier.
      :param postprocessing_defences: Postprocessing defence(s) to be applied by the classifier.
      :param preprocessing: Tuple of the form `(subtrahend, divisor)` of floats or `np.ndarray` of values to be
             used for data preprocessing. The first value will be subtracted from the input. The input will then
             be divided by the second one.
      :param device_type: Type of device on which the classifier is run, either `gpu` or `cpu`.
      :param sample_size: Number of samples for smoothing.
      :param scale: Standard deviation of Gaussian noise added.
      :param alpha: The failure probability of smoothing.
      """
      if preprocessing_defences is not None:
          warnings.warn(
              "\n With the current backend (Pytorch) Gaussian noise will be added by Randomized Smoothing "
              "AFTER the application of preprocessing defences. Please ensure this conforms to your use case.\n"
          )
  
      super().__init__(
          model=model,
          loss=loss,
          input_shape=input_shape,
          nb_classes=nb_classes,
          optimizer=optimizer,
          channels_first=channels_first,
          clip_values=clip_values,
          preprocessing_defences=preprocessing_defences,
          postprocessing_defences=postprocessing_defences,
          preprocessing=preprocessing,
          device_type=device_type,
          sample_size=sample_size,
          scale=scale,
          alpha=alpha,
      )
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import List, Optional, Tuple, Union, TYPE_CHECKING
  import warnings
  from tqdm.auto import trange
  import numpy
  from art.config import ART_NUMPY_DTYPE
  from art.estimators.classification.pytorch import PyTorchClassifier
  from art.estimators.certification.randomized_smoothing.randomized_smoothing import RandomizedSmoothingMixin
  from art.utils import check_and_transform_label_format
label_desc: Use image node_id 1 to create a new PyTorchRandomizedSmoothing object from inherited base classes: RandomizedSmoothingMixin, PyTorchClassifier with example: obj = PyTorchRandomizedSmoothing(model, loss, input_shape, nb_classes, optimizer, channels_first, clip_values, preprocessing_defences, postprocessing_defences, preprocessing, device_type, sample_size, scale, alpha)