class BBFWATestCase(TestCase): def setUp(self): self.D = 40 self.sca_custom = SineCosineAlgorithm(D=self.D, nFES=1000, NP=35, a=7, Rmin=0.1, Rmax=3, benchmark=MyBenchmark()) self.sca_griewank = SineCosineAlgorithm(D=self.D, nFES=1000, NP=10, a=5, Rmin=0.01, Rmax=3, benchmark=Griewank()) def test_custom_works_fine(self): fun = MyBenchmark().function() x = self.sca_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.sca_griewank.run() self.assertTrue(x) self.assertAlmostEqual(fun(self.D, x[0]), x[1], delta=1e2)
def simple_example(runs=10): for i in range(runs): algo = SineCosineAlgorithm(D=50, nFES=1000, NP=50, a=7, Rmin=0.1, Rmax=3, benchmark=MyBenchmark()) best = algo.run() logger.info('%s %s' % (best[0], best[1]))
def test_griewank_works_fine(self): sca_griewank = SineCosineAlgorithm(NP=10, a=5, Rmin=0.01, Rmax=3, seed=self.seed) sca_griewankc = SineCosineAlgorithm(NP=10, a=5, Rmin=0.01, Rmax=3, seed=self.seed) AlgorithmTestCase.algorithm_run_test(self, sca_griewank, sca_griewankc)
def test_custom_works_fine(self): sca_custom = SineCosineAlgorithm(NP=35, a=7, Rmin=0.1, Rmax=3, seed=self.seed) sca_customc = SineCosineAlgorithm(NP=35, a=7, Rmin=0.1, Rmax=3, seed=self.seed) AlgorithmTestCase.algorithm_run_test(self, sca_custom, sca_customc, MyBenchmark())
def setUp(self): self.D = 40 self.sca_custom = SineCosineAlgorithm(D=self.D, nFES=1000, NP=35, a=7, Rmin=0.1, Rmax=3, benchmark=MyBenchmark()) self.sca_griewank = SineCosineAlgorithm(D=self.D, nFES=1000, NP=10, a=5, Rmin=0.01, Rmax=3, benchmark=Griewank())
def test_custom_works_fine(self): sca_custom = SineCosineAlgorithm(D=self.D, nFES=self.nFES, nGEN=self.nGEN, NP=35, a=7, Rmin=0.1, Rmax=3, benchmark=MyBenchmark(), seed=self.seed) sca_customc = SineCosineAlgorithm(D=self.D, nFES=self.nFES, nGEN=self.nGEN, NP=35, a=7, Rmin=0.1, Rmax=3, benchmark=MyBenchmark(), seed=self.seed) AlgorithmTestCase.algorithm_run_test(self, sca_custom, sca_customc)
def test_griewank_works_fine(self): sca_griewank = SineCosineAlgorithm(D=self.D, nFES=self.nFES, nGEN=self.nGEN, NP=10, a=5, Rmin=0.01, Rmax=3, benchmark=Griewank(), seed=self.seed) sca_griewankc = SineCosineAlgorithm(D=self.D, nFES=self.nFES, nGEN=self.nGEN, NP=10, a=5, Rmin=0.01, Rmax=3, benchmark=Griewank(), seed=self.seed) AlgorithmTestCase.algorithm_run_test(self, sca_griewank, sca_griewankc)
# 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 SineCosineAlgorithm from NiaPy.task import StoppingTask from NiaPy.benchmarks import Sphere # we will run Sine Cosine Algorithm algorithm for 5 independent runs for i in range(5): task = StoppingTask(D=10, nFES=10000, benchmark=Sphere()) algo = SineCosineAlgorithm(NP=30, a=7, Rmin=0.1, Rmax=3) best = algo.run(task=task) print(best) # vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3
def plot_example(): task = TaskConvPlot(D=50, nFES=50000, nGEN=10000, benchmark=MyBenchmark()) algo = SineCosineAlgorithm(NP=35, a=7, Rmin=0.1, Rmax=3, task=task) best = algo.run() logger.info('%s %s' % (best[0], best[1])) input('Press [enter] to continue')
def logging_example(): task = TaskConvPrint(D=50, nFES=50000, nGEN=10000, benchmark=MyBenchmark()) algo = SineCosineAlgorithm(NP=35, a=3, Rmin=0.1, Rmax=1.1, task=task) best = algo.run() logger.info('%s %s' % (best[0], best[1]))
def test_algorithm_info_fine(self): self.assertIsNotNone(SineCosineAlgorithm.algorithmInfo())
def test_type_parameters(self): d = SineCosineAlgorithm.typeParameters() self.assertIsNotNone(d.get('NP', None)) self.assertIsNotNone(d.get('a', None)) self.assertIsNotNone(d.get('Rmin', None)) self.assertIsNotNone(d.get('Rmax', None))