Last updated: 2023-03-16.
tf_quant_finance.math.qmc.lattice_rule_sample#
Constructs a lattice rule from a generating vector.
tf_quant_finance.math.qmc.lattice_rule_sample(
generating_vectors, dim, num_results, sequence_indices=None,
additive_shift=None, apply_tent_transform=False, validate_args=False,
dtype=None, name=None
)
Examples#
import tensorflow as tf
import tf_quant_finance as tff
# Example: Sampling 1,000 points from 2D generating vectors.
generating_vectors = tf.constant([1, 387275, 314993, 50301], dtype=tf.int32)
dim = 2
num_results = 1000
tff.math.qmc.lattice_rule_sample(generating_vectors, dim, num_results)
# ==> tf.Tensor([
# [0., 0. ],
# [0.001, 0.2749939 ],
# [0.002, 0.5499878 ],
# ...
# [0.99700004, 0.1689148 ],
# [0.998, 0.4439087 ],
# [0.9990001, 0.7189026 ],
# ], shape=(1000, 2), dtype=float32)
Args:#
generating_vectors: Positive scalarTensorof integers with rank 1 representing the vector from which to sample points.dim: Positive scalarTensorof integers with rank 0. The event size of the sampled points. Must not exceed the size ofgenerating_vectors.num_results: Positive scalarTensorof integers with rank 0. The maximum number of points to sample.sequence_indices: Optional positive scalarTensorof integers with rank 1. The elements of the sequence to return specified by their position in the sequence. Default value:Nonewhich corresponds to the[0, num_results)range.additive_shift: Optional scalarTensorof real values with the sameshapeasgenerating_vectors. The additive shift to add to all the points (modulo 1) before applying the tent transform. Default value:None.apply_tent_transform: Pythonboolindicating whether to apply a tent transform to the sampled points. Default value:False.validate_args: Pythonboolindicating whether to validate arguments. Default value:False.dtype: Optionaldtype. Thedtypeof the outputTensor(eitherfloat32orfloat64). Default value:Nonewhich maps tofloat32.name: Pythonstrname prefixed to ops created by this function. Default value:Nonewhich maps tosample_lattice_rule.
Returns:#
A Tensor of samples from the Sobol sequence with shape
(num_samples,) where num_samples = min(num_results, size(sequence_indices)).