File: profile_densities.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 (54 lines) | stat: -rw-r--r-- 1,465 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
45
46
47
48
49
50
51
52
53
54
import numpy as N
from numpy.random import randn
from scipy.sandbox.pyem import densities as D
from scipy.sandbox.pyem import _c_densities as DC
#import tables

def bench(func, mode = 'diag'):
    #===========================================
    # Diag Gaussian of dimension 20
    #===========================================
    d       = 30
    n       = 1e5
    niter   = 10

    print "Compute %d times densities, %d dimension, %d frames" % (niter, d, n)
    # Generate a model with k components, d dimensions
    mu  = randn(1, d)
    if mode == 'diag':
        va  = abs(randn(1, d))
    elif mode == 'full':
        va  = randn(d, d)
        va  = N.dot(va, va.transpose())

    X   = randn(n, d)
    for i in range(niter):
        Y   = func(X, mu, va)

def benchpy():
    bench(D.gauss_den)

def benchc():
    bench(DC.gauss_den)

def benchpyfull():
    bench(D.gauss_den, 'full')

def benchcfull():
    bench(DC.gauss_den, 'full')

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

    profile_file    = 'gdenc.prof'
    prof    = hotshot.Profile(profile_file, lineevents=1)
    prof.runcall(benchc)
    p = hotshot.stats.load(profile_file)
    print p.sort_stats('cumulative').print_stats(20)
    prof.close()