Normalizing flow with a truncated support #41
-
Running the following lines
I got a Plus, I wanted to truncate the
Running the code above I got
I am new in normalization flows so I don't know how to correct this. Any help is appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Hello, I guess that you want to define a multivariate truncated normal. class LazyDiagTruncatedNormal(zuko.flows.LazyDistribution):
def __init__(self, features: int, lower: float = -1.0, upper: float = 1.0):
super().__init__()
self.register_buffer('loc', torch.zeros(features))
self.register_buffer('scale', torch.ones(features))
self.register_buffer('lower', torch.as_tensor(lower))
self.register_buffer('upper', torch.as_tensor(upper))
def forward(self, c: Tensor = None):
return Independent(Truncated(Normal(self.loc, self.scale), self.lower, self.upper), 1)
model.base = LazyDiagTruncatedNormal(3) I don't know why you want a truncated base distribution, but I should warn you that evaluating the |
Beta Was this translation helpful? Give feedback.
-
Thanks for your immediate reply! After reading the documentation, I'm still not very sure about the usage of many classes because I'm just learning normalization flows. What I want to achieve exactly is a snippet of initializing an I'm learning to use |
Beta Was this translation helpful? Give feedback.
-
Have you checked the Learn the basics tutorial and in particular the parametrization section? It is explained there why
What do you mean by a "truncated flow"? The support of the distribution defined by the flow should be limited to some interval (hyper-cube)? |
Beta Was this translation helpful? Give feedback.
Yes exactly, lazy refers to the fact that the actual distribution/transformation is lazily built when needed.
Ok! This is partially answered in #10, but the answer is a bit outdated. You are right, you can do that by adding a transformation to the flow. However, you should think about the kind of transformation to add and where to add it.
So first, what kind of transformation? Normalizing flows like$\mathbb{R}$ . So if you want features that are in $[a, b]$ , you need a transformation that maps $\mathbb{R} \mapsto [a, b]$ …
MAF
orNSF
work in