Last updated: 2023-03-16.
tf_quant_finance.math.integration.simpson#
Evaluates definite integral using composite Simpson’s 1/3 rule.
tf_quant_finance.math.integration.simpson(
func, lower, upper, num_points=1001, dtype=None, name=None
)
Integrates func using composite Simpson’s 1/3 rule [1].
Evaluates function at points of evenly spaced grid of num_points points,
then uses obtained values to interpolate func with quadratic polynomials
and integrates these polynomials.
References#
[1] Weisstein, Eric W. “Simpson’s Rule.” From MathWorld - A Wolfram Web Resource. http://mathworld.wolfram.com/SimpsonsRule.html
Example#
f = lambda x: x*x
a = tf.constant(0.0)
b = tf.constant(3.0)
simpson(f, a, b, num_points=1001) # 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 functionfuncwill be evaluated. Must be odd and at least 3. Default value: 1001.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 ‘integrate_simpson_composite’.
Returns:#
Tensor of shape func_batch_shape + limits_batch_shape, containing
value of the definite integral.