Skip to content

A unified format for shapes passed to all Estimators #1041

Closed

Description

@michaeldeistler

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.

Activity

  1. added
    enhancement
    on Mar 19, 2024
  2. bkmi commented on Mar 20, 2024

    @bkmi
    Contributor

    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.

  3. bkmi commented on Mar 22, 2024

    @bkmi
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions