Skip to content

Commit 1e2a0c3

Browse files
sharanryColCarroll
authored andcommitted
Fix examples in docs of mixture.py, bound.py and continuous.py (#2809)
* Fix examples in docs of mixture.py, bound.py and continuous.py * Add empty line after code-block
1 parent 3a09ee2 commit 1e2a0c3

File tree

3 files changed

+61
-47
lines changed

3 files changed

+61
-47
lines changed

pymc3/distributions/bound.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,15 @@ class Bound(object):
176176
177177
Examples
178178
--------
179-
with pm.Model():
180-
NegativeNormal = pm.Bound(pm.Normal, upper=0.0)
181-
par1 = NegativeNormal('par2', mu=0.0, sd=1.0, testval=1.0)
179+
.. code-block:: python
182180
183-
# or you can define it implicitly within the model context
184-
par2 = pm.Bound(pm.Normal, lower=-1.0, upper=1.0)(
185-
'par2', mu=0.0, sd=1.0, testval=1.0)
181+
with pm.Model():
182+
NegativeNormal = pm.Bound(pm.Normal, upper=0.0)
183+
par1 = NegativeNormal('par2', mu=0.0, sd=1.0, testval=1.0)
184+
185+
# or you can define it implicitly within the model context
186+
par2 = pm.Bound(pm.Normal, lower=-1.0, upper=1.0)(
187+
'par2', mu=0.0, sd=1.0, testval=1.0)
186188
"""
187189

188190
def __init__(self, distribution, lower=None, upper=None):

pymc3/distributions/continuous.py

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,13 @@ class Normal(Continuous):
275275
276276
Examples
277277
--------
278-
with pm.Model():
279-
x = pm.Normal('x', mu=0, sd=10)
280-
281-
with pm.Model():
282-
x = pm.Normal('x', mu=0, tau=1/23)
278+
.. code-block:: python
279+
280+
with pm.Model():
281+
x = pm.Normal('x', mu=0, sd=10)
282+
283+
with pm.Model():
284+
x = pm.Normal('x', mu=0, tau=1/23)
283285
"""
284286

285287
def __init__(self, mu=0, sd=None, tau=None, **kwargs):
@@ -362,11 +364,13 @@ class HalfNormal(PositiveContinuous):
362364
363365
Examples
364366
--------
365-
with pm.Model():
366-
x = pm.HalfNormal('x', sd=10)
367-
368-
with pm.Model():
369-
x = pm.HalfNormal('x', tau=1/15)
367+
.. code-block:: python
368+
369+
with pm.Model():
370+
x = pm.HalfNormal('x', sd=10)
371+
372+
with pm.Model():
373+
x = pm.HalfNormal('x', tau=1/15)
370374
"""
371375

372376
def __init__(self, sd=None, tau=None, *args, **kwargs):
@@ -861,12 +865,14 @@ class Lognormal(PositiveContinuous):
861865
862866
Example
863867
-------
864-
# Example to show that we pass in only `sd` or `tau` but not both.
865-
with pm.Model():
866-
x = pm.Lognormal('x', mu=2, sd=30)
868+
.. code-block:: python
867869
868-
with pm.Model():
869-
x = pm.Lognormal('x', mu=2, tau=1/100)
870+
# Example to show that we pass in only `sd` or `tau` but not both.
871+
with pm.Model():
872+
x = pm.Lognormal('x', mu=2, sd=30)
873+
874+
with pm.Model():
875+
x = pm.Lognormal('x', mu=2, tau=1/100)
870876
"""
871877

872878
def __init__(self, mu=0, sd=None, tau=None, *args, **kwargs):
@@ -964,11 +970,13 @@ class StudentT(Continuous):
964970
965971
Examples
966972
--------
967-
with pm.Model():
968-
x = pm.StudentT('x', nu=15, mu=0, sd=10)
969-
970-
with pm.Model():
971-
x = pm.StudentT('x', nu=15, mu=0, lam=1/23)
973+
.. code-block:: python
974+
975+
with pm.Model():
976+
x = pm.StudentT('x', nu=15, mu=0, sd=10)
977+
978+
with pm.Model():
979+
x = pm.StudentT('x', nu=15, mu=0, lam=1/23)
972980
"""
973981

974982
def __init__(self, nu, mu=0, lam=None, sd=None, *args, **kwargs):
@@ -1636,12 +1644,14 @@ class HalfStudentT(PositiveContinuous):
16361644
16371645
Examples
16381646
--------
1639-
# Only pass in one of lam or sd, but not both.
1640-
with pm.Model():
1641-
x = pm.HalfStudentT('x', sd=10, nu=10)
1642-
1643-
with pm.Model():
1644-
x = pm.HalfStudentT('x', lam=4, nu=10)
1647+
.. code-block:: python
1648+
1649+
# Only pass in one of lam or sd, but not both.
1650+
with pm.Model():
1651+
x = pm.HalfStudentT('x', sd=10, nu=10)
1652+
1653+
with pm.Model():
1654+
x = pm.HalfStudentT('x', lam=4, nu=10)
16451655
"""
16461656
def __init__(self, nu=1, sd=None, lam=None, *args, **kwargs):
16471657
super(HalfStudentT, self).__init__(*args, **kwargs)

pymc3/distributions/mixture.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,30 @@ class Mixture(Distribution):
4242
4343
Example
4444
-------
45-
# 2-Mixture Poisson distribution
46-
with pm.Model() as model:
47-
lam = pm.Exponential('lam', lam=1, shape=(2,)) # `shape=(2,)` indicates two mixtures.
45+
.. code-block:: python
4846
49-
# As we just need the logp, rather than add a RV to the model, we need to call .dist()
50-
components = pm.Poisson.dist(mu=lam, shape=(2,))
47+
# 2-Mixture Poisson distribution
48+
with pm.Model() as model:
49+
lam = pm.Exponential('lam', lam=1, shape=(2,)) # `shape=(2,)` indicates two mixtures.
5150
52-
w = pm.Dirichlet('w', a=np.array([1, 1])) # two mixture component weights.
51+
# As we just need the logp, rather than add a RV to the model, we need to call .dist()
52+
components = pm.Poisson.dist(mu=lam, shape=(2,))
5353
54-
like = pm.Mixture('like', w=w, comp_dists=components, observed=data)
54+
w = pm.Dirichlet('w', a=np.array([1, 1])) # two mixture component weights.
5555
56-
# 2-Mixture Poisson using iterable of distributions.
57-
with pm.Model() as model:
58-
lam1 = pm.Exponential('lam1', lam=1)
59-
lam2 = pm.Exponential('lam2', lam=1)
56+
like = pm.Mixture('like', w=w, comp_dists=components, observed=data)
6057
61-
pois1 = pm.Poisson.dist(mu=lam1)
62-
pois2 = pm.Poisson.dist(mu=lam2)
58+
# 2-Mixture Poisson using iterable of distributions.
59+
with pm.Model() as model:
60+
lam1 = pm.Exponential('lam1', lam=1)
61+
lam2 = pm.Exponential('lam2', lam=1)
6362
64-
w = pm.Dirichlet('w', a=np.array([1, 1]))
63+
pois1 = pm.Poisson.dist(mu=lam1)
64+
pois2 = pm.Poisson.dist(mu=lam2)
6565
66-
like = pm.Mixture('like', w=w, comp_dists = [pois1, pois2], observed=data)
66+
w = pm.Dirichlet('w', a=np.array([1, 1]))
67+
68+
like = pm.Mixture('like', w=w, comp_dists = [pois1, pois2], observed=data)
6769
"""
6870
def __init__(self, w, comp_dists, *args, **kwargs):
6971
shape = kwargs.pop('shape', ())

0 commit comments

Comments
 (0)