Skip to content

Add Normal mixture example, fixup check_toc script #4294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ repos:
entry: python scripts/check_toc_is_complete.py
language: python
name: Check all notebooks appear in table of contents
pass_filenames: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad here, I erroneously added this in #4262 😳 This script does take file names though (via argparse)

types: [jupyter]
- id: check-no-tests-are-ignored
entry: python scripts/check_all_tests_are_covered.py
Expand Down
24 changes: 23 additions & 1 deletion pymc3/distributions/mixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,29 @@ class NormalMixture(Mixture):
of the mixture distribution, with one axis being
the number of components.

Note: You only have to pass in sigma or tau, but not both.
Notes
-----
You only have to pass in sigma or tau, but not both.

Examples
--------
.. code-block:: python

n_components = 3

with pm.Model() as gauss_mix:
μ = pm.Normal(
"μ",
data.mean(),
10,
shape=n_components,
transform=pm.transforms.ordered,
testval=[1, 2, 3],
)
σ = pm.HalfNormal("σ", 10, shape=n_components)
weights = pm.Dirichlet("w", np.ones(n_components))

pm.NormalMixture("y", w=weights, mu=μ, sigma=σ, observed=data)
"""

def __init__(self, w, mu, sigma=None, tau=None, sd=None, comp_shape=(), *args, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions scripts/check_toc_is_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
You can run it manually with `pre-commit run check-toc --all`.
"""

import json
from pathlib import Path
import argparse
import ast
Comment on lines -8 to +10
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these aren't sorted, but their order will be sorted out with #4239 (which needs to have upstream/master merged anyway)


if __name__ == "__main__":
toc_examples = (Path("docs") / "source/notebooks/table_of_contents_examples.js").read_text()
toc_tutorials = (Path("docs") / "source/notebooks/table_of_contents_tutorials.js").read_text()
toc_keys = {
**json.loads(toc_examples[toc_examples.find("{") :]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was wrong with th eold way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you included a trailing comma then you'd get a mysterious

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 69 column 1 (char 3689)

, while ast.literal_eval can handle trailing commas

**json.loads(toc_tutorials[toc_tutorials.find("{") :]),
**ast.literal_eval(toc_examples[toc_examples.find("{") :]),
**ast.literal_eval(toc_tutorials[toc_tutorials.find("{") :]),
}.keys()
parser = argparse.ArgumentParser()
parser.add_argument("filenames", nargs="*")
Expand Down