[Scipy-svn] r2274 - in trunk/Lib/sandbox/pyem: . pyem

scipy-svn at scipy.org scipy-svn at scipy.org
Thu Oct 12 08:46:54 CDT 2006


Author: cdavid
Date: 2006-10-12 08:46:47 -0500 (Thu, 12 Oct 2006)
New Revision: 2274

Modified:
   trunk/Lib/sandbox/pyem/Changelog
   trunk/Lib/sandbox/pyem/TODO
   trunk/Lib/sandbox/pyem/pyem/__init__.py
   trunk/Lib/sandbox/pyem/pyem/densities.py
   trunk/Lib/sandbox/pyem/pyem/profile_densities.py
Log:
[pyem @ david at ar.media.kyoto-u.ac.jp-20060807094657-07adf51ac8a6f099]
Version 0.5, add custom confidence ellipsoids
David Cournapeau <david at ar.media.kyoto-u.ac.jp> | 2006-08-07 18:46:57 +0900 (Mon, 07 Aug 2006)

Modified: trunk/Lib/sandbox/pyem/Changelog
===================================================================
--- trunk/Lib/sandbox/pyem/Changelog	2006-10-12 13:46:30 UTC (rev 2273)
+++ trunk/Lib/sandbox/pyem/Changelog	2006-10-12 13:46:47 UTC (rev 2274)
@@ -1,3 +1,10 @@
+pyem (0.5) Fri, 04 Aug 2006 23:10:37 +0900
+
+	* put version to 0.5.0
+	* implement confidence interval using chi2
+
+-- David Cournapeau <david at ar.media.kyoto-u.ac.jp> 
+
 pyem (0.4) Fri, 04 Aug 2006 19:37:47 +0900
 
 	* put version to 0.4.2

Modified: trunk/Lib/sandbox/pyem/TODO
===================================================================
--- trunk/Lib/sandbox/pyem/TODO	2006-10-12 13:46:30 UTC (rev 2273)
+++ trunk/Lib/sandbox/pyem/TODO	2006-10-12 13:46:47 UTC (rev 2274)
@@ -1,13 +1,8 @@
-# Last Change: Thu Jul 13 05:00 PM 2006 J
+# Last Change: Fri Aug 04 11:00 PM 2006 J
 
 Things which must be implemented for a 1.0 version:
     - test for various length and model size.
-    - refactoring with a class modelling mixture models.
-    - for Gaussian densities: compute level <-> confidence ellipses 
-    relationship with Chi2 model.
     - a small help/tutorial
-    - review the code, with the difference between generic numpy functions
-    and blas ones
 
 Things which would be nice:
     - C implementation of Gaussian densities at least.

Modified: trunk/Lib/sandbox/pyem/pyem/__init__.py
===================================================================
--- trunk/Lib/sandbox/pyem/pyem/__init__.py	2006-10-12 13:46:30 UTC (rev 2273)
+++ trunk/Lib/sandbox/pyem/pyem/__init__.py	2006-10-12 13:46:47 UTC (rev 2274)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
-# Last Change: Fri Aug 04 07:00 PM 2006 J
+# Last Change: Fri Aug 04 11:00 PM 2006 J
 
-version = '0.4.2'
+version = '0.5.0'
 
 from gauss_mix import GmParamError, GM
 from gmm_em import GmmParamError, GMM

Modified: trunk/Lib/sandbox/pyem/pyem/densities.py
===================================================================
--- trunk/Lib/sandbox/pyem/pyem/densities.py	2006-10-12 13:46:30 UTC (rev 2273)
+++ trunk/Lib/sandbox/pyem/pyem/densities.py	2006-10-12 13:46:47 UTC (rev 2274)
@@ -1,12 +1,14 @@
 #! /usr/bin/python
 #
 # Copyrighted David Cournapeau
-# Last Change: Fri Aug 04 07:00 PM 2006 J
+# Last Change: Fri Aug 04 11:00 PM 2006 J
 
 import numpy as N
 import numpy.linalg as lin
 from numpy.random import randn
+from scipy.stats import chi2
 
+
 # Error classes
 class DenError(Exception):
     """Base class for exceptions in this module.
@@ -163,15 +165,14 @@
     return y
 
 # To plot a confidence ellipse from multi-variate gaussian pdf
-def gauss_ell(mu, va, dim = [0, 1], npoints = 100):
+def gauss_ell(mu, va, dim = [0, 1], npoints = 100, level = 0.39):
     """ Given a mean and covariance for multi-variate
     gaussian, returns npoints points for the ellipse
-    of confidence 0.39
+    of confidence given by level (all points will be inside
+    the ellipsoides with a probability equal to level)
     
     Returns the coordinate x and y of the ellipse"""
     
-    # TODO: Get a confidence interval using the Chi2 distribution
-    # of points at a given mahalanobis distance...
     mu      = N.atleast_1d(mu)
     va      = N.atleast_1d(va)
     c       = N.array(dim)
@@ -187,11 +188,14 @@
         else:
             raise DenError("mean and variance are not dim conformant")
 
-    level   = 0.39
+    # TODO: Get a confidence interval using the Chi2 distribution
+    # of points at a given mahalanobis distance...
+    chi22d  = chi2(2)
+    mahal   = N.sqrt(chi22d.ppf(level))
     
     # Generates a circle of npoints
     theta   = N.linspace(0, 2 * N.pi, npoints)
-    circle  = N.array([N.cos(theta), N.sin(theta)])
+    circle  = mahal * N.array([N.cos(theta), N.sin(theta)])
 
     # Get the dimension which we are interested in:
     mu  = mu[dim]
@@ -395,7 +399,7 @@
     Yc      = Yc.transpose() + mu
 
     # Plotting
-    Xe, Ye  = gauss_ell(mu, va, npoints = 100)
+    Xe, Ye  = gauss_ell(mu, va, npoints = 100, level=0.95)
     pylab.figure()
     pylab.plot(Yc[:, 0], Yc[:, 1], '.')
     pylab.plot(Xe, Ye, 'r')

Modified: trunk/Lib/sandbox/pyem/pyem/profile_densities.py
===================================================================
--- trunk/Lib/sandbox/pyem/pyem/profile_densities.py	2006-10-12 13:46:30 UTC (rev 2273)
+++ trunk/Lib/sandbox/pyem/pyem/profile_densities.py	2006-10-12 13:46:47 UTC (rev 2274)
@@ -1,4 +1,5 @@
 import numpy as N
+from numpy.random import randn
 import densities as D
 import tables
 
@@ -7,19 +8,19 @@
     # Diag Gaussian of dimension 20
     #===========================================
     d       = 20
-    n       = 1e5
-    niter   = 1
+    n       = 1e4
+    niter   = 20
     mode    = 'diag'
 
     # Generate a model with k components, d dimensions
-    mu  = N.randn(1, d)
+    mu  = randn(1, d)
     if mode == 'diag':
-        va  = abs(N.randn(1, d))
+        va  = abs(randn(1, d))
     elif mode == 'full':
-        va  = N.randn(d, d)
-        va  = N.matrixmultiply(va, va.transpose())
+        va  = randn(d, d)
+        va  = N.dot(va, va.transpose())
 
-    X   = N.randn(n, d)
+    X   = randn(n, d)
     print "Compute %d times densities, %d dimension, %d frames" % (niter, d, n)
     for i in range(niter):
         Y   = D.gauss_den(X, mu, va)



More information about the Scipy-svn mailing list