Skip to content

Commit

Permalink
qol fixes on documentation (#236)
Browse files Browse the repository at this point in the history
* use the last version of setup-python

* add sphinx_design back

* remove unnecessary import in notebooks

* use chains=2 max in tutorials

* use IPython utils to hide Colab installation outputs

* links
  • Loading branch information
LegrandNico authored Sep 14, 2024
1 parent f27e0eb commit bdafea7
Show file tree
Hide file tree
Showing 21 changed files with 121 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.12'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Run lint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.12"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v2
Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"matplotlib.sphinxext.plot_directive",
"numpydoc",
"myst_nb",
"sphinx_design",
"sphinxcontrib.bibtex",
"sphinx_togglebutton",
"sphinx_exercise",
Expand Down
3 changes: 2 additions & 1 deletion docs/source/learn.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ notebooks/1.3-Continuous_HGF.ipynb
notebooks/2-Using_custom_response_functions.ipynb
notebooks/3-Multilevel_HGF.ipynb
notebooks/4-Parameter_recovery.ipynb
notebooks/5-Non_linear_value_coupling
```

```{toctree}
Expand Down Expand Up @@ -67,7 +68,7 @@ How the generative model of the Hierarchical Gaussian filter can be turned into
:::{grid-item-card} Creating and manipulating networks of probabilistic nodes
:link: probabilistic_networks
:link-type: ref
:img-top: ./images/graph_networks.svg
:img-top: ./images/graph_network.svg

How to create and manipulate a network of probabilistic nodes for reinforcement learning? Working at the intersection of graphs, neural networks and probabilistic frameworks.
:::
Expand Down
6 changes: 4 additions & 2 deletions docs/source/notebooks/0.1-Theory.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
},
"outputs": [],
"source": [
"%%capture\n",
"import sys\n",
"from IPython.utils import io\n",
"if 'google.colab' in sys.modules:\n",
" ! pip install watermark"
"\n",
" with io.capture_output() as captured:\n",
" ! pip install watermark"
]
},
{
Expand Down
9 changes: 5 additions & 4 deletions docs/source/notebooks/0.2-Creating_networks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@
},
"outputs": [],
"source": [
"%%capture\n",
"import sys\n",
"\n",
"from IPython.utils import io\n",
"if 'google.colab' in sys.modules:\n",
" !pip install pyhgf watermark"
"\n",
" with io.capture_output() as captured:\n",
" ! pip install pyhgf watermark"
]
},
{
Expand Down Expand Up @@ -131,7 +132,7 @@
"\n",
"This list describes the sequence of function-to-nodes instructions that are executed during the inference and update processes.\n",
"\n",
"![graph_networks](../images/graph_networks.svg)\n",
"![graph_network](../images/graph_network.svg)\n",
"\n",
"```{tip} Compatibility with JAX transformations\n",
"One of the advantages of reasoning this way is that it dissociates variables that are transparent to the JAX framework and can be expressed as \"PyTress\" from variables that should be filtered before transformations. The variable `attributes` ($\\theta$) is typically expressed as a PyTree while the other variables that contain parametrized functions are filtered. See [the documattion](https://jax.readthedocs.io/en/latest/notebooks/thinking_in_jax.html#jit-mechanics-tracing-and-static-variables) for further details on JAX transformations.\n",
Expand Down
23 changes: 23 additions & 0 deletions docs/source/notebooks/0.3-Generalised_filtering.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ilabcode/pyhgf/blob/master/docs/source/notebooks/0.3-Generalised_filtering.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "31b80846",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": [
"hide-cell"
]
},
"outputs": [],
"source": [
"import sys\n",
"from IPython.utils import io\n",
"if 'google.colab' in sys.modules:\n",
"\n",
" with io.capture_output() as captured:\n",
" ! pip install pyhgf watermark"
]
},
{
"cell_type": "code",
"execution_count": 1,
Expand Down
11 changes: 6 additions & 5 deletions docs/source/notebooks/1.1-Binary_HGF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@
},
"outputs": [],
"source": [
"%%capture\n",
"import sys\n",
"\n",
"from IPython.utils import io\n",
"if 'google.colab' in sys.modules:\n",
" !pip install pyhgf watermark"
"\n",
" with io.capture_output() as captured:\n",
" ! pip install pyhgf watermark"
]
},
{
Expand Down Expand Up @@ -870,7 +871,7 @@
],
"source": [
"with two_levels_binary_hgf:\n",
" two_level_hgf_idata = pm.sample(chains=4, cores=1)"
" two_level_hgf_idata = pm.sample(chains=2, cores=1)"
]
},
{
Expand Down Expand Up @@ -1299,7 +1300,7 @@
],
"source": [
"with three_levels_binary_hgf:\n",
" three_level_hgf_idata = pm.sample(chains=4, cores=1)"
" three_level_hgf_idata = pm.sample(chains=2, cores=1)"
]
},
{
Expand Down
7 changes: 4 additions & 3 deletions docs/source/notebooks/1.2-Categorical_HGF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@
},
"outputs": [],
"source": [
"%%capture\n",
"import sys\n",
"\n",
"from IPython.utils import io\n",
"if 'google.colab' in sys.modules:\n",
" !pip install pyhgf watermark"
"\n",
" with io.capture_output() as captured:\n",
" ! pip install pyhgf watermark"
]
},
{
Expand Down
10 changes: 6 additions & 4 deletions docs/source/notebooks/1.3-Continuous_HGF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
},
"outputs": [],
"source": [
"%%capture\n",
"import sys\n",
"from IPython.utils import io\n",
"if 'google.colab' in sys.modules:\n",
" !pip install pyhgf watermark"
"\n",
" with io.capture_output() as captured:\n",
" ! pip install pyhgf watermark"
]
},
{
Expand Down Expand Up @@ -959,7 +961,7 @@
],
"source": [
"with two_level_hgf:\n",
" two_level_hgf_idata = pm.sample(chains=4, cores=1)"
" two_level_hgf_idata = pm.sample(chains=2, cores=1)"
]
},
{
Expand Down Expand Up @@ -1353,7 +1355,7 @@
],
"source": [
"with three_level_hgf:\n",
" three_level_hgf_idata = pm.sample(chains=4, cores=1)"
" three_level_hgf_idata = pm.sample(chains=2, cores=1)"
]
},
{
Expand Down
8 changes: 5 additions & 3 deletions docs/source/notebooks/2-Using_custom_response_functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
},
"outputs": [],
"source": [
"%%capture\n",
"import sys\n",
"from IPython.utils import io\n",
"if 'google.colab' in sys.modules:\n",
" !pip install pyhgf watermark"
"\n",
" with io.capture_output() as captured:\n",
" ! pip install pyhgf watermark"
]
},
{
Expand Down Expand Up @@ -907,7 +909,7 @@
],
"source": [
"with sigmoid_hgf:\n",
" sigmoid_hgf_idata = pm.sample(chains=4, cores=1)"
" sigmoid_hgf_idata = pm.sample(chains=2, cores=1)"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions docs/source/notebooks/3-Multilevel_HGF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@
},
"outputs": [],
"source": [
"%%capture\n",
"import sys\n",
"\n",
"from IPython.utils import io\n",
"if 'google.colab' in sys.modules:\n",
" !pip install pyhgf watermark"
"\n",
" with io.capture_output() as captured:\n",
" ! pip install pyhgf watermark"
]
},
{
Expand All @@ -81,7 +82,6 @@
],
"source": [
"import arviz as az\n",
"import jax.numpy as jnp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pymc as pm\n",
Expand Down
7 changes: 4 additions & 3 deletions docs/source/notebooks/4-Parameter_recovery.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@
},
"outputs": [],
"source": [
"%%capture\n",
"import sys\n",
"\n",
"from IPython.utils import io\n",
"if 'google.colab' in sys.modules:\n",
" !pip install pyhgf watermark"
"\n",
" with io.capture_output() as captured:\n",
" ! pip install pyhgf watermark"
]
},
{
Expand Down
9 changes: 5 additions & 4 deletions docs/source/notebooks/5-Non_linear_value_coupling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"import sys\n",
"\n",
"from IPython.utils import io\n",
"if 'google.colab' in sys.modules:\n",
" !pip install pyhgf watermark"
"\n",
" with io.capture_output() as captured:\n",
" ! pip install pyhgf watermark"
]
},
{
Expand All @@ -56,7 +57,7 @@
"import jax.numpy as jnp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from jax import jit, lax\n",
"from jax import lax\n",
"from pyhgf.model import Network\n",
"import seaborn as sns\n",
"\n",
Expand Down
6 changes: 4 additions & 2 deletions docs/source/notebooks/Example_1_Heart_rate_variability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
},
"outputs": [],
"source": [
"%%capture\n",
"import sys\n",
"from IPython.utils import io\n",
"if 'google.colab' in sys.modules:\n",
" !pip install pyhgf systole watermark"
"\n",
" with io.capture_output() as captured:\n",
" ! pip install pyhgf watermark systole"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
},
"outputs": [],
"source": [
"%%capture\n",
"import sys\n",
"from IPython.utils import io\n",
"if 'google.colab' in sys.modules:\n",
" !pip install pyhgf watermark"
"\n",
" with io.capture_output() as captured:\n",
" ! pip install pyhgf watermark"
]
},
{
Expand Down
7 changes: 4 additions & 3 deletions docs/source/notebooks/Example_3_Multi_armed_bandit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@
},
"outputs": [],
"source": [
"%%capture\n",
"import sys\n",
"\n",
"from IPython.utils import io\n",
"if 'google.colab' in sys.modules:\n",
" ! pip install pyhgf watermark"
"\n",
" with io.capture_output() as captured:\n",
" ! pip install pyhgf watermark"
]
},
{
Expand Down
Loading

0 comments on commit bdafea7

Please sign in to comment.