Skip to content

Commit

Permalink
update tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
LegrandNico committed Sep 22, 2023
1 parent 76f0c9e commit 0c4e3e3
Show file tree
Hide file tree
Showing 14 changed files with 447 additions and 898 deletions.
138 changes: 47 additions & 91 deletions docs/source/notebooks/1.1-Binary_HGF.ipynb

Large diffs are not rendered by default.

60 changes: 11 additions & 49 deletions docs/source/notebooks/1.1-Binary_HGF.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ from pyhgf.distribution import HGFDistribution
from pyhgf.response import first_level_binary_surprise
```

### two-level model
### Two-level model
#### Creating the model

```{code-cell} ipython3
Expand All @@ -196,7 +196,7 @@ hgf_logp_op = HGFDistribution(
```

```{note}
The data is being passed to the distribution when the instance is created.
The data is being passed to the distribution when the instance is created, so we won't use the `observed` argument in our PyMC model.
```

```{code-cell} ipython3
Expand All @@ -207,29 +207,12 @@ slideshow:
---
with pm.Model() as two_levels_binary_hgf:
# Set a prior over the evolution rate at the second level.
omega_2 = pm.Uniform("omega_2", -3.5, 0.0)
pm.Potential(
"hgf_loglike",
hgf_logp_op(
omega_1=jnp.inf,
omega_2=omega_2,
continuous_precision=jnp.nan,
binary_precision=jnp.inf,
rho_1=0.0,
rho_2=0.0,
pi_1=0.0,
pi_2=1.0,
mu_1=jnp.inf,
mu_2=0.5,
kappa_1=1.0,
omega_3=jnp.nan,
rho_3=jnp.nan,
pi_3=jnp.nan,
mu_3=jnp.nan,
kappa_2=jnp.nan
),
)
# Call the pre-parametrized HGF distribution here.
# All parameters are set to their default value, except omega_2.
pm.Potential("hgf_loglike", hgf_logp_op(omega_2=omega_2))
```

#### Visualizing the model
Expand Down Expand Up @@ -278,7 +261,7 @@ hgf_mcmc.plot_trajectories();
hgf_mcmc.surprise()
```

### three-level model
### Three-level model
#### Creating the model

```{code-cell} ipython3
Expand All @@ -295,10 +278,6 @@ hgf_logp_op = HGFDistribution(
)
```

```{note}
The data is passed to the distribution when the instance is created.
```

```{code-cell} ipython3
---
editable: true
Expand All @@ -307,30 +286,13 @@ slideshow:
---
with pm.Model() as three_levels_binary_hgf:
# Set a prior over the evolution rate at the second and third levels.
omega_2 = pm.Uniform("omega_2", -4.0, 0.0)
omega_3 = pm.Normal("omega_3", -11.0, 2)
pm.Potential(
"hgf_loglike",
hgf_logp_op(
omega_1=jnp.inf,
omega_2=omega_2,
omega_3=omega_3,
continuous_precision=jnp.nan,
binary_precision=jnp.inf,
rho_1=0.0,
rho_2=0.0,
rho_3=0.0,
pi_1=0.0,
pi_2=1.0,
pi_3=1.0,
mu_1=jnp.inf,
mu_2=0.5,
mu_3=0.0,
kappa_1=1.0,
kappa_2=1.0,
),
)
# Call the pre-parametrized HGF distribution here.
# All parameters are set to their default value except omega_2 and omega_3.
pm.Potential("hgf_loglike", hgf_logp_op(omega_2=omega_2, omega_3=omega_3))
```

#### Visualizing the model
Expand Down
117 changes: 43 additions & 74 deletions docs/source/notebooks/1.3-Continuous_HGF.ipynb

Large diffs are not rendered by default.

49 changes: 9 additions & 40 deletions docs/source/notebooks/1.3-Continuous_HGF.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ from pyhgf.distribution import HGFDistribution
from pyhgf.response import first_level_gaussian_surprise
```

### two-level model
### Two-level model
#### Creating the model

+++
Expand All @@ -216,29 +216,13 @@ The data has been passed to the distribution in the cell above when the function
```{code-cell} ipython3
with pm.Model() as two_level_hgf:
# omegas priors
# Set a prior over the evolution rate at the first level.
omega_1 = pm.Normal("omega_1", -10, 2.0)
# Call the pre-parametrized HGF distribution here.
# All parameters are set to their default value except omega_1, omega_2 and mu_1.
pm.Potential(
"hgf_loglike",
hgf_logp_op(
omega_1=omega_1,
omega_2=-2.0,
continuous_precision=1e4,
binary_precision=jnp.nan,
rho_1=0.0,
rho_2=0.0,
pi_1=1e4,
pi_2=1e1,
mu_1=timeserie[0],
mu_2=0.0,
kappa_1=1.0,
omega_3=jnp.nan,
rho_3=jnp.nan,
pi_3=jnp.nan,
mu_3=jnp.nan,
kappa_2=jnp.nan
),
"hgf_loglike", hgf_logp_op(omega_1=omega_1, omega_2=-2.0, mu_1=1.0)
)
```

Expand Down Expand Up @@ -305,28 +289,13 @@ hgf_logp_op = HGFDistribution(
```{code-cell} ipython3
with pm.Model() as three_level_hgf:
# Set a prior over the evolution rate at the first level.
omega_1 = pm.Normal("omega_1", -10, 2.0)
# Call the pre-parametrized HGF distribution here.
# All parameters are set to their default value except omega_1, omega_2, omega_3 and mu_1.
pm.Potential(
"hgf_loglike",
hgf_logp_op(
omega_1=omega_1,
omega_2=-2.0,
omega_3=-2.0,
continuous_precision=1e4,
binary_precision=jnp.nan,
rho_1=0.0,
rho_2=0.0,
rho_3=0.0,
pi_1=1e4,
pi_2=1e1,
pi_3=1e1,
mu_1=timeserie[0],
mu_2=0.0,
mu_3=0.0,
kappa_1=1.0,
kappa_2=1.0,
),
"hgf_loglike", hgf_logp_op(omega_1=omega_1, omega_2=-2.0, omega_3=-2.0, mu_1=1.0)
)
```

Expand Down
54 changes: 17 additions & 37 deletions docs/source/notebooks/2-Using_custom_response_functions.ipynb

Large diffs are not rendered by default.

22 changes: 1 addition & 21 deletions docs/source/notebooks/2-Using_custom_response_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,27 +271,7 @@ with pm.Model() as sigmoid_hgf:
omega_2 = pm.Normal("omega_2", -2.0, 2.0)
# the main HGF distribution
pm.Potential(
"hgf_loglike",
hgf_logp_op(
omega_1=jnp.inf,
omega_2=omega_2,
continuous_precision=jnp.nan,
binary_precision=jnp.inf,
rho_1=0.0,
rho_2=0.0,
pi_1=0.0,
pi_2=1e4,
mu_1=0.0,
mu_2=0.5,
kappa_1=1.0,
omega_3=jnp.nan,
rho_3=jnp.nan,
pi_3=jnp.nan,
mu_3=jnp.nan,
kappa_2=jnp.nan
),
)
pm.Potential("hgf_loglike", hgf_logp_op(omega_2=omega_2))
```

```{code-cell} ipython3
Expand Down
Loading

0 comments on commit 0c4e3e3

Please sign in to comment.