Changeset 239


Ignore:
Timestamp:
05/16/10 22:02:03 (6 years ago)
Author:
mmckerns
Message:

bugfixes for termination conditions (ticket #76); added beginnings of test scripts for termination conditions

Files:
1 deleted
1 edited
4 copied

Legend:

Unmodified
Added
Removed
  • mystic/mystic/termination.py

    r234 r239  
    2929         hist = inst.energy_history 
    3030         lg = len(hist) 
    31          return lg > generations and (hist[-generations]-hist[-1]) < tolerance 
     31         if lg <= generations: return False 
     32         return (hist[-generations]-hist[-1]) < tolerance 
    3233    return _ChangeOverGeneration 
    3334 
    34 def NormalizedChangeOverGeneration(tolerance = 1e-4, generations = 2): 
     35def NormalizedChangeOverGeneration(tolerance = 1e-4, generations = 10): 
    3536    """normalized change in cost is < tolerance over number of generations: 
    3637 
     
    4041         hist = inst.energy_history 
    4142         lg = len(hist) 
     43         if lg <= generations: return False 
    4244         diff = tolerance*(abs(hist[-generations])+abs(hist[-1])) + eta 
    43          return lg > generations and 2.0*(hist[-generations]-hist[-1]) <= diff 
     45         return 2.0*(hist[-generations]-hist[-1]) <= diff 
    4446    return _NormalizedChangeOverGeneration 
    4547               
     
    4850 
    4951abs(xi-x0) <= xtol & abs(fi-f0) <= ftol, where x=params & f=cost""" 
     52    #NOTE: this termination expects nPop > 1 
    5053    def _CandidateRelativeTolerance(inst): 
    51          sim = inst.population 
    52          fsim = inst.popEnergy 
     54         sim = numpy.array(inst.population) 
     55         fsim = numpy.array(inst.popEnergy) 
     56         if not len(fsim[1:]): 
     57             print "Warning: Invalid termination condition (nPop < 2)" 
     58             return True 
     59         #   raise ValueError, "Invalid termination condition (nPop < 2)" 
    5360         #FIXME: abs(inf - inf) will raise a warning... 
    5461         errdict = numpy.seterr(invalid='ignore') #FIXME: turn off warning  
    55          answer = (max(numpy.ravel(abs(sim[1:]-sim[0]))) <= xtol \ 
    56                   and max(abs(fsim[0]-fsim[1:])) <= ftol) 
     62         answer = max(numpy.ravel(abs(sim[1:]-sim[0]))) <= xtol 
     63         answer = answer and max(abs(fsim[0]-fsim[1:])) <= ftol 
    5764         numpy.seterr(invalid=errdict['invalid']) #FIXME: turn on warnings 
    5865         return answer 
  • mystic/tests/chebyshevinputs.py

    r183 r239  
    3131max_bounds = [200, 1,   0, 1,200, 1,   0, inf, inf] 
    3232 
    33 #termination = CandidateRelativeTolerance() 
     33termination = CandidateRelativeTolerance() 
    3434#termination = VTR() 
    3535#termination = ChangeOverGeneration() 
    36 termination = NormalizedChangeOverGeneration() 
     36#termination = NormalizedChangeOverGeneration() 
    3737 
    3838# End of file 
  • mystic/tests/chebyshevinputs_de.py

    r183 r239  
    3939 
    4040#termination = VTR() 
    41 #termination = CandidateRelativeTolerance() 
     41termination = CandidateRelativeTolerance() 
    4242#termination = ChangeOverGeneration() 
    43 termination = NormalizedChangeOverGeneration() 
     43#termination = NormalizedChangeOverGeneration() 
    4444 
    4545 
  • mystic/tests/roseninputs.py

    r183 r239  
    3131#max_bounds = [200.001, 100.001, inf]     
    3232 
    33 #termination = CandidateRelativeTolerance() 
     33termination = CandidateRelativeTolerance() 
    3434#termination = VTR() 
    35 termination = ChangeOverGeneration() 
     35#termination = ChangeOverGeneration() 
    3636#termination = NormalizedChangeOverGeneration() 
    3737 
Note: See TracChangeset for help on using the changeset viewer.