Пример #1
0
st = MultivariateTDistribution(DIMS, xy.mean(axis=1)*1.1, np.diag(xy.var(axis=1)), 3)
da = xy.T #[:500]
ds = DataSet()
ds.fromArray(da)
m = MixtureModel(1, [1], [st])
print m
m.EM(ds, 60, 0.1)
print m
#import ipdb; ipdb.set_trace()
#m2 = mix.MixtureModel(2, [0.8, 0.2], [m.components[0].distList[0], d2], compFix=[0, 0])
for _ in xrange(6):
    m = mixturate(m, xy.mean(axis=1)-10., np.diag(xy.var(axis=1)))
    m.randMaxEM(ds, 3, 30, 0.1)
    print m

import joblib
joblib.dump(m, 'test2.mix', compress=3)
pl.plotData(da[:, :2])
col = 'rgbcmyk'
icol = 0
for icomp, comp in enumerate(m.components):
    dist = comp.distList[0]
    print m.pi[icomp], dist.df, dist.mu, np.sqrt(np.diag(dist.sigma))

for comp in m.components:
    model = comp.distList[0]
    plot_cov_ellipse(model.sigma[:2, :2], model.mu[:2], facecolor=col[icol])
    icol += 1
pylab.show()