PSIS.jl icon indicating copy to clipboard operation
PSIS.jl copied to clipboard

Add function for taking expectations wrt smoothed weights

Open sethaxen opened this issue 7 months ago • 3 comments

This PR adds the API function expectation, which allows one to take some expectation wrt to PSIS-smoothed weights. This is the main function needed to compute expectations wrt LOO posteriors, though it is not limited to this application.

Some notes:

  • Currently the expectand must have shape (draws, [chains, [params...]]), i.e. it might share the data dimensions. This allows the function to be used for data-dependent scalar expectations e.g. loo_pit. However, one might have data-independent dimensions with or without data dimensions, e.g. for computing the LOO posterior means of all marginals. Supporting this could require a keyword that specifies which (trailing) dims in x are unrelated to the data or draws.
  • Currently we do not compute function-specific diagnostics. This requires something like #23, so that we can compute diagnostics without then smoothing.
  • Maybe a better way to compute expectations like mean is on the log-scale. However, this would require us to limit which expectations we can support.

Summary by CodeRabbit

  • New Features

    • Expanded statistical calculation capabilities with the addition of an expectation function for computing the expectation of values using smoothed importance weights.
  • Documentation

    • Updated API documentation to reflect new statistical functions and usage.
  • Refactor

    • Integrated the StatsBase module to enhance statistical operations within the module.

sethaxen avatar Dec 24 '23 07:12 sethaxen