Changeset 373 for branches/alta/mystic-0.2a1/test_constraints_tp24.py
- Timestamp:
- 08/04/10 16:07:50 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alta/mystic-0.2a1/test_constraints_tp24.py
r371 r373 11 11 x0 = [1., 0.5] # feasible 12 12 expected solution = [3., 1.7320508075688772] where f=-1. 13 Solution is at corner of feasible region. 13 14 """ 14 15 … … 54 55 55 56 from differential_evolution import DifferentialEvolutionSolver 56 from mystic.termination import VTR57 57 from mystic.termination import CandidateRelativeTolerance as CRT 58 58 from mystic.termination import ChangeOverGeneration as COG … … 61 61 solver.SetInitialPoints(x0) 62 62 solver.enable_signal_handler() 63 #term = VTR() # not very good 64 #term = CRT() # doesn't do much 65 term = COG() # this works well 63 term = CRT() # works well 64 #term = COG() # this works well 66 65 solver.Solve(costfunc, term, constraints=constraints_string, \ 67 66 constraints_method='penalty') … … 88 87 89 88 from differential_evolution import DifferentialEvolutionSolver2 90 from mystic.termination import VTR91 from mystic.termination import C hangeOverGeneration as COG89 from mystic.termination import ChangeOverGeneration as COG 90 from mystic.termination import CandidateRelativeTolerance as CRT 92 91 solver = DifferentialEvolutionSolver2(ndim, npop) 93 92 94 93 solver.SetInitialPoints(x0) 95 94 solver.enable_signal_handler() 96 #term = VTR() # does not workwell97 term = COG() # does work well95 term = CRT() # works well 96 #term = COG() # does work well 98 97 solver.Solve(costfunc, term, constraints=constraints_string, \ 99 98 constraints_method='penalty') … … 120 119 121 120 from scipy_optimize import NelderMeadSimplexSolver 122 from mystic.termination import VTR123 from mystic.termination import C hangeOverGeneration as COG121 from mystic.termination import ChangeOverGeneration as COG 122 from mystic.termination import CandidateRelativeTolerance as CRT 124 123 solver = NelderMeadSimplexSolver(ndim) 125 124 126 125 solver.SetInitialPoints(x0) 127 126 solver.enable_signal_handler() 128 #term = VTR() # doesn't work well129 127 term = COG() # does work well 128 #term = CRT() # litte bit off 130 129 solver.Solve(costfunc, term, constraints=constraints_string, \ 131 130 constraints_method='penalty') … … 152 151 153 152 from scipy_optimize import PowellDirectionalSolver 154 from mystic.termination import VTR 153 #from mystic.termination import VTR 154 from mystic.termination import ChangeOverGeneration as COG 155 155 solver = PowellDirectionalSolver(ndim) 156 156 157 157 solver.SetInitialPoints(x0) 158 158 solver.enable_signal_handler() 159 term = VTR() 159 #term = VTR() # strangely, seems to work ok 160 term = COG() # works well 160 161 solver.Solve(costfunc, term, constraints=constraints_string, \ 161 162 constraints_method='penalty') … … 182 183 183 184 from scipy_bfgs import BFGSSolver 184 from mystic.termination import VTR185 185 from mystic.termination import GradientTermination 186 from mystic.termination import ChangeOverGeneration as COG 186 187 solver = BFGSSolver(ndim) 187 188 188 189 solver.SetInitialPoints(x0) 189 190 solver.enable_signal_handler() 190 #term = VTR() # does notwork well191 term = GradientTermination() # does workwell191 #term = GradientTermination() # does work well 192 term = COG() # works well 192 193 solver.Solve(costfunc, term, constraints=constraints_string, \ 193 194 constraints_method='penalty') … … 214 215 215 216 from scipy_ncg import NCGSolver 216 from mystic.termination import VTR217 217 from termination import SolutionImprovement 218 218 from termination import ChangeOverGeneration as COG … … 222 222 solver.SetInitialPoints(x0) 223 223 solver.enable_signal_handler() 224 term = VTR() # does not work well 225 #term = SolutionImprovement() # does not work well 224 term = SolutionImprovement() # does not work well 226 225 #term = COG() # does not work well 227 226 #term = NCOG() # does not work well … … 250 249 251 250 from scipy_cg import CGSolver 252 from mystic.termination import VTR253 251 from termination import ChangeOverGeneration as COG 254 252 from termination import NormalizedChangeOverGeneration as NCOG … … 258 256 solver.SetInitialPoints(x0) 259 257 solver.enable_signal_handler() 260 #term = VTR() # does not work well261 258 term = COG() # works well 262 259 solver.Solve(costfunc, term, constraints=constraints_string, \ … … 318 315 319 316 from differential_evolution import DifferentialEvolutionSolver2 320 from mystic.termination import VTR321 from mystic.termination import C andidateRelativeTolerance as CRT317 from mystic.termination import CandidateRelativeTolerance as CRT 318 from mystic.termination import ChangeOverGeneration as COG 322 319 solver = DifferentialEvolutionSolver2(ndim, npop) 323 320 324 321 solver.SetInitialPoints(x0) 325 322 solver.enable_signal_handler() 326 term = VTR() # does not workwell327 #term = C RT() # works well323 term = CRT() # works well 324 #term = COG() # works well 328 325 solver.Solve(costfunc, term, constraints=constraints_string, \ 329 326 constraints_method='auglag') … … 351 348 352 349 from scipy_optimize import NelderMeadSimplexSolver 353 from mystic.termination import VTR354 from termination import ChangeOverGeneration as COG350 from mystic.termination import ChangeOverGeneration as COG 351 from mystic.termination import CandidateRelativeTolerance as CRT 355 352 solver = NelderMeadSimplexSolver(ndim) 356 353 357 354 solver.SetInitialPoints(x0) 358 355 solver.enable_signal_handler() 359 #term = VTR() # does not workwell360 term = C OG() # works well356 #term = COG() # works well 357 term = CRT() # works well 361 358 solver.Solve(costfunc, term, constraints=constraints_string, \ 362 359 constraints_method='auglag') … … 384 381 from scipy_optimize import PowellDirectionalSolver 385 382 from mystic.termination import VTR 383 from mystic.termination import ChangeOverGeneration as COG 386 384 solver = PowellDirectionalSolver(ndim) 387 385 388 386 solver.SetInitialPoints(x0) 389 387 solver.enable_signal_handler() 390 term = VTR() 388 #term = VTR() 389 term = COG() # works well 391 390 solver.Solve(costfunc, term, constraints=constraints_string, \ 392 391 constraints_method='auglag') … … 412 411 413 412 from scipy_bfgs import BFGSSolver 414 from mystic.termination import VTR415 413 from termination import GradientTermination 414 from mystic.termination import ChangeOverGeneration as COG 416 415 solver = BFGSSolver(ndim) 417 416 418 417 solver.SetInitialPoints(x0) 419 418 solver.enable_signal_handler() 420 #term = VTR() # does not workwell421 term = GradientTermination() # works well419 #term = GradientTermination() # works well 420 term = COG() # works well 422 421 solver.Solve(costfunc, term, constraints=constraints_string, \ 423 422 constraints_method='auglag') … … 444 443 445 444 from scipy_ncg import NCGSolver 446 from mystic.termination import VTR447 445 from termination import SolutionImprovement 446 from mystic.termination import ChangeOverGeneration as COG 448 447 solver = NCGSolver(ndim) 449 448 450 449 solver.SetInitialPoints(x0) 451 450 solver.enable_signal_handler() 452 term = VTR() # does not workwell453 term = SolutionImprovement() # works well451 #term = SolutionImprovement() # works well 452 term = COG() # works well 454 453 solver.Solve(costfunc, term, constraints=constraints_string, \ 455 454 constraints_method='auglag') … … 475 474 476 475 from scipy_cg import CGSolver 477 from mystic.termination import VTR478 476 from termination import ChangeOverGeneration as COG 479 477 solver = CGSolver(ndim) … … 481 479 solver.SetInitialPoints(x0) 482 480 solver.enable_signal_handler() 483 term = VTR() # does not work well484 481 term = COG() # works well 485 482 solver.Solve(costfunc, term, constraints=constraints_string, \ … … 509 506 510 507 from differential_evolution import DifferentialEvolutionSolver 511 from mystic.termination import VTR512 508 from mystic.termination import ChangeOverGeneration as COG 513 509 from mystic.termination import NormalizedChangeOverGeneration as NCOG … … 517 513 solver.SetInitialPoints(x0) 518 514 solver.enable_signal_handler() 519 #term = VTR() # does not work520 515 #term = COG() # a bit off 521 516 #term = NCOG() # also a bit off … … 545 540 546 541 from differential_evolution import DifferentialEvolutionSolver2 547 from mystic.termination import VTR548 from mystic.termination import C andidateRelativeTolerance as CRT542 from mystic.termination import CandidateRelativeTolerance as CRT 543 from mystic.termination import ChangeOverGeneration as COG 549 544 solver = DifferentialEvolutionSolver2(ndim, npop) 550 545 551 546 solver.SetInitialPoints(x0) 552 547 solver.enable_signal_handler() 553 #term = VTR() # does not workwell554 term = C RT() # works well548 #term = CRT() # works well 549 term = COG() # works ok 555 550 solver.Solve(costfunc, term, constraints=constraints_string, \ 556 551 constraints_method='filter') … … 577 572 578 573 from scipy_optimize import NelderMeadSimplexSolver 579 from mystic.termination import VTR580 574 from mystic.termination import ChangeOverGeneration as COG 581 575 from mystic.termination import NormalizedChangeOverGeneration as NCOG … … 585 579 solver.SetInitialPoints(x0) 586 580 solver.enable_signal_handler() 587 term = VTR() # doesn't work588 581 #term = COG() # quite a bit off 589 #term = CRT() # also off582 term = CRT() # also off 590 583 #term = NCOG() # also off 591 584 solver.Solve(costfunc, term, constraints=constraints_string, \ … … 645 638 646 639 from scipy_bfgs import BFGSSolver 647 from mystic.termination import VTR648 640 from termination import GradientTermination 649 641 from mystic.termination import ChangeOverGeneration as COG … … 652 644 solver.SetInitialPoints(x0) 653 645 solver.enable_signal_handler() 654 term = VTR() # does not work well 655 #term = GradientTermination() # also doesn't work 646 term = GradientTermination() # also doesn't work 656 647 #term = COG() # doesn't work well either 657 648 solver.Solve(costfunc, term, constraints=constraints_string, \ … … 679 670 680 671 from scipy_ncg import NCGSolver 681 from mystic.termination import VTR682 672 from termination import SolutionImprovement 683 673 from mystic.termination import ChangeOverGeneration as COG … … 686 676 solver.SetInitialPoints(x0) 687 677 solver.enable_signal_handler() 688 term = VTR() # does not work well 689 #term = SolutionImprovement() # doesn't work either 678 term = SolutionImprovement() # doesn't work either 690 679 #term = COG() # doesn't work either 691 680 solver.Solve(costfunc, term, constraints=constraints_string, \ … … 713 702 714 703 from scipy_cg import CGSolver 715 from mystic.termination import VTR716 704 from termination import GradientTermination 717 705 from mystic.termination import ChangeOverGeneration as COG … … 720 708 solver.SetInitialPoints(x0) 721 709 solver.enable_signal_handler() 722 term = VTR() # doesn't work well 723 #term = GradientTermination() # doesn't work well 710 term = GradientTermination() # doesn't work well 724 711 #term = COG() # doesn't work well 725 712 solver.Solve(costfunc, term, constraints=constraints_string, \ … … 739 726 740 727 if __name__ == '__main__': 741 # Penalty method doesn't work well with defaults/VTR -- possibly because 742 # solvers think they are already at a minimum, since function values are 743 # relatively flat near x0, according to the contour plot. 744 test_diffev_penalty() # needs COG 745 test_diffev2_penalty() # needs COG 746 test_neldermead_penalty() # needs COG 728 # Penalty method doesn't work well with defaults/VTR, since the final 729 # function value is negative. 730 test_diffev_penalty() 731 test_diffev2_penalty() 732 test_neldermead_penalty() 747 733 test_powelldirectional_penalty() 748 test_bfgs_penalty() # needs GradientTermination749 test_ncg_penalty() # won't work despite trying750 test_cg_penalty() # needs COG734 test_bfgs_penalty() 735 test_ncg_penalty() # bad answer 736 test_cg_penalty() 751 737 752 738 test_diffev_auglag() 753 test_diffev2_auglag() # needs CRT754 test_neldermead_auglag() # needs COG739 test_diffev2_auglag() 740 test_neldermead_auglag() 755 741 test_powelldirectional_auglag() 756 test_bfgs_auglag() # needs GradientTermination757 test_ncg_auglag() # needs SolutionImprovement termination758 test_cg_auglag() # needs COG759 760 test_diffev_filter() # needs CRT761 test_diffev2_filter() # needs CRT742 test_bfgs_auglag() 743 test_ncg_auglag() 744 test_cg_auglag() 745 746 test_diffev_filter() 747 test_diffev2_filter() 762 748 test_neldermead_filter() # bad answer 763 749 test_powelldirectional_filter() # improves with COG
Note: See TracChangeset
for help on using the changeset viewer.