Rendering: Monte Carlo Integration I
Bernhard Kerbl
Research Division of Computer Graphics Institute of Visual Computing & Human-Centered Technology TU Wien, Austria
With slides based on material by Jaakko Lehtinen, used with permission
Rendering: Monte Carlo Integration I Bernhard Kerbl Research - - PowerPoint PPT Presentation
Rendering: Monte Carlo Integration I Bernhard Kerbl Research Division of Computer Graphics Institute of Visual Computing & Human-Centered Technology TU Wien, Austria With slides based on material by Jaakko Lehtinen, used with
With slides based on material by Jaakko Lehtinen, used with permission
Rendering β Monte Carlo Integration I 2
Rendering β Monte Carlo Integration I 3
Rendering β Monte Carlo Integration I 4
Rendering β Monte Carlo Integration I 5
2 3 π¦2 3
π¦2 2 + π
Rendering β Monte Carlo Integration I 6
Rendering β Monte Carlo Integration I 7
Rendering β Monte Carlo Integration I 8
Ξπ¦ π(π¦)
Rendering β Monte Carlo Integration I 9
Ξπ¦ π(π¦)
Rendering β Monte Carlo Integration I 10
π(π¦) Ξπ¦
Rendering β Monte Carlo Integration I 11
π(π¦) Ξπ¦ = ππ¦
Rendering β Monte Carlo Integration I 12
π§ π¦ 1 1
Rendering β Monte Carlo Integration I 13
π§ π¦ 1 1
Rendering β Monte Carlo Integration I 14
Rendering β Monte Carlo Integration I 15
Rendering β Monte Carlo Integration I 16
Rendering β Monte Carlo Integration I 17
Rendering β Monte Carlo Integration I 18
Rendering β Monte Carlo Integration I 19
Rendering β Monte Carlo Integration I 20
π§ π¦ 1 1 π(π¦)
Rendering β Monte Carlo Integration I 21
π§ π¦ 1 π(π¦)
Rendering β Monte Carlo Integration I 22
π¦ 1 π0 π0 π0 π0 π1 π1 π1 π3 π2 π2 π¦ 1 π0 π1 π3 π2
Rendering β Monte Carlo Integration I 23
Rendering β Monte Carlo Integration I 24
Rendering β Monte Carlo Integration I 25
Rendering β Monte Carlo Integration I 26
Rendering β Monte Carlo Integration I 27
Rendering β Monte Carlo Integration I 28
1 π(π¦)
1
π0 π0 π0 π0 π1 π1 π1 π3 π2 π2
Rendering β Monte Carlo Integration I 29
Rendering β Monte Carlo Integration I 30
const size_t NUM_SAMPLES = 10'000; std::array<double, NUM_SAMPLES> exponential_samples{}; std::array<double, NUM_SAMPLES> uniform_samples{}; std::array<double, NUM_SAMPLES> warped_samples{}; void inversionDemo() { const double LAMBDA = 5.0; std::default_random_engine rand_eng_uniform(0xdecaf); std::default_random_engine rand_eng_exponential(0xcaffe); std::uniform_real_distribution<double> uniform_dist(0.0, 1.0); std::exponential_distribution<double> exponential_dist(LAMBDA); for (int i = 0; i < NUM_SAMPLES; i++) { auto R_i = exponential_dist(rand_eng_exponential); exponential_samples[i] = R_i; // uniform distribution: CDF(x) = x auto x_ = uniform_samples[i] = uniform_dist(rand_eng_uniform); auto X_i = -std::log(1.0 - x_) / LAMBDA; warped_samples[i] = X_i; } }
Rendering β Monte Carlo Integration I 31
π β1 ππ
Rendering β Monte Carlo Integration I 32
const size_t NUM_SAMPLES = 10'000; std::array<double, NUM_SAMPLES> exponential_samples{}; std::array<double, NUM_SAMPLES> uniform_samples{}; std::array<double, NUM_SAMPLES> warped_samples{}; void inversionDemo() { const double LAMBDA = 5.0; std::default_random_engine rand_eng_uniform(0xdecaf); std::default_random_engine rand_eng_exponential(0xcaffe); std::uniform_real_distribution<double> uniform_dist(0.0, 1.0); std::exponential_distribution<double> exponential_dist(LAMBDA); for (int i = 0; i < NUM_SAMPLES; i++) { auto R_i = exponential_dist(rand_eng_exponential); exponential_samples[i] = R_i; // uniform distribution: CDF(x) = x auto x_ = uniform_samples[i] = uniform_dist(rand_eng_uniform); auto X_i = -std::log(1.0 - x_) / LAMBDA; warped_samples[i] = X_i; } }
This is actually the implementation in many standard libraries anyway
Rendering β Monte Carlo Integration I 33
Rendering β Monte Carlo Integration I 34
Rendering β Monte Carlo Integration I 35 0,1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 1 0,2 0,4 0,6 0,8 1 1,2 1,4 1,6 1,8
Y X void inversionDemo2D() { std::default_random_engine x_rand_eng(0xdecaf); std::default_random_engine y_rand_eng(0xcaffe); std::uniform_real_distribution<double> uniform_dist; for (int i = 0; i < NUM_SAMPLES; i++) { auto x_ = uniform_dist(x_rand_eng); auto y_ = uniform_dist(y_rand_eng); auto X_i = x_; auto Y_i = asin(y_); samples2D[i] = std::make_pair(X_i, Y_i); } }
Rendering β Monte Carlo Integration I 36 0,1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 1 0,1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 1
Y X std::array<std::pair<double, double>, NUM_SAMPLES> samples2D{}; void inversionDemo2D() { std::default_random_engine x_rand_eng(0xdecaf); std::default_random_engine y_rand_eng(0xcaffe); std::uniform_real_distribution<double> uniform_dist; for (int i = 0; i < NUM_SAMPLES; i++) { // uniform distribution: CDF(x) = x auto x_ = uniform_dist(x_rand_eng); auto y_ = uniform_dist(y_rand_eng); auto X_i = sqrt(x_); auto Y_i = sqrt(y_); samples2D[i] = std::make_pair(X_i, Y_i); } }
Rendering β Monte Carlo Integration I 37
Rendering β Monte Carlo Integration I 38 0,5 1 1,5 2 2,5 3 3,5 4 0,5 1 1,5 2 2,5 3 3,5 4
Y X
Rendering β Monte Carlo Integration I 39
Rendering β Monte Carlo Integration I 40 2 2,2 2,4 2,6 2,8 3 3,2 3,4 3,6 3,8 4 2 2,5 3 3,5 4
Y X
Rendering β Monte Carlo Integration I 41
Rendering β Monte Carlo Integration I 42
Rendering β Monte Carlo Integration I 43
Rendering β Monte Carlo Integration I 44
Rendering β Monte Carlo Integration I 45
Rendering β Monte Carlo Integration I 46 0,1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 1 0,1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 1
2D Variables with Linear PDFs
Rendering β Monte Carlo Integration I 47
Rendering β Monte Carlo Integration I 48 0,1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 1 0,1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 1
2D Variables with Linear PDFs
0,1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 1 0,1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 1
Canonic Uniform Variables
Rendering β Monte Carlo Integration I 49
Rendering β Monte Carlo Integration I 50
Rendering β Monte Carlo Integration I 51
Rendering β Monte Carlo Integration I 52
Rendering β Monte Carlo Integration I 53
π(π¦) π¦
Rendering β Monte Carlo Integration I 54
π(π¦) π¦ The integral computed from these samples will vastly underestimate the true value!
Rendering β Monte Carlo Integration I 55
Rendering β Monte Carlo Integration I 56
Rendering β Monte Carlo Integration I 57
Rendering β Monte Carlo Integration I 58
Rendering β Monte Carlo Integration I 59
π(π¦) π π
Rendering β Monte Carlo Integration I 60
Rendering β Monte Carlo Integration I 61
π¦ π(π¦) π¦ π(π¦)
Rendering β Monte Carlo Integration I 62
π¦ π(π¦) π¦ π(π¦)
1 π ΰ·
π=1 π π(ππ)
π(ππ) πππ(πΈ) π ΰ·
π=1 π
π(ππ)
Rendering β Monte Carlo Integration I 63
π¦ π(π¦) π¦ π(π¦)
1 π ΰ·
π=1 π π(ππ)
π(ππ) πππ(πΈ) π ΰ·
π=1 π
π(ππ)
Final word: During Monte Carlo integration, we use
1 π π¦ π from the start as the Ξπ¦, so that
Ξπ¦ β π(π¦) gives us an area under the curve. The more samples π we take, the closer the distance between the two closest samples near a point π¦ gets to
1 π π¦ π and the better the
approximation of the true integral, i.e., the sum of infinitesimal areas under the curve.
Rendering β Monte Carlo Integration I 64
π=1 π π ππ
π=1 π
π=1 π
πΈ
π1 π
πΈ
πΈ
Rendering β Monte Carlo Integration I 65
Rendering β Monte Carlo Integration I 66
Rendering β Monte Carlo Integration I 67
Rendering β Monte Carlo Integration I 68
Rendering β Monte Carlo Integration I 69
Rendering β Monte Carlo Integration I 70
Rendering β Monte Carlo Integration I 71
Rendering β Monte Carlo Integration I 72