code: def estimate_advantage_bias_and_variance(
      advantage_fn,
      mean_reward=1.23,
      reward_noise=0.45,
      discount_mask=None,
      discount_true_return=True,
      true_value=False,
      n_samples=10000,
      length=5,
      gamma=0.9,
      margin=1,
      **advantage_kwargs,
  ):
      advantage_fn = advantage_fn(gamma, margin, **advantage_kwargs)
      rewards = np.random.normal(
          loc=mean_reward, scale=reward_noise, size=(n_samples, length)
      )
      if discount_mask is None:
          discount_mask = np.ones_like(rewards)
      gammas = advantages.mask_discount(gamma, discount_mask)
      returns = advantages.discounted_returns(rewards, gammas)
  
      true_returns = advantages.discounted_returns(
          np.full(returns.shape, fill_value=mean_reward), gammas=gammas
      )
      if true_value:
          values = true_returns
      else:
          values = np.zeros_like(returns)
  
      dones = np.zeros_like(returns, dtype=bool)
      adv = advantage_fn(rewards, returns, values, dones, discount_mask)
      if discount_true_return:
          mean_return = true_returns[0, 0]
      else:
          mean_return = mean_reward * length
      return calc_bias_and_variance(
          adv[:, 0], mean_return - values[:, 0]
      )
  
file_path: trax/trax/rl/advantages_test.py
imports: import functools
  from absl.testing import absltest
  from absl.testing import parameterized
  import numpy
  from trax.rl import advantages
label_desc: Use image node_id 2 for calling a global function with example usage: estimate_advantage_bias_and_variance(advantage_fn, mean_reward, reward_noise, discount_mask, discount_true_return, true_value, n_samples, length, gamma, margin) and returns: calc_bias_and_variance