Exemple #1
0
class NMMTestCase(TestCase):
    def setUp(self):
        self.D = 40
        self.nmm_custom = NelderMeadMethod(D=self.D,
                                           nFES=1000,
                                           n=10,
                                           C_a=2,
                                           C_r=0.5,
                                           benchmark=MyBenchmark())
        self.nmm_griewank = NelderMeadMethod(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.nmm_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.nmm_griewank.run()
        self.assertTrue(x)
        self.assertAlmostEqual(fun(self.D, x[0]), x[1], delta=1e2)
Exemple #2
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.other import NelderMeadMethod
from NiaPy.util import StoppingTask, OptimizationType
from NiaPy.benchmarks import Sphere

# we will run Nelder Mead algorithm for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10,
                        nGEN=10000,
                        optType=OptimizationType.MINIMIZATION,
                        benchmark=Sphere())
    algo = NelderMeadMethod(NP=70, alpha=0.2, gamma=0.1, rho=-0.24, sigma=-0.1)
    best = algo.run(task=task)
    print('%s -> %s' % (best[0], best[1]))
Exemple #3
0
def logging_example(D=100, nFES=50000):
	task = TaskConvPrint(D=D, nFES=nFES, nGEN=10000, benchmark=MyBenchmark())
	algo = NelderMeadMethod(task=task, n=15, C_a=1, C_r=0.5)
	best = algo.run()
	logger.info('%s %s' % (best[0], best[1]))
Exemple #4
0
def plot_example(D=100, nFES=50000):
	task = TaskConvPlot(D=D, nFES=nFES, nGEN=10000, benchmark=MyBenchmark())
	algo = NelderMeadMethod(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')
Exemple #5
0
def simple_example(runs=10, D=10, nFES=50000):
	for i in range(runs):
		algo = NelderMeadMethod(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]))