Exemplo n.º 1
0
def test_imm_loglike_1D_k10():
    """
    Chek that the log-likelihood of the data under the
    infinite gaussian mixture model
    is close to the theortical data likelihood

    Here k-fold cross validation is used(k=10)
    """
    n = 50
    dim = 1
    alpha = .5
    k = 5
    x = np.random.randn(n, dim)
    igmm = IMM(alpha, dim)
    igmm.set_priors(x)

    # warming
    igmm.sample(x, niter=100, kfold=k)

    # sampling
    like =  igmm.sample(x, niter=300, kfold=k)
    theoretical_ll = -dim*.5*(1+np.log(2*np.pi))
    empirical_ll = np.log(like).mean()
    print theoretical_ll, empirical_ll
    assert np.absolute(theoretical_ll-empirical_ll)<0.25*dim
Exemplo n.º 2
0
def test_imm_loglike_2D():
    """
    Chek that the log-likelihood of the data under the
    infinite gaussian mixture model
    is close to the theortical data likelihood

    slow (cross-validated) but accurate.
    """
    n = 50
    dim = 2
    alpha = .5
    k = 5
    x = np.random.randn(n, dim)
    igmm = IMM(alpha, dim)
    igmm.set_priors(x)

    # warming
    igmm.sample(x, niter=100, init=True, kfold=k)

    # sampling
    like =  igmm.sample(x, niter=300, kfold=k)
    theoretical_ll = -dim*.5*(1+np.log(2*np.pi))
    empirical_ll = np.log(like).mean()
    print theoretical_ll, empirical_ll
    assert np.absolute(theoretical_ll-empirical_ll)<0.25*dim
Exemplo n.º 3
0
def test_imm_loglike_known_groups():
    """
    Chek that the log-likelihood of the data under the
    infinite gaussian mixture model
    is close to the theortical data likelihood
    """
    n = 50
    dim = 1
    alpha = .5
    x = np.random.randn(n, dim)
    igmm = IMM(alpha, dim)
    igmm.set_priors(x)
    kfold = np.floor(np.random.rand(n)*5).astype(np.int)
    
    # warming
    igmm.sample(x, niter=100)

    # sampling
    like =  igmm.sample(x, niter=300, kfold=kfold)
    theoretical_ll = -dim*.5*(1+np.log(2*np.pi))
    empirical_ll = np.log(like).mean()
    print theoretical_ll, empirical_ll
    assert np.absolute(theoretical_ll-empirical_ll)<0.25*dim
Exemplo n.º 4
0
def test_imm_loglike_2D_a0_1():
    """
    Chek that the log-likelihood of the data under the
    infinite gaussian mixture model
    is close to the theortical data likelihood

    the difference is that now alpha=.1
    """
    n = 100
    dim = 2
    alpha = .1
    x = np.random.randn(n, dim)
    igmm = IMM(alpha, dim)
    igmm.set_priors(x)

    # warming
    igmm.sample(x, niter=100, init=True)

    # sampling
    like =  igmm.sample(x, niter=300)
    theoretical_ll = -dim*.5*(1+np.log(2*np.pi))
    empirical_ll = np.log(like).mean()
    print theoretical_ll, empirical_ll
    assert np.absolute(theoretical_ll-empirical_ll)<0.2*dim