def test_vbgmm(verbose=0): # perform the estimation of a gmm n = 100 dim = 2 x = nr.randn(n, dim) x[:30] += 2 k = 2 b = VBGMM(k, dim) b.guess_priors(x) b.initialize(x) b.estimate(x, verbose=verbose) z = b.map_label(x) # fixme : find a less trivial test assert z.max() + 1 == b.k
def test_vbgmm_select(kmax=6, verbose=0): # perform the estimation of a gmm n = 100 dim = 3 x = nr.randn(n, dim) x[:30] += 2 show = 0 be = -np.infty for k in range(1, kmax): b = VBGMM(k, dim) b.guess_priors(x) b.initialize(x) b.estimate(x) z = b.map_label(x) ek = b.evidence(x) if verbose: print k, ek if ek > be: be = ek bestk = k assert bestk < 3