You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A unified format for shapes passed to all Estimators #1041
Currently, handling shapes is off-loaded to the DensityEstimator. Through knowledge of the condition_shape, the DensityEstimator then reshapes the data as needed here. This leads to code duplication (e.g. between zuko and nflows) and to confusion about where shapes should be handled.
In discussion with @manuelgloeckler and @janfb, we propose to define unified shapes for all methods of all DensityEstimator. In particular, all tensors that can correspond to theta or x should follow the following shape convention:
(batch_dim, iid_dim, event_dim)
Arranging shapes into this format is handled by the Inference, Posterior, or Potential classes.
I would suggest that we follow the conventions of torch_distributions if possible which are summarized in this blog post. From a naive reading, it looks to me like the proposed convention does not follow the conventions of torch_distributions.
How this would work if you had a conditional density estimator q_Y_X is as follows:
x is data shape [N, ..., D_x]
q_Y_x = q_Y_X.condition(x)
y = q_Y_x.sample(M)
y has shape [M, N, ..., D_y]
This is also how relevant libraries do it such as torch-mist.
... another example using multiple data from a single underlying parameter:
y is shape [C, ..., D_y]
p_X_y = p_X_Y.condition(y)
xs = p_X_y.sample(B)
xs is shape [B, C, ..., D_x]
In this case there are B i.i.d samples in dim 0 from the underlying C ys in dim 1.
Then, if you wanted to condition on them with an flexible estimator q_Y_X:
q_Y_xs = q_Y_X.condition(xs)
log_prob_q_y_xs = lambda y: q_Y_xs.log_prob(y).sum(0)
To me the torch_distributions convention makes sense because the dimensions get progressively less independent / identically distributed as you go from left to right.
fyi, I think it was agreed to use the torch_distributions format; however care must be taken. For example, a posterior with an embedding net that processes multiple x using the same theta may have an event_shape that includes i.i.d. draws of x... but that does not effect the convention that we report samples from posteriors, samples from likelihood, etc. in the torch_distribution format.
Activity
bkmi commentedon Mar 20, 2024
I would suggest that we follow the conventions of
torch_distributionsif possible which are summarized in this blog post. From a naive reading, it looks to me like the proposed convention does not follow the conventions oftorch_distributions.How this would work if you had a conditional density estimator q_Y_X is as follows:
x is data shape [N, ..., D_x]
q_Y_x = q_Y_X.condition(x)
y = q_Y_x.sample(M)
y has shape [M, N, ..., D_y]
This is also how relevant libraries do it such as torch-mist.
... another example using multiple data from a single underlying parameter:
y is shape [C, ..., D_y]
p_X_y = p_X_Y.condition(y)
xs = p_X_y.sample(B)
xs is shape [B, C, ..., D_x]
In this case there are B i.i.d samples in dim 0 from the underlying C ys in dim 1.
Then, if you wanted to condition on them with an flexible estimator q_Y_X:
q_Y_xs = q_Y_X.condition(xs)
log_prob_q_y_xs = lambda y: q_Y_xs.log_prob(y).sum(0)
To me the
torch_distributionsconvention makes sense because the dimensions get progressively less independent / identically distributed as you go from left to right.bkmi commentedon Mar 22, 2024
fyi, I think it was agreed to use the
torch_distributionsformat; however care must be taken. For example, a posterior with an embedding net that processes multiplexusing the samethetamay have anevent_shapethat includes i.i.d. draws ofx... but that does not effect the convention that we report samples from posteriors, samples from likelihood, etc. in thetorch_distributionformat.