示例#1
0
# encoding=utf8
# This is temporary fix to import module from parent folder
# It will be removed when package is published on PyPI
from NiaPy.algorithms.basic import CovarianceMatrixAdaptionEvolutionStrategy
from NiaPy.task import StoppingTask, OptimizationType
from NiaPy.benchmarks import Sphere

import sys
sys.path.append('../')
# End of fix

# we will run CMA-ES for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10, nFES=1000, optType=OptimizationType.MINIMIZATION, logger=True, benchmark=Sphere())
    algo = CovarianceMatrixAdaptionEvolutionStrategy(NP=20)
    best = algo.run(task=task)
    print('%s -> %s' % (best[0], best[1]))

示例#2
0
 def test_custom1_works_fine(self):
     es1_custom = CovarianceMatrixAdaptionEvolutionStrategy(seed=self.seed)
     es1_customc = CovarianceMatrixAdaptionEvolutionStrategy(seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, es1_custom, es1_customc,
                                          MyBenchmark())
示例#3
0
 def test_griewank1_works_fine(self):
     es1_griewank = CovarianceMatrixAdaptionEvolutionStrategy(
         seed=self.seed)
     es1_griewankc = CovarianceMatrixAdaptionEvolutionStrategy(
         seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, es1_griewank, es1_griewankc)
示例#4
0
 def test_typeParametes(self):
     d = CovarianceMatrixAdaptionEvolutionStrategy.typeParameters()
     self.assertTrue(d['epsilon'](0.234))
     self.assertFalse(d['epsilon'](-0.234))
     self.assertFalse(d['epsilon'](10000.234))
     self.assertFalse(d['epsilon'](10))