docstr: Tests the QMC evaluation of (x_j + x_{j+1} ...+x_{n})^2.
  
  A good test of QMC is provided by the function:
  
    f(x_1,..x_n, x_{n+1}, ..., x_{n+m}) = (x_{n+1} + ... x_{n+m} - m / 2)^2
  
  with the coordinates taking values in the unit interval. The mean and
  variance of this function (with the uniform distribution over the
  unit-hypercube) is exactly calculable:
  
    <f> = m / 12, Var(f) = m (5m - 3) / 360
  
  The purpose of the "shift" (if n > 0) in the coordinate dependence of the
  function is to provide a test for Halton sequence which exhibit more
  dependence in the higher axes.
  
  This test confirms that the mean squared error of RQMC estimation falls
  as O(N^(2-e)) for any e>0.
docstr_tok: ["Tests","the","QMC","evaluation","of","(","x_j","+","x_","{","j+1","}","...","+x_","{","n","}",")","^2",".","A","good","test","of","QMC","is","provided","by","the","function",":","f","(","x_1",",","..","x_n",",","x_","{","n+1","}",",","...",",","x_","{","n+m","}",")","=","(","x_","{","n+1","}","+","...","x_","{","n+m","}","-","m","\/","2",")","^2","with","the","coordinates","taking","values","in","the","unit","interval",".","The","mean","and","variance","of","this","function","(","with","the","uniform","distribution","over","the","unit-hypercube",")","is","exactly","calculable",":","<","f",">","=","m","\/","12",",","Var","(","f",")","=","m","(","5m","-","3",")","\/","360","The","purpose","of","the","``","shift","''","(","if","n",">","0",")","in","the","coordinate","dependence","of","the","function","is","to","provide","a","test","for","Halton","sequence","which","exhibit","more","dependence","in","the","higher","axes",".","This","test","confirms","that","the","mean","squared","error","of","RQMC","estimation","falls","as","O","(","N^","(","2-e",")",")","for","any","e",">","0","."]
code: def test_partial_sum_func_qmc(self):
      """Tests the QMC evaluation of (x_j + x_{j+1} ...+x_{n})^2.
  
      A good test of QMC is provided by the function:
  
        f(x_1,..x_n, x_{n+1}, ..., x_{n+m}) = (x_{n+1} + ... x_{n+m} - m / 2)^2
  
      with the coordinates taking values in the unit interval. The mean and
      variance of this function (with the uniform distribution over the
      unit-hypercube) is exactly calculable:
  
        <f> = m / 12, Var(f) = m (5m - 3) / 360
  
      The purpose of the "shift" (if n > 0) in the coordinate dependence of the
      function is to provide a test for Halton sequence which exhibit more
      dependence in the higher axes.
  
      This test confirms that the mean squared error of RQMC estimation falls
      as O(N^(2-e)) for any e>0.
      """
      n, m = 5, 5
      dim = n + m
      num_results_lo, num_results_hi = 500, 5000
      replica = 10
      true_mean = m / 12.0
      seed_lo = 1925
      seed_hi = 898128
  
      def func_estimate(x):
          return tf.reduce_mean(
              input_tensor=tf.math.squared_difference(
                  tf.reduce_sum(input_tensor=x[:, -m:], axis=-1),
                  m / 2.0,
              )
          )
  
      estimates = []
      for i in range(replica):
          sample_lo, _ = random.halton.sample(
              dim, num_results=num_results_lo, seed=seed_lo + i
          )
          sample_hi, _ = random.halton.sample(
              dim, num_results=num_results_hi, seed=seed_hi + i
          )
          f_lo, f_hi = func_estimate(sample_lo), func_estimate(
              sample_hi
          )
          estimates.append((self.evaluate(f_lo), self.evaluate(f_hi)))
      var_lo, var_hi = np.mean(
          (np.array(estimates) - true_mean) ** 2, axis=0
      )
  
      # Expect that the variance scales as N^2 so var_hi / var_lo ~ k / 10^2
      # with k a fudge factor accounting for the residual N dependence
      # of the QMC error and the sampling error.
      log_rel_err = np.log(100 * var_hi / var_lo)
      self.assertAllClose(log_rel_err, 0.0, atol=1.2)
  
imports: import numpy
  from six.moves import range
  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 8 for calling the HaltonSequenceTest obj's underlying member method code with example usage: obj.test_partial_sum_func_qmc() and returns: tf