예제 #1
0
util.set_title('SMEM for 2d GMM example')

max_iter = 100
max_cand = 5
min_cov = 1e-9
max_em_iter = 1000
min_change = 1e-9
cov_type = 0

real_gmm = GMM(3)

real_gmm.set_nth_mean(array([2.0, 2.0]), 0)
real_gmm.set_nth_mean(array([-2.0, -2.0]), 1)
real_gmm.set_nth_mean(array([2.0, -2.0]), 2)

real_gmm.set_nth_cov(array([[1.0, 0.2], [0.2, 0.5]]), 0)
real_gmm.set_nth_cov(array([[0.2, 0.1], [0.1, 0.5]]), 1)
real_gmm.set_nth_cov(array([[0.3, -0.2], [-0.2, 0.8]]), 2)

real_gmm.set_coef(array([0.3, 0.4, 0.3]))

generated = array([real_gmm.sample()])
for i in range(199):
    generated = append(generated, array([real_gmm.sample()]), axis=0)

generated = generated.transpose()
feat_train = RealFeatures(generated)
est_smem_gmm = GMM(3, cov_type)
est_smem_gmm.train(feat_train)

est_smem_gmm.set_nth_mean(array([2.0, 0.0]), 0)
예제 #2
0
from shogun.Features import RealFeatures
import util

util.set_title('EM for 1d GMM example')

min_cov=1e-9
max_iter=1000
min_change=1e-9

real_gmm=GMM(3)

real_gmm.set_nth_mean(array([-2.0]), 0)
real_gmm.set_nth_mean(array([0.0]), 1)
real_gmm.set_nth_mean(array([2.0]), 2)

real_gmm.set_nth_cov(array([[0.3]]), 0)
real_gmm.set_nth_cov(array([[0.1]]), 1)
real_gmm.set_nth_cov(array([[0.2]]), 2)

real_gmm.set_coef(array([0.3, 0.5, 0.2]))

generated=array([real_gmm.sample()])
for i in range(199):
    generated=append(generated, array([real_gmm.sample()]), axis=1)

feat_train=RealFeatures(generated)
est_gmm=GMM(3)
est_gmm.train(feat_train)
est_gmm.train_em(min_cov, max_iter, min_change)

est_mean1=est_gmm.get_nth_mean(0)
예제 #3
0
#set the parameters
max_iter=100
max_cand=5
min_cov=1e-9
max_em_iter=1000
min_change=1e-9
cov_type=0

#setup the real GMM
real_gmm=GMM(3)

real_gmm.set_nth_mean(array([2.0, 2.0]), 0)
real_gmm.set_nth_mean(array([-2.0, -2.0]), 1)
real_gmm.set_nth_mean(array([2.0, -2.0]), 2)

real_gmm.set_nth_cov(array([[1.0, 0.2],[0.2, 0.5]]), 0)
real_gmm.set_nth_cov(array([[0.2, 0.1],[0.1, 0.5]]), 1)
real_gmm.set_nth_cov(array([[0.3, -0.2],[-0.2, 0.8]]), 2)

real_gmm.set_coef(array([0.3, 0.4, 0.3]))

#generate training set from real GMM
generated=array([real_gmm.sample()])
for i in range(199):
    generated=append(generated, array([real_gmm.sample()]), axis=0)

generated=generated.transpose()
feat_train=RealFeatures(generated)

#train GMM using SMEM and print log-likelihood
est_smem_gmm=GMM(3, cov_type)
예제 #4
0
from shogun.Features import RealFeatures
import util

util.set_title('EM for 2d GMM example')

min_cov = 1e-9
max_iter = 1000
min_change = 1e-9
cov_type = 0

real_gmm = GMM(2)

real_gmm.set_nth_mean(array([1.0, 1.0]), 0)
real_gmm.set_nth_mean(array([-1.0, -1.0]), 1)

real_gmm.set_nth_cov(array([[1.0, 0.2], [0.2, 0.1]]), 0)
real_gmm.set_nth_cov(array([[0.3, 0.1], [0.1, 1.0]]), 1)

real_gmm.set_coef(array([0.3, 0.7]))

generated = array([real_gmm.sample()])
for i in range(199):
    generated = append(generated, array([real_gmm.sample()]), axis=0)

generated = generated.transpose()
feat_train = RealFeatures(generated)
est_gmm = GMM(2, cov_type)
est_gmm.train(feat_train)
est_gmm.train_em(min_cov, max_iter, min_change)

est_mean1 = est_gmm.get_nth_mean(0)
##!/usr/bin/env python
# """
# Explicit examples on how to use clustering
# """
from numpy import array, append
from shogun.Distribution import GMM
from shogun.Library import Math_init_random

Math_init_random(5)

real_gmm = GMM(2, 0)

real_gmm.set_nth_mean(array([1.0, 1.0]), 0)
real_gmm.set_nth_mean(array([-1.0, -1.0]), 1)

real_gmm.set_nth_cov(array([[1.0, 0.2], [0.2, 0.1]]), 0)
real_gmm.set_nth_cov(array([[0.3, 0.1], [0.1, 1.0]]), 1)

real_gmm.set_coef(array([0.3, 0.7]))

generated = array([real_gmm.sample()])
for i in range(199):
    generated = append(generated, array([real_gmm.sample()]), axis=0)

generated = generated.transpose()

parameter_list = [[generated, 2, 1e-9, 1000, 1e-9, 0]]


def clustering_gmm_modular(fm_train=generated, n=2, min_cov=1e-9, max_iter=1000, min_change=1e-9, cov_type=0):