예제 #1
0
 def test_griewank_works_fine(self):
     fwa_griewank = FireworksAlgorithm(n=10, C_a=5, C_r=0.5, seed=self.seed)
     fwa_griewankc = FireworksAlgorithm(n=10,
                                        C_a=5,
                                        C_r=0.5,
                                        seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, fwa_griewank, fwa_griewankc)
예제 #2
0
파일: test_fwa.py 프로젝트: tuahk/NiaPy
class FWATestCase(TestCase):
    def setUp(self):
        self.D = 40
        self.fwa_custom = FireworksAlgorithm(D=self.D,
                                             nFES=1000,
                                             n=10,
                                             C_a=2,
                                             C_r=0.5,
                                             benchmark=MyBenchmark())
        self.fwa_griewank = FireworksAlgorithm(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.fwa_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.fwa_griewank.run()
        self.assertTrue(x)
        self.assertAlmostEqual(fun(self.D, x[0]), x[1], delta=1e2)
예제 #3
0
파일: test_fwa.py 프로젝트: tuahk/NiaPy
 def setUp(self):
     self.D = 40
     self.fwa_custom = FireworksAlgorithm(D=self.D,
                                          nFES=1000,
                                          n=10,
                                          C_a=2,
                                          C_r=0.5,
                                          benchmark=MyBenchmark())
     self.fwa_griewank = FireworksAlgorithm(D=self.D,
                                            nFES=1000,
                                            n=10,
                                            C_a=5,
                                            C_r=0.5,
                                            benchmark=Griewank())
예제 #4
0
파일: run_fwa.py 프로젝트: tuahk/NiaPy
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 = FireworksAlgorithm(seed=seed, task=task)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
예제 #5
0
파일: run_fwa.py 프로젝트: tuahk/NiaPy
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 = FireworksAlgorithm(D=D,
                                  nFES=nFES,
                                  optType=optType,
                                  seed=seed,
                                  benchmark=optFunc())
        best = algo.run()
        logger.info('%s %s' % (best[0], best[1]))
예제 #6
0
 def test_griewank_works_fine(self):
     fwa_griewank = FireworksAlgorithm(D=self.D,
                                       nFES=self.nFES,
                                       nGEN=self.nGEN,
                                       n=10,
                                       C_a=5,
                                       C_r=0.5,
                                       benchmark=Griewank(),
                                       seed=self.seed)
     fwa_griewankc = FireworksAlgorithm(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, fwa_griewank, fwa_griewankc)
예제 #7
0
 def test_custom_works_fine(self):
     fwa_custom = FireworksAlgorithm(D=self.D,
                                     nFES=self.nFES,
                                     nGEN=self.nGEN,
                                     n=10,
                                     C_a=2,
                                     C_r=0.5,
                                     benchmark=MyBenchmark(),
                                     seed=self.seed)
     fwa_customc = FireworksAlgorithm(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, fwa_custom, fwa_customc)
예제 #8
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

from NiaPy.algorithms.basic import FireworksAlgorithm
from NiaPy.util import StoppingTask, OptimizationType
from NiaPy.benchmarks import Sphere

# we will run Fireworks Algorithm for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10,
                        nFES=10000,
                        optType=OptimizationType.MINIMIZATION,
                        benchmark=Sphere())
    algo = FireworksAlgorithm(N=40)
    best = algo.run(task=task)
    print(best)
예제 #9
0
 def test_custom_works_fine(self):
     fwa_custom = FireworksAlgorithm(n=10, C_a=2, C_r=0.5, seed=self.seed)
     fwa_customc = FireworksAlgorithm(n=10, C_a=2, C_r=0.5, seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, fwa_custom, fwa_customc,
                                          MyBenchmark())