Beispiel #1
0
class ESMpLTestCase(TestCase):
	def setUp(self):
		self.D = 40
		self.es_custom = EvolutionStrategyMpL(D=self.D, nFES=1000, mu=45, lam=55, k=50, c_a=1.1, c_r=0.5, benchmark=MyBenchmark())
		self.es1_custom = EvolutionStrategyMpL(D=self.D, nFES=1000, mu=55, lam=45, k=50, c_a=1.1, c_r=0.5, benchmark=MyBenchmark())
		self.es_griewank = EvolutionStrategyMpL(D=self.D, nFES=1000, mu=30, lam=50, k=25, c_a=1.5, c_r=0.5, benchmark=Griewank())
		self.es1_griewank = EvolutionStrategyMpL(D=self.D, nFES=1000, mu=50, lam=30, k=25, c_a=1.5, c_r=0.5, benchmark=Griewank())

	def test_custom_works_fine(self):
		fun = MyBenchmark().function()
		x = self.es_custom.run()
		self.assertTrue(x)
		self.assertAlmostEqual(fun(self.D, x[0]), x[1], delta=1e2)

	def test_custom1_works_fine(self):
		fun = MyBenchmark().function()
		x = self.es1_custom.run()
		self.assertTrue(x)
		self.assertAlmostEqual(fun(self.D, x[0]), x[1], delta=1e2)

	def test_griewank_works_fine(self):
		fun = Griewank().function()
		x = self.es_griewank.run()
		self.assertTrue(x)
		self.assertAlmostEqual(fun(self.D, x[0]), x[1], delta=1e2)

	def test_griewank1_works_fine(self):
		fun = Griewank().function()
		x = self.es1_griewank.run()
		self.assertTrue(x)
		self.assertAlmostEqual(fun(self.D, x[0]), x[1], delta=1e2)
Beispiel #2
0
def simple_example(runs=10):
    for i in range(runs):
        algo = EvolutionStrategyMpL(D=50,
                                    nFES=50000,
                                    seed=None,
                                    benchmark=MyBenchmark())
        best = algo.run()
        logger.info('%s %s' % (best[0], best[1]))
Beispiel #3
0
def plot_example():
    task = TaskConvPlot(D=50, nFES=50000, nGEN=10000, benchmark=MyBenchmark())
    algo = EvolutionStrategyMpL(mu=65,
                                lam=50,
                                k=25,
                                c_a=1.5,
                                c_r=0.25,
                                seed=None,
                                task=task)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
    input('Press [enter] to continue')
Beispiel #4
0
def logging_example():
    task = TaskConvPrint(D=10, nFES=50000, nGEN=50000, benchmark=MyBenchmark())
    algo = EvolutionStrategyMpL(mu=50,
                                lam=40,
                                k=60,
                                c_a=1.5,
                                c_r=0.25,
                                seed=None,
                                task=task)
    best = algo.run()
    logger.info('nFES:%s nGEN:%s\n%s %s' %
                (task.Evals, task.Iters, best[0], best[1]))
Beispiel #5
0
 def test_griewank_works_fine(self):
     es_griewank = EvolutionStrategyMpL(mu=30,
                                        lam=50,
                                        k=25,
                                        c_a=1.5,
                                        c_r=0.5,
                                        seed=self.seed)
     es_griewankc = EvolutionStrategyMpL(mu=30,
                                         lam=50,
                                         k=25,
                                         c_a=1.5,
                                         c_r=0.5,
                                         seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, es_griewank, es_griewankc)
Beispiel #6
0
 def test_custom_works_fine(self):
     es_custom = EvolutionStrategyMpL(mu=45,
                                      lam=55,
                                      k=50,
                                      c_a=1.1,
                                      c_r=0.5,
                                      seed=self.seed)
     es_customc = EvolutionStrategyMpL(mu=45,
                                       lam=55,
                                       k=50,
                                       c_a=1.1,
                                       c_r=0.5,
                                       seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, es_custom, es_customc,
                                          MyBenchmark())
Beispiel #7
0
 def test_griewank1_works_fine(self):
     es1_griewank = EvolutionStrategyMpL(D=self.D,
                                         nFES=self.nFES,
                                         nGEN=self.nGEN,
                                         mu=50,
                                         lam=30,
                                         k=25,
                                         c_a=1.5,
                                         c_r=0.5,
                                         benchmark=Griewank(),
                                         seed=self.seed)
     es1_griewankc = EvolutionStrategyMpL(D=self.D,
                                          nFES=self.nFES,
                                          nGEN=self.nGEN,
                                          mu=50,
                                          lam=30,
                                          k=25,
                                          c_a=1.5,
                                          c_r=0.5,
                                          benchmark=Griewank(),
                                          seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, es1_griewank, es1_griewankc)
Beispiel #8
0
 def test_custom1_works_fine(self):
     es1_custom = EvolutionStrategyMpL(D=self.D,
                                       nFES=self.nFES,
                                       nGEN=self.nGEN,
                                       mu=55,
                                       lam=45,
                                       k=50,
                                       c_a=1.1,
                                       c_r=0.5,
                                       benchmark=MyBenchmark(),
                                       seed=self.seed)
     es1_customc = EvolutionStrategyMpL(D=self.D,
                                        nFES=self.nFES,
                                        nGEN=self.nGEN,
                                        mu=55,
                                        lam=45,
                                        k=50,
                                        c_a=1.1,
                                        c_r=0.5,
                                        benchmark=MyBenchmark(),
                                        seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, es1_custom, es1_customc)
Beispiel #9
0
## encoding=utf8
# This is temporary fix to import module from parent folder
# It will be removed when package is published on PyPI
import sys
sys.path.append('../')
# End of fix

import random
from NiaPy.algorithms.basic import EvolutionStrategyMpL
from NiaPy.task.task import StoppingTask, OptimizationType
from NiaPy.benchmarks import Sphere

#we will run Differential Evolution for 5 independent runs
for i in range(5):
	task = StoppingTask(D=10, nFES=1000, optType=OptimizationType.MINIMIZATION, benchmark=Sphere())
	algo = EvolutionStrategyMpL()
	best = algo.run(task=task)
	print('%s -> %f' % (best[0].x, best[1]))

# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3
Beispiel #10
0
	def setUp(self):
		self.D = 40
		self.es_custom = EvolutionStrategyMpL(D=self.D, nFES=1000, mu=45, lam=55, k=50, c_a=1.1, c_r=0.5, benchmark=MyBenchmark())
		self.es1_custom = EvolutionStrategyMpL(D=self.D, nFES=1000, mu=55, lam=45, k=50, c_a=1.1, c_r=0.5, benchmark=MyBenchmark())
		self.es_griewank = EvolutionStrategyMpL(D=self.D, nFES=1000, mu=30, lam=50, k=25, c_a=1.5, c_r=0.5, benchmark=Griewank())
		self.es1_griewank = EvolutionStrategyMpL(D=self.D, nFES=1000, mu=50, lam=30, k=25, c_a=1.5, c_r=0.5, benchmark=Griewank())