Introducton to Monte Carlo Method Kad Bouatouch IRISA Emal: kad@rsa.fr Wh Monte Carlo Integraton? To generate realstc lookng mages, we need to solve ntegrals of or hgher dmenson Pel flterng and lens smulaton both nvolve solvng a dmensonal ntegral Combnng pel flterng and lens smulaton requres solvng a 4 dmensonal ntegral ormal quadrature algorthms don t etend well beond dmenson Contnuous Probablt A contnuous random varable s a varable that randoml takes on a value from ts doman The behavor of s completel descrbed b the dstrbuton of values t take. Contnuous Probablt The dstrbuton of values that takes on s descrbed b a probablt dstrbuton functon p We sa that s dstrbuted accordng to p, or ~ p d = The probablt that takes on a value n b the nterval [a, b] s: P( a, b = d [ ] a
Epected Value The epected value of ~p s defned as E ( = d As a functon of a random varable s tself a random varable, the epected value of f( s E ( f ( = f ( d The epected value of a sum of random varables s the sum of the epected values: E( + = E( + E( Mult-Dmensonal Random Varables For some space S, we can defne a pdf p:s R If s a random varable, and ~p, the probablt that takes on a value n S S s: P( S = dµ Epected value of a real valued functon f :S R etends naturall to the multdmensonal case: S E ( f ( = f ( dµ S Monte Carlo Integraton Suppose we have a functon f( defned over the doman є [a, b] We would lke to evaluate the ntegral I = b f ( d a The Monte Carlo approach s to consder samples, selected randoml wth pdf, to estmate the ntegral f ( We get the followng estmator: I = = Monte Carlo Integraton Fndng the estmated value of the estmator we get: f ( E[ I ] E In other words: = = f ( = E = f ( = p d ( = f ( d = I f ( lm = I =
Varance The varance of the estmator s σ f ( I p d p = ( ( As the error n the estmator s proportonal to σ, the error s proportonal to So, to halve the error we need to use four tmes as man samples Varance Reducton Increase number of samples Choose p such that f/p has low varance (f and p should have smlar shape Ths s called mportance samplng because f p s large when f s large, and small when f s small, there wll be more sample n mportant regons Partton the doman of the ntegral nto several smaller regons and evaluate the ntegral as a the sum of ntegrals over the smaller regons Ths s called stratfed samplng Varance Reducton: Stratfed samplng Regon D dvded nto dsjont sub-regons D =[, + ]: sub-regon P = D D ( f ( / d = P ( f ( / P d = f ( Varance Reducton: Stratfed samplng samples per sub-regon n sub-regons /P : pdf for a sub-regon f ( I = f ( d = ( f ( / p ( p ( d +... + ( f ( / p ( p ( d + ( f ( / p ( p ( d D D ( f ( / d = P ( f ( / ( / P d = n f ( f ( I = n P f ( Xk = P. d I = D P X = k= k n
Varance Reducton: Stratfed samplng D eample samples Samplng Random Varables Gven a pdf, defned over the nterval [ mn, ma ], we can sample a random varable ~p from a set of unform random numbers ξ є [, prob( α < = P( = µ dµ mn To do ths, we need the cumulatve probablt dstrbuton functon: To get we transform ξ : = P - (ξ P - s guaranteed to est for all vald pdfs Eample Sample the pdf =3 /, є [-, ]: Frst we need to fnd P(: 3 P ( = 3 / d = / + C Choosng C such that P(-= and P(=, we get P(=( 3 +/ and P - 3 (ξ= ξ Thus, gven a random number ξ є [,, we can warp t accordng to to get : = 3 ξ Samplng D Random Varables If we have a D random varable α=(α, α wth pdf α, α, we need the two dmensonal cumulatve pdf: prob( α < & α < = P(, µ, µ dµ dµ = We can choose usng the margnal dstrbuton p G ( and then choose accordng to, where ma, pg ( =, d and = mn p ( If p s separable, that s, =q(,r(, the one dmensonal technque can be used on each dmenson nstead mn G mn
D eample: Unform Samplng of To unforml sample a trangle, we use barcentrc coordnates n a parametrc space Let A,B,C the 3 vertces of a trangle Then a pont P on the trangle s epressed as: C P= αa + βb + γc α + β + γ = α = - γ - β P P =(-γ - β A + βb + γc A γ B D eample: Unform Samplng of To unforml sample a trangle, we use barcentrc coordnates n a parametrc space (, β (, γ (, β + γ = D eample: Unform Samplng of To unforml sample a trangle, we use barcentrc coordnates Integratng the constant across the γ trangle gves.5 dβdγ = γ = β = Thus our pdf s β,γ= Snce β depends on γ (or γ depends on β, we use the margnal denst for γ, p G (γ: γ p G ( γ = dβ = γ D eample: Unform Samplng of From p G (γ, we fnd β γ = γ, β /p G (γ = /(-γ = /(-γ To fnd γ we look at the cummulatve pdf for γ: γ γ ξ = PG ( γ = pg ( γ dγ = γdγ = γ γ Solvng for γ we get γ = ξ We then turn to β : β ξ = P( β γ = β γ dβ = β β dβ = γ γ
D eample: Unform Samplng of Solvng for β we get: β = ξ ( γ = ξ( ( ξ = ξ Thus gven a set of random numbers ξ and ξ, we warp these to a set of barcentrc coordnates samplng a trangle: β, γ = ( ξ ξ, ( ξ ξ D eample: Unform Samplng of Dscs Dsc Generate random pont on unt dsk wth probablt denst: = /(π.r ϕ [,π ] et r [, R] d µ = ds = rdrdφ = ϕ r F( r, ϕ ( r /( π. R dr dϕ D CDF: D eample: Unform Samplng of Dscs Dsc Generate random pont on unt dsk wth probablt denst: = /(π.r ϕ [,π ] et r [, R] d µ = ds = rdrdφ = ϕ r F( r, (r/ R (/ π dr dϕ ϕ D CDF: Compute margnal pdf and assocated CDF ζ and ζ [,] are unform random numbers ϕ = πζ and r = R ζ D eample: Unform Samplng of Spheres Sphere π / θn π ϕn Θ = cos θ cos( ξ ϕ πξ π θ = a et = Θ = ( θ, ϕ dµ = dω = snθ dθ dϕ Θ = n+ cos( cosnθ θ = a ξ n + etϕ= πξ π Θ θ n dω Θn ϕ n
Summar Gven a functon f(µ, defned over an n-dmensonal doman S, we can estmate the ntegral of f over S b a sum: f ( f ( µ dµ S = where ~p s a random varable and are samples of selected accordng to p. To reduce the varance and get faster convergence we: Use mportance samplng: p should have smlar shape as f Use Stratfed samplng: Subdvde S nto smaller regons, evaluate the ntegral for each regon and sum these together