Normalizing flow training I've been learning about normalizing flow. This is my understanding, and please correct me whenever I am wrong.
There are $\{y_1,y_2,...,y_n\}$ samples from an unknown distribution $p_y(y)$ that we wish to learn. We can consider a distribution that is well-known such as Gaussian with density $p_y(x)$. Then, the goal of normalizing flow is to find a $f_{\theta}$ with parameters $\theta$ such that $Y=f_{\theta}(X)$. To find $p_y(y)$ or $\log (p_y(y))$ we need to employ the change of variable formula, namely:
$$
\log(p_y(y))=\log(p_x(f_{\theta}^{-1}(y)))-\log\left|\dfrac{dg}{dx} \right |=\log(p_x(x))-\log\left|\dfrac{df_{\theta}}{dx} \right |
$$
I know that maximum likelihood estimation is used to find $\theta$. However, I am not sure exactly how that works. I'd appreciate if someone could show me some details on that. The examples I've seen online usually just use a python library and details are not included.
*Edit: my question was: how are the data points $\{y_1,y_2,...,y_n\}$ exactly used to the gradient ascent on the likelihood function?
 A: Overview.
You're familiar with MLE, which is a good starting point. We have a parametric model whose parameters $\theta$ we seek to optimize, in order to maximize the likelihood of our model $L(\theta \mid \{y_1,y_2,...,y_n\}) = p_Y(\{y_1,y_2,...,y_n\} \mid \theta)$. Gradient-based methods are one way to do the optimization.
It's no different with normalizing flows: we're trying to maximize the likelihood.  The transformation $f$ has some parameters $\theta$ that we seek to optimize, possibly with gradient ascent. (The prior distribution on $x$, $p_X$, may have its own parameters $\phi$ to learn. Or we could just declare it to be a standard Gaussian with the same dimension as $Y$ or something. This means that only $f$ has learnable parameters.) These parameters are just like any other.

About $f$.
The transformation $f$ must have three important properties that we will use in a moment. It is deterministic; it is invertible; and it has an easily computable, easily differentiable determinant of the Jacobian. Some example functions satisfying these requirements are here.

Computing the likelihood.
Mechanically, how would you compute $p_Y(y_i \mid \theta)$? Remember that $p_Y(y_i \mid \theta) = p_X\left(f^{-1}_\theta(y_i)\right) \cdot \left|\det \left(\frac{\mathrm{d}f^{-1}_\theta}{\mathrm{d}x}\right)\right|$. (Your question was missing the $\det$.)

*

*Apply the inverse transform of your observed variable $y_i$ to compute the latent variable $x_i = f^{-1}_\theta(y_i)$.

*Compute the probability density $p_X(x_i)$.

*Compute the $\left|\det \left(\frac{\mathrm{d}f^{-1}_\theta}{\mathrm{d}x}\right)\right|$ term. This is easy because of the functional form we chose.

*Multiply these terms to get the likelihood.


Learning $\theta$.
To actually learn $\theta$ with gradient descent requires finding and following the gradient. I'll suggest a way assuming you're working in a computing toolkit that supports reverse-mode automatic differentiation (back-propagation). There are other options as well; heck, you could define the gradients by hand if you hate yourself want to.


*Backpropagate from the negative log of the likelihood to compute gradients with respect to $\theta$.

*Adjust $\theta$ by taking a step in the direction down the gradient.

