Esempio n. 1
0
def plot_example(D=10, nFES=50000):
    task = TaskConvPlot(D=D, nFES=nFES, nGEN=50000, benchmark=MyBenchmark())
    algo = HarmonySearch(HMS=50,
                         r_accept=0.7,
                         r_pa=0.2,
                         b_range=1.1,
                         task=task)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
    input('Press [enter] to continue')
Esempio n. 2
0
def logging_example(D=10, nFES=50000):
    task = TaskConvPrint(D=D, nFES=nFES, nGEN=50000, benchmark=MyBenchmark())
    algo = HarmonySearch(HMS=50,
                         r_accept=0.7,
                         r_pa=0.2,
                         b_range=1.1,
                         seed=None,
                         task=task)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
Esempio n. 3
0
def simple_example(runs=10, D=10, nFES=50000):
    for i in range(runs):
        algo = HarmonySearch(D=D,
                             nFES=nFES,
                             HMS=50,
                             r_accept=0.7,
                             r_pa=0.2,
                             b_range=1.1,
                             benchmark=MyBenchmark())
        best = algo.run()
        logger.info('%s %s' % (best[0], best[1]))
Esempio n. 4
0
class HSTestCase(TestCase):
    def setUp(self):
        self.D = 40
        self.hs_custom = HarmonySearch(D=self.D,
                                       nFES=1000,
                                       benchmark=MyBenchmark())
        self.hs_griewank = HarmonySearch(D=self.D,
                                         nFES=1000,
                                         benchmark=Griewank())

    def test_custom_works_fine(self):
        fun = MyBenchmark().function()
        x = self.hs_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.hs_griewank.run()
        self.assertTrue(x)
        self.assertAlmostEqual(fun(self.D, x[0]), x[1], delta=1e2)
Esempio n. 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

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

#we will run Harmony Search for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10,
                        nFES=10000,
                        optType=OptimizationType.MINIMIZATION,
                        benchmark=Sphere())
    algo = HarmonySearch()
    best = algo.run(task=task)
    print(best)