<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>So Jake Says &#187; Mona Lisa</title>
	<atom:link href="http://www.jakevoytko.com/blog/tag/mona-lisa/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jakevoytko.com/blog</link>
	<description>Ye Olde Computer Science Blogge</description>
	<lastBuildDate>Sun, 17 Jan 2010 15:16:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Evolving Genetic Algorithms in Lisp</title>
		<link>http://www.jakevoytko.com/blog/2008/12/16/evolving-genetic-algorithms-in-lisp/</link>
		<comments>http://www.jakevoytko.com/blog/2008/12/16/evolving-genetic-algorithms-in-lisp/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 04:00:40 +0000</pubDate>
		<dc:creator>Jake</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[asdf-install]]></category>
		<category><![CDATA[Genesis]]></category>
		<category><![CDATA[Genetic Algorithms]]></category>
		<category><![CDATA[Genetic Programming]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Mona Lisa]]></category>

		<guid isPermaLink="false">http://www.jakevoytko.com/blog/?p=329</guid>
		<description><![CDATA[Or, now with 100% more Genetic Algorithm! I&#8217;ve been programming a lot recently (instead of blogging about programming!). I caught the genetic algorithm bug along with the rest of the internet, so I&#8217;m in the middle of writing a Lisp library to make it easier to develop genetic algorithms: Genesis [Github link]. I&#8217;ve made some [...]]]></description>
			<content:encoded><![CDATA[<p><em>Or, now with 100% more Genetic Algorithm!</em></p>
<p>I&#8217;ve been programming a lot recently (instead of blogging about programming!). I caught the genetic algorithm bug along with the rest of the internet, so I&#8217;m in the middle of writing a Lisp library to make it easier to develop genetic algorithms: Genesis [<a href="http://github.com/jakevoytko/genesis/">Github link</a>].</p>
<p>I&#8217;ve made some progress in the past few weeks!</p>
<p>The first version of my program was only a genetic programming library, and barely. It produced a rule set that could be evaluated as a function, but it wasn&#8217;t anything different than hill-climbing (a phrase I learned from snobby Reddit commenters). It was inefficient, it was unwieldy, but it produced great results when it ran long enough.</p>
<p><strong>I&#8217;ve added a population!</strong> An arbitrary number of critters evolve in parallel at the moment. Previously, the individual would just mutate. I also added a basic gene-sharing algorithm: random merging.</p>
<p><strong>It&#8217;s faster!</strong> In my first version, I used two &#8216;<code>eval</code>&#8216;s per rule per round. Now I use 1, and I will cut it down to 2 per rule evaluation (instead of per round) soon.</p>
<p><strong>It&#8217;s in a package!</strong> I finally decided to <a href="http://www.jakevoytko.com/blog/2008/09/15/buddy-can-you-spare-a-namespace/">follow my own advice</a> and namespace everything properly. The package layout still needs work, as I&#8217;ve been too busy coding to figure out the ASDF system for installing packages.</p>
<p>The package system in Lisp is a lot more flexible than most module systems I&#8217;ve ever used, so I&#8217;ve been reading a few other popular Lisp packages to see how they are organized before I jump off the deep end without my swimmies.</p>
<p><strong>I started to add tests!</strong> Some of the functions are very fundamental in nature, so I&#8217;ve started to add solid tests for them.</p>
<p><strong>I segregated the example!</strong> There are currently 2 different files: genesis.lisp and square-root-sample.lisp. square-root-sample shows the code necessary to produce a simple/stupid example: finding an algorithm to calculate square roots. As I&#8217;ve mentioned before, the results are very good:</p>
<p style="text-align: center;"><img class="aligncenter" src="http://www.jakevoytko.com/blog/wp-content/uploads/2008/12/sqrt-plot.gif" alt="Plot of f(x), abs(f(x)), error(x), and sqrt(x)" width="469" height="312" /></p>
<p>All you need to do in order to run this example is load genesis.lisp and square-root-sample.lisp and call the following:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>square-root-sample <span style="color: #66cc66;">&lt;</span>em<span style="color: #66cc66;">&gt;</span>generations population-size<span style="color: #66cc66;">&lt;</span>/em<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>After it has finished (run a small number of generations to get a sense for the time it takes), you can call the following to get the best answer so far:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>funcall-best *CURRENT-POPULATION* #'sample-fitness-<span style="color: #b1b100;">function</span> <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<h2>Work Needed</h2>
<p>A recent popular example of genetic programming is the <a href="http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/">production of the Mona Lisa using random polygons.</a> My program should <em>almost</em> be able to handle this. I don&#8217;t allow for a &#8220;modify rule&#8221; function at the moment, only a &#8220;new rule&#8221; function. It would probably work, but convergence would be even slower than the example given.</p>
<p>I&#8217;m also not allowing for one of the most powerful methods of genetic algorithm development: binary serialization. Imagine: if you can represent your whole algorithm as a binary string, then crossover, reproduction, and mutation are all made trivial. I am instead using this idea for lists, which is convenient in Lisp, but I feel it lacks some of the punch.</p>
<h2>On The Horizon</h2>
<p>Of course, this is still in the toy phase. I still have a pretty substantial <a href="http://github.com/jakevoytko/genesis/tree/master/todo.org">to-do list</a>, but here are some of the high-notes:</p>
<ul>
<li>Finish writing tests for core functions.</li>
<li>Multiple populations, including cross-breeding between populations.</li>
<li>Add multithreading.</li>
<li>Give the user much greater control over (genetic-algorithm) by allowing extra key arguments.</li>
<li>Self-awareness: Gather statistics on which alterations produce better improvements, and make beneficial changes more likely to occur.</li>
</ul>
<img src="http://www.jakevoytko.com/blog/?ak_action=api_record_view&id=329&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.jakevoytko.com/blog/2008/12/16/evolving-genetic-algorithms-in-lisp/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
