docstr: Tests batch of 1-Factor model with constant parameters.
docstr_tok: ["Tests","batch","of","1-Factor","model","with","constant","parameters","."]
code: def test_mean_and_variance_batch(self, dim, corr_matrix, dtype):
      """Tests batch of 1-Factor model with constant parameters."""
      if dim == 1:
          mr = self.mean_reversion_batch_1_factor
          vol = self.volatility_batch_1_factor
      else:
          mr = self.mean_reversion_batch_2_factor
          vol = self.volatility_batch_2_factor
  
      process = tff.models.hjm.QuasiGaussianHJM(
          dim=dim,
          mean_reversion=mr,
          volatility=vol,
          initial_discount_rate_fn=self.instant_forward_rate_batch,
          corr_matrix=corr_matrix,
          dtype=dtype,
      )
  
      paths, _, _, _ = process.sample_paths(
          [0.1, 0.5, 1.0],
          num_samples=20000,
          time_step=0.1,
          num_time_steps=None,
          random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
          seed=[1, 2],
          skip=1000000,
      )
  
      paths = self.evaluate(paths)
      self.assertAllEqual(paths.shape, [2, 20000, 3])
      paths = paths[
          :, :, -1
      ]  # Extract paths values for the terminal time
      mean = np.mean(paths, axis=-1)
      variance = np.var(paths, axis=-1)
      f_0_t = [0.01, 0.02]
      for i in range(2):
          if dim == 1:
              eff_vol = vol[i][0]
          else:
              if corr_matrix is None:
                  c = 0.0
              else:
                  c = corr_matrix[i][1][0]
              eff_vol = np.sqrt(
                  vol[i][0] ** 2
                  + vol[i][1] ** 2
                  + 2 * c * vol[i][0] * vol[i][1]
              )
          with self.subTest("CloseMean"):
              self.assertAllClose(
                  mean[i],
                  self.true_mean(
                      1.0,
                      mr[i][0],
                      eff_vol,
                      self.initial_state_batch[i][0][0],
                      f_0_t[i],
                  ),
                  rtol=1e-4,
                  atol=1e-4,
              )
          with self.subTest("CloseStd"):
              self.assertAllClose(
                  variance[i],
                  self.true_var(1.0, mr[i][0], eff_vol),
                  rtol=1e-4,
                  atol=1e-4,
              )
  
file_path: tf-quant-finance/tf_quant_finance/models/hjm/quasi_gaussian_hjm_test.py
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  import tf_quant_finance
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 4 for calling the HJMModelTest obj's underlying member method code with example usage: obj.test_mean_and_variance_batch(dim, corr_matrix, dtype) without return types