class_docstr: Our Method: Double Noise Mechanism
docstr: computing gradient
docstr_tok: ["computing","gradient"]
code: def noisy_grad(self, w_cur, lrp, hyper_dict, batch=False):
      """computing gradient"""
      if batch is False:
          rho_grad = (
              hyper_dict["grad_frac"] * hyper_dict["total"]
          ) / hyper_dict["num_iteration"]
          noise_grad = np.random.normal(
              scale=(1 / lrp.num_samples) * np.sqrt(0.5 / rho_grad),
              size=lrp.dim,
          )
          noisy_grad = lrp.grad(w_cur) + noise_grad
      else:
          std_grad = hyper_dict["noise_multiplier_grad"]
          pgrad = hyper_dict["batchsize_grad"] / lrp.num_samples
          sample_vec = np.random.binomial(
              n=1, p=pgrad, size=lrp.num_samples
          )
          batch_idx_grad = np.where(sample_vec == 1)[0]
          grad_minibatch = lrp.grad_wor(w_cur, batch_idx_grad)
          noise_grad = np.random.normal(scale=std_grad, size=lrp.dim)
          noisy_grad = (
              len(batch_idx_grad) / (lrp.num_samples * pgrad)
          ) * grad_minibatch + (noise_grad) / (lrp.num_samples * pgrad)
      return noisy_grad
  
imports: import time
  from my_logistic_regression import MyLogisticRegression
  import numpy
label_desc: Use image node_id 4 for calling the DoubleNoiseMech obj's underlying member method code with example usage: obj.noisy_grad(w_cur, lrp, hyper_dict, batch) and returns: noisy_grad