Hi and welcome to a video about MonteCarlo simulations,a type of simulation that i really enjoybecauseit's a super simple concept and it stillallows to solveincredibly complex problems. So afterwatching this video you will knowexactly what Monte Carlo simulations areand what types of problems you can solvewith them.So what are Monte Carlo simulations? Wellthe name Monte Carlo actually refers tothecity in Monaco which is known for itscasinos and gambling,and in the context of simulations "MonteCarlo" is basically used as a synonym forrandomness, like the randomness ingambling.So, Monte Carlo simulations aresimulations evolvingrandomly, and this might seemcounterintuitive at first becausehow can something useful come out of arandomly evolving simulation?but we will see why randomness can beactually very useful in a simulation injust a moment.So let's take a look at the firstexample.In the simulation we have a sort ofmarble dropping devicethat moves around randomly above thisrectangular tableand drops marbles, and on the table thereare two bowlsone with a square cross section and onewith a circular cross section,and each of these bowls is placed onsome sort of scalewhich displays how many marbles are ineach bowlat this time, and if we let thesimulation evolve for a whileand then divide the number of marbles inthe circular bowlby the number of marbles in the squarebowl the result happens to beroughly pi. Without any advanced mathknowledge,simply by randomly dropping marbles intotwo bowls,we can estimate pi. Okay so let's unpackwhat happened in this simple example ofa Monte Carlo simulation.When we drop a marble in a uniformlyrandom locationthen the probability for this marble toend up in one of the bowlsis proportional to the bowlscross-section area,and if we repeat this process over andover againthen also the number of marbles endingup in this bowlwill be proportional to the bowl'scross-section area.The area of the square bowl in thisexample isits edge length a squared and the areaof the circular bowl ispi times a squared, and that's how we getpias the fraction of the two areas andconsequently asthe fraction of marbles in each bowl.So in this example of a monte carlosimulation, we essentially determine anarea by taking random samples.With each random sample we probe whetherthis specific location isinside or outside of some area, and bytaking enough sampleswe get a good idea of how big an area is.This idea of obtaining random samplesis probably quite familiar to you if youthink about howreal world studies are designed. Let'ssay we wanted to find outthe average height of all peopleworldwide.Then, in principle we would need tomeasure the height ofeach person worldwide, and then take theaverage to get an accurate result,but of course we can't go out andmeasure the height of billions of people.So what can we do? Well we can measurethe height ofsome smaller group of people, and hopethat their average heightis a good estimate for the averageheight of all people worldwide,but there are two things that we need toconsider. Firstlythe selection of the group of peopleneeds to beunbiased. We can't just measure theheight of the next five people we meetas we might live in an area withespecially tall or short people.A better way to get an unbiased samplegroupwould be to randomly select peopleworldwide.Randomness helps us to make an unbiasedselection.Secondly, the group of measuredpeople must not betoo small. If we only measure the heightof let's sayfive people we might have justcoincidentally picked five taller orshorter people,and we can be more and more confidentabout the average heightthe more people we measure. Inprobability theory this is calledthe "law of large numbers" whichessentially states thatan average tends to come closer to itsexpected valuethe more samples we have, and the exactsame is also true for Monte Carlosimulations. The core idea of a MonteCarlo simulation is that we canget an unbiased, representative group ofsamplesfrom some large ocean of possibilitiesif we allow the simulation to evolverandomly. In the marble dropping example,in principle we would need to test forevery possible locationwhether a marble ends up inside oroutside the bowlto determine the bowl's cross-sectionarea precisely,just like we in principle would need tomeasure the height of each personworldwideto determine the average heightaccurately.Instead, we can rely on randomlyselected samples, and according to thelaw of large numberswe can be more and more confident aboutthe resultthe more samples we take. We can see thisif we plotthe fraction of marbles in both bowlsover time.Initially, the value is fluctuatingheavily,but with more and more samples generatedby the randomly evolving simulation,the fluctuations become smaller andsmaller, and we can see thatthe fraction approaches the expectedvaluepiNow I hope that using a Monte Carlosimulation to determine piwas an illustrative example, but it'scertainly not really relevant,but actually this animation of droppingmarbleshas a second example of a monte carlosimulation somewhathidden in it. So let's take a look atthis hidden more relevant example of aMonte Carlo simulation in the last partof this video.Rendering such animations or the simplerexample sceneis all about simulating the flow oflight, and to get an accurate image youneed to find outhow much light hits different areas ofthe scene.This is not an easy task if youconsider thatdiffuse surfaces can scatter light invirtually any direction.So let's say we want to find out howmuch light hitsthis marked area. Then, in principle wewould need to evaluateall possible light paths to find outwhich fraction of themends up in the marked area. Now clearlyit'simpossible to follow all the possiblelight paths.So what can we do if we can't follow allpossible paths?Well I hope that after watching thevideo to this point,the answer is quite obvious. If we can'tsimulateall possible light paths then the bestwe can do is tosimulate a representative group ofsample paths, and what is a good way toget anunbiased representative group of samples?We can employ randomness! Sowhenever we hit a diffuse surface wesimply pick,randomly, one of the infinitely manydirectionsin which the light could be scattered.One randomly simulated light path on itsownis not valuable, but if we generate manysample pathsthen we get a good idea of theillumination of the scene.We will see areas that are hit by manyof the randomly generated light rays(brighter areas) and we'll see other areasthat are hit only by few of the randomlygenerated rays(darker areas). Actually if you think aboutit,counting the number of randomlygenerated light rayshitting some area is really not thatdifferent fromcounting the number of randomly droppedmarbleshitting some bowl, and in this marbledroppingattempt to determine pi we saw that theresult gets moreaccurate the more samples we take, andthe same is also true forMonte Carlo path tracing. These fourimagesshow the same scene rendered with adifferent number ofrandomly simulated light paths. Wecan clearly seethat with more sampled paths the resultbecomesmore accurate, leading to a less noisyimage.Okay so let's wrap this up. A Monte Carlosimulation is a randomly evolvingsimulation,and in this video we have looked at twoexamples how such a randomly evolvingsimulation can be useful. We havedetermined pi by randomly droppingmarbles into bowls,and we have simulated the flow of lightby generating random light paths.Both these examples and many otherexamples whereMonte Carlo simulations are useful, theyhave one thing in common.They involve an unfeasibly large numberof possibilities,and instead of trying to go through allthese possibilities,with monte carlo simulations wedeliberately only explorea random subset of them, and according tothe law of large numbers we can stillget away with these random samplesif we only gather enough of them.Okay so that's it for this video.I hope you found it useful. If you did,please leave a likeand maybe subscribe and i hope to seeyou in the next video! Bye.you