From dc33d39f1697de5fd52662911d1ac7e54b114264 Mon Sep 17 00:00:00 2001 From: Alesis Novik Date: Tue, 19 Jul 2011 23:45:06 +0100 Subject: [PATCH] Example and fix --- .../python_modular/clustering_gmm_modular.py | 44 +++++++++++++++++++ .../python_modular/graphical/em_2d_gmm.py | 2 - 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 examples/undocumented/python_modular/clustering_gmm_modular.py diff --git a/examples/undocumented/python_modular/clustering_gmm_modular.py b/examples/undocumented/python_modular/clustering_gmm_modular.py new file mode 100644 index 00000000000..838c99f3d3a --- /dev/null +++ b/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]) + diff --git a/examples/undocumented/python_modular/graphical/em_2d_gmm.py b/examples/undocumented/python_modular/graphical/em_2d_gmm.py index 98ee9eba453..df13345a37b 100644 --- a/examples/undocumented/python_modular/graphical/em_2d_gmm.py +++ b/examples/undocumented/python_modular/graphical/em_2d_gmm.py @@ -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)