Example #1
0
    def __init__(self, func_id, pop_size=100, dim=10, max_iters=100):
        self.dim = dim
        self.pop_size = pop_size
        self.xMin = -100  # Search space limits
        self.xMax = 100  #
        self.maxIters = max_iters

        self.func_id = func_id
        self.fitnessEvals = 0

        # Original parameters
        self.c1 = 2.0
        self.c2 = 2.0
        self.w = 1.0
        self.wdamp = 1.0

        # Yarpiz default
        # self.c1    = 1.4962
        # self.c2    = 1.4962
        # self.w     = 0.7298
        # self.wdamp = 1.0

        self.problem = pg.problem(
            pg.cec2014(prob_id=self.func_id, dim=self.dim))

        self.psoProblem = {
            'CostFunction': self.get_fitness,
            'nVar': self.dim,
            'xMin': self.
            xMin,  # Alternatively you can use a "numpy array" with nVar elements, instead of scalar
            'xMax': self.
            xMax,  # Alternatively you can use a "numpy array" with nVar elements, instead of scalar
        }
Example #2
0
def get_solution(func_id=1, dim=10, input_data_filepath=None):
    '''
        func_list: Function id, between 1 and 31.
        dim      : Problem dimensionality

        Returns a solution corresponding the global optima of the function given
        by func_id.
    '''
    import pygmo as pg
    from glob import glob

    # solution = dict()
    if func_id < 23:
        prob = pg.problem(pg.cec2014(prob_id=func_id, dim=dim))
        filepath = dirs.input if input_data_filepath is None else input_data_filepath
        shift_data = np.loadtxt(filepath +
                                "/shift_data_{}.txt".format(func_id))

        # solution[func_id] = prob.fitness(shift_data[:dim])[0]
        solution = prob.fitness(shift_data[:dim])[0]

    if func_id >= 23:
        raise NotImplementedError(
            "f_{:2d} not yet implemented".format(func_id))
        return None
    return solution
Example #3
0
    def __init__(self, dim=2, func_id=1, pop_size=20):
        self.dim = dim  # Problem dimensionality
        self.xMin = -100  # Search space limits
        self.xMax = 100  #
        self.pop_size = pop_size  # Population size
        self.func_id = func_id
        self.fitnessEvals = 0  # Initial fitness evaluations

        # Algorithm parameters
        self.minSigma = 0.0001
        self.tau1 = 4 * 1 / (np.sqrt(2 * self.pop_size))
        self.tau2 = 4 * 1 / (np.sqrt(2 * np.sqrt(self.pop_size)))
        self.mutateProb = 1.0
        self.numTourneyPlays = 10

        # Fitness Function definition
        if self.func_id < 23:
            self.problem = pg.problem(
                pg.cec2014(prob_id=self.func_id, dim=self.dim))
        else:
            raise ValueError("f_{:2d} not yet implemented".format(
                self.func_id))
            return -1

        # Initialize population DataFrame and compute initial Fitness
        self.init_states()
Example #4
0
    def __init__(self, func_id, pop_size=100, dim=10, max_iters=100):
        self.dim = dim
        self.pop_size = pop_size
        self.xMin = -100  # Search space limits
        self.xMax = 100  #
        self.vMin = self.xMin / 2  # Velocity limits
        self.vMax = self.xMax / 2  #

        self.func_id = func_id
        self.fitnessEvals = 0

        # # Debug
        # self.c1    = 1.0
        # self.c2    = 1.0
        # self.w     = 1.0
        # self.wdamp = 1.0

        # GOPSO default
        self.c1 = 1.49618
        self.c2 = 1.49618
        self.w = 0.72984
        self.wdamp = 1.0

        self.problem = pg.problem(
            pg.cec2014(prob_id=self.func_id, dim=self.dim))

        self.init_states()
Example #5
0
    def __init__(self, dim=2, func_id=1, pop_size=30):
        # Initialize parameters
        self.dim = dim
        self.pop_size = pop_size
        self.xMin = -100  # Search space limits
        self.xMax = 100  #

        self.func_id = func_id
        self.fitnessEvals = 0

        # Parameters
        self.param_F = 0.9  # Mutation parameter F
        self.cross_rate = 0.9  # Crossover probability

        # Fitness Function definition
        self.problem = pg.problem(
            pg.cec2014(prob_id=self.func_id, dim=self.dim))

        # Initialize population DataFrame and compute initial Fitness
        self.init_states()
Example #6
0
    def __init__(self, dim=2, func_id=1, pop_size=30):
        # Initialize superclass EvolutionaryAlgorithm
        super().__init__(dim=dim, pop_size=pop_size)
        self.xMin = -100  # Search space limits
        self.xMax = 100  #

        self.func_id = func_id

        # Parameters
        self.param_F = [0.8, 0.9]  # Mutation parameter F
        # CURRENTLY MUST BE A LIST OF CHOICES FOR F
        self.cross_rate = 0.9  # Crossover probability

        # Fitness Function definition
        if self.func_id < 23:
            self.problem = pg.problem(
                pg.cec2014(prob_id=self.func_id, dim=self.dim))
        else:
            raise NotImplementedError("f_{:2d} not yet implemented".format(
                self.func_id))
            return -1

        # Initialize population DataFrame and compute initial Fitness
        self.init_states()
""" Benchmark to test the cec2014 objective-functions 
"""

import numpy as np
import pandas as pd
import pygmo as pg
import dirs

func_list = [1, 2, 6, 7, 9, 14]  # Assignment function list
dim = 10

# Initializing a test vector with zero elements
x = np.zeros(dim)

for func_id in func_list:
    if func_id < 23:
        prob = pg.problem(pg.cec2014(prob_id=func_id, dim=dim))
        shift_data = np.loadtxt(dirs.input +
                                "shift_data_{}.txt".format(func_id))

        print("f_{:2d}(0)  = {:.6f}".format(func_id, prob.fitness(x)[0]))
        print("f_{:2d}(x*) = {:.6f}\n".format(
            func_id,
            prob.fitness(shift_data[:dim])[0]))
    else:
        print("f_{:2d} not yet implemented".format(func_id))
Example #8
0
import pygmo as pg
import numpy as np

prob = pg.problem(pg.cec2014(prob_id=5, dim=10))
algo = pg.algorithm(pg.cmaes(gen=100))
archi = pg.archipelago(8, algo=algo, prob=prob, pop_size=20)
archi.evolve(1000)
archi.wait()
res = [isl.get_population().champion_f for isl in archi]
res = np.array(res)
print(f"Problem {5}: {res.mean()}")
Example #9
0
 def __init__( self, **kw ):
   import pygmo as pg
   dim     = retrieve_kw( kw, 'dim', 2 )
   prob = retrieve_kw( kw, 'prob', 1)
   self._cec2014_core = pg.problem(pg.cec2014( prob, dim ))
import numpy as np
import pandas as pd
import pygmo as pg

import dirs

# funcList = [1, 2, 6, 7, 9, 14]   # Assignment function list
funcList = [23]
funcList = range(1, 31)
dim = 10

x = np.zeros(dim)

print("\n")
for i in funcList:
    if i < 23:
        prob = pg.problem(pg.cec2014(prob_id=i, dim=dim))
        shift_data = np.loadtxt(dirs.input + "shift_data_{}.txt".format(i))

        print("f_{:2d}(0)  = {:.6f}".format(i, prob.fitness(x)[0]))
        print("f_{:2d}(x*) = {:.6f}\n".format(
            i,
            prob.fitness(shift_data[:dim])[0]))

    if i >= 23:
        print("f_{:2d} not yet implemented".format(i))