vegas: Integration with a Monte Carlo Algorithm

Description Usage Arguments Details Value References See Also Examples

View source: R/vegas.R

Description

Implement a Monte Carlo algorithm for multidimensional numerical integration. This algorithm uses importance sampling as a variance-reduction technique. Vegas iteratively builds up a piecewise constant weight function, represented on a rectangular grid. Each iteration consists of a sampling step followed by a refinement of the grid.

Usage

1
2
3
4
5
6
vegas(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, smooth=0, mersenne.seed=NULL),
      min.eval=0,  max.eval=50000,
      nstart=1000,  nincrease=500, nbatch=1000, gridno=0, state.file=NULL)

Arguments

ndim

same as cuhre

ncomp

same as cuhre

integrand

same as cuhre; But, here, the input argument phw contains the weight of the point being sampled. This extra value can safely be ignored.

...

same as cuhre

lower

same as cuhre

upper

same as cuhre

rel.tol

same as cuhre

abs.tol

same as cuhre

flags

same as cuhre. But flags may have an additional component: smooth. When smooth = 0, apply additional smoothing to the importance function, this moderately improves convergence for many integrands. When smooth = 1 , use the importance function without smoothing, this should be chosen if the integrand has sharp edges.

Note: Value 3 of flags$verbose has the same effect as value 2 (Vegas does not partition the integration region).

min.eval

same as cuhre

max.eval

same as cuhre

nstart

the number of integrand evaluations per iteration to start with.

nincrease

the increase in the number of integrand evaluations per iteration. The j-th iteration evaluates the integrand at nstart+(j-1)*nincrease points.

nbatch

Vegas samples points not all at once, but in batches of a predetermined size, to avoid excessive memory consumption. nbatch is the number of points sampled in each batch. Tuning this number should usually not be necessary as performance is affected significantly only as far as the batch of samples fits into the CPU cache.

gridno

an integer. Vegas may accelerate convergence to keep the grid accumulated during one integration for the next one, if the integrands are reasonably similar to each other. Vegas maintains an internal table with space for ten grids for this purpose. If gridno is a number between 1 and 10, the grid is not discarded at the end of the integration, but stored in the respective slot of the table for a future invocation. The grid is only re-used if the dimension of the subsequent integration is the same as the one it originates from. In repeated invocations it may become necessary to flush a slot in memory. In this case the negative of the grid number should be set. Vegas will then start with a new grid and also restore the grid number to its positive value, such that at the end of the integration the grid is again stored in the indicated slot.

state.file

the name of an external file. Vegas can store its entire internal state (i.e. all the information to resume an interrupted integration) in an external file.

The state file is updated after every iteration. If, on a subsequent invocation, Vegas finds a file of the specified name, it loads the internal state and continues from the point it left off. Needless to say, using an existing state file with a different integrand generally leads to wrong results. Once the integration finishes successfully, i.e. the prescribed accuracy is attained, the state file is removed. This feature is useful mainly to define ‘check-points’ in long-running integrations from which the calculation can be restarted.

Details

See details in the documentation.

Value

Idem as cuhre, except from nregions (not present)

References

G. P. Lepage (1978) A new algorithm for adaptive multidimensional integration. J. Comput. Phys., 27, 192-210.

G. P. Lepage (1980) VEGAS - An adaptive multi-dimensional integration program. Research Report CLNS-80/447. Cornell University, Ithaca, N.-Y.

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

See Also

cuhre, suave, divonne

Examples

1
2
3
4
5
6
7
8
integrand <- function(arg, weight) {
  x <- arg[1]
  y <- arg[2]
  z <- arg[3]
  ff <- sin(x)*cos(y)*exp(z);
return(ff)
} # end integrand
vegas(3, 1, integrand, rel.tol=1e-3,  abs.tol=1e-12, flags=list(verbose=2))

Example output

Vegas input parameters:
  ndim 3
  ncomp 1
  rel.tol 0.001
  abs.tol 1e-12
  smooth 0
  pseudo.random  0
  final 0
  verbose 2
  min.eval 0
  max.eval 50000
  nstart 1000
  nincrease 500
  vegas.gridno 0
  vegas.state ""
Iteration 1:  1000 integrand evaluations so far
[1] 0.664916 +- 0.0138647  	chisq 0 (0 df)
Iteration 2:  2500 integrand evaluations so far
[1] 0.664102 +- 0.00448861  	chisq 0.0038488 (1 df)
Iteration 3:  4500 integrand evaluations so far
[1] 0.664341 +- 0.00174067  	chisq 0.00717154 (2 df)
Iteration 4:  7000 integrand evaluations so far
[1] 0.665279 +- 0.000771133  	chisq 0.368573 (3 df)
Iteration 5:  10000 integrand evaluations so far
[1] 0.664811 +- 0.000492177  	chisq 0.990089 (4 df)
integral: 0.6648107 (+-0.00049)
number of evaluations:  10000; probability:  0.08870493 

R2Cuba documentation built on May 29, 2017, 7:53 p.m.