docstr: Tests path properties for 1-dimentional Ito process.
  
  We construct the following Ito process.
  
  ````
  dX = mu * sqrt(t) * dt + (a * t + b) dW
  ````
  
  For this process expected value at time t is x_0 + 2/3 * mu * t^1.5 .
docstr_tok: ["Tests","path","properties","for","1-dimentional","Ito","process",".","We","construct","the","following","Ito","process",".","``","``","dX","=","mu","*","sqrt","(","t",")","*","dt","+","(","a","*","t","+","b",")","dW","``","``","For","this","process","expected","value","at","time","t","is","x_0","+","2\/3","*","mu","*","t^1.5","."]
code: def test_sample_paths_1d(self):
      """Tests path properties for 1-dimentional Ito process.
  
      We construct the following Ito process.
  
      ````
      dX = mu * sqrt(t) * dt + (a * t + b) dW
      ````
  
      For this process expected value at time t is x_0 + 2/3 * mu * t^1.5 .
      """
      mu = 0.2
      a = 0.4
      b = 0.33
  
      def drift_fn(t, x):
          return mu * tf.sqrt(t) * tf.ones_like(x, dtype=t.dtype)
  
      def vol_fn(t, x):
          del x
          return (a * t + b) * tf.ones([1, 1], dtype=t.dtype)
  
      times = np.array([0.0, 0.1, 0.21, 0.32, 0.43, 0.55])
      num_samples = 10000
      x0 = np.array([0.1])
      paths = self.evaluate(
          milstein_sampling.sample(
              dim=1,
              drift_fn=drift_fn,
              volatility_fn=vol_fn,
              times=times,
              num_samples=num_samples,
              initial_state=x0,
              random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
              time_step=0.01,
              seed=[1, 42],
          )
      )
      paths_no_zero = self.evaluate(
          milstein_sampling.sample(
              dim=1,
              drift_fn=drift_fn,
              volatility_fn=vol_fn,
              times=times[1:],
              num_samples=num_samples,
              initial_state=x0,
              random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
              time_step=0.01,
              seed=[1, 42],
          )
      )
  
      with self.subTest("CorrectShape"):
          self.assertAllClose(paths.shape, (num_samples, 6, 1), atol=0)
      means = np.mean(paths, axis=0).reshape(-1)
      expected_means = x0 + (2.0 / 3.0) * mu * np.power(times, 1.5)
      with self.subTest("ExpectedResult"):
          self.assertAllClose(
              means, expected_means, rtol=1e-2, atol=1e-2
          )
      with self.subTest("IncludeInitialState"):
          self.assertAllClose(paths[:, 1:, :], paths_no_zero)
  
file_path: tf-quant-finance/tf_quant_finance/models/milstein_sampling_test.py
imports: import functools
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  import tf_quant_finance
  from tensorflow.python.framework import test_util
  from tf_quant_finance.math import gradient
label_desc: Use image node_id 2 for calling the MilsteinSamplingTest obj's underlying member method code with example usage: obj.test_sample_paths_1d() and returns: unknown, unknown