8.1.1. Introduction¶
In order to compute the following integral numerically
one represents it as a sum:
where \(K\) is the order of integration, \(x_i\) is a set of points of size \(K\) on which the function is computed and \(\omega_i\) are the weights.
The formula is valid regardless of the method is used. In case the rectangular integration (left) is used with \(K=3\), then \(x=\{a, a+\Delta/3, a+2\Delta/3\}\) and \(\omega_i=\Delta/3\), where \(\Delta=b-a\). For \(K=3\) and trapezoidal integration \(x=\{a, (a+b)/2, b\}\) and \(\omega=\{\Delta/4, \Delta/2, \Delta/4\}\).
Other methods may be used, such as Gauss-Legendre or Gauss-Kronrod quadratures. The important point here is that regardless of the method used for the given the order \(K\) and limits \(a\) and \(b\) the sets of \(x_i\) and \(\omega_i\) may be defined once.
The typical problem in calculations is when one needs to compute a set of integrals for each bin to produce a histogram:
this integral is approximated in a similar way:
Note, that each bin \(k\) may have different integration precision, different number of integration points and thus has its own index \(i_k\).
The rule may be extended to the higher orders. For example, 2-dimensional integral yielding 2d histogram reads as follows:
where we have added a set of bins over variable \(y\) with edges \(b_m\) and integration orders \(M_m\).
Given the formulas (1) and (2) we may now define the integration procedure that involves 2+ transformations:
Sampler transformation. This transformation is provided by the bin edges and required integration orders for each bin. The transformation produces the arrays with integration points \(x\) and weights \(\omega\), needed to compute an integral for each bin. The values of \(x\) and \(\omega\) depend on the quadrature method used.
The integrand transformation or calculation chain that implements \(y_i=f(x_i)\). It receives array \(x\) as input. The integrand is provided by the user.
Integrator transformation. The transformations receives the output of the integrand transformation \(y_i\) as well as the integration weights from the sampler. Integrator implements the convolution and produces the histogram \(H\) as the output. Integrator implementation does not depend on actual sampler used.