[galib] Getting several genomes of only 0's...

anselmop@sc.usp.br anselmop at sc.usp.br
Thu Jan 3 14:13:05 EST 2008


Citando galib-request at mit.edu:

> Send galib mailing list submissions to
> 	galib at mit.edu
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://mailman.mit.edu/mailman/listinfo/galib
> or, via email, send a message with subject or body 'help' to
> 	galib-request at mit.edu
>
> You can reach the person managing the list at
> 	galib-owner at mit.edu
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of galib digest..."
>
>
> Today's Topics:
>
>    1. Re: Getting several genomes of only 0's... (David Love)
>    2. Compiling a Windows Form Application with Visual Studio
>       (Emanuele Ferraro)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 2 Jan 2008 16:33:11 -0700
> From: David Love <wvpryde at hotmail.com>
> Subject: Re: [galib] Getting several genomes of only 0's...
> To: <galib at mit.edu>
> Message-ID: <BAY101-W205C5BDC242BCFC4A685DCB4520 at phx.gbl>
> Content-Type: text/plain; charset="Windows-1252"
>
>
>
>
> ----------------------------------------
>> Date: Sun, 23 Dec 2007 01:32:54 -0500
>> From: p at dirac.org
>> To: galib at mit.edu
>> Subject: Re: [galib] Getting several genomes of only 0's...
>>
>> On Wed 19 Dec 07,  4:57 PM, anselmop at sc.usp.br <anselmop at sc.usp.br> said:
>> > > Message: 1
>> > > Date: Tue, 18 Dec 2007 15:14:11 -0700
>> > > From: David Love <wvpryde at hotmail.com>
>> > > Subject: [galib] Getting several genomes of only 0's after completion
>> > > 	of first generation, before mutation and crosso
>> > > To: <galib at mit.edu>
>> > > Message-ID: <BAY101-W1050FE12A5C28FF3DD0D83B4630 at phx.gbl>
>> > > Content-Type: text/plain; charset="iso-8859-1"
>> > >
>> > >
>> > > Hi everyone,
>> > >
>> > > I'm doing a GASimpleGA using the GA1DArrayGenome data type.  I've
>> > > noticed that after the GA has finished evaluating the first
>> > > generation I receive several genomes for evaluation where every gene
>> > >  is given by 0.0, which occurs before the mutation and crossover
>> > > operations.  For my problem, a genome with only zero entries is
>> > > invalid, so the algorithm cannot continue.
>> > >
>> > > Is it possible for me to avoid getting these zero genomes?   If so, how?
>> > >
>> > > If you need any more information about what I am doing, I can try to
>> > >  provide that.
>> > >
>> > > Thanks,
>> > > David
>> >
>> >
>> > Hi, David.
>> >
>> > Did you provide the genome with an initialization function? If not,
>> > GALib will use a default initialization, which (hopefully) initializes
>> > each gene of the genome with zero value. Quoting GALib's manual, "This
>> > operator does not actually create new genomes, rather it 'stuffs' the
>> > genomes with the primordial genetic material from which all solutions
>> > will evolve."
>>
>>
>> > When you create a GAPopulation or a GAGeneticAlgorithm object, you
>> > must pass a GAGenome object as argument. It is then cloned to create
>> > all the n population individuals. In other words, after that, all the
>> > individuals in the population are identical. The initialization
>> > function must be called for each individual so that they get diverse
>> > genetic material. Your initialization function must do some sort of
>> > variation in order to accomplish this, using, for example, random
>> > numbers.
>> >
>> >
>> > What may be happenning with your code is that you didn't provide an
>> > initialization function, and all the individuals are identical to the
>> > first one, which may have all its genes initializes to zero.
>> >
>> > In case this isn't your problem, a code snnipet may help to clarify things
>> >
>> >
>> > Good luck
>> >
>> >
>> > Anselmo
>>
>>
>> Ola Anselmo,
>>
>> A previous poster had asked about some code that I looked into and it
>> *appeared* (I haven't checked this against the source code yet) that in the
>> absence of an initializer, the genes were being set to their lower limit (at
>> least for the genome/ga combo he was using).
>>
>> Dave, unless you already have a good idea where the solution is, you want to
>> start out with as diverse a population as possible.   If 50 people were to
>> look for a needle laying on the ground somewhere in a football field,
>> they'll find it faster if they start looking in random places than if they
>> all started looking in the same general location.
>>
>> Pete
>>
>> --
>> GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E  70A9 A3B9 1945 67EA 951D
>> Last night I dreamt of 09-f9-11-02-9d-74-e3-5b-d8-41-56-c5-63-56-88-c0
>>
>> "A mathematician is a machine for converting coffee    p at dirac.org
>>  into theorems."     -- Paul Erd?s                     http://www.dirac.org
>> _______________________________________________
>> galib mailing list
>> galib at mit.edu
>> http://mailman.mit.edu/mailman/listinfo/galib
>
> Anselmo and Pete,
>
> Thanks for the replies.  I do have the initializer defined, and it   
> is working correctly as far as I can tell.  I will post my main()   
> and Initializer() below.  I only get the genomes of 0 entries after   
> the completion of the first generation of (correctly initialized)   
> genomes, and before the mutation and crossover sequence begins.  For  
>  the time being, I have simply amended my code so that the 0 genomes  
>  return a very bad objective value without being evaluated in the   
> normal way.  When I began to write this, I started with the code   
> from ex1.C (as I recall) and modified it from there.  The code that   
> I have (anything specified in all caps is given by a #define):
>
> int main(int argc, char **argv) {
>
>   for(int ii=1; ii genome( length, Objective );
>   genome.initializer(::Initializer);
>   genome.mutator(::Mutator);
>   genome.crossover(::Crossover);
>   genome.comparator(::Comparator);
>
>   GASimpleGA ga(genome);
>   ga.minimize();
>   ga.nBestGenomes( 5 );
>   ga.nConvergence( 10 );
>   ga.populationSize(popsize);
>   ga.nGenerations(ngen);
>   ga.pMutation(pmut);
>   ga.pCrossover(pcross);
>
>   ga.selectScores( GAStatistics::AllScores );
>   ga.scoreFrequency( 1 );
>   ga.flushFrequency( 5 );
>
>   ga.evolve();
>
> 	cout << "The GA found:\n" << ga.statistics() << "\n";
>   cout << "The GA found:\n" << ga.statistics().bestPopulation() << "\n";
>
>   return 0;
> }
>
> ------------------------------------------------------------------------------------------------
>
> void Initializer(GAGenome& g) {
> 	GA1DArrayGenome& genome = (GA1DArrayGenome&)g;
> 	int		ii;
>
>  	static int n = 1;
> 	printf( "Inside Initializer, n = %d\n", n++ );
> 	float LayerNumber;
>
> 	int Sum = MULT_LENGTH;
> 	int Number = -1;
> 	int MaxInt = getlen( NUM_PIECEWISE_CONST_LAYERS, Sum, Number );
>
> 	LayerNumber = (float) GARandomInt(1, MaxInt);
> 	genome.gene( 0, LayerNumber );
> 	for( ii = 1; ii <= NUM_PIECEWISE_CONST_LAYERS; ii++ ) {
> 		genome.gene( ii, GARandomFloat( minwidth, maxwidth ) );
> 	}
>
> 	for( ii = NUM_PIECEWISE_CONST_LAYERS + 1; ii <   
> NUM_PIECEWISE_CONST_LAYERS + 3; ii++ ) {
> 		genome.gene( ii, GARandomFloat( minwidth, maxwidth ) );
> 	}
>
> 	cout << genome << endl;
> }
> _________________________________________________________________
> i?m is proud to present Cause Effect, a series about real people   
> making a difference.
> http://im.live.com/Messenger/IM/MTV/?source=text_Cause_Effect

Hello, David,

There is something weird in your code. Are you sure it is compiling?  
For example, the compiler should complain about the line:

GA1DArrayGenome& genome = (GA1DArrayGenome&)g;

since GA1DArrayGenome is a template class. The line should instead read :


GA1DArrayGenome<float>& genome = (GA1DArrayGenome<float>&)g;


Meanwhile, I could'n figure out why your genomes are being populated  
with zeros.
What about the variable "minwidth"? Where its value comes from?


Good luck


Anselmo



Eng. Anselmo Pitombeira

Laboratório de Simulação e Controle
NUMA - Núcleo de Manufatura Avançada
Programa de Pós-Graduação em Engenharia Mecânica
EESC-USP

www.simulacao.eesc.sc.usp.br


"As pessoas sem imaginação podem ter tido as mais imprevistas aventuras,
podem ter visitado as terras mais estranhas...Nada lhes ficou. Nada  
lhes sobrou.
Uma vida não basta apenas ser vivida: Também precisa ser sonhada."

Mário Quintana




More information about the galib mailing list