From 8d2fe1c365a033799e97b0e27682e8a4ba3618d2 Mon Sep 17 00:00:00 2001 From: Sean Payne Date: Sun, 11 May 2025 10:32:17 -0700 Subject: [PATCH 1/3] Fix ICD formula for solved PDF in Importance Sampling (#1622) --- CHANGELOG.md | 1 + books/RayTracingTheRestOfYourLife.html | 4 ++-- src/TheRestOfYourLife/integrate_x_sq.cc | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7bb82d5..8ac47c00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Change Log / Ray Tracing in One Weekend - Fix -- Remove premature source line for call to `get_sphere_uv` (#1701) ### The Rest of Your Life + - Fix -- Fix ICD formula for solved PDF in Importance Sampling (#1622) ---------------------------------------------------------------------------------------------------- diff --git a/books/RayTracingTheRestOfYourLife.html b/books/RayTracingTheRestOfYourLife.html index 5af3fc0a..ded8155d 100644 --- a/books/RayTracingTheRestOfYourLife.html +++ b/books/RayTracingTheRestOfYourLife.html @@ -1362,8 +1362,8 @@ nonuniform PDF is usually called _importance sampling_. In all of the examples given, we always converged to the correct answer of $8/3$. We got the same -answer when we used both a uniform PDF and the "correct" PDF (that is, $\operatorname{ICD}(d) = -8d^{\frac{1}{3}}$). While they both converged to the same answer, the uniform PDF took much longer. +answer when we used both a uniform PDF and the solved PDF (that is, $p(r) = +\frac{3}{8}r^2$). While they both converged to the same answer, the uniform PDF took much longer. After all, we only needed a single sample from the PDF that perfectly matched the integral. This should make sense, as we were choosing to sample the important parts of the distribution more often, whereas the uniform PDF just sampled the whole distribution equally, without taking importance into diff --git a/src/TheRestOfYourLife/integrate_x_sq.cc b/src/TheRestOfYourLife/integrate_x_sq.cc index e680d553..7b95affe 100644 --- a/src/TheRestOfYourLife/integrate_x_sq.cc +++ b/src/TheRestOfYourLife/integrate_x_sq.cc @@ -16,7 +16,7 @@ double icd(double d) { - return 8.0 * std::pow(d, 1.0/3.0); + return 2.0 * std::pow(d, 1.0/3.0); } From dc11df909ecab8869f1478488df8a250ee8f4725 Mon Sep 17 00:00:00 2001 From: Sean Payne Date: Sun, 11 May 2025 11:23:53 -0700 Subject: [PATCH 2/3] update inline example code --- books/RayTracingTheRestOfYourLife.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/books/RayTracingTheRestOfYourLife.html b/books/RayTracingTheRestOfYourLife.html index ded8155d..8c843f7a 100644 --- a/books/RayTracingTheRestOfYourLife.html +++ b/books/RayTracingTheRestOfYourLife.html @@ -1318,7 +1318,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ double icd(double d) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight - return 8.0 * std::pow(d, 1.0/3.0); + return 2.0 * std::pow(d, 1.0/3.0); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ } From d528400048e0ac85f775f7ded65d8c4b9f8779b2 Mon Sep 17 00:00:00 2001 From: Sean Payne Date: Sun, 11 May 2025 11:25:39 -0700 Subject: [PATCH 3/3] update topmost ICD --- books/RayTracingTheRestOfYourLife.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/books/RayTracingTheRestOfYourLife.html b/books/RayTracingTheRestOfYourLife.html index 8c843f7a..704a611e 100644 --- a/books/RayTracingTheRestOfYourLife.html +++ b/books/RayTracingTheRestOfYourLife.html @@ -1310,7 +1310,7 @@ and - $$ P^{-1}(x) = \operatorname{ICD}(d) = 8d^\frac{1}{3} $$ + $$ P^{-1}(x) = \operatorname{ICD}(d) = 2d^\frac{1}{3} $$
For just one sample we get: