tf_quant_finance.math.qmc.digital_net_sample

Last updated: 2023-03-16.

tf_quant_finance.math.qmc.digital_net_sample#

View source

Constructs a digital net from a generating matrix.

tf_quant_finance.math.qmc.digital_net_sample(
    generating_matrices, num_results, num_digits, sequence_indices=None,
    scrambling_matrices=None, digital_shift=None, apply_tent_transform=False,
    validate_args=False, dtype=None, name=None
)

Examples#

import tf_quant_finance as tff

# Example: Sampling 1,000 points from 2D Sobol generating matrices.

dim = 2
num_results = 1000
num_digits = 10

tff.math.qmc.digital_net_sample(
    tff.math.qmc.sobol_generating_matrices(dim, num_results, num_digits),
    num_results,
    num_digits)
# ==> tf.Tensor([
#             [0.,         0.        ],
#             [0.5,        0.5       ],
#             [0.25,       0.75      ],
#             ...
#             [0.65527344, 0.9736328 ],
#             [0.40527344, 0.7236328 ],
#             [0.90527344, 0.22363281],
#         ], shape=(1000, 2), dtype=float32)

Args:#

  • generating_matrices: Positive scalar Tensor of integers with rank 2. The matrix from which to sample points.

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

  • num_digits: Positive scalar Tensor of integers with rank 0. the base-2 precision of the points sampled from generating_matrices.

  • 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.

  • scrambling_matrices: Optional positive scalar Tensor of integers with the same shape as generating_matrices. The left matrix scramble to apply to the generating matrices. Default value: None.

  • digital_shift: Optional positive scalar Tensor of integers with shape (dim) where dim = tf.shape(generating_matrices)[0]. The digital shift to apply to all the sampled points via a bitwise xor. 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_digital_net.

Returns:#

A Tensor of samples from the Sobol sequence with shape (num_samples, dim) where num_samples = min(num_results, size(sequence_indices)) and dim = tf.shape(generating_matrices)[0].