Loading [MathJax]/jax/input/TeX/config.js
scipy 1.10.1 Pypi GitHub Homepage
Other Docs

NotesParametersReturns
_qmc_quad(func, a, b, *, n_points=1024, n_estimates=8, qrng=None, log=False, args=None)

Notes

Values of the integrand at each of the n_points points of a QMC sample are used to produce an estimate of the integral. This estimate is drawn from a population of possible estimates of the integral, the value of which we obtain depends on the particular points at which the integral was evaluated. We perform this process n_estimates times, each time evaluating the integrand at different scrambled QMC points, effectively drawing i.i.d. random samples from the population of integral estimates. The sample mean m of these integral estimates is an unbiased estimator of the true value of the integral, and the standard error of the mean s of these estimates may be used to generate confidence intervals using the t distribution with n_estimates - 1 degrees of freedom. Perhaps counter-intuitively, increasing n_points while keeping the total number of function evaluation points n_points * n_estimates fixed tends to reduce the actual error, whereas increasing n_estimates tends to decrease the error estimate.

Parameters

func : callable

The integrand. Must accept a single arguments x, an array which specifies the point at which to evaluate the integrand. For efficiency, the function should be vectorized to compute the integrand for each element an array of shape (n_points, n), where n is number of variables.

a, b : array-like

One-dimensional arrays specifying the lower and upper integration limits, respectively, of each of the n variables.

n_points, n_estimates : int, optional

One QMC sample of n_points (default: 256) points will be generated by qrng, and n_estimates (default: 8) statistically independent estimates of the integral will be produced. The total number of points at which the integrand func will be evaluated is n_points * n_estimates. See Notes for details.

qrng : `~scipy.stats.qmc.QMCEngine`, optional

An instance of the QMCEngine from which to sample QMC points. The QMCEngine must be initialized to a number of dimensions corresponding with the number of variables x0, ..., xn passed to func. The provided QMCEngine is used to produce the first integral estimate. If n_estimates is greater than one, additional QMCEngines are spawned from the first (with scrambling enabled, if it is an option.) If a QMCEngine is not provided, the default scipy.stats.qmc.Halton will be initialized with the number of dimensions determine from a.

log : boolean, default: False

When set to True, func returns the log of the integrand, and the result object contains the log of the integral.

Returns

result : object

A result object with attributes:

integral

integral

standard_error :

The error estimate. See Notes for interpretation.

Compute an integral in N-dimensions using Quasi-Monte Carlo quadrature.

Examples

QMC quadrature is particularly useful for computing integrals in higher dimensions. An example integrand is the probability density function of a multivariate normal distribution.
import numpy as np
from scipy import stats
dim = 8
mean = np.zeros(dim)
cov = np.eye(dim)
def func(x):
    return stats.multivariate_normal.pdf(x, mean, cov)
To compute the integral over the unit hypercube:
from scipy.integrate import qmc_quad
a = np.zeros(dim)
b = np.ones(dim)
rng = np.random.default_rng()
qrng = stats.qmc.Halton(d=dim, seed=rng)
n_estimates = 8
res = qmc_quad(func, a, b, n_estimates=n_estimates, qrng=qrng)
res.integral, res.standard_error
A two-sided, 99% confidence interval for the integral may be estimated as:
t = stats.t(df=n_estimates-1, loc=res.integral,
            scale=res.standard_error)
t.interval(0.99)
Indeed, the value reported by `scipy.stats.multivariate_normal` is within this range.
stats.multivariate_normal.cdf(b, mean, cov, lower_limit=a)
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

scipy.stats._qmc:Halton_qmc:Halton

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /scipy/integrate/_quadrature.py#1216
type: <class 'function'>
Commit: