docstr: Tests path properties with time dependent drift and variance.
docstr_tok: ["Tests","path","properties","with","time","dependent","drift","and","variance","."]
code: def test_paths_time_dependent(self):
      """Tests path properties with time dependent drift and variance."""
  
      def vol_fn(t):
          return tf.expand_dims(0.2 - 0.1 * tf.exp(-t), axis=-1)
  
      def variance_fn(t0, t1):
          # The instantaneous volatility is 0.2 - 0.1 e^(-t).
          tot_var = (t1 - t0) * 0.04 - (
              tf.exp(-2 * t1) - tf.exp(-2 * t0)
          ) * 0.005
          tot_var += 0.04 * (tf.exp(-t1) - tf.exp(-t0))
          return tf.reshape(tot_var, [-1, 1, 1])
  
      process = BrownianMotion(
          dim=1,
          drift=0.1,
          volatility=vol_fn,
          total_covariance_fn=variance_fn,
      )
      times = np.array([0.2, 0.33, 0.7, 0.9, 1.88])
      num_samples = 10000
      paths = self.evaluate(
          process.sample_paths(
              times,
              num_samples=num_samples,
              initial_state=np.array(0.1),
              seed=12134,
          )
      )
  
      self.assertArrayEqual(paths.shape, (num_samples, 5, 1))
      self.assertArrayNear(
          np.mean(paths, axis=0).reshape([-1]), 0.1 + times * 0.1, 0.05
      )
  
      covars = np.cov(paths.reshape([num_samples, 5]), rowvar=False)
      # Expected covariances are: cov_{ij} = variance_fn(0, min(t_i, t_j))
      min_times = np.minimum(
          times.reshape([-1, 1]), times.reshape([1, -1])
      ).reshape([-1])
      expected_covars = self.evaluate(
          variance_fn(tf.zeros_like(min_times), min_times)
      )
      self.assertArrayNear(covars.reshape([-1]), expected_covars, 0.005)
  
file_path: tf-quant-finance/tf_quant_finance/models/legacy/brownian_motion_test.py
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow.python.framework import test_util
  from tf_quant_finance.models.legacy.brownian_motion import BrownianMotion
label_desc: Use image node_id 6 for calling the BrownianMotionTest obj's underlying member method code with example usage: obj.test_paths_time_dependent() and returns: tf, tf