Пример #1
0
def test_em_gmm_heterosc(verbose=0):
    # testing the model in very ellipsoidal data: compute the big values
    # for several values of k and check that the macimal is 1 or 2

    # generate some data
    dim = 2
    x = nr.randn(100, dim)
    x[:50, :] += 3
    # x[:,0]*=10

    # estimate different GMMs of that data
    maxiter = 100
    delta = 1.0e-4

    bic = np.zeros(5)
    for k in range(1, 6):
        lgmm = GMM(k, dim)
        lgmm.initialize(x)
        bic[k - 1] = lgmm.estimate(x, maxiter, delta, 0)
        if verbose:
            print "bic of the %d-classes model" % k, bic

    if verbose:
        # plot the result
        z = lgmm.map_label(x)
        from test_bgmm import plot2D

        plot2D(x, lgmm, z, show=1, verbose=0)
    assert bic[4] < bic[1]
Пример #2
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))