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: Perform prediction of the given classifier for a batch of inputs, taking an expectation over transformations.
  
  :param x: Input samples.
  :param batch_size: Batch size.
  :param verbose: Display training progress bar.
  :param is_abstain: True if function will abstain from prediction and return 0s. Default: True
  :type is_abstain: `boolean`
  :return: Array of predictions of shape `(nb_inputs, nb_classes)`.
docstr_tok: ["Perform","prediction","of","the","given","classifier","for","a","batch","of","inputs",",","taking","an","expectation","over","transformations",".",":","param","x",":","Input","samples",".",":","param","batch_size",":","Batch","size",".",":","param","verbose",":","Display","training","progress","bar",".",":","param","is_abstain",":","True","if","function","will","abstain","from","prediction","and","return","0s",".","Default",":","True",":","type","is_abstain",":","`","boolean","`",":","return",":","Array","of","predictions","of","shape","`","(","nb_inputs",",","nb_classes",")","`","."]
code: def predict(
      self,
      x: np.ndarray,
      batch_size: int = 128,
      verbose: bool = False,
      **kwargs,
  ) -> np.ndarray:
      """
      Perform prediction of the given classifier for a batch of inputs, taking an expectation over transformations.
  
      :param x: Input samples.
      :param batch_size: Batch size.
      :param verbose: Display training progress bar.
      :param is_abstain: True if function will abstain from prediction and return 0s. Default: True
      :type is_abstain: `boolean`
      :return: Array of predictions of shape `(nb_inputs, nb_classes)`.
      """
      from scipy.stats import binom_test
  
      is_abstain = kwargs.get("is_abstain")
      if is_abstain is not None and not isinstance(
          is_abstain, bool
      ):  # pragma: no cover
          raise ValueError(
              "The argument is_abstain needs to be of type bool."
          )
      if is_abstain is None:
          is_abstain = True
  
      logger.info("Applying randomized smoothing.")
      n_abstained = 0
      prediction = []
      for x_i in tqdm(
          x, desc="Randomized smoothing", disable=not verbose
      ):
          # get class counts
          counts_pred = self._prediction_counts(
              x_i, batch_size=batch_size
          )
          top = counts_pred.argsort()[::-1]
          count1 = np.max(counts_pred)
          count2 = counts_pred[top[1]]
  
          # predict or abstain
          smooth_prediction = np.zeros(counts_pred.shape)
          if (not is_abstain) or (
              binom_test(count1, count1 + count2, p=0.5) <= self.alpha
          ):
              smooth_prediction[np.argmax(counts_pred)] = 1
          elif is_abstain:
              n_abstained += 1
  
          prediction.append(smooth_prediction)
      if n_abstained > 0:
          logger.info("%s prediction(s) abstained.", n_abstained)
      return np.array(prediction)
  
file_path: adversarial-robustness-toolbox/art/estimators/certification/randomized_smoothing/randomized_smoothing.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  from abc import ABC
  import logging
  from typing import Optional, Tuple
  import numpy
  from scipy.stats import norm
  from tqdm.auto import tqdm
  from art.config import ART_NUMPY_DTYPE
label_desc: Use image node_id 3 for calling the RandomizedSmoothingMixin obj's underlying member method code with example usage: obj.predict(x, batch_size, verbose) and returns: np