Example #1
0
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])
Example #2
0
        pdude.copy_DNA_of(odude,copyscore=True,copyparents=True,copyancestcode=True)
    parents.advance_generation()
    #parents.sort() # not necessary in case offspring has already been sorted

    # step D: recording generation characteristics for plot
    parents.sa_improverate=sa_improved/float(sa_events)
    parents.sa_toleraterate=sa_tolerated/float(sa_events)
    parents.ga_improverate=ga_improved/float(ps-sa_events-elite_size)
    rec.save_status()

#-------------------------------------------------------------------------------
#--- part 4: plotting ----------------------------------------------------------
#-------------------------------------------------------------------------------

# plot A: the usual population score distribution, but this time in colour!!
ancestryplot(rec,ylimits=[90,130],whiggle=0.6)


# plot B: improvement etc rates
gg=rec.gg
saimp=rec.sdat['sa_improverate']
satol=rec.sdat['sa_toleraterate']
gaimp=rec.sdat['ga_improverate']
plt.plot(gg,saimp,'cx',label='SA improve rate')
plt.plot(gg,satol,'yx',label='SA tolerate rate')
plt.plot(gg,gaimp,'g+',label='GA improve rate')

# low-pass filtering:
win=np.hamming(10)
lp_saimp=np.convolve(saimp,win,mode='same')/np.sum(win)
lp_satol=np.convolve(satol,win,mode='same')/np.sum(win)
Example #3
0
                pass  # accepting improvement
            elif rand() < exp(-(dude.score - oldguy.score) / sa_T):
                pass  # accepting improvement
            else:
                dude.copy_DNA_of(oldguy,
                                 copyscore=True)  # preferring parent DNA
        else:
            pa, pb = pse(ps, ga_selp, size=2)
            dude.CO_from(parents[pa], parents[pb])
            dude.evaluate()

    # step B: cooling down temperature and mutation step size parameter
    sa_T *= exp(-AE)
    sa_mstep *= exp(-AE)

    # step C: closing generational cycle --> offspring becomes new parent population
    for pdude, odude in zip(parents, offspring):
        pdude.copy_DNA_of(odude, copyscore=True, copyparents=True)
    parents.advance_generation()
    parents.sort()

    # step D: recording generation characteristics for plot
    rec.save_status()

#-------------------------------------------------------------------------------
#--- part 4: plotting ----------------------------------------------------------
#-------------------------------------------------------------------------------

ancestryplot(rec, ylimits=[90, 130], bg='w')
ancestryplot(rec, ylimits=[90, 130], bg='w', whiggle=0.6, suffix='_whiggled')
Example #4
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])
                          copyancestcode=True)
    parents.advance_generation()
    #parents.sort() # not necessary in case offspring has already been sorted

    # step D: recording generation characteristics for plot
    parents.sa_improverate = sa_improved / float(sa_events)
    parents.sa_toleraterate = sa_tolerated / float(sa_events)
    parents.ga_improverate = ga_improved / float(ps - sa_events - elite_size)
    rec.save_status()

#-------------------------------------------------------------------------------
#--- part 4: plotting ----------------------------------------------------------
#-------------------------------------------------------------------------------

# plot A: the usual population score distribution, but this time in colour!!
ancestryplot(rec, ylimits=[90, 130], whiggle=0.6)

# plot B: improvement etc rates
gg = rec.gg
saimp = rec.sdat['sa_improverate']
satol = rec.sdat['sa_toleraterate']
gaimp = rec.sdat['ga_improverate']
plt.plot(gg, saimp, 'cx', label='SA improve rate')
plt.plot(gg, satol, 'yx', label='SA tolerate rate')
plt.plot(gg, gaimp, 'g+', label='GA improve rate')

# low-pass filtering:
win = np.hamming(10)
lp_saimp = np.convolve(saimp, win, mode='same') / np.sum(win)
lp_satol = np.convolve(satol, win, mode='same') / np.sum(win)
lp_gaimp = np.convolve(gaimp, win, mode='same') / np.sum(win)
Example #6
0
G=120     # number of generations to go through

for i,r in enumerate([0.2,0.5,0.8]):
    parents=SAGA_Population(Individual,ps,f11,searchspace); parents.objname='CEC05 f11'
    offspring=SAGA_Population(Individual,ps,f11,searchspace); offspring.objname='CEC05 f11'
    parents.ncase=2+i
    
    ea=SAGA(parents,offspring,userec=True)
    ea.AE=0.04
    ea.saga_ratio=r
    ea.reduce_mstep=False
    ea.sa_mstep=0.05
    ea.rec.set_goalvalue(97)
    ea.simple_run(G)
    txt='best score: {0}'.format(parents[0].score)
    ancestryplot(ea.rec,whiggle=0.6,ylimits=[90,120],addtext=txt)
    plot_improvement_rates(ea.rec)
    
    parents.reset()
    parents.next_subcase()
    ea.rec.clear()
    ea.reduce_mstep=True
    ea.sa_mstep=0.05      # not really necessary as it stayed fix during first run
    ea.simple_run(G)
    txt='best score: {0}'.format(parents[0].score)
    ancestryplot(ea.rec,whiggle=0.6,ylimits=[90,120],addtext=txt)
    plot_improvement_rates(ea.rec)

# ea.saga_ratio=0.5 seems to be the best setting.
# That at this point 100% GA will not work is quite clear, remember, there is
# no mutation operator in the GA offspring production so you would ever just
Example #7
0
                pass # accepting improvement
            elif rand() < exp(-(dude.score-oldguy.score)/sa_T):
                pass # accepting improvement
            else:
                dude.copy_DNA_of(oldguy,copyscore=True) # preferring parent DNA
        else:
            pa,pb=pse(ps,ga_selp,size=2)
            dude.CO_from(parents[pa],parents[pb])
            dude.evaluate()
    
    # step B: cooling down temperature and mutation step size parameter
    sa_T*=exp(-AE)
    sa_mstep*=exp(-AE)

    # step C: closing generational cycle --> offspring becomes new parent population
    for pdude,odude in zip(parents,offspring):
        pdude.copy_DNA_of(odude,copyscore=True,copyparents=True)
    parents.advance_generation()
    parents.sort()

    # step D: recording generation characteristics for plot
    rec.save_status()
    
#-------------------------------------------------------------------------------
#--- part 4: plotting ----------------------------------------------------------
#-------------------------------------------------------------------------------

ancestryplot(rec,ylimits=[90,130],bg='w')
ancestryplot(rec,ylimits=[90,130],bg='w',whiggle=0.6,suffix='_whiggled')

Example #8
0
for i, r in enumerate([0.2, 0.5, 0.8]):
    parents = SAGA_Population(Individual, ps, f11, searchspace)
    parents.objname = 'CEC05 f11'
    offspring = SAGA_Population(Individual, ps, f11, searchspace)
    offspring.objname = 'CEC05 f11'
    parents.ncase = 2 + i

    ea = SAGA(parents, offspring, userec=True)
    ea.AE = 0.04
    ea.saga_ratio = r
    ea.reduce_mstep = False
    ea.sa_mstep = 0.05
    ea.rec.set_goalvalue(97)
    ea.simple_run(G)
    txt = 'best score: {0}'.format(parents[0].score)
    ancestryplot(ea.rec, whiggle=0.6, ylimits=[90, 120], addtext=txt)
    plot_improvement_rates(ea.rec)

    parents.reset()
    parents.next_subcase()
    ea.rec.clear()
    ea.reduce_mstep = True
    ea.sa_mstep = 0.05  # not really necessary as it stayed fix during first run
    ea.simple_run(G)
    txt = 'best score: {0}'.format(parents[0].score)
    ancestryplot(ea.rec, whiggle=0.6, ylimits=[90, 120], addtext=txt)
    plot_improvement_rates(ea.rec)

# ea.saga_ratio=0.5 seems to be the best setting.
# That at this point 100% GA will not work is quite clear, remember, there is
# no mutation operator in the GA offspring production so you would ever just