예제 #1
0
def main(fname, N, n, params):
    """Run GMM EM on the data in @fname"""

    gmm = GaussianMixtureModel.from_file(fname)
    k, d, M, S, w = gmm.k, gmm.d, gmm.means, gmm.sigmas, gmm.weights

    X = gmm.sample(N, n)

    # Set seed for the algorithm
    sc.random.seed(int(params.seed))

    algo = GaussianMixtureEM(k, d)

    O = M, S, w

    def report(i, O_, lhood):
        M_, _, _ = O_

    lhood, Z, O_ = algo.run(X, None, report)

    M_, S_, w_ = O_
    M_ = closest_permuted_matrix(M.T, M_.T).T

    # Table
    print column_aerr(M, M_), column_rerr(M, M_)
예제 #2
0
def make_table(model, data, methods):
    tbl = []
    tbl.append(["Method","Parameter error", "Likelihood"])
    tbl.append(["True", 0., model.llikelihood(data)])
    print "true", model["M"]
    for name, method in methods:
        w, params = method(model, data)
        w, params = fix_parameters(model["M"], params, w)

        print name, params
        lhood = model.using(M=params, w=w).llikelihood(data)
        tbl.append([name, column_rerr(model["M"], params), lhood])
    return tbl
예제 #3
0
def main(fname, N, n, params):
    """Run GMM EM on the data in @fname"""

    gmm = GaussianMixtureModel.from_file( fname )
    k, d, M, S, w = gmm.k, gmm.d, gmm.means, gmm.sigmas, gmm.weights

    X = gmm.sample( N, n )

    # Set seed for the algorithm
    sc.random.seed( int( params.seed ) )

    algo = GaussianMixtureEM( k, d )

    O = M, S, w
    def report( i, O_, lhood ):
        M_, _, _ = O_
    lhood, Z, O_ = algo.run( X, None, report )

    M_, S_, w_ = O_
    M_ = closest_permuted_matrix( M.T, M_.T ).T

    # Table
    print column_aerr( M, M_ ), column_rerr( M, M_ )