<s> __author__ = '<STR_LIT>' <EOL> from pybrain . optimization . optimizer import BlackBoxOptimizer <EOL> from scipy import exp <EOL> from random import random <EOL> class HillClimber ( BlackBoxOptimizer ) : <EOL> """<STR_LIT>""" <EOL> evaluatorIsNoisy = False <EOL> def _additionalInit ( self ) : <EOL> self . _oneEvaluation ( self . _initEvaluable ) <EOL> def _learnStep ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . evaluatorIsNoisy : <EOL> self . bestEvaluation = self . _oneEvaluation ( self . bestEvaluable ) <EOL> challenger = self . bestEvaluable . copy ( ) <EOL> challenger . mutate ( ) <EOL> self . _oneEvaluation ( challenger ) <EOL> @ property <EOL> def batchSize ( self ) : <EOL> if self . evaluatorIsNoisy : <EOL> return <NUM_LIT:2> <EOL> else : <EOL> return <NUM_LIT:1> <EOL> class StochasticHillClimber ( HillClimber ) : <EOL> """<STR_LIT>""" <EOL> temperature = <NUM_LIT:1.> <EOL> def _learnStep ( self ) : <EOL> if self . evaluatorIsNoisy : <EOL> self . bestEvaluation = self . _oneEvaluation ( self . bestEvaluable ) <EOL> challenger = self . bestEvaluable . copy ( ) <EOL> challenger . mutate ( ) <EOL> newEval = self . _oneEvaluation ( challenger ) <EOL> if ( ( not self . minimize and newEval < self . bestEvaluation ) or <EOL> ( self . minimize and newEval > self . bestEvaluation ) ) : <EOL> acceptProbability = exp ( - abs ( newEval - self . bestEvaluation ) / self . temperature ) <EOL> if random ( ) < acceptProbability : <EOL> self . bestEvaluable , self . bestEvaluation = challenger , newEval </s>
