[Scipy-svn] r3100 - trunk/Lib/sandbox/pyem/tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Wed Jun 13 06:08:20 EDT 2007
Author: cdavid
Date: 2007-06-13 05:08:00 -0500 (Wed, 13 Jun 2007)
New Revision: 3100
Added:
trunk/Lib/sandbox/pyem/tests/testcommon.py
Modified:
trunk/Lib/sandbox/pyem/tests/test_densities.py
trunk/Lib/sandbox/pyem/tests/test_gmm_em.py
Log:
Fix importing datasets in pyem/test
Modified: trunk/Lib/sandbox/pyem/tests/test_densities.py
===================================================================
--- trunk/Lib/sandbox/pyem/tests/test_densities.py 2007-06-12 12:21:04 UTC (rev 3099)
+++ trunk/Lib/sandbox/pyem/tests/test_densities.py 2007-06-13 10:08:00 UTC (rev 3100)
@@ -19,10 +19,9 @@
#Optional:
set_local_path()
# import modules that are located in the same directory as this file.
+from testcommon import DEF_DEC
restore_path()
-from testcommon import DEF_DEC
-
class TestDensities(NumpyTestCase):
def _generate_test_data_1d(self):
self.va = 2.0
@@ -106,21 +105,24 @@
"""This function checks that logsumexp works as expected."""
# We check wether naive implementation would underflow, to be sure we
# are actually testing something here.
- N.seterr(under='raise')
+ errst = N.seterr(under='raise')
try:
- a = N.array([[-1000]])
- self.naive_logsumexp(a)
- raise AssertionError("expected to catch underflow, we should not be here")
- except FloatingPointError, e:
- print "Catching underflow, as expected"
- assert pyem.densities.logsumexp(a) == -1000.
- try:
- a = N.array([[-1000, -1000, -1000]])
- self.naive_logsumexp(a)
- raise AssertionError("expected to catch underflow, we should not be here")
- except FloatingPointError, e:
- print "Catching underflow, as expected"
- assert_array_almost_equal(pyem.densities.logsumexp(a), -998.90138771)
+ try:
+ a = N.array([[-1000]])
+ self.naive_logsumexp(a)
+ raise AssertionError("expected to catch underflow, we should not be here")
+ except FloatingPointError, e:
+ print "Catching underflow, as expected"
+ assert pyem.densities.logsumexp(a) == -1000.
+ try:
+ a = N.array([[-1000, -1000, -1000]])
+ self.naive_logsumexp(a)
+ raise AssertionError("expected to catch underflow, we should not be here")
+ except FloatingPointError, e:
+ print "Catching underflow, as expected"
+ assert_array_almost_equal(pyem.densities.logsumexp(a), -998.90138771)
+ finally:
+ N.seterr(under=errst['under'])
def naive_logsumexp(self, data):
return N.log(N.sum(N.exp(data), 1))
Modified: trunk/Lib/sandbox/pyem/tests/test_gmm_em.py
===================================================================
--- trunk/Lib/sandbox/pyem/tests/test_gmm_em.py 2007-06-12 12:21:04 UTC (rev 3099)
+++ trunk/Lib/sandbox/pyem/tests/test_gmm_em.py 2007-06-13 10:08:00 UTC (rev 3100)
@@ -4,6 +4,7 @@
# For now, just test that all mode/dim execute correctly
import sys
+import os
from numpy.testing import *
import numpy as N
@@ -12,11 +13,15 @@
from pyem import GMM, GM, EM
restore_path()
+set_local_path()
+# import modules that are located in the same directory as this file.
from testcommon import DEF_DEC
+curpath = sys.path[0]
+restore_path()
def load_dataset(filename):
from scipy.io import loadmat
- dic = loadmat(filename, squeeze_me = False)
+ dic = loadmat(os.path.join(curpath, filename), squeeze_me = False)
dic['w0'] = dic['w0'].squeeze()
dic['w'] = dic['w'].squeeze()
dic['tw'] = dic['tw'].squeeze()
Added: trunk/Lib/sandbox/pyem/tests/testcommon.py
===================================================================
--- trunk/Lib/sandbox/pyem/tests/testcommon.py 2007-06-12 12:21:04 UTC (rev 3099)
+++ trunk/Lib/sandbox/pyem/tests/testcommon.py 2007-06-13 10:08:00 UTC (rev 3100)
@@ -0,0 +1 @@
+DEF_DEC = 12
More information about the Scipy-svn
mailing list