<?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>SQL in the Wild &#187; Personal</title>
	<atom:link href="http://sqlinthewild.co.za/index.php/category/personal/feed/" rel="self" type="application/rss+xml" />
	<link>http://sqlinthewild.co.za</link>
	<description>A discussion on SQL Server</description>
	<lastBuildDate>Tue, 31 Aug 2010 17:26:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Genetic Algorithms</title>
		<link>http://sqlinthewild.co.za/index.php/2010/01/28/genetic-algorithms/</link>
		<comments>http://sqlinthewild.co.za/index.php/2010/01/28/genetic-algorithms/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 14:00:59 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Artificial Intelligence]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=531</guid>
		<description><![CDATA[Warning. This post has absolutely nothing to do with SQL Server. What are Genetic Algorithms? Genetic algorithms are a form of evolutionary computation, a branch of artificial intelligence that focuses on evolving effective or optimal solutions to difficult problems, based on the biological theory of evolution. Genetic algorithms are, at their core, a search/optimisation technique. [...]]]></description>
			<content:encoded><![CDATA[<p>Warning. This post has absolutely nothing to do with SQL Server.</p>
<h3>What are Genetic Algorithms?</h3>
<p>Genetic algorithms are a form of evolutionary computation, a branch of artificial intelligence that focuses on evolving effective or optimal solutions to difficult problems, based on the biological theory of evolution.</p>
<p>Genetic algorithms are, at their core, a search/optimisation technique. They are a way of finding maximum/minimum solutions to problems and, can be effective when there is no algorithmic solution to the problem. An example here would be the ‘Travelling Salesman’ problem.</p>
<p>Genetic algorithms work by taking an initial population of potential solutions (referred to as individuals), selecting a subset of the population that has the highest fitness then using that subset to generate a second generation. From the second generation again a subset with the highest fitness is selected and used to generate a third generation. This repeats until either the &#8216;fittest’ individual is considered a good enough solution, or until a certain number of generations have passed.</p>
<p>There are advantage to using genetic algorithms to solve problems over more traditional methods like <a href="http://en.wikipedia.org/wiki/Hill_climbing">hill climbing</a>.</p>
<ul>
<li>Genetic algorithms can quickly produce good solutions though they may take a lot of time to find the best solution. This is a benefit when the problem is such that the absolute best solution is not necessary, just one that is ‘good enough’</li>
<li>They are not susceptible to getting trapped by local maxima.</li>
<li>They do not work on the entire search space one potential solution at a time, but rather work on populations of potential solutions, focusing towards more optimal areas of the search space.</li>
</ul>
<p>A genetic algorithm will almost always find an optimal solution, given enough time. The main downside is that they may take a lot of time to find that optimal solution.</p>
<p><span id="more-531"></span></p>
<h3>Components of a Genetic Algorithm</h3>
<p>There are two main critical parts in setting up a genetic algorithm for a problem.</p>
<ul>
<li>The encoding of the potential solutions into a form where they can be operated on.</li>
<li>The fitness function which defines which individuals are better than others, which are closer to the maximum that is being searched for.</li>
</ul>
<p>Most of the design work when using genetic algorithms goes into those two problems.</p>
<h4>Encoding</h4>
<p>Encoding is the process of taking all the values that make up a potential solution and turning them into a form that the genetic algorithm can operate on.</p>
<p>The selection of an encoding is of utmost importance to the effectiveness of the entire process and a poor representation can make the entire problem much harder than it should. Unfortunately there has been little academic work done on the process of designing representations.</p>
<p>Often for genetic algorithms, the end result of the encoding will be a binary string. There are other variations of evolutionary computation that use other representations, from the arrays of real numbers used by evolutionary strategies to the code trees used by genetic programming.</p>
<h4>Fitness function</h4>
<p>Depending on the problem, the fitness function can be trivial to write or near-impossible. The design of the fitness function is completely based on the problem that is being solved.</p>
<p>There are two important considerations for a fitness function.</p>
<ul>
<li>It must be deterministic.</li>
<li>It must be fast</li>
</ul>
<p>If the fitness of an individual is assessed twice, it must come to the same value<sup>1</sup>. If the fitness function could return different values for the same individual, then it is of no use in determining the fittest individuals in the population and hence the genetic algorithm will not be able to identify the best solution to the problem.</p>
<p>The fitness of each individual is assessed at least once in each generation. The calculation of the fitness function is usually the most time consuming part of the entire process and the longer the fitness function takes to run, the longer the entire process is run</p>
<p>(1) There are cases where the fitness of an individual may depend on external factors which change over time. Hence a fitness function may give different values for one individual if calculated at different times. Genetic algorithms in a changing environment are a little beyond the scope of this entry.</p>
<h3>Evolution Process</h3>
<p>In order to create a new generation, the fittest individuals from the previous generation are taken and used to generate the next generation. There are two main operators that are used to generate a generation from the previous one. Crossover and mutation.</p>
<h4>Crossover</h4>
<p>Crossover involved taking two individuals, splitting each one’s encoded string and swapping parts to generate two new individuals.</p>
<p>Say we had two individuals with the following encoded strings (spaces added for clarity)<br />
0000 0001 1111 1110<br />
0101 1010 1100 0011<br />
and we chose the splitting point for the crossover after the 4th bit, the resulting strings after the crossover will be<br />
0000 1010 1100 0011<br />
0101 0001 1111 1110</p>
<p>In genetic algorithms crossover is the primary operator used. What I described here was a single crossover. There are a number of other variations that can be used.</p>
<h4>Mutation</h4>
<p>Mutation is an operator applied to a single individual. It’s usually applied after crossover has generated new individuals. Mutation involves flipping a single bit somewhere in the encoded string.</p>
<p>Let’s take the two individuals that were generates by the crossover earlier and apply a random mutation to each<br />
0000 1010 1100 0011<br />
0101 0001 1111 1110<br />
After<br />
0000 1010 1101 0011<br />
0101 0001 1011 1110</p>
<p>In genetic algorithms mutation is very seldom applied and only a small percentage of individuals in a generation will be affected by the mutation operator.</p>
<h3>Example</h3>
<p>As a quick example let’s manually evolve a simple function to see how the whole thing works.</p>
<p>Let’s say I have an array of 4 numbers (call it num) between 0 and 15. I want to know what values give me the best value for the following.</p>
<p>num[1]-num[2]-num[3]+num[4]</p>
<p>I know, that’s simple enough that we could work out the optimal solution just by eye. Not the point. This is enough to do a quick and effective demo with.</p>
<p>I’m going to encode that by simply converting the numbers in the array to binary and concatenating the binary representations of the 4 numbers (spaces just added for clarity). The fitness function is already defined. I’m going to start with an initial population of eight individuals.</p>
<p>1111 1111 1100 1110 – fitness = (15-15-12+14) = 2<br />
0101 1010 1100 0011 – fitness = (9-10-12+3) = –10<br />
1011 0111 0011 1111 – fitness = (11-7-3+15) = 16<br />
1111 1001 1010 0011 – fitness = (15-9-10+3) = -1<br />
1010 1010 1010 1010 – fitness = (10-10-10+10) = 0<br />
1000 0010 0111 0110 – fitness = (8-2-7+6) = 5<br />
0000 0001 1111 1110 – fitness = (0-1-15+14) = -2<br />
1010 0101 0010 0101 – fitness = (10-5-2+5) = 8</p>
<p>From this I’m going to take the 4 individuals with the highest fitness, use crossover operations (with the crossover point exactly in the middle) between them until I have 8 individuals for the 2nd generation and then apply a single bit mutation to one of the individuals (detailed steps left as an exercise for the reader)</p>
<p>1111 1111 0011 1111 – fitness = (15-15-3+15) = 12<br />
1011 0111 1100 1110 – fitness = (11-7-12+14) = 6<br />
1111 1011 0010 0101 – fitness = (15-11-2+5) = 7<br />
1010 0101 1100 1110 – fitness = (10-5-7+6) = 4<br />
1011 0111 0111 0110 – fitness = (11-7-7+6) = 3<br />
1000 0010 0011 1111 – fitness = (8-2-3+15) = 18<br />
1010 0101 0111 0110 – fitness = (10-5-7+6) = 4<br />
1000 0010 0010 0101 – fitness = (8-2-2+5) = 9</p>
<p>We can already see an improvement. The average and maximum fitness is much higher than for the first generation. I’ll do one more generation in this example, again taking the 4 fittest individuals, crossing over to generate 8 new individuals and then applying a single bit mutation to two individuals. This time however, the crossover point will between the 4th and 5th bit.</p>
<p>1000 1111 0011 1111 &#8211; fitness = (8-15-3+15) = 5<br />
1111 0010 0011 1111 &#8211; fitness = (15-2-3+15) = 25<br />
1000 1011 0010 0101 &#8211; fitness = (8-11-2+5) = 0<br />
1111 0010 0011 1111 &#8211; fitness = (15-2-3+15) = 25<br />
1111 0010 1010 0101 &#8211; fitness = (15-2-10+5) = 8<br />
1000 0111 0011 1111 &#8211; fitness = (8-7-3+15) = 13<br />
1111 0010 0010 0101 &#8211; fitness = (15-2-2+5) = 16<br />
1000 1011 0010 0101 &#8211; fitness = (8-11-2+5) = 0</p>
<p>I think that’s enough for this example. We’re getting fairly close to the best possible solution (15,0,0,15), close enough to see how this works. The population size was very low, that’s why there are duplicates appearing in the results of the crossover. With a larger search space there would be a lot more diversity.</p>
<p>I hope that anyone still reading found this brief diversion into the realms of AI interesting. The regular SQL-related posts will return soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2010/01/28/genetic-algorithms/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Great start to the new year. Not!</title>
		<link>http://sqlinthewild.co.za/index.php/2009/01/04/great-start-to-the-new-year-not/</link>
		<comments>http://sqlinthewild.co.za/index.php/2009/01/04/great-start-to-the-new-year-not/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 10:32:20 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=190</guid>
		<description><![CDATA[My flat got broken into last night. Cell phone, laptop, camera and wallet all gone. Yay. Not! Edit: And my iPod. And an ornamental knife I bought in Scotland a few year back.]]></description>
			<content:encoded><![CDATA[<p>My flat got broken into last night. Cell phone, laptop, camera and wallet all gone.</p>
<p>Yay. Not!</p>
<p>Edit: And my iPod. And an ornamental knife I bought in Scotland a few year back.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2009/01/04/great-start-to-the-new-year-not/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Stepping down</title>
		<link>http://sqlinthewild.co.za/index.php/2008/06/03/stepping-down/</link>
		<comments>http://sqlinthewild.co.za/index.php/2008/06/03/stepping-down/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 21:35:55 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Roleplaying]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=75</guid>
		<description><![CDATA[Sunday saw the last game (for now) of the d20 Modern campaign I&#8217;m running. I&#8217;m going to miss DMing, but it was for the best. I&#8217;m struggling with a bit of burnout and a lack of free time. The campaign went quite well. The players seemed to enjoy it and that&#8217;s the only real measure [...]]]></description>
			<content:encoded><![CDATA[<p>Sunday saw the last game (for now) of the d20 Modern campaign I&#8217;m running. I&#8217;m going to miss DMing, but it was for the best. I&#8217;m struggling with a bit of burnout and a lack of free time.</p>
<p>The campaign went quite well. The players seemed to enjoy it and that&#8217;s the only real measure of any importance. We didn&#8217;t get quite as far as I had hoped, but a lot of hints and clues were dropped during the various adventures and I think that all the players have a better idea of the &#8216;big picture&#8217;. They&#8217;ve also managed to disrupt the big bad guy&#8217;s plans often enough to be irritating.</p>
<p>For the next few months at least, we&#8217;ll be playing high-fantasy D&amp;D as we return to the world of Per-rune. Currently our characters are about to disembark ship after a rather exciting trip to the Elven kingdom. All we need is to do some shopping for winter gear and then head inland back to the small town of Kurat, where the whole thing started. Easy, right?</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2008/06/03/stepping-down/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Birthday musings</title>
		<link>http://sqlinthewild.co.za/index.php/2007/12/07/birthday-musings/</link>
		<comments>http://sqlinthewild.co.za/index.php/2007/12/07/birthday-musings/#comments</comments>
		<pubDate>Fri, 07 Dec 2007 19:45:11 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/index.php/2007/12/07/birthday-musings/</guid>
		<description><![CDATA[Another year gone, another year older. It&#8217;s been an interesting year. Professionally, I&#8217;m very happy with the past year. I&#8217;ve achieved several goals, got to know some interesting people in the SQL community and, of course, started this blog. I&#8217;ve also made some fairly important decisions about the future. Academically, I&#8217;m not so happy. My [...]]]></description>
			<content:encoded><![CDATA[<p>Another year gone, another year older. It&#8217;s been an interesting year.</p>
<p>Professionally, I&#8217;m very happy with the past year. I&#8217;ve achieved several goals, got to know some interesting people in the SQL community and, of course, started this blog. I&#8217;ve also made some fairly important decisions about the future.</p>
<p>Academically, I&#8217;m not so happy. My masters thesis is behind where it should be. (a fact I&#8217;m sure my supervisor would agree with.) Most of the initial reading is done and I know what I need to do. I need to sit down and get busy. This is going to have to take a higher priority in the next few months.</p>
<p>On more personal matters, a good friend moved up to JHB. It&#8217;s very good to see her again. The roleplaying campaign is going well and from the feedback I&#8217;ve been having, the players are all enjoying themselves.</p>
<p>Overall, it&#8217;s been a good year. Here&#8217;s to the next one.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2007/12/07/birthday-musings/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>On a haunted house</title>
		<link>http://sqlinthewild.co.za/index.php/2007/09/12/on-a-haunted-house/</link>
		<comments>http://sqlinthewild.co.za/index.php/2007/09/12/on-a-haunted-house/#comments</comments>
		<pubDate>Wed, 12 Sep 2007 21:10:45 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Roleplaying]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=28</guid>
		<description><![CDATA[The second session of the haunted house adventure went down far better than I could have ever hoped. In fact, the players asked to stay late so that they could finish it, they were having so much fun. They survived the haunted house and uncovered the reason behind all the strange occurrences. they couldn&#8217;t prevent [...]]]></description>
			<content:encoded><![CDATA[<p>The second session of the haunted house adventure went down far better than I could have ever hoped. In fact, the players asked to stay late so that they could finish it, they were having so much fun.</p>
<p>They survived the haunted house and uncovered the reason behind all the strange occurrences. they couldn&#8217;t prevent a thug from making off with the knife that had been the focus of all the strange events, but that&#8217;s fine. It adds possibilities for the future.</p>
<p>Everyone was enthusiastic, interested and most importantly, involved in the story. I&#8217;m still on a bit of a buzz from the game and I&#8217;m very psyched for the campaign.</p>
<p>Next up, depending on the players, either investigating the happenings at the cathedral, visiting a museum exhibit, or attending the cultural festival.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2007/09/12/on-a-haunted-house/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Back in the GM chair</title>
		<link>http://sqlinthewild.co.za/index.php/2007/08/30/back-in-the-gm-chair/</link>
		<comments>http://sqlinthewild.co.za/index.php/2007/08/30/back-in-the-gm-chair/#comments</comments>
		<pubDate>Thu, 30 Aug 2007 20:05:08 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Roleplaying]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=25</guid>
		<description><![CDATA[This last sunday saw me taking back the GM chair for the group that I play with. For the past year we&#8217;ve been playing my friend Phillip&#8217;s Per-rune game. (details and an in-character journal on my web site) My campaign is a modern day supernatural game, a bit like Buffy, but darker. It&#8217;s set in [...]]]></description>
			<content:encoded><![CDATA[<p>This last sunday saw me taking back the GM chair for the group that I play with. For the past year we&#8217;ve been playing my friend Phillip&#8217;s Per-rune game. (details and an in-character journal on my <a href="http://gail.rucus.net/Roleplaying/Guardian.php">web site</a>)</p>
<p>My campaign is a modern day supernatural game, a bit like Buffy, but darker. It&#8217;s set in the historical city of Oxford, in England, in the year 2002. More details are available on the <a href="http://gail.rucus.net/Roleplaying/Shadow.php">campaign web site</a>. The pages aren&#8217;t finished, there&#8217;s a lot of links that go no where.</p>
<p>All in all, the game went off without a hitch. Lots of admin-type stuff to start, reminders of clues, shopping, etc, etc but less than I expected.</p>
<p>Now let&#8217;s see if the characters can unravel the mysteries of a haunted house, and if they can survive to tell the tale.</p>
<p>I&#8217;ll probably comment here occationally on on significant bits of the campaign as they happen.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2007/08/30/back-in-the-gm-chair/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
