Skip to content

Commit cd0b93b

Browse files
author
juanitorduz
committed
add warning comments
1 parent de1cfc2 commit cd0b93b

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

examples/howto/updating_priors.ipynb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
"cell_type": "markdown",
1818
"metadata": {},
1919
"source": [
20-
"In this notebook, we will show how it is possible to update the priors as new data becomes available."
20+
"In this notebook, we will show how, in principle, it is possible to update the priors as new data becomes available.\n",
21+
"\n",
22+
"`````{admonition} Words of Caution\n",
23+
":class: warning\n",
24+
"This example provides a very nice usage example for the {class}`~pymc.Interpolated` class, as we will see below. However, this might not be a good idea to do in practice, not only for the posterior -> kde part, but mostly because Interpolated distributions used as priors are **unidimensional** and **uncorrelated**. So even if a perfect fit *marginally* they don't really incorporate all the information we have from the previous posterior into the model, especially when posterior variables are correlated. See a nice discussion about the subject in the blog post [Some dimensionality devils](https://oriolabrilpla.cat/en/blog/posts/2022/too-eager-reduction.html#univariate-priors) by [Oriol Abril](https://oriolabrilpla.cat/en/).\n",
25+
"``````"
2126
]
2227
},
2328
{
@@ -376,6 +381,31 @@
376381
"What is interesting to note is that the posterior distributions for our parameters tend to get centered on their true value (vertical lines), and the distribution gets thiner and thiner. This means that we get more confident each time, and the (false) belief we had at the beginning gets flushed away by the new data we incorporate."
377382
]
378383
},
384+
{
385+
"cell_type": "markdown",
386+
"metadata": {},
387+
"source": [
388+
"``````{admonition} Not silver bullet\n",
389+
":class: warning\n",
390+
"Observe that, despite the fact that the iterations seems improving, toms of them look actually a bit sketchy as the MC error can creep in.\n",
391+
"``````"
392+
]
393+
},
394+
{
395+
"cell_type": "markdown",
396+
"metadata": {},
397+
"source": [
398+
"``````{admonition} An alternative approach\n",
399+
":class: tip\n",
400+
"There is an alternative way in `pymc-experimental` trough the function {func}`~pymc_experimental/utils/prior.prior_from_idata` that does something similar. This function:\n",
401+
"> Creates a prior from posterior using MvNormal approximation.\n",
402+
"> The approximation uses MvNormal distribution. Keep in mind that this function will only work well for unimodal\n",
403+
"> posteriors and will fail when complicated interactions happen. Moreover, if a retrieved variable is constrained, you\n",
404+
"> should specify a transform for the variable, e.g.\n",
405+
"> {func}`~pymc.distributions.transforms.log` for standard deviation posterior.\n",
406+
"``````"
407+
]
408+
},
379409
{
380410
"cell_type": "code",
381411
"execution_count": 10,

examples/howto/updating_priors.myst.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ kernelspec:
2020

2121
+++
2222

23-
In this notebook, we will show how it is possible to update the priors as new data becomes available.
23+
In this notebook, we will show how, in principle, it is possible to update the priors as new data becomes available.
24+
25+
`````{admonition} Words of Caution
26+
:class: warning
27+
This example provides a very nice usage example for the {class}`~pymc.Interpolated` class, as we will see below. However, this might not be a good idea to do in practice, not only for the posterior -> kde part, but mostly because Interpolated distributions used as priors are **unidimensional** and **uncorrelated**. So even if a perfect fit *marginally* they don't really incorporate all the information we have from the previous posterior into the model, especially when posterior variables are correlated. See a nice discussion about the subject in the blog post [Some dimensionality devils](https://oriolabrilpla.cat/en/blog/posts/2022/too-eager-reduction.html#univariate-priors) by [Oriol Abril](https://oriolabrilpla.cat/en/).
28+
``````
2429
2530
```{code-cell} ipython3
2631
import arviz as az
@@ -184,6 +189,25 @@ You can re-execute the last two cells to generate more updates.
184189
185190
What is interesting to note is that the posterior distributions for our parameters tend to get centered on their true value (vertical lines), and the distribution gets thiner and thiner. This means that we get more confident each time, and the (false) belief we had at the beginning gets flushed away by the new data we incorporate.
186191
192+
+++
193+
194+
``````{admonition} Not silver bullet
195+
:class: warning
196+
Observe that, despite the fact that the iterations seems improving, toms of them look actually a bit sketchy as the MC error can creep in.
197+
``````
198+
199+
+++
200+
201+
``````{admonition} An alternative approach
202+
:class: tip
203+
There is an alternative way in `pymc-experimental` trough the function {func}`~pymc_experimental/utils/prior.prior_from_idata` that does something similar. This function:
204+
> Creates a prior from posterior using MvNormal approximation.
205+
> The approximation uses MvNormal distribution. Keep in mind that this function will only work well for unimodal
206+
> posteriors and will fail when complicated interactions happen. Moreover, if a retrieved variable is constrained, you
207+
> should specify a transform for the variable, e.g.
208+
> {func}`~pymc.distributions.transforms.log` for standard deviation posterior.
209+
``````
210+
187211
```{code-cell} ipython3
188212
%load_ext watermark
189213
%watermark -n -u -v -iv -w

0 commit comments

Comments
 (0)