R: Integration by a Deterministic Iterative Adaptive Algorithm
cuhre
R Documentation
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.
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.
Details
See details in the documentation.
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.
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
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))
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(R2Cuba)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/R2Cuba/cuhre.Rd_%03d_medium.png", width=480, height=480)
> ### Name: cuhre
> ### Title: Integration by a Deterministic Iterative Adaptive Algorithm
> ### Aliases: cuhre
> ### Keywords: math
>
> ### ** Examples
>
> 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))
Cuhre input parameters:
ndim 3
ncomp 1
rel.tol 0.001
abs.tol 1e-12
pseudo.random 0
final 0
verbose 2
min.eval 0
max.eval 50000
key 0
Iteration 1: 127 integrand evaluations so far
[1] 0.66467 +- 7.2682e-10 chisq 0 (0 df)
Iteration 2: 381 integrand evaluations so far
[1] 0.66467 +- 3.33018e-11 chisq 0 (1 df)
integral: 0.6646697 (+-3.3e-11)
nregions: 2; number of evaluations: 381; probability: 0
>
>
>
>
>
> dev.off()
null device
1
>