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
 def test_michalewichz_works_fine(self):
     nmm_griewank = NelderMeadMethod(n=10, C_a=5, C_r=0.5, seed=self.seed)
     nmm_griewankc = NelderMeadMethod(n=10, C_a=5, C_r=0.5, seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self,
                                          nmm_griewank,
                                          nmm_griewankc,
                                          'michalewicz',
                                          nGEN=10000000)
Exemple #3
0
 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())
Exemple #4
0
 def test_type_parameters(self):
     d = NelderMeadMethod.typeParameters()
     self.assertIsNotNone(d.get('NP', None))
     self.assertIsNotNone(d.get('alpha', None))
     self.assertIsNotNone(d.get('gamma', None))
     self.assertIsNotNone(d.get('rho', None))
     self.assertIsNotNone(d.get('sigma', None))
Exemple #5
0
 def test_custom_works_fine(self):
     nmm_custom = NelderMeadMethod(D=self.D,
                                   nFES=self.nFES,
                                   nGEN=self.nGEN,
                                   n=10,
                                   C_a=2,
                                   C_r=0.5,
                                   benchmark=MyBenchmark(),
                                   seed=self.seed)
     nmm_customc = NelderMeadMethod(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, nmm_custom, nmm_customc)
Exemple #6
0
 def test_griewank_works_fine(self):
     nmm_griewank = NelderMeadMethod(D=self.D,
                                     nFES=self.nFES,
                                     nGEN=self.nGEN,
                                     n=10,
                                     C_a=5,
                                     C_r=0.5,
                                     benchmark=Griewank(),
                                     seed=self.seed)
     nmm_griewankc = NelderMeadMethod(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, nmm_griewank, nmm_griewankc)
Exemple #7
0
    def __init__(self, algorithm_name, objective, maxfeval, population=30):
        super().__init__(algorithm_name, objective, maxfeval)
        self.algorithm_name = algorithm_name
        self.algo = None  #this is the suggest function from hyperopt
        if algorithm_name not in __all__:
            raise Exception('NiaPy does not have algorithm :' +
                            str(algorithm_name))

        elif self.algorithm_name == 'NiaPyABC':
            self.algo = ArtificialBeeColonyAlgorithm(NP=population, Limit=100)

        elif self.algorithm_name == 'NiaPyBat':
            self.algo = BatAlgorithm(NP=population)

        elif self.algorithm_name == 'NiaPyCuckooSearch':
            self.algo = CuckooSearch(N=population, pa=0.2, alpha=0.5)

        elif self.algorithm_name == 'NiaPyDifferentialEvolution':
            self.algo = DifferentialEvolution(NP=population, F=1, CR=0.8)

        elif self.algorithm_name == 'NiaPyFireflyAlgorithm':
            self.algo = FireflyAlgorithm(NP=population,
                                         alpha=0.5,
                                         betamin=0.2,
                                         gamma=1.0)

        elif self.algorithm_name == 'NiaPyGeneticAlgorithm':
            self.algo = FireflyAlgorithm(NP=population,
                                         Crossover=UniformCrossover,
                                         Mutation=UniformMutation,
                                         Cr=0.45,
                                         Mr=0.9)

        elif self.algorithm_name == 'NiaPyGWO':
            self.algo = GreyWolfOptimizer(NP=population)
        # config
        elif self.algorithm_name == 'NiaPyNelderMead':
            self.algo = NelderMeadMethod()
        # config
        elif self.algorithm_name == 'NiaPyPSO':
            self.algo = ParticleSwarmAlgorithm(NP=population,
                                               C1=2,
                                               C2=2,
                                               w=0.9,
                                               vMin=-1.5,
                                               vMax=1.5)

        # config

        # config
        # config
        elif self.algorithm_name == 'NiaPySimulatedAnnealing':
            self.algo = SimulatedAnnealing(coolingMethod=coolLinear)
Exemple #8
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 #9
0
 def test_algorithm_info(self):
     self.assertIsNotNone(NelderMeadMethod.algorithmInfo())
Exemple #10
0
 def test_custom_works_fine(self):
     nmm_custom = NelderMeadMethod(n=10, C_a=2, C_r=0.5, seed=self.seed)
     nmm_customc = NelderMeadMethod(n=10, C_a=2, C_r=0.5, seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, nmm_custom, nmm_customc,
                                          MyBenchmark())
Exemple #11
0
 def test_griewank_works_fine(self):
     nmm_griewank = NelderMeadMethod(n=10, C_a=5, C_r=0.5, seed=self.seed)
     nmm_griewankc = NelderMeadMethod(n=10, C_a=5, C_r=0.5, seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, nmm_griewank, nmm_griewankc)
Exemple #12
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=1000,
                        optType=OptimizationType.MINIMIZATION,
                        benchmark=Sphere())
    algo = NelderMeadMethod()
    best = algo.run(task=task)
    print(best)
Exemple #13
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 #14
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 #15
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]))