docstr: Tests 1-Factor model with constant parameters.
docstr_tok: ["Tests","1-Factor","model","with","constant","parameters","."]
code: def test_mean_and_variance_1d(
      self, use_xla, time_step, num_time_steps
  ):
      """Tests 1-Factor model with constant parameters."""
      dtype = tf.float64
      # exact discretization is not supported for time-dependent specification
      # of mean reversion rate.
      process = tff.models.hjm.QuasiGaussianHJM(
          dim=1,
          mean_reversion=self.mean_reversion_1_factor,
          volatility=self.volatility_1_factor,
          initial_discount_rate_fn=self.instant_forward_rate,
          dtype=dtype,
      )
  
      num_samples = 10_000
  
      def _fn():
          paths, _, _, _ = process.sample_paths(
              [0.1, 0.5, 1.0],
              num_samples=num_samples,
              time_step=time_step,
              num_time_steps=num_time_steps,
              random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
              seed=[1, 2],
              skip=1000000,
          )
          return paths
  
      if use_xla:
          paths = self.evaluate(
              tf.function(_fn, experimental_compile=True)()
          )
      else:
          paths = self.evaluate(_fn())
      self.assertAllEqual(paths.shape, [num_samples, 3])
      paths = paths[:, -1]  # Extract paths values for the terminal time
      mean = np.mean(paths, axis=0)
      variance = np.var(paths, axis=0)
      self.assertAllClose(
          mean,
          self.true_mean(
              1.0,
              self.mean_reversion_1_factor,
              self.volatility_1_factor,
              self.initial_state,
              self.instant_forward_rate(1.0),
          )[0],
          rtol=1e-4,
          atol=1e-4,
      )
      self.assertAllClose(
          variance,
          self.true_var(
              1.0,
              self.mean_reversion_1_factor,
              self.volatility_1_factor,
          )[0],
          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 2 for calling the HJMModelTest obj's underlying member method code with example usage: obj.test_mean_and_variance_1d(use_xla, time_step, num_time_steps) and returns: paths