Ejemplo n.º 1
0
class MTSTestCase(TestCase):
    def setUp(self):
        self.D = 40
        self.mts_custom = MultipleTrajectorySearch(D=self.D,
                                                   nFES=1000,
                                                   n=10,
                                                   C_a=2,
                                                   C_r=0.5,
                                                   benchmark=MyBenchmark())
        self.mts_griewank = MultipleTrajectorySearch(D=self.D,
                                                     nFES=1000,
                                                     n=10,
                                                     C_a=5,
                                                     C_r=0.5,
                                                     benchmark=Griewank())

    def test_custom_works_fine(self):
        fun = MyBenchmark().function()
        x = self.mts_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.mts_griewank.run()
        self.assertTrue(x)
        self.assertAlmostEqual(fun(self.D, x[0]), x[1], delta=1e2)
Ejemplo n.º 2
0
 def test_griewank_works_fine(self):
     mts_griewank = MultipleTrajectorySearch(n=10,
                                             C_a=5,
                                             C_r=0.5,
                                             seed=self.seed)
     mts_griewankc = MultipleTrajectorySearch(n=10,
                                              C_a=5,
                                              C_r=0.5,
                                              seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, mts_griewank, mts_griewankc)
Ejemplo n.º 3
0
 def test_custom_works_fine(self):
     mts_custom = MultipleTrajectorySearch(n=10,
                                           C_a=2,
                                           C_r=0.5,
                                           seed=self.seed)
     mts_customc = MultipleTrajectorySearch(n=10,
                                            C_a=2,
                                            C_r=0.5,
                                            seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, mts_custom, mts_customc,
                                          MyBenchmark())
Ejemplo n.º 4
0
 def setUp(self):
     self.D = 40
     self.mts_custom = MultipleTrajectorySearch(D=self.D,
                                                nFES=1000,
                                                n=10,
                                                C_a=2,
                                                C_r=0.5,
                                                benchmark=MyBenchmark())
     self.mts_griewank = MultipleTrajectorySearch(D=self.D,
                                                  nFES=1000,
                                                  n=10,
                                                  C_a=5,
                                                  C_r=0.5,
                                                  benchmark=Griewank())
Ejemplo n.º 5
0
def logging_example(D=10,
                    nFES=50000,
                    nGEN=100000,
                    seed=None,
                    optType=OptimizationType.MINIMIZATION,
                    optFunc=MinMB,
                    **kn):
    task = TaskConvPrint(D=D,
                         nFES=nFES,
                         nGEN=nGEN,
                         optType=optType,
                         benchmark=optFunc())
    algo = MultipleTrajectorySearch(task=task, n=15, C_a=1, C_r=0.5)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
Ejemplo n.º 6
0
 def test_griewank_works_fine(self):
     mts_griewank = MultipleTrajectorySearch(D=self.D,
                                             nFES=self.nFES,
                                             nGEN=self.nGEN,
                                             n=10,
                                             C_a=5,
                                             C_r=0.5,
                                             benchmark=Griewank(),
                                             seed=self.seed)
     mts_griewankc = MultipleTrajectorySearch(D=self.D,
                                              nFES=self.nFES,
                                              nGEN=self.nGEN,
                                              n=10,
                                              C_a=5,
                                              C_r=0.5,
                                              benchmark=Griewank(),
                                              seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, mts_griewank, mts_griewankc)
Ejemplo n.º 7
0
 def test_custom_works_fine(self):
     mts_custom = MultipleTrajectorySearch(D=self.D,
                                           nFES=self.nFES,
                                           nGEN=self.nGEN,
                                           n=10,
                                           C_a=2,
                                           C_r=0.5,
                                           benchmark=MyBenchmark(),
                                           seed=self.seed)
     mts_customc = MultipleTrajectorySearch(D=self.D,
                                            nFES=self.nFES,
                                            nGEN=self.nGEN,
                                            n=10,
                                            C_a=2,
                                            C_r=0.5,
                                            benchmark=MyBenchmark(),
                                            seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, mts_custom, mts_customc)
Ejemplo n.º 8
0
def simple_example(runs=10,
                   D=10,
                   nFES=50000,
                   nGEN=10000,
                   seed=None,
                   optType=OptimizationType.MINIMIZATION,
                   optFunc=MinMB,
                   **kn):
    for i in range(runs):
        algo = MultipleTrajectorySearch(D=D,
                                        nFES=nFES,
                                        nGEN=nGEN,
                                        n=15,
                                        C_a=1,
                                        C_r=0.5,
                                        optType=optType,
                                        benchmark=optFunc())
        best = algo.run()
        logger.info('%s %s' % (best[0], best[1]))
Ejemplo n.º 9
0
 def test_type_parameters(self):
     d = MultipleTrajectorySearch.typeParameters()
     self.assertTrue(d['NoLsTests'](10))
     self.assertTrue(d['NoLsTests'](0))
     self.assertFalse(d['NoLsTests'](-10))
     self.assertTrue(d['NoLs'](10))
     self.assertTrue(d['NoLs'](0))
     self.assertFalse(d['NoLs'](-10))
     self.assertTrue(d['NoLsBest'](10))
     self.assertTrue(d['NoLsBest'](0))
     self.assertFalse(d['NoLsBest'](-10))
     self.assertTrue(d['NoEnabled'](10))
     self.assertFalse(d['NoEnabled'](0))
     self.assertFalse(d['NoEnabled'](-10))
Ejemplo n.º 10
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.other import MultipleTrajectorySearch
from NiaPy.task.task import StoppingTask, OptimizationType
from NiaPy.benchmarks import Sphere

# we will run Nelder Mead algorithm for 5 independent runs
for i in range(5):
	task = StoppingTask(D=10, nGEN=40, optType=OptimizationType.MINIMIZATION, benchmark=Sphere())
	algo = MultipleTrajectorySearch()
	best = algo.run(task=task)
	print('%s -> %s' % (best[0], best[1]))

# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3