Last updated: 2023-03-16.
tf_quant_finance.math.integration.gauss_legendre#
Evaluates definite integral using Gauss-Legendre quadrature.
tf_quant_finance.math.integration.gauss_legendre(
func, lower, upper, num_points=32, dtype=None, name=None
)
Integrates func using Gauss-Legendre quadrature [1].
Applies change of variables to the function to obtain the [-1,1] integration
interval.
Takes the sum of values obtained from evaluating the new function at points
given by the roots of the Legendre polynomial of degree num_points,
multiplied with corresponding precalculated coefficients.
References#
Example#
f = lambda x: x*x
a = tf.constant(0.0)
b = tf.constant(3.0)
gauss_legendre(f, a, b, num_points=15) # 9.0
Args:#
func: Represents a function to be integrated. It must be a callable of a singleTensorparameter and return aTensorof the same shape and dtype as its input. It will be called with aTensorof shapelower.shape + [n](where n is integer number of points) and of the samedtypeaslower.lower: Represents the lower limits of integration.funcwill be integrated between each pair of points defined bylowerandupper.upper: Same shape and dtype aslowerrepresenting the upper limits of intergation.num_points: Number of points at which the functionfuncwill be evaluated. Implemented for 2-15,20,32. Default value: 32.dtype: If supplied, the dtype for thelowerandupper. Result will have the same dtype. Default value: None which maps to dtype oflower.name: The name to give to the ops created by this function. Default value: None which maps to ‘gauss_legendre’.
Returns:#
Tensor of shape func_batch_shape + limits_batch_shape, containing
value of the definite integral.