Skip to content

Commit

Permalink
Example and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alesis committed Jul 20, 2011
1 parent eeec47b commit dc33d39
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
44 changes: 44 additions & 0 deletions examples/undocumented/python_modular/clustering_gmm_modular.py
@@ -0,0 +1,44 @@
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)

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]

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

from shogun.Distribution import GMM
from shogun.Features import RealFeatures
from shogun.Library import Math_init_random

Math_init_random(5)

feat_train=RealFeatures(generated)

est_gmm=GMM(n, cov_type)
est_gmm.train(feat_train)
est_gmm.train_em(min_cov, max_iter, min_change)

return est_gmm

if __name__=='__main__':
print 'GMM'
clustering_gmm_modular(*parameter_list[0])

2 changes: 0 additions & 2 deletions examples/undocumented/python_modular/graphical/em_2d_gmm.py
Expand Up @@ -11,8 +11,6 @@
min_change=1e-9
cov_type=0

gaus1=Gaussian(array([1.0, 1.0]), array([[1.0, 0.2],[0.2, 0.1]]))
gaus2=Gaussian(array([-1.0, -1.0]), array([[0.3, 0.1],[0.1, 1.0]]))
real_gmm=GMM(2)

real_gmm.set_nth_mean(array([1.0, 1.0]), 0)
Expand Down

0 comments on commit dc33d39

Please sign in to comment.