Skip to content
Snippets Groups Projects
Commit 2eff92e8 authored by Alexandre Passos's avatar Alexandre Passos
Browse files

Adding example; adding explicit lower bound computation; optionally monitoring...

Adding example; adding explicit lower bound computation; optionally monitoring convergence; full and tied work, somehow spherical and diag diverge.
parent 68423537
No related branches found
No related tags found
No related merge requests found
......@@ -128,13 +128,10 @@ distribution.
\begin{array}{rcl}
&& E_q[\log P(z)] - E_q[\log Q(z)] \\
&=&
\sum_{k} \left( \left(\sum_{j=k+1}^K
\nu_{z_{i,j}}\right)(\Psi(\gamma{k,1})-\Psi(\gamma{k,1}+\gamma_{k,2}))
+
\nu_{z_{i,k}}(\Psi(\gamma_{k,1})-\Psi(\gamma_{k,1}+\gamma_{k,2}))\right)
\\ &&
- \sum_k
\nu_{z_{i,k}} \log \nu_{z_{i,k}} \\
\sum_{k} \left(
\left(\sum_{j=k+1}^K \nu_{z_{i,j}}\right)(\Psi(\gamma{k,1})-\Psi(\gamma{k,1}+\gamma_{k,2}))
+ \nu_{z_{i,k}}(\Psi(\gamma_{k,1})-\Psi(\gamma_{k,1}+\gamma_{k,2}))
- \log \nu_{z_{i,k}} \right)
\end{array}
......
"""
=================================
DP Mixture Model Ellipsoids
=================================
Plot the confidence ellipsoids of a mixture of two gaussians.
"""
import numpy as np
from scikits.learn import mixture
import itertools
import pylab as pl
import matplotlib as mpl
n, m = 300, 2
# generate random sample, two components
np.random.seed(0)
C = np.array([[0., -0.7], [3.5, .7]])
X = np.r_[np.dot(np.random.randn(n, 2), C),
np.random.randn(n, 2) + np.array([3, 3])]
for p,alpha in enumerate([0.01, 1., 100.]):
clf = mixture.DPGMM(n_states=10, cvtype='full', alpha=alpha)
clf.fit(X)
splot = pl.subplot(310+p+1, aspect='equal')
color_iter = itertools.cycle (['r', 'g', 'b', 'c'])
Y_ = clf.predict(X)
for i, (mean, covar, color) in enumerate(zip(clf.means, clf.covars, color_iter)):
v, w = np.linalg.eigh(covar)
u = w[0] / np.linalg.norm(w[0])
if sum(Y_ == i) > 1:
pl.scatter(X[Y_==i, 0], X[Y_==i, 1], .8, color=color)
else:
continue
angle = np.arctan(u[1]/u[0])
angle = 180 * angle / np.pi # convert to degrees
ell = mpl.patches.Ellipse (mean, v[0], v[1], 180 + angle, color=color)
ell.set_clip_box(splot.bbox)
ell.set_alpha(0.5)
splot.add_artist(ell)
pl.show()
......@@ -4,4 +4,4 @@ Mixture modeling algorithms
from .gmm import logsum, normalize, sample_gaussian, lmvnpdf
from .gmm import GMM
from .dpgmm import DPGMM, VBGMM
from .dpgmm import DPGMM
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment