Hi Fransis,<div><br></div><div>Genome that can hold some integers and some real numbers is very nicely explain bye Mr. Pete</div><div>just pasting the old post very much thanks to Pete</div><div><br></div><div><br></div><div>
Sandy</div><div><br></div><div><br></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">Message: 1<br>Date: Mon, 26 Nov 2007 17:25:59 -0500<br>From: Peter Jay Salzman <<a href="mailto:p@dirac.org" style="color: rgb(0, 0, 204); ">p@dirac.org</a>><br>
Subject: Re: [galib] Similar to Example 9 with discrete variable<br>To: GALib Mailing List <<a href="mailto:galib@mit.edu" style="color: rgb(0, 0, 204); ">galib@mit.edu</a>><br>Message-ID: <<a href="mailto:20071126222559.GA7474@dirac.org" style="color: rgb(0, 0, 204); ">20071126222559.GA7474@dirac.org</a>><br>
Content-Type: text/plain; charset=iso-8859-1<br><br>On Mon 26 Nov 07, 6:57 PM, Sandip Karale <<a href="mailto:sandipkarale@gmail.com" style="color: rgb(0, 0, 204); ">sandipkarale@gmail.com</a>> said:<br>> Hi All,<br>
><br>> I want to find maximum value in the function.<br>> y = - ( x1^2 / x3 ) - ( x3 / x2^2 )<br>><br>> with the constraints<br>> -5 <= x1 <= 5<br>> -5 <= x2 <= 5<br>
> and x3 = { 4, 6, 7, 13}<br>><br>> I am not getting how to add the phenotype for the discrete variable x3.<br>><br>> Thanks,<br>><br>> Sandy<br><br><br><br>Hi Sandy,<br><br>I'm very new to GALib, but here's my understanding:<br>
<br>One genome you can use for this problem is the GA1DArrayAlleleGenome<T>,<br>which can represent allels on a whole bunch of different types of genes<br>(floats, chars, ints, unsigned, coins/booleans, etc).<br><br>
Since you're only interested in floats, you should use GARealGenome, which<br>is a GA1DArrayAlleleGenome specifically for floats only.<br><br>A GARealGenome can be made one of two ways:<br><br> 1) # of genes "n", an allele set "aSet", ptr to ObjF<br>
<br> In this case, you tell GALib explicitly how many genes you want (you<br> want n of them) and a single allele set, aSet. The allele set will<br> be applied to all n genes.<br><br> 2) an array of allele sets "aArr", ptr to ObjF<br>
<br> In this case, you don't tell GALib explicitly how many genes you want.<br> Instead, GALib takes your array of alleles and counts the number of<br> elements. If there are 3 elements of the array, then there will be<br>
3 genes in your genome. The first array element will hold the<br> allele set for the 1st gene, the 2nd array element will hold the<br> allele set for the 2nd gene, and so on.<br><br>Given the above, you're forced into wanting to use a GARealGenome, created<br>
with an array of allele sets, rather than a set of alleles.<br><br><br>Note that if x3's bounds were also [-5,5], you WOULD create your genome with:<br><br> GAAlleleSet<float> aSet( -5.0F, -5.0F );<br> GARealGenome genome( 3, aSet, objective );<br>
<br>But since x3's bounds are not the same as x1 and x2, you need to create an<br>allele array and pass the allele array to GARealGenome. Here's how you'd do<br>that (the default is "inclusive", not "exclusive"):<br>
<br> // Create the x3 allele<br> GAAlleleSet<float> zA;<br> zA.add(4.0);<br> zA.add(6.0);<br> zA.add(7.0);<br> zA.add(13.0);<br><br> // Create the allele array with 3 genes<br> GARealAlleleSetArray alleles;<br>
alleles.add(-5.0, 5.0);<br> alleles.add(-5.0, 5.0);<br> alleles.add(zA);<br><br><br>and that's pretty much it, to my knowledge. Note that I'm new to GALib, so<br>all this can be wrong, but I think it at least approximates the truth to<br>
zeroth order.<br><br>For my own education, I tried to implement your problem.<br><br>The first thing I did was throw it onto Excel. Unfortunately, I trust Excel<br>a bit more than GALib at the moment. I couldn't find a way of making solver<br>
constrain a problem to discrete values, so I set z=k for each run:<br><br>x = -8.1E-10<br>y = 5<br>z = 4<br>F -.16<br><br>x = -8.1E-10<br>y = 5<br>z = 6<br>F -.24<br><br>x = -8.1E-10<br>y = 5<br>z = 7<br>F -.28<br><br>
x = -8.1E-10<br>y = 5<br>z = 13<br>F -.52<br><br>So clearly, Excel thinks the answer to your problem is:<br><br>x = -8.1E-10<br>y = 5<br>z = 4<br>F -.16<br><br>Since that maximizes F (-.16 is the least negative value for your objective<br>
function).<br><br>Next I tried to find an answer by hand. By taking partial derivatives, the<br>function is maximized when:<br><br> x = 0<br> y = infinity<br> z = xy<br><br>Given the constraint on y, the answer Solver should've given me was:<br>
<br> x = 0<br> y = 5<br> z = xy<br><br>I'm not sure what to do with z since it's indeterminant (x*y = 5*0), but if<br>I had to take a guess, this would indicate that z=0, or given your<br>constraint on z, that z would be as small as possible. Your smallest<br>
constraint on z is 4, so I think the analytic answer would be:<br><br> x = 0<br> y = 5<br> z = 4<br><br>which is pretty much what Excel's Solver said.<br><br><br>Next I coded something up with GALib. Here are the results with the<br>
"standard" GALib:<br><br> p@satan$ time 03main<br><br> 9.88578e-05 5 4<br><br> real 0m26.531s<br> user 0m26.421s<br> sys 0m0.009s<br><br>It took about 26 seconds to run, and got an answer of {0,5,4}, which is<br>
exactly what I found using both Excel's solver and calculus.<br><br>When I ran your problem through my GALibDbl version of the GALib library,<br>the returned answer was:<br><br> p@satan$ time ./03maindbl<br><br> 1.56162e-06 5 4<br>
<br> real 0m26.848s<br> user 0m26.809s<br> sys 0m0.009s<br><br>Took just as long, but the numerical "zero" is an order of magnitude closer<br>to actual zero. :)<br><br>At this point, you'd play with population, generation, crossover, and<br>
mutation probabilities to determine whehter x1 is really "zero zero" or<br>simply just something close to zero. Basically, you'd look at covergence.<br><br>The code I wrote to implement your problem is below (make sure to change<br>
TYPE to float if you're going to use the default GALib library).<br><br>Shameless Plug Alert -- Shameless Plug Alert -- Shameless Plug Alert:<br><br> If anyone finds this answer remotely useful, please consider answering my<br>
or other peoples' questions in the future. I still have many questions<br> about GALib, but would be more than happy to share what I know with other<br> people. I could really really use some GALib using friends to converse<br>
and share knowledge with.<br><br>Thanks,<br>Pete<br><br><br>// Compile with:<br>// g++ -Wall -I galibdbl/ -g3 03main.cc -L galibdbl/ -lga -o 03maindbl<br>// or:<br>// g++ -Wall -I galib/ -g3 03main.cc -L galib/ -lga -o 03main<br>
#include <cstdio><br>#include <cmath><br>#include <ctime><br>#include <cfloat><br>#include "ga/ga.h"<br>#include "ga/std_stream.h"<br>#define TYPE double<br><br>#define INSTANTIATE_REAL_GENOME<br>
#include "ga/GARealGenome.h"<br>using namespace std;<br><br><br>TYPE objective(GAGenome &);<br>void initializer(GAGenome &);<br><br><br><br>int main( int argc, char *argv[] )<br>{<br> GAAlleleSet<TYPE> zA;<br>
zA.add(4.0);<br> zA.add(6.0);<br> zA.add(7.0);<br> zA.add(13.0);<br><br> GARealAlleleSetArray alleles;<br> alleles.add(-5.0, 5.0);<br> alleles.add(-5.0, 5.0);<br> alleles.add(zA);<br><br> GARealGenome genome(alleles, objective);<br>
genome.initializer(initializer);<br><br><br> GASteadyStateGA ga(genome);<br><br><br> GASigmaTruncationScaling trunc;<br> ga.scaling(trunc);<br><br> ga.maximize();<br> ga.populationSize( 800 );<br> ga.nGenerations( 15000 );<br>
ga.pMutation( .05 );<br> ga.pCrossover( .8 );<br> ga.scoreFilename("bog.dat");<br> ga.selectScores(GAStatistics::AllScores);<br> ga.scoreFrequency(10);<br> ga.flushFrequency(50);<br><br> ga.set(gaNscoreFilename, "bog.dat");<br>
ga.evolve( 0 );<br> cout << endl << endl << ga.statistics().bestIndividual() << endl << endl;<br><br> return 0;<br>}<br><br>TYPE objective( GAGenome &g )<br>{<br> GARealGenome& genome = ( GARealGenome& )g;<br>
<br> TYPE x = genome.gene(0);<br> TYPE y = genome.gene(1);<br> TYPE z = genome.gene(2);<br><br> return - ( x*x / z ) - z /(y*y );<br>}<br><br><br><br>void initializer( GAGenome &g )<br>{<br> GARealGenome& genome = ( GARealGenome& )g;<br>
genome.gene(0, 3.1415926);<br> genome.gene(1, 3.1415926);<br> genome.gene(2, 13);<br>}<br><br><br>--<br>GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D<br>Last night I dreamt of 09-f9-11-02-9d-74-e3-5b-d8-41-56-c5-63-56-88-c0<br>
<br>"A mathematician is a machine for converting coffee <a href="mailto:p@dirac.org" style="color: rgb(0, 0, 204); ">p@dirac.org</a><br> into theorems." -- Paul Erd?s <a href="http://www.dirac.org/" target="_blank" style="color: rgb(0, 0, 204); ">http://www.dirac.org</a><br>
<br><br>------------------------------<br><br>_______________________________________________<br>galib mailing list<br><a href="mailto:galib@mit.edu" style="color: rgb(0, 0, 204); ">galib@mit.edu</a><br><a href="http://mailman.mit.edu/mailman/listinfo/galib" target="_blank" style="color: rgb(0, 0, 204); ">http://mailman.mit.edu/mailman/listinfo/galib</a><br>
<br><br>End of galib Digest, Vol 52, Issue 12<br>*************************************</span></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br>
</span></font><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br><br>
Message: 3<br>
Date: Fri, 16 Apr 2010 18:09:04 -0300<br>
From: francis keyes <<a href="mailto:fkeymo@gmail.com">fkeymo@gmail.com</a>><br>
Subject: [galib] composite genome example<br>
To: <a href="mailto:galib@mit.edu">galib@mit.edu</a><br>
Message-ID:<br>
<<a href="mailto:z2md64607cc1004161409heb156fc3q3b7bd589bc466698@mail.gmail.com">z2md64607cc1004161409heb156fc3q3b7bd589bc466698@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
Hey All,<br>
<br>
Does anyone have an example for a composite genome that can hold some<br>
integers and some real numbers?<br>
<br>
Thanks,<br>
Francis<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://mailman.mit.edu/pipermail/galib/attachments/20100416/166875e2/attachment-0001.htm" target="_blank">http://mailman.mit.edu/pipermail/galib/attachments/20100416/166875e2/attachment-0001.htm</a><br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
galib mailing list<br>
<a href="mailto:galib@mit.edu">galib@mit.edu</a><br>
<a href="http://mailman.mit.edu/mailman/listinfo/galib" target="_blank">http://mailman.mit.edu/mailman/listinfo/galib</a><br>
<br>
<br>
End of galib Digest, Vol 79, Issue 3<br>
************************************<br>
</blockquote></div><br><br clear="all"><br>-- <br>I wish to walk alone always...but will be happy, if you with me....<br>
</div>