class_docstr: Base class for Ito processes.
  
    Represents a general Ito process:
  
    ```None
      dX_i = a_i(t, X) dt + Sum(S_{ij}(t, X) dW_j for 1 <= j <= n), 1 <= i <= n
    ```
  
  The vector coefficient `a_i` is referred to as the drift of the process and
  the matrix `S_{ij}` as the volatility of the process. For the process to be
  well defined, these coefficients need to satisfy certain technical conditions
  which may be found in Ref. [1]. The vector `dW_j` represents independent
  Brownian increments.
  
  #### Example. 2-dimensional Ito process of the form
  
  ```none
  dX_1 = mu_1 * sqrt(t) dt + s11 * dW_1 + s12 * dW_2
  dX_2 = mu_2 * sqrt(t) dt + s21 * dW_1 + s22 * dW_2
  ```
  
  class SimpleItoProcess(ito_process.ItoProcess):
    def __init__(self, dim, drift_fn, vol_fn, dtype=tf.float64):
      self._dim = dim
      self._drift_fn = drift_fn
      self._vol_fn = vol_fn
      self._dtype = dtype
  
    def dim(self):
      return self._dim
  
    def drift_fn(self):
      return self._drift_fn
  
    def volatility_fn(self):
      return self._vol_fn
  
    def dtype(self):
      return self._dtype
  
    def name(self):
      return 'simple_ito_process'
  
  mu = np.array([0.2, 0.7])
  s = np.array([[0.3, 0.1], [0.1, 0.3]])
  num_samples = 10000
  dim = 2
  dtype=tf.float64
  
  # Define drift and volatility functions
  def drift_fn(t, x):
    return mu * tf.sqrt(t) * tf.ones([num_samples, dim], dtype=dtype)
  
  def vol_fn(t, x):
    return s * tf.ones([num_samples, dim, dim], dtype=dtype)
  
  # Initialize `SimpleItoProcess`
  process = SimpleItoProcess(dim=2, drift_fn=drift_fn, vol_fn=vol_fn,
                             dtype=dtype)
  # Set starting location
  x0 = np.array([0.1, -1.1])
  # Sample `num_samples` paths at specified `times` locations using built-in
  # Euler scheme.
  times = [0.1, 1.0, 2.0]
  paths = process.sample_paths(
            times,
            num_samples=num_samples,
            initial_state=x0,
            grid_step=0.01,
            seed=42)
  
  #### References
  [1]: Brent Oksendal. Stochastic Differential Equations: An Introduction with
    Applications. Springer. 2010.
docstr: Returns a sample of paths from the process.
  
  The default implementation uses Euler schema. However, for particular types
  of Ito processes more efficient schemes can be used.
  
  Args:
    times: Rank 1 `Tensor` of increasing positive real values. The times at
      which the path points are to be evaluated.
    num_samples: Positive scalar `int`. The number of paths to draw.
    initial_state: `Tensor` of shape `[dim]`. The initial state of the
      process.
      Default value: None which maps to a zero initial state.
    random_type: Enum value of `RandomType`. The type of (quasi)-random number
      generator to use to generate the paths.
      Default value: None which maps to the standard pseudo-random numbers.
    seed: Python `int`. The random seed to use. If not supplied, no seed is
      set.
    swap_memory: Whether GPU-CPU memory swap is enabled for this op. See
      equivalent flag in `tf.while_loop` documentation for more details.
      Useful when computing a gradient of the op since `tf.while_loop` is used
      to propagate stochastic process in time.
    name: str. The name to give this op. If not supplied, default name of
      `sample_paths` is used.
    **kwargs: parameters, specific to Euler schema: `grid_step` is rank 0 real
      `Tensor` - maximal distance between points in grid in Euler schema.
  
  Returns:
   A real `Tensor` of shape [num_samples, k, n] where `k` is the size of the
      `times`, `n` is the dimension of the process.
docstr_tok: ["Returns","a","sample","of","paths","from","the","process",".","The","default","implementation","uses","Euler","schema",".","However",",","for","particular","types","of","Ito","processes","more","efficient","schemes","can","be","used",".","Args",":","times",":","Rank","1","`","Tensor","`","of","increasing","positive","real","values",".","The","times","at","which","the","path","points","are","to","be","evaluated",".","num_samples",":","Positive","scalar","`","int","`",".","The","number","of","paths","to","draw",".","initial_state",":","`","Tensor","`","of","shape","`","[","dim","]","`",".","The","initial","state","of","the","process",".","Default","value",":","None","which","maps","to","a","zero","initial","state",".","random_type",":","Enum","value","of","`","RandomType","`",".","The","type","of","(","quasi",")","-random","number","generator","to","use","to","generate","the","paths",".","Default","value",":","None","which","maps","to","the","standard","pseudo-random","numbers",".","seed",":","Python","`","int","`",".","The","random","seed","to","use",".","If","not","supplied",",","no","seed","is","set",".","swap_memory",":","Whether","GPU-CPU","memory","swap","is","enabled","for","this","op",".","See","equivalent","flag","in","`","tf.while_loop","`","documentation","for","more","details",".","Useful","when","computing","a","gradient","of","the","op","since","`","tf.while_loop","`","is","used","to","propagate","stochastic","process","in","time",".","name",":","str",".","The","name","to","give","this","op",".","If","not","supplied",",","default","name","of","`","sample_paths","`","is","used",".","*","*","kwargs",":","parameters",",","specific","to","Euler","schema",":","`","grid_step","`","is","rank","0","real","`","Tensor","`","-","maximal","distance","between","points","in","grid","in","Euler","schema",".","Returns",":","A","real","`","Tensor","`","of","shape","[","num_samples",",","k",",","n","]","where","`","k","`","is","the","size","of","the","`","times","`",",","`","n","`","is","the","dimension","of","the","process","."]
code: def sample_paths(
      self,
      times,
      num_samples=1,
      initial_state=None,
      random_type=None,
      seed=None,
      swap_memory=True,
      name=None,
      **kwargs,
  ):
      """Returns a sample of paths from the process.
  
      The default implementation uses Euler schema. However, for particular types
      of Ito processes more efficient schemes can be used.
  
      Args:
        times: Rank 1 `Tensor` of increasing positive real values. The times at
          which the path points are to be evaluated.
        num_samples: Positive scalar `int`. The number of paths to draw.
        initial_state: `Tensor` of shape `[dim]`. The initial state of the
          process.
          Default value: None which maps to a zero initial state.
        random_type: Enum value of `RandomType`. The type of (quasi)-random number
          generator to use to generate the paths.
          Default value: None which maps to the standard pseudo-random numbers.
        seed: Python `int`. The random seed to use. If not supplied, no seed is
          set.
        swap_memory: Whether GPU-CPU memory swap is enabled for this op. See
          equivalent flag in `tf.while_loop` documentation for more details.
          Useful when computing a gradient of the op since `tf.while_loop` is used
          to propagate stochastic process in time.
        name: str. The name to give this op. If not supplied, default name of
          `sample_paths` is used.
        **kwargs: parameters, specific to Euler schema: `grid_step` is rank 0 real
          `Tensor` - maximal distance between points in grid in Euler schema.
  
      Returns:
       A real `Tensor` of shape [num_samples, k, n] where `k` is the size of the
          `times`, `n` is the dimension of the process.
      """
      if self.drift_fn() is None or self.volatility_fn() is None:
          raise NotImplementedError(
              "In order to use Euler scheme, both drift_fn and volatility_fn "
              "should be provided."
          )
      default_name = self.name() + "_sample_paths"
      with tf.compat.v1.name_scope(
          name, default_name=default_name, values=[times, initial_state]
      ):
          if initial_state is None:
              initial_state = tf.zeros(self._dim, dtype=self._dtype)
          times = tf.convert_to_tensor(times, dtype=self._dtype)
          initial_state = tf.convert_to_tensor(
              initial_state, dtype=self._dtype, name="initial_state"
          )
          num_requested_times = tf.shape(times)[-1]
          grid_step = kwargs["grid_step"]
          times, keep_mask = self._prepare_grid(times, grid_step)
          return self._sample_paths(
              times,
              grid_step,
              keep_mask,
              num_requested_times,
              num_samples,
              initial_state,
              random_type,
              seed,
              swap_memory,
          )
  
file_path: tf-quant-finance/tf_quant_finance/models/legacy/ito_process.py
imports: import abc
  import six
  import tensorflow.compat.v2
  from tf_quant_finance.math import random_ops
label_desc: Use image node_id 6 for calling the ItoProcess obj's underlying member method code with example usage: obj.sample_paths(times, num_samples, initial_state, random_type, seed, swap_memory, name) and returns: self