Changeset 734
- Timestamp:
- 07/28/14 18:08:15 (22 months ago)
- Location:
- mystic
- Files:
-
- 1 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
mystic/mystic/termination.py
r713 r734 291 291 sim = numpy.array(inst.population) 292 292 #if not len(sim[1:]): 293 # print "Warning: Invalid termination condition (nPop < 2)" 294 # return True 293 # warn = "Warning: Invalid termination condition (nPop < 2)" 294 # print warn 295 # return warn 295 296 if numpy.all(abs(sim - sim[0]) <= abs(tolerance * sim[0])): return info(doc) 296 297 return info(null) -
mystic/tests/test_solver_compare.py
r713 r734 9 9 try: 10 10 from scipy.optimize import fmin, fmin_powell 11 scipy_solvers = ['fmin_powell', 'fmin']12 11 except ImportError: 13 print "Warning: scipy not installed; comparison tests skipped" 14 scipy_solvers = [] 12 from mystic._scipyoptimize import fmin, fmin_powell 13 # print "Warning: scipy not installed; defaulting to local solver copy" 14 scipy_solvers = ['fmin_powell', 'fmin'] 15 15 16 16 import mystic.solvers as solvers … … 56 56 # print 'my:', my_x[0:2] 57 57 # print 'sp:', sp_x[0:2] 58 if m axiter != 0: # mystic can stop at iter=0, scipy can't58 if my_x[3] == sp_x[-2]: # mystic can stop at iter=0, scipy can't 59 59 assert almostEqual(my_x[0], sp_x[0]) 60 60 assert almostEqual(my_x[1], sp_x[1]) … … 76 76 77 77 # check solutions versus results based on the random_seed 78 78 # print "comparing against known results" 79 79 sol = solvers.diffev(rosen, x0, npop=40, disp=0, full_output=True) 80 80 assert almostEqual(sol[1], 0.0020640145337293249, tol=3e-3) … … 88 88 solver2 = 'diffev2' 89 89 for solver in ['diffev']: 90 90 # print "comparing %s and %s from mystic" % (solver, solver2) 91 91 test_solvers(solver, solver2, x0, npop=40) 92 #test_solvers(solver, solver2, x0, npop=40, maxiter=None, maxfun=0)93 #test_solvers(solver, solver2, x0, npop=40, maxiter=None, maxfun=1)94 #test_solvers(solver, solver2, x0, npop=40, maxiter=None, maxfun=2)95 #test_solvers(solver, solver2, x0, npop=40, maxiter=None, maxfun=9)92 test_solvers(solver, solver2, x0, npop=40, maxiter=None, maxfun=0) 93 test_solvers(solver, solver2, x0, npop=40, maxiter=None, maxfun=1) 94 test_solvers(solver, solver2, x0, npop=40, maxiter=None, maxfun=2) 95 test_solvers(solver, solver2, x0, npop=40, maxiter=None, maxfun=9) 96 96 test_solvers(solver, solver2, x0, npop=40, maxiter=0) 97 97 test_solvers(solver, solver2, x0, npop=40, maxiter=1) … … 100 100 101 101 for solver in scipy_solvers: 102 102 # print "comparing %s from mystic and scipy" % (solver) 103 103 test_compare(solver, x0) 104 #test_compare(solver, x0, maxiter=None, maxfun=0)105 #test_compare(solver, x0, maxiter=None, maxfun=1)106 #test_compare(solver, x0, maxiter=None, maxfun=2)107 #test_compare(solver, x0, maxiter=None, maxfun=9)104 test_compare(solver, x0, maxiter=None, maxfun=0) 105 test_compare(solver, x0, maxiter=None, maxfun=1) 106 test_compare(solver, x0, maxiter=None, maxfun=2) 107 test_compare(solver, x0, maxiter=None, maxfun=9) 108 108 test_compare(solver, x0, maxiter=0) 109 109 test_compare(solver, x0, maxiter=1) -
mystic/tests/test_solver_sanity.py
r713 r734 9 9 # should report clock-time, # of iterations, and # of function evaluations 10 10 11 import sys 12 from StringIO import StringIO 11 13 import unittest 12 14 from math import * 13 15 from mystic.math import almostEqual 16 17 def trap_stdout(): #XXX: better with contextmanager? 18 "temporarily trap stdout; return original sys.stdout" 19 orig, sys.stdout = sys.stdout, StringIO() 20 return orig 21 22 def release_stdout(orig): 23 "release stdout; return any trapped output as a string" 24 out = sys.stdout.getvalue() 25 sys.stdout.close() 26 sys.stdout = orig 27 return out 28 14 29 15 30 class TestRosenbrock(unittest.TestCase): … … 36 51 import numpy 37 52 from mystic.tools import random_seed 38 random_seed(321) 53 seed = 111 if self.maxiter is None else 321 #XXX: good numbers... 54 random_seed(seed) 39 55 esow = Monitor() 40 56 ssow = Monitor() … … 46 62 if self.useevalmon: solver.SetEvaluationMonitor(esow) 47 63 if self.usestepmon: solver.SetGenerationMonitor(ssow) 64 #### run solver, but trap output 65 _stdout = trap_stdout() 48 66 solver.Solve(self.costfunction, self.term, **kwds) 67 out = release_stdout(_stdout) 68 ################################ 49 69 sol = solver.Solution() 50 70 … … 68 88 if early_terminate: 69 89 self.assertTrue(solver.generations < 2) 90 warn = "Warning: Invalid termination condition (nPop < 2)" 91 self.assertTrue(warn in out) 70 92 return 71 93 … … 104 126 105 127 # Verify solution is close to exact 106 128 #print sol 107 129 for i in range(len(sol)): 108 130 self.assertAlmostEqual(sol[i], self.exact[i], self.precision) … … 232 254 suite1 = unittest.TestLoader().loadTestsFromTestCase(TestRosenbrock) 233 255 allsuites = unittest.TestSuite([suite1]) 256 # runner = unittest.TextTestRunner(verbosity=2) 257 runner = unittest.TextTestRunner() 258 234 259 my_maxiter = 0 235 # my_maxiter = 1 236 # my_maxiter = 2 237 # my_maxiter = None 238 unittest.TextTestRunner(verbosity=2).run(allsuites) 260 runner.run(allsuites) 261 my_maxiter = 1 262 runner.run(allsuites) 263 my_maxiter = 2 264 runner.run(allsuites) 265 my_maxiter = None 266 runner.run(allsuites) 267 239 268 240 269 # EOF
Note: See TracChangeset
for help on using the changeset viewer.