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 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 #3
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 #4
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 #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 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