Changeset 151 for releases


Ignore:
Timestamp:
07/23/09 11:47:37 (7 years ago)
Author:
altafang
Message:

Adding snobfit (branch and bound) optimizer to Mystic framework

Location:
releases/mystic-0.1a2/mystic
Files:
4 added
1 edited

Legend:

Unmodified
Added
Removed
  • releases/mystic-0.1a2/mystic/termination.py

    r124 r151  
    5959    return _ 
    6060 
     61def SnobfitTermination(fglob=0, rtol=1e-6, ftol=1e-6, nstop=250): 
     62    """fglob -- the user specified global function value. 
     63rtol -- a relative error for checking stopping criterion. 
     64ftol -- acceptable relative error in func(xopt) for convergence. 
     65nstop  -- number of times no improvement is tolerated. 
     66 
     67Terminate if no improvement after nstop iterations or  if  
     68abs((fopt-fglob)/fglob) < rtol for fglob != 0, abs(fopt) < ftol  
     69for fglob == 0""" 
     70 
     71    def _(inst): 
     72         answer = False 
     73         hist = inst.energy_history 
     74         if len(hist) > nstop and (hist[-nstop]-hist[-1]) < 0: 
     75             answer = True 
     76         else: 
     77             fopt = inst.bestEnergy 
     78             if fglob: 
     79                 if  abs((fopt-fglob)/fglob) < rtol: 
     80                     answer = True  
     81             else: # safeguard if functions with fglob=0 are added by user 
     82                 if  abs(fopt) < ftol: 
     83                     answer = True  
     84         return answer 
     85    return _ 
     86 
    6187# end of file 
Note: See TracChangeset for help on using the changeset viewer.