[Scipy-svn] r3073 - in trunk/Lib/sandbox/pyem: . profile_data
scipy-svn at scipy.org
scipy-svn at scipy.org
Thu Jun 7 22:25:11 EDT 2007
Author: cdavid
Date: 2007-06-07 21:25:02 -0500 (Thu, 07 Jun 2007)
New Revision: 3073
Added:
trunk/Lib/sandbox/pyem/profile_data/blop.c
trunk/Lib/sandbox/pyem/profile_data/gden.m
trunk/Lib/sandbox/pyem/profile_data/mat_prof.m
Removed:
trunk/Lib/sandbox/pyem/.bzrignore
trunk/Lib/sandbox/pyem/test_reg.py
Modified:
trunk/Lib/sandbox/pyem/TODO
Log:
Add some profiling scripts to compare likelihood computation with matlab.
Deleted: trunk/Lib/sandbox/pyem/.bzrignore
===================================================================
--- trunk/Lib/sandbox/pyem/.bzrignore 2007-06-08 02:23:29 UTC (rev 3072)
+++ trunk/Lib/sandbox/pyem/.bzrignore 2007-06-08 02:25:02 UTC (rev 3073)
@@ -1,29 +0,0 @@
-dist
-pyem/src/c_gmm.c
-MANIFEST
-build
-pyem/bench1prof
-pyem/diag.dat
-pyem/gdenprof
-tmp.py
-test.py
-profile_gmm_em.py
-data.h5
-gmmprof
-valgrind-python.supp
-valgrind-python.supp
-pyem/
-pyem/matcode/
-pyem/tmp/
-pyem/tmp/kmean.py
-pyem/tmp/blop.py
-pyem/tmp/
-pyem/tmp
-matcode
-../MSG
-MSG
-exinfo.py
-blop
-*.prog
-*.prof
-test_storage.py
Modified: trunk/Lib/sandbox/pyem/TODO
===================================================================
--- trunk/Lib/sandbox/pyem/TODO 2007-06-08 02:23:29 UTC (rev 3072)
+++ trunk/Lib/sandbox/pyem/TODO 2007-06-08 02:25:02 UTC (rev 3073)
@@ -1,11 +1,12 @@
-# Last Change: Mon May 28 11:00 AM 2007 J
+# Last Change: Mon Jun 04 07:00 PM 2007 J
Things which must be implemented for a 1.0 version (in importante order)
- A classifier
+ - handle rank 1 for 1d data
- basic regularization
- - Use scipy.cluster kmeans instead of our own, as it now provides all
- necessary functionalities.
+ - docstrings
+ - demo for pdf estimtation, discriminant analysis and clustering
Things which would be nice (after 1.0 version):
- Bayes prior (hard, suppose MCMC)
Added: trunk/Lib/sandbox/pyem/profile_data/blop.c
===================================================================
--- trunk/Lib/sandbox/pyem/profile_data/blop.c 2007-06-08 02:23:29 UTC (rev 3072)
+++ trunk/Lib/sandbox/pyem/profile_data/blop.c 2007-06-08 02:25:02 UTC (rev 3073)
@@ -0,0 +1,37 @@
+#include <math.h>
+#include <stddef.h>
+
+int compute(const double *in, size_t n, size_t d, const double* mu, double* out)
+{
+ size_t i, j;
+ double acc;
+
+ for (i = 0; i < n; ++i) {
+ acc = 0;
+ for (j = 0; j < d; ++j) {
+ acc += (in[i*d+j] - mu[j]) * (in[i*d+j] - mu[j]);
+ }
+ out[i] = exp(acc);
+ }
+
+ return 0;
+}
+
+#if 0
+int main(void)
+{
+ const size_t n = 1e5;
+ const size_t d = 30;
+ size_t iter = 10, i;
+
+ double *in, *out;
+
+ in = malloc(sizeof(*in) * n * d);
+ out = malloc(sizeof(*out) * n * d);
+
+ for (i = 0; i < iter; ++i) {
+ }
+ free(in);
+ out(in);
+}
+#endif
Added: trunk/Lib/sandbox/pyem/profile_data/gden.m
===================================================================
--- trunk/Lib/sandbox/pyem/profile_data/gden.m 2007-06-08 02:23:29 UTC (rev 3072)
+++ trunk/Lib/sandbox/pyem/profile_data/gden.m 2007-06-08 02:25:02 UTC (rev 3073)
@@ -0,0 +1,10 @@
+function out = gden(x, mu)
+
+% Last Change: Mon Jun 04 10:00 AM 2007 J
+[n, d] = size(x);
+[nm, dm] = size(mu);
+if nm ~= n
+ out = sum(x-repmat(mu, n, 1), 1);
+else
+ out = sum(x-mu, 1);
+end;
Added: trunk/Lib/sandbox/pyem/profile_data/mat_prof.m
===================================================================
--- trunk/Lib/sandbox/pyem/profile_data/mat_prof.m 2007-06-08 02:23:29 UTC (rev 3072)
+++ trunk/Lib/sandbox/pyem/profile_data/mat_prof.m 2007-06-08 02:25:02 UTC (rev 3073)
@@ -0,0 +1,11 @@
+% Last Change: Mon Jun 04 10:00 AM 2007 J
+
+n = 1e5;
+d = 30;
+
+x = randn(n, d);
+mu = randn(n, d);
+
+for i=1:10
+ y = gden(x, mu);
+end;
Deleted: trunk/Lib/sandbox/pyem/test_reg.py
===================================================================
--- trunk/Lib/sandbox/pyem/test_reg.py 2007-06-08 02:23:29 UTC (rev 3072)
+++ trunk/Lib/sandbox/pyem/test_reg.py 2007-06-08 02:25:02 UTC (rev 3073)
@@ -1,44 +0,0 @@
-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()
-
More information about the Scipy-svn
mailing list