<!--
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.models.longstaff_schwartz.make_polynomial_basis" />
<meta itemprop="path" content="Stable" />
</div>

# tf_quant_finance.models.longstaff_schwartz.make_polynomial_basis

<!-- 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/models/longstaff_schwartz/lsm.py">View source</a>



Produces a callable from samples to polynomial basis for use in regression.

```python
tf_quant_finance.models.longstaff_schwartz.make_polynomial_basis(
    degree
)
```



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

The output callable accepts a scalar `Tensor` `t` and a `Tensor` `X` of
shape `[num_samples, dim]`, computes a centered value
`Y = X - mean(X, axis=0)` and outputs a `Tensor` of shape
`[degree * dim, num_samples]`, where
```
Z[i*j, k] = X[k, j]**(degree - i) * X[k, j]**i, 0<=i<degree - 1, 0<=j<dim
```
For example, if `degree` and `dim` are both equal to 2, the polynomial basis
is `1, X, X**2, Y, Y**2, X * Y, X**2 * Y, X * Y**2`, where `X` and `Y` are
the spatial axes.

#### Example
```python
basis = tff.experimental.lsm_algorithm.make_polynomial_basis_v2(2)
x = [[1.0], [2.0], [3.0], [4.0]]
x = tf.expand_dims(x, axis=-1)
basis(x, tf.constant(0, dtype=np.int32))
# Expected result:
[[ 1.  ,  1.  ,  1.  ,  1.  ], [-1.5 , -0.5 ,  0.5 ,  1.5 ],
[ 2.25,  0.25,  0.25,  2.25]]
```

#### Args:


* <b>`degree`</b>: An `int32` scalar `Tensor`. The degree of the desired polynomial
  basis.


#### Returns:

A callable from `Tensor`s of shape `[batch_size, num_samples, dim]` to
`Tensor`s of shape `[batch_size, (degree + 1)**dim, num_samples]`.
