Skip to content

Commit df3ae60

Browse files
authored
Add Normal mixture example, fixup check_toc script (#4294)
* add gaussian mixture example * update check-toc script
1 parent 9311899 commit df3ae60

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ repos:
4141
entry: python scripts/check_toc_is_complete.py
4242
language: python
4343
name: Check all notebooks appear in table of contents
44-
pass_filenames: false
4544
types: [jupyter]
4645
- id: check-no-tests-are-ignored
4746
entry: python scripts/check_all_tests_are_covered.py

pymc3/distributions/mixture.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,29 @@ class NormalMixture(Mixture):
602602
of the mixture distribution, with one axis being
603603
the number of components.
604604
605-
Note: You only have to pass in sigma or tau, but not both.
605+
Notes
606+
-----
607+
You only have to pass in sigma or tau, but not both.
608+
609+
Examples
610+
--------
611+
.. code-block:: python
612+
613+
n_components = 3
614+
615+
with pm.Model() as gauss_mix:
616+
μ = pm.Normal(
617+
"μ",
618+
data.mean(),
619+
10,
620+
shape=n_components,
621+
transform=pm.transforms.ordered,
622+
testval=[1, 2, 3],
623+
)
624+
σ = pm.HalfNormal("σ", 10, shape=n_components)
625+
weights = pm.Dirichlet("w", np.ones(n_components))
626+
627+
pm.NormalMixture("y", w=weights, mu=μ, sigma=σ, observed=data)
606628
"""
607629

608630
def __init__(self, w, mu, sigma=None, tau=None, sd=None, comp_shape=(), *args, **kwargs):

scripts/check_toc_is_complete.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
You can run it manually with `pre-commit run check-toc --all`.
66
"""
77

8-
import json
98
from pathlib import Path
109
import argparse
10+
import ast
1111

1212
if __name__ == "__main__":
1313
toc_examples = (Path("docs") / "source/notebooks/table_of_contents_examples.js").read_text()
1414
toc_tutorials = (Path("docs") / "source/notebooks/table_of_contents_tutorials.js").read_text()
1515
toc_keys = {
16-
**json.loads(toc_examples[toc_examples.find("{") :]),
17-
**json.loads(toc_tutorials[toc_tutorials.find("{") :]),
16+
**ast.literal_eval(toc_examples[toc_examples.find("{") :]),
17+
**ast.literal_eval(toc_tutorials[toc_tutorials.find("{") :]),
1818
}.keys()
1919
parser = argparse.ArgumentParser()
2020
parser.add_argument("filenames", nargs="*")

0 commit comments

Comments
 (0)