tf_quant_finance.math.random.uniform

Last updated: 2023-03-16.

tf_quant_finance.math.random.uniform#

View source

Generates draws from a uniform distribution on [0, 1).

tf_quant_finance.math.random.uniform(
    dim, sample_shape, random_type=None, dtype=None, seed=None, name=None, **kwargs
)

Allows generating either (pseudo) random or quasi-random draws based on the random_type parameter. Dimension parameter dim is required since for quasi-random draws one needs to know the dimensionality of the space as opposed to just sample shape.

Example:#

sample_shape = [10]  # Generates 10 draws.

# `Tensor` of shape [10, 1]
uniform_samples = uniform(1, sample_shape)

# `Tensor` of shape [10, 5]
sobol_samples = uniform(5, sample_shape, RandomType.SOBOL)

Args:#

  • dim: A positive Python int representing each sample’s event_size.

  • sample_shape: Rank 1 Tensor of positive int32s. Should specify a valid shape for a Tensor. The shape of the samples to be drawn.

  • random_type: Enum value of RandomType. The type of draw to generate. Default value: None which is mapped to RandomType.PSEUDO.

  • dtype: Optional dtype (eithier tf.float32 or tf.float64). The dtype of the output Tensor. Default value: None which maps to tf.float32.

  • seed: Seed for the random number generator. The seed is only relevant if random_type is one of [STATELESS, PSEUDO, HALTON_RANDOMIZED]. For PSEUDO, and HALTON_RANDOMIZED the seed should be a Python integer. For STATELESS must be supplied as an integer Tensor of shape [2]. Default value: None which means no seed is set.

  • name: Python str name prefixed to ops created by this class. Default value: None which is mapped to the default name uniform_distribution.

  • **kwargs: parameters, specific to a random type: (1) skip is an int 0-d Tensor. The number of initial points of the Sobol or Halton sequence to skip. Used only when random_type is ‘SOBOL’, ‘HALTON’, or ‘HALTON_RANDOMIZED’, otherwise ignored. (2) randomization_params is an instance of tff.math.random.HaltonParams that fully describes the randomization behavior. Used only when random_type is ‘HALTON_RANDOMIZED’, otherwise ignored (see halton.sample args for more details). If this parameter is provided when random_type is HALTON_RANDOMIZED, the seed parameter is ignored. Default value: None. In this case with randomized = True, the necessary randomization parameters will be computed from scratch.

Returns:#

  • samples: A Tensor of shape sample_shape + [dim]. The draws from the uniform distribution of the requested random type.

Raises:#

  • ValueError: if random_type is STATELESS and the seed is None.