Closed nwaftp23 closed 2 years ago
From my understanding to sample from a normalizing flow you sample the base distribution and then push that forward through the transformations, but it seems you have decided to use the inverse.
What to define as a "forward" pass of a transformation is an arbitrary choice. We can define (as you suggest) that $x = f(z)$, but it makes no less sense to define $z = f(x)$. In fact, the latter definition (one that we use in nflows
) is better aligned with the "normalizing" part of the "normalizing flow": the transformation $f$ normalizes the input distribution, i.e. transforms it into a standard normal.
As to your question, if you want the samples from your flow to lie in $[-1, 1]$, you simply need to use an inverse of Tanh
(InverseTransform(Tanh())
) as the first step of your flow. Alternatively, if it's easier for you to think in terms of $x = f(z)$, you can first define a transformation $f^{-1}$, and then wrap it in InverseTransform
before passing to Flow
. Note that for some transformations the forward and the inverse pass don't have the same computational cost, so you'd need to be a bit careful with my latter suggestion.
Hope this helps.
Hi,
From my understanding to sample from a normalizing flow you sample the base distribution and then push that forward through the transformations, but it seems you have decided to use the inverse. I would like the output of my flow to be bounded by [-1,1] and therefore apply a tanh transformation at the end of my transforms list. Though I am not getting the behavior I expect. I was hoping you could clarify what is meant by forward and inverse in the code.
Best, Lucas