def test_evidence(verbose=0,k=1): """ Compare the evidence estimated by Chib's method with the variational evidence (free energy) fixme : this one really takes time """ n=50 dim=2 x = nr.randn(n,dim) x[:15] += 3 b = VBGMM(k,dim) b.guess_priors(x) b.initialize(x) b.estimate(x) vbe = b.evidence(x), if verbose: print 'vb: ',vbe, niter = 1000 b = BGMM(k,dim) b.guess_priors(x) b.initialize(x) b.sample(x,100) w,cent,prec,pz = b.sample(x, niter=niter, mem=1) bplugin = BGMM(k, dim, cent, prec, w) bplugin.guess_priors(x) bfchib = bplugin.bayes_factor(x, pz.astype(np.int), 1) if verbose: print ' chib:', bfchib assert(bfchib>vbe)
def test_evidence(verbose=0, k=1): # Compare the evidence estimated by Chib's method with the # variational evidence (free energy) fixme : this one really takes # time n = 100 dim = 2 x = nr.randn(n, dim) x[:30] += 3 show = 0 b = VBGMM(k, dim) b.guess_priors(x) b.initialize(x) b.estimate(x) vbe = (b.evidence(x),) if verbose: print "vb: ", vbe, niter = 1000 b = BGMM(k, dim) b.guess_priors(x) b.initialize(x) b.sample(x, 100) w, cent, prec, pz = b.sample(x, niter=niter, mem=1) bplugin = BGMM(k, dim, cent, prec, w) bplugin.guess_priors(x) bfchib = bplugin.Bfactor(x, pz.astype(np.int), 1) if verbose: print " chib:", bfchib assert bfchib > vbe
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 be = -np.infty for k in range(1,kmax): b = VBGMM(k,dim) b.guess_priors(x) b.initialize(x) b.estimate(x) ek = b.evidence(x) if verbose: print k,ek if ek > be: be = ek bestk = k assert(bestk<3)