stefanradev93 / BayesFlow

A Python library for amortized Bayesian workflows using generative neural networks.
https://bayesflow.org/
MIT License
286 stars 45 forks source link

Remove code duplication from diagnostics module #138

Open stefanradev93 opened 5 months ago

stefanradev93 commented 5 months ago

Currently, the functions in diagnostics.py exhibit a lot of code duplication; most of it can be delegated to one or two helper functions which are then utilized by the diagnostics functions.

han-ol commented 4 months ago

Agreed!

Related: it would be useful to have a more flexible/general function akin to plot_posterior_2d().

AmortizedPointEstimator.bootstrap_sample() produces structurally similar data as AmortizedPosterior.sample(). However, if we want to plot it, the label used in plot_posterior_2d() cannot be changed and the legend would wrongly read 'Posterior'.

Additionally and orthogonal to that, in order to do global sensitivity analysis via context variables, multiple distributions need to be plotted and a legend should indicate the context.

One solution I can think of would be to expose a (currently not existing) function like plot_distribution(df:DataFrame, ...) to users. Such a function would also remove some of the code duplication, so maybe this can be taken into account when refactoring the diagnostics module.