Skip to content

Commit 37eec80

Browse files
committed
Fix examples in docs of mixture.py, bound.py and continuous.py
1 parent 90215a8 commit 37eec80

File tree

3 files changed

+55
-48
lines changed

3 files changed

+55
-48
lines changed

pymc3/distributions/bound.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,14 @@ 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)
182-
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)
179+
.. code-block:: python
180+
with pm.Model():
181+
NegativeNormal = pm.Bound(pm.Normal, upper=0.0)
182+
par1 = NegativeNormal('par2', mu=0.0, sd=1.0, testval=1.0)
183+
184+
# or you can define it implicitly within the model context
185+
par2 = pm.Bound(pm.Normal, lower=-1.0, upper=1.0)(
186+
'par2', mu=0.0, sd=1.0, testval=1.0)
186187
"""
187188

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

pymc3/distributions/continuous.py

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,12 @@ 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+
with pm.Model():
280+
x = pm.Normal('x', mu=0, sd=10)
281+
282+
with pm.Model():
283+
x = pm.Normal('x', mu=0, tau=1/23)
283284
"""
284285

285286
def __init__(self, mu=0, sd=None, tau=None, **kwargs):
@@ -362,11 +363,12 @@ class HalfNormal(PositiveContinuous):
362363
363364
Examples
364365
--------
365-
with pm.Model():
366-
x = pm.HalfNormal('x', sd=10)
367-
368-
with pm.Model():
369-
x = pm.HalfNormal('x', tau=1/15)
366+
.. code-block:: python
367+
with pm.Model():
368+
x = pm.HalfNormal('x', sd=10)
369+
370+
with pm.Model():
371+
x = pm.HalfNormal('x', tau=1/15)
370372
"""
371373

372374
def __init__(self, sd=None, tau=None, *args, **kwargs):
@@ -861,12 +863,13 @@ class Lognormal(PositiveContinuous):
861863
862864
Example
863865
-------
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)
866+
.. code-block:: python
867+
# Example to show that we pass in only `sd` or `tau` but not both.
868+
with pm.Model():
869+
x = pm.Lognormal('x', mu=2, sd=30)
867870
868-
with pm.Model():
869-
x = pm.Lognormal('x', mu=2, tau=1/100)
871+
with pm.Model():
872+
x = pm.Lognormal('x', mu=2, tau=1/100)
870873
"""
871874

872875
def __init__(self, mu=0, sd=None, tau=None, *args, **kwargs):
@@ -964,11 +967,12 @@ class StudentT(Continuous):
964967
965968
Examples
966969
--------
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)
970+
.. code-block:: python
971+
with pm.Model():
972+
x = pm.StudentT('x', nu=15, mu=0, sd=10)
973+
974+
with pm.Model():
975+
x = pm.StudentT('x', nu=15, mu=0, lam=1/23)
972976
"""
973977

974978
def __init__(self, nu, mu=0, lam=None, sd=None, *args, **kwargs):
@@ -1633,12 +1637,13 @@ class HalfStudentT(PositiveContinuous):
16331637
16341638
Examples
16351639
--------
1636-
# Only pass in one of lam or sd, but not both.
1637-
with pm.Model():
1638-
x = pm.HalfStudentT('x', sd=10, nu=10)
1639-
1640-
with pm.Model():
1641-
x = pm.HalfStudentT('x', lam=4, nu=10)
1640+
.. code-block:: python
1641+
# Only pass in one of lam or sd, but not both.
1642+
with pm.Model():
1643+
x = pm.HalfStudentT('x', sd=10, nu=10)
1644+
1645+
with pm.Model():
1646+
x = pm.HalfStudentT('x', lam=4, nu=10)
16421647
"""
16431648
def __init__(self, nu=1, sd=None, lam=None, *args, **kwargs):
16441649
super(HalfStudentT, self).__init__(*args, **kwargs)

pymc3/distributions/mixture.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,29 @@ 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
46+
# 2-Mixture Poisson distribution
47+
with pm.Model() as model:
48+
lam = pm.Exponential('lam', lam=1, shape=(2,)) # `shape=(2,)` indicates two mixtures.
4849
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,))
50+
# As we just need the logp, rather than add a RV to the model, we need to call .dist()
51+
components = pm.Poisson.dist(mu=lam, shape=(2,))
5152
52-
w = pm.Dirichlet('w', a=np.array([1, 1])) # two mixture component weights.
53+
w = pm.Dirichlet('w', a=np.array([1, 1])) # two mixture component weights.
5354
54-
like = pm.Mixture('like', w=w, comp_dists=components, observed=data)
55+
like = pm.Mixture('like', w=w, comp_dists=components, observed=data)
5556
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)
57+
# 2-Mixture Poisson using iterable of distributions.
58+
with pm.Model() as model:
59+
lam1 = pm.Exponential('lam1', lam=1)
60+
lam2 = pm.Exponential('lam2', lam=1)
6061
61-
pois1 = pm.Poisson.dist(mu=lam1)
62-
pois2 = pm.Poisson.dist(mu=lam2)
62+
pois1 = pm.Poisson.dist(mu=lam1)
63+
pois2 = pm.Poisson.dist(mu=lam2)
6364
64-
w = pm.Dirichlet('w', a=np.array([1, 1]))
65+
w = pm.Dirichlet('w', a=np.array([1, 1]))
6566
66-
like = pm.Mixture('like', w=w, comp_dists = [pois1, pois2], observed=data)
67+
like = pm.Mixture('like', w=w, comp_dists = [pois1, pois2], observed=data)
6768
"""
6869
def __init__(self, w, comp_dists, *args, **kwargs):
6970
shape = kwargs.pop('shape', ())

0 commit comments

Comments
 (0)