class documentation

class SurrogatePopulation(object):

View In Hierarchy

surrogate f-values for a population.

See also __call__ method.

What is new:

  • the model is built with >=3 evaluations (compared to LS-CMA and lmm-CMA)
  • the model is linear at first, then diagonal, then full
  • the model uses the fitness ranks as weights for weighted regression.
>>> import cma
>>> import cma.fitness_models as fm
>>> from cma.fitness_transformations import Function as FFun  # adds evaluations attribute
>>> # fm.Logger, Logger = fm.LoggerDummy, fm.Logger
>>> surrogate = fm.SurrogatePopulation(cma.ff.elli)

Example using the ask-and-tell interface:

>>> for ifun, fun in enumerate([cma.ff.elli, cma.ff.sectorsphere]):
...     for irun in range(7):
...         assert irun < 4  # measure best of four
...         es = cma.CMAEvolutionStrategy(5 * [1], 2.2,
...                     {'CMA_injections_threshold_keep_len': 1,
...                         'ftarget':1e-9, 'verbose': -9, 'seed':3 + irun})
...         fitfun = FFun(fun)
...         surrogate = fm.SurrogatePopulation(fitfun)
...         while not es.stop():
...             X = es.ask()
...             es.tell(X, surrogate(X))  # surrogate evaluation
...             es.inject([surrogate.model.xopt])
...             # es.disp(); es.logger.add()  # ineffective with verbose=-9
...         # print(irun, fitfun.evaluations)  # was: (sig=2.2) 12 161, 18 131, 18 150, 18 82, 15 59, 15 87, 15 132, 18 83, 18 55, 18 68
...         assert 'ftarget' in es.stop()
...         if ifun == 0:
...             if fitfun.evaluations < 20:
...                 break
...         if ifun == 1:
...             if fitfun.evaluations < 90:
...                 break

Example using the parallel_objective interface to cma.fmin:

>>> for fitfun, evals in [[FFun(cma.ff.elli), 22], [FFun(cma.ff.ellirot), 40]]:
...     surrogate = fm.SurrogatePopulation(fitfun)
...     inject_xopt = fm.ModelInjectionCallback(surrogate.model)  # must use the same model
...     xopt, es = cma.fmin2(None, 5 * [1], 2.2,
...                      {'CMA_injections_threshold_keep_len': 1,
...                       'ftarget':1e-12, 'verbose': -9},
...                      parallel_objective=surrogate,
...                      callback=inject_xopt)
...     # print(fitfun.evaluations)
...     assert fitfun.evaluations == es.result.evaluations
...     assert es.result[1] < 1e-12
...     assert es.result[2] < evals
>>> # fm.Logger = Logger
Class EvaluationManager Manage incremental evaluation of a population of solutions.
Method __call__ return population f-values.
Method __init__ If model is None, a default LQModel instance is used. By setting self.model to None, only the fitness for each population member is evaluated in each call.
Instance Variable count Undocumented
Instance Variable evals multiply with 1.5 and take ceil [1, 2, 3, 5, 8, 12, 18, 27, 41, 62, 93, 140, 210, 315, 473] +[1, 1, 2, 3, 4, 6, 9, 14, 21, 31, 47, 70, 105, 158]
Instance Variable evaluations Undocumented
Instance Variable fitness Undocumented
Instance Variable logger Undocumented
Instance Variable logger_eigenvalues Undocumented
Instance Variable model Undocumented
Instance Variable settings Undocumented
def __call__(self, X):

return population f-values.

Also update the underlying model. Evaluate at least one solution on the true fitness. The smallest returned value is never smaller than the smallest truly evaluated value.

Uses (this may not be a complete list): model.settings.max_absolute_size, model.settings.truncation_ratio, model.size, model.sort, model.eval, model.reset, model.add_data_row, model.kendall, model.adapt_max_relative_size, relies on default value zero for max_absolute_size.

def __init__(self, fitness, model=None, model_max_size_factor=None, tau_truth_threshold=None):

If model is None, a default LQModel instance is used. By setting self.model to None, only the fitness for each population member is evaluated in each call.

count: int =

Undocumented

evals =

multiply with 1.5 and take ceil [1, 2, 3, 5, 8, 12, 18, 27, 41, 62, 93, 140, 210, 315, 473] +[1, 1, 2, 3, 4, 6, 9, 14, 21, 31, 47, 70, 105, 158]

evaluations: float =

Undocumented

fitness =

Undocumented

logger =

Undocumented

logger_eigenvalues =

Undocumented

model =

Undocumented

settings =

Undocumented