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_tp6.py

    r364 r373  
    88Mystic Results: 
    99--------------- 
     10Results below are after testing different termination conditions and using 
     11ones that worked, if any worked. 
     12 
    1013Differential Evolution, penalty 
    11 soln= [ 0.93185794  0.86835217] 
    12 f value = 0.00464334043612 
    13 Time elapsed= 3.22497200966 
    14 -7.04931582951e-05  ?=  0.0 
     14soln= [ 0.99999626  0.99999252] 
     15f value = 1.39955330985e-11 
     16Time elapsed= 1.82334899902 
     172.74909317532e-08  ?=  0.0 
    1518True 
    1619 
     
    1821soln= [ 0.77856495  0.6061442 ] 
    1922f value = 0.0490334793345 
    20 Time elapsed= 5.53334498405 
     23Time elapsed= 2.31935405731 
    2124-0.000191837517554  ?=  0.0 
    2225True 
     
    2528soln= [-0.79924969  0.63882551] 
    2629f value = 3.23729944276 
    27 Time elapsed= 0.173187971115 
     30Time elapsed= 0.0765020847321 
    28310.000254426113928  ?=  0.0 
    2932True 
     
    3235soln= [-0.54298813  0.29474638] 
    3336f value = 2.3808123589 
    34 Time elapsed= 0.693130016327 
     37Time elapsed= 0.30738401413 
    3538-0.000897233040719  ?=  0.0 
    3639True 
     
    3942soln= [-1.2  1. ] 
    4043f value = 4.84 
    41 Time elapsed= 0.347265005112 
     44Time elapsed= 0.158123016357 
    4245-4.4  ?=  0.0 
    4346False 
    4447 
    4548NCG, penalty 
    46 soln= [-1.03440639  1.06999695] 
    47 f value = 4.13880936014 
    48 Time elapsed= 0.591888189316 
    49 3.72762859691e-06  ?=  0.0 
     49soln= [-1.03447871  1.07014734] 
     50f value = 4.13910362412 
     51Time elapsed= 0.00758099555969 
     521.13919376488e-05  ?=  0.0 
    5053True 
    5154 
     
    5356soln= [ 0.2151731   0.04624554] 
    5457f value = 0.615953267272 
    55 Time elapsed= 0.507454156876 
     58Time elapsed= 0.318397045135 
    5659-0.000539243908523  ?=  0.0 
    5760True 
    5861 
    5962DifferentialEvolution, auglag 
    60 soln= [ 1.0265255   1.05539154] 
    61 f value = 0.000703602183114 
    62 Time elapsed= 0.444896936417 
    63 0.0163693695118  ?=  0.0 
     63soln= [ 1.00001488  1.00002945] 
     64f value = 2.21482471957e-10 
     65Time elapsed= 0.617501974106 
     66-3.15108766635e-06  ?=  0.0 
     67True 
     68 
     69DifferentialEvolution2, auglag 
     70soln= [ 1.00000246  1.00000481] 
     71f value = 6.04295189197e-12 
     72Time elapsed= 0.828866958618 
     73-1.08042532698e-06  ?=  0.0 
     74True 
     75 
     76NelderMead, auglag 
     77soln= [ 0.99999706  0.99999401] 
     78f value = 8.62311013723e-12 
     79Time elapsed= 0.106360912323 
     80-1.15163547698e-06  ?=  0.0 
     81True 
     82 
     83PowellDirectional, auglag 
     84soln= [ 1.  1.] 
     85f value = 0.0 
     86Time elapsed= 0.686278104782 
     870.0  ?=  0.0 
     88True 
     89 
     90BFGS, auglag 
     91soln= [ 0.99999077  0.99998178] 
     92f value = 8.51914601677e-11 
     93Time elapsed= 0.0958249568939 
     942.39940897706e-06  ?=  0.0 
     95True 
     96 
     97NCG, auglag 
     98soln= [-0.23107736  0.05350618] 
     99f value = 1.51555147832 
     100Time elapsed= 32.7819998264 
     1010.00109432112118  ?=  0.0 
    64102False 
    65103 
    66 DifferentialEvolution2, auglag 
    67 soln= [ 0.95122535  0.90491171] 
    68 f value = 0.00237896631011 
    69 Time elapsed= 0.696881055832 
    70 0.000820387523576  ?=  0.0 
    71 True 
    72  
    73 NelderMead, auglag 
    74 soln= [ 0.9665114   0.93380755] 
    75 f value = 0.00112148653455 
    76 Time elapsed= 0.149505138397 
    77 -0.00336728044141  ?=  0.0 
    78 False 
    79  
    80 PowellDirectional, auglag 
    81 soln= [ 0.97953372  0.9594863 ] 
    82 f value = 0.000418868698238 
    83 Time elapsed= 0.570738077164 
    84 -1.11022302463e-15  ?=  0.0 
    85 True 
    86  
    87 BFGS, auglag 
    88 soln= [ 0.95481343  0.91217455] 
    89 f value = 0.00204182583475 
    90 Time elapsed= 0.164708137512 
    91 0.00505859260701  ?=  0.0 
    92 False 
    93  
    94 NCG gets stuck 
    95  
    96104CG, auglag 
    97 soln= [ 0.95841557  0.91844345] 
    98 f value = 0.00172926461434 
    99 Time elapsed= 0.449685096741 
    100 -0.0011695707853  ?=  0.0 
    101 False 
     105soln= [ 0.99997764  0.99995528] 
     106f value = 4.99909986311e-10 
     107Time elapsed= 0.253920793533 
     108-6.79715139729e-08  ?=  0.0 
     109True 
    102110 
    103111 
     
    157165    from mystic.termination import VTR 
    158166    from mystic.termination import CandidateRelativeTolerance as CRT 
     167    from mystic.termination import ChangeOverGeneration as COG 
    159168    solver = DifferentialEvolutionSolver(ndim, npop) 
    160169     
    161170    solver.SetInitialPoints(x0) 
    162171    solver.enable_signal_handler() 
    163     term = VTR() 
    164     #term = CRT() 
     172    #term = VTR() # must specify tol=0 
     173    #term = CRT() # works well 
     174    term = COG() # works well 
    165175    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    166176                constraints_method='penalty') 
     
    190200    from mystic.termination import CandidateRelativeTolerance as CRT 
    191201    from mystic.termination import ChangeOverGeneration as COG 
     202    from mystic.termination import NormalizedChangeOverGeneration as NCOG 
     203    from mystic.strategy import Rand1Bin 
     204 
     205    npop = 70 # Won't work unless npop is large 
    192206    solver = DifferentialEvolutionSolver2(ndim, npop) 
    193207     
    194208    solver.SetInitialPoints(x0) 
    195209    solver.enable_signal_handler() 
    196     term = VTR() 
    197     #term = CRT() 
    198     #term = COG() 
     210    #term = VTR() # must specify tol=0 
     211    #term = CRT() # bad 
     212    term = COG() # bad 
     213    #term = NCOG() # bad 
    199214    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    200215                constraints_method='penalty') 
     
    224239    from mystic.termination import ChangeOverGeneration as COG 
    225240    from mystic.termination import NormalizedChangeOverGeneration as NCOG 
     241    from mystic.termination import CandidateRelativeTolerance as CRT 
    226242    solver = NelderMeadSimplexSolver(ndim) 
    227243     
    228244    solver.SetInitialPoints(x0) 
    229245    solver.enable_signal_handler() 
    230     term = VTR() # does not work well 
     246    #term = VTR(0) # must specify tol=0 
    231247    #term = COG() # does not work well 
    232248    #term = NCOG() # does not work well 
     249    term = CRT() # bad 
    233250    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    234251                constraints_method='penalty') 
     
    257274    from mystic.termination import VTR 
    258275    from mystic.termination import ChangeOverGeneration as COG 
     276    from mystic.termination import NormalizedChangeOverGeneration as NCOG 
    259277    solver = PowellDirectionalSolver(ndim) 
    260278     
    261279    solver.SetInitialPoints(x0) 
    262280    solver.enable_signal_handler() 
    263     term = VTR() 
    264     #term = COG() 
     281    #term = VTR(0) # must specify tol=0 
     282    #term = COG() # bad 
     283    term = NCOG() # bad 
    265284    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    266285                constraints_method='penalty') 
     
    289308    from mystic.termination import VTR 
    290309    from mystic.termination import GradientTermination 
     310    from mystic.termination import ChangeOverGeneration as COG 
    291311    solver = BFGSSolver(ndim) 
    292312     
    293313    solver.SetInitialPoints(x0) 
    294314    solver.enable_signal_handler() 
    295     term = VTR() 
    296     #term = GradientTermination() 
     315    #term = VTR(0) # must specify tol=0 
     316    term = GradientTermination() # doesn't iterate 
     317    #term = COG() # doesn't iterate 
    297318    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    298319                constraints_method='penalty')#, penalty=1e3) 
     
    320341    from scipy_ncg import NCGSolver 
    321342    from mystic.termination import VTR 
     343    from mystic.termination import ChangeOverGeneration as COG 
     344    from mystic.termination import SolutionImprovement 
    322345    solver = NCGSolver(ndim) 
    323346     
    324347    solver.SetInitialPoints(x0) 
    325348    solver.enable_signal_handler() 
    326     term = VTR() 
     349    #term = VTR(0) # must specify tol=0 
     350    #term = COG() # bad 
     351    term = SolutionImprovement() # local min 
    327352    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    328353                constraints_method='penalty') 
     
    352377    from mystic.termination import GradientTermination 
    353378    from mystic.termination import ChangeOverGeneration as COG 
     379    from mystic.termination import NormalizedChangeOverGeneration as NCOG 
    354380    solver = CGSolver(ndim) 
    355381     
    356382    solver.SetInitialPoints(x0) 
    357383    solver.enable_signal_handler() 
    358     term = VTR() # doesn't work 
    359     #term = GradientTermination() # doesn't help 
     384    #term = VTR(0) # must specify tol=0 
     385    term = GradientTermination() # doesn't help 
    360386    #term = COG() # doesn't work either 
    361     solver.Solve(costfunc, term, constraints=constraints_string, \ 
    362                 constraints_method='penalty')#, penalty=1e3) 
     387    #term = NCOG() # bad 
     388    solver.Solve(costfunc, term, constraints=constraints_string, \ 
     389                constraints_method='penalty')#, penalty=1e7) 
    363390    soln = solver.Solution() 
    364391 
     
    391418    solver.SetInitialPoints(x0) 
    392419    solver.enable_signal_handler() 
    393     term = VTR() 
    394     #term = CRT() 
     420    #term = VTR(0) # must specify tol=0 
     421    term = CRT() # works well 
    395422    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    396423                constraints_method='auglag') 
     
    423450    solver.SetInitialPoints(x0) 
    424451    solver.enable_signal_handler() 
    425     term = VTR() 
    426     #term = CRT() 
     452    #term = VTR(0) # must specify tol=0 
     453    term = CRT() # works well 
    427454    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    428455                constraints_method='auglag') 
     
    456483    solver.SetInitialPoints(x0) 
    457484    solver.enable_signal_handler() 
    458     term = VTR() # gives answer that is a bit off 
    459     #term = COG() # works well 
     485    #term = VTR(0)  # must specify tol=0 
     486    term = COG() # works well 
    460487    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    461488                constraints_method='auglag') 
     
    488515    solver.SetInitialPoints(x0) 
    489516    solver.enable_signal_handler() 
    490     term = VTR() # gives answer that is a bit off 
    491     #term = COG()  # works well 
     517    #term = VTR(0) # must specify tol=0 
     518    term = COG()  # works well 
    492519    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    493520                constraints_method='auglag') 
     
    519546    solver.SetInitialPoints(x0) 
    520547    solver.enable_signal_handler() 
    521     term = VTR() # gives answer that is quite off 
    522     #term = GradientTermination() # works well 
     548    #term = VTR(0) # must specify tol=0 
     549    term = GradientTermination() # works well 
    523550    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    524551                constraints_method='auglag') 
     
    547574    from mystic.termination import VTR 
    548575    from mystic.termination import SolutionImprovement 
     576    from mystic.termination import ChangeOverGeneration as COG 
    549577    solver = NCGSolver(ndim) 
    550578     
    551579    solver.SetInitialPoints(x0) 
    552580    solver.enable_signal_handler() 
    553     term = VTR() # doesn't work 
     581    #term = VTR(0) # must specify tol=0 
    554582    #term = SolutionImprovement() # doesn't help 
     583    term = COG() # works well 
    555584    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    556585                constraints_method='auglag') 
     
    582611    solver.SetInitialPoints(x0) 
    583612    solver.enable_signal_handler() 
    584     term = VTR() # gives answer that is a bit off   
    585     #term = COG() # much better 
     613    #term = VTR(0)  # must specify tol=0 
     614    term = COG() # much better 
    586615    solver.Solve(costfunc, term, constraints=constraints_string, \ 
    587616                constraints_method='auglag') 
     
    598627 
    599628if __name__ == '__main__': 
    600     # All tests do poorly with defaults.  
    601     test_diffev_penalty() # good with CRT 
    602     test_diffev2_penalty() # really won't work 
    603     test_neldermead_penalty() # off 
    604     test_powelldirectional_penalty() # off 
    605     test_bfgs_penalty() # needs penalty=1e3 and GradientTermination 
    606     test_ncg_penalty() # off 
    607     test_cg_penalty() # off 
    608  
    609     test_diffev_auglag() # good with CRT 
    610     test_diffev2_auglag() # good with CRT 
    611     test_neldermead_auglag() # good with COG 
    612     test_powelldirectional_auglag() # good with COG 
    613     test_bfgs_auglag() # good with GradientTermination 
    614     test_ncg_auglag() # stuck 
    615     test_cg_auglag() # good with COG 
     629    # All tests do poorly with defaults because VTR has a default tol of 0.005, 
     630    # and f(minimum) here is 0.  
     631    test_diffev_penalty()  
     632    test_diffev2_penalty() # need to increase npop 
     633    test_neldermead_penalty() # bad answer; higher penalty -> local min 
     634    test_powelldirectional_penalty() # bad answer; higher penalty -> local min 
     635    test_bfgs_penalty() # needs lower penalty 
     636    test_ncg_penalty() # local min 
     637    test_cg_penalty() # quite bad; higher penalty -> local min 
     638 
     639    test_diffev_auglag()  
     640    test_diffev2_auglag()  
     641    test_neldermead_auglag()  
     642    test_powelldirectional_auglag()  
     643    test_bfgs_auglag() 
     644    test_ncg_auglag() # takes a very long time, and bad answer 
     645    test_cg_auglag()  
    616646    print "expected: [1., 1.]" 
    617647 
Note: See TracChangeset for help on using the changeset viewer.