<!--
This file is generated by a tool. Do not edit directly.
For open-source contributions the docs will be updated automatically.
-->

*Last updated: 2023-03-16.*

<div itemscope itemtype="http://developers.google.com/ReferenceObject">
<meta itemprop="name" content="tf_quant_finance.math.qmc.lattice_rule_sample" />
<meta itemprop="path" content="Stable" />
</div>

# tf_quant_finance.math.qmc.lattice_rule_sample

<!-- Insert buttons and diff -->

<table class="tfo-notebook-buttons tfo-api" align="left">
</table>

<a target="_blank" href="https://github.com/paolodelia99/tf-quant-finance/blob/main/tf_quant_finance/math/qmc/lattice_rule.py">View source</a>



Constructs a lattice rule from a generating vector.

```python
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
)
```



<!-- Placeholder for "Used in" -->

#### Examples

```python
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:


* <b>`generating_vectors`</b>: Positive scalar `Tensor` of integers with rank 1
  representing the vector from which to sample points.
* <b>`dim`</b>: Positive scalar `Tensor` of integers with rank 0. The event size of the
  sampled points. Must not exceed the size of `generating_vectors`.
* <b>`num_results`</b>: Positive scalar `Tensor` of integers with rank 0. The maximum
  number of points to sample.
* <b>`sequence_indices`</b>: 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.
* <b>`additive_shift`</b>: 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`.
* <b>`apply_tent_transform`</b>: Python `bool` indicating whether to apply a tent
  transform to the sampled points.
  Default value: `False`.
* <b>`validate_args`</b>: Python `bool` indicating whether to validate arguments.
  Default value: `False`.
* <b>`dtype`</b>: Optional `dtype`. The `dtype` of the output `Tensor` (either
  `float32` or `float64`).
  Default value: `None` which maps to `float32`.
* <b>`name`</b>: 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))`.
