Beispiel #1
0
def test_em_gmm_multi(verbose=0):
    # Playing with various initilizations on the same data

    # generate some data
    dim = 2
    x = np.concatenate((nr.randn(1000, dim), 3 + 2 * nr.randn(100, dim)))

    # estimate different GMMs of that data
    maxiter = 100
    delta = 1.0e-4
    ninit = 5
    k = 2

    lgmm = GMM(k, dim)
    bgmm = lgmm.initialize_and_estimate(x, maxiter, delta, ninit, verbose)
    bic = bgmm.evidence(x)

    if verbose:
        print "bic of the best model", bic

    if verbose:
        # plot the result
        from test_bgmm import plot2D

        z = lgmm.map_label(x)
        plot2D(x, lgmm, z, show=1, verbose=0)

    assert_true(np.isfinite(bic))
Beispiel #2
0
def test_em_gmm_largedim(verbose=0):
    """
    testing the GMM model in larger dimensions
    """
    # generate some data
    dim = 10
    x = nr.randn(100,dim)
    x[:30,:] += 2
    
    # estimate different GMMs of that data
    maxiter = 100
    delta = 1.e-4
    
    for k in range(2,3):
        lgmm = GMM(k,dim)
        bgmm = lgmm.initialize_and_estimate(x, None, maxiter, delta, ninit=5)
        
    z = bgmm.map_label(x)
    
    # define the correct labelling
    u = np.zeros(100)
    u[:30]=1

    #check the correlation between the true labelling
    # and the computed one
    eta = np.absolute(np.dot(z-z.mean(),u-u.mean())/(np.std(z)*np.std(u)*100))
    assert (eta>0.3)