MC积分

Monte Carlo方法由冯·诺伊曼于二战时提出,1777年法国人布丰用此思路估计pi值被认为是Monte Carlo的起源,这个方法简单又快速,通过产生随机数,将数值计算问题变成随机变量的某些特征值(比如期望值)。

积分运算,和估计pi值一样,用hit and miss法估计。

hit_miss <- function(fun, lower, upper, n=500) {
    # Monte Carlo integration using the hit and miss method
    x <- runif(n, lower, upper)
    f.value <- sapply(seq(lower, upper, 0.001), fun)
    f.min <- min(f.value)
    f.max <- max(f.value)
    y <- runif(n, f.min, f.max)
    hits <- sum(y <= fun(x))
    area <- (upper-lower) * f.min + hits/n * (upper-lower) * (f.max-f.min)
    return(area)
}

hit and miss方法收敛太慢,效率并不高,通常所说的MC积分是指下面这个方法。

Continue reading

The foundamental idea of numerical integration is to estimate the area of the region in the xy-plane bounded by the graph of function f(x). The integral was esimated by dividing x into small intervals, then adds all the small approximations to give a total approximation. Trapezoidal rule Numerical integration can be done by trapezoidal rule, simpson’s rule and quadrature rules. R has a built-in function, integrate, which performs adaptive quadrature.

Continue reading

Author's picture

Guangchuang Yu

Bioinformatics Professor @ SMU

Bioinformatics Professor

Guangzhou