# alibi.utils.approximation_methods module

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

Bases: `enum.Enum`

An enumeration.

left = 1
middle = 3
right = 2
trapezoid = 4
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 only riemann and gauss legendre are

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

Numpy’s 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 of **step_sizes*, **alphas***

• - **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`) – left, right, middle and trapezoid riemann

Return type
Returns

2-element tuple of **step_sizes*, **alphas*** –

• 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]