Skip to content

Commit

Permalink
More fixes for GitHub build of docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre René committed Feb 5, 2024
1 parent 97305d1 commit b7153ac
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 61 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ jobs:
pages: write
id-token: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# Install dependencies
- name: Set up Python 3.11
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.11

Expand All @@ -48,11 +48,11 @@ jobs:
# Upload the book's HTML as an artifact
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
uses: actions/upload-pages-artifact@v3
with:
path: "_build/html"

# Deploy the book's HTML to GitHub Pages
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ author : Alexandre René # The author of the book
copyright : "2023" # Copyright year to be placed in the footer
logo : "" # A path to the book logo
exclude_patterns : [_build, Thumbs.db, .DS_Store, "**.ipynb_checkpoints", ".*", "**.egg-info", "*.mypy_cache", "**__pycache__", "**/.pytest_cache",
".jupyter", ".jupyter_cache",
".jupyter", ".jupyter_cache", "build/**",
"**purgatory", "**.smt"]

# Force re-execution of notebooks on each build.
Expand Down
13 changes: 6 additions & 7 deletions src/emd_falsify/config/__init__.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ kernelspec:

# Configuration options

```{code-cell}
```{code-cell} ipython3
---
editable: true
slideshow:
Expand All @@ -30,17 +30,14 @@ from typing import Optional, ClassVar, Union, Literal, Dict
from configparser import ConfigParser
```

```{code-cell}
```{code-cell} ipython3
---
editable: true
slideshow:
slide_type: ''
tags: [hide-input]
---
from pydantic import BaseModel, Field, validator, root_validator
# from mackelab_toolbox.config import ValidatingConfig, prepend_rootdir, ensure_dir_exists
# from mackelab_toolbox.config.holoviews import FiguresConfig
# prepend_rootdir is a workaround because assigning automatically doesn’t currently work
from valconfig import ValConfig, ensure_dir_exists
from valconfig.contrib.holoviews import FiguresConfig, HoloMPLConfig, HoloBokehConfig, GenericParam
from scityping import Config as ScitypingConfig
Expand All @@ -52,13 +49,15 @@ Possible improvement: If we could have nested config parsers, we might be
In particular, the `colors` field could remain a config parser, although
we would still want to allow dotted access.

```{code-cell}
```{code-cell} ipython3
class Config(ValConfig):
__default_config_path__ = "defaults.cfg"
class paths:
figures : Path
ensure_dir_exists = validator('figures', allow_reuse=True)(ensure_dir_exists)
class mp:
max_cores: int
maxtasksperchild: Union[int,None]
Expand Down Expand Up @@ -131,7 +130,7 @@ class Config(ValConfig):
config = Config(Path(__file__).parent/"defaults.cfg",
config_module_name=__name__)

```{code-cell}
```{code-cell} ipython3
---
editable: true
slideshow:
Expand Down
5 changes: 2 additions & 3 deletions src/emd_falsify/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@

# %% editable=true slideshow={"slide_type": ""} tags=["hide-input"]
from pydantic import BaseModel, Field, validator, root_validator
# from mackelab_toolbox.config import ValidatingConfig, prepend_rootdir, ensure_dir_exists
# from mackelab_toolbox.config.holoviews import FiguresConfig
# prepend_rootdir is a workaround because assigning automatically doesn’t currently work
from valconfig import ValConfig, ensure_dir_exists
from valconfig.contrib.holoviews import FiguresConfig, HoloMPLConfig, HoloBokehConfig, GenericParam
from scityping import Config as ScitypingConfig
Expand All @@ -47,6 +44,8 @@ class Config(ValConfig):
class paths:
figures : Path

ensure_dir_exists = validator('figures', allow_reuse=True)(ensure_dir_exists)

class mp:
max_cores: int
maxtasksperchild: Union[int,None]
Expand Down
2 changes: 1 addition & 1 deletion src/emd_falsify/emd.md
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ fig.opts(
)
```

+++ {"editable": true, "slideshow": {"slide_type": ""}, "tags": ["active-ipynb"]}
+++ {"editable": true, "slideshow": {"slide_type": ""}}

(supp_emd-implementation_Bemd)=
## Implementation of $B^{\mathrm{emd}}_{AB;c}$
Expand Down
2 changes: 1 addition & 1 deletion src/emd_falsify/emd.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def generate_paths(M, previous_M=0, qstar=mixed_risk_ppf, δemd=δemd, c=c, res=
# hv.opts.Layout(sublabel_format="")
# )

# %% editable=true slideshow={"slide_type": ""} tags=["active-ipynb"]
# %% [markdown] editable=true slideshow={"slide_type": ""}
# (supp_emd-implementation_Bemd)=
# ## Implementation of $B^{\mathrm{emd}}_{AB;c}$

Expand Down
44 changes: 22 additions & 22 deletions src/emd_falsify/path_sampling.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,22 @@ Because the joint requirements of monotonicity, non-stationarity and $Φ$-symmet
Moreover, instead of drawing quantile values, we draw increments
```{math}
:label: eq_def-quantile-increment
Δ l_{ΔΦ}(Φ) := \lnLh(Φ+ΔΦ) - \lnLh(Φ) \,.
Δ q_{ΔΦ}(Φ) := \lnLh(Φ+ΔΦ) - \lnLh(Φ) \,.
```
Given two initial end points $\lnLh(0)$ and $\lnLh(1)$, we therefore first we draw the pair $\bigl\{Δ l_{2^{-1}}(0),\; Δ l_{2^{-1}}\bigl(2^{-1}\bigr)\}$, which gives us
Given two initial end points $\lnLh(0)$ and $\lnLh(1)$, we therefore first we draw the pair $\bigl\{Δ q_{2^{-1}}(0),\; Δ q_{2^{-1}}\bigl(2^{-1}\bigr)\}$, which gives us
```{math}
\lnLh\bigl(2^{-1}\bigr) = \lnLh(0) + Δ l_{2^{-1}}(0) = \lnLh(1) - Δ l_{2^{-1}}\bigl(2^{-1}\bigr)\,.
\lnLh\bigl(2^{-1}\bigr) = \lnLh(0) + Δ q_{2^{-1}}(0) = \lnLh(1) - Δ q_{2^{-1}}\bigl(2^{-1}\bigr)\,.
```
Then $\bigl\{\lnLh(0), \lnLh\bigl(\frac{1}{2}\bigr) \bigr\}$ and $\bigl\{ \lnLh\bigl(\frac{1}{2}\bigr), \lnLh(1) \bigr\}$ serve as end points to draw $\bigl\{Δ l_{2^{-2}}\bigl(0\bigr),\; Δ l_{2^{-2}}\bigl(2^{-2}\bigr) \bigr\}$ and $\bigl\{Δ l_{2^{-2}}\bigl(2^{-1}\bigr),\; Δ l_{2^{-2}}\bigl(2^{-1} + 2^{-2}\bigr) \bigr\}$. We repeat the procedure as needed, sampling smaller and smaller incremenents, until the path has the desired resolution. As the increments are constrained:
Then $\bigl\{\lnLh(0), \lnLh\bigl(\frac{1}{2}\bigr) \bigr\}$ and $\bigl\{ \lnLh\bigl(\frac{1}{2}\bigr), \lnLh(1) \bigr\}$ serve as end points to draw $\bigl\{Δ q_{2^{-2}}\bigl(0\bigr),\; Δ q_{2^{-2}}\bigl(2^{-2}\bigr) \bigr\}$ and $\bigl\{Δ q_{2^{-2}}\bigl(2^{-1}\bigr),\; Δ q_{2^{-2}}\bigl(2^{-1} + 2^{-2}\bigr) \bigr\}$. We repeat the procedure as needed, sampling smaller and smaller incremenents, until the path has the desired resolution. As the increments are constrained:
```{math}
Δ l_{2^{-n}}(Φ) \in \bigl( 0, \lnLh(Φ+2^{-n+1}) - \lnLh(Φ)\,\bigr)\,,
Δ q_{2^{-n}}(Φ) \in \bigl( 0, \lnLh(Φ+2^{-n+1}) - \lnLh(Φ)\,\bigr)\,,
```
the path thus sampled is always monotone. Note also that increments must be drawn in pairs (or more generally as a *combination*) of values constrained by their sum:
```{math}
:label: eq_sum-constraint
Δ l_{2^{-n}}\bigl(Φ\bigr) + Δ l_{2^{-n}}\bigl(Φ + 2^{-n} \bigr) \stackrel{!}{=} \lnLh(Φ+2^{-n+1}) - \lnLh(Φ) \,.
Δ q_{2^{-n}}\bigl(Φ\bigr) + Δ q_{2^{-n}}\bigl(Φ + 2^{-n} \bigr) \stackrel{!}{=} \lnLh(Φ+2^{-n+1}) - \lnLh(Φ) \,.
```
The possible increments therefore lie on a 1-simplex, for which a natural choice is to use a beta distribution[^1], with the random variable corresponding to the first increment $Δ l_{2^{-n}}(Φ)$. The density function of a beta random variable has the form
The possible increments therefore lie on a 1-simplex, for which a natural choice is to use a beta distribution[^1], with the random variable corresponding to the first increment $Δ q_{2^{-n}}(Φ)$. The density function of a beta random variable has the form
```{math}
:label: eq_beta-pdf
p(x_1) \propto x^{α-1} (1-x)^{β-1}\,,
Expand Down Expand Up @@ -180,7 +180,7 @@ Satisfying this requirement is required in order to compute integrals over $\lnL
Recall that we made the assumption that the variability of the path process $\pathP$ should determined by $δ^{\EMD}$, up to some constant $c$.{cite:p}`reneFalsifyingModels2024` This constant is determined by a calibration experiment.
To keep expressions concise, in this section we use $\emdstd(Φ) := c δ^{\EMD}(Φ)$.
:::
To draw an increment $Δ l_{2^{-n}}$, we need to convert $\lnLtt(Φ)$ and $\emdstd(Φ)$ into beta distribution parameters $α$ and $β$. If $x_1$ follows a beta distribution, then its first two cumulants are given by
To draw an increment $Δ q_{2^{-n}}$, we need to convert $\lnLtt(Φ)$ and $\emdstd(Φ)$ into beta distribution parameters $α$ and $β$. If $x_1$ follows a beta distribution, then its first two cumulants are given by
```{math}
\begin{aligned}
x_1 &\sim \Beta(α, β) \,, \\
Expand All @@ -205,15 +205,15 @@ Here $ψ$ and $ψ_1$ are the digamma and trigamma functions respectively.
Since we want the sum to be $d := \lnLh(Φ+2^{-n+1}) - \lnLh(Φ)$, we define
```{math}
:label: eq_relation-beta-increment
\bigl[Δ l_{2^{-n}}\bigl(Φ\bigr),\, Δ l_{2^{-n}}\bigl(Φ+2^{-n})\bigr)\bigr] = d \bigl[x_1, x_2\bigr] \,.
\bigl[Δ q_{2^{-n}}\bigl(Φ\bigr),\, Δ q_{2^{-n}}\bigl(Φ+2^{-n})\bigr)\bigr] = d \bigl[x_1, x_2\bigr] \,.
```
Then

+++

$$\begin{aligned}
\EE_a\Bigl[\bigl[Δ l_{2^{-n}}\bigl(Φ\bigr),\, Δ l_{2^{-n}}\bigl(Φ+2^{-n}\bigr)\bigr]\Bigr] &= \frac{d}{e^{ψ(α)} + e^{ψ(β)}} \bigl[e^{ψ(α)}, e^{ψ(β)}\bigr] \,, \\
\Mvar\Bigl[\bigl[Δ l_{2^{-n}}\bigl(Φ\bigr),\, Δ l_{2^{-n}}\bigl(Φ+2^{-n}\bigr)\bigr]\Bigr] &= \frac{1}{2} \bigl(ψ_1(α) + ψ_1(β)\bigr) \,.
\EE_a\Bigl[\bigl[Δ q_{2^{-n}}\bigl(Φ\bigr),\, Δ q_{2^{-n}}\bigl(Φ+2^{-n}\bigr)\bigr]\Bigr] &= \frac{d}{e^{ψ(α)} + e^{ψ(β)}} \bigl[e^{ψ(α)}, e^{ψ(β)}\bigr] \,, \\
\Mvar\Bigl[\bigl[Δ q_{2^{-n}}\bigl(Φ\bigr),\, Δ q_{2^{-n}}\bigl(Φ+2^{-n}\bigr)\bigr]\Bigr] &= \frac{1}{2} \bigl(ψ_1(α) + ψ_1(β)\bigr) \,.
\end{aligned}$$

+++
Expand All @@ -223,8 +223,8 @@ We now choose to define the parameters $α$ and $β$ via the following relations
:class: important

$$\begin{aligned}
\EE_a\Bigl[\bigl[Δ l_{2^{-n}}\bigl(Φ\bigr),\, Δ l_{2^{-n}}\bigl(Φ+2^{-n}\bigr)\bigr]\Bigr] &\stackrel{!}{=}^* \bigl[\, \lnLtt\bigl(Φ+2^{-n}\bigr) - \lnLtt\bigl(Φ\bigr),\,\lnLtt\bigl(Φ+2^{-n+1}\bigr) - \lnLtt\bigl(Φ+2^{-n}\bigr) \,\bigr]\,, \\
\Mvar\Bigl[\bigl[Δ l_{2^{-n}}\bigl(Φ\bigr),\, Δ l_{2^{-n}}\bigl(Φ+2^{-n}\bigr)\bigr]\Bigr] &\stackrel{!}{=} \emdstd\bigl(Φ+2^{-n}\bigr)^2 \,.
\EE_a\Bigl[\bigl[Δ q_{2^{-n}}\bigl(Φ\bigr),\, Δ q_{2^{-n}}\bigl(Φ+2^{-n}\bigr)\bigr]\Bigr] &\stackrel{!}{=}^* \bigl[\, \lnLtt\bigl(Φ+2^{-n}\bigr) - \lnLtt\bigl(Φ\bigr),\,\lnLtt\bigl(Φ+2^{-n+1}\bigr) - \lnLtt\bigl(Φ+2^{-n}\bigr) \,\bigr]\,, \\
\Mvar\Bigl[\bigl[Δ q_{2^{-n}}\bigl(Φ\bigr),\, Δ q_{2^{-n}}\bigl(Φ+2^{-n}\bigr)\bigr]\Bigr] &\stackrel{!}{=} \emdstd\bigl(Φ+2^{-n}\bigr)^2 \,.
\end{aligned}$$ (eq_defining-conditions-a)
:::
Expand All @@ -236,7 +236,7 @@ We use $=^*$ to indicate equality in spirit rather than true equality, since str
:::{admonition}  
:class: important
$$\frac{\EE_a\bigl[Δ l_{2^{-n}}\bigl(Φ\bigr)\bigr]}{\EE_a \bigl[Δ l_{2^{-n}}\bigl(Φ+2^{-n}\bigr)\bigr]} \stackrel{!}{=} \frac{\lnLtt\bigl(Φ+2^{-n}\bigr) - \lnLtt\bigl(Φ\bigr)}{\lnLtt\bigl(Φ+2^{-n+1}\bigr) - \lnLtt\bigl(Φ+2^{-n}\bigr)} \,.$$ (eq_defining_conditions-b)
$$\frac{\EE_a\bigl[Δ q_{2^{-n}}\bigl(Φ\bigr)\bigr]}{\EE_a \bigl[Δ q_{2^{-n}}\bigl(Φ+2^{-n}\bigr)\bigr]} \stackrel{!}{=} \frac{\lnLtt\bigl(Φ+2^{-n}\bigr) - \lnLtt\bigl(Φ\bigr)}{\lnLtt\bigl(Φ+2^{-n+1}\bigr) - \lnLtt\bigl(Φ+2^{-n}\bigr)} \,.$$ (eq_defining_conditions-b)
:::
+++
Expand All @@ -248,13 +248,13 @@ $$\frac{\EE_a\bigl[Δ l_{2^{-n}}\bigl(Φ\bigr)\bigr]}{\EE_a \bigl[Δ l_{2^{-n}}\
```
- The stochastic process is not Markovian, so successive increments are not independent. The variance of a larger increment therefore need not equal the sum of the variance of constituent smaller ones; in other words,
```{math}
Δ l_{2^{-n+1}}\bigl(Φ\bigr) = Δ l_{2^{-n}}\bigl(Φ\bigr) + Δ l_{2^{-n}}\bigl(Φ+2^{-n}\bigr)
Δ q_{2^{-n+1}}\bigl(Φ\bigr) = Δ q_{2^{-n}}\bigl(Φ\bigr) + Δ q_{2^{-n}}\bigl(Φ+2^{-n}\bigr)
```
does *not* imply
```{math}
\VV\bigl[Δ l_{2^{-n+1}}\bigl(Φ\bigr)\bigr] = \VV\bigl[Δ l_{2^{-n}}\bigl(Φ\bigr)\bigr] + \VV\bigl[Δ l_{2^{-n}}\bigl(Φ+2^{-n}\bigr)\bigr]\,.
\VV\bigl[Δ q_{2^{-n+1}}\bigl(Φ\bigr)\bigr] = \VV\bigl[Δ q_{2^{-n}}\bigl(Φ\bigr)\bigr] + \VV\bigl[Δ q_{2^{-n}}\bigl(Φ+2^{-n}\bigr)\bigr]\,.
```
- Our defining equations make equivalent use of the pre ($Δ l_{2^{-n}}(Φ)$) and post ($Δ l_{2^{-n}}(Φ+2^{-n})$) increments, thus preserving symmetry in $Φ$.
- Our defining equations make equivalent use of the pre ($Δ q_{2^{-n}}(Φ)$) and post ($Δ q_{2^{-n}}(Φ+2^{-n})$) increments, thus preserving symmetry in $Φ$.
- Step sizes of the form $2^{-n}$ have exact representations in binary. Thus even small step sizes should not introduce additional numerical errors.
+++
Expand All @@ -273,7 +273,7 @@ r &:= \frac{\lnLtt(Φ+2^{-n}) - \lnLtt(Φ)}{\lnLtt(Φ+2^{-n+1}) - \lnLtt(Φ+2^{-
v &:= 2 \emdstd\bigl(Φ + 2^{-n}\bigr)^2 \,.
\end{align}$$ (eq_def-r-v)
:::
The first value, $r$, is the ratio of two subincrements within $Δ l_{2^{-n+1}}(Φ)$.
The first value, $r$, is the ratio of two subincrements within $Δ q_{2^{-n+1}}(Φ)$.
Setting $\frac{e^{ψ(α)}}{e^{ψ(β)}} = r$, the two equations we need to solve for $α$ and $β$ can be written
```{math}
:label: eq_root-finding-problem
Expand Down Expand Up @@ -447,11 +447,11 @@ For extreme values of $r$ or $v$, the beta distribution becomes degenerate and n
$\boldsymbol{r \to 0}$
^^^
The corresponds to stating that $Δ l_{2^{-n}}(Φ)$ is infinitely smaller than $Δ l_{2^{-n}}(Φ+2^{-n})$. Thus we set $x_1 = 1$, which is equivalent to setting
The corresponds to stating that $Δ q_{2^{-n}}(Φ)$ is infinitely smaller than $Δ q_{2^{-n}}(Φ+2^{-n})$. Thus we set $x_1 = 1$, which is equivalent to setting
$$\begin{aligned}
Δ l_{2^{-n}}(Φ) &= 0 \,, \\
Δ l_{2^{-n}}(Φ+2^{-n}) &= \lnLtt(Φ+2^{-n+1}) - \lnLtt(Φ) \,.
Δ q_{2^{-n}}(Φ) &= 0 \,, \\
Δ q_{2^{-n}}(Φ+2^{-n}) &= \lnLtt(Φ+2^{-n+1}) - \lnLtt(Φ) \,.
\end{aligned}$$

:::
Expand All @@ -462,7 +462,7 @@ $$\begin{aligned}
$\boldsymbol{r \to \infty}$
^^^

The converse of the previous case: $Δ l_{2^{-n}}(Φ)$ is infinitely larger than $Δ l_{2^{-n}}(Φ+2^{-n})$. We set $x_1 = 0$.
The converse of the previous case: $Δ q_{2^{-n}}(Φ)$ is infinitely larger than $Δ q_{2^{-n}}(Φ+2^{-n})$. We set $x_1 = 0$.

:::

Expand Down
Loading

0 comments on commit b7153ac

Please sign in to comment.