Exemplo n.º 1
0
class BBFWATestCase(TestCase):
    def setUp(self):
        self.D = 40
        self.bbfa_custom = BareBonesFireworksAlgorithm(D=self.D,
                                                       nFES=1000,
                                                       n=10,
                                                       C_a=2,
                                                       C_r=0.5,
                                                       benchmark=MyBenchmark())
        self.bbfa_griewank = BareBonesFireworksAlgorithm(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.bbfa_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.bbfa_griewank.run()
        self.assertTrue(x)
        self.assertAlmostEqual(fun(self.D, x[0]), x[1], delta=1e2)
Exemplo n.º 2
0
def simple_example(runs=10, D=10, nFES=50000):
    for i in range(runs):
        algo = BareBonesFireworksAlgorithm(D=D,
                                           nFES=nFES,
                                           n=15,
                                           C_a=1,
                                           C_r=0.5,
                                           benchmark=MyBenchmark())
        best = algo.run()
        logger.info('%s %s' % (best[0], best[1]))
Exemplo n.º 3
0
 def setUp(self):
     self.D = 40
     self.bbfwa_custom = BareBonesFireworksAlgorithm(
         D=self.D, nFES=1000, n=10, C_a=2, C_r=0.5, benchmark=MyBenchmark())
     self.bbfwa_griewank = BareBonesFireworksAlgorithm(D=self.D,
                                                       nFES=1000,
                                                       n=10,
                                                       C_a=5,
                                                       C_r=0.5,
                                                       benchmark=Griewank())
Exemplo n.º 4
0
 def test_custom_works_fine(self):
     bbfwa_custom = BareBonesFireworksAlgorithm(n=10,
                                                C_a=2,
                                                C_r=0.5,
                                                seed=self.seed)
     bbfwa_customc = BareBonesFireworksAlgorithm(n=10,
                                                 C_a=2,
                                                 C_r=0.5,
                                                 seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, bbfwa_custom, bbfwa_customc,
                                          MyBenchmark())
Exemplo n.º 5
0
 def test_griewank_works_fine(self):
     bbfwa_griewank = BareBonesFireworksAlgorithm(n=10,
                                                  C_a=5,
                                                  C_r=0.5,
                                                  seed=self.seed)
     bbfwa_griewankc = BareBonesFireworksAlgorithm(n=10,
                                                   C_a=5,
                                                   C_r=0.5,
                                                   seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, bbfwa_griewank,
                                          bbfwa_griewankc)
Exemplo n.º 6
0
 def test_custom_works_fine(self):
     bbfwa_custom = BareBonesFireworksAlgorithm(D=self.D,
                                                nFES=self.nFES,
                                                nGEN=self.nGEN,
                                                n=10,
                                                C_a=2,
                                                C_r=0.5,
                                                benchmark=MyBenchmark(),
                                                seed=self.seed)
     bbfwa_customc = BareBonesFireworksAlgorithm(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, bbfwa_custom, bbfwa_customc)
Exemplo n.º 7
0
 def test_griewank_works_fine(self):
     bbfwa_griewank = BareBonesFireworksAlgorithm(D=self.D,
                                                  nFES=self.nFES,
                                                  nGEN=self.nGEN,
                                                  n=10,
                                                  C_a=5,
                                                  C_r=0.5,
                                                  benchmark=Griewank(),
                                                  seed=self.seed)
     bbfwa_griewankc = BareBonesFireworksAlgorithm(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, bbfwa_griewank,
                                          bbfwa_griewankc)
Exemplo n.º 8
0
def plot_example(D=100, nFES=50000):
    task = TaskConvPlot(D=D, nFES=nFES, nGEN=10000, benchmark=MyBenchmark())
    algo = BareBonesFireworksAlgorithm(task=task, n=15, C_a=1, C_r=0.5)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
    input('Press [enter] to continue')
Exemplo n.º 9
0
def logging_example(D=100, nFES=50000):
    task = TaskConvPrint(D=D, nFES=nFES, nGEN=10000, benchmark=MyBenchmark())
    algo = BareBonesFireworksAlgorithm(task=task, n=15, C_a=1, C_r=0.5)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
Exemplo 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

from NiaPy.algorithms.basic import BareBonesFireworksAlgorithm
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=1000,
                        optType=OptimizationType.MINIMIZATION,
                        benchmark=Sphere())
    algo = BareBonesFireworksAlgorithm()
    best = algo.run(task=task)
    print('%s -> %s' % (best[0], best[1]))

# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3
Exemplo n.º 11
0
    def __init__(self):
        self.Lower = -11
        self.Upper = 11

    def function(self):
        def evaluate(D, sol):
            val = 0.0
            for i in range(D):
                val += sol[i]**2
            return val

        return evaluate


for i in range(10):
    algo = BareBonesFireworksAlgorithm(D=50,
                                       nFES=50000,
                                       n=15,
                                       C_a=1,
                                       C_r=0.5,
                                       benchmark=MyBenchmark())
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
    # dodatek
    # import numpy as np
    # logger.info('%s' % (MyBenchmark().function()(50, best[0])))
    # print (best[2])
    # logger.info('%s' % np.apply_along_axis(lambda x: np.sum(x ** 2), 1, best[2]))

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