Example #1
0
class ASOCrossoverTestCase(TestCase):
    def setUp(self):
        self.D = 40
        self.aso_custom = AnarchicSocietyOptimization(NP=40,
                                                      D=self.D,
                                                      nGEN=10,
                                                      nFES=4000,
                                                      Combination=Crossover,
                                                      benchmark=MyBenchmark())
        self.aso_griewank = AnarchicSocietyOptimization(NP=40,
                                                        D=self.D,
                                                        nGEN=10,
                                                        nFES=4000,
                                                        Combination=Crossover,
                                                        benchmark=Griewank())

    def test_custom_works_fine(self):
        fun = MyBenchmark().function()
        x = self.aso_custom.run()
        self.assertTrue(x)
        self.assertAlmostEqual(fun(self.D, asarray(x[0])), x[1], delta=1e3)

    def test_griewank_works_fine(self):
        fun = Griewank().function()
        x = self.aso_griewank.run()
        self.assertTrue(x)
        self.assertAlmostEqual(fun(self.D, asarray(x[0])), x[1], delta=1e3)
Example #2
0
 def test_griewank_works_fine(self):
     aso_griewank = AnarchicSocietyOptimization(NP=40,
                                                Combination=Crossover,
                                                seed=self.seed)
     aso_griewankc = AnarchicSocietyOptimization(NP=40,
                                                 Combination=Crossover,
                                                 seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, aso_griewank, aso_griewankc)
Example #3
0
 def test_custom_works_fine(self):
     aso_custom = AnarchicSocietyOptimization(NP=40,
                                              Combination=Crossover,
                                              seed=self.seed)
     aso_customc = AnarchicSocietyOptimization(NP=40,
                                               Combination=Crossover,
                                               seed=self.seed)
     AlgorithmTestCase.algorithm_run_test(self, aso_custom, aso_customc,
                                          MyBenchmark())
Example #4
0
 def setUp(self):
     self.D = 40
     self.aso_custom = AnarchicSocietyOptimization(NP=40,
                                                   D=self.D,
                                                   nGEN=10,
                                                   nFES=4000,
                                                   Combination=Crossover,
                                                   benchmark=MyBenchmark())
     self.aso_griewank = AnarchicSocietyOptimization(NP=40,
                                                     D=self.D,
                                                     nGEN=10,
                                                     nFES=4000,
                                                     Combination=Crossover,
                                                     benchmark=Griewank())
Example #5
0
	def test_parameter_types(self):
		d = AnarchicSocietyOptimization.typeParameters()
		self.assertTrue(d['NP'](1))
		self.assertFalse(d['NP'](0))
		self.assertFalse(d['NP'](-1))
		self.assertTrue(d['F'](10))
		self.assertFalse(d['F'](0))
		self.assertFalse(d['F'](-10))
		self.assertTrue(d['CR'](0.1))
		self.assertFalse(d['CR'](-19))
		self.assertFalse(d['CR'](19))
		self.assertTrue(d['alpha'](10))
		self.assertTrue(d['gamma'](10))
		self.assertTrue(d['theta'](10))
Example #6
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.other import AnarchicSocietyOptimization
from NiaPy.algorithms.other.aso import Elitism, Sequential, Crossover
from NiaPy.util import StoppingTask, OptimizationType
from NiaPy.benchmarks import Sphere

# we will run Anarchic Society Optimization for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10, nFES=10000, optType=OptimizationType.MINIMIZATION, benchmark=Sphere())
    algo = AnarchicSocietyOptimization(NP=40, Combination=Elitism)
    best = algo.run(task=task)
    print best
Example #7
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 = AnarchicSocietyOptimization(seed=seed, task=task)
	best = algo.run()
	logger.info('%s %s' % (best[0], best[1]))
	input('Press [enter] to continue')
Example #8
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 = AnarchicSocietyOptimization(D=D, nFES=nFES, optType=optType, seed=seed, benchmark=optFunc())
		best = algo.run()
		logger.info('%s %s' % (best[0], best[1]))
Example #9
0
	def test_griewank_works_fine(self):
		aso_griewank = AnarchicSocietyOptimization(NP=40, D=self.D, nGEN=self.nGEN, nFES=self.nFES, Combination=Crossover, benchmark=Griewank(), seed=self.seed)
		aso_griewankc = AnarchicSocietyOptimization(NP=40, D=self.D, nGEN=self.nGEN, nFES=self.nFES, Combination=Crossover, benchmark=Griewank(), seed=self.seed)
		AlgorithmTestCase.algorithm_run_test(self, aso_griewank, aso_griewankc)
Example #10
0
	def test_custom_works_fine(self):
		aso_custom = AnarchicSocietyOptimization(NP=40, D=self.D, nGEN=self.nGEN, nFES=self.nFES, Combination=Crossover, benchmark=MyBenchmark(), seed=self.seed)
		aso_customc = AnarchicSocietyOptimization(NP=40, D=self.D, nGEN=self.nGEN, nFES=self.nFES, Combination=Crossover, benchmark=MyBenchmark(), seed=self.seed)
		AlgorithmTestCase.algorithm_run_test(self, aso_custom, aso_customc)