
<?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>daniel shiffman &#187; neural</title>
	<atom:link href="http://www.shiffman.net/category/neural/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shiffman.net</link>
	<description></description>
	<lastBuildDate>Wed, 08 Feb 2012 03:00:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Neural Network Turkey Recipes</title>
		<link>http://www.shiffman.net/2006/11/19/neural-network-turkey-recipes/</link>
		<comments>http://www.shiffman.net/2006/11/19/neural-network-turkey-recipes/#comments</comments>
		<pubDate>Mon, 20 Nov 2006 04:06:43 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[neural]]></category>
		<category><![CDATA[p5]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[teaching_]]></category>

		<guid isPermaLink="false">http://www.shiffman.net/2006/11/19/neural-network-turkey-recipes/</guid>
		<description><![CDATA[A first pass at my Neural Networks in processing tutorial is ready for public consumption. So, before you go and consume a turkey, consume this link. And let me know if it makes any sense at all. . .? The &#8230; <a href="http://www.shiffman.net/2006/11/19/neural-network-turkey-recipes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A first pass at my Neural Networks in processing tutorial is ready for public consumption.  So, before you go and consume a turkey,  consume <a href="http://www.shiffman.net/teaching/the-nature-of-code/nn/">this link</a>.   And let me know if it makes any sense at all. . .?  The examples are still trivial  &#8212; Linear classification, Solving XOR &#8212; but I hope to develop some more advanced pattern recognition examples soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shiffman.net/2006/11/19/neural-network-turkey-recipes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Multi-Layered Neural Network</title>
		<link>http://www.shiffman.net/2006/11/10/multi-layered-neural-network/</link>
		<comments>http://www.shiffman.net/2006/11/10/multi-layered-neural-network/#comments</comments>
		<pubDate>Fri, 10 Nov 2006 21:48:49 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[neural]]></category>
		<category><![CDATA[p5]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[teaching_]]></category>

		<guid isPermaLink="false">http://www.shiffman.net/2006/11/10/multi-layered-neural-network/</guid>
		<description><![CDATA[view applet and source So after a fierce battle with my own neurons, I am ready to release part II of my Processing series: &#8220;Neural Network! Huah! What is it good for? (Sing it again, now.)&#8221; This example implements a &#8230; <a href="http://www.shiffman.net/2006/11/10/multi-layered-neural-network/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.shiffman.net/itp/classes/nature/nn/xor/"><img src="http://www.shiffman.net/itp/classes/nature/nn/xor/xor.jpg" alt="nn" /></a><br />
<a href="http://www.shiffman.net/itp/classes/nature/nn/xor/">view applet and source</a></p>
<p>So after a fierce battle with my own neurons, I am ready to release part II of my <a href="http://www.processing.org">Processing</a> series: &#8220;Neural Network!  Huah!  What is it good for? (Sing it again, now.)&#8221;</p>
<p>This example implements a multi-layered neural network that learns via &#8220;back propogation.&#8221; It&#8217;s specifically trained to solve XOR.  In other words, there are two inputs and the desired result is input1 XOR input2.</p>
<p>0,1 &#8211;> 1<br />
1,0 &#8211;> 1<br />
0,0 &#8211;> 0<br />
1,1 &#8211;> 0</p>
<p>The structure looks something like this:</p>
<p><a href="http://www.flickr.com/photos/shiffman/293987721/" title="Photo Sharing"><img src="http://static.flickr.com/117/293987721_280d21ba51_m.jpg" width="240" height="180" alt="11102006163" /></a></p>
<p>However, I think there might be a flaw in my back propogation learning algorithm.  For whatever reason, with the above neural structure, I can only successfully train my network (starting with random connection weights between -1 and 1) approximately 60% of the time.  For the other 40%, the network gets stuck and can&#8217;t find the proper solution.  If I add two more neurons to the hidden layer, like so. . . </p>
<p><a href="http://www.flickr.com/photos/shiffman/293989845/" title="Photo Sharing"><img src="http://static.flickr.com/107/293989845_1ebffca388_m.jpg" width="240" height="180" alt="11102006164" /></a></p>
<p>. . . it trains flawlessly, finding a reasonable solution space after  a few thousand training iterations 100% of the time (or at least as far as I can reasonably test.)   What am I missing?</p>
<p>Anyway, a more involved tutorial about the theory, concepts, algorithms, and code behind neural networks is forthcoming. . . at some point. . .  after I invent that machine that makes time that is . .</p>
<p><del>If you are <a href="http://www.shiffman.net/itp/classes/nature/nn/xor/xor.zip">downloading the source</a>, note that the code for the nn.jar package is contained in /xor/code/src/nn.  Because I&#8217;m using a large number of classes in the design of the network, I didn&#8217;t want to restrict myself to Processing tabs.</del> Update (2/08/10): New download link: <a href="http://www.shiffman.net/teaching/nature/nn/">http://www.shiffman.net/teaching/nature/nn/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shiffman.net/2006/11/10/multi-layered-neural-network/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Perceptron</title>
		<link>http://www.shiffman.net/2006/11/06/perceptron/</link>
		<comments>http://www.shiffman.net/2006/11/06/perceptron/#comments</comments>
		<pubDate>Tue, 07 Nov 2006 02:57:34 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[ITP]]></category>
		<category><![CDATA[neural]]></category>
		<category><![CDATA[p5]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[teaching_]]></category>

		<guid isPermaLink="false">http://www.shiffman.net/2006/11/06/perceptron/</guid>
		<description><![CDATA[view applet and source Long overdue, I&#8217;ve started working on a series of]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.shiffman.net/itp/classes/nature/week10_s06/perceptron/"><img id="image145" src="http://www.shiffman.net/wp-content/uploads/2006/11/perceptron.jpg" alt="perceptron" /></a><br />
<a href="http://www.shiffman.net/itp/classes/nature/week10_s06/perceptron/">view applet and source</a></p>
<p>Long overdue, I&#8217;ve started working on a series of <a href="http://www.processing.org"Processing</a> examples that implement neural networks.  First up is the simplest, a little </a><a href="http://en.wikipedia.org/wiki/Perceptron">Perceptron</a> that learns whether points live on one side of a line (in Cartesian space) or the other.</p>
<p>y = x*0.9-0.2</p>
<p>In this example, the perceptron is trained via an array of known point objects (with known answers), and the resulting &#8220;guess&#8221; line is displayed in real-time.  I made the learning constant rather low so that one can see the slow progression of changing weights.  I&#8217;ve been spending some quality time with <a href="http://www.cs.unm.edu/~luger/index.html">Artifical Intelligence, by George Luger</a>.  It&#8217;s a wonderful book, and even better, it&#8217;s free for download online!</p>
<p>All the code is in the link, but here&#8217;s a quick peek at the meat of the matter: a function inside the Perceptron class that adjusts weights according to 3 input values and their corresponding &#8220;known&#8221; output.  (Note if the perceptron&#8217;s guess output produces the desired result, the weights are not changed.)</p>
<p>A more involved write-up will arrive online at some point. . .</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Function to train the Perceptron</span>
<span style="color: #666666; font-style: italic;">// Weights are adjusted based on &quot;desired&quot; answer</span>
<span style="color: #000066; font-weight: bold;">void</span> train<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> vals, <span style="color: #000066; font-weight: bold;">int</span> desired<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Sum all the weights</span>
  <span style="color: #000066; font-weight: bold;">float</span> sum <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> weights.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    sum <span style="color: #339933;">+=</span> vals<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span>weights<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #666666; font-style: italic;">// The result is the sign of the sum</span>
  <span style="color: #000066; font-weight: bold;">int</span> result <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Start with 1</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sum <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> result <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// If less than zero, change to -1</span>
  <span style="color: #666666; font-style: italic;">// Compute factor to change weight</span>
  <span style="color: #666666; font-style: italic;">// (DESIRED - RESULT): note this can only be 0, -2, or 2</span>
  <span style="color: #666666; font-style: italic;">// Multiply by learning constant</span>
  <span style="color: #000066; font-weight: bold;">float</span> weightChange <span style="color: #339933;">=</span> c<span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>desired <span style="color: #339933;">-</span> result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// Adjust weights based on weightChange * input</span>
  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> weights.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    weights<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+=</span> weightChange <span style="color: #339933;">*</span> vals<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>         
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>For related work, check out <a href="http://www.robotacid.com/PBeta/AILibrary/">Aaron Steed&#8217;s site</a>.</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.shiffman.net/2006/11/06/perceptron/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

