Diego Kuonen wrote:
>
> First, let us start with the proposed Monte Carlo integration. The analytical
> solution is 20*log(5)/6 = 5.364793, hence using the following function ...
Using always transformations down to [0,1]^2 for my variables, I forgot
to multiply the MC estimates by the volume of the region of integration.
The corrected MC function becomes
MC.integrate.2D <- function(fct, low=c(-1,1), upp=c(1,1),
npoints=100, exact.value=NULL)
{
points.x<-runif(n=npoints, min=low[1], max=upp[1])
points.y<-runif(n=npoints, min=low[2], max=upp[2])
approx.tmp <- fct(points.x, points.y)
V.tmp <- diff(c(low[1], upp[1])) * diff(c(low[2], upp[2]))
approx <- mean(approx.tmp) * V.tmp
varapprox <- var(approx.tmp) * V.tmp
if(!is.null(exact.value)) {
cat("To achieve an error of 0.0001 you need at least",
floor(abs(varapprox - exact.value^2)/(0.0001^2)),
"points.\n")
}
approx
}
Nevertheless, my previous comments remain: I do not feel
comfortable using MC methods.
Greets
Diego Kuonen
--
Diego DOT Kuonen AT epfl DOT ch diego AT kuonen DOT com
http://stat.kuonen.com http://www.Statoo.com
`If you can imagine it, you can achieve it; if you can dream
it, you can become it.' Powered by Open Source!
|