code: def test_normal_integral_mean_and_var_correctly_estimated(self):
      n = int(1000)
      # This test is almost identical to the similarly named test in
      # monte_carlo_test.py. The only difference is that we use the Sobol
      # samples instead of the random samples to evaluate the expectations.
      # MC with pseudo random numbers converges at the rate of 1/ Sqrt(N)
      # (N=number of samples). For QMC in low dimensions, the expected convergence
      # rate is ~ 1/N. Hence we should only need 1e3 samples as compared to the
      # 1e6 samples used in the pseudo-random monte carlo.
      dtype = tf.float64
      mu_p = tf.constant([-1.0, 1.0], dtype=dtype)
      mu_q = tf.constant([0.0, 0.0], dtype=dtype)
      sigma_p = tf.constant([0.5, 0.5], dtype=dtype)
      sigma_q = tf.constant([1.0, 1.0], dtype=dtype)
      p = tfp.distributions.Normal(loc=mu_p, scale=sigma_p)
      q = tfp.distributions.Normal(loc=mu_q, scale=sigma_q)
  
      cdf_sample = random.sobol.sample(2, n, dtype=dtype)
      q_sample = q.quantile(cdf_sample)
  
      # Compute E_p[X].
      e_x = tf.reduce_mean(
          q_sample * p.prob(q_sample) / q.prob(q_sample), 0
      )
  
      # Compute E_p[X^2 - E_p[X]^2].
      e_x2 = tf.reduce_mean(
          q_sample**2 * p.prob(q_sample) / q.prob(q_sample)
          - e_x**2,
          0,
      )
      stddev = tf.sqrt(e_x2)
  
      # Keep the tolerance levels the same as in monte_carlo_test.py.
      self.assertEqual(p.batch_shape, e_x.shape)
      self.assertAllClose(
          self.evaluate(p.mean()), self.evaluate(e_x), rtol=0.01
      )
      self.assertAllClose(
          self.evaluate(p.stddev()), self.evaluate(stddev), rtol=0.02
      )
  
file_path: tf-quant-finance/tf_quant_finance/math/random_ops/sobol/sobol_test.py
imports: import numpy
  import tensorflow.compat.v2
  import tensorflow_probability
  from tensorflow.python.framework import test_util
  from tf_quant_finance.math import random
label_desc: Use image node_id 6 for calling the SampleSobolSequenceTest obj's underlying member method code with example usage: obj.test_normal_integral_mean_and_var_correctly_estimated() without return types