at: **Data Umbrella**

by: **Oriol Abril Pla**

Data is considered fixed *once observed*

Model parameters are *treated* as random

Data is considered fixed *once observed*

Model parameters are *treated* as random

\[p(\theta \mid y)\]

\[p(\theta \mid y)\]

- Physical constraints
- Model constraints
- Prior studies
- ...

MCMC: HMC+NUTS, Metropolis, Gibbs...

Variational Inference: ADVI (+mini batch ADVI), OPVI

Example from Salvatier, J., Wiecki, T. V., & Fonnesbeck, C. (2016).
*Probabilistic programming in Python using PyMC3.*
PeerJ Computer Science

Video | Code |
---|---|

(talk by @fonnesbeck at Montreal Python) | (2nd case study) |

\[\begin{aligned}
y & \sim \text{Poisson}(r) \\
\end{aligned} \]

```
with pm.Model():
disasters = pm.Poisson(
"disasters", rate, observed=data
)
```

\[\begin{aligned}
y & \sim \text{Poisson}(r) \\
r & = \begin{cases}
e, \ \text{if}\ t \leq s\\
l, \ \text{if}\ t \gt s
\end{cases}
\end{aligned} \]

```
with pm.Model():
rate = pm.math.switch(s >= years, e, l)
disasters = pm.Poisson(
"disasters", rate, observed=data
)
```

\[\begin{aligned}
y & \sim \text{Poisson}(r) \\
r & = \begin{cases}
e, \ \text{if}\ t \leq s\\
l, \ \text{if}\ t \gt s
\end{cases} \\
s & \sim \text{DiscreteUniform}(t_0, t_e) \\
\end{aligned} \]

```
with pm.Model():
s = pm.DiscreteUniform(
"switchpoint", lower=t_0, upper=t_e
)
rate = pm.math.switch(s >= years, e, l)
disasters = pm.Poisson(
"disasters", rate, observed=data
)
```

\[\begin{aligned}
y & \sim \text{Poisson}(r) \\
r & = \begin{cases}
e, \ \text{if}\ t \leq s\\
l, \ \text{if}\ t \gt s
\end{cases}\\
s & \sim \text{DiscreteUniform}(t_0, t_e) \\
e & \sim \text{Exponential}(1) \\
l & \sim \text{Exponential}(1)
\end{aligned} \]

```
with pm.Model():
s = pm.DiscreteUniform(
"switchpoint", lower=t_0, upper=t_e
)
e = pm.Exponential("early_rate", 1.0)
l = pm.Exponential("late_rate", 1.0)
rate = pm.math.switch(s >= years, e, l)
disasters = pm.Poisson(
"disasters", rate, observed=data
)
```

```
with model:
trace = pm.sample(3000, tune=2000)
```

```
Multiprocess sampling (4 chains in 4 jobs)
CompoundStep
>Metropolis: [switchpoint]
>NUTS: [late_rate, early_rate]
```

Example by @corrieaar at PyConDE & PyData Berlin 2019

Video | Code | Slides |
---|

This talk is heavily inspired by many other talks about Bayesian statistics and PyMC3 as well as by interactions with the whole PyMC3 and greater Bayesian OSS community on GitHub and Discourse

Special thanks go to PyMC3 and ArviZ core members, to Thomas Wiecki, Chris Fonnesbeck, Corrie Bartelheimer and Allen Downey, check out their profiles and websites for more amazing content!

PyMC3 documentation: docs.pymc.io

PyMCon 2020 talks: publicly available on Discourse

Learn Bayesian Statistics Podcast: learnbayesstats.com