derivkit.derivatives.finite.extrapolators module#
Finite difference extrapolation utilities.
- derivkit.derivatives.finite.extrapolators.adaptive_gre_fd(single_finite: Callable[[int, float, int, int], ndarray[tuple[Any, ...], dtype[_ScalarT]] | float], *, order: int, stepsize: float, num_points: int, n_workers: int, p: int, max_levels: int = 6, min_levels: int = 2, r: float = 2.0, rtol: float = 1e-08, atol: float = 1e-12, return_error: bool = False) ndarray[tuple[Any, ...], dtype[_ScalarT]] | float | tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]] | float, ndarray[tuple[Any, ...], dtype[_ScalarT]] | float]#
Returns an adaptive Gauss–Richardson extrapolation for finite differences.
This function computes finite-difference estimates at decreasing step sizes, builds up sequences of base values and corresponding step sizes, and applies Gauss–Richardson extrapolation iteratively until convergence based on the change between successive estimates.
- Parameters:
single_finite – Function that computes a single finite-difference estimate for a given derivative order and step size
single_finite(order, h, num_points, n_workers).order – The order of the derivative to compute.
stepsize – The initial step size
h.num_points – Number of points in the finite-difference stencil.
n_workers – Number of parallel workers to use.
p – The order of the leading error term in the finite difference approximation.
max_levels – Maximum number of levels of extrapolation to perform (default is
6).min_levels – Minimum number of levels of extrapolation before checking for convergence (default is
2).r – Step-size reduction factor between successive levels (default is
2.0).rtol – Relative tolerance for convergence (default is
1e-8).atol – Absolute tolerance for convergence (default is
1e-12).return_error – Whether to return an error estimate along with the value (default is
False).
- Returns:
The Gauss–Richardson-extrapolated finite-difference estimate. If
return_erroris True, also returns an error estimate with the same shape as the estimate.
- derivkit.derivatives.finite.extrapolators.adaptive_richardson_fd(single_finite: Callable[[int, float, int, int], ndarray[tuple[Any, ...], dtype[_ScalarT]] | float], *, order: int, stepsize: float, num_points: int, n_workers: int, p: int, max_levels: int = 6, min_levels: int = 2, r: float = 2.0, rtol: float = 1e-08, atol: float = 1e-12, return_error: bool = False) ndarray[tuple[Any, ...], dtype[_ScalarT]] | float | tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]] | float, ndarray[tuple[Any, ...], dtype[_ScalarT]] | float]#
Returns an adaptive Richardson extrapolation for finite differences.
This function computes finite difference estimates at decreasing step sizes and applies Richardson extrapolation iteratively until convergence is achieved based on specified tolerances.
- Parameters:
single_finite – Function that computes a single finite difference estimate.
order – The order of the derivative to compute.
stepsize – The initial step size h.
num_points – Number of points in the finite difference stencil.
n_workers – Number of parallel workers to use.
p – The order of the leading error term in the finite difference approximation.
max_levels – Maximum number of levels of extrapolation to perform (default is
6).min_levels – Minimum number of levels of extrapolation before checking for convergence. Default is
2.r – The step-size reduction factor between successive levels (default is
2.0).rtol – Relative tolerance for convergence (default is
1e-8).atol – Absolute tolerance for convergence (default is
1e-12).return_error – Whether to return an error estimate along with the value (default is
False).
Returns: The Richardson-extrapolated finite difference estimate.
- derivkit.derivatives.finite.extrapolators.adaptive_ridders_fd(single_finite: Callable[[int, float, int, int], ndarray[tuple[Any, ...], dtype[_ScalarT]] | float], *, order: int, stepsize: float, num_points: int, n_workers: int, p: int, max_levels: int = 6, min_levels: int = 2, r: float = 2.0, rtol: float = 1e-08, atol: float = 1e-12, return_error: bool = False) ndarray[tuple[Any, ...], dtype[_ScalarT]] | float | tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]] | float, ndarray[tuple[Any, ...], dtype[_ScalarT]] | float]#
Returns an adaptive Ridders extrapolation for finite differences.
This function computes finite difference estimates at decreasing step sizes, building up a sequence of base values and repeatedly applying Ridders extrapolation until convergence is achieved based on specified tolerances.
- Parameters:
single_finite – Function that computes a single finite difference estimate for a given derivative order and step size
single_finite(order, h, num_points, n_workers).order – The order of the derivative to compute.
stepsize – The initial step size
h.num_points – Number of points in the finite difference stencil.
n_workers – Number of parallel workers to use.
p – The order of the leading error term in the finite difference approximation.
max_levels – Maximum number of levels of extrapolation to perform (default is
6).min_levels – Minimum number of levels of extrapolation before checking for convergence (default is
2).r – Step-size reduction factor between successive levels (default is
2.0).rtol – Relative tolerance for convergence (default is 1e-8).
atol – Absolute tolerance for convergence (default is 1e-12).
return_error – Whether to return an error estimate along with the value (default is
False).
- Returns:
The Ridders-extrapolated finite difference estimate.
- derivkit.derivatives.finite.extrapolators.fixed_gre_fd(single_finite: Callable[[int, float, int, int], ndarray[tuple[Any, ...], dtype[_ScalarT]] | float], *, order: int, stepsize: float, num_points: int, n_workers: int, p: int, levels: int, r: float = 2.0, return_error: bool = False) ndarray[tuple[Any, ...], dtype[_ScalarT]] | float | tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]] | float, ndarray[tuple[Any, ...], dtype[_ScalarT]] | float]#
Returns a fixed-level Gauss–Richardson extrapolation for finite differences.
Fixed level means we compute m base estimates with step sizes h, h/r, h/r^2, …, h/r^(m-1) and then apply Gauss–Richardson extrapolation to get the final estimate.
- Parameters:
single_finite – Function that computes a single finite difference estimate.
order – The order of the derivative to compute.
stepsize – The initial step size h.
num_points – Number of points in the finite difference stencil.
n_workers – Number of parallel workers to use.
p – The order of the leading error term in the finite difference approximation.
levels – Number of levels (m) for Gauss–Richardson extrapolation.
r – The step-size reduction factor between successive levels (default is
2.0).return_error – Whether to return an error estimate along with the value (default is
False).
- Returns:
The Gauss–Richardson-extrapolated finite difference estimate. If return_error is True, also returns an error estimate.
- Raises:
ValueError – If the combination of
num_pointsandorderis notsupported or if levels < 2. –
- derivkit.derivatives.finite.extrapolators.fixed_richardson_fd(single_finite: Callable[[int, float, int, int], ndarray[tuple[Any, ...], dtype[_ScalarT]] | float], *, order: int, stepsize: float, num_points: int, n_workers: int, levels: int, p: int = 2, r: float = 2.0, return_error: bool = False) ndarray[tuple[Any, ...], dtype[_ScalarT]] | float | tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]] | float, ndarray[tuple[Any, ...], dtype[_ScalarT]] | float]#
Returns fixed-level Richardson extrapolation for finite differences.
Fixed level means we compute m base estimates with step sizes h, h/r, h/r^2, …, h/r^(m-1) and then apply Richardson extrapolation to get the final estimate.
- Parameters:
single_finite – Function that computes a single finite difference estimate.
order – The order of the derivative to compute.
stepsize – The initial step size h.
num_points – Number of points in the finite difference stencil.
n_workers – Number of parallel workers to use.
levels – Number of levels (m) for Richardson extrapolation.
p – The order of the leading error term in the finite difference approximation. Default is
2.r – The step-size reduction factor between successive levels (default is
2.0).return_error – Whether to return an error estimate along with the value (default is
False).
- Returns:
The Richardson-extrapolated finite difference estimate. If return_error is True, also returns an error estimate.
- derivkit.derivatives.finite.extrapolators.fixed_ridders_fd(single_finite: Callable[[int, float, int, int], ndarray[tuple[Any, ...], dtype[_ScalarT]] | float], *, order: int, stepsize: float, num_points: int, n_workers: int, levels: int, p: int = 2, r: float = 2.0, return_error: bool = False) ndarray[tuple[Any, ...], dtype[_ScalarT]] | float | tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]] | float, ndarray[tuple[Any, ...], dtype[_ScalarT]] | float]#
Returns a fixed-level Ridders extrapolation for finite differences.
Fixed level means we compute m base estimates with step sizes h, h/r, h/r^2, …, h/r^(m-1) and then apply Ridders extrapolation to get the final estimate.
- Parameters:
single_finite – Function that computes a single finite difference estimate.
order – The order of the derivative to compute.
stepsize – The initial step size h.
num_points – Number of points in the finite difference stencil.
n_workers – Number of parallel workers to use.
levels – Number of levels (m) for Ridders extrapolation.
p – The order of the leading error term in the finite difference approximation (default is
2).r – The step-size reduction factor between successive levels (default is
2.0).return_error – Whether to return an error estimate along with the value (default is
False).
- Returns:
The Ridders-extrapolated finite difference estimate. If return_error is True, also returns an error estimate.