class_docstr: This class implements the black-box attack `SimBA`.
  
  | Paper link: https://arxiv.org/abs/1905.07121
class_docstr_tok: ["This","class","implements","the","black-box","attack","`","SimBA","`",".","|","Paper","link",":","https",":","\/\/arxiv.org\/abs\/1905.07121"]
docstr: Applies IDCT to each block of size block_size.
  
  :param x: An array with the inputs to be attacked.
  :param block_size: block size for DCT attacks.
  :param masked: use the mask.
  :param ratio: Ratio of the lowest frequency directions in order to make the adversarial perturbation in the low
                frequency space.
  
  :return var_z: An array holding the order of DCT attacks.
docstr_tok: ["Applies","IDCT","to","each","block","of","size","block_size",".",":","param","x",":","An","array","with","the","inputs","to","be","attacked",".",":","param","block_size",":","block","size","for","DCT","attacks",".",":","param","masked",":","use","the","mask",".",":","param","ratio",":","Ratio","of","the","lowest","frequency","directions","in","order","to","make","the","adversarial","perturbation","in","the","low","frequency","space",".",":","return","var_z",":","An","array","holding","the","order","of","DCT","attacks","."]
code: def _block_idct(self, x, block_size=8, masked=False, ratio=0.5):
      """
      Applies IDCT to each block of size block_size.
  
      :param x: An array with the inputs to be attacked.
      :param block_size: block size for DCT attacks.
      :param masked: use the mask.
      :param ratio: Ratio of the lowest frequency directions in order to make the adversarial perturbation in the low
                    frequency space.
  
      :return var_z: An array holding the order of DCT attacks.
      """
      if not self.estimator.channels_first:
          x = x.transpose(0, 3, 1, 2)
      var_z = np.zeros(x.shape).astype(ART_NUMPY_DTYPE)
      num_blocks = int(x.shape[2] / block_size)
      mask = np.zeros((x.shape[0], x.shape[1], block_size, block_size))
      if not isinstance(ratio, float):
          for i in range(x.shape[0]):
              mask[
                  i,
                  :,
                  : int(block_size * ratio[i]),
                  : int(block_size * ratio[i]),
              ] = 1
      else:
          mask[
              :, :, : int(block_size * ratio), : int(block_size * ratio)
          ] = 1
      for i in range(num_blocks):
          for j in range(num_blocks):
              submat = x[
                  :,
                  :,
                  (i * block_size) : ((i + 1) * block_size),
                  (j * block_size) : ((j + 1) * block_size),
              ]
              if masked:
                  submat = submat * mask
              var_z[
                  :,
                  :,
                  (i * block_size) : ((i + 1) * block_size),
                  (j * block_size) : ((j + 1) * block_size),
              ] = idct(
                  idct(submat, axis=3, norm="ortho"),
                  axis=2,
                  norm="ortho",
              )
  
      if self.estimator.channels_first:
          return var_z
  
      return var_z.transpose((0, 2, 3, 1))
  
file_path: adversarial-robustness-toolbox/art/attacks/evasion/simba.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, TYPE_CHECKING
  import numpy
  from scipy.fftpack import idct
  from tqdm.auto import trange
  from art.attacks.attack import EvasionAttack
  from art.estimators.estimator import BaseEstimator, NeuralNetworkMixin
  from art.estimators.classification.classifier import ClassifierMixin
  from art.config import ART_NUMPY_DTYPE
  from art.utils import is_probability
label_desc: Use image node_id 5 for calling the SimBA obj's underlying member method code with example usage: obj._block_idct(x, block_size, masked, ratio) and returns: var_z, var_z