class_docstr: Our Method: Double Noise Mechanism
docstr: noisy direction for stochastic variant
docstr_tok: ["noisy","direction","for","stochastic","variant"]
code: def noisy_direction_stochastic(
      self, w_cur, lrp, hyper_dict, noisy_grad
  ):
      """noisy direction for stochastic variant"""
      std_hess = hyper_dict["noise_multiplier_hess"]
      phess = hyper_dict["batchsize_hess"] / lrp.num_samples
      min_eval = hyper_dict["min_eval"]
      sample_vec = np.random.binomial(
          n=1, p=phess, size=lrp.num_samples
      )
      batch_idx_hess = np.where(sample_vec == 1)[0]
      batch_size_hess_t = len(batch_idx_hess)
      hess_cur = (
          (batch_size_hess_t)
          / (lrp.num_samples * phess)
          * self.hess(w_cur, batch_idx_hess)
      )
      smooth_param = 0.25  # smoothness parameter
      grad_norm = np.linalg.norm(noisy_grad)
      if (
          self.type_reg == "add"
      ):  # Sensitivity is different for add vs clip
          sens2 = (
              grad_norm
              * smooth_param
              / (
                  (lrp.num_samples * phess) * min_eval**2
                  + smooth_param * min_eval
              )
          )
          noise2 = np.random.normal(
              scale=sens2 * std_hess, size=lrp.dim
          )
          return (
              w_cur
              - np.linalg.solve(
                  hess_cur + min_eval * np.eye(len(hess_cur)),
                  noisy_grad,
              )
              + noise2
          )
      # type_reg=clip
      min_eval_c = max(min_eval, 1 / ((lrp.num_samples * phess)))
      sens2 = (
          grad_norm
          * smooth_param
          / (
              (lrp.num_samples * phess) * min_eval_c**2
              - smooth_param * min_eval_c
          )
      )
      noise2 = np.random.normal(scale=sens2 * std_hess, size=lrp.dim)
      eval_hess, evec_hess = np.linalg.eigh(hess_cur)
      eval_trunc = eval_hess[eval_hess >= min_eval_c]
      num_eig = len(eval_trunc)
      if num_eig == 0:
          hess_modified_inv = 1 / min_eval_c * np.eye(lrp.dim)
      else:
          evec_trun = evec_hess[:, -num_eig:]
          hess_modified_inv = np.dot(
              evec_trun
              * (1 / eval_trunc - 1 / min_eval_c * np.ones(num_eig)),
              evec_trun.T,
          ) + 1 / min_eval_c * np.eye(lrp.dim)
      return w_cur - (hess_modified_inv @ noisy_grad) + noise2
  
imports: import time
  from my_logistic_regression import MyLogisticRegression
  import numpy
label_desc: Use image node_id 6 for calling the DoubleNoiseMech obj's underlying member method code with example usage: obj.noisy_direction_stochastic(w_cur, lrp, hyper_dict, noisy_grad) and returns: unknown, unknown