naginterfaces.library.quad.md_​mcarlo

naginterfaces.library.quad.md_mcarlo(a, b, mincls, maxcls, f, eps, wrkstr, finest, data=None)[source]

md_mcarlo returns an approximation to the integral of a function over a hyper-rectangular region, using a Monte Carlo method. An approximate relative error estimate is also returned. This function is suitable for low accuracy work.

For full information please refer to the NAG Library document for d01gb

https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/d01/d01gbf.html

Parameters
afloat, array-like, shape

The lower limits of integration, , for .

bfloat, array-like, shape

The upper limits of integration, , for .

minclsint

Must be set

either to the minimum number of integrand evaluations to be allowed, in which case ;

or to a negative value. In this case, the function assumes that a previous call had been made with the same arguments , and and with either the same integrand (in which case md_mcarlo continues calculation) or a similar integrand (in which case md_mcarlo begins the calculation with the subdivision used in the last iteration of the previous call). See also .

maxclsint

The maximum number of integrand evaluations to be allowed. In the continuation case this is the number of new integrand evaluations to be allowed. These counts do not include zero integrand values.

fcallable retval = f(x, data=None)

must return the value of the integrand at a given point.

Parameters
xfloat, ndarray, shape

The coordinates of the point at which the integrand must be evaluated.

dataarbitrary, optional, modifiable in place

User-communication data for callback functions.

Returns
retvalfloat

The value of the integrand at the given point.

epsfloat

The relative accuracy required.

wrkstrfloat, array-like, shape

If , must be unchanged from the previous call of md_mcarlo – except that for a new integrand must be set to . See also .

finestfloat

Must be unchanged from a previous call to md_mcarlo.

dataarbitrary, optional

User-communication data for callback functions.

Returns
minclsint

Contains the number of integrand evaluations actually used by md_mcarlo.

accfloat

The estimated relative accuracy of .

wrkstrfloat, ndarray, shape

Contains information about the current sub-interval structure which could be used in later calls of md_mcarlo. In particular, gives the number of sub-intervals used along the th coordinate axis.

finestfloat

The best estimate obtained for the integral.

Raises
NagValueError
(errno )

On entry, .

Constraint: .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, is too small. . Minimum possible dimension: .

(errno )

On entry, .

Constraint: .

Warns
NagAlgorithmicWarning
(errno )

too small to obtain required accuracy . and .

Notes

In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.

md_mcarlo uses an adaptive Monte Carlo method based on the algorithm described in Lautrup (1971). It is implemented for integrals of the form:

Upon entry, unless has been set to the minimum value , the function subdivides the integration region into a number of equal volume subregions. Inside each subregion the integral and the variance are estimated by means of pseudorandom sampling. All contributions are added together to produce an estimate for the whole integral and total variance. The variance along each coordinate axis is determined and the function uses this information to increase the density and change the widths of the sub-intervals along each axis, so as to reduce the total variance. The total number of subregions is then increased by a factor of two and the program recycles for another iteration. The program stops when a desired accuracy has been reached or too many integral evaluations are needed for the next cycle.

References

Lautrup, B, 1971, An adaptive multi-dimensional integration procedure, Proc. 2nd Coll. Advanced Methods in Theoretical Physics, Marseille