# alibi.utils.approximation_methods module

class alibi.utils.approximation_methods.Riemann(value)[source]

Bases: `Enum`

An enumeration.

left = 1
middle = 3
right = 2
trapezoid = 4
alibi.utils.approximation_methods.SUPPORTED_RIEMANN_METHODS = ['riemann_left', 'riemann_right', 'riemann_middle', 'riemann_trapezoid']

Riemann integration methods.

alibi.utils.approximation_methods.approximation_parameters(method)[source]

Retrieves parameters for the input approximation method.

Parameters:

method (`str`) – The name of the approximation method. Currently supported only: `'riemann_*'` and `'gausslegendre`’. Check `alibi.utils.approximation_methods.SUPPORTED_RIEMANN_METHODS` for all `'riemann_*'` possible values.

Return type:
alibi.utils.approximation_methods.gauss_legendre_builders()[source]

np.polynomial.legendre function helps to compute step sizes and alpha coefficients using gauss-legendre quadrature rule. Since numpy returns the integration parameters in different scales we need to rescale them to adjust to the desired scale.

Gauss Legendre quadrature rule for approximating the integrals was originally proposed by [Xue Feng and her intern Hauroun Habeeb] (https://research.fb.com/people/feng-xue/).

Parameters:

n – The number of integration steps.

Return type:
Returns:

2-element tuple consisting of

• step_sizes : `Callable` - step_sizes takes the number of steps as an input argument and returns an array of steps sizes which sum is smaller than or equal to one.

• alphas : `Callable` - alphas takes the number of steps as an input argument and returns the multipliers/coefficients for the inputs of integrand in the range of [0, 1].

alibi.utils.approximation_methods.riemann_builders(method=Riemann.trapezoid)[source]

Step sizes are identical and alphas are scaled in [0, 1].

Parameters:
• n – The number of integration steps.

• method (`Riemann`) – Riemann method: `Riemann.left` | `Riemann.right` | `Riemann.middle` | `Riemann.trapezoid`.

Return type:
Returns:

2-element tuple consisting of

• step_sizes : `Callable` - step_sizes takes the number of steps as an input argument and returns an array of steps sizes which sum is smaller than or equal to one.

• alphas : `Callable` - alphas takes the number of steps as an input argument and returns the multipliers/coefficients for the inputs of integrand in the range of [0, 1].