docstr: Tests that GBM sampling can accept dynamically shaped inputs.
docstr_tok: ["Tests","that","GBM","sampling","can","accept","dynamically","shaped","inputs","."]
code: def test_univariate_dynamic_inputs(self):
      """Tests that GBM sampling can accept dynamically shaped inputs."""
      times = [0.1, 0.5, 1.0]
      initial_state = [[1.0], [2.0]]
  
      @tf.function(
          input_signature=[
              tf.TensorSpec(
                  [None, None], dtype=tf.float64, name="initial_state"
              ),
              tf.TensorSpec([None, 1], dtype=tf.float64, name="mean"),
              tf.TensorSpec(
                  [None, 1], dtype=tf.float64, name="volatility"
              ),
              tf.TensorSpec([None], dtype=tf.float64, name="times"),
          ]
      )
      def sample_fn(initial_state, mean, volatility, times):
          process = tff.models.GeometricBrownianMotion(
              mean=mean, volatility=volatility, dtype=tf.float64
          )
          return process.sample_paths(
              times=times,
              initial_state=initial_state,
              num_samples=10000,
          )
  
      mean = np.array([[0.05], [0.1]], dtype=np.float64)
      volatility = np.array([[0.1]], dtype=np.float64)
      samples = sample_fn(
          initial_state=initial_state,
          mean=mean,
          volatility=volatility,
          times=times,
      )
      log_s = tf.math.log(samples)
      expected_mean = (mean - volatility**2 / 2) * np.array(
          np.expand_dims(times, 0)
      ) + np.log(initial_state)
      actual_mean = tf.reduce_mean(log_s, axis=1)
      self.assertAllClose(
          actual_mean,
          expected_mean[..., np.newaxis],
          atol=1e-2,
          rtol=1e-2,
      )
  
imports: 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.models.geometric_brownian_motion import geometric_brownian_motion_test_utils
  from tf_quant_finance.models.geometric_brownian_motion import univariate_geometric_brownian_motion
label_desc: Use image node_id 22 for calling the GeometricBrownianMotionTest obj's underlying member method code with example usage: obj.test_univariate_dynamic_inputs() and returns: process