tf_quant_finance.math.qmc.lattice_rule_sample

Last updated: 2023-03-16.

tf_quant_finance.math.qmc.lattice_rule_sample#

View source

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 scalar Tensor of integers with rank 1 representing the vector from which to sample points.

  • dim: Positive scalar Tensor of integers with rank 0. The event size of the sampled points. Must not exceed the size of generating_vectors.

  • num_results: Positive scalar Tensor of integers with rank 0. The maximum number of points to sample.

  • sequence_indices: Optional positive scalar Tensor of integers with rank 1. The elements of the sequence to return specified by their position in the sequence. Default value: None which corresponds to the [0, num_results) range.

  • additive_shift: Optional scalar Tensor of real values with the same shape as generating_vectors. The additive shift to add to all the points (modulo 1) before applying the tent transform. Default value: None.

  • apply_tent_transform: Python bool indicating whether to apply a tent transform to the sampled points. Default value: False.

  • validate_args: Python bool indicating whether to validate arguments. Default value: False.

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

  • name: Python str name prefixed to ops created by this function. Default value: None which maps to sample_lattice_rule.

Returns:#

A Tensor of samples from the Sobol sequence with shape (num_samples,) where num_samples = min(num_results, size(sequence_indices)).