code: def calculate_mean_and_variance_from_sample_paths(
      samples, num_samples, dtype
  ):
      """Returns the mean and variance of log(`samples`).
  
      Args:
        samples: A real `Tensor` of shape [batch_shape, `num_samples`, num_times, 1]
          containing the samples of random paths drawn from an Ito process.
        num_samples: A scalar integer. The number of sample paths in `samples`.
        dtype: The default dtype to use when converting values to `Tensor`s.
  
      Returns:
        A tuple of (mean, variance, standard_error of the mean,
        standard_error of the variance) of the log of the samples.  Where the
        components of the tuple have shape [batch_shape, num_times].
      """
      log_s = tf.math.log(samples)
      mean = tf.reduce_mean(log_s, axis=-3, keepdims=True)
      var = tf.reduce_mean((log_s - mean) ** 2, axis=-3, keepdims=True)
      mean = tf.squeeze(mean, axis=[-1, -3])
      var = tf.squeeze(var, axis=[-1, -3])
  
      # Standard error of the mean formula taken from
      # https://en.wikipedia.org/wiki/Standard_error.
      std_err_mean = tf.math.sqrt(var / num_samples)
      # Standard error of the sample variance (\sigma_{S^2}) is given by:
      # \sigma_{S^2} = S^2.\sqrt(2 / (n-1)).
      # Taken from 'Standard Errors of Mean, Variance, and Standard Deviation
      # Estimators' Ahn, Fessler 2003.
      # (https://web.eecs.umich.edu/~fessler/papers/files/tr/stderr.pdf)
      std_err_var = var * tf.math.sqrt(
          tf.constant(2.0, dtype=dtype)
          / (
              tf.constant(num_samples, dtype=dtype)
              - tf.constant(1.0, dtype=dtype)
          )
      )
      return (mean, var, std_err_mean, std_err_var)
  
file_path: tf-quant-finance/tf_quant_finance/models/geometric_brownian_motion/geometric_brownian_motion_test_utils.py
imports: import numpy
  import tensorflow.compat.v2
  import tf_quant_finance
label_desc: Use image node_id 4 for calling a global function with example usage: calculate_mean_and_variance_from_sample_paths(samples, num_samples, dtype) and returns: mean,  var,  std_err_mean,  std_err_var