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

scipy-svn@scip... scipy-svn@scip...
Mon Jun 11 05:34:27 CDT 2007


Author: cdavid
Date: 2007-06-11 05:34:20 -0500 (Mon, 11 Jun 2007)
New Revision: 3097

Modified:
   trunk/Lib/sandbox/pyem/densities.py
   trunk/Lib/sandbox/pyem/tests/test_densities.py
Log:
Add tests for pdf computation in log domain (1st step for logsumexp trick support)

Modified: trunk/Lib/sandbox/pyem/densities.py
===================================================================
--- trunk/Lib/sandbox/pyem/densities.py	2007-06-11 10:12:10 UTC (rev 3096)
+++ trunk/Lib/sandbox/pyem/densities.py	2007-06-11 10:34:20 UTC (rev 3097)
@@ -1,7 +1,7 @@
 #! /usr/bin/python
 #
 # Copyrighted David Cournapeau
-# Last Change: Mon Jun 11 03:00 PM 2007 J
+# Last Change: Mon Jun 11 07:00 PM 2007 J
 """This module implements various basic functions related to multivariate
 gaussian, such as pdf estimation, confidence interval/ellipsoids, etc..."""
 
@@ -119,7 +119,7 @@
     if not log:
         y   = fac * N.exp(y)
     else:
-        y   = y + log(fac)
+        y   += N.log(fac)
 
     return y
     

Modified: trunk/Lib/sandbox/pyem/tests/test_densities.py
===================================================================
--- trunk/Lib/sandbox/pyem/tests/test_densities.py	2007-06-11 10:12:10 UTC (rev 3096)
+++ trunk/Lib/sandbox/pyem/tests/test_densities.py	2007-06-11 10:34:20 UTC (rev 3097)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Mon Jun 11 06:00 PM 2007 J
+# Last Change: Mon Jun 11 07:00 PM 2007 J
 
 # TODO:
 #   - having "fake tests" to check that all mode (scalar, diag and full) are
@@ -72,6 +72,10 @@
         Y   = gauss_den(self.X, self.mu, self.va)
         assert_array_almost_equal(Y, self.Yt, decimal)
 
+    def _test_log(self, level, decimal = DEF_DEC):
+        Y   = gauss_den(self.X, self.mu, self.va, log = True)
+        assert_array_almost_equal(N.exp(Y), self.Yt, decimal)
+
     def test_2d_diag(self, level = 0):
         self._generate_test_data_2d_diag()
         self._test(level)
@@ -80,10 +84,22 @@
         self._generate_test_data_2d_full()
         self._test(level)
     
-    def test_py_1d(self, level = 0):
+    def test_1d(self, level = 0):
         self._generate_test_data_1d()
         self._test(level)
 
+    def test_2d_diag_log(self, level = 0):
+        self._generate_test_data_2d_diag()
+        self._test_log(level)
+
+    def test_2d_full_log(self, level = 0):
+        self._generate_test_data_2d_full()
+        self._test_log(level)
+
+    def test_1d_log(self, level = 0):
+        self._generate_test_data_1d()
+        self._test_log(level)
+
 class test_c_implementation(TestDensities):
     def _test(self, level, decimal = DEF_DEC):
         try:



More information about the Scipy-svn mailing list