docstr: Tests that GBM sampling can accept dynamically shaped inputs.
docstr_tok: ["Tests","that","GBM","sampling","can","accept","dynamically","shaped","inputs","."]
code: def test_multivariate_dynamic_inputs(self):
      """Tests that GBM sampling can accept dynamically shaped inputs."""
      corr_matrix = [[1, 0.1], [0.1, 1]]
      times = [0.1, 0.5, 1.0]
      initial_state = [1.0, 2.0]
  
      @tf.function(
          input_signature=[
              tf.TensorSpec(
                  [None], dtype=tf.float64, name="initial_state"
              ),
              tf.TensorSpec([None], dtype=tf.float64, name="means"),
              tf.TensorSpec(
                  [None], dtype=tf.float64, name="volatilities"
              ),
              tf.TensorSpec(
                  [2, 2], dtype=tf.float64, name="corr_matrix"
              ),
              tf.TensorSpec([None], dtype=tf.float64, name="times"),
          ]
      )
      def sample_fn(
          initial_state, means, volatilities, corr_matrix, times
      ):
          process = tff.models.MultivariateGeometricBrownianMotion(
              dim=2,
              means=means,
              volatilities=volatilities,
              corr_matrix=corr_matrix,
              dtype=tf.float64,
          )
          return process.sample_paths(
              times=times,
              initial_state=initial_state,
              num_samples=10000,
          )
  
      means = np.array([0.05], dtype=np.float64)
      volatilities = np.array([0.1, 0.2], dtype=np.float64)
      samples = sample_fn(
          initial_state=initial_state,
          means=means,
          volatilities=volatilities,
          corr_matrix=corr_matrix,
          times=times,
      )
      log_s = tf.math.log(samples)
      expected_means = (means - volatilities**2 / 2) * np.array(
          np.expand_dims(times, -1)
      ) + np.log(initial_state)
      actual_means = tf.reduce_mean(log_s, axis=0)
      self.assertAllClose(
          actual_means, expected_means, 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 21 for calling the GeometricBrownianMotionTest obj's underlying member method code with example usage: obj.test_multivariate_dynamic_inputs() and returns: process