nint_integrateNCube {docopulae} | R Documentation |
Integrate Hypercube
Description
Interface to the integration over interval dimensions.
Usage
nint_integrateNCube(f, lowerLimit, upperLimit, ...)
nint_integrateNCube_integrate(integrate)
nint_integrateNCube_cubature(adaptIntegrate)
nint_integrateNCube_SparseGrid(createIntegrationGrid)
Arguments
integrate |
|
adaptIntegrate |
|
createIntegrationGrid |
|
f |
the scalar-valued wrapper function to be integrated. |
lowerLimit |
the lower limits of integration. |
upperLimit |
the upper limits of integration. |
... |
other arguments passed to |
Details
nint_integrate
uses nint_integrateNCube
to handle interval dimensions.
See examples below on how to deploy different solutions.
The function built by nint_integrateNCube_integrate
calls integrate
(argument) recursively.
The number of function evaluations therefore increases exponentially with the number of dimensions ((subdivisions * 21) ** D
if integrate
, the default, is used).
At the moment it is the default method because no additional package is required.
However, you most likely want to consider different solutions.
The function built by nint_integrateNCube_cubature
is a trivial wrapper for cubature::adaptIntegrate
.
The function built by nint_integrateNCube_SparseGrid
is an almost trivial wrapper for SparseGrid::createIntegrationGrid
.
It scales the grid to the integration region.
Value
nint_integrateNCube
returns a single numeric.
nint_integrateNCube_integrate
returns a recursive implementation for nint_integrateNCube
based on one dimensional integration.
nint_integrateNCube_cubature
returns a trivial implementation for nint_integrateNCube
indirectly based on cubature::adaptIntegrate
.
nint_integrateNCube_SparseGrid
returns an implementation for nint_integrateNCube
indirectly based on SparseGrid::createIntegrationGrid
.
See Also
adaptIntegrate
in package cubature
createIntegrationGrid
in package SparseGrid
Examples
## integrate with defaults (stats::integrate)
nint_integrate(sin, nint_space(nint_intvDim(pi/4, 3*pi/4)))
dfltNCube = nint_integrateNCube
## prepare for integrateA
ncube = function(f, lowerLimit, upperLimit, ...) {
cat('using integrateA\n')
integrateA(f, lowerLimit, upperLimit, ..., subdivisions=2)
}
ncube = nint_integrateNCube_integrate(ncube)
unlockBinding('nint_integrateNCube', environment(nint_integrate))
assign('nint_integrateNCube', ncube, envir=environment(nint_integrate))
## integrate with integrateA
nint_integrate(sin, nint_space(nint_intvDim(pi/4, 3*pi/4)))
## prepare for cubature
ncube = function(f, lowerLimit, upperLimit, ...) {
cat('using cubature\n')
r = cubature::adaptIntegrate(f, lowerLimit, upperLimit, ..., maxEval=1e3)
return(r$integral)
}
unlockBinding('nint_integrateNCube', environment(nint_integrate))
assign('nint_integrateNCube', ncube, envir=environment(nint_integrate))
## integrate with cubature
nint_integrate(sin, nint_space(nint_intvDim(pi/4, 3*pi/4)))
## prepare for SparseGrid
ncube = function(dimension) {
cat('using SparseGrid\n')
SparseGrid::createIntegrationGrid('GQU', dimension, 7)
}
ncube = nint_integrateNCube_SparseGrid(ncube)
unlockBinding('nint_integrateNCube', environment(nint_integrate))
assign('nint_integrateNCube', ncube, envir=environment(nint_integrate))
## integrate with SparseGrid
nint_integrate(sin, nint_space(nint_intvDim(pi/4, 3*pi/4)))
assign('nint_integrateNCube', dfltNCube, envir=environment(nint_integrate))