Changeset 376
- Timestamp:
- 08/05/10 16:47:50 (6 years ago)
- Location:
- branches/alta/mystic-0.2a1
- Files:
-
- 9 added
- 3 edited
- 13 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/alta/mystic-0.2a1/augmented_lagrangian_constraints.py
r373 r376 250 250 x = solver.Solution() 251 251 252 #XXX When a user sets maxiter and maxfun, that is actually the maxiter 253 # and maxfun *each* SUMT iteration. The total iterations could actually 254 # be much more. Adjust for that, or just write a warning in the 255 # documentation? 252 # When a user sets maxiter and maxfun, that is actually the maxiter 253 # and maxfun *each* SUMT iteration. However, it is difficult to check 254 # total maxfun and maxiter each SUMT iteration because then what 255 # would the inner maxiter and maxfun be? Better to just leave maxiter 256 # and maxfun as limits for each inner optimization... 256 257 total_iterations += solver.generations 257 258 total_energy_history += solver.energy_history -
branches/alta/mystic-0.2a1/constrained_tests/test_constraints_mech_design.py
r360 r376 25 25 Comparison of different software: 26 26 27 Again, expected: (1.125, 0.625, 58.290, 43.693), f=719828 29 27 Mystic results: 30 28 --------------- 31 Penalty method, with penalty=1e6: 32 DifferentialEvolution, penalty: 33 soln= [ 1.125 0.625 58.37151357 42.91702352] 34 f value = 7178.27575655 35 Time elapsed= 15.0106379986 36 Constraints satisfied? True 37 38 DifferentialEvolution2, penalty: 39 soln= [ 1.125 0.625 58.37151357 42.91702354] 40 f value = 7178.27575755 41 Time elapsed= 14.9718539715 42 Constraints satisfied? True 43 44 NelderMead, penalty: 45 soln= [ 1.125 0.625 50.03412086 97.57104948] 46 f value = 7847.70126182 47 Time elapsed= 0.76296710968 48 Constraints satisfied? True 49 50 Powelldirectional, penalty: 51 soln= [ 1.125 0.625 58.37151357 42.91702357] 52 f value = 7178.27575886 53 Time elapsed= 3.08916687965 54 Constraints satisfied? True 55 56 BFGS, penalty: 57 soln= [ 1.34557843 1.27226119 59.09936969 53.98159996] 58 f value = 13005.5250723 59 Time elapsed= 0.159216880798 60 Constraints satisfied? True 61 62 NCG, penalty: 63 soln= [ 1.27032014 1.65777684 48.03515965 101.04926928] 64 f value = 12693.3502272 65 Time elapsed= 1.65720391273 66 Constraints satisfied? False 67 68 CG, penalty: 69 soln= [ 1.12505189 1.17561523 54.25138573 107.57753739] 70 f value = 12032.5868672 71 Time elapsed= 0.224512815475 72 Constraints satisfied? True 73 74 Augmented Lagrangian method: 75 Note: results below are with non-default rg, rh due to this problem having 76 large function values. 77 78 Diffev, auglag: 79 soln= [ 1.125 0.625 58.29018567 43.69246167] 80 f value = 7198.00229999 81 Time elapsed= 315.373667955 82 True 83 84 Diffev2, auglag: 85 soln= [ 1.125 0.625 58.29015258 43.69267472] 86 f value = 7198.00571951 87 Time elapsed= 250.608822107 88 True 89 90 NelderMead, auglag: 91 soln= [ 1.12539147 0.625 58.29557452 43.67355902] 92 f value = 7199.91438019 93 Time elapsed= 12.3814969063 94 True 95 96 PowellDirectional, auglag: 97 soln= [ 1.125 0.625 58.28263221 43.77778598] 98 f value = 7200.42694867 99 Time elapsed= 70.8250758648 100 True 101 102 BFGS, auglag: 103 soln= [ 1.13929512 0.6250201 47.65228491 49.18558259] 104 f value = 5614.85177789 105 Time elapsed= 0.646522045135 106 False 107 108 NCG, auglag: 109 soln= [ 1.17081815 0.74488168 48.14483527 48.6160188 ] 110 f value = 6296.06882163 111 Time elapsed= 28.1646289825 112 False 113 114 CG, auglag: 115 soln= [ 1.12502104 0.69798627 48.14299071 48.61562258] 116 f value = 5919.11213151 117 Time elapsed= 0.31470990181 118 False 119 120 For the code that generated these results, see the code in this script. 121 None of the time results are particularly rigorous, but are included just to 122 get a general idea. 29 None of the times listed are particularly rigorous, but are included just to 30 get a general idea. Penalty method used penalty=1e7. Termination conditions 31 were the default for the solver. Note that while verify_constraints_satisfied 32 says the constraints are satisfied, it is with tol=1e-6, so some of the 33 constraints may not actually be strictly satisfied (tol=1e-6 is pretty lenient, 34 as it is the sum of squared errors <= 1e-6). 35 36 DifferentialEvolution, penalty: 37 soln= [ 1.125 0.625 58.29836344 43.61450809] 38 f value = 7196.02292104 39 Time elapsed= 6.968075037 40 True 41 42 DifferentialEvolution2, penalty: 43 soln= [ 1.125 0.625 58.29836493 43.61449852] 44 f value = 7196.02276745 45 Time elapsed= 6.39398908615 46 True 47 48 NelderMead, penalty: 49 soln= [ 1.1250001 0.71579527 58.28008846 43.74569592] 50 f value = 7746.8703903 51 Time elapsed= 0.736877918243 52 True 53 54 Powelldirectional, penalty: 55 soln= [ 1.125 0.625 58.29439508 43.64290028] 56 f value = 7196.56057668 57 Time elapsed= 3.49020886421 58 True 59 60 BFGS, penalty: 61 soln= [ 1.25 0.625 50. 120. ] 62 f value = 9589.925 63 Time elapsed= 0.288455963135 64 True 65 66 NCG, penalty: 67 ^C 68 soln= [ NaN NaN NaN NaN] 69 f value = nan 70 Time elapsed= 43.6070699692 71 False 72 73 CG, penalty: 74 soln= [ 1.25 0.625 50. 120. ] 75 f value = 9589.925 76 Time elapsed= 0.00531411170959 77 True 78 79 Diffev, auglag: 80 soln= [ 1.12500503 0.62500011 58.29013632 43.69342076] 81 f value = 7198.05944809 82 Time elapsed= 43.1847889423 83 True 84 85 Diffev2, auglag: 86 soln= [ 1.125 0.625 58.28943222 43.69711476] 87 f value = 7198.07127457 88 Time elapsed= 41.6524450779 89 True 90 91 NelderMead, auglag: 92 soln= [ 1.12557137 0.625 58.35821875 43.27438764] 93 f value = 7194.41567298 94 Time elapsed= 8.42519307137 95 True 96 97 PowellDirectional, auglag: 98 soln= [ 1.125 0.625 58.2737825 43.81915823] 99 f value = 7200.64105846 100 Time elapsed= 19.0831940174 101 True 102 103 BFGS, auglag: 104 soln= [ 1.25 0.625 50. 120. ] 105 f value = 9589.925 106 Time elapsed= 0.0480899810791 107 True 108 109 NCG, auglag: 110 ^C 111 soln= [ NaN NaN NaN NaN] 112 f value = nan 113 Time elapsed= 16.3369438648 114 False 115 116 CG, auglag: 117 soln= [ 1.25 0.625 50. 120. ] 118 f value = 9589.925 119 Time elapsed= 0.0273869037628 120 True 121 123 122 124 123 OpenOpt code and results: … … 167 166 # Random seed 168 167 from mystic.tools import random_seed 169 seed = 789#123168 seed = 123 170 169 random_seed(seed) 171 170 … … 180 179 ndim = 4 181 180 x0 = [1.25, 0.625, 50., 120.] # Source: Kannan and Kramer 182 npop = 30 # for differential evolution181 npop = 50 # for differential evolution 183 182 184 183 lb = [1.125, 0.625, 40., 40.] … … 194 193 time_before = time.time() 195 194 196 from constraint_tools import wrap_constraints_to_cost195 from mystic.constraint_tools import wrap_constraints_to_cost 197 196 constrained_cost = wrap_constraints_to_cost(constraints_string, ndim, costfunc)#,\ 198 197 # penalty=1e6) 199 from differential_evolution import DifferentialEvolutionSolver198 from mystic.differential_evolution import DifferentialEvolutionSolver 200 199 from mystic.termination import VTR 201 200 solver = DifferentialEvolutionSolver(ndim, npop) … … 210 209 print "Time elapsed=", time_elapsed 211 210 212 from constraint_tools import verify_constraints_satisfied213 print verify_constraints_satisfied(constraints_string, soln )211 from mystic.constraint_tools import verify_constraints_satisfied 212 print verify_constraints_satisfied(constraints_string, soln, disp=False) 214 213 215 214 #------------------------------------------------------------- … … 225 224 time_before = time.time() 226 225 227 from differential_evolution import DifferentialEvolutionSolver 228 from mystic.termination import VTR 226 from mystic.differential_evolution import DifferentialEvolutionSolver 227 from mystic.termination import VTR 228 from mystic.termination import ChangeOverGeneration as COG 229 229 solver = DifferentialEvolutionSolver(ndim, npop) 230 230 solver.SetStrictRanges(lb, ub) 231 231 solver.SetInitialPoints(x0) 232 232 solver.enable_signal_handler() 233 term = VTR() 234 solver.Solve(costfunc, term, constraints=constraints_string, \ 235 constraints_method='penalty', penalty=1e7) 236 soln = solver.Solution() 237 238 time_elapsed = time.time() - time_before 239 print "soln=", soln 240 print "f value =", costfunc(soln) 241 print "Time elapsed=", time_elapsed 242 243 from constraint_tools import verify_constraints_satisfied 244 print verify_constraints_satisfied(constraints_string, soln) 233 #term = VTR() 234 term = COG() 235 # here, Best1Bin seems better than Rand1Bin 236 solver.Solve(costfunc, term, constraints=constraints_string, \ 237 constraints_method='penalty', penalty=1e7) 238 soln = solver.Solution() 239 240 time_elapsed = time.time() - time_before 241 print "soln=", soln 242 print "f value =", costfunc(soln) 243 print "Time elapsed=", time_elapsed 244 245 from mystic.constraint_tools import verify_constraints_satisfied 246 print verify_constraints_satisfied(constraints_string, soln, disp=False) 245 247 246 248 def test_diffev2_penalty(): … … 254 256 time_before = time.time() 255 257 256 from differential_evolution import DifferentialEvolutionSolver2 257 from mystic.termination import VTR 258 from mystic.differential_evolution import DifferentialEvolutionSolver2 259 from mystic.termination import VTR 260 from mystic.termination import ChangeOverGeneration as COG 258 261 solver = DifferentialEvolutionSolver2(ndim, npop) 259 262 solver.SetStrictRanges(lb, ub) 260 263 solver.SetInitialPoints(x0) 261 264 solver.enable_signal_handler() 262 term = VTR() 263 solver.Solve(costfunc, term, constraints=constraints_string, \ 264 constraints_method='penalty', penalty=1e6) 265 soln = solver.Solution() 266 267 time_elapsed = time.time() - time_before 268 print "soln=", soln 269 print "f value =", costfunc(soln) 270 print "Time elapsed=", time_elapsed 271 272 from constraint_tools import verify_constraints_satisfied 273 print verify_constraints_satisfied(constraints_string, soln) 265 #term = VTR() 266 term = COG() 267 solver.Solve(costfunc, term, constraints=constraints_string, \ 268 constraints_method='penalty', penalty=1e7) 269 soln = solver.Solution() 270 271 time_elapsed = time.time() - time_before 272 print "soln=", soln 273 print "f value =", costfunc(soln) 274 print "Time elapsed=", time_elapsed 275 276 from mystic.constraint_tools import verify_constraints_satisfied 277 print verify_constraints_satisfied(constraints_string, soln, disp=False) 274 278 275 279 def test_neldermead_penalty(): … … 283 287 time_before = time.time() 284 288 285 from scipy_optimize import NelderMeadSimplexSolver289 from mystic.scipy_optimize import NelderMeadSimplexSolver 286 290 from mystic.termination import VTR 287 291 from mystic.termination import CandidateRelativeTolerance as CRT … … 292 296 solver.SetInitialPoints(x0) 293 297 solver.enable_signal_handler() 294 term = VTR()295 #term = CRT(1e-9)298 #term = VTR() 299 term = CRT() 296 300 #term = COG(1e-9) 297 301 #term = NCOG() 298 302 solver.Solve(costfunc, term, constraints=constraints_string, \ 299 constraints_method='penalty', penalty=1e 6)300 soln = solver.Solution() 301 302 time_elapsed = time.time() - time_before 303 print "soln=", soln 304 print "f value =", costfunc(soln) 305 print "Time elapsed=", time_elapsed 306 307 from constraint_tools import verify_constraints_satisfied308 print verify_constraints_satisfied(constraints_string, soln )303 constraints_method='penalty', penalty=1e7) 304 soln = solver.Solution() 305 306 time_elapsed = time.time() - time_before 307 print "soln=", soln 308 print "f value =", costfunc(soln) 309 print "Time elapsed=", time_elapsed 310 311 from mystic.constraint_tools import verify_constraints_satisfied 312 print verify_constraints_satisfied(constraints_string, soln, disp=False) 309 313 310 314 … … 319 323 time_before = time.time() 320 324 321 from scipy_optimize import PowellDirectionalSolver 322 from mystic.termination import VTR 325 from mystic.scipy_optimize import PowellDirectionalSolver 326 from mystic.termination import VTR 327 from mystic.termination import NormalizedChangeOverGeneration as NCOG 323 328 solver = PowellDirectionalSolver(ndim) 324 329 solver.SetStrictRanges(lb, ub) 325 330 solver.SetInitialPoints(x0) 326 331 solver.enable_signal_handler() 327 term = VTR() 328 solver.Solve(costfunc, term, constraints=constraints_string, \ 329 constraints_method='penalty', penalty=1e6) 330 soln = solver.Solution() 331 332 time_elapsed = time.time() - time_before 333 print "soln=", soln 334 print "f value =", costfunc(soln) 335 print "Time elapsed=", time_elapsed 336 337 from constraint_tools import verify_constraints_satisfied 338 print verify_constraints_satisfied(constraints_string, soln) 332 #term = VTR() 333 term = NCOG() 334 solver.Solve(costfunc, term, constraints=constraints_string, \ 335 constraints_method='penalty', penalty=1e7) 336 soln = solver.Solution() 337 338 time_elapsed = time.time() - time_before 339 print "soln=", soln 340 print "f value =", costfunc(soln) 341 print "Time elapsed=", time_elapsed 342 343 from mystic.constraint_tools import verify_constraints_satisfied 344 print verify_constraints_satisfied(constraints_string, soln, disp=False) 339 345 340 346 def test_bfgs_penalty(): … … 348 354 time_before = time.time() 349 355 350 from scipy_bfgs import BFGSSolver 351 from mystic.termination import VTR 356 from mystic.scipy_bfgs import BFGSSolver 357 from mystic.termination import VTR 358 from mystic.termination import GradientTermination 352 359 solver = BFGSSolver(ndim) 353 360 solver.SetStrictRanges(lb, ub) 354 361 solver.SetInitialPoints(x0) 355 362 solver.enable_signal_handler() 356 term = VTR() 357 solver.Solve(costfunc, term, constraints=constraints_string, \ 358 constraints_method='penalty', penalty=1e6) 359 soln = solver.Solution() 360 361 time_elapsed = time.time() - time_before 362 print "soln=", soln 363 print "f value =", costfunc(soln) 364 print "Time elapsed=", time_elapsed 365 366 from constraint_tools import verify_constraints_satisfied 367 print verify_constraints_satisfied(constraints_string, soln) 363 #term = VTR() 364 term = GradientTermination() 365 solver.Solve(costfunc, term, constraints=constraints_string, \ 366 constraints_method='penalty', penalty=1e7) 367 soln = solver.Solution() 368 369 time_elapsed = time.time() - time_before 370 print "soln=", soln 371 print "f value =", costfunc(soln) 372 print "Time elapsed=", time_elapsed 373 374 from mystic.constraint_tools import verify_constraints_satisfied 375 print verify_constraints_satisfied(constraints_string, soln, disp=False) 368 376 369 377 def test_ncg_penalty(): … … 377 385 time_before = time.time() 378 386 379 from scipy_ncg import NCGSolver 380 from mystic.termination import VTR 387 from mystic.scipy_ncg import NCGSolver 388 from mystic.termination import VTR 389 from mystic.termination import SolutionImprovement 381 390 solver = NCGSolver(ndim) 382 391 solver.SetStrictRanges(lb, ub) 383 392 solver.SetInitialPoints(x0) 384 393 solver.enable_signal_handler() 385 term = VTR() 386 solver.Solve(costfunc, term, constraints=constraints_string, \ 387 constraints_method='penalty', penalty=1e6) 388 soln = solver.Solution() 389 390 time_elapsed = time.time() - time_before 391 print "soln=", soln 392 print "f value =", costfunc(soln) 393 print "Time elapsed=", time_elapsed 394 395 from constraint_tools import verify_constraints_satisfied 396 print verify_constraints_satisfied(constraints_string, soln) 394 #term = VTR() 395 term = SolutionImprovement() 396 solver.Solve(costfunc, term, constraints=constraints_string, \ 397 constraints_method='penalty', penalty=1e7) 398 soln = solver.Solution() 399 400 time_elapsed = time.time() - time_before 401 print "soln=", soln 402 print "f value =", costfunc(soln) 403 print "Time elapsed=", time_elapsed 404 405 from mystic.constraint_tools import verify_constraints_satisfied 406 print verify_constraints_satisfied(constraints_string, soln, disp=False) 397 407 398 408 def test_cg_penalty(): … … 406 416 time_before = time.time() 407 417 408 from scipy_cg import CGSolver418 from mystic.scipy_cg import CGSolver 409 419 from mystic.termination import VTR 410 420 from mystic.termination import GradientTermination … … 413 423 solver.SetInitialPoints(x0) 414 424 solver.enable_signal_handler() 415 term = VTR()416 #term = GradientTermination()417 solver.Solve(costfunc, term, constraints=constraints_string, \ 418 constraints_method='penalty', penalty=1e 6)419 soln = solver.Solution() 420 421 time_elapsed = time.time() - time_before 422 print "soln=", soln 423 print "f value =", costfunc(soln) 424 print "Time elapsed=", time_elapsed 425 426 from constraint_tools import verify_constraints_satisfied427 print verify_constraints_satisfied(constraints_string, soln )425 #term = VTR() 426 term = GradientTermination() 427 solver.Solve(costfunc, term, constraints=constraints_string, \ 428 constraints_method='penalty', penalty=1e7) 429 soln = solver.Solution() 430 431 time_elapsed = time.time() - time_before 432 print "soln=", soln 433 print "f value =", costfunc(soln) 434 print "Time elapsed=", time_elapsed 435 436 from mystic.constraint_tools import verify_constraints_satisfied 437 print verify_constraints_satisfied(constraints_string, soln, disp=False) 428 438 429 439 #--------------------------------------------------------------------- … … 439 449 time_before = time.time() 440 450 441 from differential_evolution import DifferentialEvolutionSolver 442 from mystic.termination import VTR 451 from mystic.differential_evolution import DifferentialEvolutionSolver 452 from mystic.termination import VTR 453 from mystic.termination import ChangeOverGeneration as COG 443 454 solver = DifferentialEvolutionSolver(ndim, npop) 444 455 solver.SetStrictRanges(lb, ub) 445 456 solver.SetInitialPoints(x0) 446 457 solver.enable_signal_handler() 447 term = VTR() 448 solver.Solve(costfunc, term, constraints=constraints_string, \ 449 constraints_method='auglag', disp=True, rg=1e3, rh=1e3) 450 soln = solver.Solution() 451 452 time_elapsed = time.time() - time_before 453 print "soln=", soln 454 print "f value =", costfunc(soln) 455 print "Time elapsed=", time_elapsed 456 457 from constraint_tools import verify_constraints_satisfied 458 print verify_constraints_satisfied(constraints_string, soln) 458 #term = VTR() 459 term = COG() 460 solver.Solve(costfunc, term, constraints=constraints_string, \ 461 constraints_method='auglag',rg=1e3, rh=1e3) 462 soln = solver.Solution() 463 464 time_elapsed = time.time() - time_before 465 print "soln=", soln 466 print "f value =", costfunc(soln) 467 print "Time elapsed=", time_elapsed 468 469 from mystic.constraint_tools import verify_constraints_satisfied 470 print verify_constraints_satisfied(constraints_string, soln, disp=False) 459 471 460 472 def test_diffev2_auglag(): … … 468 480 time_before = time.time() 469 481 470 from differential_evolution import DifferentialEvolutionSolver2 471 from mystic.termination import VTR 482 from mystic.differential_evolution import DifferentialEvolutionSolver2 483 from mystic.termination import VTR 484 from mystic.termination import ChangeOverGeneration as COG 472 485 solver = DifferentialEvolutionSolver2(ndim, npop) 473 486 solver.SetStrictRanges(lb, ub) 474 487 solver.SetInitialPoints(x0) 475 488 solver.enable_signal_handler() 476 term = VTR() 489 #term = VTR() 490 term = COG() 477 491 solver.Solve(costfunc, term, constraints=constraints_string, \ 478 492 constraints_method='auglag', rg=1e3, rh=1e3) … … 484 498 print "Time elapsed=", time_elapsed 485 499 486 from constraint_tools import verify_constraints_satisfied487 print verify_constraints_satisfied(constraints_string, soln )500 from mystic.constraint_tools import verify_constraints_satisfied 501 print verify_constraints_satisfied(constraints_string, soln, disp=False) 488 502 489 503 def test_neldermead_auglag(): … … 497 511 time_before = time.time() 498 512 499 from scipy_optimize import NelderMeadSimplexSolver513 from mystic.scipy_optimize import NelderMeadSimplexSolver 500 514 from mystic.termination import VTR 501 515 from mystic.termination import CandidateRelativeTolerance as CRT … … 504 518 solver.SetInitialPoints(x0) 505 519 solver.enable_signal_handler() 506 term = VTR()507 #term = CRT()520 #term = VTR() 521 term = CRT() 508 522 solver.Solve(costfunc, term, constraints=constraints_string, \ 509 523 constraints_method='auglag', rg=1e3, rh=1e3) … … 515 529 print "Time elapsed=", time_elapsed 516 530 517 from constraint_tools import verify_constraints_satisfied518 print verify_constraints_satisfied(constraints_string, soln )531 from mystic.constraint_tools import verify_constraints_satisfied 532 print verify_constraints_satisfied(constraints_string, soln, disp=False) 519 533 520 534 def test_powelldirectional_auglag(): … … 528 542 time_before = time.time() 529 543 530 from scipy_optimize import PowellDirectionalSolver544 from mystic.scipy_optimize import PowellDirectionalSolver 531 545 from mystic.termination import VTR 532 546 from mystic.termination import NormalizedChangeOverGeneration as NCOG … … 535 549 solver.SetInitialPoints(x0) 536 550 solver.enable_signal_handler() 537 term = VTR()538 #term = NCOG(1e-8)551 #term = VTR() 552 term = NCOG() 539 553 solver.Solve(costfunc, term, constraints=constraints_string, \ 540 554 constraints_method='auglag', rg=1e3, rh=1e3) … … 546 560 print "Time elapsed=", time_elapsed 547 561 548 from constraint_tools import verify_constraints_satisfied549 print verify_constraints_satisfied(constraints_string, soln )562 from mystic.constraint_tools import verify_constraints_satisfied 563 print verify_constraints_satisfied(constraints_string, soln, disp=False) 550 564 551 565 def test_bfgs_auglag(): … … 559 573 time_before = time.time() 560 574 561 from scipy_bfgs import BFGSSolver562 from mystic.termination import VTR 563 from termination import GradientTermination575 from mystic.scipy_bfgs import BFGSSolver 576 from mystic.termination import VTR 577 from mystic.termination import GradientTermination 564 578 from mystic.termination import ChangeOverGeneration as COG 565 579 solver = BFGSSolver(ndim) … … 567 581 solver.SetInitialPoints(x0) 568 582 solver.enable_signal_handler() 569 term = VTR()570 #term = GradientTermination()583 #term = VTR() 584 term = GradientTermination() 571 585 #term = COG() 572 586 solver.Solve(costfunc, term, constraints=constraints_string, \ … … 579 593 print "Time elapsed=", time_elapsed 580 594 581 from constraint_tools import verify_constraints_satisfied582 print verify_constraints_satisfied(constraints_string, soln )595 from mystic.constraint_tools import verify_constraints_satisfied 596 print verify_constraints_satisfied(constraints_string, soln, disp=False) 583 597 584 598 def test_ncg_auglag(): … … 592 606 time_before = time.time() 593 607 594 from scipy_ncg import NCGSolver 595 from mystic.termination import VTR 608 from mystic.scipy_ncg import NCGSolver 609 from mystic.termination import VTR 610 from mystic.termination import SolutionImprovement 596 611 solver = NCGSolver(ndim) 597 612 solver.SetStrictRanges(lb, ub) 598 613 solver.SetInitialPoints(x0) 599 614 solver.enable_signal_handler() 600 term = VTR() 615 #term = VTR() 616 term = SolutionImprovement() 601 617 solver.Solve(costfunc, term, constraints=constraints_string, \ 602 618 constraints_method='auglag', rg=1e3, rh=1e3) … … 608 624 print "Time elapsed=", time_elapsed 609 625 610 from constraint_tools import verify_constraints_satisfied611 print verify_constraints_satisfied(constraints_string, soln )626 from mystic.constraint_tools import verify_constraints_satisfied 627 print verify_constraints_satisfied(constraints_string, soln, disp=False) 612 628 613 629 def test_cg_auglag(): … … 621 637 time_before = time.time() 622 638 623 from scipy_cg import CGSolver 624 from mystic.termination import VTR 639 from mystic.scipy_cg import CGSolver 640 from mystic.termination import VTR 641 from mystic.termination import GradientTermination 625 642 solver = CGSolver(ndim) 626 643 solver.SetStrictRanges(lb, ub) 627 644 solver.SetInitialPoints(x0) 628 645 solver.enable_signal_handler() 629 term = VTR() 646 #term = VTR() 647 term = GradientTermination() 630 648 solver.Solve(costfunc, term, constraints=constraints_string, \ 631 649 constraints_method='auglag', rg=1e3, rh=1e3) … … 637 655 print "Time elapsed=", time_elapsed 638 656 639 from constraint_tools import verify_constraints_satisfied640 print verify_constraints_satisfied(constraints_string, soln )657 from mystic.constraint_tools import verify_constraints_satisfied 658 print verify_constraints_satisfied(constraints_string, soln, disp=False) 641 659 642 660 if __name__ == '__main__': … … 644 662 # the function values for this function are quite high, on the order of 645 663 # 1e3 to 1e4. 664 # Default VTR may not be a good termination here, since f(min) ~ 7000 646 665 647 666 #test_direct_diffev_penalty() -
branches/alta/mystic-0.2a1/constrained_tests/test_constraints_openoptexample.py
r367 r376 119 119 120 120 """ 121 from constraint_tools import verify_constraints_satisfied121 from mystic.constraint_tools import verify_constraints_satisfied 122 122 import time 123 123 … … 160 160 time_before = time.time() 161 161 162 from differential_evolution import DifferentialEvolutionSolver162 from mystic.differential_evolution import DifferentialEvolutionSolver 163 163 from mystic.termination import VTR 164 164 from mystic.termination import CandidateRelativeTolerance as CRT … … 178 178 print "Time elapsed=", time_elapsed 179 179 180 from constraint_tools import verify_constraints_satisfied180 from mystic.constraint_tools import verify_constraints_satisfied 181 181 print verify_constraints_satisfied(constraints_string, soln,\ 182 182 varnamelist=varnamelist) … … 193 193 time_before = time.time() 194 194 195 from differential_evolution import DifferentialEvolutionSolver2195 from mystic.differential_evolution import DifferentialEvolutionSolver2 196 196 from mystic.termination import VTR 197 197 solver = DifferentialEvolutionSolver2(ndim, npop) … … 209 209 print "Time elapsed=", time_elapsed 210 210 211 from constraint_tools import verify_constraints_satisfied211 from mystic.constraint_tools import verify_constraints_satisfied 212 212 print verify_constraints_satisfied(constraints_string, soln,\ 213 213 varnamelist=varnamelist) … … 224 224 time_before = time.time() 225 225 226 from scipy_optimize import NelderMeadSimplexSolver226 from mystic.scipy_optimize import NelderMeadSimplexSolver 227 227 from mystic.termination import VTR 228 228 solver = NelderMeadSimplexSolver(ndim) … … 240 240 print "Time elapsed=", time_elapsed 241 241 242 from constraint_tools import verify_constraints_satisfied242 from mystic.constraint_tools import verify_constraints_satisfied 243 243 print verify_constraints_satisfied(constraints_string, soln,\ 244 244 varnamelist=varnamelist) … … 255 255 time_before = time.time() 256 256 257 from scipy_optimize import PowellDirectionalSolver257 from mystic.scipy_optimize import PowellDirectionalSolver 258 258 from mystic.termination import VTR 259 259 solver = PowellDirectionalSolver(ndim) … … 272 272 print "Time elapsed=", time_elapsed 273 273 274 from constraint_tools import verify_constraints_satisfied274 from mystic.constraint_tools import verify_constraints_satisfied 275 275 print verify_constraints_satisfied(constraints_string, soln,\ 276 276 varnamelist=varnamelist) … … 286 286 time_before = time.time() 287 287 288 from scipy_bfgs import BFGSSolver289 from mystic.termination import VTR 290 from termination import GradientTermination288 from mystic.scipy_bfgs import BFGSSolver 289 from mystic.termination import VTR 290 from mystic.termination import GradientTermination 291 291 solver = BFGSSolver(ndim) 292 292 … … 305 305 print "Time elapsed=", time_elapsed 306 306 307 from constraint_tools import verify_constraints_satisfied307 from mystic.constraint_tools import verify_constraints_satisfied 308 308 print verify_constraints_satisfied(constraints_string, soln,\ 309 309 varnamelist=varnamelist) … … 319 319 time_before = time.time() 320 320 321 from scipy_ncg import NCGSolver321 from mystic.scipy_ncg import NCGSolver 322 322 from mystic.termination import VTR 323 323 solver = NCGSolver(ndim) … … 336 336 print "Time elapsed=", time_elapsed 337 337 338 from constraint_tools import verify_constraints_satisfied338 from mystic.constraint_tools import verify_constraints_satisfied 339 339 print verify_constraints_satisfied(constraints_string, soln,\ 340 340 varnamelist=varnamelist) … … 350 350 time_before = time.time() 351 351 352 from scipy_cg import CGSolver352 from mystic.scipy_cg import CGSolver 353 353 from mystic.termination import VTR 354 354 solver = CGSolver(ndim) … … 367 367 print "Time elapsed=", time_elapsed 368 368 369 from constraint_tools import verify_constraints_satisfied369 from mystic.constraint_tools import verify_constraints_satisfied 370 370 print verify_constraints_satisfied(constraints_string, soln,\ 371 371 varnamelist=varnamelist) … … 383 383 time_before = time.time() 384 384 385 from differential_evolution import DifferentialEvolutionSolver385 from mystic.differential_evolution import DifferentialEvolutionSolver 386 386 from mystic.termination import VTR 387 387 solver = DifferentialEvolutionSolver(ndim, npop) … … 401 401 print "Time elapsed=", time_elapsed 402 402 403 from constraint_tools import verify_constraints_satisfied403 from mystic.constraint_tools import verify_constraints_satisfied 404 404 print verify_constraints_satisfied(constraints_string, soln,\ 405 405 varnamelist=varnamelist) … … 415 415 time_before = time.time() 416 416 417 from differential_evolution import DifferentialEvolutionSolver2417 from mystic.differential_evolution import DifferentialEvolutionSolver2 418 418 from mystic.termination import VTR 419 419 solver = DifferentialEvolutionSolver2(ndim, npop) … … 432 432 print "Time elapsed=", time_elapsed 433 433 434 from constraint_tools import verify_constraints_satisfied434 from mystic.constraint_tools import verify_constraints_satisfied 435 435 print verify_constraints_satisfied(constraints_string, soln,\ 436 436 varnamelist=varnamelist) … … 447 447 time_before = time.time() 448 448 449 from scipy_optimize import NelderMeadSimplexSolver449 from mystic.scipy_optimize import NelderMeadSimplexSolver 450 450 from mystic.termination import VTR 451 451 solver = NelderMeadSimplexSolver(ndim) … … 463 463 print "Time elapsed=", time_elapsed 464 464 465 from constraint_tools import verify_constraints_satisfied465 from mystic.constraint_tools import verify_constraints_satisfied 466 466 print verify_constraints_satisfied(constraints_string, soln,\ 467 467 varnamelist=varnamelist) … … 478 478 time_before = time.time() 479 479 480 from scipy_optimize import PowellDirectionalSolver480 from mystic.scipy_optimize import PowellDirectionalSolver 481 481 from mystic.termination import VTR 482 482 solver = PowellDirectionalSolver(ndim) … … 494 494 print "Time elapsed=", time_elapsed 495 495 496 from constraint_tools import verify_constraints_satisfied496 from mystic.constraint_tools import verify_constraints_satisfied 497 497 print verify_constraints_satisfied(constraints_string, soln,\ 498 498 varnamelist=varnamelist) … … 508 508 time_before = time.time() 509 509 510 from scipy_bfgs import BFGSSolver510 from mystic.scipy_bfgs import BFGSSolver 511 511 from mystic.termination import VTR 512 512 solver = BFGSSolver(ndim) … … 525 525 print "Time elapsed=", time_elapsed 526 526 527 from constraint_tools import verify_constraints_satisfied527 from mystic.constraint_tools import verify_constraints_satisfied 528 528 print verify_constraints_satisfied(constraints_string, soln,\ 529 529 varnamelist=varnamelist) … … 539 539 time_before = time.time() 540 540 541 from scipy_ncg import NCGSolver541 from mystic.scipy_ncg import NCGSolver 542 542 from mystic.termination import VTR 543 543 solver = NCGSolver(ndim) … … 555 555 print "Time elapsed=", time_elapsed 556 556 557 from constraint_tools import verify_constraints_satisfied557 from mystic.constraint_tools import verify_constraints_satisfied 558 558 print verify_constraints_satisfied(constraints_string, soln,\ 559 559 varnamelist=varnamelist) … … 569 569 time_before = time.time() 570 570 571 from scipy_cg import CGSolver571 from mystic.scipy_cg import CGSolver 572 572 from mystic.termination import VTR 573 573 solver = CGSolver(ndim) … … 587 587 print "Time elapsed=", time_elapsed 588 588 589 from constraint_tools import verify_constraints_satisfied589 from mystic.constraint_tools import verify_constraints_satisfied 590 590 print verify_constraints_satisfied(constraints_string, soln,\ 591 591 varnamelist=varnamelist) -
branches/alta/mystic-0.2a1/constrained_tests/test_constraints_range.py
r373 r376 35 35 36 36 import numpy 37 from constraint_tools import verify_constraints_satisfied37 from mystic.constraint_tools import verify_constraints_satisfied 38 38 import time 39 39 … … 79 79 time_before = time.time() 80 80 81 from differential_evolution import DifferentialEvolutionSolver81 from mystic.differential_evolution import DifferentialEvolutionSolver 82 82 from mystic.termination import VTR 83 83 from mystic.termination import CandidateRelativeTolerance as CRT … … 100 100 print "Time elapsed=", time_elapsed 101 101 102 from constraint_tools import verify_constraints_satisfied102 from mystic.constraint_tools import verify_constraints_satisfied 103 103 print verify_constraints_satisfied(constraints_string, soln, disp=False) 104 104 … … 114 114 time_before = time.time() 115 115 116 from differential_evolution import DifferentialEvolutionSolver2116 from mystic.differential_evolution import DifferentialEvolutionSolver2 117 117 from mystic.termination import VTR 118 118 from mystic.termination import ChangeOverGeneration as COG … … 135 135 print "Time elapsed=", time_elapsed 136 136 137 from constraint_tools import verify_constraints_satisfied137 from mystic.constraint_tools import verify_constraints_satisfied 138 138 print verify_constraints_satisfied(constraints_string, soln, disp=False) 139 139 … … 149 149 time_before = time.time() 150 150 151 from scipy_optimize import NelderMeadSimplexSolver151 from mystic.scipy_optimize import NelderMeadSimplexSolver 152 152 from mystic.termination import VTR 153 153 from mystic.termination import CandidateRelativeTolerance as CRT … … 169 169 print "Time elapsed=", time_elapsed 170 170 171 from constraint_tools import verify_constraints_satisfied171 from mystic.constraint_tools import verify_constraints_satisfied 172 172 print verify_constraints_satisfied(constraints_string, soln, disp=False) 173 173 … … 183 183 time_before = time.time() 184 184 185 from scipy_optimize import PowellDirectionalSolver185 from mystic.scipy_optimize import PowellDirectionalSolver 186 186 from mystic.termination import VTR 187 187 solver = PowellDirectionalSolver(ndim) … … 200 200 print "Time elapsed=", time_elapsed 201 201 202 from constraint_tools import verify_constraints_satisfied202 from mystic.constraint_tools import verify_constraints_satisfied 203 203 print verify_constraints_satisfied(constraints_string, soln, disp=False) 204 204 … … 213 213 time_before = time.time() 214 214 215 from scipy_bfgs import BFGSSolver215 from mystic.scipy_bfgs import BFGSSolver 216 216 from mystic.termination import VTR 217 217 solver = BFGSSolver(ndim) … … 230 230 print "Time elapsed=", time_elapsed 231 231 232 from constraint_tools import verify_constraints_satisfied232 from mystic.constraint_tools import verify_constraints_satisfied 233 233 print verify_constraints_satisfied(constraints_string, soln, disp=False) 234 234 … … 243 243 time_before = time.time() 244 244 245 from scipy_ncg import NCGSolver246 from mystic.termination import VTR 247 from termination import SolutionImprovement248 from termination import ChangeOverGeneration as COG245 from mystic.scipy_ncg import NCGSolver 246 from mystic.termination import VTR 247 from mystic.termination import SolutionImprovement 248 from mystic.termination import ChangeOverGeneration as COG 249 249 solver = NCGSolver(ndim) 250 250 … … 264 264 print "Time elapsed=", time_elapsed 265 265 266 from constraint_tools import verify_constraints_satisfied266 from mystic.constraint_tools import verify_constraints_satisfied 267 267 print verify_constraints_satisfied(constraints_string, soln, disp=False) 268 268 … … 277 277 time_before = time.time() 278 278 279 from scipy_cg import CGSolver279 from mystic.scipy_cg import CGSolver 280 280 from mystic.termination import VTR 281 281 solver = CGSolver(ndim) … … 294 294 print "Time elapsed=", time_elapsed 295 295 296 from constraint_tools import verify_constraints_satisfied296 from mystic.constraint_tools import verify_constraints_satisfied 297 297 print verify_constraints_satisfied(constraints_string, soln, disp=False) 298 298 … … 329 329 print "Time elapsed=", time_elapsed 330 330 331 from constraint_tools import verify_constraints_satisfied331 from mystic.constraint_tools import verify_constraints_satisfied 332 332 print verify_constraints_satisfied(constraints_string, soln, disp=False) 333 333 … … 361 361 print "Time elapsed=", time_elapsed 362 362 363 from constraint_tools import verify_constraints_satisfied363 from mystic.constraint_tools import verify_constraints_satisfied 364 364 print verify_constraints_satisfied(constraints_string, soln)#, disp=False) 365 365 … … 374 374 time_before = time.time() 375 375 376 from scipy_optimize import NelderMeadSimplexSolver377 from mystic.termination import VTR 378 from termination import CandidateRelativeTolerance as CRT379 from termination import ChangeOverGeneration as COG376 from mystic.scipy_optimize import NelderMeadSimplexSolver 377 from mystic.termination import VTR 378 from mystic.termination import CandidateRelativeTolerance as CRT 379 from mystic.termination import ChangeOverGeneration as COG 380 380 solver = NelderMeadSimplexSolver(ndim) 381 381 … … 394 394 print "Time elapsed=", time_elapsed 395 395 396 from constraint_tools import verify_constraints_satisfied396 from mystic.constraint_tools import verify_constraints_satisfied 397 397 print verify_constraints_satisfied(constraints_string, soln, disp=False) 398 398 … … 408 408 time_before = time.time() 409 409 410 from scipy_optimize import PowellDirectionalSolver410 from mystic.scipy_optimize import PowellDirectionalSolver 411 411 from mystic.termination import VTR 412 412 from mystic.termination import NormalizedChangeOverGeneration as NCOG … … 426 426 print "Time elapsed=", time_elapsed 427 427 428 from constraint_tools import verify_constraints_satisfied428 from mystic.constraint_tools import verify_constraints_satisfied 429 429 print verify_constraints_satisfied(constraints_string, soln, disp=False) 430 430 … … 439 439 time_before = time.time() 440 440 441 from scipy_bfgs import BFGSSolver441 from mystic.scipy_bfgs import BFGSSolver 442 442 from mystic.termination import VTR 443 443 solver = BFGSSolver(ndim) … … 456 456 print "Time elapsed=", time_elapsed 457 457 458 from constraint_tools import verify_constraints_satisfied458 from mystic.constraint_tools import verify_constraints_satisfied 459 459 print verify_constraints_satisfied(constraints_string, soln, disp=False) 460 460 … … 469 469 time_before = time.time() 470 470 471 from scipy_ncg import NCGSolver471 from mystic.scipy_ncg import NCGSolver 472 472 from mystic.termination import VTR 473 473 solver = NCGSolver(ndim) … … 485 485 print "Time elapsed=", time_elapsed 486 486 487 from constraint_tools import verify_constraints_satisfied487 from mystic.constraint_tools import verify_constraints_satisfied 488 488 print verify_constraints_satisfied(constraints_string, soln, disp=False) 489 489 … … 498 498 time_before = time.time() 499 499 500 from scipy_cg import CGSolver500 from mystic.scipy_cg import CGSolver 501 501 from mystic.termination import VTR 502 502 solver = CGSolver(ndim) … … 515 515 print "Time elapsed=", time_elapsed 516 516 517 from constraint_tools import verify_constraints_satisfied517 from mystic.constraint_tools import verify_constraints_satisfied 518 518 print verify_constraints_satisfied(constraints_string, soln, disp=False) 519 519 … … 530 530 time_before = time.time() 531 531 532 from differential_evolution import DifferentialEvolutionSolver532 from mystic.differential_evolution import DifferentialEvolutionSolver 533 533 from mystic.termination import VTR 534 534 solver = DifferentialEvolutionSolver(ndim, npop) … … 546 546 print "Time elapsed=", time_elapsed 547 547 548 from constraint_tools import verify_constraints_satisfied548 from mystic.constraint_tools import verify_constraints_satisfied 549 549 print verify_constraints_satisfied(constraints_string, soln, disp=False) 550 550 … … 560 560 time_before = time.time() 561 561 562 from differential_evolution import DifferentialEvolutionSolver2562 from mystic.differential_evolution import DifferentialEvolutionSolver2 563 563 from mystic.termination import VTR 564 564 solver = DifferentialEvolutionSolver2(ndim, npop) … … 576 576 print "Time elapsed=", time_elapsed 577 577 578 from constraint_tools import verify_constraints_satisfied578 from mystic.constraint_tools import verify_constraints_satisfied 579 579 print verify_constraints_satisfied(constraints_string, soln, disp=False) 580 580 … … 590 590 time_before = time.time() 591 591 592 from scipy_optimize import NelderMeadSimplexSolver592 from mystic.scipy_optimize import NelderMeadSimplexSolver 593 593 from mystic.termination import VTR 594 594 solver = NelderMeadSimplexSolver(ndim) … … 606 606 print "Time elapsed=", time_elapsed 607 607 608 from constraint_tools import verify_constraints_satisfied608 from mystic.constraint_tools import verify_constraints_satisfied 609 609 print verify_constraints_satisfied(constraints_string, soln, disp=False) 610 610 … … 620 620 time_before = time.time() 621 621 622 from scipy_optimize import PowellDirectionalSolver622 from mystic.scipy_optimize import PowellDirectionalSolver 623 623 from mystic.termination import VTR 624 624 from mystic.termination import NormalizedChangeOverGeneration as NCOG … … 639 639 print "Time elapsed=", time_elapsed 640 640 641 from constraint_tools import verify_constraints_satisfied641 from mystic.constraint_tools import verify_constraints_satisfied 642 642 print verify_constraints_satisfied(constraints_string, soln, disp=False) 643 643 … … 652 652 time_before = time.time() 653 653 654 from scipy_bfgs import BFGSSolver655 from mystic.termination import VTR 656 from termination import GradientTermination654 from mystic.scipy_bfgs import BFGSSolver 655 from mystic.termination import VTR 656 from mystic.termination import GradientTermination 657 657 solver = BFGSSolver(ndim) 658 658 … … 671 671 print "Time elapsed=", time_elapsed 672 672 673 from constraint_tools import verify_constraints_satisfied673 from mystic.constraint_tools import verify_constraints_satisfied 674 674 print verify_constraints_satisfied(constraints_string, soln, disp=False) 675 675 … … 701 701 print "Time elapsed=", time_elapsed 702 702 703 from constraint_tools import verify_constraints_satisfied703 from mystic.constraint_tools import verify_constraints_satisfied 704 704 print verify_constraints_satisfied(constraints_string, soln, disp=False) 705 705 … … 714 714 time_before = time.time() 715 715 716 from scipy_cg import CGSolver716 from mystic.scipy_cg import CGSolver 717 717 from mystic.termination import VTR 718 718 solver = CGSolver(ndim) … … 731 731 print "Time elapsed=", time_elapsed 732 732 733 from constraint_tools import verify_constraints_satisfied733 from mystic.constraint_tools import verify_constraints_satisfied 734 734 print verify_constraints_satisfied(constraints_string, soln, disp=False) 735 735 -
branches/alta/mystic-0.2a1/constrained_tests/test_constraints_rosen2d.py
r364 r376 148 148 149 149 import numpy 150 from constraint_tools import verify_constraints_satisfied150 from mystic.constraint_tools import verify_constraints_satisfied 151 151 import time 152 152 … … 188 188 time_before = time.time() 189 189 190 from differential_evolution import DifferentialEvolutionSolver190 from mystic.differential_evolution import DifferentialEvolutionSolver 191 191 from mystic.termination import VTR 192 192 solver = DifferentialEvolutionSolver(ndim, npop) … … 204 204 print "Time elapsed=", time_elapsed 205 205 206 from constraint_tools import verify_constraints_satisfied206 from mystic.constraint_tools import verify_constraints_satisfied 207 207 print verify_constraints_satisfied(constraints_string, soln, disp=False) 208 208 … … 218 218 time_before = time.time() 219 219 220 from differential_evolution import DifferentialEvolutionSolver2220 from mystic.differential_evolution import DifferentialEvolutionSolver2 221 221 from mystic.termination import VTR 222 222 solver = DifferentialEvolutionSolver2(ndim, npop) … … 234 234 print "Time elapsed=", time_elapsed 235 235 236 from constraint_tools import verify_constraints_satisfied236 from mystic.constraint_tools import verify_constraints_satisfied 237 237 print verify_constraints_satisfied(constraints_string, soln, disp=False) 238 238 … … 248 248 time_before = time.time() 249 249 250 from scipy_optimize import NelderMeadSimplexSolver250 from mystic.scipy_optimize import NelderMeadSimplexSolver 251 251 from mystic.termination import VTR 252 252 solver = NelderMeadSimplexSolver(ndim) … … 264 264 print "Time elapsed=", time_elapsed 265 265 266 from constraint_tools import verify_constraints_satisfied266 from mystic.constraint_tools import verify_constraints_satisfied 267 267 print verify_constraints_satisfied(constraints_string, soln, disp=False) 268 268 … … 278 278 time_before = time.time() 279 279 280 from scipy_optimize import PowellDirectionalSolver280 from mystic.scipy_optimize import PowellDirectionalSolver 281 281 from mystic.termination import VTR 282 282 solver = PowellDirectionalSolver(ndim) … … 295 295 print "Time elapsed=", time_elapsed 296 296 297 from constraint_tools import verify_constraints_satisfied297 from mystic.constraint_tools import verify_constraints_satisfied 298 298 print verify_constraints_satisfied(constraints_string, soln, disp=False) 299 299 … … 308 308 time_before = time.time() 309 309 310 from scipy_bfgs import BFGSSolver310 from mystic.scipy_bfgs import BFGSSolver 311 311 from mystic.termination import VTR 312 312 solver = BFGSSolver(ndim) … … 325 325 print "Time elapsed=", time_elapsed 326 326 327 from constraint_tools import verify_constraints_satisfied327 from mystic.constraint_tools import verify_constraints_satisfied 328 328 print verify_constraints_satisfied(constraints_string, soln, disp=False) 329 329 … … 338 338 time_before = time.time() 339 339 340 from scipy_ncg import NCGSolver341 from mystic.termination import VTR 342 from termination import SolutionImprovement343 from termination import ChangeOverGeneration as COG340 from mystic.scipy_ncg import NCGSolver 341 from mystic.termination import VTR 342 from mystic.termination import SolutionImprovement 343 from mystic.termination import ChangeOverGeneration as COG 344 344 solver = NCGSolver(ndim) 345 345 … … 359 359 print "Time elapsed=", time_elapsed 360 360 361 from constraint_tools import verify_constraints_satisfied361 from mystic.constraint_tools import verify_constraints_satisfied 362 362 print verify_constraints_satisfied(constraints_string, soln, disp=False) 363 363 … … 372 372 time_before = time.time() 373 373 374 from scipy_cg import CGSolver374 from mystic.scipy_cg import CGSolver 375 375 from mystic.termination import VTR 376 376 solver = CGSolver(ndim) … … 389 389 print "Time elapsed=", time_elapsed 390 390 391 from constraint_tools import verify_constraints_satisfied391 from mystic.constraint_tools import verify_constraints_satisfied 392 392 print verify_constraints_satisfied(constraints_string, soln, disp=False) 393 393 … … 404 404 time_before = time.time() 405 405 406 from differential_evolution import DifferentialEvolutionSolver406 from mystic.differential_evolution import DifferentialEvolutionSolver 407 407 from mystic.termination import VTR 408 408 solver = DifferentialEvolutionSolver(ndim, npop) … … 421 421 print "Time elapsed=", time_elapsed 422 422 423 from constraint_tools import verify_constraints_satisfied423 from mystic.constraint_tools import verify_constraints_satisfied 424 424 print verify_constraints_satisfied(constraints_string, soln, disp=False) 425 425 … … 434 434 time_before = time.time() 435 435 436 from differential_evolution import DifferentialEvolutionSolver2436 from mystic.differential_evolution import DifferentialEvolutionSolver2 437 437 from mystic.termination import VTR 438 438 solver = DifferentialEvolutionSolver2(ndim, npop) … … 451 451 print "Time elapsed=", time_elapsed 452 452 453 from constraint_tools import verify_constraints_satisfied453 from mystic.constraint_tools import verify_constraints_satisfied 454 454 print verify_constraints_satisfied(constraints_string, soln, disp=False) 455 455 … … 465 465 time_before = time.time() 466 466 467 from scipy_optimize import NelderMeadSimplexSolver467 from mystic.scipy_optimize import NelderMeadSimplexSolver 468 468 from mystic.termination import VTR 469 469 solver = NelderMeadSimplexSolver(ndim) … … 481 481 print "Time elapsed=", time_elapsed 482 482 483 from constraint_tools import verify_constraints_satisfied483 from mystic.constraint_tools import verify_constraints_satisfied 484 484 print verify_constraints_satisfied(constraints_string, soln, disp=False) 485 485 … … 495 495 time_before = time.time() 496 496 497 from scipy_optimize import PowellDirectionalSolver497 from mystic.scipy_optimize import PowellDirectionalSolver 498 498 from mystic.termination import VTR 499 499 solver = PowellDirectionalSolver(ndim) … … 511 511 print "Time elapsed=", time_elapsed 512 512 513 from constraint_tools import verify_constraints_satisfied513 from mystic.constraint_tools import verify_constraints_satisfied 514 514 print verify_constraints_satisfied(constraints_string, soln, disp=False) 515 515 … … 524 524 time_before = time.time() 525 525 526 from scipy_bfgs import BFGSSolver526 from mystic.scipy_bfgs import BFGSSolver 527 527 from mystic.termination import VTR 528 528 solver = BFGSSolver(ndim) … … 541 541 print "Time elapsed=", time_elapsed 542 542 543 from constraint_tools import verify_constraints_satisfied543 from mystic.constraint_tools import verify_constraints_satisfied 544 544 print verify_constraints_satisfied(constraints_string, soln, disp=False) 545 545 … … 554 554 time_before = time.time() 555 555 556 from scipy_ncg import NCGSolver556 from mystic.scipy_ncg import NCGSolver 557 557 from mystic.termination import VTR 558 558 solver = NCGSolver(ndim) … … 570 570 print "Time elapsed=", time_elapsed 571 571 572 from constraint_tools import verify_constraints_satisfied572 from mystic.constraint_tools import verify_constraints_satisfied 573 573 print verify_constraints_satisfied(constraints_string, soln, disp=False) 574 574 … … 583 583 time_before = time.time() 584 584 585 from scipy_cg import CGSolver585 from mystic.scipy_cg import CGSolver 586 586 from mystic.termination import VTR 587 587 solver = CGSolver(ndim) … … 600 600 print "Time elapsed=", time_elapsed 601 601 602 from constraint_tools import verify_constraints_satisfied602 from mystic.constraint_tools import verify_constraints_satisfied 603 603 print verify_constraints_satisfied(constraints_string, soln, disp=False) 604 604 … … 615 615 time_before = time.time() 616 616 617 from differential_evolution import DifferentialEvolutionSolver617 from mystic.differential_evolution import DifferentialEvolutionSolver 618 618 from mystic.termination import VTR 619 619 solver = DifferentialEvolutionSolver(ndim, npop) … … 631 631 print "Time elapsed=", time_elapsed 632 632 633 from constraint_tools import verify_constraints_satisfied633 from mystic.constraint_tools import verify_constraints_satisfied 634 634 print verify_constraints_satisfied(constraints_string, soln, disp=False) 635 635 … … 645 645 time_before = time.time() 646 646 647 from differential_evolution import DifferentialEvolutionSolver2647 from mystic.differential_evolution import DifferentialEvolutionSolver2 648 648 from mystic.termination import VTR 649 649 solver = DifferentialEvolutionSolver2(ndim, npop) … … 661 661 print "Time elapsed=", time_elapsed 662 662 663 from constraint_tools import verify_constraints_satisfied663 from mystic.constraint_tools import verify_constraints_satisfied 664 664 print verify_constraints_satisfied(constraints_string, soln, disp=False) 665 665 … … 675 675 time_before = time.time() 676 676 677 from scipy_optimize import NelderMeadSimplexSolver677 from mystic.scipy_optimize import NelderMeadSimplexSolver 678 678 from mystic.termination import VTR 679 679 solver = NelderMeadSimplexSolver(ndim) … … 691 691 print "Time elapsed=", time_elapsed 692 692 693 from constraint_tools import verify_constraints_satisfied693 from mystic.constraint_tools import verify_constraints_satisfied 694 694 print verify_constraints_satisfied(constraints_string, soln, disp=False) 695 695 … … 705 705 time_before = time.time() 706 706 707 from scipy_optimize import PowellDirectionalSolver707 from mystic.scipy_optimize import PowellDirectionalSolver 708 708 from mystic.termination import VTR 709 709 solver = PowellDirectionalSolver(ndim) … … 722 722 print "Time elapsed=", time_elapsed 723 723 724 from constraint_tools import verify_constraints_satisfied724 from mystic.constraint_tools import verify_constraints_satisfied 725 725 print verify_constraints_satisfied(constraints_string, soln, disp=False) 726 726 … … 735 735 time_before = time.time() 736 736 737 from scipy_bfgs import BFGSSolver737 from mystic.scipy_bfgs import BFGSSolver 738 738 from mystic.termination import VTR 739 739 solver = BFGSSolver(ndim) … … 752 752 print "Time elapsed=", time_elapsed 753 753 754 from constraint_tools import verify_constraints_satisfied754 from mystic.constraint_tools import verify_constraints_satisfied 755 755 print verify_constraints_satisfied(constraints_string, soln, disp=False) 756 756 … … 765 765 time_before = time.time() 766 766 767 from scipy_ncg import NCGSolver767 from mystic.scipy_ncg import NCGSolver 768 768 from mystic.termination import VTR 769 769 solver = NCGSolver(ndim) … … 782 782 print "Time elapsed=", time_elapsed 783 783 784 from constraint_tools import verify_constraints_satisfied784 from mystic.constraint_tools import verify_constraints_satisfied 785 785 print verify_constraints_satisfied(constraints_string, soln, disp=False) 786 786 … … 795 795 time_before = time.time() 796 796 797 from scipy_cg import CGSolver797 from mystic.scipy_cg import CGSolver 798 798 from mystic.termination import VTR 799 799 solver = CGSolver(ndim) … … 812 812 print "Time elapsed=", time_elapsed 813 813 814 from constraint_tools import verify_constraints_satisfied814 from mystic.constraint_tools import verify_constraints_satisfied 815 815 print verify_constraints_satisfied(constraints_string, soln, disp=False) 816 816 … … 833 833 test_powelldirectional_auglag() 834 834 test_bfgs_auglag() 835 test_ncg_auglag() # gets stuck without the hack in scipy_ncg. continues to835 test_ncg_auglag() # gets stuck without the hack in mystic.scipy_ncg. continues to 836 836 # get stuck with x0=[1., 1.] 837 837 test_cg_auglag() -
branches/alta/mystic-0.2a1/constrained_tests/test_constraints_rosen3d_1.py
r360 r376 8 8 Mystic Results: 9 9 --------------- 10 Below results are for x0=[3., -0.5, 1.] with the mystic.termination conditions 11 that are default for each solver. The differential evolution results are all 12 with Rand1Bin and npop=40, which seems to work better. 10 13 11 14 Differential Evolution, penalty 12 soln= [ 1.48865 497 2.21994399 4.92815133]13 f value = 1.728529 5637814 Time elapsed= 7.1284201145215 soln= [ 1.48865565 2.21994417 4.92815476] 16 f value = 1.72852922752 17 Time elapsed= 3.19864988327 15 18 True 16 19 17 20 Differential Evolution2, penalty 18 soln= [ 1.48865 497 2.21994399 4.92815133]19 f value = 1.72852 95639220 Time elapsed= 7.7426710128821 soln= [ 1.48865613 2.21994424 4.92815596] 22 f value = 1.72852883348 23 Time elapsed= 3.71830892563 21 24 True 22 25 23 26 NelderMead, penalty 24 soln= [ 8.69745142e-07 9.99270862e-01 1.15214768e+00]25 f value = 1 03.21368720526 Time elapsed= 0. 2742362022427 soln= [ 1.48865958 2.21994303 4.92818437] 28 f value = 1.72852057093 29 Time elapsed= 0.113229990005 27 30 True 28 31 29 32 PowellDirectional, penalty 30 33 soln= [ 1.48865497 2.21994399 4.92815133] 31 f value = 1.7285295638 432 Time elapsed= 0. 89001703262334 f value = 1.72852956385 35 Time elapsed= 0.502039909363 33 36 True 34 37 35 38 BFGS, penalty 36 soln= [ 47.34498284 63.44819316 48.57560494] 37 f value = 2056148203.48 38 Time elapsed= 0.138121128082 39 soln= [ 1.48865488 2.21994394 4.9281511 ] 40 f value = 1.72852952678 41 Time elapsed= 0.338249206543 42 True 43 44 NCG gets stuck 45 46 CG gets stuck 47 48 DifferentialEvolution, auglag 49 soln= [ 1.48869307 2.22006117 4.92867142] 50 f value = 1.72885561061 51 Time elapsed= 12.5052418709 52 True 53 54 DifferentialEvolution2, auglag 55 soln= [ 1.48796979 2.21789754 4.91907453] 56 f value = 1.7228661551 57 Time elapsed= 11.4325180054 39 58 False 40 59 41 NCG, penalty 42 soln= [ 3.74321743 5.32352946 49.17010029] 43 f value = 50964.0581912 44 Time elapsed= 0.61452794075 60 NelderMead, auglag 61 soln= [ 1.48869652 2.22006837 4.92870857] 62 f value = 1.72887418176 63 Time elapsed= 0.618191003799 64 True 65 66 PowellDirectional, auglag 67 soln= [ 1.48871851 2.2201335 4.92899276] 68 f value = 1.7290543256 69 Time elapsed= 5.98634505272 70 True 71 72 BFGS, auglag 73 soln= [ 1.48872051 2.22013952 4.92901947] 74 f value = 1.72907101056 75 Time elapsed= 1.1560549736 76 True 77 78 NCG, auglag 79 soln= [ 1.31011697 1.7192198 2.95581549] 80 f value = 0.614242112099 81 Time elapsed= 1.70558714867 45 82 False 46 83 47 CG gets stuck. 48 49 DifferentialEvolution, auglag 50 soln= [ 1.48869288 2.22005707 4.92865339] 51 f value = 1.72884267207 52 Time elapsed= 37.709154129 53 True 54 55 DifferentialEvolution2, auglag 56 soln= [ 1.48869288 2.22005707 4.92865338] 57 f value = 1.72884266439 58 Time elapsed= 36.4304840565 59 True 60 61 NelderMead, auglag 62 soln= [ 1.48869288 2.22005707 4.92865339] 63 f value = 1.72884266999 64 Time elapsed= 0.860516786575 65 True 66 67 PowellDirectional, auglag 68 soln= [ 1.48882563 2.22045297 4.9304114 ] 69 f value = 1.72993912916 70 Time elapsed= 6.52501392365 71 True 72 73 BFGS gets stuck. 74 75 NCG gets stuck. 76 77 CG gets stuck. 84 CG gets stuck 85 86 DifferentialEvolution, direct 87 soln= [ 1.48871731 2.22013004 4.92897792] 88 f value = 1.72904479216 89 Time elapsed= 3.22128295898 90 True 91 92 DifferentialEvolution2, direct 93 soln= [ 1.48871755 2.22013014 4.92897722] 94 f value = 1.72904479219 95 Time elapsed= 3.08842515945 96 True 97 98 NelderMead, direct 99 soln= [ 1.48873189 2.22013601 4.92899136] 100 f value = 1.72904494708 101 Time elapsed= 0.124616146088 102 True 103 104 PowellDirectional, direct 105 soln= [ 1.48871736 2.22013006 4.92897748] 106 f value = 1.72904479213 107 Time elapsed= 0.269498109818 108 True 109 110 BFGS, direct 111 soln= [ 1.48871735 2.22013005 4.92897744] 112 f value = 1.72904479213 113 Time elapsed= 0.069039106369 114 True 115 116 NCG, direct 117 ^C 118 soln= [ NaN NaN NaN] 119 f value = nan 120 Time elapsed= 15.6861510277 121 False 122 123 CG, direct 124 soln= [ 0.03920643 1.19800614 2.19841953] 125 f value = 202.363685381 126 Time elapsed= 0.0680270195007 127 True 78 128 """ 79 129 80 130 import numpy 81 from constraint_tools import verify_constraints_satisfied131 from mystic.constraint_tools import verify_constraints_satisfied 82 132 import time 83 133 84 134 # Random seed 85 135 from mystic.tools import random_seed 86 seed = 1 136 seed = 123 87 137 random_seed(seed) 88 138 … … 90 140 from mystic.models import rosen as costfunc 91 141 92 npop= 30142 npop=40 93 143 MAX_GENERATIONS = 99999 94 144 … … 97 147 """ 98 148 99 x0 = [0.8, 1.2, 0.7]100 #x0 = [1., 2., 5.] 101 #x0 = [3., -0.5, 1.]149 #x0 = [0.8, 1.2, 0.7] 150 #x0 = [1., 2., 5.] # close to solution 151 x0 = [3., -0.5, 1.] 102 152 103 153 ndim = 3 … … 117 167 time_before = time.time() 118 168 119 from differential_evolution import DifferentialEvolutionSolver169 from mystic.differential_evolution import DifferentialEvolutionSolver 120 170 from mystic.termination import VTR 121 171 from mystic.termination import CandidateRelativeTolerance as CRT 172 from mystic.termination import ChangeOverGeneration as COG 122 173 from mystic.strategy import Rand1Bin 123 174 solver = DifferentialEvolutionSolver(ndim, npop) … … 126 177 solver.enable_signal_handler() 127 178 #term = VTR() 128 term = CRT() 179 #term = CRT() 180 term = COG() 129 181 solver.Solve(costfunc, term, constraints=constraints_string, \ 130 182 constraints_method='penalty',strategy=Rand1Bin) … … 136 188 print "Time elapsed=", time_elapsed 137 189 138 from constraint_tools import verify_constraints_satisfied190 from mystic.constraint_tools import verify_constraints_satisfied 139 191 print verify_constraints_satisfied(constraints_string, soln, disp=False) 140 192 … … 150 202 time_before = time.time() 151 203 152 from differential_evolution import DifferentialEvolutionSolver2204 from mystic.differential_evolution import DifferentialEvolutionSolver2 153 205 from mystic.termination import VTR 154 206 from mystic.termination import CandidateRelativeTolerance as CRT 207 from mystic.termination import ChangeOverGeneration as COG 155 208 from mystic.strategy import Rand1Bin 156 209 solver = DifferentialEvolutionSolver2(ndim, npop) … … 159 212 solver.enable_signal_handler() 160 213 #term = VTR() 161 term = CRT() 214 #term = CRT() 215 term = COG() 162 216 solver.Solve(costfunc, term, constraints=constraints_string, \ 163 217 constraints_method='penalty', strategy=Rand1Bin) … … 169 223 print "Time elapsed=", time_elapsed 170 224 171 from constraint_tools import verify_constraints_satisfied225 from mystic.constraint_tools import verify_constraints_satisfied 172 226 print verify_constraints_satisfied(constraints_string, soln, disp=False) 173 227 … … 183 237 time_before = time.time() 184 238 185 from scipy_optimize import NelderMeadSimplexSolver239 from mystic.scipy_optimize import NelderMeadSimplexSolver 186 240 from mystic.termination import VTR 187 241 from mystic.termination import CandidateRelativeTolerance as CRT … … 203 257 print "Time elapsed=", time_elapsed 204 258 205 from constraint_tools import verify_constraints_satisfied259 from mystic.constraint_tools import verify_constraints_satisfied 206 260 print verify_constraints_satisfied(constraints_string, soln, disp=False) 207 261 … … 217 271 time_before = time.time() 218 272 219 from scipy_optimize import PowellDirectionalSolver 220 from mystic.termination import VTR 273 from mystic.scipy_optimize import PowellDirectionalSolver 274 from mystic.termination import VTR 275 from mystic.termination import NormalizedChangeOverGeneration as NCOG 221 276 solver = PowellDirectionalSolver(ndim) 222 277 solver.SetStrictRanges(lb, ub) 223 278 solver.SetInitialPoints(x0) 224 279 solver.enable_signal_handler() 225 term = VTR() 280 #term = VTR() 281 term = NCOG() 226 282 solver.Solve(costfunc, term, constraints=constraints_string, \ 227 283 constraints_method='penalty') … … 234 290 print "Time elapsed=", time_elapsed 235 291 236 from constraint_tools import verify_constraints_satisfied292 from mystic.constraint_tools import verify_constraints_satisfied 237 293 print verify_constraints_satisfied(constraints_string, soln, disp=False) 238 294 … … 247 303 time_before = time.time() 248 304 249 from scipy_bfgs import BFGSSolver 250 from mystic.termination import VTR 305 from mystic.scipy_bfgs import BFGSSolver 306 from mystic.termination import VTR 307 from mystic.termination import Gradientmystic.termination 251 308 solver = BFGSSolver(ndim) 252 309 solver.SetStrictRanges(lb, ub) 253 310 solver.SetInitialPoints(x0) 254 311 solver.enable_signal_handler() 255 term = VTR() 312 #term = VTR() 313 term = Gradientmystic.termination() 256 314 solver.Solve(costfunc, term, constraints=constraints_string, \ 257 315 constraints_method='penalty')#, penalty=1e3) … … 264 322 print "Time elapsed=", time_elapsed 265 323 266 from constraint_tools import verify_constraints_satisfied324 from mystic.constraint_tools import verify_constraints_satisfied 267 325 print verify_constraints_satisfied(constraints_string, soln, disp=False) 268 326 … … 277 335 time_before = time.time() 278 336 279 from scipy_ncg import NCGSolver280 from mystic.termination import VTR 281 from termination import SolutionImprovement337 from mystic.scipy_ncg import NCGSolver 338 from mystic.termination import VTR 339 from mystic.termination import SolutionImprovement 282 340 from mystic.termination import ChangeOverGeneration as COG 283 341 from mystic.termination import NormalizedChangeOverGeneration as NCOG … … 286 344 solver.SetInitialPoints(x0) 287 345 solver.enable_signal_handler() 288 term = VTR()289 #term = SolutionImprovement() # doesn't help346 #term = VTR() 347 term = SolutionImprovement() # doesn't help 290 348 #term = COG() # doesn't work either 291 349 #term = NCOG() # doesn't work either … … 300 358 print "Time elapsed=", time_elapsed 301 359 302 from constraint_tools import verify_constraints_satisfied360 from mystic.constraint_tools import verify_constraints_satisfied 303 361 print verify_constraints_satisfied(constraints_string, soln, disp=False) 304 362 … … 313 371 time_before = time.time() 314 372 315 from scipy_cg import CGSolver316 from mystic.termination import VTR 317 from termination import GradientTermination373 from mystic.scipy_cg import CGSolver 374 from mystic.termination import VTR 375 from mystic.termination import Gradientmystic.termination 318 376 solver = CGSolver(ndim) 319 377 solver.SetStrictRanges(lb, ub) 320 378 solver.SetInitialPoints(x0) 321 379 solver.enable_signal_handler() 322 term = VTR()323 #term = GradientTermination()380 #term = VTR() 381 term = Gradientmystic.termination() 324 382 solver.Solve(costfunc, term, constraints=constraints_string, \ 325 383 constraints_method='penalty')#, penalty=1e2) … … 332 390 print "Time elapsed=", time_elapsed 333 391 334 from constraint_tools import verify_constraints_satisfied392 from mystic.constraint_tools import verify_constraints_satisfied 335 393 print verify_constraints_satisfied(constraints_string, soln, disp=False) 336 394 … … 347 405 time_before = time.time() 348 406 349 from differential_evolution import DifferentialEvolutionSolver 350 from mystic.termination import VTR 407 from mystic.differential_evolution import DifferentialEvolutionSolver 408 from mystic.termination import VTR 409 from mystic.termination import ChangeOverGeneration as COG 410 from mystic.strategy import Rand1Bin 351 411 solver = DifferentialEvolutionSolver(ndim, npop) 352 412 solver.SetStrictRanges(lb, ub) 353 413 solver.SetInitialPoints(x0) 354 414 solver.enable_signal_handler() 355 term = VTR() 356 solver.Solve(costfunc, term, constraints=constraints_string, \ 357 constraints_method='auglag') 358 soln = solver.Solution() 359 360 time_elapsed = time.time() - time_before 361 362 print "soln=", soln 363 print "f value =", costfunc(soln) 364 print "Time elapsed=", time_elapsed 365 366 from constraint_tools import verify_constraints_satisfied 415 #term = VTR() 416 term = COG() 417 solver.Solve(costfunc, term, constraints=constraints_string, \ 418 constraints_method='auglag', strategy=Rand1Bin) 419 soln = solver.Solution() 420 421 time_elapsed = time.time() - time_before 422 423 print "soln=", soln 424 print "f value =", costfunc(soln) 425 print "Time elapsed=", time_elapsed 426 427 from mystic.constraint_tools import verify_constraints_satisfied 367 428 print verify_constraints_satisfied(constraints_string, soln, disp=False) 368 429 … … 377 438 time_before = time.time() 378 439 379 from differential_evolution import DifferentialEvolutionSolver2440 from mystic.differential_evolution import DifferentialEvolutionSolver2 380 441 from mystic.termination import VTR 381 442 from mystic.termination import CandidateRelativeTolerance as CRT 443 from mystic.termination import ChangeOverGeneration as COG 382 444 from mystic.strategy import Rand1Bin 383 445 solver = DifferentialEvolutionSolver2(ndim, npop) … … 385 447 solver.SetInitialPoints(x0) 386 448 solver.enable_signal_handler() 387 term = VTR()449 #term = VTR() 388 450 #term = CRT() 389 solver.Solve(costfunc, term, constraints=constraints_string, \ 390 constraints_method='auglag')#, strategy=Rand1Bin) 391 soln = solver.Solution() 392 393 time_elapsed = time.time() - time_before 394 395 print "soln=", soln 396 print "f value =", costfunc(soln) 397 print "Time elapsed=", time_elapsed 398 399 from constraint_tools import verify_constraints_satisfied 451 term = COG() 452 solver.Solve(costfunc, term, constraints=constraints_string, \ 453 constraints_method='auglag', strategy=Rand1Bin) 454 soln = solver.Solution() 455 456 time_elapsed = time.time() - time_before 457 458 print "soln=", soln 459 print "f value =", costfunc(soln) 460 print "Time elapsed=", time_elapsed 461 462 from mystic.constraint_tools import verify_constraints_satisfied 400 463 print verify_constraints_satisfied(constraints_string, soln, disp=False) 401 464 … … 411 474 time_before = time.time() 412 475 413 from scipy_optimize import NelderMeadSimplexSolver476 from mystic.scipy_optimize import NelderMeadSimplexSolver 414 477 from mystic.termination import VTR 415 478 from mystic.termination import ChangeOverGeneration as COG 416 479 from mystic.termination import NormalizedChangeOverGeneration as NCOG 480 from mystic.termination import CandidateRelativeTolerance as CRT 417 481 solver = NelderMeadSimplexSolver(ndim) 418 482 solver.SetStrictRanges(lb, ub) 419 483 solver.SetInitialPoints(x0) 420 484 solver.enable_signal_handler() 421 term = VTR()485 #term = VTR() 422 486 #term = COG() 423 487 #term = NCOG() # Works poorly 488 term = CRT() 424 489 solver.Solve(costfunc, term, constraints=constraints_string, \ 425 490 constraints_method='auglag') # Results improve with larger rh,rg … … 431 496 print "Time elapsed=", time_elapsed 432 497 433 from constraint_tools import verify_constraints_satisfied498 from mystic.constraint_tools import verify_constraints_satisfied 434 499 print verify_constraints_satisfied(constraints_string, soln, disp=False) 435 500 … … 445 510 time_before = time.time() 446 511 447 from scipy_optimize import PowellDirectionalSolver 448 from mystic.termination import VTR 512 from mystic.scipy_optimize import PowellDirectionalSolver 513 from mystic.termination import VTR 514 from mystic.termination import NormalizedChangeOverGeneration as NCOG 449 515 solver = PowellDirectionalSolver(ndim) 450 516 solver.SetStrictRanges(lb, ub) 451 517 solver.SetInitialPoints(x0) 452 518 solver.enable_signal_handler() 453 term = VTR() 519 #term = VTR() 520 term = NCOG() 454 521 solver.Solve(costfunc, term, constraints=constraints_string, \ 455 522 constraints_method='auglag') … … 461 528 print "Time elapsed=", time_elapsed 462 529 463 from constraint_tools import verify_constraints_satisfied530 from mystic.constraint_tools import verify_constraints_satisfied 464 531 print verify_constraints_satisfied(constraints_string, soln, disp=False) 465 532 … … 474 541 time_before = time.time() 475 542 476 from scipy_bfgs import BFGSSolver477 from mystic.termination import VTR 478 from termination import GradientTermination543 from mystic.scipy_bfgs import BFGSSolver 544 from mystic.termination import VTR 545 from mystic.termination import Gradientmystic.termination 479 546 solver = BFGSSolver(ndim) 480 547 solver.SetStrictRanges(lb, ub) 481 548 solver.SetInitialPoints(x0) 482 549 solver.enable_signal_handler() 483 term = VTR()484 #term = GradientTermination() # doesn't seem to help550 #term = VTR() 551 term = Gradientmystic.termination() # doesn't seem to help 485 552 solver.Solve(costfunc, term, constraints=constraints_string, \ 486 553 constraints_method='auglag') … … 493 560 print "Time elapsed=", time_elapsed 494 561 495 from constraint_tools import verify_constraints_satisfied562 from mystic.constraint_tools import verify_constraints_satisfied 496 563 print verify_constraints_satisfied(constraints_string, soln, disp=False) 497 564 … … 506 573 time_before = time.time() 507 574 508 from scipy_ncg import NCGSolver 509 from mystic.termination import VTR 575 from mystic.scipy_ncg import NCGSolver 576 from mystic.termination import VTR 577 from mystic.termination import SolutionImprovement 510 578 solver = NCGSolver(ndim) 511 579 solver.SetStrictRanges(lb, ub) 512 580 solver.SetInitialPoints(x0) 513 581 solver.enable_signal_handler() 514 term = VTR() 582 #term = VTR() 583 term = SolutionImprovement() 515 584 solver.Solve(costfunc, term, constraints=constraints_string, \ 516 585 constraints_method='auglag') … … 522 591 print "Time elapsed=", time_elapsed 523 592 524 from constraint_tools import verify_constraints_satisfied593 from mystic.constraint_tools import verify_constraints_satisfied 525 594 print verify_constraints_satisfied(constraints_string, soln, disp=False) 526 595 … … 535 604 time_before = time.time() 536 605 537 from scipy_cg import CGSolver 538 from mystic.termination import VTR 606 from mystic.scipy_cg import CGSolver 607 from mystic.termination import VTR 608 from mystic.termination import Gradientmystic.termination 539 609 solver = CGSolver(ndim) 540 610 solver.SetStrictRanges(lb, ub) 541 611 solver.SetInitialPoints(x0) 542 612 solver.enable_signal_handler() 543 term = VTR() 613 #term = VTR() 614 term = Gradientmystic.termination() 544 615 solver.Solve(costfunc, term, constraints=constraints_string, \ 545 616 constraints_method='auglag') … … 552 623 print "Time elapsed=", time_elapsed 553 624 554 from constraint_tools import verify_constraints_satisfied625 from mystic.constraint_tools import verify_constraints_satisfied 555 626 print verify_constraints_satisfied(constraints_string, soln, disp=False) 556 627 … … 568 639 time_before = time.time() 569 640 570 from differential_evolution import DifferentialEvolutionSolver 571 from mystic.termination import VTR 641 from mystic.differential_evolution import DifferentialEvolutionSolver 642 from mystic.termination import VTR 643 from mystic.termination import ChangeOverGeneration as COG 644 from mystic.strategy import Rand1Bin 572 645 solver = DifferentialEvolutionSolver(ndim, npop) 573 646 solver.SetStrictRanges(lb, ub) 574 647 solver.SetInitialPoints(x0) 575 648 solver.enable_signal_handler() 576 term = VTR() 577 solver.Solve(costfunc, term, constraints=constraints_string, \ 578 constraints_method='direct', suggestedorder=(2, 1, 3)) 579 soln = solver.Solution() 580 581 time_elapsed = time.time() - time_before 582 583 print "soln=", soln 584 print "f value =", costfunc(soln) 585 print "Time elapsed=", time_elapsed 586 587 from constraint_tools import verify_constraints_satisfied 649 #term = VTR() 650 term = COG() 651 solver.Solve(costfunc, term, constraints=constraints_string, \ 652 constraints_method='direct', suggestedorder=(2, 1, 3),\ 653 strategy=Rand1Bin) 654 soln = solver.Solution() 655 656 time_elapsed = time.time() - time_before 657 658 print "soln=", soln 659 print "f value =", costfunc(soln) 660 print "Time elapsed=", time_elapsed 661 662 from mystic.constraint_tools import verify_constraints_satisfied 588 663 print verify_constraints_satisfied(constraints_string, soln, disp=False) 589 664 … … 598 673 time_before = time.time() 599 674 600 from differential_evolution import DifferentialEvolutionSolver2 601 from mystic.termination import VTR 675 from mystic.differential_evolution import DifferentialEvolutionSolver2 676 from mystic.termination import VTR 677 from mystic.termination import ChangeOverGeneration as COG 678 from mystic.strategy import Rand1Bin 679 #npop = 50 602 680 solver = DifferentialEvolutionSolver2(ndim, npop) 603 681 solver.SetStrictRanges(lb, ub) 604 682 solver.SetInitialPoints(x0) 605 683 solver.enable_signal_handler() 606 term = VTR() 607 solver.Solve(costfunc, term, constraints=constraints_string, \ 608 constraints_method='direct', suggestedorder=(2, 1, 3)) 609 soln = solver.Solution() 610 611 time_elapsed = time.time() - time_before 612 613 print "soln=", soln 614 print "f value =", costfunc(soln) 615 print "Time elapsed=", time_elapsed 616 617 from constraint_tools import verify_constraints_satisfied 684 #term = VTR() 685 term = COG() 686 solver.Solve(costfunc, term, constraints=constraints_string, \ 687 constraints_method='direct', suggestedorder=(2, 1, 3),\ 688 strategy=Rand1Bin) 689 soln = solver.Solution() 690 691 time_elapsed = time.time() - time_before 692 693 print "soln=", soln 694 print "f value =", costfunc(soln) 695 print "Time elapsed=", time_elapsed 696 697 from mystic.constraint_tools import verify_constraints_satisfied 618 698 print verify_constraints_satisfied(constraints_string, soln, disp=False) 619 699 … … 629 709 time_before = time.time() 630 710 631 from scipy_optimize import NelderMeadSimplexSolver711 from mystic.scipy_optimize import NelderMeadSimplexSolver 632 712 from mystic.termination import VTR 633 713 from mystic.termination import ChangeOverGeneration as COG 634 714 from mystic.termination import NormalizedChangeOverGeneration as NCOG 715 from mystic.termination import CandidateRelativeTolerance as CRT 635 716 solver = NelderMeadSimplexSolver(ndim) 636 717 solver.SetStrictRanges(lb, ub) 637 718 solver.SetInitialPoints(x0) 638 719 solver.enable_signal_handler() 639 term = VTR()720 #term = VTR() 640 721 #term = COG() 641 #term = NCOG() 722 #term = NCOG() 723 term = CRT() 642 724 solver.Solve(costfunc, term, constraints=constraints_string, \ 643 725 constraints_method='direct', suggestedorder=(2, 1, 3)) … … 649 731 print "Time elapsed=", time_elapsed 650 732 651 from constraint_tools import verify_constraints_satisfied733 from mystic.constraint_tools import verify_constraints_satisfied 652 734 print verify_constraints_satisfied(constraints_string, soln, disp=False) 653 735 … … 663 745 time_before = time.time() 664 746 665 from scipy_optimize import PowellDirectionalSolver 666 from mystic.termination import VTR 747 from mystic.scipy_optimize import PowellDirectionalSolver 748 from mystic.termination import VTR 749 from mystic.termination import NormalizedChangeOverGeneration as NCOG 667 750 solver = PowellDirectionalSolver(ndim) 668 751 solver.SetStrictRanges(lb, ub) 669 752 solver.SetInitialPoints(x0) 670 753 solver.enable_signal_handler() 671 term = VTR() 754 #term = VTR() 755 term = NCOG() 672 756 solver.Solve(costfunc, term, constraints=constraints_string, \ 673 757 constraints_method='direct', suggestedorder=(2, 1, 3)) … … 679 763 print "Time elapsed=", time_elapsed 680 764 681 from constraint_tools import verify_constraints_satisfied765 from mystic.constraint_tools import verify_constraints_satisfied 682 766 print verify_constraints_satisfied(constraints_string, soln, disp=False) 683 767 … … 692 776 time_before = time.time() 693 777 694 from scipy_bfgs import BFGSSolver695 from mystic.termination import VTR 696 from termination import GradientTermination778 from mystic.scipy_bfgs import BFGSSolver 779 from mystic.termination import VTR 780 from mystic.termination import Gradientmystic.termination 697 781 solver = BFGSSolver(ndim) 698 782 solver.SetStrictRanges(lb, ub) 699 783 solver.SetInitialPoints(x0) 700 784 solver.enable_signal_handler() 701 term = VTR()702 #term = GradientTermination()785 #term = VTR() 786 term = Gradientmystic.termination() 703 787 solver.Solve(costfunc, term, constraints=constraints_string, \ 704 788 constraints_method='direct', suggestedorder=(2, 1, 3)) … … 711 795 print "Time elapsed=", time_elapsed 712 796 713 from constraint_tools import verify_constraints_satisfied797 from mystic.constraint_tools import verify_constraints_satisfied 714 798 print verify_constraints_satisfied(constraints_string, soln, disp=False) 715 799 … … 724 808 time_before = time.time() 725 809 726 from scipy_ncg import NCGSolver 727 from mystic.termination import VTR 810 from mystic.scipy_ncg import NCGSolver 811 from mystic.termination import VTR 812 from mystic.termination import SolutionImprovement 728 813 solver = NCGSolver(ndim) 729 814 solver.SetStrictRanges(lb, ub) 730 815 solver.SetInitialPoints(x0) 731 816 solver.enable_signal_handler() 732 term = VTR() 817 #term = VTR() 818 term = SolutionImprovement() 733 819 solver.Solve(costfunc, term, constraints=constraints_string, \ 734 820 constraints_method='direct', suggestedorder=(2, 1, 3)) … … 740 826 print "Time elapsed=", time_elapsed 741 827 742 from constraint_tools import verify_constraints_satisfied828 from mystic.constraint_tools import verify_constraints_satisfied 743 829 print verify_constraints_satisfied(constraints_string, soln, disp=False) 744 830 … … 753 839 time_before = time.time() 754 840 755 from scipy_cg import CGSolver 756 from mystic.termination import VTR 841 from mystic.scipy_cg import CGSolver 842 from mystic.termination import VTR 843 from mystic.termination import Gradientmystic.termination 757 844 solver = CGSolver(ndim) 758 845 solver.SetStrictRanges(lb, ub) 759 846 solver.SetInitialPoints(x0) 760 847 solver.enable_signal_handler() 761 term = VTR() 848 #term = VTR() 849 term = Gradientmystic.termination() 762 850 solver.Solve(costfunc, term, constraints=constraints_string, \ 763 851 constraints_method='direct', suggestedorder=(2, 1, 3)) … … 770 858 print "Time elapsed=", time_elapsed 771 859 772 from constraint_tools import verify_constraints_satisfied860 from mystic.constraint_tools import verify_constraints_satisfied 773 861 print verify_constraints_satisfied(constraints_string, soln, disp=False) 774 862 … … 776 864 777 865 if __name__ == '__main__': 778 # below results are with randominitialpoints. all solvers work well with 779 # penalty method if x0=[1., 2., 5.] (i.e. close to solution) 780 test_diffev_penalty() # bad with x0=[0.8, 1.2, 0.7], fixed with Rand1Bin 781 test_diffev2_penalty() # bad with x0=[0.8, 1.2, 0.7], fixed with Rand1Bin 866 test_diffev_penalty() # needs Rand1Bin 867 test_diffev2_penalty() # needs Rand1Bin 782 868 test_neldermead_penalty() 783 869 test_powelldirectional_penalty() 784 test_bfgs_penalty() # s ometimes works if penalty=1e3, but depends on x0785 test_ncg_penalty() # bad answer870 test_bfgs_penalty() # stuck with x0=[0.8, 1.2, 0.7], ok with [3., -0.5, 1] 871 test_ncg_penalty() # gets stuck, NaN 786 872 test_cg_penalty() # gets stuck 787 873 788 test_diffev_auglag() 874 test_diffev_auglag() # bad with x0=[3., -0.5, 1.], fixed with Rand1Bin 789 875 test_diffev2_auglag() # bad with x0=[3., -0.5, 1.], fixed with Rand1Bin 790 876 test_neldermead_auglag() 791 877 test_powelldirectional_auglag() 792 test_bfgs_auglag() # gets stuck or gives bad answer878 test_bfgs_auglag() # stuck with x0=[0.8, 1.2, 0.7], ok with [3., -0.5, 1.] 793 879 test_ncg_auglag() # bad answer. sometimes gets stuck. 794 880 test_cg_auglag() # gets stuck 795 881 796 test_diffev_direct() # bad 797 test_diffev2_direct() # bad 882 test_diffev_direct() # needs Rand1Bin 883 test_diffev2_direct() # needs Rand1Bin; with x0=[0.8, 1.2, 0.7], also needs 884 # larger npop (> 50) 798 885 test_neldermead_direct() 799 886 test_powelldirectional_direct() 800 test_bfgs_direct() # bad887 test_bfgs_direct() # stuck with x0=[0.8, 1.2, 0.7], ok with [3., -0.5, 1.] 801 888 test_ncg_direct() # NaN 802 889 test_cg_direct() # bad -
branches/alta/mystic-0.2a1/constrained_tests/test_constraints_tp24.py
r373 r376 15 15 16 16 import numpy 17 from constraint_tools import verify_constraints_satisfied17 from mystic.constraint_tools import verify_constraints_satisfied 18 18 import time 19 19 … … 54 54 time_before = time.time() 55 55 56 from differential_evolution import DifferentialEvolutionSolver56 from mystic.differential_evolution import DifferentialEvolutionSolver 57 57 from mystic.termination import CandidateRelativeTolerance as CRT 58 58 from mystic.termination import ChangeOverGeneration as COG … … 72 72 print "Time elapsed=", time_elapsed 73 73 74 from constraint_tools import verify_constraints_satisfied74 from mystic.constraint_tools import verify_constraints_satisfied 75 75 print verify_constraints_satisfied(constraints_string, soln, disp=False) 76 76 … … 86 86 time_before = time.time() 87 87 88 from differential_evolution import DifferentialEvolutionSolver288 from mystic.differential_evolution import DifferentialEvolutionSolver2 89 89 from mystic.termination import ChangeOverGeneration as COG 90 90 from mystic.termination import CandidateRelativeTolerance as CRT … … 104 104 print "Time elapsed=", time_elapsed 105 105 106 from constraint_tools import verify_constraints_satisfied106 from mystic.constraint_tools import verify_constraints_satisfied 107 107 print verify_constraints_satisfied(constraints_string, soln, disp=False) 108 108 … … 118 118 time_before = time.time() 119 119 120 from scipy_optimize import NelderMeadSimplexSolver120 from mystic.scipy_optimize import NelderMeadSimplexSolver 121 121 from mystic.termination import ChangeOverGeneration as COG 122 122 from mystic.termination import CandidateRelativeTolerance as CRT … … 136 136 print "Time elapsed=", time_elapsed 137 137 138 from constraint_tools import verify_constraints_satisfied138 from mystic.constraint_tools import verify_constraints_satisfied 139 139 print verify_constraints_satisfied(constraints_string, soln, disp=False) 140 140 … … 150 150 time_before = time.time() 151 151 152 from scipy_optimize import PowellDirectionalSolver152 from mystic.scipy_optimize import PowellDirectionalSolver 153 153 #from mystic.termination import VTR 154 154 from mystic.termination import ChangeOverGeneration as COG … … 169 169 print "Time elapsed=", time_elapsed 170 170 171 from constraint_tools import verify_constraints_satisfied171 from mystic.constraint_tools import verify_constraints_satisfied 172 172 print verify_constraints_satisfied(constraints_string, soln, disp=False) 173 173 … … 182 182 time_before = time.time() 183 183 184 from scipy_bfgs import BFGSSolver185 from mystic.termination import Gradient Termination184 from mystic.scipy_bfgs import BFGSSolver 185 from mystic.termination import Gradientmystic.termination 186 186 from mystic.termination import ChangeOverGeneration as COG 187 187 solver = BFGSSolver(ndim) … … 189 189 solver.SetInitialPoints(x0) 190 190 solver.enable_signal_handler() 191 #term = Gradient Termination() # does work well191 #term = Gradientmystic.termination() # does work well 192 192 term = COG() # works well 193 193 solver.Solve(costfunc, term, constraints=constraints_string, \ … … 201 201 print "Time elapsed=", time_elapsed 202 202 203 from constraint_tools import verify_constraints_satisfied203 from mystic.constraint_tools import verify_constraints_satisfied 204 204 print verify_constraints_satisfied(constraints_string, soln, disp=False) 205 205 … … 214 214 time_before = time.time() 215 215 216 from scipy_ncg import NCGSolver217 from termination import SolutionImprovement218 from termination import ChangeOverGeneration as COG219 from termination import NormalizedChangeOverGeneration as NCOG216 from mystic.scipy_ncg import NCGSolver 217 from mystic.termination import SolutionImprovement 218 from mystic.termination import ChangeOverGeneration as COG 219 from mystic.termination import NormalizedChangeOverGeneration as NCOG 220 220 solver = NCGSolver(ndim) 221 221 … … 235 235 print "Time elapsed=", time_elapsed 236 236 237 from constraint_tools import verify_constraints_satisfied237 from mystic.constraint_tools import verify_constraints_satisfied 238 238 print verify_constraints_satisfied(constraints_string, soln, disp=False) 239 239 … … 248 248 time_before = time.time() 249 249 250 from scipy_cg import CGSolver251 from termination import ChangeOverGeneration as COG252 from termination import NormalizedChangeOverGeneration as NCOG253 from mystic.termination import Gradient Termination250 from mystic.scipy_cg import CGSolver 251 from mystic.termination import ChangeOverGeneration as COG 252 from mystic.termination import NormalizedChangeOverGeneration as NCOG 253 from mystic.termination import Gradientmystic.termination 254 254 solver = CGSolver(ndim) 255 255 … … 267 267 print "Time elapsed=", time_elapsed 268 268 269 from constraint_tools import verify_constraints_satisfied269 from mystic.constraint_tools import verify_constraints_satisfied 270 270 print verify_constraints_satisfied(constraints_string, soln, disp=False) 271 271 … … 282 282 time_before = time.time() 283 283 284 from differential_evolution import DifferentialEvolutionSolver284 from mystic.differential_evolution import DifferentialEvolutionSolver 285 285 from mystic.termination import VTR 286 286 from mystic.termination import CandidateRelativeTolerance as CRT … … 301 301 print "Time elapsed=", time_elapsed 302 302 303 from constraint_tools import verify_constraints_satisfied303 from mystic.constraint_tools import verify_constraints_satisfied 304 304 print verify_constraints_satisfied(constraints_string, soln, disp=False) 305 305 … … 314 314 time_before = time.time() 315 315 316 from differential_evolution import DifferentialEvolutionSolver2316 from mystic.differential_evolution import DifferentialEvolutionSolver2 317 317 from mystic.termination import CandidateRelativeTolerance as CRT 318 318 from mystic.termination import ChangeOverGeneration as COG … … 333 333 print "Time elapsed=", time_elapsed 334 334 335 from constraint_tools import verify_constraints_satisfied335 from mystic.constraint_tools import verify_constraints_satisfied 336 336 print verify_constraints_satisfied(constraints_string, soln, disp=False) 337 337 … … 347 347 time_before = time.time() 348 348 349 from scipy_optimize import NelderMeadSimplexSolver349 from mystic.scipy_optimize import NelderMeadSimplexSolver 350 350 from mystic.termination import ChangeOverGeneration as COG 351 351 from mystic.termination import CandidateRelativeTolerance as CRT … … 365 365 print "Time elapsed=", time_elapsed 366 366 367 from constraint_tools import verify_constraints_satisfied367 from mystic.constraint_tools import verify_constraints_satisfied 368 368 print verify_constraints_satisfied(constraints_string, soln, disp=False) 369 369 … … 379 379 time_before = time.time() 380 380 381 from scipy_optimize import PowellDirectionalSolver381 from mystic.scipy_optimize import PowellDirectionalSolver 382 382 from mystic.termination import VTR 383 383 from mystic.termination import ChangeOverGeneration as COG … … 397 397 print "Time elapsed=", time_elapsed 398 398 399 from constraint_tools import verify_constraints_satisfied399 from mystic.constraint_tools import verify_constraints_satisfied 400 400 print verify_constraints_satisfied(constraints_string, soln, disp=False) 401 401 … … 410 410 time_before = time.time() 411 411 412 from scipy_bfgs import BFGSSolver413 from termination import GradientTermination412 from mystic.scipy_bfgs import BFGSSolver 413 from mystic.termination import Gradientmystic.termination 414 414 from mystic.termination import ChangeOverGeneration as COG 415 415 solver = BFGSSolver(ndim) … … 417 417 solver.SetInitialPoints(x0) 418 418 solver.enable_signal_handler() 419 #term = Gradient Termination() # works well419 #term = Gradientmystic.termination() # works well 420 420 term = COG() # works well 421 421 solver.Solve(costfunc, term, constraints=constraints_string, \ … … 429 429 print "Time elapsed=", time_elapsed 430 430 431 from constraint_tools import verify_constraints_satisfied431 from mystic.constraint_tools import verify_constraints_satisfied 432 432 print verify_constraints_satisfied(constraints_string, soln, disp=False) 433 433 … … 442 442 time_before = time.time() 443 443 444 from scipy_ncg import NCGSolver445 from termination import SolutionImprovement444 from mystic.scipy_ncg import NCGSolver 445 from mystic.termination import SolutionImprovement 446 446 from mystic.termination import ChangeOverGeneration as COG 447 447 solver = NCGSolver(ndim) … … 460 460 print "Time elapsed=", time_elapsed 461 461 462 from constraint_tools import verify_constraints_satisfied462 from mystic.constraint_tools import verify_constraints_satisfied 463 463 print verify_constraints_satisfied(constraints_string, soln, disp=False) 464 464 … … 473 473 time_before = time.time() 474 474 475 from scipy_cg import CGSolver476 from termination import ChangeOverGeneration as COG475 from mystic.scipy_cg import CGSolver 476 from mystic.termination import ChangeOverGeneration as COG 477 477 solver = CGSolver(ndim) 478 478 … … 490 490 print "Time elapsed=", time_elapsed 491 491 492 from constraint_tools import verify_constraints_satisfied492 from mystic.constraint_tools import verify_constraints_satisfied 493 493 print verify_constraints_satisfied(constraints_string, soln, disp=False) 494 494 … … 505 505 time_before = time.time() 506 506 507 from differential_evolution import DifferentialEvolutionSolver507 from mystic.differential_evolution import DifferentialEvolutionSolver 508 508 from mystic.termination import ChangeOverGeneration as COG 509 509 from mystic.termination import NormalizedChangeOverGeneration as NCOG … … 525 525 print "Time elapsed=", time_elapsed 526 526 527 from constraint_tools import verify_constraints_satisfied527 from mystic.constraint_tools import verify_constraints_satisfied 528 528 print verify_constraints_satisfied(constraints_string, soln, disp=False) 529 529 … … 539 539 time_before = time.time() 540 540 541 from differential_evolution import DifferentialEvolutionSolver2541 from mystic.differential_evolution import DifferentialEvolutionSolver2 542 542 from mystic.termination import CandidateRelativeTolerance as CRT 543 543 from mystic.termination import ChangeOverGeneration as COG … … 557 557 print "Time elapsed=", time_elapsed 558 558 559 from constraint_tools import verify_constraints_satisfied559 from mystic.constraint_tools import verify_constraints_satisfied 560 560 print verify_constraints_satisfied(constraints_string, soln, disp=False) 561 561 … … 571 571 time_before = time.time() 572 572 573 from scipy_optimize import NelderMeadSimplexSolver573 from mystic.scipy_optimize import NelderMeadSimplexSolver 574 574 from mystic.termination import ChangeOverGeneration as COG 575 575 from mystic.termination import NormalizedChangeOverGeneration as NCOG … … 591 591 print "Time elapsed=", time_elapsed 592 592 593 from constraint_tools import verify_constraints_satisfied593 from mystic.constraint_tools import verify_constraints_satisfied 594 594 print verify_constraints_satisfied(constraints_string, soln, disp=False) 595 595 … … 605 605 time_before = time.time() 606 606 607 from scipy_optimize import PowellDirectionalSolver607 from mystic.scipy_optimize import PowellDirectionalSolver 608 608 from mystic.termination import VTR 609 609 from mystic.termination import ChangeOverGeneration as COG … … 624 624 print "Time elapsed=", time_elapsed 625 625 626 from constraint_tools import verify_constraints_satisfied626 from mystic.constraint_tools import verify_constraints_satisfied 627 627 print verify_constraints_satisfied(constraints_string, soln, disp=False) 628 628 … … 637 637 time_before = time.time() 638 638 639 from scipy_bfgs import BFGSSolver640 from termination import GradientTermination639 from mystic.scipy_bfgs import BFGSSolver 640 from mystic.termination import Gradientmystic.termination 641 641 from mystic.termination import ChangeOverGeneration as COG 642 642 solver = BFGSSolver(ndim) … … 644 644 solver.SetInitialPoints(x0) 645 645 solver.enable_signal_handler() 646 term = Gradient Termination() # also doesn't work646 term = Gradientmystic.termination() # also doesn't work 647 647 #term = COG() # doesn't work well either 648 648 solver.Solve(costfunc, term, constraints=constraints_string, \ … … 656 656 print "Time elapsed=", time_elapsed 657 657 658 from constraint_tools import verify_constraints_satisfied658 from mystic.constraint_tools import verify_constraints_satisfied 659 659 print verify_constraints_satisfied(constraints_string, soln, disp=False) 660 660 … … 669 669 time_before = time.time() 670 670 671 from scipy_ncg import NCGSolver672 from termination import SolutionImprovement671 from mystic.scipy_ncg import NCGSolver 672 from mystic.termination import SolutionImprovement 673 673 from mystic.termination import ChangeOverGeneration as COG 674 674 solver = NCGSolver(ndim) … … 688 688 print "Time elapsed=", time_elapsed 689 689 690 from constraint_tools import verify_constraints_satisfied690 from mystic.constraint_tools import verify_constraints_satisfied 691 691 print verify_constraints_satisfied(constraints_string, soln, disp=False) 692 692 … … 701 701 time_before = time.time() 702 702 703 from scipy_cg import CGSolver704 from termination import GradientTermination703 from mystic.scipy_cg import CGSolver 704 from mystic.termination import Gradientmystic.termination 705 705 from mystic.termination import ChangeOverGeneration as COG 706 706 solver = CGSolver(ndim) … … 708 708 solver.SetInitialPoints(x0) 709 709 solver.enable_signal_handler() 710 term = Gradient Termination() # doesn't work well710 term = Gradientmystic.termination() # doesn't work well 711 711 #term = COG() # doesn't work well 712 712 solver.Solve(costfunc, term, constraints=constraints_string, \ … … 720 720 print "Time elapsed=", time_elapsed 721 721 722 from constraint_tools import verify_constraints_satisfied722 from mystic.constraint_tools import verify_constraints_satisfied 723 723 print verify_constraints_satisfied(constraints_string, soln, disp=False) 724 724 -
branches/alta/mystic-0.2a1/constrained_tests/test_constraints_tp6.py
r373 r376 129 129 130 130 import numpy 131 from constraint_tools import verify_constraints_satisfied131 from mystic.constraint_tools import verify_constraints_satisfied 132 132 import time 133 133 … … 162 162 time_before = time.time() 163 163 164 from differential_evolution import DifferentialEvolutionSolver164 from mystic.differential_evolution import DifferentialEvolutionSolver 165 165 from mystic.termination import VTR 166 166 from mystic.termination import CandidateRelativeTolerance as CRT … … 182 182 print "Time elapsed=", time_elapsed 183 183 184 from constraint_tools import verify_constraints_satisfied184 from mystic.constraint_tools import verify_constraints_satisfied 185 185 print verify_constraints_satisfied(constraints_string, soln) 186 186 … … 196 196 time_before = time.time() 197 197 198 from differential_evolution import DifferentialEvolutionSolver2198 from mystic.differential_evolution import DifferentialEvolutionSolver2 199 199 from mystic.termination import VTR 200 200 from mystic.termination import CandidateRelativeTolerance as CRT … … 221 221 print "Time elapsed=", time_elapsed 222 222 223 from constraint_tools import verify_constraints_satisfied223 from mystic.constraint_tools import verify_constraints_satisfied 224 224 print verify_constraints_satisfied(constraints_string, soln) 225 225 … … 235 235 time_before = time.time() 236 236 237 from scipy_optimize import NelderMeadSimplexSolver237 from mystic.scipy_optimize import NelderMeadSimplexSolver 238 238 from mystic.termination import VTR 239 239 from mystic.termination import ChangeOverGeneration as COG … … 257 257 print "Time elapsed=", time_elapsed 258 258 259 from constraint_tools import verify_constraints_satisfied259 from mystic.constraint_tools import verify_constraints_satisfied 260 260 print verify_constraints_satisfied(constraints_string, soln) 261 261 … … 271 271 time_before = time.time() 272 272 273 from scipy_optimize import PowellDirectionalSolver273 from mystic.scipy_optimize import PowellDirectionalSolver 274 274 from mystic.termination import VTR 275 275 from mystic.termination import ChangeOverGeneration as COG … … 292 292 print "Time elapsed=", time_elapsed 293 293 294 from constraint_tools import verify_constraints_satisfied294 from mystic.constraint_tools import verify_constraints_satisfied 295 295 print verify_constraints_satisfied(constraints_string, soln) 296 296 … … 305 305 time_before = time.time() 306 306 307 from scipy_bfgs import BFGSSolver307 from mystic.scipy_bfgs import BFGSSolver 308 308 from mystic.termination import VTR 309 309 from mystic.termination import GradientTermination … … 326 326 print "Time elapsed=", time_elapsed 327 327 328 from constraint_tools import verify_constraints_satisfied328 from mystic.constraint_tools import verify_constraints_satisfied 329 329 print verify_constraints_satisfied(constraints_string, soln) 330 330 … … 339 339 time_before = time.time() 340 340 341 from scipy_ncg import NCGSolver341 from mystic.scipy_ncg import NCGSolver 342 342 from mystic.termination import VTR 343 343 from mystic.termination import ChangeOverGeneration as COG … … 360 360 print "Time elapsed=", time_elapsed 361 361 362 from constraint_tools import verify_constraints_satisfied362 from mystic.constraint_tools import verify_constraints_satisfied 363 363 print verify_constraints_satisfied(constraints_string, soln) 364 364 … … 373 373 time_before = time.time() 374 374 375 from scipy_cg import CGSolver375 from mystic.scipy_cg import CGSolver 376 376 from mystic.termination import VTR 377 377 from mystic.termination import GradientTermination … … 396 396 print "Time elapsed=", time_elapsed 397 397 398 from constraint_tools import verify_constraints_satisfied398 from mystic.constraint_tools import verify_constraints_satisfied 399 399 print verify_constraints_satisfied(constraints_string, soln) 400 400 … … 411 411 time_before = time.time() 412 412 413 from differential_evolution import DifferentialEvolutionSolver413 from mystic.differential_evolution import DifferentialEvolutionSolver 414 414 from mystic.termination import VTR 415 415 from mystic.termination import CandidateRelativeTolerance as CRT … … 430 430 print "Time elapsed=", time_elapsed 431 431 432 from constraint_tools import verify_constraints_satisfied432 from mystic.constraint_tools import verify_constraints_satisfied 433 433 print verify_constraints_satisfied(constraints_string, soln) 434 434 … … 443 443 time_before = time.time() 444 444 445 from differential_evolution import DifferentialEvolutionSolver2445 from mystic.differential_evolution import DifferentialEvolutionSolver2 446 446 from mystic.termination import VTR 447 447 from mystic.termination import CandidateRelativeTolerance as CRT … … 462 462 print "Time elapsed=", time_elapsed 463 463 464 from constraint_tools import verify_constraints_satisfied464 from mystic.constraint_tools import verify_constraints_satisfied 465 465 print verify_constraints_satisfied(constraints_string, soln) 466 466 … … 476 476 time_before = time.time() 477 477 478 from scipy_optimize import NelderMeadSimplexSolver478 from mystic.scipy_optimize import NelderMeadSimplexSolver 479 479 from mystic.termination import VTR 480 480 from mystic.termination import ChangeOverGeneration as COG … … 494 494 print "Time elapsed=", time_elapsed 495 495 496 from constraint_tools import verify_constraints_satisfied496 from mystic.constraint_tools import verify_constraints_satisfied 497 497 print verify_constraints_satisfied(constraints_string, soln) 498 498 … … 508 508 time_before = time.time() 509 509 510 from scipy_optimize import PowellDirectionalSolver510 from mystic.scipy_optimize import PowellDirectionalSolver 511 511 from mystic.termination import VTR 512 512 from mystic.termination import ChangeOverGeneration as COG … … 526 526 print "Time elapsed=", time_elapsed 527 527 528 from constraint_tools import verify_constraints_satisfied528 from mystic.constraint_tools import verify_constraints_satisfied 529 529 print verify_constraints_satisfied(constraints_string, soln) 530 530 … … 539 539 time_before = time.time() 540 540 541 from scipy_bfgs import BFGSSolver541 from mystic.scipy_bfgs import BFGSSolver 542 542 from mystic.termination import VTR 543 543 from mystic.termination import GradientTermination … … 558 558 print "Time elapsed=", time_elapsed 559 559 560 from constraint_tools import verify_constraints_satisfied560 from mystic.constraint_tools import verify_constraints_satisfied 561 561 print verify_constraints_satisfied(constraints_string, soln) 562 562 … … 571 571 time_before = time.time() 572 572 573 from scipy_ncg import NCGSolver573 from mystic.scipy_ncg import NCGSolver 574 574 from mystic.termination import VTR 575 575 from mystic.termination import SolutionImprovement … … 591 591 print "Time elapsed=", time_elapsed 592 592 593 from constraint_tools import verify_constraints_satisfied593 from mystic.constraint_tools import verify_constraints_satisfied 594 594 print verify_constraints_satisfied(constraints_string, soln) 595 595 … … 604 604 time_before = time.time() 605 605 606 from scipy_cg import CGSolver606 from mystic.scipy_cg import CGSolver 607 607 from mystic.termination import VTR 608 608 from mystic.termination import ChangeOverGeneration as COG … … 623 623 print "Time elapsed=", time_elapsed 624 624 625 from constraint_tools import verify_constraints_satisfied625 from mystic.constraint_tools import verify_constraints_satisfied 626 626 print verify_constraints_satisfied(constraints_string, soln) 627 627 -
branches/alta/mystic-0.2a1/constrained_tests/test_constraints_tp80.py
r367 r376 178 178 time_before = time.time() 179 179 180 from differential_evolution import DifferentialEvolutionSolver180 from mystic.differential_evolution import DifferentialEvolutionSolver 181 181 from mystic.termination import VTR 182 182 solver = DifferentialEvolutionSolver(ndim, npop) … … 208 208 time_before = time.time() 209 209 210 from differential_evolution import DifferentialEvolutionSolver2210 from mystic.differential_evolution import DifferentialEvolutionSolver2 211 211 from mystic.termination import VTR 212 212 solver = DifferentialEvolutionSolver2(ndim, npop) … … 238 238 time_before = time.time() 239 239 240 from scipy_optimize import NelderMeadSimplexSolver240 from mystic.scipy_optimize import NelderMeadSimplexSolver 241 241 from mystic.termination import VTR 242 242 solver = NelderMeadSimplexSolver(ndim) … … 268 268 time_before = time.time() 269 269 270 from scipy_optimize import PowellDirectionalSolver270 from mystic.scipy_optimize import PowellDirectionalSolver 271 271 from mystic.termination import VTR 272 272 solver = PowellDirectionalSolver(ndim) … … 298 298 time_before = time.time() 299 299 300 from scipy_bfgs import BFGSSolver300 from mystic.scipy_bfgs import BFGSSolver 301 301 from mystic.termination import VTR 302 302 solver = BFGSSolver(ndim) … … 328 328 time_before = time.time() 329 329 330 from scipy_ncg import NCGSolver330 from mystic.scipy_ncg import NCGSolver 331 331 from mystic.termination import VTR 332 332 solver = NCGSolver(ndim) … … 358 358 time_before = time.time() 359 359 360 from scipy_cg import CGSolver360 from mystic.scipy_cg import CGSolver 361 361 from mystic.termination import VTR 362 362 solver = CGSolver(ndim) … … 390 390 time_before = time.time() 391 391 392 from differential_evolution import DifferentialEvolutionSolver392 from mystic.differential_evolution import DifferentialEvolutionSolver 393 393 from mystic.termination import VTR 394 394 solver = DifferentialEvolutionSolver(ndim, npop) … … 420 420 time_before = time.time() 421 421 422 from differential_evolution import DifferentialEvolutionSolver2422 from mystic.differential_evolution import DifferentialEvolutionSolver2 423 423 from mystic.termination import VTR 424 424 solver = DifferentialEvolutionSolver2(ndim, npop) … … 451 451 time_before = time.time() 452 452 453 from scipy_optimize import NelderMeadSimplexSolver453 from mystic.scipy_optimize import NelderMeadSimplexSolver 454 454 from mystic.termination import VTR 455 455 solver = NelderMeadSimplexSolver(ndim) … … 481 481 time_before = time.time() 482 482 483 from scipy_optimize import PowellDirectionalSolver483 from mystic.scipy_optimize import PowellDirectionalSolver 484 484 from mystic.termination import VTR 485 485 solver = PowellDirectionalSolver(ndim) … … 510 510 time_before = time.time() 511 511 512 from scipy_bfgs import BFGSSolver512 from mystic.scipy_bfgs import BFGSSolver 513 513 from mystic.termination import VTR 514 514 solver = BFGSSolver(ndim) … … 540 540 time_before = time.time() 541 541 542 from scipy_ncg import NCGSolver542 from mystic.scipy_ncg import NCGSolver 543 543 from mystic.termination import VTR 544 544 solver = NCGSolver(ndim) … … 569 569 time_before = time.time() 570 570 571 from scipy_cg import CGSolver571 from mystic.scipy_cg import CGSolver 572 572 from mystic.termination import VTR 573 573 solver = CGSolver(ndim) -
branches/alta/mystic-0.2a1/constrained_tests/test_constraints_venkataraman_71.py
r355 r376 147 147 148 148 import numpy 149 from constraint_tools import verify_constraints_satisfied149 from mystic.constraint_tools import verify_constraints_satisfied 150 150 import time 151 151 … … 184 184 time_before = time.time() 185 185 186 from differential_evolution import DifferentialEvolutionSolver186 from mystic.differential_evolution import DifferentialEvolutionSolver 187 187 from mystic.termination import VTR 188 188 solver = DifferentialEvolutionSolver(ndim, npop) … … 200 200 print "Time elapsed=", time_elapsed 201 201 202 from constraint_tools import verify_constraints_satisfied202 from mystic.constraint_tools import verify_constraints_satisfied 203 203 print verify_constraints_satisfied(constraints_string, soln) 204 204 … … 214 214 time_before = time.time() 215 215 216 from differential_evolution import DifferentialEvolutionSolver2216 from mystic.differential_evolution import DifferentialEvolutionSolver2 217 217 from mystic.termination import VTR 218 218 solver = DifferentialEvolutionSolver2(ndim, npop) … … 230 230 print "Time elapsed=", time_elapsed 231 231 232 from constraint_tools import verify_constraints_satisfied232 from mystic.constraint_tools import verify_constraints_satisfied 233 233 print verify_constraints_satisfied(constraints_string, soln) 234 234 … … 244 244 time_before = time.time() 245 245 246 from scipy_optimize import NelderMeadSimplexSolver246 from mystic.scipy_optimize import NelderMeadSimplexSolver 247 247 from mystic.termination import VTR 248 248 solver = NelderMeadSimplexSolver(ndim) … … 260 260 print "Time elapsed=", time_elapsed 261 261 262 from constraint_tools import verify_constraints_satisfied262 from mystic.constraint_tools import verify_constraints_satisfied 263 263 print verify_constraints_satisfied(constraints_string, soln) 264 264 … … 274 274 time_before = time.time() 275 275 276 from scipy_optimize import PowellDirectionalSolver276 from mystic.scipy_optimize import PowellDirectionalSolver 277 277 from mystic.termination import VTR 278 278 solver = PowellDirectionalSolver(ndim) … … 291 291 print "Time elapsed=", time_elapsed 292 292 293 from constraint_tools import verify_constraints_satisfied293 from mystic.constraint_tools import verify_constraints_satisfied 294 294 print verify_constraints_satisfied(constraints_string, soln) 295 295 … … 304 304 time_before = time.time() 305 305 306 from scipy_bfgs import BFGSSolver306 from mystic.scipy_bfgs import BFGSSolver 307 307 from mystic.termination import VTR 308 308 solver = BFGSSolver(ndim) … … 321 321 print "Time elapsed=", time_elapsed 322 322 323 from constraint_tools import verify_constraints_satisfied323 from mystic.constraint_tools import verify_constraints_satisfied 324 324 print verify_constraints_satisfied(constraints_string, soln) 325 325 … … 334 334 time_before = time.time() 335 335 336 from scipy_ncg import NCGSolver336 from mystic.scipy_ncg import NCGSolver 337 337 from mystic.termination import VTR 338 338 solver = NCGSolver(ndim) … … 351 351 print "Time elapsed=", time_elapsed 352 352 353 from constraint_tools import verify_constraints_satisfied353 from mystic.constraint_tools import verify_constraints_satisfied 354 354 print verify_constraints_satisfied(constraints_string, soln) 355 355 … … 364 364 time_before = time.time() 365 365 366 from scipy_cg import CGSolver366 from mystic.scipy_cg import CGSolver 367 367 from mystic.termination import VTR 368 368 solver = CGSolver(ndim) … … 381 381 print "Time elapsed=", time_elapsed 382 382 383 from constraint_tools import verify_constraints_satisfied383 from mystic.constraint_tools import verify_constraints_satisfied 384 384 print verify_constraints_satisfied(constraints_string, soln) 385 385 … … 396 396 time_before = time.time() 397 397 398 from differential_evolution import DifferentialEvolutionSolver398 from mystic.differential_evolution import DifferentialEvolutionSolver 399 399 from mystic.termination import VTR 400 400 solver = DifferentialEvolutionSolver(ndim, npop) … … 413 413 print "Time elapsed=", time_elapsed 414 414 415 from constraint_tools import verify_constraints_satisfied415 from mystic.constraint_tools import verify_constraints_satisfied 416 416 print verify_constraints_satisfied(constraints_string, soln) 417 417 … … 426 426 time_before = time.time() 427 427 428 from differential_evolution import DifferentialEvolutionSolver2428 from mystic.differential_evolution import DifferentialEvolutionSolver2 429 429 from mystic.termination import VTR 430 430 solver = DifferentialEvolutionSolver2(ndim, npop) … … 443 443 print "Time elapsed=", time_elapsed 444 444 445 from constraint_tools import verify_constraints_satisfied445 from mystic.constraint_tools import verify_constraints_satisfied 446 446 print verify_constraints_satisfied(constraints_string, soln) 447 447 … … 457 457 time_before = time.time() 458 458 459 from scipy_optimize import NelderMeadSimplexSolver459 from mystic.scipy_optimize import NelderMeadSimplexSolver 460 460 from mystic.termination import VTR 461 461 solver = NelderMeadSimplexSolver(ndim) … … 473 473 print "Time elapsed=", time_elapsed 474 474 475 from constraint_tools import verify_constraints_satisfied475 from mystic.constraint_tools import verify_constraints_satisfied 476 476 print verify_constraints_satisfied(constraints_string, soln) 477 477 … … 487 487 time_before = time.time() 488 488 489 from scipy_optimize import PowellDirectionalSolver489 from mystic.scipy_optimize import PowellDirectionalSolver 490 490 from mystic.termination import VTR 491 491 solver = PowellDirectionalSolver(ndim) … … 503 503 print "Time elapsed=", time_elapsed 504 504 505 from constraint_tools import verify_constraints_satisfied505 from mystic.constraint_tools import verify_constraints_satisfied 506 506 print verify_constraints_satisfied(constraints_string, soln) 507 507 … … 516 516 time_before = time.time() 517 517 518 from scipy_bfgs import BFGSSolver518 from mystic.scipy_bfgs import BFGSSolver 519 519 from mystic.termination import VTR 520 520 solver = BFGSSolver(ndim) … … 533 533 print "Time elapsed=", time_elapsed 534 534 535 from constraint_tools import verify_constraints_satisfied535 from mystic.constraint_tools import verify_constraints_satisfied 536 536 print verify_constraints_satisfied(constraints_string, soln) 537 537 … … 546 546 time_before = time.time() 547 547 548 from scipy_ncg import NCGSolver548 from mystic.scipy_ncg import NCGSolver 549 549 from mystic.termination import VTR 550 550 solver = NCGSolver(ndim) … … 562 562 print "Time elapsed=", time_elapsed 563 563 564 from constraint_tools import verify_constraints_satisfied564 from mystic.constraint_tools import verify_constraints_satisfied 565 565 print verify_constraints_satisfied(constraints_string, soln) 566 566 … … 575 575 time_before = time.time() 576 576 577 from scipy_cg import CGSolver577 from mystic.scipy_cg import CGSolver 578 578 from mystic.termination import VTR 579 579 solver = CGSolver(ndim) … … 592 592 print "Time elapsed=", time_elapsed 593 593 594 from constraint_tools import verify_constraints_satisfied594 from mystic.constraint_tools import verify_constraints_satisfied 595 595 print verify_constraints_satisfied(constraints_string, soln) 596 596 … … 612 612 test_powelldirectional_auglag() 613 613 test_bfgs_auglag() # a little off with x0=[0.5, 0.5] 614 test_ncg_auglag() # gets stuck without the hack in scipy_ncg614 test_ncg_auglag() # gets stuck without the hack in mystic.scipy_ncg 615 615 # with x0=[0.5, 0.5], does not iterate 616 616 test_cg_auglag() -
branches/alta/mystic-0.2a1/constrained_tests/test_constraints_zimmermann.py
r373 r376 208 208 time_before = time.time() 209 209 210 from differential_evolution import DifferentialEvolutionSolver210 from mystic.differential_evolution import DifferentialEvolutionSolver 211 211 from mystic.termination import VTR 212 212 from mystic.termination import CandidateRelativeTolerance as CRT … … 240 240 time_before = time.time() 241 241 242 from differential_evolution import DifferentialEvolutionSolver2242 from mystic.differential_evolution import DifferentialEvolutionSolver2 243 243 from mystic.termination import VTR 244 244 from mystic.strategy import Rand1Bin … … 271 271 time_before = time.time() 272 272 273 from scipy_optimize import NelderMeadSimplexSolver273 from mystic.scipy_optimize import NelderMeadSimplexSolver 274 274 from mystic.termination import VTR 275 275 solver = NelderMeadSimplexSolver(ndim) … … 296 296 print "\nPowellDirectional, penalty" 297 297 298 random_seed(seed) 299 300 # Do some timing 301 time_before = time.time() 302 303 from scipy_optimize import PowellDirectionalSolver 298 import mystic 299 300 random_seed(seed) 301 302 # Do some timing 303 time_before = time.time() 304 305 from mystic.scipy_optimize import PowellDirectionalSolver 304 306 from mystic.termination import VTR 305 307 solver = PowellDirectionalSolver(ndim) 306 307 308 solver.SetRandomInitialPoints(lb, ub) 308 309 solver.enable_signal_handler() … … 331 332 time_before = time.time() 332 333 333 from scipy_bfgs import BFGSSolver334 from mystic.scipy_bfgs import BFGSSolver 334 335 from mystic.termination import VTR 335 336 solver = BFGSSolver(ndim) … … 361 362 time_before = time.time() 362 363 363 from scipy_ncg import NCGSolver364 from mystic.scipy_ncg import NCGSolver 364 365 from mystic.termination import VTR 365 366 solver = NCGSolver(ndim) … … 391 392 time_before = time.time() 392 393 393 from scipy_cg import CGSolver394 from mystic.scipy_cg import CGSolver 394 395 from mystic.termination import VTR 395 396 solver = CGSolver(ndim) … … 424 425 time_before = time.time() 425 426 426 from differential_evolution import DifferentialEvolutionSolver427 from mystic.differential_evolution import DifferentialEvolutionSolver 427 428 from mystic.termination import VTR 428 429 from mystic.termination import ChangeOverGeneration as COG … … 456 457 time_before = time.time() 457 458 458 from differential_evolution import DifferentialEvolutionSolver2459 from mystic.differential_evolution import DifferentialEvolutionSolver2 459 460 from mystic.termination import VTR 460 461 from mystic.strategy import Rand1Bin … … 487 488 time_before = time.time() 488 489 489 from scipy_optimize import NelderMeadSimplexSolver490 from mystic.scipy_optimize import NelderMeadSimplexSolver 490 491 from mystic.termination import VTR 491 492 from mystic.termination import CandidateRelativeTolerance as CRT … … 519 520 time_before = time.time() 520 521 521 from scipy_optimize import PowellDirectionalSolver522 from mystic.scipy_optimize import PowellDirectionalSolver 522 523 from mystic.termination import VTR 523 524 solver = PowellDirectionalSolver(ndim) … … 548 549 time_before = time.time() 549 550 550 from scipy_bfgs import BFGSSolver551 from mystic.scipy_bfgs import BFGSSolver 551 552 from mystic.termination import VTR 552 553 from mystic.termination import GradientTermination … … 580 581 time_before = time.time() 581 582 582 from scipy_ncg import NCGSolver583 from mystic.scipy_ncg import NCGSolver 583 584 from mystic.termination import VTR 584 585 solver = NCGSolver(ndim) … … 609 610 time_before = time.time() 610 611 611 from scipy_cg import CGSolver612 from mystic.scipy_cg import CGSolver 612 613 from mystic.termination import VTR 613 614 solver = CGSolver(ndim) … … 642 643 time_before = time.time() 643 644 644 from differential_evolution import DifferentialEvolutionSolver645 from mystic.differential_evolution import DifferentialEvolutionSolver 645 646 from mystic.termination import VTR 646 647 from mystic.strategy import Rand1Bin … … 673 674 time_before = time.time() 674 675 675 from differential_evolution import DifferentialEvolutionSolver2676 from mystic.differential_evolution import DifferentialEvolutionSolver2 676 677 from mystic.termination import VTR 677 678 from mystic.strategy import Rand1Bin … … 704 705 time_before = time.time() 705 706 706 from scipy_optimize import NelderMeadSimplexSolver707 from mystic.scipy_optimize import NelderMeadSimplexSolver 707 708 from mystic.termination import VTR 708 709 solver = NelderMeadSimplexSolver(ndim) … … 734 735 time_before = time.time() 735 736 736 from scipy_optimize import PowellDirectionalSolver737 from mystic.scipy_optimize import PowellDirectionalSolver 737 738 from mystic.termination import VTR 738 739 solver = PowellDirectionalSolver(ndim) … … 763 764 time_before = time.time() 764 765 765 from scipy_bfgs import BFGSSolver766 from mystic.scipy_bfgs import BFGSSolver 766 767 from mystic.termination import VTR 767 768 solver = BFGSSolver(ndim) … … 793 794 time_before = time.time() 794 795 795 from scipy_ncg import NCGSolver796 from mystic.scipy_ncg import NCGSolver 796 797 from mystic.termination import VTR 797 798 solver = NCGSolver(ndim) … … 822 823 time_before = time.time() 823 824 824 from scipy_cg import CGSolver825 from mystic.scipy_cg import CGSolver 825 826 from mystic.termination import VTR 826 827 solver = CGSolver(ndim) -
branches/alta/mystic-0.2a1/constrained_tests/test_problems_constrained.py
r367 r376 21 21 22 22 #print venkataraman_71([1.0, 1.0]) 23 24 25 def antoniou_lu_15_6(x):26 """27 Minimize (x1 - 2)**2 + (x2 - 1)**228 subject to:29 -x1**2 + x2 >= 030 -x1 + x2**2 >= 031 Expected minimum: (1., 1.)32 Mathematica: x -> 1.16537, y -> 1.3580933 Source: Example 15.6, page 527. Practical Optimization: Algorithms34 and Engineering Applications, by Andreas Antoniou and Wu-Sheng Lu.35 Springer. 2007.""" #XXX Does not work?36 x1 = x[0]37 x2 = x[1]38 return (x1 - 2.)**2 + (x2 - 1.)**239 40 #print antoniou_lu_15_6([1., 1.])41 23 42 24 def cvxopt_qp(x): … … 216 198 #print g4([78, 33, 29.995256, 45, 36.7758129]) #-30665.539 217 199 218 ###################################################219 220 def shuonan(x):221 """Source: 'Toy' problem from the project paper of Shuonan Dong, 18.086 MIT222 Project 2, Spring 2006. "Methods for Constrained Optimization".223 224 Minimize 2.*x1**2 + x1*x2 + 2.*x2**2 - 6.*x1 - 6.*x2 + 15.225 subject to:226 x1 + 2.*x2 <= 5.227 4.*x1 <= 7.228 x2 <= 2.229 -2.*x1 + 2.*x2 = -1.230 231 Graphs and results from this function do not seem to match his paper though..."""232 x1 = x[0]233 x2 = x[1]234 return 2.*x1**2 + x1*x2 + 2.*x2**2 - 6.*x1 - 6.*x2 + 15.235 236 200 ################################################################## 237 201 # A very large source of constrained and only box-constrained test problems … … 291 255 return 1./(27.*(3.**0.5))*((x[0] - 3.)**2 - 9.)*x[1]**3 292 256 257 258 c = [-6.089, -17.164, -34.054, -5.914,-24.721, -14.986, -24.100, -10.708,\ 259 -26.662, -22.179] 293 260 def tp112(x): 294 261 """TP112 of Schittkowski's test problems. … … 306 273 where f= -47.707579 307 274 """ 308 c = [-6.089, -17.164, -34.054, -5.914,-24.721, -14.986, -24.100, -10.708,\309 -26.662, -22.179] #XXX Move this list of constants outside?310 275 s = 0. 311 276 for j in range(10): -
branches/alta/mystic-0.2a1/constraint_tools.py
r371 r376 1183 1183 if method == 'direct': 1184 1184 if type(constraints) == str: 1185 suggestedorder = None 1186 if kwds.has_key('suggestedorder'): 1187 suggestedorder = kwds['suggestedorder'] 1185 1188 constraints = form_constraints_function(constraints, ndim, \ 1186 varname=varname, varnamelist=varnamelist, **kwds) 1189 varname=varname, varnamelist=varnamelist,\ 1190 suggestedorder=suggestedorder) 1187 1191 # If there are strict constraints, wrap them. 1188 1192 if constraints_strict: -
branches/alta/mystic-0.2a1/mystic_test_suite.py
r373 r376 586 586 self.min = [-1.28]*self.ND 587 587 self.max = [1.28]*self.ND 588 self.maxiter = 10000588 self.maxiter = 2500 589 589 self.nplaces = 0 # Precision of answer 590 590 … … 593 593 import numpy 594 594 from mystic.tools import random_seed 595 random_seed(123)595 #random_seed(123) 596 596 esow = Sow() 597 597 ssow = Sow() … … 620 620 from mystic.termination import VTR 621 621 tol = 1e-7 622 self.NP = 40622 self.NP = 100 623 623 self.solver = DifferentialEvolutionSolver(self.ND, self.NP) 624 624 self.term = VTR()#tol) … … 630 630 from mystic.termination import ChangeOverGeneration as COG 631 631 tol = 1e-7 632 self.NP = 40632 self.NP = 100 633 633 self.solver = DifferentialEvolutionSolver(self.ND, self.NP) 634 634 self.term = COG()#tol) … … 640 640 from mystic.termination import NormalizedChangeOverGeneration as NCOG 641 641 tol = 1e-7 642 self.NP = 40642 self.NP = 100 643 643 self.solver = DifferentialEvolutionSolver(self.ND, self.NP) 644 644 self.term = NCOG()#tol) … … 650 650 from mystic.termination import CandidateRelativeTolerance as CRT 651 651 tol = 1e-7 652 self.NP = 40652 self.NP = 100 653 653 self.solver = DifferentialEvolutionSolver(self.ND, self.NP) 654 654 self.term = CRT()#tol) … … 662 662 from mystic.termination import VTR 663 663 tol = 1e-7 664 self.NP = 40664 self.NP = 100 665 665 self.solver = DifferentialEvolutionSolver2(self.ND, self.NP) 666 666 self.term = VTR()#tol) … … 672 672 from mystic.termination import ChangeOverGeneration as COG 673 673 tol = 1e-7 674 self.NP = 40674 self.NP = 100 675 675 self.solver = DifferentialEvolutionSolver2(self.ND, self.NP) 676 676 self.term = COG()#tol) … … 682 682 from mystic.termination import NormalizedChangeOverGeneration as NCOG 683 683 tol = 1e-7 684 self.NP = 40684 self.NP = 100 685 685 self.solver = DifferentialEvolutionSolver2(self.ND, self.NP) 686 686 self.term = NCOG()#tol) … … 692 692 from mystic.termination import CandidateRelativeTolerance as CRT 693 693 tol = 1e-7 694 self.NP = 40694 self.NP = 100 695 695 self.solver = DifferentialEvolutionSolver2(self.ND, self.NP) 696 696 self.term = CRT()#tol) … … 780 780 import numpy 781 781 from mystic.tools import random_seed 782 #random_seed(123)782 random_seed(123) 783 783 esow = Sow() 784 784 ssow = Sow() … … 1370 1370 from mystic.termination import VTR 1371 1371 tol = 1e-7 1372 self.NP = 1001373 self.solver = DifferentialEvolutionSolver(self.ND, self.NP) 1374 self.term = VTR( 0.00001)1372 self.NP = 40 1373 self.solver = DifferentialEvolutionSolver(self.ND, self.NP) 1374 self.term = VTR()#0.00001) 1375 1375 from mystic.strategy import Rand1Exp 1376 1376 self._run_solver( strategy=Rand1Exp, CrossProbability=0.3, ScalingFactor=1.0 ) … … 1380 1380 from mystic.termination import ChangeOverGeneration as COG 1381 1381 tol = 1e-7 1382 self.NP = 1001382 self.NP = 40 1383 1383 self.solver = DifferentialEvolutionSolver(self.ND, self.NP) 1384 1384 self.term = COG()#tol) … … 1390 1390 from mystic.termination import NormalizedChangeOverGeneration as NCOG 1391 1391 tol = 1e-7 1392 self.NP = 1001392 self.NP = 40 1393 1393 self.solver = DifferentialEvolutionSolver(self.ND, self.NP) 1394 1394 self.term = NCOG()#tol) … … 1400 1400 from mystic.termination import CandidateRelativeTolerance as CRT 1401 1401 tol = 1e-7 1402 self.NP = 1001402 self.NP = 40 1403 1403 self.solver = DifferentialEvolutionSolver(self.ND, self.NP) 1404 1404 self.term = CRT()#tol) … … 1412 1412 from mystic.termination import VTR 1413 1413 tol = 1e-7 1414 self.NP = 1001414 self.NP = 40 1415 1415 self.solver = DifferentialEvolutionSolver2(self.ND, self.NP) 1416 1416 self.term = VTR()#tol) … … 1422 1422 from mystic.termination import ChangeOverGeneration as COG 1423 1423 tol = 1e-7 1424 self.NP = 1001424 self.NP = 40 1425 1425 self.solver = DifferentialEvolutionSolver2(self.ND, self.NP) 1426 1426 self.term = COG()#tol) … … 1432 1432 from mystic.termination import NormalizedChangeOverGeneration as NCOG 1433 1433 tol = 1e-7 1434 self.NP = 1001434 self.NP = 40 1435 1435 self.solver = DifferentialEvolutionSolver2(self.ND, self.NP) 1436 1436 self.term = NCOG()#tol) … … 1442 1442 from mystic.termination import CandidateRelativeTolerance as CRT 1443 1443 tol = 1e-7 1444 self.NP = 1001444 self.NP = 40 1445 1445 self.solver = DifferentialEvolutionSolver2(self.ND, self.NP) 1446 1446 self.term = CRT()#tol) … … 3224 3224 # suite11, suite12, suite13, suite14,\ 3225 3225 # suite15, suite16, suite17]) 3226 allsuites = unittest.TestSuite([suite 4])3226 allsuites = unittest.TestSuite([suite5]) 3227 3227 unittest.TextTestRunner(verbosity=2).run(allsuites)
Note: See TracChangeset
for help on using the changeset viewer.