tf_quant_finance.experimental.lsm_algorithm.make_polynomial_basis

Last updated: 2023-03-16.

tf_quant_finance.experimental.lsm_algorithm.make_polynomial_basis#

View source

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

tf_quant_finance.experimental.lsm_algorithm.make_polynomial_basis(
    degree
)

The output callable accepts 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#

basis = make_polynomial_basis(2)
x = [1.0, 2.0, 3.0, 4.0]
x = tf.expand_dims(x, -1)
basis(x)
# Expected result:
[[ 1.0, 1.0, 1.0, 1.0], [-1.5, -0.5, 0.5, 1.5]]

Args:#

  • degree: An int32 scalar Tensor. The degree of the desired polynomial basis.

Returns:#

A callable from Tensors of shape [num_samples, dim] to Tensors of shape [degree * dim, num_samples].

Raises:#

  • ValueError: If degree is less than 1.