Title: | Stochastic Integrating |
---|---|
Description: | An implementation of four stochastic methods of integrating in R, including: 1. Stochastic Point Method (or Monte Carlo Method); 2. Mean Value Method; 3. Important Sampling Method; 4. Stratified Sampling Method. It can be used to estimate one-dimension or multi-dimension integration by Monte Carlo methods. And the estimated variance (precision) is given. Reference: Caflisch, R. E. (1998) <doi:10.1017/S0962492900002804>. |
Authors: | Jinhong Du |
Maintainer: | Jinhong Du <[email protected]> |
License: | GPL |
Version: | 0.2.0 |
Built: | 2024-12-09 06:46:23 UTC |
Source: | CRAN |
Important Sampling Method
SI.ISM(h, g, G_inv, N, min_G = 0, max_G = 1)
SI.ISM(h, g, G_inv, N, min_G = 0, max_G = 1)
h |
Density function to be integrated |
g |
Sampling density function |
G_inv |
The inverse function of sampling distribution function |
N |
The number of trials |
min_G |
The min value of G |
max_G |
The max value of G |
I |
Approximated integration |
Var |
Estimated variance |
## To integrate exp(x) from -1 to 1 ## Use the sampling density (3/2+x)/3 set.seed(0) h <- function(x){ exp(x) } N <- 100000 g <- function(x){return((3/2+x)/3)} G_inv <- function(y){return(sqrt(6*y+1/4)-3/2)} ISMresult <- SI.ISM(h,g,G_inv,N) I3 <- ISMresult[[1]] VarI3 <- ISMresult[[2]]
## To integrate exp(x) from -1 to 1 ## Use the sampling density (3/2+x)/3 set.seed(0) h <- function(x){ exp(x) } N <- 100000 g <- function(x){return((3/2+x)/3)} G_inv <- function(y){return(sqrt(6*y+1/4)-3/2)} ISMresult <- SI.ISM(h,g,G_inv,N) I3 <- ISMresult[[1]] VarI3 <- ISMresult[[2]]
Mean Value Method
SI.MVM(h, from, to, N)
SI.MVM(h, from, to, N)
h |
Density function to be integrated |
from |
The start point |
to |
The end point |
N |
The number of trials |
I |
Approximated integration |
Var |
Estimated variance |
## To integrate exp(x) from -1 to 1 set.seed(0) h <- function(x){ exp(x) } N <- 100000 MVMresult <- SI.MVM(h,-1,1,N) I2 <- MVMresult[[1]] VarI2 <- MVMresult[[2]]
## To integrate exp(x) from -1 to 1 set.seed(0) h <- function(x){ exp(x) } N <- 100000 MVMresult <- SI.MVM(h,-1,1,N) I2 <- MVMresult[[1]] VarI2 <- MVMresult[[2]]
Stochastic Point Method
SI.SPM(h, from, to, M, N)
SI.SPM(h, from, to, M, N)
h |
Density function to be integrated |
from |
The start point |
to |
The end point |
M |
The upper bound of h(x) in [from,to] |
N |
The number of trials |
I |
Approximated integration |
Var |
Estimated variance |
## To integrate exp(x) from -1 to 1 set.seed(0) h <- function(x){ exp(x) } N <- 100000 SPMresult <- SI.SPM(h,-1,1,exp(1),N) I1 <- SPMresult[[1]] VarI1 <- SPMresult[[2]]
## To integrate exp(x) from -1 to 1 set.seed(0) h <- function(x){ exp(x) } N <- 100000 SPMresult <- SI.SPM(h,-1,1,exp(1),N) I1 <- SPMresult[[1]] VarI1 <- SPMresult[[2]]
Stratified Sampling Method
SI.SSM(h, from, to, level, N)
SI.SSM(h, from, to, level, N)
h |
Density function to be integrated |
from |
The start point |
to |
The end point |
level |
Stratification, number of intervals |
N |
The number of trials |
I |
Approximated integration |
Var |
Estimated variance |
## To integrate exp(x) from -1 to 1 set.seed(0) h <- function(x){ exp(x) } N <- 100000 SSMresult <- SI.SSM(h,-1,1,10,N) I4 <- SSMresult[[1]] VarI4 <- SSMresult[[2]]
## To integrate exp(x) from -1 to 1 set.seed(0) h <- function(x){ exp(x) } N <- 100000 SSMresult <- SI.SSM(h,-1,1,10,N) I4 <- SSMresult[[1]] VarI4 <- SSMresult[[2]]