Marginalized PDFs
How to split a hemisphere's joint PDF into two 1D PDFs and use them to sample ϕ and θ.
Intro
-
Sometimes, it's useful to split a multi-dimensional PDF into lower-dimensional ones.
-
Like splitting a joint PDF $p(\omega) = p(\phi, \theta)$ into two individual PDFs $a(\phi)$ and $b(\theta)$.
-
These are called Marginalized PDFs.
-
With these marginalized PDFs, we will be able to sample $\phi$ and $\theta$ from each separately.
-
You can think of them like this: if $p(\omega)$ was the density of a point on the hemisphere, then $b(\theta)$ is the density of a whole ring of $\phi$'s when fixing $\theta$.
-
So when integrating over $b(\theta)$, we sum up those rings, getting the equivalent of the double integral on $p(\omega)$.
-
You may notice that this notion of "fixing a parameter and integrating the other" is exactly the same as that in iterated double integrals.
-
This is exactly what we'll be using to find the marginalized PDFs for $p(\omega) = f(\theta)$
Derivation
1. $b(\theta)$
- We get this first because it's easier.
- We need $b(\theta)$ where for all $\phi$:
$$P(\theta_1 \leq \theta \leq \theta_2) = \int_{\theta_1}^{\theta_2} b(\theta)\,d\theta$$
- Let's start with the full integral over a hemisphere
$$\iint_\omega f(\theta) d\omega$$ $$= \int_{\theta_1}^{\theta_2} \int_0^{2\pi} f(\theta)\sin\theta\,d\phi\,d\theta$$
- Our goal was the density function for a fixed $\phi$, which is the function that we integrate over $\phi$ to get the final joint probability.
- This is just the inner integral.
- The way this double integral works is that we integrate the inner integral over $\phi$ getting the joint probability, and it's fixed per $\phi$. Exactly what we need.
$$b(\theta) = \int_0^{2\pi} f(\theta)\sin\theta\,d\phi$$ $$= \bigg[f(\theta) \cdot \sin\theta \cdot \phi \bigg]_0^{2\pi}$$
$$= 2\pi \cdot f(\theta) \cdot \sin\theta \quad \blacksquare$$
2. $a(\phi)$
- We will do the same thing, but the other way around (fix $\phi$, iterate over $\theta$).
- Goal is $a(\phi)$ where for all $\theta$:
$$P({\phi_1} \leq \phi \leq {\phi_2}) = \int_{\phi_1}^{\phi_2} a(\phi)\,d\phi$$
- Let's start again with the full integral over a hemisphere, but this time, we will reverse the integration order:
$$I = \int_{\phi_1}^{\phi_2} \int_0^{\pi/2} f(\theta)\sin\theta\,d\theta\,d\phi$$
- Again, the inner integral is what we want. For a fixed $\phi$, the inner integral tells us the density of the entire arc from $0$ to $2\pi$.
- So:
$$a(\phi) = \int_0^{\pi/2} f(\theta)\sin\theta\,d\theta$$
-
Now, we don't know how to integrate this.
-
But we do know that the integrand does not depend on $\phi$ at all.
-
Which means $a(\phi)$ is just some constant $K$.
-
This makes total sense intuitively, because when the scattering function $f$ only depends on $\theta$, this means it protrudes symmetrically in a radial manner. So it's the same for all $\phi$ when fixing $\theta$.
-
Still, how do we evaluate this?
-
We know that:
$$\int_0^{2\pi} a(\phi)\,d\phi = 1$$
- Let's substitute $a(\phi)$ with $K$:
$$\int_0^{2\pi} K\,d\phi = K \cdot \big[\phi\big]_0^{2\pi} = K \cdot 2\pi$$
- Since we know this is just equal to 1:
$$K \cdot 2\pi = 1$$ $$a(\phi) = K = \frac{1}{2\pi} \quad \blacksquare$$
Conclusion
- For a 2D PDF $f(\theta)$ which only depends on $\theta$ (symmetric over $\phi$), the marginalized PDFs are:
$$a(\phi) = \frac{1}{2\pi}$$ $$b(\theta) = 2\pi \cdot f(\theta) \cdot \sin\theta$$
Sampling $\phi$ and $\theta$ Using the Marginalized PDFs
- Now we can use each of these marginalized PDFs to sample $\phi$ and $\theta$, ultimately sampling points on the hemisphere per the joint distribution $f(\theta)$.
1. $\phi$
-
Quick revision first: to sample from a distribution, we get the CDF by integrating the PDF, invert it which gives us the ICD (inverse cumulative distribution), then ICD(uniform random) finally gives us a random number following the distribution we care about.
-
Concretely, for a uniform random variable $r_1$, we get a random angle $\phi'$ sampled from the distribution of the CDF $F$ like this:
$$F^{-1}(r_1) = \phi'$$
- So:
$$r_1 = F(\phi')$$
-
Let's do that.
-
First, we get the CDF:
$$r_1 = F(\phi) = \int_{-\infty}^{\phi'} a(\phi)\,d\phi$$
- Since $a(\phi)$ is just $0$ before $\phi = 0$, we can just start from there:
$$r_1 = \int_{0}^{\phi'} a(\phi)\,d\phi$$
$$= \int_0^{\phi'} \frac{1}{2\pi}\,d\phi$$
$$= \frac{\phi'}{2\pi}$$
- Then finally:
$$\phi'(r_1) = 2\pi r_1$$
-
NOTE: no explicit "inversion" happened here, because we already inverted in the beginning when saying $r = F(\phi)$.
-
Now we just pass a uniform random variable between 0 and 1 in this function to get a random $\phi'$ between 0 and $2\pi$.
-
Intuitively, you may notice that this is perfectly linear (uniformly picks a number between 0 and $2\pi$), which makes sense because of the symmetry over $\phi$.
2. $\theta$
- CDF:
$$r_2 = F(\theta') = \int_0^{\theta'} b(\theta)\,d\theta$$ $$= 2\pi\int_0^{\theta'} f(\theta) \cdot \sin\theta\,d\theta$$
- Assuming we are uniform sampling over a hemisphere, then $p(\omega) = f(\theta) = \dfrac{1}{2\pi}$
- So:
$$r_2 = 2\pi\int_0^{\theta'} \frac{1}{2\pi} \cdot \sin\theta\,d\theta$$ $$= \int_0^{\theta'} \sin\theta\,d\theta$$ $$= -\cos\theta' + 1$$
- Finally:
$$\cos\theta' = 1 - r_2$$
- This is not exactly a function like $\theta'(r_2)$ and we can definitely solve for $\theta'$, but $\operatorname{arccos}$ calls are unnecessary as we usually just need an explicit $\cos$ in our calculations.
- We'll be seeing that in the next step.
Converting $(\phi, \theta)$ to $(x, y, z)$
- We already know the mapping from basic trig:
$$x = \cos\phi\cdot\sin\theta$$ $$y = \sin\phi\cdot\sin\theta$$ $$z = \cos\theta$$
- With some substitutions you will be able to find $x$, $y$, and $z$ in terms of $r_1$ and $r_2$. I might write them later.