Ejemplo n.º 1
0
 def _oneEvaluation(self, evaluable):
     if self.numEvaluations == 0:
         return BlackBoxOptimizer._oneEvaluation(self, evaluable)
     else:
         self.switchMutations()
         if isinstance(evaluable, MaskedParameters):
             evaluable.returnZeros = False
             x0 = evaluable.params
             evaluable.returnZeros = True            
             def f(x): 
                 evaluable._setParameters(x)
                 return BlackBoxOptimizer._oneEvaluation(self, evaluable)
         else:
             f = lambda x: BlackBoxOptimizer._oneEvaluation(self, x)
             x0 = evaluable
         outsourced = self.localSearch(f, x0, 
                                       maxEvaluations = self.localSteps, 
                                       desiredEvaluation = self.desiredEvaluation,
                                       minimize = self.minimize,
                                       **self.localSearchArgs)
         assert self.localSteps > outsourced.batchSize, 'localSteps too small ('+str(self.localSteps)+\
                                             '), because local search has a batch size of '+str(outsourced.batchSize)
         _, fitness = outsourced.learn()
         self.switchMutations()  
         return fitness
Ejemplo n.º 2
0
    def _oneEvaluation(self, evaluable):
        if self.numEvaluations == 0:
            return BlackBoxOptimizer._oneEvaluation(self, evaluable)
        else:
            self.switchMutations()
            if isinstance(evaluable, MaskedParameters):
                evaluable.returnZeros = False
                x0 = evaluable.params
                evaluable.returnZeros = True

                def f(x):
                    evaluable._setParameters(x)
                    return BlackBoxOptimizer._oneEvaluation(self, evaluable)
            else:
                f = lambda x: BlackBoxOptimizer._oneEvaluation(self, x)
                x0 = evaluable
            outsourced = self.localSearch(
                f,
                x0,
                maxEvaluations=self.localSteps,
                desiredEvaluation=self.desiredEvaluation,
                minimize=self.minimize,
                **self.localSearchArgs)
            assert self.localSteps > outsourced.batchSize, 'localSteps too small ('+str(self.localSteps)+\
                                                '), because local search has a batch size of '+str(outsourced.batchSize)
            _, fitness = outsourced.learn()
            self.switchMutations()
            return fitness
Ejemplo n.º 3
0
 def f(x): 
     evaluable._setParameters(x)
     return BlackBoxOptimizer._oneEvaluation(self, evaluable)
Ejemplo n.º 4
0
 def f(x):
     evaluable._setParameters(x)
     return BlackBoxOptimizer._oneEvaluation(self, evaluable)