defines the order of the error term in the Taylor approximation used.
For ‘central’ and ‘complex’ methods, it must be an even number.
nint, optional
Order of the derivative.
richardson_terms: scalar integer, default 2.
number of terms used in the Richardson extrapolation.
full_outputbool, optional
If full_output is False, only the derivative is returned.
If full_output is True, then (der, r) is returned der is the
derivative, and r is a Results object.
Complex methods are usually the most accurate provided the function to
differentiate is analytic. The complex-step methods also requires fewer
steps than the other methods and can work very close to the support of
a function.
The complex-step derivative has truncation error O(steps**2) for n=1 and
O(steps**4) for n larger, so truncation error can be eliminated by
choosing steps to be very small.
Especially the first order complex-step derivative avoids the problem of
round-off error with small steps because there is no subtraction. However,
this method fails if fun(x) does not support complex numbers or involves
non-analytic functions such as e.g.: abs, max, min.
Central difference methods are almost as accurate and has no restriction on
type of function. For this reason the ‘central’ method is the default
method, but sometimes one can only allow evaluation in forward or backward
direction.
For all methods one should be careful in decreasing the step size too much
due to round-off errors.
Higher order approximation methods will generally be more accurate, but may
also suffer more from numerical problems. First order methods is usually
not recommended.
References
Ridout, M.S. (2009) Statistical applications of the complex-step method
of numerical differentiation. The American Statistician, 63, 66-74
K.-L. Lai, J.L. Crassidis, Y. Cheng, J. Kim (2005), New complex step
derivative approximations with application to second-order
kalman filtering, AIAA Guidance, Navigation and Control Conference,
San Francisco, California, August 2005, AIAA-2005-5944.
Lyness, J. M., Moler, C. B. (1966). Vandermonde Systems and Numerical
Differentiation. Numerische Mathematik.
Lyness, J. M., Moler, C. B. (1969). Generalized Romberg Methods for
defines the order of the error term in the Taylor approximation used.
For ‘central’ and ‘complex’ methods, it must be an even number.
richardson_terms: scalar integer, default 2.
number of terms used in the Richardson extrapolation.
full_outputbool, optional
If full_output is False, only the derivative is returned.
If full_output is True, then (der, r) is returned der is the
derivative, and r is a Results object.
Complex methods are usually the most accurate provided the function to
differentiate is analytic. The complex-step methods also requires fewer
steps than the other methods and can work very close to the support of
a function.
The complex-step derivative has truncation error O(steps**2) for n=1 and
O(steps**4) for n larger, so truncation error can be eliminated by
choosing steps to be very small.
Especially the first order complex-step derivative avoids the problem of
round-off error with small steps because there is no subtraction. However,
this method fails if fun(x) does not support complex numbers or involves
non-analytic functions such as e.g.: abs, max, min.
Central difference methods are almost as accurate and has no restriction on
type of function. For this reason the ‘central’ method is the default
method, but sometimes one can only allow evaluation in forward or backward
direction.
For all methods one should be careful in decreasing the step size too much
due to round-off errors.
Higher order approximation methods will generally be more accurate, but may
also suffer more from numerical problems. First order methods is usually
not recommended.
If x0 is an n x m array, then fun is assumed to be a function of n * m
variables.
References
Ridout, M.S. (2009) Statistical applications of the complex-step method
of numerical differentiation. The American Statistician, 63, 66-74
K.-L. Lai, J.L. Crassidis, Y. Cheng, J. Kim (2005), New complex step
derivative approximations with application to second-order
kalman filtering, AIAA Guidance, Navigation and Control Conference,
San Francisco, California, August 2005, AIAA-2005-5944.
Lyness, J. M., Moler, C. B. (1966). Vandermonde Systems and Numerical
Differentiation. Numerische Mathematik.
Lyness, J. M., Moler, C. B. (1969). Generalized Romberg Methods for
defines the method used in the approximationorder : int, optional
defines the order of the error term in the Taylor approximation used.
For ‘central’ and ‘complex’ methods, it must be an even number.
richardson_terms: scalar integer, default 2.
number of terms used in the Richardson extrapolation.
full_outputbool, optional
If full_output is False, only the derivative is returned.
If full_output is True, then (der, r) is returned der is the
derivative, and r is a Results object.
Complex methods are usually the most accurate provided the function to
differentiate is analytic. The complex-step methods also requires fewer
steps than the other methods and can work very close to the support of
a function.
The complex-step derivative has truncation error O(steps**2) for n=1 and
O(steps**4) for n larger, so truncation error can be eliminated by
choosing steps to be very small.
Especially the first order complex-step derivative avoids the problem of
round-off error with small steps because there is no subtraction. However,
this method fails if fun(x) does not support complex numbers or involves
non-analytic functions such as e.g.: abs, max, min.
Central difference methods are almost as accurate and has no restriction on
type of function. For this reason the ‘central’ method is the default
method, but sometimes one can only allow evaluation in forward or backward
direction.
For all methods one should be careful in decreasing the step size too much
due to round-off errors.
Higher order approximation methods will generally be more accurate, but may
also suffer more from numerical problems. First order methods is usually
not recommended.
References
Ridout, M.S. (2009) Statistical applications of the complex-step method
of numerical differentiation. The American Statistician, 63, 66-74
K.-L. Lai, J.L. Crassidis, Y. Cheng, J. Kim (2005), New complex step
derivative approximations with application to second-order
kalman filtering, AIAA Guidance, Navigation and Control Conference,
San Francisco, California, August 2005, AIAA-2005-5944.
Lyness, J. M., Moler, C. B. (1966). Vandermonde Systems and Numerical
Differentiation. Numerische Mathematik.
Lyness, J. M., Moler, C. B. (1969). Generalized Romberg Methods for
number of terms used in the Richardson extrapolation.
full_outputbool, optional
If full_output is False, only the derivative is returned.
If full_output is True, then (der, r) is returned der is the
derivative, and r is a Results object.
Complex methods are usually the most accurate provided the function to
differentiate is analytic. The complex-step methods also requires fewer
steps than the other methods and can work very close to the support of
a function.
The complex-step derivative has truncation error O(steps**2) for n=1 and
O(steps**4) for n larger, so truncation error can be eliminated by
choosing steps to be very small.
Especially the first order complex-step derivative avoids the problem of
round-off error with small steps because there is no subtraction. However,
this method fails if fun(x) does not support complex numbers or involves
non-analytic functions such as e.g.: abs, max, min.
Central difference methods are almost as accurate and has no restriction on
type of function. For this reason the ‘central’ method is the default
method, but sometimes one can only allow evaluation in forward or backward
direction.
For all methods one should be careful in decreasing the step size too much
due to round-off errors.
Computes the Hessian according to method as:
‘forward’ (4.7), ‘central’ (4.9) and ‘complex’ (4.10):
where \(e_j\) is a vector with element \(j\) is one and the rest
are zero and \(d_j\) is a scalar spacing \(steps_j\).
References
Ridout, M.S. (2009) Statistical applications of the complex-step method
of numerical differentiation. The American Statistician, 63, 66-74
K.-L. Lai, J.L. Crassidis, Y. Cheng, J. Kim (2005), New complex step
derivative approximations with application to second-order
kalman filtering, AIAA Guidance, Navigation and Control Conference,
San Francisco, California, August 2005, AIAA-2005-5944.
Lyness, J. M., Moler, C. B. (1966). Vandermonde Systems and Numerical
Differentiation. Numerische Mathematik.
Lyness, J. M., Moler, C. B. (1969). Generalized Romberg Methods for
defines the order of the error term in the Taylor approximation used.
For ‘central’ and ‘complex’ methods, it must be an even number.
richardson_terms: scalar integer, default 2.
number of terms used in the Richardson extrapolation.
full_outputbool, optional
If full_output is False, only the derivative is returned.
If full_output is True, then (der, r) is returned der is the
derivative, and r is a Results object.
Complex methods are usually the most accurate provided the function to
differentiate is analytic. The complex-step methods also requires fewer
steps than the other methods and can work very close to the support of
a function.
The complex-step derivative has truncation error O(steps**2) for n=1 and
O(steps**4) for n larger, so truncation error can be eliminated by
choosing steps to be very small.
Especially the first order complex-step derivative avoids the problem of
round-off error with small steps because there is no subtraction. However,
this method fails if fun(x) does not support complex numbers or involves
non-analytic functions such as e.g.: abs, max, min.
Central difference methods are almost as accurate and has no restriction on
type of function. For this reason the ‘central’ method is the default
method, but sometimes one can only allow evaluation in forward or backward
direction.
For all methods one should be careful in decreasing the step size too much
due to round-off errors.
Higher order approximation methods will generally be more accurate, but may
also suffer more from numerical problems. First order methods is usually
not recommended.
If fun returns a 1d array, it returns a Jacobian. If a 2d array is returned
by fun (e.g., with a value for each observation), it returns a 3d array
with the Jacobian of each observation with shape xk x nobs x xk. I.e.,
the Jacobian of the first observation would be [:, 0, :]
References
Ridout, M.S. (2009) Statistical applications of the complex-step method
of numerical differentiation. The American Statistician, 63, 66-74
K.-L. Lai, J.L. Crassidis, Y. Cheng, J. Kim (2005), New complex step
derivative approximations with application to second-order
kalman filtering, AIAA Guidance, Navigation and Control Conference,
San Francisco, California, August 2005, AIAA-2005-5944.
Lyness, J. M., Moler, C. B. (1966). Vandermonde Systems and Numerical
Differentiation. Numerische Mathematik.
Lyness, J. M., Moler, C. B. (1969). Generalized Romberg Methods for
defines number of steps generated. It should be larger than
min_num_steps = (n + order - 1) / fact where fact is 1, 2 or 4
depending on differentiation method used.
step_nomdefault maximum(log(exp(1)+|x|), 1)
Nominal step where x is supplied at runtime through the __call__
method.
offsetreal scalar, optional, default 0
offset to the base step
num_extrapscalar integer, default 0
number of points used for extrapolation
check_num_stepsboolean, default True
If True make sure num_steps is larger than the minimum required steps.
defines number of steps generated. It should be larger than
min_num_steps = (n + order - 1) / fact where fact is 1, 2 or 4
depending on differentiation method used.
step_nomdefault maximum(log(exp(1)+|x|), 1)
Nominal step where x is supplied at runtime through the __call__ method.
offsetreal scalar, optional, default 0
offset to the base step
num_extrapscalar integer, default 0
number of points used for extrapolation
check_num_stepsboolean, default True
If True make sure num_steps is larger than the minimum required steps.
use_exact_stepsboolean, default True
If true make sure exact steps are generated
scalereal scalar, optional
scale used in base step. If not None it will override the default
computed with the default_scale function.
where the ai are unknown constants and the k_i are known constants such that h^k_i > h^(k_i+1).
If we evaluate the right hand side for different stepsizes h
we can fit a polynomial to that sequence of approximations.
This is exactly what this class does.
Here k_0 is the leading order step size behavior of truncation error as L = f(h)+O(h^k_0)
(f(h) -> L as h -> 0, but f(0) != L) and k_i = order + step * i .
Extrapolates a slowly convergent sequence using Shanks transformations.
Parameters:
v_0, v_1, v_2array-like
Three consecutive values of a convergent sequence to extrapolate.
symmetricbool, optional
If True, returns a sequence with symmetric error estimates.
Defaults to False.
Returns:
resultarray-like
The extrapolated value(s).
abserrarray-like
The estimated absolute error(s).
See also
Dea
Notes
DEA3 uses nonlinear Shanks transformations based on three values to
extrapolate to a better estimate of the sequence’s limit. It is a vectorized
translation of the DQELG function from the QUADPACK Fortran library.
for LIMEXP=3, see [Rf7ab399ffe8b-2] and [Rf7ab399ffe8b-3].
Extrapolate a slowly convergent sequence using repeated Shanks transformations.
Notes
DEA attempts to extrapolate nonlinearly by Shanks transformations to a better
estimate of the sequence’s limiting value, thus improving the rate of convergence.
The epsilon algorithm of P. Wynn, see [1]_, is used to perform the
non-linear Shanks transformations. The routine is a translation of the
DQELG function found in the QUADPACK fortran library, see [2]_ and [3]_.
List of major variables:
LIMEXP: scalar integer
The maximum number of elements the epsilon table data can contain.
The epsilon table is stored in the first (LIMEXP+2) entries of EPSTAB.
EPSTAB: real vector or size (LIMEXP+2+3)
The first LIMEXP+2 elements contains the two lower diagonals of the triangular
epsilon table. The elements are numbered starting at the right-hand corner of the
triangle.
E0,E1,E2,E3: real scalars
The 4 elements on which the computation of a new element in the epsilon table is based.
NRES: scalar integer
Number of extrapolation results actually generated by the epsilon algorithm in prior
calls to the routine.
NEWELM: scalar integer
Number of elements to be computed in the new diagonal of the epsilon table.
The condensed epsilon table is computed. Only those elements needed for the
computation of the next diagonal are preserved.
RES: real scalar
New element in the new diagonal of the epsilon table.
ERROR: real scalar
An estimate of the absolute error of RES. The routine decides whether RESULT=RES or
RESULT=SVALUE by comparing ERROR with abserr from the previous call.
Extrapolate a slowly convergent sequence using Shanks transformation.
Notes
The iterated Shanks transformation is computed using the Wynn
epsilon algorithm (see equation 4.3-10a to 4.3-10c given on page 25 in [R9678172c97e0-1]).
where the ai are unknown constants and the k_i are known constants such that h^k_i > h^(k_i+1).
If we evaluate the right hand side for different stepsizes h
we can fit a polynomial to that sequence of approximations.
This is exactly what this class does.
Here k_0 is the leading order step size behavior of truncation error as L = f(h)+O(h^k_0)
(f(h) -> L as h -> 0, but f(0) != L) and k_i = order + step * i .
DEA3 uses nonlinear Shanks transformations based on three values to
extrapolate to a better estimate of the sequence’s limit. It is a vectorized
translation of the DQELG function from the QUADPACK Fortran library.
for LIMEXP=3, see [Rc8bfc08f7c28-2] and [Rc8bfc08f7c28-3].
Return Taylor coefficients of complex analytic function using FFT
Parameters:
funcallable
function to differentiate
z0real or complex scalar at which to evaluate the derivatives
nscalar integer, default 1
Number of taylor coefficents to compute. Maximum number is 100.
rreal scalar, default 0.0059
Initial radius at which to evaluate. For well-behaved functions,
the computation should be insensitive to the initial radius to within
about four orders of magnitude.
num_extrapscalar integer, default 3
number of extrapolation steps used in the calculation
step_ratioreal scalar, default 1.6
Initial grow/shrinking factor for finding the best radius.
max_iterscalar integer, default 30
Maximum number of iterations
min_iterscalar integer, default max_iter // 2
Minimum number of iterations before the solution may be deemed
degenerate. A larger number allows the algorithm to correct a bad
initial radius.
full_outputbool, optional
If full_output is False, only the coefficents is returned (default).
If full_output is True, then (coefs, status) is returned
Returns:
coefsndarray
array of taylor coefficents
status: Optional object into which output information is written:
degenerate: True if the algorithm was unable to bound the error
iterations: Number of iterations executed
function_count: Number of function calls
final_radius: Ending radius of the algorithm
failed: True if the maximum number of iterations was reached
error_estimate: approximate bounds of the rounding error.
Notes
This module uses the method of Fornberg to compute the Taylor series
coefficients of a complex analytic function along with error bounds. The
method uses a Fast Fourier Transform to invert function evaluations around
a circle into Taylor series coefficients and uses Richardson Extrapolation
to improve and bound the estimate. Unlike real-valued finite differences,
the method searches for a desirable radius and so is reasonably
insensitive to the initial radius-to within a number of orders of
magnitude at least. For most cases, the default configuration is likely to
succeed.
Restrictions:
The method uses the coefficients themselves to control the truncation
error, so the error will not be properly bounded for functions like
low-order polynomials whose Taylor series coefficients are nearly zero.
If the error cannot be bounded, degenerate flag will be set to true, and
an answer will still be computed and returned but should be used with
caution.
References
[1] Fornberg, B. (1981).
Numerical Differentiation of Analytic Functions.
ACM Transactions on Mathematical Software (TOMS),
7(4), 512-526. http://doi.org/10.1145/355972.355979
Examples
Compute the first 6 taylor coefficients 1 / (1 - z) expanded round z0 = 0:
Calculate n-th derivative of complex analytic function using FFT
Parameters:
funcallable
function to differentiate
z0real or complex scalar at which to evaluate the derivatives
nscalar integer, default 1
Number of derivatives to compute where 0 represents the value of the
function and n represents the nth derivative. Maximum number is 100.
rreal scalar, default 0.0061
Initial radius at which to evaluate. For well-behaved functions,
the computation should be insensitive to the initial radius to within
about four orders of magnitude.
max_iterscalar integer, default 30
Maximum number of iterations
min_iterscalar integer, default max_iter // 2
Minimum number of iterations before the solution may be deemed
degenerate. A larger number allows the algorithm to correct a bad
initial radius.
step_ratioreal scalar, default 1.6
Initial grow/shrinking factor for finding the best radius.
num_extrapscalar integer, default 3
number of extrapolation steps used in the calculation
full_outputbool, optional
If full_output is False, only the derivative is returned (default).
If full_output is True, then (der, status) is returned der is the
derivative, and status is a Results object.
Returns:
derndarray
array of derivatives
status: Optional object into which output information is written. Fields:
degenerate: True if the algorithm was unable to bound the error
iterations: Number of iterations executed
function_count: Number of function calls
final_radius: Ending radius of the algorithm
failed: True if the maximum number of iterations was reached
error_estimate: approximate bounds of the rounding error.
Notes
This module uses the method of Fornberg to compute the derivatives of a
complex analytic function along with error bounds. The method uses a
Fast Fourier Transform to invert function evaluations around a circle into
Taylor series coefficients, uses Richardson Extrapolation to improve
and bound the estimate, then multiplies by a factorial to compute the
derivatives. Unlike real-valued finite differences, the method searches for
a desirable radius and so is reasonably insensitive to the initial
radius-to within a number of orders of magnitude at least. For most cases,
the default configuration is likely to succeed.
Restrictions:
The method uses the coefficients themselves to control the truncation
error, so the error will not be properly bounded for functions like
low-order polynomials whose Taylor series coefficients are nearly zero.
If the error cannot be bounded, degenerate flag will be set to true, and
an answer will still be computed and returned but should be used with
caution.
References
[1] Fornberg, B. (1981).
Numerical Differentiation of Analytic Functions.
ACM Transactions on Mathematical Software (TOMS),
7(4), 512-526. http://doi.org/10.1145/355972.355979
Examples
To compute the first five derivatives of 1 / (1 - z) at z = 0:
Compute the first 6 taylor derivatives of 1 / (1 - z) at z0 = 0:
Return the n’th derivative for all points using Finite Difference method.
Parameters:
fxvector
function values which are evaluated on x i.e. fx[i] = f(x[i])
xvector
abscissas on which fx is evaluated. The x values can be arbitrarily
spaced but must be distinct and len(x) > n.
nscalar integer
order of derivative.
mscalar integer
defines the stencil size. The stencil size is of 2 * mm + 1
points in the interior, and 2 * mm + 2 points for each of the 2 * mm
boundary points where mm = n // 2 + m.
fd_derivative evaluates an approximation for the n’th derivative of the
vector function f(x) using the Fornberg finite difference method.
Return Taylor coefficients of complex analytic function using FFT
Parameters:
funcallable
function to differentiate
z0real or complex scalar at which to evaluate the derivatives
nscalar integer, default 1
Number of taylor coefficents to compute. Maximum number is 100.
rreal scalar, default 0.0059
Initial radius at which to evaluate. For well-behaved functions,
the computation should be insensitive to the initial radius to within
about four orders of magnitude.
num_extrapscalar integer, default 3
number of extrapolation steps used in the calculation
step_ratioreal scalar, default 1.6
Initial grow/shrinking factor for finding the best radius.
max_iterscalar integer, default 30
Maximum number of iterations
min_iterscalar integer, default max_iter // 2
Minimum number of iterations before the solution may be deemed
degenerate. A larger number allows the algorithm to correct a bad
initial radius.
full_outputbool, optional
If full_output is False, only the coefficents is returned (default).
If full_output is True, then (coefs, status) is returned
Returns:
coefsndarray
array of taylor coefficents
status: Optional object into which output information is written:
degenerate: True if the algorithm was unable to bound the error
iterations: Number of iterations executed
function_count: Number of function calls
final_radius: Ending radius of the algorithm
failed: True if the maximum number of iterations was reached
error_estimate: approximate bounds of the rounding error.
Notes
This module uses the method of Fornberg to compute the Taylor series
coefficents of a complex analytic function along with error bounds. The
method uses a Fast Fourier Transform to invert function evaluations around
a circle into Taylor series coefficients and uses Richardson Extrapolation
to improve and bound the estimate. Unlike real-valued finite differences,
the method searches for a desirable radius and so is reasonably
insensitive to the initial radius-to within a number of orders of
magnitude at least. For most cases, the default configuration is likely to
succeed.
Restrictions:
The method uses the coefficients themselves to control the truncation
error, so the error will not be properly bounded for functions like
low-order polynomials whose Taylor series coefficients are nearly zero.
If the error cannot be bounded, degenerate flag will be set to true, and
an answer will still be computed and returned but should be used with
caution.
References
[1] Fornberg, B. (1981).
Numerical Differentiation of Analytic Functions.
ACM Transactions on Mathematical Software (TOMS),
7(4), 512-526. http://doi.org/10.1145/355972.355979
Examples
Compute the first 6 taylor coefficients 1 / (1 - z) expanded round z0 = 0:
function fun(z, *args, **kwds) to compute the limit for z->z0.
The function, fun, is assumed to return a result of the same shape and
size as its input, z.
step: float, complex, array-like or StepGenerator object, optional
Defines the spacing used in the approximation.
Default is CStepGenerator(base_step=step, **options)
method{‘above’, ‘below’}
defines if the limit is taken from above or below
order: positive scalar integer, optional.
defines the order of approximation used to find the specified limit.
The order must be member of [1 2 3 4 5 6 7 8]. 4 is a good compromise.
full_output: bool
If true return additional info.
options:
options to pass on to CStepGenerator
Returns:
limit_fz: array like
estimated limit of f(z) as z –> z0
info:
Only given if full_output is True and contains the following:
error estimate: ndarray
95 % uncertainty estimate around the limit, such that
abs(limit_fz - lim z->z0 f(z)) < error_estimate
final_step: ndarray
final step used in approximation
Notes
Limit computes the limit of a given function at a specified
point, z0. When the function is evaluable at the point in question,
this is a simple task. But when the function cannot be evaluated
at that location due to a singularity, you may need a tool to
compute the limit. Limit does this, as well as produce an
uncertainty estimate in the final result.
The methods used by Limit are Richardson extrapolation in a combination
with Wynn’s epsilon algorithm which also yield an error estimate.
The user can specify the method order, as well as the path into
z0. z0 may be real or complex. Limit uses a proportionally cascaded
series of function evaluations, moving away from your point of evaluation
along a path along the real line (or in the complex plane for complex z0 or
step.) The step_ratio is the ratio used between sequential steps. The
sign of step allows you to specify a limit from above or below. Negative
values of step will cause the limit to be taken approaching z0 from below.
A smaller step_ratio means that Limit will take more function
evaluations to evaluate the limit, but the result will potentially be less
accurate. The step_ratio MUST be a scalar larger than 1. A value in the
range [2,100] is recommended. 4 seems a good compromise.
Compute the residue at a first order pole at z = 0
The function 1./(1-exp(2*z)) has a pole at z == 0.
The residue is given by the limit of z*fun(z) as z –> 0.
Here, that residue should be -0.5.
A more difficult limit is one where there is significant
subtractive cancellation at the limit point. In the following
example, the cancellation is second order. The true limit
should be 0.5.
function fun(z, *args, **kwds) to compute the Residue at z=z0.
The function, fun, is assumed to return a result of the same shape and
size as its input, z.
step: float, complex, array-like or StepGenerator object, optional
Defines the spacing used in the approximation.
Default is CStepGenerator(base_step=step, **options)
method{‘above’, ‘below’}
defines if the limit is taken from above or below
order: positive scalar integer, optional.
defines the order of approximation used to find the specified limit.
The order must be member of [1 2 3 4 5 6 7 8]. 4 is a good compromise.
pole_orderscalar integer
specifies the order of the pole at z0.
full_output: bool
If true return additional info.
options:
options to pass on to CStepGenerator
Returns:
res_fz: array like
estimated residue, i.e., limit of f(z)*(z-z0)**pole_order as z –> z0
When the residue is estimated as approximately zero,
the wrong order pole may have been specified.
info: namedtuple,
Only given if full_output is True and contains the following:
error estimate: ndarray
95 % uncertainty estimate around the residue, such that
abs(res_fz - lim z->z0 f(z)*(z-z0)**pole_order) < error_estimate
Large uncertainties here suggest that the wrong order
pole was specified for f(z0).
final_step: ndarray
final step used in approximation
Notes
Residue computes the residue of a given function at a simple first order
pole, or at a second order pole.
The methods used by residue are polynomial extrapolants, which also yield
an error estimate. The user can specify the method order, as well as the
order of the pole.
z0 - scalar point at which to compute the residue. z0 may be
real or complex.
See the document DERIVEST.pdf for more explanation of the
algorithms behind the parameters of Residue. In most cases,
the user should never need to specify anything other than possibly
the PoleOrder.
A second order pole around z = 0 and z = pi
>>> def h(z): return 1.0/np.sin(z)**2
>>> res_h, info = Residue(h, full_output=True, pole_order=2)([0, np.pi])
>>> np.allclose(res_h, 1)
True
>>> bool((info.error_estimate < 1e-10).all())
True
A methodology for robust optimization of
low-thrust trajectories in multi-body
environments
Gregory Lantoine (2010)
Phd thesis, Georgia Institute of Technology
Using multicomplex variables for automatic
computation of high-order derivatives
Gregory Lantoine, Ryan P. Russell , and Thierry Dargent
ACM Transactions on Mathematical Software, Vol. 38, No. 3, Article 16,
April 2012, 21 pages,
http://doi.acm.org/10.1145/2168773.2168774
Bicomplex Numbers and Their Elementary Functions
M.E. Luna-Elizarraras, M. Shapiro, D.C. Struppa1, A. Vajiac (2012)
CUBO A Mathematical Journal
Vol. 14, No 2, (61-80). June 2012.
Computation of higher-order derivatives using the multi-complex
step method
Adriaen Verheyleweghen, (2014)
Project report, NTNU
This module provide an easy to use interface to derivatives calculated with
AlgoPy. Algopy stands for Algorithmic Differentiation in Python.
The purpose of AlgoPy is the evaluation of higher-order derivatives in the
forward and reverse mode of Algorithmic Differentiation (AD) of functions that
are implemented as Python programs. Particular focus are functions that contain
numerical linear algebra functions as they often appear in statistically
motivated functions. The intended use of AlgoPy is for easy prototyping at
reasonable execution speeds. More precisely, for a typical program a
directional derivative takes order 10 times as much time as time as the
function evaluation. This is approximately also true for the gradient.
Algorithmic differentiation (AD) is a set of techniques to numerically
evaluate the derivative of a function specified by a computer program. AD
exploits the fact that every computer program, no matter how complicated,
executes a sequence of elementary arithmetic operations (addition,
subtraction, multiplication, division, etc.) and elementary functions
(exp, log, sin, cos, etc.). By applying the chain rule repeatedly to these
operations, derivatives of arbitrary order can be computed automatically,
accurately to working precision, and using at most a small constant factor
more arithmetic operations than the original program.
Algorithmic differentiation is not:
Symbolic differentiation, nor Numerical differentiation (the method of
finite differences). These classical methods run into problems:
symbolic differentiation leads to inefficient code (unless carefully done)
and faces the difficulty of converting a computer program into a single
expression, while numerical differentiation can introduce round-off errors
in the discretization process and cancellation. Both classical methods have
problems with calculating higher derivatives, where the complexity and
errors increase. Finally, both classical methods are slow at computing the
partial derivatives of a function with respect to many inputs, as is needed
for gradient-based optimization algorithms. Algoritmic differentiation
solves all of these problems.
Algorithmic differentiation is a set of techniques to numerically
evaluate the derivative of a function specified by a computer program.
AD exploits the fact that every computer program, no matter how
complicated, executes a sequence of elementary arithmetic operations
(addition, subtraction, multiplication, division, etc.) and elementary
functions (exp, log, sin, cos, etc.). By applying the chain rule
repeatedly to these operations, derivatives of arbitrary order can be
computed automatically, accurately to working precision, and using at
most a small constant factor more arithmetic operations than the original
program.
Algorithmic differentiation is a set of techniques to numerically
evaluate the derivative of a function specified by a computer program.
AD exploits the fact that every computer program, no matter how
complicated, executes a sequence of elementary arithmetic operations
(addition, subtraction, multiplication, division, etc.) and elementary
functions (exp, log, sin, cos, etc.). By applying the chain rule
repeatedly to these operations, derivatives of arbitrary order can be
computed automatically, accurately to working precision, and using at
most a small constant factor more arithmetic operations than the original
program.
Algorithmic differentiation is a set of techniques to numerically
evaluate the derivative of a function specified by a computer program.
AD exploits the fact that every computer program, no matter how
complicated, executes a sequence of elementary arithmetic operations
(addition, subtraction, multiplication, division, etc.) and elementary
functions (exp, log, sin, cos, etc.). By applying the chain rule
repeatedly to these operations, derivatives of arbitrary order can be
computed automatically, accurately to working precision, and using at
most a small constant factor more arithmetic operations than the original
program.
Algorithmic differentiation is a set of techniques to numerically
evaluate the derivative of a function specified by a computer program.
AD exploits the fact that every computer program, no matter how
complicated, executes a sequence of elementary arithmetic operations
(addition, subtraction, multiplication, division, etc.) and elementary
functions (exp, log, sin, cos, etc.). By applying the chain rule
repeatedly to these operations, derivatives of arbitrary order can be
computed automatically, accurately to working precision, and using at
most a small constant factor more arithmetic operations than the original
program.
Algorithmic differentiation is a set of techniques to numerically
evaluate the derivative of a function specified by a computer program.
AD exploits the fact that every computer program, no matter how
complicated, executes a sequence of elementary arithmetic operations
(addition, subtraction, multiplication, division, etc.) and elementary
functions (exp, log, sin, cos, etc.). By applying the chain rule
repeatedly to these operations, derivatives of arbitrary order can be
computed automatically, accurately to working precision, and using at
most a small constant factor more arithmetic operations than the original
program.
Calculate Gradient with finite difference approximation
Parameters:
funfunction
function of one array fun(x, *args, **kwds)
stepfloat, optional
Stepsize, if None, optimal stepsize is used, i.e.,
x * _EPS for method==`complex`
x * _EPS**(1/2) for method==`forward`
x * _EPS**(1/3) for method==`central`.
Calculate Jacobian with finite difference approximation
Parameters:
funfunction
function of one array fun(x, *args, **kwds)
stepfloat, optional
Stepsize, if None, optimal stepsize is used, i.e.,
x * _EPS for method==`complex`
x * _EPS**(1/2) for method==`forward`
x * _EPS**(1/3) for method==`central`.
Calculate Gradient with finite difference approximation
Parameters:
funfunction
function of one array fun(x, *args, **kwds)
stepfloat, optional
Stepsize, if None, optimal stepsize is used, i.e.,
x * _EPS for method==`complex`
x * _EPS**(1/2) for method==`forward`
x * _EPS**(1/3) for method==`central`.
Calculate Jacobian with finite difference approximation
Parameters:
funfunction
function of one array fun(x, *args, **kwds)
stepfloat, optional
Stepsize, if None, optimal stepsize is used, i.e.,
x * _EPS for method==`complex`
x * _EPS**(1/2) for method==`forward`
x * _EPS**(1/3) for method==`central`.
Gradient of function, or Jacobian if function fun returns 1d array
Parameters:
xarray
parameters at which the derivative is evaluated
funfunction
fun(*((x,)+args), **kwargs) returning either one value or 1d array
epsilonfloat, optional
Stepsize, if None, optimal stepsize is used. This is _EPS**(1/2)*x for
centered == False and _EPS**(1/3)*x for centered == True.
argstuple
Tuple of additional arguments for function fun.
kwargsdict
Dictionary of additional keyword arguments for function fun.
centeredbool
Whether central difference should be returned. If not, does forward
differencing.
Returns:
gradarray
gradient or Jacobian
Notes
If fun returns a 1d array, it returns a Jacobian. If a 2d array is returned
by fun (e.g., with a value for each observation), it returns a 3d array
with the Jacobian of each observation with shape xk x nobs x xk. I.e.,
the Jacobian of the first observation would be [:, 0, :]
Calculate gradient or Jacobian with complex step derivative approximation
Parameters:
xarray
parameters at which the derivative is evaluated
ffunction
f(*((x,)+args), **kwargs) returning either one value or 1d array
epsilonfloat, optional
Stepsize, if None, optimal stepsize is used. Optimal step-size is
EPS*x. See note.
argstuple
Tuple of additional arguments for function f.
kwargsdict
Dictionary of additional keyword arguments for function f.
Returns:
partialsndarray
array of partial derivatives, Gradient or Jacobian
Notes
The complex-step derivative has truncation error O(epsilon**2), so
truncation error can be eliminated by choosing epsilon to be very small.
The complex-step derivative avoids the problem of round-off error with
small epsilon because there is no subtraction.
defines number of steps generated. It should be larger than
min_num_steps = (n + order - 1) / fact where fact is 1, 2 or 4
depending on differentiation method used.
step_nomdefault maximum(log(exp(1)+|x|), 1)
Nominal step where x is supplied at runtime through the __call__
method.
offsetreal scalar, optional, default 0
offset to the base step
num_extrapscalar integer, default 0
number of points used for extrapolation
check_num_stepsboolean, default True
If True make sure num_steps is larger than the minimum required steps.
defines number of steps generated. It should be larger than
min_num_steps = (n + order - 1) / fact where fact is 1, 2 or 4
depending on differentiation method used.
step_nomdefault maximum(log(exp(1)+|x|), 1)
Nominal step where x is supplied at runtime through the __call__ method.
offsetreal scalar, optional, default 0
offset to the base step
num_extrapscalar integer, default 0
number of points used for extrapolation
check_num_stepsboolean, default True
If True make sure num_steps is larger than the minimum required steps.
use_exact_stepsboolean, default True
If true make sure exact steps are generated
scalereal scalar, optional
scale used in base step. If not None it will override the default
computed with the default_scale function.