|
61 | 61 | programs, then it'll be good to pause and catch you up. There are two kinds of randomized
|
62 | 62 | algorithms: Monte Carlo and Las Vegas. Randomized algorithms can be found everywhere in computer
|
63 | 63 | graphics, so getting a decent foundation isn't a bad idea. A randomized algorithm uses some amount
|
64 |
| -of randomness in its computation. A Las Vegas (LV) random algorithm always produces the correct |
65 |
| -result, whereas a Monte Carlo (MC) algorithm _may_ produce a correct result--and frequently gets it |
66 |
| -wrong! But for especially complicated problems such as ray tracing, we may not place as huge a |
67 |
| -priority on being perfectly exact as on getting an answer in a reasonable amount of time. LV |
68 |
| -algorithms will eventually arrive at the correct result, but we can't make too many guarantees on |
69 |
| -how long it will take to get there. The classic example of an LV algorithm is the _quicksort_ |
70 |
| -sorting algorithm. The quicksort algorithm will always complete with a fully sorted list, but, the |
71 |
| -time it takes to complete is random. Another good example of an LV algorithm is the code that we use |
| 64 | +of randomness in its computation. A Las Vegas random algorithm always produces the correct result, |
| 65 | +whereas a Monte Carlo algorithm _may_ produce a correct result--and frequently gets it wrong! But |
| 66 | +for especially complicated problems such as ray tracing, we may not place as huge a priority on |
| 67 | +being perfectly exact as on getting an answer in a reasonable amount of time. Las Vegas algorithms |
| 68 | +will eventually arrive at the correct result, but we can't make too many guarantees on how long it |
| 69 | +will take to get there. The classic example of a Las Vegas algorithm is the _quicksort_ sorting |
| 70 | +algorithm. The quicksort algorithm will always complete with a fully sorted list, but, the time it |
| 71 | +takes to complete is random. Another good example of a Las Vegas algorithm is the code that we use |
72 | 72 | to pick a random point in a unit sphere:
|
73 | 73 |
|
74 | 74 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
|
84 | 84 |
|
85 | 85 | This code will always eventually arrive at a random point in the unit sphere, but we can't say
|
86 | 86 | beforehand how long it'll take. It may take only 1 iteration, it may take 2, 3, 4, or even longer.
|
87 |
| -Whereas, an MC program will give a statistical estimate of an answer, and this estimate will get |
88 |
| -more and more accurate the longer you run it. Which means that at a certain point, we can just |
| 87 | +Whereas, a Monte Carlo program will give a statistical estimate of an answer, and this estimate will |
| 88 | +get more and more accurate the longer you run it. Which means that at a certain point, we can just |
89 | 89 | decide that the answer is accurate _enough_ and call it quits. This basic characteristic of simple
|
90 |
| -programs producing noisy but ever-better answers is what MC is all about, and is especially good for |
91 |
| -applications like graphics where great accuracy is not needed. |
| 90 | +programs producing noisy but ever-better answers is what Monte Carlo is all about, and is especially |
| 91 | +good for applications like graphics where great accuracy is not needed. |
92 | 92 |
|
93 | 93 |
|
94 | 94 | Estimating Pi
|
|
0 commit comments