Пример #1
0
ps = 40  # population size
G = 80  # number of generations to go through
parents = Population(Individual, ps, f11, searchspace)
offspring = Population(Individual, ps, f11, searchspace)

#-------------------------------------------------------------------------------
#--- 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()
sa_T = parents[-1].score - parents[0].score  # starting temperature
saga_ratio = 0.5  # fraction of offspring created by SA and not GA
sa_mstep = 0.02  # mutation step size parameter
sa_mprob = 0.6  # mutation probability
ga_selp = 3.  # selection pressure
AE = 0.04  # annealing exponent --> exp(-AE) is multiplier for reducing temperature
elite_size = 0

g_rec = []  # for recording x-data for plot, i.e. generation
bs_rec = []  # for recording y-data for plot, here best score
ws_rec = []  # for recording y-data for plot, here worst score
T_rec = []  # for recording y-data for plot, here temperature
ms_rec = []  # for recording y-data for plot, here mutation step size

# saving initial generation characteristics
Пример #2
0
print "the population's scores: ", sc  # should give the list [ 1.22  1.32  0.53  0.17  1.81]
print 'the population itself gets printed out like this:'
print p
print 'now sorting'
p.sort()
print p
print 'now reversing'
p.reverse()
print p
print '\n'
print 'each dude has a number, its attribute "no", and each one has also a stored former number "oldno"'
print 'dude.no: ', [dude.no for dude in p]
print 'dude.oldno: ', [dude.oldno for dude in p]
print "now let's update the numbering so it corresponds to the current sequence"
p.update_no()
print 'dude.no: ', [dude.no for dude in p]
print 'dude.oldno: ', [dude.oldno for dude in p]
print 'new look of the direct printout: ', p, '   which is the output of "Population.__str__()"'
print 2 * '\n'

print "now let's sort the population according to the first entry of the DNA vector saying p.sort_for('DNA[0]')"
p.sort_for(
    'DNA[0]'
)  # you can sort_for(somestring) as long as eval('dude.'+somestring) makes some sense
print "you can sort_for(somestring) as long as eval('dude.'+somestring) makes some sense"
print 'dude.no: ', [dude.no for dude in p]
print 'dude.oldno: ', [dude.oldno for dude in p]
print 'dude.DNA[0]: ', [dude.DNA[0] for dude in p]
print "or let's change opinion and sort for the second DNA vector entry, the wall thickness"
print "there is a sorting routine accepting the DNA parameter name: p.sort_for_DNApar('wall_thickness')"
Пример #3
0
print "the population's scores: ",sc  # should give the list [ 1.22  1.32  0.53  0.17  1.81]
print 'the population itself gets printed out like this:'
print p
print 'now sorting'
p.sort()
print p
print 'now reversing'
p.reverse()
print p
print '\n'
print 'each dude has a number, its attribute "no", and each one has also a stored former number "oldno"'
print 'dude.no: ',[dude.no for dude in p]
print 'dude.oldno: ',[dude.oldno for dude in p]
print "now let's update the numbering so it corresponds to the current sequence"
p.update_no()
print 'dude.no: ',[dude.no for dude in p]
print 'dude.oldno: ',[dude.oldno for dude in p]
print 'new look of the direct printout: ',p,'   which is the output of "Population.__str__()"'
print 2*'\n'

print "now let's sort the population according to the first entry of the DNA vector saying p.sort_for('DNA[0]')"
p.sort_for('DNA[0]')  # you can sort_for(somestring) as long as eval('dude.'+somestring) makes some sense
print "you can sort_for(somestring) as long as eval('dude.'+somestring) makes some sense"
print 'dude.no: ',[dude.no for dude in p]
print 'dude.oldno: ',[dude.oldno for dude in p]
print 'dude.DNA[0]: ',[dude.DNA[0] for dude in p]
print "or let's change opinion and sort for the second DNA vector entry, the wall thickness"
print "there is a sorting routine accepting the DNA parameter name: p.sort_for_DNApar('wall_thickness')"
p.sort_for_DNApar('wall_thickness')
print 'dude.no: ',[dude.no for dude in p]
Пример #4
0
searchspace=simple_searchspace(10,-3.,1.)

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

#-------------------------------------------------------------------------------
#--- 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()
sa_T=parents[-1].score-parents[0].score # starting temperature
saga_ratio=0.5 # fraction of offspring created by SA and not GA
sa_mstep=0.02 # mutation step size parameter
sa_mprob=0.6 # mutation probability
ga_selp=3. # selection pressure
AE=0.04 # annealing exponent --> exp(-AE) is multiplier for reducing temperature
elite_size=0

g_rec=[]  # for recording x-data for plot, i.e. generation
bs_rec=[]  # for recording y-data for plot, here best score
ws_rec=[]  # for recording y-data for plot, here worst score
T_rec=[]  # for recording y-data for plot, here temperature
ms_rec=[]  # for recording y-data for plot, here mutation step size

# saving initial generation characteristics