# [galib] GA program

Peter Jay Salzman p at dirac.org
Fri Nov 16 16:45:11 EST 2007

Hi Somnath,

On Sat 17 Nov 07, 12:17 AM, Somnath Bhattacharjee <sn.bhattacharjee at yahoo.co.in> said:
>                      I want to solve the Quadratic equation y= x*x+5*x+6.
>    According to manual calculation the result will be two roots ( -3 and -2 ,
>    for these values of x the function value will be ZERO ).

OK, that's what I suspected.

>    Now by GA the
>    results (means the roots) should be nearly -3 and -2 (not exactly -3,-2).
>    I'm not sure that  it is right or not. I'm beginner in GA so your
>    suggestion will be benchmark for me.

There's nothing wrong with being a beginner.  I'm a beginner too, both with
GAs in general and with GALib.  Let me point out a few things that I noticed

First off, you have the following line of code in your program:

>      ga.minimize();

What do you suppose this line of code does?  Compare that with what you want
to accomplish.

Secondly, look at your objective function:

>      GABin2DecPhenotype map;
>
>        ...
>
>    float
>    objective(GAGenome & c)
>    {
>      GABin2DecGenome & genome = (GABin2DecGenome &)c;
>      float y=6.0;
>      y  += genome.phenotype(0) * genome.phenotype(0);
>       y += 5 * genome.phenotype(0);
>        return y;
>    }

You have two genes in your genome.

Your objective function is a function of only one variable.  It says a whole
genome.phenotype(1)?   GALib knows how fit phenotype(0) is because
objective() returns a fitness score that's a function of phenotype(0).

But the objective is not a function of phenotype(1).  How does GALib know
how fit phenotype(1) is?

Thirdly, look at the "roots" that GALib is giving to you.  You have two
numbers (note: increase the number of generations to see the "root values"
more clearly.)  Now focus on the meaning of this:

>      ga.minimize();

Notice anything?  If so, you've just discovered what genome.phenotype(0)
really is.  Now the question is, what is genome.phenotype(1)?

To find out what phenotype(1) is, turn your mutation and crossover
probabilities way, way down to almost zero.  Take a look at what the
starting values are for your two genes, before you evolve the system.  Now
evolve the system and look at the final values.

You should be able to guess what genome.phenotype(1) is from this.

Lastly, you set your gene value boundaries to fall exactly on the two
numbers you were expecting GALib to find.  I don't really know much about
GAs myself, but I wonder if that's a good strategy.  It could be.  But until
I learned a bit more about GAs, I'd probably put the expected values on the
"inside" of the search domain, not on its boundary.

Weird things can happen on boundaries.

Again, I'm new to all this too, so perhaps all this is wrong, so take
everything I say with a grain of salt.

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