Esempio n. 1
0
 def __init__(self, F0pop, F1pop, userec=False):
     self.F0 = F0pop  # parent population, nomenclature like in your biology book
     self.F1 = F1pop  # offspring population, nomenclature like in your biology book
     self.sa_T = 1.  # temperature
     self.saga_ratio = 0.5  # fraction of offspring created by SA and not GA
     self.sa_mstep = 0.05  # mutation step size parameter
     self.sa_mprob = 0.6  # mutation probability
     self.ga_selp = 3.  # selection pressure
     self.AE = 0.08  # annealing exponent --> exp(-AE) is multiplier for reducing temperature
     self.elite_size = 2
     self.reduce_mstep = False
     if userec:
         self.rec = Recorder(F0pop)
         self.rec.snames.append(
             'sa_improverate'
         )  # appending a scalar property's name to the survey list
         self.rec.snames.append('sa_toleraterate')
         self.rec.snames.append('ga_improverate')
         self.rec.reinitialize_data_dictionaries()
         self.userec = True
     else:
         self.rec = None
         self.userec = False
Esempio n. 2
0
#-------------------------------------------------------------------------------

dim = 10
f11 = tfp(11, dim)  # Weierstrass function in 10 dimensions

searchspace = simple_searchspace(10, -3., 1.)

ps = 40  # population size
G = 40  # number of generations to go through
parents = Population(Individual, ps, f11, searchspace)
parents.objname = 'CEC05 f11'
offspring = Population(Individual, ps, f11, searchspace)
offspring.objname = 'CEC05 f11'

rec = Recorder(
    parents
)  # creating this Recorder instance to collect survey data on parent population

#-------------------------------------------------------------------------------
#--- part 2: initialisation ----------------------------------------------------
#-------------------------------------------------------------------------------

seed(
    1
)  # seeding numpy's random number generator so we get reproducibly the same random numbers
parents.new_random_genes()
parents.eval_all()
parents.sort()
parents.update_no()

rec.save_status()
Esempio n. 3
0
    b.plot_FMsynth_solution()
    print 'gcb: score: {}   DNA: {}'.format(b.score, b.DNA)
    print 'gcb: target[:5]: ', b.target[:5]


# search space boundaries:
searchspace = (('amp 1', -6.4, +6.35), ('omega 1', -6.4, +6.35),
               ('amp 2', -6.4, +6.35), ('omega 2', -6.4, +6.35),
               ('amp 3', -6.4, +6.35), ('omega 3', -6.4, +6.35))

dim = len(searchspace)  # search space dimension

ps_ref = 20
dset = Population(FMsynthC, 40, dummyfunc, searchspace)
rset = Population(FMsynthC, ps_ref, dummyfunc, searchspace)
rec = Recorder(rset)


def gcb2(eaobj):
    rec.save_status()


ea = ScatterSearch(dset, rset, nref=ps_ref, b1=10)
ea.refset_update_style = 'Herrera'
ea.generation_callbacks.append(gcb1)
ea.generation_callbacks.append(gcb2)

ea.complete_algo(10)

ancestryplot(rec, ylimits=[0, 70])
Esempio n. 4
0
        plt.close()

    def set_bad_score(self):
        self.score = 9999.


# search space boundaries:
searchspace = (('amp 1', -6.4, +6.35), ('omega 1', -6.4, +6.35),
               ('amp 2', -6.4, +6.35), ('omega 2', -6.4, +6.35),
               ('amp 3', -6.4, +6.35), ('omega 3', -6.4, +6.35))

dim = len(searchspace)  # search space dimension

ps = 80
p = Population(FMsynthC, ps, dummyfunc, searchspace)
rec = Recorder(p)
ea = CMAES(p, 40, rec)  # instanciate the algorithm from library
ea.maxeval = 1e6


def gcb(eaobj):
    if eaobj.F0.gg % 10 == 0:  # every 10th generation
        b = eaobj.F0[0]
        b.plot_FMsynth_solution()
        print 'gcb: generation: {} score: {}   DNA: {}'.format(
            eaobj.F0.gg, b.score, b.DNA)
    rec.save_status()


ea.generation_callbacks.append(gcb)
    def set_bad_score(self):
        self.score = 9999.


# search space boundaries:
searchspace = (('amp 1', -6.4, +6.35), ('omega 1', -6.4, +6.35),
               ('amp 2', -6.4, +6.35), ('omega 2', -6.4, +6.35),
               ('amp 3', -6.4, +6.35), ('omega 3', -6.4, +6.35))

dim = len(searchspace)  # search space dimension

ps = 80
parents = Population(FMsynthC, ps, dummyfunc, searchspace)
offspring = Population(FMsynthC, ps, dummyfunc, searchspace)
rec = Recorder(parents)
ea = ComboB(parents, offspring)  # instanciate the algorithm from library


def gcb(eaobj):
    if eaobj.F0.gg % 10 == 0:  # every 10th generation
        b = eaobj.F0[0]
        b.plot_FMsynth_solution()
        print 'gcb: generation: {} score: {}   DNA: {}'.format(
            eaobj.F0.gg, b.score, b.DNA)
    rec.save_status()


ea.generation_callbacks.append(gcb)

# set algorithm parameters (meaning of unexplained parameters should be inferred from source code)
Esempio n. 6
0
#plt.ion()

def dummyfunc(x):
    return np.sum(x)
    
ndim=8
ps=80

problem = 'gf_kragtraeger'
EA_type = 'CMAES'

if problem == 'FMsynth':
    space=simple_searchspace(ndim, -6.4, +6.35)
    p0=Population(FMsynth,ps,dummyfunc,space)
    p1=Population(FMsynth,ps,dummyfunc,space)
    rec=Recorder(p0)
    
elif problem == 'necklace':
    space=simple_searchspace(ndim, 0., 360.)
    p0=Population(necklace,ps,dummyfunc,space)
    p1=Population(necklace,ps,dummyfunc,space)
    rec=Recorder(p0)

elif problem == 'hilly':
    space=simple_searchspace(ndim, 0., 360.)
    p0=Population(hilly,ps,dummyfunc,space)
    p1=Population(hilly,ps,dummyfunc,space)
    rec=Recorder(p0)

elif problem == 'murmeln':
    space=simple_searchspace(ndim, 0., 360.)