tf_quant_finance.math.interpolation.cubic.interpolate

Last updated: 2023-03-16.

tf_quant_finance.math.interpolation.cubic.interpolate#

View source

Interpolates spline values for the given x and the spline_data.

tf_quant_finance.math.interpolation.cubic.interpolate(
    x, spline_data, optimize_for_tpu=False, dtype=None, name=None
)

Constant extrapolation is performed for the values outside the domain spline_data.x_data. This means that for x > max(spline_data.x_data), interpolate(x, spline_data) = spline_data.y_data[-1] and for x < min(spline_data.x_data), interpolate(x, spline_data) = spline_data.y_data[0].

For the interpolation formula refer to p.548 of [1].

References:#

[1]: R. Sedgewick, Algorithms in C, 1990, p. 545-550. Link: http://index-of.co.uk/Algorithms/Algorithms in C.pdf

Args:#

  • x: A real Tensor of shape batch_shape + [num_points].

  • spline_data: An instance of SplineParameters. spline_data.x_data should have the same batch shape as x.

  • optimize_for_tpu: A Python bool. If True, the algorithm uses one-hot encoding to lookup indices of x in spline_data.x_data. This significantly improves performance of the algorithm on a TPU device but may slow down performance on the CPU. Default value: False.

  • dtype: Optional dtype for x. Default value: None which maps to the default dtype inferred by TensorFlow.

  • name: Python str name prefixed to ops created by this function. Default value: None which is mapped to the default name cubic_spline_interpolate.

Returns:#

A Tensor of the same shape and dtype as x. Represents the interpolated values.

Raises:#

  • ValueError: If x batch shape is different from spline_data.x_data batch shape.