File: test_reg.py

package info (click to toggle)
python-scipy 0.5.2-0.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 33,888 kB
  • ctags: 44,231
  • sloc: ansic: 156,256; cpp: 90,347; python: 89,604; fortran: 73,083; sh: 1,318; objc: 424; makefile: 342
file content (44 lines) | stat: -rw-r--r-- 979 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import numpy as N

from gauss_mix import GM
from gmm_em import GMM, EM

from numpy.random import seed

def test_reg():
    seed(0)
    # Generate data with a few components
    d   = 2
    k   = 1
    n   = 500

    w, mu, va   = GM.gen_param(d, k)
    gm          = GM.fromvalues(w, mu, va)

    data    = gm.sample(n)

    # Try to learn with an insane number of components
    gmm = GMM(GM(d, 30), 'random')

    em  = EM()
    like= em.train(data, gmm, 20, 1e-20)

    # import pylab as P
    # P.subplot(2, 1, 1)
    # P.plot(data[:, 0], data[:, 1], '.')
    # gmm.gm.plot()
    # P.subplot(2, 1, 2)
    # P.plot(like)
    # print like
    # P.show()

if __name__ == "__main__":
    # import hotshot, hotshot.stats
    # profile_file    = 'manyk.prof'
    # prof    = hotshot.Profile(profile_file, lineevents=1)
    # prof.runcall(test_reg)
    # p = hotshot.stats.load(profile_file)
    # print p.sort_stats('cumulative').print_stats(20)
    # prof.close()
    test_reg()