Skip to content

Shape conventions for all DensityEstimators - #1066

Merged
michaeldeistler merged 1 commit into
mainfrom
useshapes
Apr 9, 2024
Merged

michaeldeistler merged 1 commit into
mainfrom
useshapes

Conversation

@michaeldeistler

@michaeldeistler michaeldeistler commented Mar 20, 2024 •

Copy link
Copy Markdown
Contributor

Shape conventions for the DensityEstimator

All density estimators now have a unified format of their input and output shapes.

  • input must have shape (sample_dim: int, batch_dim: int, *event_shape: Tuple[int])
  • condition must have shape (batch_dim: int, *event_shape: Tuple[int])
  • batch_dim of input and condition must be the same for log_prob.

API

density_estimator.log_prob(input, condition)

input: (sample_input, batch_input, *event_shape_input)
condition: (batch_condition, *event_shape_condition)
returns: (sample_input, batch_input)
raises: batch_input != batch_condition

density_estimator.sample(sample_shape, condition)

sample_shape: (*sample_shape)
condition: (batch_condition, *event_shape_condition)
returns: (*sample_shape, batch_condition, *event_shape_input)

Examples

density_estimator.log_prob(input, condition)

(1, 1, 3), (1, 6) -> (1, 1)
(1, 5, 3), (5, 6) -> (1, 5)
(10, 5, 3), (5, 6) -> (10, 5)
(1, 1, 3), (5, 6) -> Error, batch dims must match

density_estimator.sample(shape, condition)

(1,), (1, 6) -> (1, *event_shape_input)
(1,), (5, 6) -> (1, 5, *event_shape_input)
(10,), (5, 6) -> (10, 5, *event_shape_input)
(10, 3), (5, 6) -> (10, 3, 5, *event_shape_input)

Issues to be opened

  • MixedDensityEstimator cannot have embedding_net.
  • build_categoricalmassestimator should have z-score option and perform z-scoring by itself.
  • Only DensityEstimator should be carrying condition_shape. posterior and inference should not carry these attributes.
  • log_prob_iid of MNLE not working

Limitations

Not all DensityEstimators can...

  • ...handle batch_shapes (but only batch_dims, i.e. scalar values)
  • ...evaluate one datapoint under multiple conditions with log_prob without adapting the batch_dim of the datapoint
  • ...perform log_prob on data without iid_dim_input. I.e. log_prob((50,3), (50,4)) might fail, but log_prob((1,50,3), (50,4)) will work

Does this close any currently open issues?

Fixes #1041

Additional (but orthogonal) contributions

  • Make the naming of variables in MixedDensityEstimator independent of having to estimate the likelihood (it can, in principle, be used to estimate mixed posteriors)

Checklist

  • I have read and understood the contribution
    guidelines
  • I agree with re-licensing my contribution from AGPLv3 to Apache-2.0.
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have reported how long the new tests run and potentially marked them
    with pytest.mark.slow.
  • New and existing unit tests pass locally with my changes
  • I performed linting and formatting as described in the contribution
    guidelines
  • I rebased on main (or there are no conflicts with main)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A unified format for shapes passed to all Estimators

3 participants