PBRT_V2 总结记录 <77> Monte Carlo Integration

1.Prepare

 It states(陈述) that the expected value(期望值) of a function of a random variable f(X) can be defined as:

Where PX is the probability distribution of the random variable X. This is hopefully something you understand well.

(以上的公式在 《PBRT_V2 总结记录 <75> Expected Value of the Function of a Random Variable》有说明)

 

2.  Basic Monte Carlo Estimator

The principle of a basic Monte Carlo estimation is this: imagine that we want to integrate a one-dimensional function f(x)

from a to b such as:

 

As you may remember, the integral of a function f(x) can be interpreted as(理解) calculating the area below the function's curve

. This idea is illustrated in figure 1.

Now imagine that we just pick up a random value, say x in the range [a,b], evaluate the

function f(x) at x and multiply the result by (b-a). Figure 2 shows what the result looks like: it's another rectangle (where f(x) is

the height of that rectangle and (b-a) its width), which in a way you can also look at a very crude(粗糙) approximation of the

area under the curve. Of couse we maybe get it more or less right. If we evaluate the function at x1 (figure 3) we quite

drastically(彻底) underestimate(低估) this area. If we evaluate the function at x2, we over estimate(高估) the area. But as we

keep evaluating the function at different random points between a and b, adding up the area of the rectangles and averaging

the sum, the resulting number gets closer and closer to the actual result of the integral. It's not surprising in a way as the

rectangles which are too large compensate(补偿) for the rectangles which are too small. And in fact, we will soon give the

proof(很快就会给出证据) that summing them up and averaging their areas actually converges to the integral "area" as the

number of samples used in the calculation increases. This idea is illustrated in the following figure. The function was evaluated

in four different locations. The result of the function as these four values of x randomly chosen, are then multiplied by (b-a),

summed up and averaged (we divide the sum by 4). The result can be considered as an approximation of the actual integral.

 

Of course, as usual with Monte Carlo methods, this approximation converges to the integral result as the number of rectangles

or samples used increases.

 

We can formalize this idea with the following formula:

Where N here, is the number of samples used in this approximation

Where N here, is the number of samples used in this approximation. In mathematical notation (and statistics), represents the average of all the elements in S (is an approximation of F using N samples. It is equivalent to the sample mean notation we used in lesson 16 and the two are actually equivalent).This equation is called a basic Monte Carlo

estimator. The random point in the interval [a,b] can easily be obtained by multiplying the result of a random generator

producing uniformly distributed numbers in the interval [0,1] with (b-a):

where ξ is uniformly distributed between zero and one.

The PDF of the resulting  Xis is 1/(b-a). Since the random numbers are produced with equiprobability(等概率的) (each number

is produced with the same probability than the others), we just divide 1 by the total number of outcomes as in the case of a

dice. However in this example, the function is continuous (as opposed to discrete), so we divide 1 by the interval [a,b].

It is important here to note that:

The law of large numbers which we talked in lesson 16, tells us that as N approaches infinity, our Monte Carlo approximation

converges (in probabiliy) to the right answer (the probabiliy is 1).

Note also that is a random variable, since it's actually made up of a sum of random numbers.  We can now proof(证明) that the expected value(期望值) of is equal to F:

Remember that the pdf is equal to 1/(b-a) thus it cancels out the term (b-a) on the right inside of the integral sign(积分符号) (line 3).

(以上最精彩的就是,让你理解积分可以用数学期望来进行表示)

 

3. Generalization(一般化) to Arbitrary PDF

Now, as mentioned above, the formula we used for the Monte Carlo estimator is basic(基本的). Why? Because it only works if the PDF of the random variable X is uniform. However, we can extend Monte Carlo integration to random variables with arbitry PDFs. The more generic formula is then:

This is the more generalized form of the Monte Carlo estimator, and the one you should remember (if there's only one equation to remember from the last two chapters, it is the one).

To be clear, the pdf in the denominator is the same as the pdf of the random variable X.

As with the basic Monte Carlo estimator, to be sure that this formula is valid, we need to check that this estimator has the correct expected value. Let's check:

(这里为什么的变换,可以参考 1.Prepare, PBRT_V2 总结记录 <75> Expected Value of the Function of a Random Variable》,

Take the time to understand these equations. As we just said, this is the most important result of everything we have studied so

far, and is the backbone(支柱) of almost every algorithm we are going to study in the next lessons. If you don't understand

this algorithm, you won't understand monte carlo ray tracing. With the rendering equation this is probably the second most

important equation.

 

we just demonstrated(演示) that you can still use a Monte Carlo integration, as long as you don't forget to

divide f(Xi) by pdf(Xi). 

Let's get an intuition(直观) as to why dividing f(x) by pdf(x) is necessary (for non-constant PDFs). As you know, the pdf gives the

probability that a random variable X get some value xi, . When you draw samples from an arbitrary PDF, samples aren't

uniformly distributed: more samples are generated where the PDF is high and reversely(反之), fewer samples are generated

where the PDF is low (see adjacent figure). In a monte carlo integration though, the samples need to be uniformly distributed. If

you generate a high concentration(高浓度) of samples in some region of the function (because the PDF is high in this region),

the result of the Monte Carlo integration will be clearly biased. Dividing f(x) by pdf(x) though will counterbalance(平行) this

effect. Indeed, when the pdf is high (which is also where more samples are generated) dividing f(x) by pdf(x) will decrase the

"weight" of these samples in the sum. So in essence(本质上), we compensate(补偿) for the higher concentration(浓度) of

samples, by weighting down their contribution. On the other hand, when the pdf is low, fewer samples are generated (the

density of samples is lower than in region where the pdf is high). But if we divide f(x) by a low value (1 divided by 0.1 for

instance), the contribution of these samples is scaled up. We compensate(补偿) for the lesser density of samples by giving

them more weight. That's in essence, what the division of f(x) by pdf(x) does. It weights the samples' contribution to

compensate(补偿) for the fact that samples generated from an arbitrary PDF won't be uniformly distributed (assuming the PDF

is not constant of course): it scales down samples generated in regions of higher density (where the PDF is high), and scales

up samples generared in regions of lesser density (where the PDF is low).

(以上的主要证明就是,为什么   是可以表示积分,给出推导)

 

As you can see, a Monte Carlo estimation is nothing else than a sample mean, only, we substitute(代替) the population for a

real-value arbitrary function. 

(其实 Monte Carlo Integration 就是一个 mean,平均值,数学期望 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值