Latest recipes tagged "artificial"http://code.activestate.com/recipes/tags/artificial/new/2012-06-19T12:59:13-07:00ActiveState Code RecipesGenetic Algorithm in Python source code - AI-Junkie tutorial (Python)
2012-06-19T12:59:13-07:00David Adlerhttp://code.activestate.com/recipes/users/4182015/http://code.activestate.com/recipes/578128-genetic-algorithm-in-python-source-code-ai-junkie-/
<p style="color: grey">
Python
recipe 578128
by <a href="/recipes/users/4182015/">David Adler</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/artificial/">artificial</a>, <a href="/recipes/tags/genetic/">genetic</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/neural/">neural</a>, <a href="/recipes/tags/python/">python</a>).
Revision 5.
</p>
<p>A simple genetic algorithm program. I followed this tutorial to make the program <a href="http://www.ai-junkie.com/ga/intro/gat1.html." rel="nofollow">http://www.ai-junkie.com/ga/intro/gat1.html.</a></p>
<p>The objective of the code is to evolve a mathematical expression which calculates a user-defined target integer.</p>
<hr />
<p>KEY:</p>
<p>chromosome = binary list (this is translated/decoded into a protein in the format number --> operator --> number etc, any genes (chromosome is read in blocks of four) which do not conform to this are ignored.</p>
<p>protein = mathematical expression (this is evaluated from left to right in number + operator blocks of two)</p>
<p>output = output of protein (mathematical expression)</p>
<p>error = inverse of difference between output and target</p>
<p>fitness score = a fraction of sum of of total errors</p>
<hr />
<p>OTHER:</p>
<p>One-point crossover is used.</p>
<p>I have incorporated <strong>elitism</strong> in my code, which somewhat deviates from the tutorial but made my code more efficient (top ~7% of population are carried through to next generation)</p>