code: def sweep_epsilon(
      layer, inp, pert_rng, out_shape=None, lshape=None, pert_frac=0.1
  ):
      # sweep the given list of perturbations (pert_rng)
      # return perturbation magnitude which gave best
      # match between brop deltas and finite diff grads
  
      if out_shape is None:
          # if the output shape is not provided
          # get it by running fprop
          inpa = layer.be.array(inp.copy())
          in_shape = lshape if lshape is not None else inpa.shape[0]
          layer.configure(in_shape)
          out_shape = layer.out_shape
  
      # generate loss_scale outside so that the the
      # model/be state can be reset and the computation
      # is repeatable...for some reason the first run is
      # not repeatable if loss_scale is generated inside
      # self.general_gradient_comp()
      loss_scale = np.random.random(out_shape) * 2.0 - 1.0
  
      # select pert_frac fraction of inps to perturb
      pert_cnt = int(np.ceil(inpa.size * pert_frac))
      pert_inds = np.random.permutation(inpa.size)[0:pert_cnt]
  
      layer.be.rng_reset()  # reset to same initial rng state
  
      min_max_diff = -1.0
      min_max_pert = None
      neon_logger.display("epsilon, max diff")
      for epsilon in pert_rng:
          (max_abs, max_rel) = general_gradient_comp(
              layer,
              inp,
              epsilon=epsilon,
              loss_scale=loss_scale,
              lshape=lshape,
              pert_inds=pert_inds,
          )
          layer.be.rng_reset()  # reset to same initial rng state
          if min_max_diff < 0 or max_abs < min_max_diff:
              min_max_diff = max_abs
              min_max_pert = epsilon
          neon_logger.display("%e %e %e" % (epsilon, max_abs, max_rel))
          neon_logger.display(
              "Min max diff : %e at Pert. Mag. %e"
              % (min_max_diff, min_max_pert)
          )
      return (min_max_pert, min_max_diff)
  
imports: import numpy
  from neon import logger
  from neon.layers.container import DeltasTree
label_desc: Use image node_id 1 for calling a global function with example usage: sweep_epsilon(layer, inp, pert_rng, out_shape, lshape, pert_frac) and returns: min_max_pert,  min_max_diff