Skip to content

Commit

Permalink
Fix examples in docs of mixture.py, bound.py and continuous.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sharanry committed Jan 18, 2018
1 parent 90215a8 commit 37eec80
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 48 deletions.
15 changes: 8 additions & 7 deletions pymc3/distributions/bound.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,14 @@ 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)
# 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)
.. code-block:: python
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
57 changes: 31 additions & 26 deletions pymc3/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,12 @@ 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 +363,12 @@ 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 +863,13 @@ 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
# 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)
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 +967,12 @@ 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 +1637,13 @@ 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
31 changes: 16 additions & 15 deletions pymc3/distributions/mixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,29 @@ 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
# 2-Mixture Poisson distribution
with pm.Model() as model:
lam = pm.Exponential('lam', lam=1, shape=(2,)) # `shape=(2,)` indicates two mixtures.
# 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,))
# 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,))
w = pm.Dirichlet('w', a=np.array([1, 1])) # two mixture component weights.
w = pm.Dirichlet('w', a=np.array([1, 1])) # two mixture component weights.
like = pm.Mixture('like', w=w, comp_dists=components, observed=data)
like = pm.Mixture('like', w=w, comp_dists=components, observed=data)
# 2-Mixture Poisson using iterable of distributions.
with pm.Model() as model:
lam1 = pm.Exponential('lam1', lam=1)
lam2 = pm.Exponential('lam2', lam=1)
# 2-Mixture Poisson using iterable of distributions.
with pm.Model() as model:
lam1 = pm.Exponential('lam1', lam=1)
lam2 = pm.Exponential('lam2', lam=1)
pois1 = pm.Poisson.dist(mu=lam1)
pois2 = pm.Poisson.dist(mu=lam2)
pois1 = pm.Poisson.dist(mu=lam1)
pois2 = pm.Poisson.dist(mu=lam2)
w = pm.Dirichlet('w', a=np.array([1, 1]))
w = pm.Dirichlet('w', a=np.array([1, 1]))
like = pm.Mixture('like', w=w, comp_dists = [pois1, pois2], observed=data)
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

0 comments on commit 37eec80

Please sign in to comment.