Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from alesis/gmm
Example and fix
- Loading branch information
Showing
2 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
examples/undocumented/python_modular/clustering_gmm_modular.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters