Skip to content

Fix ICD formula for solved PDF in Importance Sampling (#1622) #1705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev-patch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


----------------------------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions books/RayTracingTheRestOfYourLife.html
Original file line number Diff line number Diff line change
Expand Up @@ -1310,15 +1310,15 @@

and

$$ P^{-1}(x) = \operatorname{ICD}(d) = 8d^\frac{1}{3} $$
$$ P^{-1}(x) = \operatorname{ICD}(d) = 2d^\frac{1}{3} $$

<div class='together'>
For just one sample we get:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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++
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/TheRestOfYourLife/integrate_x_sq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down