arviz-devs / preliz

Exploring and eliciting probability distributions
https://preliz.readthedocs.io
Apache License 2.0
90 stars 9 forks source link

Export roulette state/figures to variables #545

Closed peter-8640 closed 1 month ago

peter-8640 commented 1 month ago

Say we have:

%matplotlib widget
pz.roulette()

image

Is it possible to get:

Is this stored somewhere under the hood as a json? then it would be easy enough to parse downstream.


Hopefully this is is just a docs question, but if it isn't already possible then I guess this is a feature request. Thanks!

aloctavodia commented 1 month ago

Hi @peter-8640, Now is not possible. But I have been thinking about adding this. Originally my idea was to provide easy access to the fitted distribution. But now I wonder if I should do the same with the "histogram/chips". Why do you think having access to the "histogram/chips" is a good idea? I am curious what do you want to do with that information?

peter-8640 commented 1 month ago

Hi @aloctavodia My use case is to use jupyter as a form and gather multiple views around the distribution of the same event. Then save the form responses (somewhere else in the form there will be an identifier field, which I would link to the result). If there was a way to access this it could be trivially written to file or database.

Having histogram/chips stored would be interesting for combining multiple views. Say,

We want a combined distribution, applying some creibility weighting h to each of them I think it would be much better to use:

h1 *x1 + h2 *x2 + h3*x3 ... hn*xn

Than

h1 *f1 + h2 *f2 + h3*f3 ... hn*fn

To fit a combined distribution

aloctavodia commented 1 month ago

That totally makes sense. Thanks for the feedback. PreliZ should have a function that allows the combination of many Roulette instances. In the meantime now you have easy access to the internal attributes.

aloctavodia commented 1 month ago

I created a function that combines the outputs of many Roulette instances. I tried different made-up examples and the result looked as expected. I will keep testing, most likely next week. Feel free to try it and give any suggestions if you have any. https://github.com/arviz-devs/preliz/pull/555