Beispiel #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)
Beispiel #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]))
Beispiel #3
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')
Beispiel #4
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]))
Beispiel #5
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
Beispiel #6
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