Skip to content

Commit

Permalink
Styling (#13)
Browse files Browse the repository at this point in the history
* Fix docs

* Fix docs

* Fix docs

---------

Co-authored-by: Thomas Pinder <pinthoma@amazon.com>
  • Loading branch information
thomaspinder and Thomas Pinder authored Sep 9, 2024
1 parent 1cbb1e1 commit 7507996
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 42 deletions.
17 changes: 12 additions & 5 deletions docs/examples/azcausal.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"\n",
"linear_trend = Trend(degree=1, coefficient=0.05)\n",
"data = linear_trend(simulate(cfg))\n",
"plot(data)"
"ax = plot(data)"
]
},
{
Expand All @@ -76,7 +76,7 @@
"TRUE_EFFECT = 0.05\n",
"effect = StaticEffect(effect=TRUE_EFFECT)\n",
"inflated_data = effect(data)\n",
"plot(inflated_data)"
"ax = plot(inflated_data)"
]
},
{
Expand Down Expand Up @@ -121,14 +121,18 @@
"in effort to fully stress-test any new model and identify its limitations.\n",
"\n",
"To achieve this, we'll simulate 10 control units, 60 pre-intervention time points, and\n",
"30 post-intervention time points according to the following process: $$ \\begin{align}\n",
"30 post-intervention time points according to the following process: \n",
"\n",
"$$ \\begin{align}\n",
"\\mu_{n, t} & \\sim\\mathcal{N}(20, 0.5^2)\\\\\n",
"\\alpha_{n} & \\sim \\mathcal{N}(0, 1^2)\\\\\n",
"\\beta_{n} & \\sim \\mathcal{N}(0.05, 0.01^2)\\\\\n",
"\\nu_n & \\sim \\mathcal{N}(1, 1^2)\\\\\n",
"\\gamma_n & \\sim \\operatorname{Student-t}_{10}(1, 1^2)\\\\\n",
"\\mathbf{Y}_{n, t} & = \\mu_{n, t} + \\alpha_{n} + \\beta_{n}t + \\nu_n\\sin\\left(3\\times\n",
"2\\pi t + \\gamma\\right) + \\delta_{t, n} \\end{align} $$ where the true treatment effect\n",
"2\\pi t + \\gamma\\right) + \\delta_{t, n} \\end{align} $$ \n",
"\n",
"where the true treatment effect\n",
"$\\delta_{t, n}$ is 5% when $n=1$ and $t\\geq 60$ and 0 otherwise. Meanwhile,\n",
"$\\mathbf{Y}$ is the matrix of observations, long in the number of time points and wide\n",
"in the number of units."
Expand Down Expand Up @@ -159,7 +163,7 @@
"periodic = Periodic(amplitude=amplitude, shift=shift, frequency=3)\n",
"\n",
"data = effect(periodic(linear_trend(simulate(cfg))))\n",
"plot(data)"
"ax = plot(data)"
]
},
{
Expand Down Expand Up @@ -193,6 +197,9 @@
"cell_metadata_filter": "title,-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
Expand Down
28 changes: 15 additions & 13 deletions docs/examples/basic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
")\n",
"\n",
"data = simulate(cfg)\n",
"plot(data)"
"ax = plot(data)"
]
},
{
Expand Down Expand Up @@ -113,7 +113,7 @@
" global_scale=s,\n",
" )\n",
" data = simulate(cfg)\n",
" plot(data, ax=ax, title=f\"Mean: {m}, Scale: {s}\")"
" _ = plot(data, ax=ax, title=f\"Mean: {m}, Scale: {s}\")"
]
},
{
Expand Down Expand Up @@ -162,7 +162,7 @@
"fig, axes = plt.subplots(ncols=2, figsize=(10, 3))\n",
"for ax in axes:\n",
" data = simulate(cfg)\n",
" plot(data, ax=ax)"
" _ = plot(data, ax=ax)"
]
},
{
Expand All @@ -180,13 +180,12 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"rng = np.random.RandomState(42)\n",
"\n",
"fig, axes = plt.subplots(ncols=2, figsize=(10, 3))\n",
"for ax in axes:\n",
" data = simulate(cfg, key=rng)\n",
" plot(data, ax=ax)"
" _ = plot(data, ax=ax)"
]
},
{
Expand All @@ -213,8 +212,8 @@
"effect = StaticEffect(effect=0.02)\n",
"inflated_data = effect(data)\n",
"fig, (ax0, ax1) = plt.subplots(ncols=2, figsize=(10, 3))\n",
"plot(data, ax=ax0, title=\"Original data\")\n",
"plot(inflated_data, ax=ax1, title=\"Inflated data\")"
"ax0 = plot(data, ax=ax0, title=\"Original data\")\n",
"ax1 = plot(inflated_data, ax=ax1, title=\"Inflated data\")"
]
},
{
Expand All @@ -238,7 +237,7 @@
"source": [
"trend_term = Trend(degree=1, coefficient=0.1)\n",
"data_with_trend = effect(trend_term(data))\n",
"plot(data_with_trend)"
"ax = plot(data_with_trend)"
]
},
{
Expand All @@ -250,7 +249,7 @@
"source": [
"trend_term = Trend(degree=2, coefficient=0.0025)\n",
"data_with_trend = effect(trend_term(data))\n",
"plot(data_with_trend)"
"ax = plot(data_with_trend)"
]
},
{
Expand All @@ -270,7 +269,7 @@
"source": [
"periodicity = Periodic(amplitude=2, frequency=6)\n",
"perioidic_data = effect(periodicity(trend_term(data)))\n",
"plot(perioidic_data)"
"ax = plot(perioidic_data)"
]
},
{
Expand All @@ -292,7 +291,7 @@
"intercept = UnitVaryingParameter(sampling_dist=sampling_dist)\n",
"trend_term = Trend(degree=1, intercept=intercept, coefficient=0.1)\n",
"data_with_trend = effect(trend_term(data))\n",
"plot(data_with_trend)"
"ax = plot(data_with_trend)"
]
},
{
Expand All @@ -306,7 +305,7 @@
"frequency = UnitVaryingParameter(sampling_dist=sampling_dist)\n",
"\n",
"p = Periodic(frequency=frequency)\n",
"plot(p(data))"
"ax = plot(p(data))"
]
},
{
Expand All @@ -322,7 +321,7 @@
"variation. In a follow-up notebook, we show how these datasets may be integrated with\n",
"Amazon's own AZCausal library to compare the effect estimated by a model with the true\n",
"effect of the underlying data generating process. A link to this notebook is\n",
"[here](https://github.com/amazon-science/causal-validation/blob/main/examples/azcausal.pct.py)."
"[here](http://localhost:9998/causal-validation/examples/azcausal/)."
]
}
],
Expand All @@ -331,6 +330,9 @@
"cell_metadata_filter": "title,-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/placebo_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"TRUE_EFFECT = 0.05\n",
"effect = StaticEffect(effect=TRUE_EFFECT)\n",
"data = effect(simulate(cfg))\n",
"plot(data)"
"ax = plot(data)"
]
},
{
Expand Down
44 changes: 22 additions & 22 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@

The latest stable release of `causal-validation` can be installed via `pip`:

```bash
``` bash
pip install causal-validation
```

!!! note "Check your installation"
We recommend you check your installation version:
```
python -c 'import causal_validation; print(causal_validation.__version__)'
```
We recommend you check your installation version:

``` bash
python -c 'import causal_validation; print(causal_validation.__version__)'
```

## Development version

!!! warning
This version is possibly unstable and may contain bugs.

The latest development version of `causal_validation` can be installed via running following:

```bash
git clone git@github.com:amazon-science/causal-validation.git
cd causal-validation
hatch shell create
```
The latest development version of `causal_validation` can be installed via running following:

!!! tip
We advise you create virtual environment before installing:
``` bash
git clone git@github.com:amazon-science/causal-validation.git;
cd causal-validation;
hatch shell create
```

```bash
conda create -n causal-validation python=3.11.0
conda activate causal-validation
```
We advise you create virtual environment before installing:

``` bash
conda create -n causal-validation python=3.11.0;
conda activate causal-validation
```

and recommend you check your installation passes the supplied unit tests:
and recommend you check your installation passes the supplied unit tests:

```bash
hatch run dev:test
```
``` bash
hatch run dev:test
```
19 changes: 19 additions & 0 deletions docs/javascripts/mathjax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
window.MathJax = {
tex: {
inlineMath: [["\\(", "\\)"]],
displayMath: [["\\[", "\\]"]],
processEscapes: true,
processEnvironments: true
},
options: {
ignoreHtmlClass: ".*|",
processHtmlClass: "arithmatex"
}
};

document$.subscribe(() => {
MathJax.startup.output.clearCache()
MathJax.typesetClear()
MathJax.texReset()
MathJax.typesetPromise()
})
9 changes: 9 additions & 0 deletions docs/stylesheets/extra.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[data-md-color-scheme="reds"] {
--md-primary-fg-color: #b5121b;
--md-primary-fg-color--light: #ECB7B7;
--md-primary-fg-color--dark: #7d030b;
}

/* :root > * { */
/* --md-code-bg-color: #0FF1CE; */
/* } */
20 changes: 20 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,23 @@ theme:
- navigation.sections
- search.suggest
- content.code.copy
palette:
scheme: reds

markdown_extensions:
- abbr
- admonition
- pymdownx.superfences
- pymdownx.inlinehilite
- pymdownx.arithmatex:
generic: true
- pymdownx.highlight:
anchor_linenums: true
line_spans: __span
use_pygments: true
pygments_lang_class: true
pygments_style: autumn
noclasses: true

plugins:
- search
Expand All @@ -35,5 +48,12 @@ extra:
version:
provider: mike

extra_css:
- stylesheets/extra.css

extra_javascript:
- javascripts/mathjax.js
- https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js

watch:
- src
2 changes: 1 addition & 1 deletion src/causal_validation/__about__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.0.5"
__version__ = "0.0.6"

__all__ = ["__version__"]

0 comments on commit 7507996

Please sign in to comment.