Understanding uncertainty in conditional distributions #79
-
|
Dear all, thanks for providing such a great library. If I want to use flows, I resort to zuko these days. Really excellent code and quality of implementation. I currently am struggling to train an NSF flow on a particular problem. Here is a surrogate code to illustrate the data: num_dims = 3
hoffset = .25
hscale = .8
hprior = torch.distributions.Uniform(low=hoffset+torch.zeros(num_dims),
high=hoffset + (torch.ones(num_dims)*hscale)
)
htheta = hprior.sample((num_training_samples,)).to(device) #our condition later on
htheta *= (1 + .05*torch.randn_like(htheta)) #add more noise, can be removed if need be
# (optional) set to 0 for an even simpler simulator
# we shift by quite some
hard_shift = torch.arange(1,num_dims+1).to(device)
hx = htheta + hard_shift + torch.randn_like(htheta)*torch.sqrt(hard_cov*torch.ones(3))My goal is to learn hflow = zuko.flows.NSF(features=3, context=3, transforms=6, hidden_features=[256]).to(device)
for step in range(5_000):
#load batches of htheta -> htheta_, hx -> hx_
hloss = -hflow(htheta_).log_prob(hx_) # -log p(hx|htheta)
hloss = hloss.mean()
hlosses[hep] = hloss.item()
hloss.backward()
hoptimizer.step()
hoptimizer.zero_grad()However, the flow doesn't really learn too well. So I am wondering about the cause? Should I normalize the two datasets with min-max scaling or potentially z-scaling (mean, std) before training? Or should I normalize only x because it is clearly outside of What are people's thoughts and experiences? Cheers, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
Hi Peter, Thank you for the kind words! Could you tell me what The last thing would be: have you tried with MAF instead of NSF? The former is less powerful but also more forgiving. |
Beta Was this translation helpful? Give feedback.



Hi @psteinb, after looking at the data generation code, I can say a few things. First, the distribution of$x$ overlaps greatly for very different values of $\theta$ .
This means that given a single reference$x_+$ , many $\theta$ are plausible and we should expect $q(\theta | x_+)$ to be very wide (almost the prior distribution). In addition, it also means that even if samples $\bar{\theta} \sim q(\theta | x_+)$ are close to the ground-truth $\theta_+$ , $p(x | \bar{\theta})$ will be wide too. The posterior predictive $q(x | x_+)$ combines these two sources of uncertainty, and is therefore even wider.
So the issue here is not with NSF, or MAF, or any model, but the data process itself that…