Last updated: 2023-03-16.
tf_quant_finance.math.random.uniform#
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 Pythonintrepresenting each sample’sevent_size.sample_shape: Rank 1Tensorof positiveint32s. Should specify a valid shape for aTensor. The shape of the samples to be drawn.random_type: Enum value ofRandomType. The type of draw to generate. Default value: None which is mapped toRandomType.PSEUDO.dtype: Optionaldtype(eithiertf.float32ortf.float64). The dtype of the outputTensor. Default value:Nonewhich maps totf.float32.seed: Seed for the random number generator. The seed is only relevant ifrandom_typeis one of[STATELESS, PSEUDO, HALTON_RANDOMIZED]. ForPSEUDO, andHALTON_RANDOMIZEDthe seed should be a Python integer. ForSTATELESSmust be supplied as an integerTensorof shape[2]. Default value:Nonewhich means no seed is set.name: Pythonstrname prefixed to ops created by this class. Default value:Nonewhich is mapped to the default nameuniform_distribution.**kwargs: parameters, specific to a random type: (1)skipis anint0-dTensor. The number of initial points of the Sobol or Halton sequence to skip. Used only whenrandom_typeis ‘SOBOL’, ‘HALTON’, or ‘HALTON_RANDOMIZED’, otherwise ignored. (2)randomization_paramsis an instance oftff.math.random.HaltonParamsthat fully describes the randomization behavior. Used only whenrandom_typeis ‘HALTON_RANDOMIZED’, otherwise ignored (see halton.sample args for more details). If this parameter is provided when random_type isHALTON_RANDOMIZED, theseedparameter is ignored. Default value:None. In this case with randomized = True, the necessary randomization parameters will be computed from scratch.
Returns:#
samples: ATensorof shapesample_shape + [dim]. The draws from the uniform distribution of the requested random type.
Raises:#
ValueError: ifrandom_typeisSTATELESSand theseedisNone.