<!--
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.math.integration.gauss_kronrod" />
<meta itemprop="path" content="Stable" />
</div>

# tf_quant_finance.math.integration.gauss_kronrod

<!-- 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/math/integration/gauss_kronrod.py">View source</a>



Evaluates definite integral using adaptive Gauss-Kronrod quadrature.

```python
tf_quant_finance.math.integration.gauss_kronrod(
    func, lower, upper, tolerance, num_points=21, max_depth=20, dtype=None,
    name=None
)
```



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

Integrates `func` using adaptive Gauss-Kronrod 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-1)//2`
and the roots of the Stieltjes polynomial of degree `(num_points+1)//2`,
multiplied with corresponding precalculated coefficients.
Repeats procedure if not accurate enough by halving the intervals and dividing
these into the same number of subintervals.

#### References
[1] https://en.wikipedia.org/wiki/Gauss%E2%80%93Kronrod_quadrature_formula

#### Example
```python
  f = lambda x: x*x
  a = tf.constant([0.0])
  b = tf.constant([3.0])
  tol = 1e-5
  num_points = 21
  max_depth = 10
  gauss_kronrod(f, a, b, tol, num_points, max_depth) # [9.0]
```

#### Args:


* <b>`func`</b>: Represents a function to be integrated. It must be a callable of a
  single `Tensor` parameter and return a `Tensor` of the same shape and
  dtype as its input. It will be called with a `Tensor` of shape
  `lower.shape + [n,  num_points]` (where `n` is defined by the algorithm
  and represents the number of subintervals) and of the same `dtype` as
  `lower`.
* <b>`lower`</b>: Represents the lower limits of integration. `func` will be integrated
  between each pair of points defined by `lower` and `upper`. Must be a
  1-dimensional tensor of shape `[batch_dim]`.
* <b>`upper`</b>: Same shape and dtype as `lower` representing the upper limits of
  intergation.
* <b>`tolerance`</b>: Represents the tolerance for the estimated error of the integral
  estimation, at which to stop further dividing the intervals.
* <b>`num_points`</b>: Number of points at which the function `func` will be evaluated.
  Implemented for 15,21,31. Default value: 21.
* <b>`max_depth`</b>: Maximum number of times to divide intervals into two parts and
  recalculate Gauss-Kronrod on them. Default value: 20.
* <b>`dtype`</b>: If supplied, the dtype for the `lower` and `upper`. Result will have
  the same dtype. Default value: None which maps to dtype of `lower`.
* <b>`name`</b>: The name to give to the ops created by this function. Default value:
  None which maps to 'gauss_kronrod'.


#### Returns:

`Tensor` of shape `[batch_dim]`, containing value of the definite integral.
