From 0a66e043c5f08177a2ac1975d807e154c72ee18b Mon Sep 17 00:00:00 2001
From: mikoff
What this formula states is that any density $g(y)$ can be obtained from a fixed density $f(x)$.
Suppose that $Y = a + bX$, $a \in \mathcal{R}$ and $b \in \mathcal{R} \backslash {0}$, the distribution of $X$ is known: $f(x)$. What is the pdf of $Y$?
Since $r(x) = y = a + bx$, we can find inverse function to be $r^{-1}(y) = x = \frac{y - a}{b}$ and the derivative $\frac{dx}{dy} = \frac{1}{b}$.
Then $g(y) = f(\frac{y - a}{b})\frac{1}{|b|}$.
Suppose that $f(x) = 2 x, x \in [0, 1)$ and $y(x) = x^2$.
First, derive the inverse of the function $x(y) = \sqrt{y}$.
Now, having:
$$
-f(x(y)) = 2 \sqrt{y} \frac{dx}{dy} = \frac{1}{2\sqrt{y}}
+\begin{align}
+f(x(y)) = 2 \sqrt{y}~\text{and}~ \frac{dx}{dy} = \frac{1}{2\sqrt{y}}
+\end{align}
$$
we can find $g(y)$ to be:\text{and}
$$ g(y) = f(x(y)) \left|\frac{dx}{dy}\right| = 2 \sqrt{y} \frac{1}{2\sqrt{y}} = 1. @@ -54,7 +56,9 @@ # print(sp.latex(x_y), sp.latex(dx_dy))
After solving for $y$ and finding the derivative we got:
$$
-x(y) = \log{\left(- \frac{y}{y - 1.0} \right)} + 5.0 \frac{dx}{dy} = -\frac{1.0}{y \left(y - 1\right)}
+\begin{align}
+x(y) = \log{\left(- \frac{y}{y - 1.0} \right)} + 5.0 ~\text{and}~ \frac{dx}{dy} = -\frac{1.0}{y \left(y - 1\right)}
+\end{align}
$$\text{and}
import sympy.stats
@@ -113,18 +117,18 @@
ax2.grid(axis='both')
For the next example, let’s consider coordinate transform.
The polar coordinate transforms two numbers $(r, \theta)$, where radial distance $r \in [0, \inf)$ and polar angle $\theta \in [0, 2\pi)$ to a point on a plane. $$ -\begin{eqnarray} +\begin{align} x = r \cos{\left(\theta \right)} \\ y = r \sin{\left(\theta \right)} -\end{eqnarray} +\end{align} $$
Evaluating the derivatives we get: $$ -\begin{eqnarray} +\begin{align} \frac{\partial x}{\partial r} &= \cos(\phi) \\ \frac{\partial x}{\partial \phi} &= - r \sin(\phi) \\ \frac{\partial y}{\partial r} &= \sin(\phi) \\ \frac{\partial x}{\partial \phi} &= r \cos(\phi) -\end{eqnarray} +\end{align} $$
We can view this transformation as a multivariate change of variables. In such a case instead of $\frac{dx}{dy}$ we use the determinant of Jacobian ($\mathbf{J}$) that describes how the volume changes under the transformation.
Now, if we sample a polar coordinate $(r, \theta)$ with probability $f(r, \theta)$, then the distribution $g(x, y)$ is given by: $$ g(x, y) = \frac{f(r, \theta)}{\det\mathbf{J}} = \frac{f(r, \theta)}{r}.