Skip to content

Commit

Permalink
fixing random seed issue in pm.Model definition (pymc-devs#403)
Browse files Browse the repository at this point in the history
* fixing random seed issue in pm.Model definition

* re-run and saved with jupytext installed

* re-run and updated spline.myst.md

* pre-commit passing
  • Loading branch information
kuvychko authored Jul 23, 2022
1 parent c90e91e commit e3a0e5c
Show file tree
Hide file tree
Showing 2 changed files with 285 additions and 308 deletions.
587 changes: 281 additions & 306 deletions examples/case_studies/spline.ipynb

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions myst_nbs/case_studies/spline.myst.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jupytext:
format_version: 0.13
jupytext_version: 1.13.7
kernelspec:
display_name: Python 3.10.4 ('pymc_env')
display_name: Python 3 (ipykernel)
language: python
name: python3
---
Expand All @@ -27,6 +27,8 @@ kernelspec:
Often, the model we want to fit is not a perfect line between some $x$ and $y$.
Instead, the parameters of the model are expected to vary over $x$.
There are multiple ways to handle this situation, one of which is to fit a *spline*.
Spline fit is effectively a sum of multiple individual curves (piecewise polynomials), each fit to a different section of $x$, that are tied together at their boundaries, often called *knots*.

The spline is effectively multiple individual lines, each fit to a different section of $x$, that are tied together at their boundaries, often called *knots*.

Below is a full working example of how to fit a spline using PyMC. The data and model are taken from [*Statistical Rethinking* 2e](https://xcelab.net/rm/statistical-rethinking/) by [Richard McElreath's](https://xcelab.net/rm/) {cite:p}`mcelreath2018statistical`.
Expand Down Expand Up @@ -158,7 +160,7 @@ Finally, the model can be built using PyMC. A graphical diagram shows the organi

```{code-cell} ipython3
COORDS = {"splines": np.arange(B.shape[1])}
with pm.Model(coords=COORDS, rng_seeder=RANDOM_SEED) as spline_model:
with pm.Model(coords=COORDS) as spline_model:
a = pm.Normal("a", 100, 5)
w = pm.Normal("w", mu=0, sigma=3, size=B.shape[1], dims="splines")
mu = pm.Deterministic("mu", a + pm.math.dot(np.asarray(B, order="F"), w.T))
Expand Down

0 comments on commit e3a0e5c

Please sign in to comment.