Skip to content

Commit e300f3a

Browse files
ericmjltwiecki
authored andcommitted
Updates to Mixture docs. (#2799)
* Updates to Mixture docs.
1 parent 5eefc14 commit e300f3a

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

pymc3/distributions/mixture.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,34 @@ class Mixture(Distribution):
3636
w : array of floats
3737
w >= 0 and w <= 1
3838
the mixture weights
39-
comp_dists : multidimensional PyMC3 distribution or iterable of one-dimensional PyMC3 distributions
40-
the component distributions :math:`f_1, \ldots, f_n`
39+
comp_dists : multidimensional PyMC3 distribution (e.g. `pm.Poisson.dist(...)`)
40+
or iterable of one-dimensional PyMC3 distributions the
41+
component distributions :math:`f_1, \ldots, f_n`
42+
43+
Example
44+
-------
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.
48+
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,))
51+
52+
w = pm.Dirichlet('w', a=np.array([1, 1])) # two mixture component weights.
53+
54+
like = pm.Mixture('like', w=w, comp_dists=components, observed=data)
55+
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)
60+
61+
pois1 = pm.Poisson.dist(mu=lam1)
62+
pois2 = pm.Poisson.dist(mu=lam2)
63+
64+
w = pm.Dirichlet('w', a=np.array([1, 1]))
65+
66+
like = pm.Mixture('like', w=w, comp_dists = [pois1, pois2], observed=data)
4167
"""
4268
def __init__(self, w, comp_dists, *args, **kwargs):
4369
shape = kwargs.pop('shape', ())
@@ -165,7 +191,7 @@ class NormalMixture(Mixture):
165191
the component standard deviations
166192
tau : array of floats
167193
the component precisions
168-
194+
169195
Note: You only have to pass in sd or tau, but not both.
170196
"""
171197
def __init__(self, w, mu, *args, **kwargs):

0 commit comments

Comments
 (0)