diff --git a/tests/aipy_test.py b/tests/aipy_test.py index 288396e6..6a97847c 100644 --- a/tests/aipy_test.py +++ b/tests/aipy_test.py @@ -14,7 +14,6 @@ from . import coord_test from . import deconv_test from . import miriad_test -from . import optimize_test from . import phs_test from . import phs_benchmark from . import scripting_test @@ -34,7 +33,6 @@ def __init__(self): self.addTest(coord_test.TestSuite()) self.addTest(deconv_test.TestSuite()) self.addTest(miriad_test.TestSuite()) - self.addTest(optimize_test.TestSuite()) self.addTest(phs_test.TestSuite()) self.addTest(phs_benchmark.TestSuite()) self.addTest(scripting_test.TestSuite()) diff --git a/tests/optimize_test.py b/tests/optimize_test.py deleted file mode 100644 index 6d0ccc96..00000000 --- a/tests/optimize_test.py +++ /dev/null @@ -1,132 +0,0 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function, division, absolute_import - -import unittest, numpy as n -import scipy.optimize as o - -class TestOptimize(unittest.TestCase): - def test_fmin(self): - """Test optimize.fmin""" - x0 = [0.8, 1.2, 0.7] - fit = o.fmin(o.rosen, x0, disp=0) - self.assertAlmostEqual(1.0, fit[0], 4) - self.assertAlmostEqual(1.0, fit[1], 4) - self.assertAlmostEqual(1.0, fit[2], 4) - - def test_fmin_powell(self): - """Test optimize.fmin_powell""" - x0 = [0.8, 1.2, 0.7] - fit = o.fmin_powell(o.rosen, x0, disp=0) - self.assertAlmostEqual(1.0, fit[0], 6) - self.assertAlmostEqual(1.0, fit[1], 6) - self.assertAlmostEqual(1.0, fit[2], 6) - - def test_fmin_ncg(self): - """Test optimize.fmin_ncg""" - x0 = [0.8, 1.2, 0.7] - fit = o.fmin_ncg(o.rosen, x0, o.rosen_der, disp=0, maxiter=80) - self.assertAlmostEqual(1.0, fit[0], 6) - self.assertAlmostEqual(1.0, fit[1], 6) - self.assertAlmostEqual(1.0, fit[2], 6) - - def test_fmin_ncg_hess_prod(self): - """Test optimize.fmin_ncg with Hessian product""" - x0 = [0.8, 1.2, 0.7] - fit = o.fmin_ncg(o.rosen, x0, o.rosen_der, fhess_p=o.rosen_hess_prod, disp=0, maxiter=80) - self.assertAlmostEqual(1.0, fit[0], 6) - self.assertAlmostEqual(1.0, fit[1], 6) - self.assertAlmostEqual(1.0, fit[2], 6) - - def test_fmin_ncg_hess_full(self): - """Test optimize.fmin_ncg with full Hessian""" - x0 = [0.8, 1.2, 0.7] - fit = o.fmin_ncg(o.rosen, x0, o.rosen_der, fhess=o.rosen_hess, disp=0, maxiter=80) - self.assertAlmostEqual(1.0, fit[0], 6) - self.assertAlmostEqual(1.0, fit[1], 6) - self.assertAlmostEqual(1.0, fit[2], 6) - -class TestAnneal(unittest.TestCase): - def test_cauchy(self): - """Test optimize.anneal with the cauchy schedule""" - func = lambda x: n.cos(14.5*x-0.3) + (x+0.2)*x - fit = o.anneal(func,1.0,full_output=1,upper=3.0,lower=-3.0,feps=1e-4,maxiter=2000,schedule='cauchy') - self.assertAlmostEqual(-0.195, fit[0], 2) - - def test_fast(self): - """Test optimize.anneal with the fast schedule""" - func = lambda x: n.cos(14.5*x-0.3) + (x+0.2)*x - fit = o.anneal(func,1.0,full_output=1,upper=3.0,lower=-3.0,feps=1e-4,maxiter=2000,schedule='fast') - self.assertAlmostEqual(-0.195, fit[0], 2) - - def test_boltzmann(self): - """Test optimize.anneal with the boltzmann schedule""" - func = lambda x: n.cos(14.5*x-0.3) + (x+0.2)*x - fit = o.anneal(func,1.0,full_output=1,upper=3.0,lower=-3.0,feps=1e-4,maxiter=2000,schedule='boltzmann') - self.assertAlmostEqual(-0.195, fit[0], 2) - - #def test_cauchy_twovar(self): - # func = lambda x: n.cos(14.5*x[0]-0.3) + (x[1]+0.2)*x[1] + (x[0]+0.2)*x[0] - # fit = o.anneal(func,[1.0, 1.0],full_output=1,upper=[3.0, 3.0],lower=[-3.0, -3.0],feps=1e-4,maxiter=2000,schedule='cauchy') - # self.assertAlmostEqual(-0.195, fit[0][0], 2) - # self.assertAlmostEqual(-0.100, fit[0][1], 2) - - #def test_fast_twovar(self): - # func = lambda x: n.cos(14.5*x[0]-0.3) + (x[1]+0.2)*x[1] + (x[0]+0.2)*x[0] - # fit = o.anneal(func,[1.0, 1.0],full_output=1,upper=[3.0, 3.0],lower=[-3.0, -3.0],feps=1e-4,maxiter=2000,schedule='fast') - # self.assertAlmostEqual(-0.195, fit[0][0], 2) - # self.assertAlmostEqual(-0.100, fit[0][1], 2) - - #def test_boltzmann_twovar(self): - # func = lambda x: n.cos(14.5*x[0]-0.3) + (x[1]+0.2)*x[1] + (x[0]+0.2)*x[0] - # fit = o.anneal(func,[1.0, 1.0],full_output=1,upper=[3.0, 3.0],lower=[-3.0, -3.0],feps=1e-4,maxiter=2000,schedule='boltzmann') - # self.assertAlmostEqual(-0.195, fit[0][0], 2) - # self.assertAlmostEqual(-0.100, fit[0][1], 2) - -class TestNonlin(unittest.TestCase): - def test_broyden1(self): - """Test optimize.broyden1""" - def F(x): - "Should converge to x=[0,0,0,0,0]" - d = n.array([3,2,1.5,1,0.5]) - c = 0.01 - return -d*n.array(x)-c*n.array(x)**3 - fit = o.broyden1(F,[1,1,1,1,1]) - for i in range(5): - self.assertAlmostEqual(0.0, fit[i], 0) - - def test_broyden2(self): - """Test optimize.broyden2""" - def F(x): - "Should converge to x=[0,0,0,0,0]" - d = n.array([3,2,1.5,1,0.5]) - c = 0.01 - return -d*n.array(x)-c*n.array(x)**3 - fit = o.broyden2(F,[1,1,1,1,1]) - for i in range(5): - self.assertAlmostEqual(0.0, fit[i], 4) - - def test_broyden3(self): - """Test optimize.broyden3""" - def F(x): - "Should converge to x=[0,0,0,0,0]" - d = n.array([3,2,1.5,1,0.5]) - c = 0.01 - return -d*n.array(x)-c*n.array(x)**3 - fit = o.broyden3(F,[1,1,1,1,1]) - for i in range(5): - self.assertAlmostEqual(0.0, fit[i], 4) - -class TestSuite(unittest.TestSuite): - """A unittest.TestSuite class which contains all of the aipy.phs unit tests.""" - - def __init__(self): - unittest.TestSuite.__init__(self) - - loader = unittest.TestLoader() - self.addTests(loader.loadTestsFromTestCase(TestOptimize)) - self.addTests(loader.loadTestsFromTestCase(TestAnneal)) - self.addTests(loader.loadTestsFromTestCase(TestNonlin)) - -if __name__ == '__main__': - unittest.main()