Popular recipes tagged "genetic"http://code.activestate.com/recipes/tags/genetic/popular/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> Evolutionary Algorithm (Generation of Prime Numbers) (Python) 2011-11-27T06:45:00-08:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/577964-evolutionary-algorithm-generation-of-prime-numbers/ <p style="color: grey"> Python recipe 577964 by <a href="/recipes/users/4179768/">Alexander James Wallar</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/example/">example</a>, <a href="/recipes/tags/genetic/">genetic</a>, <a href="/recipes/tags/genetic_algorithm/">genetic_algorithm</a>, <a href="/recipes/tags/genetic_algorithms/">genetic_algorithms</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/number/">number</a>, <a href="/recipes/tags/of/">of</a>, <a href="/recipes/tags/prime/">prime</a>, <a href="/recipes/tags/primelist/">primelist</a>, <a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/theory/">theory</a>). </p> <p>This is an evolutionary algorithm that returns a random list of prime numbers. This code is highly inefficient for a reason. This algorithm is more of a proof of concept that if a prime was a heritable trait, it would not be a desired one. </p> <p>Parameters:</p> <p>isPrime --> n: number to check if it is prime allPrimes --> n: size of list of random primes, m: the primes in the list will be between 0 and m</p>