quadax.adaptive_quadrature

quadax.adaptive_quadrature(rule: AbstractQuadratureRule, fun: Callable[[...], Array], interval: Array | ndarray | bool | number | bool | int | float | complex, args: tuple = (), full_output: bool = False, epsabs: Array | ndarray | bool | number | bool | int | float | complex | None = None, epsrel: Array | ndarray | bool | number | bool | int | float | complex | None = None, max_ninter: int = 50, norm: float | int | Callable[[Array], Array] = inf, **kwargs)Source

Global adaptive quadrature.

This is a lower level routine allowing for custom local quadrature rules. For most applications the higher order methods quadgk, quadcc, quadts are preferable.

Parameters:
  • rule (AbstractQuadratureRule) – Local quadrature rule to use.

  • fun (callable) – Function to integrate, should have a signature of the form fun(x, *args) -> float, Array. Should be JAX transformable.

  • interval (array-like) – Lower and upper limits of integration with possible breakpoints. Use np.inf to denote infinite intervals.

  • args (tuple, optional) – Extra arguments passed to fun.

  • full_output (bool, optional) – If True, return the full state of the integrator. See below for more information.

  • epsabs (float, optional) – Absolute and relative error tolerance. Default is square root of machine precision. Algorithm tries to obtain an accuracy of abs(i-result) <= max(epsabs, epsrel*abs(i)) where i = integral of fun over interval, and result is the numerical approximation.

  • epsrel (float, optional) – Absolute and relative error tolerance. Default is square root of machine precision. Algorithm tries to obtain an accuracy of abs(i-result) <= max(epsabs, epsrel*abs(i)) where i = integral of fun over interval, and result is the numerical approximation.

  • max_ninter (int, optional) – An upper bound on the number of sub-intervals used in the adaptive algorithm.

  • kwargs (dict) – Additional keyword arguments passed to rule.

Returns:

  • y (float, Array) – The integral of fun from a to b.

  • info (QuadratureInfo) – Named tuple with the following fields:

    • err : (float) Estimate of the error in the approximation.

    • neval : (int) Total number of rule evaluations.

    • status : (int) Flag indicating reason for termination. status of 0 means normal termination, any other value indicates a possible error. A human readable message can be obtained by print(quadax.STATUS[status])

    • info : (dict or None) Other information returned by the algorithm. Only present if full_output is True. Contains the following:

      • ’ninter’ : (int) The number, K, of sub-intervals produced in the subdivision process.

      • ’a_arr’ : (ndarray) rank-1 array of length max_ninter, the first K elements of which are the left end points of the (remapped) sub-intervals in the partition of the integration range.

      • ’b_arr’ : (ndarray) rank-1 array of length max_ninter, the first K elements of which are the right end points of the (remapped) sub-intervals.

      • ’r_arr’ : (ndarray) rank-1 array of length max_ninter, the first K elements of which are the integral approximations on the sub-intervals.

      • ’e_arr’ : (ndarray) rank-1 array of length max_ninter, the first K elements of which are the moduli of the absolute error estimates on the sub-intervals.