Changeset 782 for mystic


Ignore:
Timestamp:
02/17/15 10:30:50 (15 months ago)
Author:
mmckerns
Message:

moved _SetEvaluationLimits inside CheckTermination?;
moved _termination and callback inside Step

Location:
mystic/mystic
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • mystic/mystic/abstract_solver.py

    r781 r782  
    542542        if termination is None: 
    543543            termination = self._termination 
     544        # ensure evaluation limits have been imposed 
     545        self._SetEvaluationLimits() 
    544546        # check for termination messages 
    545547        msg = termination(self, info=True) 
     
    704706        # set up signal handler 
    705707        import signal 
    706         self._EARLYEXIT = False 
     708        self._EARLYEXIT = False  #XXX: why not use EARLYEXIT singleton? 
    707709        self._generateHandler(sigint_callback)  
    708         if self._handle_sigint: signal.signal(signal.SIGINT, self.signal_handler) 
     710        if self._handle_sigint: signal.signal(signal.SIGINT,self.signal_handler) 
    709711 
    710712       ## decorate cost function with bounds, penalties, monitors, etc 
     
    716718        # the initital optimization iteration 
    717719        if not len(self._stepmon): # do generation = 0 
    718             self.Step() 
    719             if callback is not None: 
    720                 callback(self.bestSolution) 
    721           
    722             # initialize termination conditions, if needed 
    723             self._termination(self) #XXX: call at generation 0 or always? 
    724         # impose the evaluation limits 
    725         self._SetEvaluationLimits() 
     720            self.Step(callback=callback) 
    726721 
    727722        # the main optimization loop 
    728723        while not self.CheckTermination() and not self._EARLYEXIT: 
    729             self.Step(**settings) 
    730             if callback is not None: 
    731                 callback(self.bestSolution) 
     724            self.Step(**settings)  # includes settings['callback'] 
    732725        else: self._exitMain() 
    733726 
  • mystic/mystic/differential_evolution.py

    r781 r782  
    222222        cost = self._bootstrap_objective(cost, ExtraArgs) 
    223223        # process and activate input settings 
    224         kwds['strategy'] = strategy  # override default strategy with None 
     224        kwds['strategy'] = strategy  # override default strategy 
    225225        settings = self._process_inputs(kwds) 
    226226        for key in settings: 
    227227            exec "%s = settings['%s']" % (key,key) 
    228228 
     229        init = False  # flag to do 0th iteration 'post-initialization' 
     230 
    229231        if not len(self._stepmon): # do generation = 0 
     232            init = True 
    230233            self.population[0] = asfarray(self.population[0]) 
    231234            # decouple bestSolution from population and bestEnergy from popEnergy 
     
    267270        # if savefrequency matches, then save state 
    268271        self._AbstractSolver__save_state() 
     272 
     273        # do callback 
     274        if callback is not None: callback(self.bestSolution) 
     275        # initialize termination conditions, if needed 
     276        if init: self._termination(self) #XXX: at generation 0 or always? 
    269277        return #XXX: call CheckTermination ? 
    270278 
     
    379387        cost = self._bootstrap_objective(cost, ExtraArgs) 
    380388        # process and activate input settings 
    381         kwds['strategy'] = strategy  # override default strategy with None 
     389        kwds['strategy'] = strategy  # override default strategy 
    382390        settings = self._process_inputs(kwds) 
    383391        for key in settings: 
    384392            exec "%s = settings['%s']" % (key,key) 
    385393 
     394        init = False  # flag to do 0th iteration 'post-initialization' 
     395 
    386396        if not len(self._stepmon): # do generation = 0 
     397            init = True 
    387398            self.population[0] = asfarray(self.population[0]) 
    388399            # decouple bestSolution from population and bestEnergy from popEnergy 
     
    429440        # if savefrequency matches, then save state 
    430441        self._AbstractSolver__save_state() 
     442 
     443        # do callback 
     444        if callback is not None: callback(self.bestSolution) 
     445        # initialize termination conditions, if needed 
     446        if init: self._termination(self) #XXX: at generation 0 or always? 
    431447        return #XXX: call CheckTermination ? 
    432448 
  • mystic/mystic/scipy_optimize.py

    r781 r782  
    152152 
    153153        rho = 1; chi = 2; psi = 0.5; sigma = 0.5; 
     154        init = False  # flag to do 0th iteration 'post-initialization' 
    154155 
    155156        if not len(self._stepmon): # do generation = 0 
     157            init = True 
    156158            x0 = self.population[0] 
    157159            x0 = asfarray(x0).flatten() 
     
    252254        # if savefrequency matches, then save state 
    253255        self._AbstractSolver__save_state() 
     256 
     257        # do callback 
     258        if callback is not None: callback(self.bestSolution) 
     259        # initialize termination conditions, if needed 
     260        if init: self._termination(self) #XXX: at generation 0 or always? 
    254261        return #XXX: call CheckTermination ? 
    255262 
     
    469476        fval = self.popEnergy[0] # bestEnergy 
    470477        x1, fx, bigind, delta = self.__internals 
     478        init = False  # flag to do 0th iteration 'post-initialization' 
    471479 
    472480        if not len(self._stepmon): # do generation = 0 
     481            init = True 
    473482            x = asfarray(x).flatten() 
    474483            x = asfarray(self._constraints(x)) 
     
    558567        self.population[0] = x   # bestSolution 
    559568        self.popEnergy[0] = fval # bestEnergy 
     569 
     570        # do callback 
     571        if callback is not None: callback(self.bestSolution) 
     572        # initialize termination conditions, if needed 
     573        if init: self._termination(self) #XXX: at generation 0 or always? 
    560574        return #XXX: call CheckTermination ? 
    561575 
Note: See TracChangeset for help on using the changeset viewer.