Changeset 239
- Timestamp:
- 05/16/10 22:02:03 (6 years ago)
- Files:
-
- 1 deleted
- 1 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
mystic/mystic/termination.py
r234 r239 29 29 hist = inst.energy_history 30 30 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 32 33 return _ChangeOverGeneration 33 34 34 def NormalizedChangeOverGeneration(tolerance = 1e-4, generations = 2):35 def NormalizedChangeOverGeneration(tolerance = 1e-4, generations = 10): 35 36 """normalized change in cost is < tolerance over number of generations: 36 37 … … 40 41 hist = inst.energy_history 41 42 lg = len(hist) 43 if lg <= generations: return False 42 44 diff = tolerance*(abs(hist[-generations])+abs(hist[-1])) + eta 43 return lg > generations and2.0*(hist[-generations]-hist[-1]) <= diff45 return 2.0*(hist[-generations]-hist[-1]) <= diff 44 46 return _NormalizedChangeOverGeneration 45 47 … … 48 50 49 51 abs(xi-x0) <= xtol & abs(fi-f0) <= ftol, where x=params & f=cost""" 52 #NOTE: this termination expects nPop > 1 50 53 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)" 53 60 #FIXME: abs(inf - inf) will raise a warning... 54 61 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 57 64 numpy.seterr(invalid=errdict['invalid']) #FIXME: turn on warnings 58 65 return answer -
mystic/tests/chebyshevinputs.py
r183 r239 31 31 max_bounds = [200, 1, 0, 1,200, 1, 0, inf, inf] 32 32 33 #termination = CandidateRelativeTolerance()33 termination = CandidateRelativeTolerance() 34 34 #termination = VTR() 35 35 #termination = ChangeOverGeneration() 36 termination = NormalizedChangeOverGeneration()36 #termination = NormalizedChangeOverGeneration() 37 37 38 38 # End of file -
mystic/tests/chebyshevinputs_de.py
r183 r239 39 39 40 40 #termination = VTR() 41 #termination = CandidateRelativeTolerance()41 termination = CandidateRelativeTolerance() 42 42 #termination = ChangeOverGeneration() 43 termination = NormalizedChangeOverGeneration()43 #termination = NormalizedChangeOverGeneration() 44 44 45 45 -
mystic/tests/roseninputs.py
r183 r239 31 31 #max_bounds = [200.001, 100.001, inf] 32 32 33 #termination = CandidateRelativeTolerance()33 termination = CandidateRelativeTolerance() 34 34 #termination = VTR() 35 termination = ChangeOverGeneration()35 #termination = ChangeOverGeneration() 36 36 #termination = NormalizedChangeOverGeneration() 37 37
Note: See TracChangeset
for help on using the changeset viewer.