class_docstr: Cox–Ingersoll–Ross model.
  
  Represents the Ito process:
  
  ```None
    dX_i(t) = (a - k*X_i(t)) * dt +  sigma * sqrt(X_i(t)) * dW_i(t)
  ```
  where
    a / k: Corresponds to the long term mean.
    k: Corresponds to the speed of reversion.
    sigma: Corresponds to the instantaneous volatility.
  
  See [1] for details.
  
  #### References:
    [1]: A. Alfonsi. Affine Diffusions and Related Processes: Simulation,
      Theory and Applications
class_docstr_tok: ["Cox\u2013Ingersoll\u2013Ross","model",".","Represents","the","Ito","process",":","``","`","None","dX_i","(","t",")","=","(","a","-","k","*","X_i","(","t",")",")","*","dt","+","sigma","*","sqrt","(","X_i","(","t",")",")","*","dW_i","(","t",")","``","`","where","a","\/","k",":","Corresponds","to","the","long","term","mean",".","k",":","Corresponds","to","the","speed","of","reversion",".","sigma",":","Corresponds","to","the","instantaneous","volatility",".","See","[","1","]","for","details",".","#","#","#","#","References",":","[","1","]",":","A.","Alfonsi",".","Affine","Diffusions","and","Related","Processes",":","Simulation",",","Theory","and","Applications"]
docstr: Returns a sample of paths from the process.
  
  Using exact simulation method from [1].
  
  Args:
    times: Rank 1 `Tensor` of positive real values. The times at which the
      path points are to be evaluated.
    initial_state: A `Tensor` of the same `dtype` as `times` and of shape
      broadcastable with `batch_shape + [num_samples, 1]`. Represents the
      initial state of the Ito process. `batch_shape` is the shape of the
      independent stochastic processes being modelled and is inferred from the
      initial state `x0`.
      Default value: `None` which maps to a initial state of ones.
    num_samples: Positive scalar `int`. The number of paths to draw.
    random_type: `STATELESS` or `PSEUDO` type from `RandomType` Enum. The type
      of (quasi)-random number generator to use to generate the paths.
    seed: The seed for the random number generator.
      For `PSEUDO` random type: it is an Integer.
      For `STATELESS` random type: it is an integer `Tensor` of shape `[2]`.
        In this case the algorithm samples random numbers with seeds `[seed[0]
        + i, seed[1] + j], i in {0, 1}, j in {0, 1, ..., num_times}`, where
        `num_times` is the size of `times`.
      Default value: `None` which means no seed is set, but it works only with
        `PSEUDO` random type. For `STATELESS` it has to be provided.
    name: Str. The name to give this op.
      Default value: `sample_paths`.
  
  Returns:
    A `Tensor`s of shape batch_shape + [num_samples, num_times, 1] where
    `num_times` is
    the size of the `times`.
  
  Raises:
    ValueError: If `random_type` or `seed` is not supported.
  
  ## Example
  
  ```python
  import tensorflow as tf
  import tf_quant_finance as tff
  
  # In this example `batch_shape` is 2, so parameters has shape [2, 1]
  process = tff.models.CirModel(
      theta=[[0.02], [0.03]],
      mean_reversion=[[0.5], [0.4]],
      sigma=[[0.1], [0.5]],
      dtype=tf.float64)
  
  num_samples = 5
  # `initial_state` has shape [num_samples, 1]
  initial_state=[[0.1], [0.2], [0.3], [0.4], [0.5]]
  times = [0.1, 0.2, 1.0]
  samples = process.sample_paths(
      times=times,
      num_samples=num_samples,
      initial_state=initial_state)
  # `samples` has shape [2, 5, 3, 1]
  ```
  
  #### References:
  [1]: A. Alfonsi. Affine Diffusions and Related Processes: Simulation,
    Theory and Applications
docstr_tok: ["Returns","a","sample","of","paths","from","the","process",".","Using","exact","simulation","method","from","[","1","]",".","Args",":","times",":","Rank","1","`","Tensor","`","of","positive","real","values",".","The","times","at","which","the","path","points","are","to","be","evaluated",".","initial_state",":","A","`","Tensor","`","of","the","same","`","dtype","`","as","`","times","`","and","of","shape","broadcastable","with","`","batch_shape","+","[","num_samples",",","1","]","`",".","Represents","the","initial","state","of","the","Ito","process",".","`","batch_shape","`","is","the","shape","of","the","independent","stochastic","processes","being","modelled","and","is","inferred","from","the","initial","state","`","x0","`",".","Default","value",":","`","None","`","which","maps","to","a","initial","state","of","ones",".","num_samples",":","Positive","scalar","`","int","`",".","The","number","of","paths","to","draw",".","random_type",":","`","STATELESS","`","or","`","PSEUDO","`","type","from","`","RandomType","`","Enum",".","The","type","of","(","quasi",")","-random","number","generator","to","use","to","generate","the","paths",".","seed",":","The","seed","for","the","random","number","generator",".","For","`","PSEUDO","`","random","type",":","it","is","an","Integer",".","For","`","STATELESS","`","random","type",":","it","is","an","integer","`","Tensor","`","of","shape","`","[","2","]","`",".","In","this","case","the","algorithm","samples","random","numbers","with","seeds","`","[","seed","[","0","]","+","i",",","seed","[","1","]","+","j","]",",","i","in","{","0",",","1","}",",","j","in","{","0",",","1",",","...",",","num_times","}","`",",","where","`","num_times","`","is","the","size","of","`","times","`",".","Default","value",":","`","None","`","which","means","no","seed","is","set",",","but","it","works","only","with","`","PSEUDO","`","random","type",".","For","`","STATELESS","`","it","has","to","be","provided",".","name",":","Str",".","The","name","to","give","this","op",".","Default","value",":","`","sample_paths","`",".","Returns",":","A","`","Tensor","`","s","of","shape","batch_shape","+","[","num_samples",",","num_times",",","1","]","where","`","num_times","`","is","the","size","of","the","`","times","`",".","Raises",":","ValueError",":","If","`","random_type","`","or","`","seed","`","is","not","supported",".","#","#","Example","``","`","python","import","tensorflow","as","tf","import","tf_quant_finance","as","tff","#","In","this","example","`","batch_shape","`","is","2",",","so","parameters","has","shape","[","2",",","1","]","process","=","tff.models.CirModel","(","theta=","[","[","0.02","]",",","[","0.03","]","]",",","mean_reversion=","[","[","0.5","]",",","[","0.4","]","]",",","sigma=","[","[","0.1","]",",","[","0.5","]","]",",","dtype=tf.float64",")","num_samples","=","5","#","`","initial_state","`","has","shape","[","num_samples",",","1","]","initial_state=","[","[","0.1","]",",","[","0.2","]",",","[","0.3","]",",","[","0.4","]",",","[","0.5","]","]","times","=","[","0.1",",","0.2",",","1.0","]","samples","=","process.sample_paths","(","times=times",",","num_samples=num_samples",",","initial_state=initial_state",")","#","`","samples","`","has","shape","[","2",",","5",",","3",",","1","]","``","`","#","#","#","#","References",":","[","1","]",":","A.","Alfonsi",".","Affine","Diffusions","and","Related","Processes",":","Simulation",",","Theory","and","Applications"]
code: def sample_paths(
      self,
      times: types.RealTensor,
      initial_state: Optional[types.RealTensor] = None,
      num_samples: int = 1,
      random_type: Optional[random.RandomType] = None,
      seed: Optional[int] = None,
      name: Optional[str] = None,
  ) -> types.RealTensor:
      """Returns a sample of paths from the process.
  
      Using exact simulation method from [1].
  
      Args:
        times: Rank 1 `Tensor` of positive real values. The times at which the
          path points are to be evaluated.
        initial_state: A `Tensor` of the same `dtype` as `times` and of shape
          broadcastable with `batch_shape + [num_samples, 1]`. Represents the
          initial state of the Ito process. `batch_shape` is the shape of the
          independent stochastic processes being modelled and is inferred from the
          initial state `x0`.
          Default value: `None` which maps to a initial state of ones.
        num_samples: Positive scalar `int`. The number of paths to draw.
        random_type: `STATELESS` or `PSEUDO` type from `RandomType` Enum. The type
          of (quasi)-random number generator to use to generate the paths.
        seed: The seed for the random number generator.
          For `PSEUDO` random type: it is an Integer.
          For `STATELESS` random type: it is an integer `Tensor` of shape `[2]`.
            In this case the algorithm samples random numbers with seeds `[seed[0]
            + i, seed[1] + j], i in {0, 1}, j in {0, 1, ..., num_times}`, where
            `num_times` is the size of `times`.
          Default value: `None` which means no seed is set, but it works only with
            `PSEUDO` random type. For `STATELESS` it has to be provided.
        name: Str. The name to give this op.
          Default value: `sample_paths`.
  
      Returns:
        A `Tensor`s of shape batch_shape + [num_samples, num_times, 1] where
        `num_times` is
        the size of the `times`.
  
      Raises:
        ValueError: If `random_type` or `seed` is not supported.
  
      ## Example
  
      ```python
      import tensorflow as tf
      import tf_quant_finance as tff
  
      # In this example `batch_shape` is 2, so parameters has shape [2, 1]
      process = tff.models.CirModel(
          theta=[[0.02], [0.03]],
          mean_reversion=[[0.5], [0.4]],
          sigma=[[0.1], [0.5]],
          dtype=tf.float64)
  
      num_samples = 5
      # `initial_state` has shape [num_samples, 1]
      initial_state=[[0.1], [0.2], [0.3], [0.4], [0.5]]
      times = [0.1, 0.2, 1.0]
      samples = process.sample_paths(
          times=times,
          num_samples=num_samples,
          initial_state=initial_state)
      # `samples` has shape [2, 5, 3, 1]
      ```
  
      #### References:
      [1]: A. Alfonsi. Affine Diffusions and Related Processes: Simulation,
        Theory and Applications
      """
      name = name or (self._name + "_sample_path")
      with tf.name_scope(name):
          element_shape = self._batch_shape + [num_samples, self._dim]
  
          # batch_shape + [1] -> batch_shape + [1 (for num_samples), 1]
          theta = self._expand_param_on_rank(self._theta, 1, axis=-2)
          mean_reversion = self._expand_param_on_rank(
              self._mean_reversion, 1, axis=-2
          )
          sigma = self._expand_param_on_rank(self._sigma, 1, axis=-2)
  
          if initial_state is None:
              initial_state = tf.ones(
                  element_shape, dtype=self._dtype, name="initial_state"
              )
          else:
              initial_state = tf.convert_to_tensor(
                  initial_state, dtype=self._dtype, name="initial_state"
              ) + tf.zeros(element_shape, dtype=self._dtype)
  
          times = tf.convert_to_tensor(
              times, dtype=self._dtype, name="times"
          )
          num_requested_times = tff_utils.get_shape(times)[0]
          if random_type is None:
              random_type = random.RandomType.PSEUDO
          if (
              random_type == random.RandomType.STATELESS
              and seed is None
          ):
              raise ValueError(
                  "`seed` equal to None is not supported with STATELESS random type."
              )
  
          return self._sample_paths(
              theta=theta,
              mean_reversion=mean_reversion,
              sigma=sigma,
              element_shape=element_shape,
              times=times,
              num_requested_times=num_requested_times,
              initial_state=initial_state,
              num_samples=num_samples,
              random_type=random_type,
              seed=seed,
          )
  
file_path: tf-quant-finance/tf_quant_finance/models/cir/cir_model.py
imports: from typing import Optional
  import tensorflow.compat.v2
  from tf_quant_finance import types
  from tf_quant_finance import utils
  from tf_quant_finance.math import random_ops
  from tf_quant_finance.models import generic_ito_process
label_desc: Use image node_id 2 for calling the CirModel obj's underlying member method code with example usage: obj.sample_paths(times, initial_state, num_samples, random_type, seed, name) and returns: self