예제 #1
0
파일: test_sca.py 프로젝트: tuahk/NiaPy
class BBFWATestCase(TestCase):
    def setUp(self):
        self.D = 40
        self.sca_custom = SineCosineAlgorithm(D=self.D,
                                              nFES=1000,
                                              NP=35,
                                              a=7,
                                              Rmin=0.1,
                                              Rmax=3,
                                              benchmark=MyBenchmark())
        self.sca_griewank = SineCosineAlgorithm(D=self.D,
                                                nFES=1000,
                                                NP=10,
                                                a=5,
                                                Rmin=0.01,
                                                Rmax=3,
                                                benchmark=Griewank())

    def test_custom_works_fine(self):
        fun = MyBenchmark().function()
        x = self.sca_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.sca_griewank.run()
        self.assertTrue(x)
        self.assertAlmostEqual(fun(self.D, x[0]), x[1], delta=1e2)
예제 #2
0
파일: run_sca.py 프로젝트: tuahk/NiaPy
def simple_example(runs=10):
    for i in range(runs):
        algo = SineCosineAlgorithm(D=50,
                                   nFES=1000,
                                   NP=50,
                                   a=7,
                                   Rmin=0.1,
                                   Rmax=3,
                                   benchmark=MyBenchmark())
        best = algo.run()
        logger.info('%s %s' % (best[0], best[1]))
예제 #3
0
 def test_griewank_works_fine(self):
     sca_griewank = SineCosineAlgorithm(NP=10,
                                        a=5,
                                        Rmin=0.01,
                                        Rmax=3,
                                        seed=self.seed)
     sca_griewankc = SineCosineAlgorithm(NP=10,
                                         a=5,
                                         Rmin=0.01,
                                         Rmax=3,
                                         seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, sca_griewank, sca_griewankc)
예제 #4
0
 def test_custom_works_fine(self):
     sca_custom = SineCosineAlgorithm(NP=35,
                                      a=7,
                                      Rmin=0.1,
                                      Rmax=3,
                                      seed=self.seed)
     sca_customc = SineCosineAlgorithm(NP=35,
                                       a=7,
                                       Rmin=0.1,
                                       Rmax=3,
                                       seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, sca_custom, sca_customc,
                                          MyBenchmark())
예제 #5
0
파일: test_sca.py 프로젝트: tuahk/NiaPy
 def setUp(self):
     self.D = 40
     self.sca_custom = SineCosineAlgorithm(D=self.D,
                                           nFES=1000,
                                           NP=35,
                                           a=7,
                                           Rmin=0.1,
                                           Rmax=3,
                                           benchmark=MyBenchmark())
     self.sca_griewank = SineCosineAlgorithm(D=self.D,
                                             nFES=1000,
                                             NP=10,
                                             a=5,
                                             Rmin=0.01,
                                             Rmax=3,
                                             benchmark=Griewank())
예제 #6
0
 def test_custom_works_fine(self):
     sca_custom = SineCosineAlgorithm(D=self.D,
                                      nFES=self.nFES,
                                      nGEN=self.nGEN,
                                      NP=35,
                                      a=7,
                                      Rmin=0.1,
                                      Rmax=3,
                                      benchmark=MyBenchmark(),
                                      seed=self.seed)
     sca_customc = SineCosineAlgorithm(D=self.D,
                                       nFES=self.nFES,
                                       nGEN=self.nGEN,
                                       NP=35,
                                       a=7,
                                       Rmin=0.1,
                                       Rmax=3,
                                       benchmark=MyBenchmark(),
                                       seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, sca_custom, sca_customc)
예제 #7
0
 def test_griewank_works_fine(self):
     sca_griewank = SineCosineAlgorithm(D=self.D,
                                        nFES=self.nFES,
                                        nGEN=self.nGEN,
                                        NP=10,
                                        a=5,
                                        Rmin=0.01,
                                        Rmax=3,
                                        benchmark=Griewank(),
                                        seed=self.seed)
     sca_griewankc = SineCosineAlgorithm(D=self.D,
                                         nFES=self.nFES,
                                         nGEN=self.nGEN,
                                         NP=10,
                                         a=5,
                                         Rmin=0.01,
                                         Rmax=3,
                                         benchmark=Griewank(),
                                         seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, sca_griewank, sca_griewankc)
예제 #8
0
파일: run_sca.py 프로젝트: zyumons/NiaPy
# 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 SineCosineAlgorithm
from NiaPy.task import StoppingTask
from NiaPy.benchmarks import Sphere

# we will run Sine Cosine Algorithm algorithm for 5 independent runs
for i in range(5):
	task = StoppingTask(D=10, nFES=10000, benchmark=Sphere())
	algo = SineCosineAlgorithm(NP=30, a=7, Rmin=0.1, Rmax=3)
	best = algo.run(task=task)
	print(best)

# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3
예제 #9
0
파일: run_sca.py 프로젝트: tuahk/NiaPy
def plot_example():
    task = TaskConvPlot(D=50, nFES=50000, nGEN=10000, benchmark=MyBenchmark())
    algo = SineCosineAlgorithm(NP=35, a=7, Rmin=0.1, Rmax=3, task=task)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
    input('Press [enter] to continue')
예제 #10
0
파일: run_sca.py 프로젝트: tuahk/NiaPy
def logging_example():
    task = TaskConvPrint(D=50, nFES=50000, nGEN=10000, benchmark=MyBenchmark())
    algo = SineCosineAlgorithm(NP=35, a=3, Rmin=0.1, Rmax=1.1, task=task)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
예제 #11
0
 def test_algorithm_info_fine(self):
     self.assertIsNotNone(SineCosineAlgorithm.algorithmInfo())
예제 #12
0
 def test_type_parameters(self):
     d = SineCosineAlgorithm.typeParameters()
     self.assertIsNotNone(d.get('NP', None))
     self.assertIsNotNone(d.get('a', None))
     self.assertIsNotNone(d.get('Rmin', None))
     self.assertIsNotNone(d.get('Rmax', None))