Example #1
0
class DFWATestCase(TestCase):
    def setUp(self):
        self.D = 40
        self.dfwa_custom = DynamicFireworksAlgorithm(D=self.D,
                                                     nFES=1000,
                                                     n=10,
                                                     C_a=2,
                                                     C_r=0.5,
                                                     benchmark=MyBenchmark())
        self.dfwa_griewank = DynamicFireworksAlgorithm(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.dfwa_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.dfwa_griewank.run()
        self.assertTrue(x)
        self.assertAlmostEqual(fun(self.D, x[0]), x[1], delta=1e2)
Example #2
0
 def test_griewank_works_fine(self):
     fwa_griewank = DynamicFireworksAlgorithm(n=10,
                                              C_a=5,
                                              C_r=0.5,
                                              seed=self.seed)
     fwa_griewankc = DynamicFireworksAlgorithm(n=10,
                                               C_a=5,
                                               C_r=0.5,
                                               seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, fwa_griewank, fwa_griewankc)
Example #3
0
 def test_custom_works_fine(self):
     fwa_custom = DynamicFireworksAlgorithm(n=10,
                                            C_a=2,
                                            C_r=0.5,
                                            seed=self.seed)
     fwa_customc = DynamicFireworksAlgorithm(n=10,
                                             C_a=2,
                                             C_r=0.5,
                                             seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, fwa_custom, fwa_customc,
                                          MyBenchmark())
Example #4
0
 def setUp(self):
     self.D = 40
     self.dfwa_custom = DynamicFireworksAlgorithm(D=self.D,
                                                  nFES=1000,
                                                  n=10,
                                                  C_a=2,
                                                  C_r=0.5,
                                                  benchmark=MyBenchmark())
     self.dfwa_griewank = DynamicFireworksAlgorithm(D=self.D,
                                                    nFES=1000,
                                                    n=10,
                                                    C_a=5,
                                                    C_r=0.5,
                                                    benchmark=Griewank())
Example #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 = DynamicFireworksAlgorithm(seed=None, task=task)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
Example #6
0
def plot_example(D=10,
                 nFES=50000,
                 nGEN=100000,
                 seed=None,
                 optType=OptimizationType.MINIMIZATION,
                 optFunc=MinMB,
                 **kn):
    task = TaskConvPlot(D=D,
                        nFES=nFES,
                        nGEN=nGEN,
                        optType=optType,
                        benchmark=optFunc())
    algo = DynamicFireworksAlgorithm(seed=seed, task=task)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
    input('Press [enter] to continue')
Example #7
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 = DynamicFireworksAlgorithm(D=D,
                                         nFES=nFES,
                                         optType=optType,
                                         seed=seed,
                                         benchmark=optFunc())
        best = algo.run()
        logger.info('%s %s' % (best[0], best[1]))
Example #8
0
 def test_griewank_works_fine(self):
     fwa_griewank = DynamicFireworksAlgorithm(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 = DynamicFireworksAlgorithm(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)
Example #9
0
 def test_custom_works_fine(self):
     fwa_custom = DynamicFireworksAlgorithm(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 = DynamicFireworksAlgorithm(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)
Example #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

from NiaPy.algorithms.basic import DynamicFireworksAlgorithm
from NiaPy.util import StoppingTask
from NiaPy.task.task import OptimizationType
from NiaPy.benchmarks import Sphere

# we will run Fireworks Algorithm for 5 independent runs
for i in range(5):
	task = StoppingTask(D=10, nGEN=80, optType=OptimizationType.MINIMIZATION, benchmark=Sphere())
	algo = DynamicFireworksAlgorithm(N=70, Ainit=0.1, Afinal=0.9)
	best = algo.run(task=task)
	print('%s -> %s' % (best[0], best[1]))

# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3
Example #11
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.task import StoppingTask
from NiaPy.benchmarks import Sphere
from NiaPy.algorithms.basic import DynamicFireworksAlgorithm

# we will run Fireworks Algorithm for 5 independent runs
algo = DynamicFireworksAlgorithm(N=70, Ainit=0.1, Afinal=0.9)
for i in range(5):
    task = StoppingTask(D=10, nGEN=80, benchmark=Sphere())
    best = algo.run(task)
    print('%s -> %s' % (best[0], best[1]))
print(algo.getParameters())

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