Skip to content

Commit

Permalink
polish docs and update github action
Browse files Browse the repository at this point in the history
  • Loading branch information
LegrandNico committed Jul 3, 2024
1 parent d0eb58e commit 819ece8
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 81 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name: Build and Deploy

on:
push:
branches:
- master
release:
types: [published]
pull_request:
branches:
- "*"
types:
- opened
permissions:
contents: write

Expand All @@ -29,14 +28,14 @@ jobs:
sphinx-build -j 4 -T -b html docs/source docs/build/html
- name: Deploy Stable 🚀
if: startsWith(github.ref, 'refs/tags/')
if: github.event_name == 'release'
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: docs/build/html
branch: gh-pages

- name: Deploy Dev 🚀
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
if: github.event_name == 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: docs/build/html
Expand Down
2 changes: 1 addition & 1 deletion docs/source/learn.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ A generalisation of the binary Hierarchical Gaussian Filter to multiarmed bandit
Hand-on exercises for theComputational Psychiatry Course (Zurich) to build intuition around the generalised Hierarchical Gaussian Filter, how to create and manipulate probabilistic networks, design an agent to perform a reinforcement learning task and use MCMC sampling for parameter inference and model comparison—about 4 hours.


::::{grid} 1 1 2 3
::::{grid} 1 1 2 2
:gutter: 1

:::{grid-item-card} Introduction to the Generalised Hierarchical Gaussian Filter
Expand Down
9 changes: 5 additions & 4 deletions docs/source/notebooks/0.1-Theory.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "6430ec8b-1b42-450b-9ed5-a9866384042f",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import seaborn as sns"
"import seaborn as sns\n",
"\n",
"plt.rcParams[\"figure.constrained_layout.use\"] = True"
]
},
{
Expand Down Expand Up @@ -416,8 +418,6 @@
"\n",
"axs[1, 2].plot(x_1_3, \"-\", linewidth=1, color=\"#55a868\")\n",
"axs[1, 2].set(xlabel=\"Time steps\", ylabel=r\"$x_1$\")\n",
"\n",
"plt.tight_layout()\n",
"sns.despine()"
]
},
Expand Down Expand Up @@ -679,6 +679,7 @@
"\n",
"Gaussian Random Walk\n",
" A Gaussian Random Walk is a [Random Walk](https://en.wikipedia.org/wiki/Random_walk) with normally distributed increments. This is a mathematical model used to describe the behaviour of a variable that changes randomly over time. The Generalized Hierarchical Gaussian Filter implies that the behaviour of continuous state nodes is guided by this kind of process. This process can be further complexified by adding a constant drift or an autoregression component.\n",
"\n",
"Node\n",
" HGF models are defined as networks of probabilistic nodes. A node is defined by its parameters (e.g. sufficient statistics, coupling values...) and by its connection with other nodes. The dependencies structure can have more than one dimension (i.e. there are many kinds of dependencies between nodes, especially here the volatility coupling and the value coupling).\n",
"\n",
Expand Down
9 changes: 4 additions & 5 deletions docs/source/notebooks/0.2-Creating_networks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "81a63672",
"metadata": {
"editable": true,
Expand All @@ -66,7 +66,9 @@
"import numpy as np\n",
"import seaborn as sns\n",
"from pyhgf.model import Network, HGF\n",
"from pyhgf.typing import AdjacencyLists"
"from pyhgf.typing import AdjacencyLists\n",
"\n",
"plt.rcParams[\"figure.constrained_layout.use\"] = True"
]
},
{
Expand Down Expand Up @@ -881,7 +883,6 @@
"many_value_children_hgf.input_data(input_data=input_data)\n",
"\n",
"many_value_children_hgf.plot_nodes([3, 2], figsize=(12, 5), show_observations=True)\n",
"plt.tight_layout()\n",
"sns.despine()"
]
},
Expand Down Expand Up @@ -1089,7 +1090,6 @@
" figsize=(12, 8),\n",
" show_observations=False,\n",
")\n",
"plt.tight_layout()\n",
"sns.despine()"
]
},
Expand Down Expand Up @@ -1317,7 +1317,6 @@
"axs[-2].legend()\n",
"axs[-3].plot(u_1_prob, label=\"Contingencies - Input Node 1\", linestyle=\":\")\n",
"axs[-3].legend()\n",
"plt.tight_layout()\n",
"sns.despine()"
]
},
Expand Down
6 changes: 2 additions & 4 deletions docs/source/notebooks/0.3-Generalised_filtering.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,17 @@
],
"source": [
"import jax.numpy as jnp\n",
"import matplotlib.animation as animation\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import seaborn as sns\n",
"from matplotlib.ticker import MultipleLocator\n",
"from pyhgf.math import MultivariateNormal, Normal, gaussian_predictive_distribution\n",
"from pyhgf.model import HGF, Network\n",
"from pyhgf.utils import beliefs_propagation\n",
"from scipy.special import gammaln\n",
"from scipy.stats import norm, t\n",
"\n",
"np.random.seed(123)"
"np.random.seed(123)\n",
"plt.rcParams[\"figure.constrained_layout.use\"] = True"
]
},
{
Expand Down Expand Up @@ -903,7 +902,6 @@
" ax[i].set_ylabel(rf\"$\\nu_{i}$\")\n",
" ax[i].set_xlabel(\"Observations\")\n",
" ax[i].legend()\n",
"plt.tight_layout()\n",
"sns.despine()"
]
},
Expand Down
11 changes: 5 additions & 6 deletions docs/source/notebooks/1.1-Binary_HGF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@
"import jax.numpy as jnp\n",
"import matplotlib.pyplot as plt\n",
"import pymc as pm\n",
"import seaborn as sns\n",
"from pyhgf import load_data\n",
"from pyhgf.distribution import HGFDistribution\n",
"from pyhgf.model import HGF\n",
"from pyhgf.response import first_level_binary_surprise"
"from pyhgf.response import first_level_binary_surprise\n",
"\n",
"plt.rcParams[\"figure.constrained_layout.use\"] = True"
]
},
{
Expand Down Expand Up @@ -890,8 +891,7 @@
}
],
"source": [
"az.plot_trace(two_level_hgf_idata, var_names=[\"tonic_volatility_2\"])\n",
"plt.tight_layout()"
"az.plot_trace(two_level_hgf_idata, var_names=[\"tonic_volatility_2\"]);"
]
},
{
Expand Down Expand Up @@ -1322,8 +1322,7 @@
"source": [
"az.plot_trace(\n",
" three_level_hgf_idata, var_names=[\"tonic_volatility_2\", \"tonic_volatility_3\"]\n",
")\n",
"plt.tight_layout()"
");"
]
},
{
Expand Down
9 changes: 2 additions & 7 deletions docs/source/notebooks/1.2-Categorical_HGF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,13 @@
},
"outputs": [],
"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",
"import pytensor\n",
"import pytensor.tensor as pt\n",
"import seaborn as sns\n",
"from jax import grad, jit, vjp\n",
"from jax import jit, vjp\n",
"from jax.tree_util import Partial\n",
"from pyhgf import load_data\n",
"from pyhgf.model import HGF\n",
"from pyhgf.plots import plot_nodes\n",
"from pytensor.graph import Apply, Op"
Expand Down Expand Up @@ -786,8 +782,7 @@
"axs[4].set_title(\"Sum of binary surprises\", loc=\"left\")\n",
"axs[2].set_ylabel(\"Surprises\")\n",
"\n",
"sns.despine()\n",
"plt.tight_layout()"
"sns.despine()"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions docs/source/notebooks/1.3-Continuous_HGF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@
"import jax.numpy as jnp\n",
"import matplotlib.pyplot as plt\n",
"import pymc as pm\n",
"import seaborn as sns\n",
"\n",
"from pyhgf import load_data\n",
"from pyhgf.distribution import HGFDistribution\n",
"from pyhgf.model import HGF\n",
"from pyhgf.response import first_level_gaussian_surprise"
"from pyhgf.response import first_level_gaussian_surprise\n",
"\n",
"plt.rcParams[\"figure.constrained_layout.use\"] = True"
]
},
{
Expand Down Expand Up @@ -1373,8 +1374,7 @@
}
],
"source": [
"az.plot_trace(three_level_hgf_idata);\n",
"plt.tight_layout()"
"az.plot_trace(three_level_hgf_idata);"
]
},
{
Expand Down
5 changes: 3 additions & 2 deletions docs/source/notebooks/2-Using_custom_response_functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
"\n",
"from pyhgf import load_data\n",
"from pyhgf.distribution import HGFDistribution\n",
"from pyhgf.model import HGF"
"from pyhgf.model import HGF\n",
"\n",
"plt.rcParams[\"figure.constrained_layout.use\"] = True"
]
},
{
Expand Down Expand Up @@ -988,7 +990,6 @@
],
"source": [
"az.plot_trace(sigmoid_hgf_idata, var_names=[\"tonic_volatility_2\"]);\n",
"plt.tight_layout()\n",
"az.summary(sigmoid_hgf_idata, var_names=[\"tonic_volatility_2\"])"
]
},
Expand Down
11 changes: 5 additions & 6 deletions docs/source/notebooks/3-Multilevel_HGF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pymc as pm\n",
"import pytensor.tensor as tt\n",
"import seaborn as sns\n",
"from numpy import loadtxt\n",
"from pyhgf import load_data\n",
"from pyhgf.distribution import HGFDistribution, hgf_logp\n",
"from pyhgf.distribution import HGFDistribution\n",
"from pyhgf.model import HGF\n",
"from pyhgf.response import binary_softmax_inverse_temperature"
"from pyhgf.response import binary_softmax_inverse_temperature\n",
"\n",
"plt.rcParams[\"figure.constrained_layout.use\"] = True"
]
},
{
Expand Down Expand Up @@ -625,8 +625,7 @@
" two_level_hgf_idata,\n",
" var_names=[\"mu_temperature\", \"mu_volatility\"],\n",
" ref_val=[0.5, -4.0],\n",
")\n",
"plt.tight_layout()"
")"
]
},
{
Expand Down
3 changes: 1 addition & 2 deletions docs/source/notebooks/4-Parameter_recovery.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@
"import numpy as np\n",
"import pymc as pm\n",
"import seaborn as sns\n",
"from numpy import loadtxt\n",
"from pyhgf import load_data\n",
"from pyhgf.distribution import HGFDistribution, hgf_logp\n",
"from pyhgf.distribution import HGFDistribution\n",
"from pyhgf.math import sigmoid_inverse_temperature\n",
"from pyhgf.model import HGF\n",
"from pyhgf.response import binary_softmax_inverse_temperature"
Expand Down
8 changes: 4 additions & 4 deletions docs/source/notebooks/Example_1_Heart_rate_variability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pymc as pm\n",
"import seaborn as sns\n",
"from systole import import_dataset1\n",
"from systole.detection import ecg_peaks\n",
"from systole.plots import plot_raw\n",
"from systole.utils import input_conversion\n",
"\n",
"from pyhgf.distribution import HGFDistribution\n",
"from pyhgf.model import HGF\n",
"from pyhgf.response import total_gaussian_surprise"
"from pyhgf.response import total_gaussian_surprise\n",
"\n",
"plt.rcParams[\"figure.constrained_layout.use\"] = True"
]
},
{
Expand Down Expand Up @@ -410,8 +411,7 @@
}
],
"source": [
"az.plot_trace(idata)\n",
"plt.tight_layout()"
"az.plot_trace(idata);"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,10 @@
},
"outputs": [],
"source": [
"import arviz as az\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pymc as pm\n",
"import seaborn as sns\n",
"from scipy.stats import norm\n",
"\n",
"from pyhgf.distribution import HGFDistribution\n",
"from pyhgf.model import Network"
]
},
Expand Down
Loading

0 comments on commit 819ece8

Please sign in to comment.