Python API#
The functions described in the C API can be access using the Python lintegrate module
provided with the library. These functions have a similar style to the SciPy
quad()
function.
- logtrapz(f, x[, disable_checks=False, args=()])#
Given the natural logarithm
f
of some functiong
(i.e., f = log(g)), compute the natural logarithm of the integral of that function using the trapezium rule.- Parameters:
f (
numpy.ndarray
, list, or function handle) – A set of values of the logarithm of a function evaluated at points given byx
, or a function handle of the log function to be evaluated.x (
numpy.ndarray
, list, or float) – An array of values at whichf
has been evaluated, or is to be evaluated at. Or, providedf
is also an array, a single value giving the spacing between evaluation points (if the function has been evaluated on an evenly spaced grid).disable_checks (bool) – Set this to True to disable checks, such as making sure
x
values are in ascending order. Defaults to False.args (tuple) – A tuple of any additional parameters required by the function
f
(to be unpacked within the function).
- Returns:
The natural logarithm of the integral of the function
- Return type:
- lqng(func, a=0., b=0.[, args=(), epsabs=1.49e-8, epsrel=1.49e-8, intervals=None, nintervals=0, intervaltype='linear'])#
Python wrapper to the
lintegration_qng()
function. This will integrate exp(func), whilst staying in log-space to ensure numerical precision, using a non-adaptive procedure. It uses fixed Gauss-Kronrod-Patterson abscisae to sample the integrand at a maximum of 87 points (seegsl_integration_qng()
).- Parameters:
func (function) – A callable Python function which returns the natural logarithm of the underlying function being integrated over.
a (float) – Lower limit of integration
b (float) – Upper limit of integration
args (tuple) –
Extra arguments to pass to func. These must be unpacked within func, e.g.:
def myfunc(x, args): y, z = args return x + y + z
epsabs (float) – The absolute error tolerance for the integral
epsrel (float) – The relative error tolerance for the integral
intervals (
numpy.ndarray
or list) – An array of values bounding intervals into which the integral will be split (this could be used, for example, if you have a very tightly peaked function and require small intervals around the peak).nintervals (int) – If
intervals
is not given then split the range betweena
andb
intonintervals
intervalsintervaltype (str) – If splitting into
nintervals
intervals then choose whether to split the range in equal intervals in ‘linear’, ‘log’, or ‘log10’ space
- Returns:
A tuple containing: the natural logarithm of the integral of exp(func), an estimate of the absolute error in the result, and the number of evaluations used in the integration
- Return type:
- lqag(func, a=0., b=0.[, args=(), epsabs=1.49e-8, epsrel=1.49e-8, limit=50, intkey=1, intervals=None, nintervals=0, intervaltype='linear'])#
Python wrapper to the
lintegration_qag()
function. This will integrate exp(func), whilst staying in log-space to ensure numerical precision, using a simple adaptive procedure (seegsl_integration_qag()
).- Parameters:
func (function) – A callable Python function which returns the natural logarithm of the underlying function being integrated over.
a (float) – Lower limit of integration
b (float) – Upper limit of integration
args (tuple) –
Extra arguments to pass to func. These must be unpacked within func, e.g.:
def myfunc(x, args): y, z = args return x + y + z
epsabs (float) – The absolute error tolerance for the integral
epsrel (float) – The relative error tolerance for the integral
limit (int) – The maximum number of subintervals used in the integration
intkey (int) – A key given the integration rule following those for the
gsl_integration_qag()
function. This can be 1, 2, 3, 4, 5, or 6, corresponding to the 15, 21, 31, 41, 51 and 61 point Gauss-Kronrod rules respectively.intervals (
numpy.ndarray
or list) – An array of values bounding intervals into which the integral will be split (this could be used, for example, if you have a very tightly peaked function and require small intervals around the peak).nintervals (int) – If
intervals
is not given then split the range betweena
andb
intonintervals
intervalsintervaltype (str) – If splitting into
nintervals
intervals then choose whether to split the range in equal intervals in ‘linear’, ‘log’, or ‘log10’ space
- Returns:
A tuple containing: the natural logarithm of the integral of exp(func) and an estimate of the absolute error in the result
- Return type:
- lcquad(func, a, b[, args=(), epsabs=1.49e-8, epsrel=1.49e-8, wsintervals=100, intervals=None, nintervals=0, intervaltype='linear'])#
Python wrapper to the
lintegration_cquad()
function. This will integrate exp(func), whilst staying in log-space to ensure numerical precision, using a doubly adaptive procedure (seegsl_integration_cquad()
).- Parameters:
func (function) – A callable Python function which returns the natural logarithm of the underlying function being integrated over.
a (float) – Lower limit of integration
b (float) – Upper limit of integration
args (tuple) –
Extra arguments to pass to func. These must be unpacked within func, e.g.:
def myfunc(x, args): y, z = args return x + y + z
epsabs (float) – The absolute error tolerance for the integral
epsrel (float) – The relative error tolerance for the integral
wsintervals (int) – A sufficient number of subintervals for the integration (if the workspace is full the smallest intervals will be discarded)
intervals (
numpy.ndarray
or list) – An array of values bounding intervals into which the integral will be split (this could be used, for example, if you have a very tightly peaked function and require small intervals around the peak).nintervals (int) – If
intervals
is not given then split the range betweena
andb
intonintervals
intervalsintervaltype (str) – If splitting into
nintervals
intervals then choose whether to split the range in equal intervals in ‘linear’, ‘log’, or ‘log10’ space
- Returns:
A tuple containing: the natural logarithm of the integral of exp(func), an estimate of the absolute error in the result, and the number of evaluations used in the integration
- Return type: