Learn R Programming

R2Cuba (version 1.1-0)

cuhre: Integration by a Deterministic Iterative Adaptive Algorithm

Description

Implement a deterministic algorithm for multidimensional numerical integration. Its algorithm uses one of several cubature rules in a globally adaptive subdivision scheme. The subdivision algorithm is similar to suave's.

Usage

cuhre(ndim, ncomp, integrand, ..., lower=rep(0,ndim), upper=rep(1,ndim), rel.tol= 0.001, abs.tol = 0, flags=list(verbose=1, final=1, pseudo.random=0, mersenne.seed=NULL), min.eval=0, max.eval=50000, key=0)

Arguments

ndim
the number of dimensions of the integral. It should be less or equal to 40.
ncomp
the number of components of the integrand. It should be less or equal to 10.
integrand
the R function which computes the integrand. It is expected to be declared as integrand <- function(x, ...) or

integrand <- function(x, phw, ...) where x is an input vector of length ndim, and phw an ignored argument for compatibility with the other 'R2Cuba' functions.

... denotes optional additional arguments which correspond to those passed to the main function in “...”. The value returned by this R function should be a vector of length ncomp.

...
optional additional parameters to be passed to integrand, if any
lower
the lower bounds of the integration region. Vector of length ndim
upper
the upper bounds of the integration region. Vector of length ndim
rel.tol
the requested relative accuracy. Default, 0.001.
abs.tol
the requested absolute accuracy. The algorithm stops when either the relative or the absolute accuracies are met. Default, near 0 (the algorithm stops when the relative accuracy is met).
flags
flags governing the integration. A list with components: - verbose: verbose encodes the verbosity level, from. 0 to 3. Level 0 does not print any output, level 1 prints “reasonable” information on the progress of the integration, level 2 also echoes the input parameters, and level 3 further prints the subregion results.

- final: when 0, all sets of samples collected on a subregion during the various iterations or phases contribute to the final result. When 1, only the last (largest) set of samples is used in the final result.

- pseudo.random: (ignored in cuhre)

when 0, Sobol quasi-random numbers are used for sampling. When 1, Mersenne Twister pseudo-random numbers are used for sampling.

- mersenne.seed: (ignored in cuhre)

the seed for the Mersenne Twister algorithm, when pseudo.random=1 and when it would be explicitly set.

min.eval
the minimum number of integrand evaluations required.
max.eval
the (approximate) maximum number of integrand evaluations allowed.
key
chooses the basic integration rule: key = 7, 9, 11, 13 selects the cubature rule of degree key. Note that the degree-11 rule is available only in 3 dimensions, the degree-13 rule only in 2 dimensions.

For other values, the default rule is taken, which is the degree-13 rule in 2 dimensions, the degree-11 rule in 3 dimensions, and the degree-9 rule otherwise.

Value

A list of the S3-class cuba with components:
method
here, “cuhre”
nregions
the actual number of subregions needed.
neval
the actual number of integrand evaluations needed.
ifail
an error flag:ifail = 0 , the desired accuracy was reached,ifail = -1, dimension out of range,ifail = 1, the accuracy goal was not met within the allowed maximum number of integrand evaluations.
value
vector of length ncomp; the integral of integrand over the hypercube.
abs.error
vector of length ncomp; the presumed absolute error of value.
prob
vector of length ncomp; the $Chi2$-probability (not the $Chi2$-value itself!) that abs.error is not a reliable estimate of the true integration error.
message
“OK” or a character string giving the error message.
call
The matched call.

Details

See details in the documentation.

References

J. Berntsen, T. O. Espelid (1991) An adaptive algorithm for the approximate calculation of multiple integrals. ACM Transactions on Mathematical Software, 17(4), 437-451.

T. Hahn (2005) CUBA-a library for multidimensional numerical integration. Computer Physics Communications, 168, 78-95.

See Also

vegas, suave, divonne

Examples

Run this code
integrand <- function(arg) {
  x <- arg[1]
  y <- arg[2]
  z <- arg[3]
  ff <- sin(x)*cos(y)*exp(z);
return(ff)
} # End integrand

NDIM <- 3
NCOMP <- 1
cuhre(NDIM, NCOMP,  integrand,
             rel.tol= 1e-3, abs.tol= 1e-12,
             flags= list(verbose=2, final=0))

Run the code above in your browser using DataLab