Пример #1
0
class jDETestCase(TestCase):
    def setUp(self):
        self.jde_custom = SelfAdaptiveDifferentialEvolutionAlgorithm(
            D=10,
            NP=40,
            nFES=1000,
            F=0.5,
            F_l=0.0,
            F_u=2.0,
            Tao1=0.9,
            CR=0.1,
            Tao2=0.45,
            benchmark=MyBenchmark())
        self.jde_griewank = SelfAdaptiveDifferentialEvolutionAlgorithm(
            D=10,
            NP=40,
            nFES=1000,
            F=0.5,
            F_l=0.0,
            F_u=2.0,
            Tao1=0.9,
            CR=0.1,
            Tao2=0.45,
            benchmark='griewank')

    def test_custom_works_fine(self):
        self.assertTrue(self.jde_custom.run())

    def test_griewank_works_fine(self):
        self.assertTrue(self.jde_griewank.run())
Пример #2
0
class jDETestCase(TestCase):
    def setUp(self):
        self.jde_custom = SelfAdaptiveDifferentialEvolutionAlgorithm(
            10, 40, 10000, 0.5, 0.9, 0.1, MyBenchmark())
        self.jde_griewank = SelfAdaptiveDifferentialEvolutionAlgorithm(
            10, 40, 10000, 0.5, 0.9, 0.1, 'griewank')

    def test_custom_works_fine(self):
        self.assertTrue(self.jde_custom.run())

    def test_griewank_works_fine(self):
        self.assertTrue(self.jde_griewank.run())
Пример #3
0
def logging_example(D=10, nFES=50000):
    task = TaskConvPrint(D=D, nFES=nFES, nGEN=50000, benchmark=MyBenchmark())
    algo = SelfAdaptiveDifferentialEvolutionAlgorithm(NP=10,
                                                      F=0.5,
                                                      F_l=-1,
                                                      F_u=2.0,
                                                      Tao1=0.1,
                                                      CR=0.45,
                                                      Tao2=0.25,
                                                      task=task)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
Пример #4
0
def plot_example(D=10, nFES=50000):
    task = TaskConvPlot(D=D, nFES=nFES, nGEN=10000, benchmark=MyBenchmark())
    algo = SelfAdaptiveDifferentialEvolutionAlgorithm(NP=10,
                                                      F=0.5,
                                                      F_l=-1,
                                                      F_u=2.0,
                                                      Tao1=0.1,
                                                      CR=0.45,
                                                      Tao2=0.25,
                                                      task=task)
    best = algo.run()
    logger.info('%s %s' % (best[0], best[1]))
    input('Press [enter] to continue')
Пример #5
0
def simple_example(runs=10, D=50, nFES=50000):
    for i in range(10):
        algo = SelfAdaptiveDifferentialEvolutionAlgorithm(
            NP=50,
            D=D,
            nFES=nFES,
            F=0.5,
            F_l=-1,
            F_u=2.0,
            Tao1=0.1,
            CR=0.45,
            Tao2=0.25,
            benchmark=MyBenchmark())
        Best = algo.run()
        logger.info('%s %s' % (Best[0], Best[1]))
Пример #6
0
 def setUp(self):
     self.jde_custom = SelfAdaptiveDifferentialEvolutionAlgorithm(
         D=10,
         NP=40,
         nFES=1000,
         F=0.5,
         F_l=0.0,
         F_u=2.0,
         Tao1=0.9,
         CR=0.1,
         Tao2=0.45,
         benchmark=MyBenchmark())
     self.jde_griewank = SelfAdaptiveDifferentialEvolutionAlgorithm(
         D=10,
         NP=40,
         nFES=1000,
         F=0.5,
         F_l=0.0,
         F_u=2.0,
         Tao1=0.9,
         CR=0.1,
         Tao2=0.45,
         benchmark='griewank')
Пример #7
0
 def setUp(self):
     self.jde_custom = SelfAdaptiveDifferentialEvolutionAlgorithm(
         10, 40, 10000, 0.5, 0.9, 0.1, MyBenchmark())
     self.jde_griewank = SelfAdaptiveDifferentialEvolutionAlgorithm(
         10, 40, 10000, 0.5, 0.9, 0.1, 'griewank')
Пример #8
0
# 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.modified import SelfAdaptiveDifferentialEvolutionAlgorithm


def Fun(D, sol):
    val = 0.0
    for i in range(D):
        val = val + sol[i] * sol[i]
    return val


for i in range(10):
    Algorithm = SelfAdaptiveDifferentialEvolutionAlgorithm(
        10, 40, 10000, 0.5, 0.9, 0.0, 2.0, Fun)
    Best = Algorithm.run()

    print(Best)
Пример #9
0
# 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.modified import SelfAdaptiveDifferentialEvolutionAlgorithm

for i in range(10):
    Algorithm = SelfAdaptiveDifferentialEvolutionAlgorithm(
        10, 40, 10000, 0.5, 0.9, 0.1, 'sphere')
    Best = Algorithm.run()

    print(Best)
Пример #10
0
logging.basicConfig()
logger = logging.getLogger('examples')
logger.setLevel('INFO')

# For reproducive results
random.seed(1234)


class MyBenchmark(object):
    def __init__(self):
        self.Lower = -11
        self.Upper = 11

    def function(self):
        def evaluate(D, sol):
            val = 0.0
            for i in range(D):
                val = val + sol[i] * sol[i]
            return val

        return evaluate


for i in range(10):
    Algorithm = SelfAdaptiveDifferentialEvolutionAlgorithm(
        10, 40, 10000, 0.5, 0.9, 0.1, MyBenchmark())
    Best = Algorithm.run()

    logger.info(Best)