problems with minimizing an objective function
Douglas McNab
dmcnab at ultra.eee.strath.ac.uk
Mon Apr 28 06:08:24 EDT 2003
Hi List Users,
I am having problems minimizing my objective function using GALIB.
I am using an array of 8 real numbers as my genome with limits set by
other variables in my code.
Here is an extract of my code for running the GA:
GARealAlleleSetArray alleles;
alleles.add(m_xLower, m_xUpper, 0.5,
GAAllele::INCLUSIVE,GAAllele::INCLUSIVE);
alleles.add(m_yLower, m_yUpper, 0.5,
GAAllele::INCLUSIVE,GAAllele::INCLUSIVE);
alleles.add(m_zLower, m_zUpper, 0.5,
GAAllele::INCLUSIVE,GAAllele::INCLUSIVE);
alleles.add(m_tiltLower, m_tiltUpper, 0.5,
GAAllele::INCLUSIVE,GAAllele::INCLUSIVE);
alleles.add(m_skewLower, m_skewUpper, 0.5,
GAAllele::INCLUSIVE,GAAllele::INCLUSIVE);
alleles.add(m_orientationLower, m_orientationUpper, 0.5,
GAAllele::INCLUSIVE, GAAllele::INCLUSIVE);
alleles.add(m_widthLower, m_widthUpper, 0.5,
GAAllele::INCLUSIVE,GAAllele::INCLUSIVE);
alleles.add(m_lengthLower, m_lengthUpper, 0.5,
GAAllele::INCLUSIVE,GAAllele::INCLUSIVE);
GARealGenome genome(alleles, ObjectiveFunction);
// set the operators on the genome, depending on what kind
// of genome we have and what operators are desired. note that
// we could just use the defaults that are in GAlib, but by
// doing it here we know exactly what operators we will be
// using. (defaults are listed in the GAlib documentation)
// Note that the default operators for the real genome are uniform
// initializer,gaussian mutator, and uniform crossover.
// Now that we have the genomes, create a parameter list that will be
used // by the genetic algorithms and the genome.
GAParameterList params;
GASteadyStateGA::registerDefaultParameters(params);
params.set(gaNnGenerations, 500);// THE NUMBER OF GENERATIONS TO EVOLVE
params.set(gaNpopulationSize, 110); // HOW MANY IN THE POPULATION
params.set(gaNscoreFrequency, 10); // KEEP THE SCORES OF
GENERATIONS
params.set(gaNpMutation,0.01); // LIKELYHOOD OF MUTATING NEW OFFSPRING
params.set(gaNpCrossover, 0.9); // LIKELYHOOD OF CROSSING OVER NEW
PARENTS
params.set(gaNflushFrequency, 50); // SPECIFY HOW OFTEN TO WRITE
THE SCORE
params.set(gaNselectScores, (int)GAStatistics::Mean|
(int)GAStatistics::Maximum | (int)GAStatistics::Minimum);
GASteadyStateGA ga(genome); // NOW CREATE THE GA FOR RUNNING THE
GENOME
ga.minimize(); // SET THE OBJECTIVE FUNCTION TO MINIMIZATION
ga.parameters(params); // SET THE PARAMETERS FOR THE GA OBJECT
ga.set(gaNscoreFilename, "..\\Output\\worstCaseScores.dat");
ga.initialize();
ofstream outfile;
// dump the initial population to file
cout << "printing initial population to file..." << endl;
outfile.open("..\\Output\\initialPopulation.dat", (ios::out |
ios::trunc));
for(int ii=0; ii<ga.population().size(); ii++){
genome = ga.population().individual(ii);
outfile << genome.gene(0) << "\t" << genome.gene(1) << "\t" <<
genome.gene(2) << "\t" << genome.gene(3) << "\t" << genome.gene(4)
<< "\t" << genome.gene(5) << "\t" << genome.gene(6) << "\t" <<
genome.gene(7) << "\t" << genome.score() << "\n";
}
outfile.close();
while(!ga.done()) ga.step(); // RUN THE GA!!!!
// dump the final population to file
cout << "printing final population to file..." << endl;
outfile.open("..\\Output\\finalPopulation.dat", (ios::out |
ios::trunc));
for(int i=0; i<ga.population().size(); i++){
genome = ga.population().individual(i);
outfile << genome.gene(0) << "\t" << genome.gene(1) <<
"\t" << genome.gene(2) << "\t" << genome.gene(3) << "\t"
<< genome.gene(4) << "\t" << genome.gene(5)
<< "\t" << genome.gene(6) << "\t" <<
genome.gene(7) << "\t" << genome.score()
<< "\n";
}
outfile.close();
cout << "the ga generated:\n" << ga.statistics().bestIndividual() <<
endl;
cout << "objective: " << genome.score() << endl; // BEST GENE OBJECTIVE
Using this setup the GA does not seem to minimize the objective
function. My objective function is very problem specific so it wouldn't
really mean much if I presented it here but all it is doing is carrying
out a calculation which has a result in the range [0-1]. I want to
minimize and find the lowest possible values, here is an extract of my
initial populations and final population; the last column contains the
score:
Initial:
67.5 50 80 -44.5 0 0 10 100 1
46.5 50 80 -45.5 0 0 10 100 1
67.5 50 80 -47.5 0 0 10 100 1
48.5 50 80 -46.5 0 0 10 100 1
24 50 80 -45.5 0 0 10 100 1
86 50 80 -36.5 0 0 10 100 0.923725
47.5 50 80 -40 0 0 10 100 0.918861
88.5 50 80 -41 0 0 10 100 0.914851
19.5 50 80 -48.5 0 0 10 100 0.905531
62 50 80 -48 0 0 10 100 0.905434
79 50 80 -50.5 0 0 10 100 0.902146
27.5 50 80 -51 0 0 10 100 0.901866
52.5 50 80 -48 0 0 10 100 0.901818
24 50 80 -49.5 0 0 10 100 0.899786
65 50 80 -49.5 0 0 10 100 0.899786
24.5 50 80 -53 0 0 10 100 0.898862
67.5 50 80 -52.5 0 0 10 100 0.898036
83.5 50 80 -55 0 0 10 100 0.897259
20.5 50 80 -54.5 0 0 10 100 0.894487
61 50 80 -54.5 0 0 10 100 0.893837
41 50 80 -56 0 0 10 100 0.893459
final:
46.5 50 80 -42.5 0 0 10 100 1
72.5 50 80 -46.5 0 0 10 100 1
46.5 50 80 -42.5 0 0 10 100 1
59 50 80 -42.5 0 0 10 100 1
48.5 50 80 -46.5 0 0 10 100 1
46.5 50 80 -45.5 0 0 10 100 1
48.5 50 80 -45.5 0 0 10 100 1
48.5 50 80 -42.5 0 0 10 100 1
71.5 50 80 -46.5 0 0 10 100 1
46.5 50 80 -46.5 0 0 10 100 1
48.5 50 80 -45.5 0 0 10 100 1
46.5 50 80 -46.5 0 0 10 100 1
71.5 50 80 -42.5 0 0 10 100 1
71.5 50 80 -46.5 0 0 10 100 1
40 50 80 -46.5 0 0 10 100 1
46.5 50 80 -46.5 0 0 10 100 1
So you can see that it has maximized the objective function and has
closed in on the maximum value of 1 even though I have set the GA to
minimize with the command: ga.minimize(); I want to find the minimum
value say around 0 (probably).
Have I set up the GA correctly? And if so do you have any ideas what
could be causing it to maximize?
Cheers,
Douglas
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Douglas McNab - Research Assistant
CUE - Centre for Ultrasonic Engineering
University of Strathclyde, 204 George Street
Glasgow, G1 1XW
Tel: +44 (0)141 548 3477 Fax: +44 (0)141 548 2950
http://www.cue.ac.uk
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the galib
mailing list