Skip to content
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

Fix examples in docs of mixture.py, bound.py and continuous.py #2809

Merged
merged 2 commits into from
Jan 19, 2018
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
14 changes: 8 additions & 6 deletions pymc3/distributions/bound.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,15 @@ class Bound(object):

Examples
--------
with pm.Model():
NegativeNormal = pm.Bound(pm.Normal, upper=0.0)
par1 = NegativeNormal('par2', mu=0.0, sd=1.0, testval=1.0)
.. code-block:: python

# or you can define it implicitly within the model context
par2 = pm.Bound(pm.Normal, lower=-1.0, upper=1.0)(
'par2', mu=0.0, sd=1.0, testval=1.0)
with pm.Model():
NegativeNormal = pm.Bound(pm.Normal, upper=0.0)
par1 = NegativeNormal('par2', mu=0.0, sd=1.0, testval=1.0)

# or you can define it implicitly within the model context
par2 = pm.Bound(pm.Normal, lower=-1.0, upper=1.0)(
'par2', mu=0.0, sd=1.0, testval=1.0)
"""

def __init__(self, distribution, lower=None, upper=None):
Expand Down
62 changes: 36 additions & 26 deletions pymc3/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,13 @@ class Normal(Continuous):

Examples
--------
with pm.Model():
x = pm.Normal('x', mu=0, sd=10)

with pm.Model():
x = pm.Normal('x', mu=0, tau=1/23)
.. code-block:: python

with pm.Model():
x = pm.Normal('x', mu=0, sd=10)

with pm.Model():
x = pm.Normal('x', mu=0, tau=1/23)
"""

def __init__(self, mu=0, sd=None, tau=None, **kwargs):
Expand Down Expand Up @@ -362,11 +364,13 @@ class HalfNormal(PositiveContinuous):

Examples
--------
with pm.Model():
x = pm.HalfNormal('x', sd=10)

with pm.Model():
x = pm.HalfNormal('x', tau=1/15)
.. code-block:: python

with pm.Model():
x = pm.HalfNormal('x', sd=10)

with pm.Model():
x = pm.HalfNormal('x', tau=1/15)
"""

def __init__(self, sd=None, tau=None, *args, **kwargs):
Expand Down Expand Up @@ -861,12 +865,14 @@ class Lognormal(PositiveContinuous):

Example
-------
# Example to show that we pass in only `sd` or `tau` but not both.
with pm.Model():
x = pm.Lognormal('x', mu=2, sd=30)
.. code-block:: python

with pm.Model():
x = pm.Lognormal('x', mu=2, tau=1/100)
# Example to show that we pass in only `sd` or `tau` but not both.
with pm.Model():
x = pm.Lognormal('x', mu=2, sd=30)

with pm.Model():
x = pm.Lognormal('x', mu=2, tau=1/100)
"""

def __init__(self, mu=0, sd=None, tau=None, *args, **kwargs):
Expand Down Expand Up @@ -964,11 +970,13 @@ class StudentT(Continuous):

Examples
--------
with pm.Model():
x = pm.StudentT('x', nu=15, mu=0, sd=10)

with pm.Model():
x = pm.StudentT('x', nu=15, mu=0, lam=1/23)
.. code-block:: python

with pm.Model():
x = pm.StudentT('x', nu=15, mu=0, sd=10)

with pm.Model():
x = pm.StudentT('x', nu=15, mu=0, lam=1/23)
"""

def __init__(self, nu, mu=0, lam=None, sd=None, *args, **kwargs):
Expand Down Expand Up @@ -1633,12 +1641,14 @@ class HalfStudentT(PositiveContinuous):

Examples
--------
# Only pass in one of lam or sd, but not both.
with pm.Model():
x = pm.HalfStudentT('x', sd=10, nu=10)

with pm.Model():
x = pm.HalfStudentT('x', lam=4, nu=10)
.. code-block:: python

# Only pass in one of lam or sd, but not both.
with pm.Model():
x = pm.HalfStudentT('x', sd=10, nu=10)

with pm.Model():
x = pm.HalfStudentT('x', lam=4, nu=10)
"""
def __init__(self, nu=1, sd=None, lam=None, *args, **kwargs):
super(HalfStudentT, self).__init__(*args, **kwargs)
Expand Down
32 changes: 17 additions & 15 deletions pymc3/distributions/mixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,30 @@ class Mixture(Distribution):

Example
-------
# 2-Mixture Poisson distribution
with pm.Model() as model:
lam = pm.Exponential('lam', lam=1, shape=(2,)) # `shape=(2,)` indicates two mixtures.
.. code-block:: python

# As we just need the logp, rather than add a RV to the model, we need to call .dist()
components = pm.Poisson.dist(mu=lam, shape=(2,))
# 2-Mixture Poisson distribution
with pm.Model() as model:
lam = pm.Exponential('lam', lam=1, shape=(2,)) # `shape=(2,)` indicates two mixtures.

w = pm.Dirichlet('w', a=np.array([1, 1])) # two mixture component weights.
# As we just need the logp, rather than add a RV to the model, we need to call .dist()
components = pm.Poisson.dist(mu=lam, shape=(2,))

like = pm.Mixture('like', w=w, comp_dists=components, observed=data)
w = pm.Dirichlet('w', a=np.array([1, 1])) # two mixture component weights.

# 2-Mixture Poisson using iterable of distributions.
with pm.Model() as model:
lam1 = pm.Exponential('lam1', lam=1)
lam2 = pm.Exponential('lam2', lam=1)
like = pm.Mixture('like', w=w, comp_dists=components, observed=data)

pois1 = pm.Poisson.dist(mu=lam1)
pois2 = pm.Poisson.dist(mu=lam2)
# 2-Mixture Poisson using iterable of distributions.
with pm.Model() as model:
lam1 = pm.Exponential('lam1', lam=1)
lam2 = pm.Exponential('lam2', lam=1)

w = pm.Dirichlet('w', a=np.array([1, 1]))
pois1 = pm.Poisson.dist(mu=lam1)
pois2 = pm.Poisson.dist(mu=lam2)

like = pm.Mixture('like', w=w, comp_dists = [pois1, pois2], observed=data)
w = pm.Dirichlet('w', a=np.array([1, 1]))

like = pm.Mixture('like', w=w, comp_dists = [pois1, pois2], observed=data)
"""
def __init__(self, w, comp_dists, *args, **kwargs):
shape = kwargs.pop('shape', ())
Expand Down