Ignore:
Timestamp:
08/04/10 16:07:50 (6 years ago)
Author:
altafang
Message:

Fixing minor things, adjusting termination conditions on tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/alta/mystic-0.2a1/test_constraints_tp24.py

    r371 r373  
    1111x0 = [1., 0.5] # feasible 
    1212expected solution = [3., 1.7320508075688772] where f=-1. 
     13Solution is at corner of feasible region. 
    1314""" 
    1415 
     
    5455 
    5556    from differential_evolution import DifferentialEvolutionSolver 
    56     from mystic.termination import VTR 
    5757    from mystic.termination import CandidateRelativeTolerance as CRT 
    5858    from mystic.termination import ChangeOverGeneration as COG 
     
    6161    solver.SetInitialPoints(x0) 
    6262    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 
    6665    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    6766                constraints_method='penalty') 
     
    8887 
    8988    from differential_evolution import DifferentialEvolutionSolver2 
    90     from mystic.termination import VTR 
    91     from mystic.termination import ChangeOverGeneration as COG 
     89    from mystic.termination import ChangeOverGeneration as COG 
     90    from mystic.termination import CandidateRelativeTolerance as CRT 
    9291    solver = DifferentialEvolutionSolver2(ndim, npop) 
    9392       
    9493    solver.SetInitialPoints(x0) 
    9594    solver.enable_signal_handler() 
    96     #term = VTR() # does not work well 
    97     term = COG() # does work well 
     95    term = CRT() # works well 
     96    #term = COG() # does work well 
    9897    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    9998                constraints_method='penalty') 
     
    120119 
    121120    from scipy_optimize import NelderMeadSimplexSolver 
    122     from mystic.termination import VTR 
    123     from mystic.termination import ChangeOverGeneration as COG 
     121    from mystic.termination import ChangeOverGeneration as COG 
     122    from mystic.termination import CandidateRelativeTolerance as CRT 
    124123    solver = NelderMeadSimplexSolver(ndim) 
    125124       
    126125    solver.SetInitialPoints(x0) 
    127126    solver.enable_signal_handler() 
    128     #term = VTR() # doesn't work well 
    129127    term = COG() # does work well 
     128    #term = CRT() # litte bit off 
    130129    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    131130                constraints_method='penalty') 
     
    152151 
    153152    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 
    155155    solver = PowellDirectionalSolver(ndim) 
    156156       
    157157    solver.SetInitialPoints(x0) 
    158158    solver.enable_signal_handler() 
    159     term = VTR() 
     159    #term = VTR() # strangely, seems to work ok 
     160    term = COG() # works well 
    160161    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    161162                constraints_method='penalty') 
     
    182183 
    183184    from scipy_bfgs import BFGSSolver 
    184     from mystic.termination import VTR 
    185185    from mystic.termination import GradientTermination 
     186    from mystic.termination import ChangeOverGeneration as COG 
    186187    solver = BFGSSolver(ndim) 
    187188       
    188189    solver.SetInitialPoints(x0) 
    189190    solver.enable_signal_handler() 
    190     #term = VTR() # does not work well 
    191     term = GradientTermination() # does work well 
     191    #term = GradientTermination() # does work well 
     192    term = COG() # works well 
    192193    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    193194                constraints_method='penalty') 
     
    214215 
    215216    from scipy_ncg import NCGSolver 
    216     from mystic.termination import VTR 
    217217    from termination import SolutionImprovement 
    218218    from termination import ChangeOverGeneration as COG 
     
    222222    solver.SetInitialPoints(x0) 
    223223    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 
    226225    #term = COG() # does not work well 
    227226    #term = NCOG() # does not work well 
     
    250249 
    251250    from scipy_cg import CGSolver 
    252     from mystic.termination import VTR 
    253251    from termination import ChangeOverGeneration as COG 
    254252    from termination import NormalizedChangeOverGeneration as NCOG 
     
    258256    solver.SetInitialPoints(x0) 
    259257    solver.enable_signal_handler() 
    260     #term = VTR() # does not work well 
    261258    term = COG() # works well 
    262259    solver.Solve(costfunc, term, constraints=constraints_string, \ 
     
    318315 
    319316    from differential_evolution import DifferentialEvolutionSolver2 
    320     from mystic.termination import VTR 
    321     from mystic.termination import CandidateRelativeTolerance as CRT 
     317    from mystic.termination import CandidateRelativeTolerance as CRT 
     318    from mystic.termination import ChangeOverGeneration as COG 
    322319    solver = DifferentialEvolutionSolver2(ndim, npop) 
    323320       
    324321    solver.SetInitialPoints(x0) 
    325322    solver.enable_signal_handler() 
    326     term = VTR() # does not work well 
    327     #term = CRT() # works well 
     323    term = CRT() # works well 
     324    #term = COG() # works well 
    328325    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    329326                constraints_method='auglag') 
     
    351348 
    352349    from scipy_optimize import NelderMeadSimplexSolver 
    353     from mystic.termination import VTR 
    354     from termination import ChangeOverGeneration as COG 
     350    from mystic.termination import ChangeOverGeneration as COG 
     351    from mystic.termination import CandidateRelativeTolerance as CRT 
    355352    solver = NelderMeadSimplexSolver(ndim) 
    356353       
    357354    solver.SetInitialPoints(x0) 
    358355    solver.enable_signal_handler() 
    359     #term = VTR() # does not work well 
    360     term = COG() # works well 
     356    #term = COG() # works well 
     357    term = CRT() # works well 
    361358    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    362359                constraints_method='auglag') 
     
    384381    from scipy_optimize import PowellDirectionalSolver 
    385382    from mystic.termination import VTR 
     383    from mystic.termination import ChangeOverGeneration as COG 
    386384    solver = PowellDirectionalSolver(ndim) 
    387385       
    388386    solver.SetInitialPoints(x0) 
    389387    solver.enable_signal_handler() 
    390     term = VTR() 
     388    #term = VTR() 
     389    term = COG() # works well 
    391390    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    392391                constraints_method='auglag') 
     
    412411 
    413412    from scipy_bfgs import BFGSSolver 
    414     from mystic.termination import VTR 
    415413    from termination import GradientTermination 
     414    from mystic.termination import ChangeOverGeneration as COG 
    416415    solver = BFGSSolver(ndim) 
    417416       
    418417    solver.SetInitialPoints(x0) 
    419418    solver.enable_signal_handler() 
    420     #term = VTR() # does not work well 
    421     term = GradientTermination() # works well 
     419    #term = GradientTermination() # works well 
     420    term = COG() # works well 
    422421    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    423422                constraints_method='auglag') 
     
    444443 
    445444    from scipy_ncg import NCGSolver 
    446     from mystic.termination import VTR 
    447445    from termination import SolutionImprovement 
     446    from mystic.termination import ChangeOverGeneration as COG 
    448447    solver = NCGSolver(ndim) 
    449448       
    450449    solver.SetInitialPoints(x0) 
    451450    solver.enable_signal_handler() 
    452     term = VTR() # does not work well 
    453     term = SolutionImprovement() # works well 
     451    #term = SolutionImprovement() # works well 
     452    term = COG() # works well 
    454453    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    455454                constraints_method='auglag') 
     
    475474 
    476475    from scipy_cg import CGSolver 
    477     from mystic.termination import VTR 
    478476    from termination import ChangeOverGeneration as COG 
    479477    solver = CGSolver(ndim) 
     
    481479    solver.SetInitialPoints(x0) 
    482480    solver.enable_signal_handler() 
    483     term = VTR() # does not work well 
    484481    term = COG() # works well 
    485482    solver.Solve(costfunc, term, constraints=constraints_string, \ 
     
    509506 
    510507    from differential_evolution import DifferentialEvolutionSolver 
    511     from mystic.termination import VTR 
    512508    from mystic.termination import ChangeOverGeneration as COG 
    513509    from mystic.termination import NormalizedChangeOverGeneration as NCOG 
     
    517513    solver.SetInitialPoints(x0) 
    518514    solver.enable_signal_handler() 
    519     #term = VTR() # does not work 
    520515    #term = COG() # a bit off 
    521516    #term = NCOG() # also a bit off 
     
    545540 
    546541    from differential_evolution import DifferentialEvolutionSolver2 
    547     from mystic.termination import VTR 
    548     from mystic.termination import CandidateRelativeTolerance as CRT 
     542    from mystic.termination import CandidateRelativeTolerance as CRT 
     543    from mystic.termination import ChangeOverGeneration as COG 
    549544    solver = DifferentialEvolutionSolver2(ndim, npop) 
    550545       
    551546    solver.SetInitialPoints(x0) 
    552547    solver.enable_signal_handler() 
    553     #term = VTR() # does not work well 
    554     term = CRT() # works well 
     548    #term = CRT() # works well 
     549    term = COG() # works ok 
    555550    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    556551                constraints_method='filter') 
     
    577572 
    578573    from scipy_optimize import NelderMeadSimplexSolver 
    579     from mystic.termination import VTR 
    580574    from mystic.termination import ChangeOverGeneration as COG 
    581575    from mystic.termination import NormalizedChangeOverGeneration as NCOG 
     
    585579    solver.SetInitialPoints(x0) 
    586580    solver.enable_signal_handler() 
    587     term = VTR() # doesn't work  
    588581    #term = COG() # quite a bit off 
    589     #term = CRT() # also off 
     582    term = CRT() # also off 
    590583    #term = NCOG() # also off 
    591584    solver.Solve(costfunc, term, constraints=constraints_string, \ 
     
    645638 
    646639    from scipy_bfgs import BFGSSolver 
    647     from mystic.termination import VTR 
    648640    from termination import GradientTermination 
    649641    from mystic.termination import ChangeOverGeneration as COG 
     
    652644    solver.SetInitialPoints(x0) 
    653645    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 
    656647    #term = COG() # doesn't work well either 
    657648    solver.Solve(costfunc, term, constraints=constraints_string, \ 
     
    679670 
    680671    from scipy_ncg import NCGSolver 
    681     from mystic.termination import VTR 
    682672    from termination import SolutionImprovement 
    683673    from mystic.termination import ChangeOverGeneration as COG 
     
    686676    solver.SetInitialPoints(x0) 
    687677    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 
    690679    #term = COG() # doesn't work either 
    691680    solver.Solve(costfunc, term, constraints=constraints_string, \ 
     
    713702 
    714703    from scipy_cg import CGSolver 
    715     from mystic.termination import VTR 
    716704    from termination import GradientTermination  
    717705    from mystic.termination import ChangeOverGeneration as COG 
     
    720708    solver.SetInitialPoints(x0) 
    721709    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 
    724711    #term = COG() # doesn't work well 
    725712    solver.Solve(costfunc, term, constraints=constraints_string, \ 
     
    739726 
    740727if __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()  
    747733    test_powelldirectional_penalty() 
    748     test_bfgs_penalty() # needs GradientTermination 
    749     test_ncg_penalty() # won't work despite trying 
    750     test_cg_penalty() # needs COG 
     734    test_bfgs_penalty()  
     735    test_ncg_penalty() # bad answer 
     736    test_cg_penalty()  
    751737 
    752738    test_diffev_auglag()  
    753     test_diffev2_auglag() # needs CRT 
    754     test_neldermead_auglag() # needs COG 
     739    test_diffev2_auglag()  
     740    test_neldermead_auglag()  
    755741    test_powelldirectional_auglag() 
    756     test_bfgs_auglag() # needs GradientTermination 
    757     test_ncg_auglag() # needs SolutionImprovement termination 
    758     test_cg_auglag() # needs COG 
    759  
    760     test_diffev_filter() # needs CRT 
    761     test_diffev2_filter() # needs CRT 
     742    test_bfgs_auglag()  
     743    test_ncg_auglag()  
     744    test_cg_auglag()  
     745 
     746    test_diffev_filter()  
     747    test_diffev2_filter() 
    762748    test_neldermead_filter() # bad answer 
    763749    test_powelldirectional_filter() # improves with COG 
Note: See TracChangeset for help on using the changeset viewer.