<?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>Manfredas Zabarauskas&#039; Blog &#187; Development</title>
	<atom:link href="http://blog.zabarauskas.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.zabarauskas.com</link>
	<description>We are what we repeatedly do; excellence, then, is not an act but a habit. -- Aristotle</description>
	<lastBuildDate>Tue, 29 Nov 2011 03:23:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Backpropagation Tutorial</title>
		<link>http://blog.zabarauskas.com/backpropagation-tutorial/</link>
		<comments>http://blog.zabarauskas.com/backpropagation-tutorial/#comments</comments>
		<pubDate>Sun, 17 Apr 2011 23:16:25 +0000</pubDate>
		<dc:creator>Manfredas Zabarauskas</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[applet]]></category>
		<category><![CDATA[backpropagation]]></category>
		<category><![CDATA[derivation]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[linear classifier]]></category>
		<category><![CDATA[multiple layer]]></category>
		<category><![CDATA[neural network]]></category>
		<category><![CDATA[perceptron]]></category>
		<category><![CDATA[single layer]]></category>
		<category><![CDATA[training]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.zabarauskas.com/?p=848</guid>
		<description><![CDATA[// // The PhD thesis of Paul J. Werbos at Harvard in 1974 described backpropagation as a method of teaching feed-forward artificial neural networks (ANNs). In the words of Wikipedia, it lead to a "rennaisance" in the ANN research in 1980s. As we will see later, it is an extremely straightforward technique, yet most of [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript">// <![CDATA[
 function show_multiplelayer_applet() { var html_element, body_element, p_element, text_node; html_element = document.documentElement; body_element = html_element.lastChild; applet_element = document.createElement("applet"); text_node = document.createTextNode("Cannot start the applet! Please install the Java Runtime Environment."); applet_element.appendChild(text_node); applet_element.setAttribute("code", "com.zabarauskas.ai1.MultipleLayerApplet"); applet_element.setAttribute("archive", "http://www.zabarauskas.com/downloads/ANNs/multilayer.jar"); applet_element.setAttribute("height", "0"); applet_element.setAttribute("width", "0"); body_element.appendChild(applet_element); }
// ]]&gt;</script><script type="text/javascript">// <![CDATA[
 function show_singlelayer_applet() { var html_element, body_element, p_element, text_node; html_element = document.documentElement; body_element = html_element.lastChild; applet_element = document.createElement("applet"); text_node = document.createTextNode("Cannot start the applet! Please install the Java Runtime Environment."); applet_element.appendChild(text_node); applet_element.setAttribute("code", "com.zabarauskas.ai1.SingleLayerApplet"); applet_element.setAttribute("archive", "http://www.zabarauskas.com/downloads/ANNs/singlelayer.jar"); applet_element.setAttribute("height", "0"); applet_element.setAttribute("width", "0"); body_element.appendChild(applet_element); }
// ]]&gt;</script>The PhD thesis of <a href="http://en.wikipedia.org/wiki/Paul_Werbos" target="_blank">Paul J. Werbos</a> at Harvard in 1974 described backpropagation as a method of teaching <a href="http://en.wikipedia.org/wiki/Feedforward_neural_network" target="_blank">feed-forward artificial neural networks</a> (ANNs). In the words of Wikipedia, it lead to a "rennaisance" in the ANN research in 1980s.</p>
<p>As we will see later, it is an extremely straightforward technique, yet most of the tutorials online seem to skip a fair amount of details. Here's a simple (yet still thorough and mathematical) tutorial of how backpropagation works from the ground-up; together with a couple of example applets. Feel free to play with them (and watch the videos) to get a better understanding of the methods described below!</p>
<input type="submit" name="sub_button" onclick="javascript:show_singlelayer_applet()" style="width: 305px; float: left;" value="Launch the single-layer neural network applet!" width="305">
<input type="submit" name="sub_button" style="width: 305px; float: right;" onclick="javascript:show_multiplelayer_applet()" value="Launch the multilayer neural network applet!" width="305">
<p><small><div class="wp-caption alignleft" style="width: 304px"><iframe title="YouTube video player" width="293" height="336" src="http://www.youtube.com/embed/D8iMDH5va9M" frameborder="0" allowfullscreen></iframe><p class="wp-caption-text">Training a single perceptron (linear classifier)</p></div> <div class="wp-caption alignright" style="width: 304px"><iframe title="YouTube video player" width="293" height="336" src="http://www.youtube.com/embed/fAKwocta2wM" frameborder="0" allowfullscreen></iframe><p class="wp-caption-text">Training a multilayer neural network</p></div></small><br />
&nbsp;<br />
&nbsp; </p>
<p><strong>1. Background</strong></p>
<p>To start with, imagine that you have gathered some empirical data relevant to the situation that you are trying to predict - be it fluctuations in the stock market, chances that a tumour is benign, likelihood that the picture that you are seeing is a face or (like in the applets above) the coordinates of red and blue points.</p>
<p>We will call this data <em>training examples</em> and we will describe <script type='math/tex'>i</script><sup>th</sup> training example as a tuple <script type='math/tex'>(\vec{x_i}, y_i)</script>, where <script type='math/tex'>\vec{x_i} \in \mathbb{R}^n</script> is a vector of inputs and <script type='math/tex'>y_i \in \mathbb{R}</script> is the observed output.</p>
<p>Ideally, our neural network should output <script type='math/tex'>y_i</script> when given <script type='math/tex'>\vec{x_i}</script> as an input. In case that does not always happen, let's define the <em>error </em>measure as a simple squared distance between the actual observed output and the prediction of the neural network: <script type='math/tex'>E := \sum_i (h(\vec{x_i}) - y_i)^2</script>, where <script type='math/tex'>h(\vec{x_i})</script> is the output of the network.</p>
<p><strong>2. Perceptrons (building-blocks)</strong></p>
<p>The simplest classifiers out of which we will build our neural network are <a href="http://en.wikipedia.org/wiki/Perceptron" target="_blank"><em>perceptrons</em></a> (fancy name thanks to <a href="http://en.wikipedia.org/wiki/Frank_Rosenblatt" target="_blank">Frank Rosenblatt</a>). In reality, a perceptron is a plain-vanilla linear classifier which takes a number of inputs <script type='math/tex'>a_1, ..., a_n</script>, scales them using some weights <script type='math/tex'>w_1, ..., w_n</script>, adds them all up (together with some bias <script type='math/tex'>b</script>) and feeds everything through an <em>activation function</em> <script type='math/tex'>\sigma \in \mathbb{R} \rightarrow \mathbb{R}</script>.</p>
<p>A picture is worth a thousand equations:</p>
<p><small><div class="wp-caption aligncenter" style="width: 244px"><img title="Perceptron (linear classifier)" src="http://blog.zabarauskas.com/img/perceptron.gif" alt="Perceptron (linear classifier)" width="234" height="140" /><p class="wp-caption-text">Perceptron (linear classifier)</p></div></small></p>
<p>To slightly simplify the equations, define <script type='math/tex'>w_0 := b</script> and <script type='math/tex'>a_0 := 1</script>. Then the behaviour of the perceptron can be described as <script type='math/tex'>\sigma(\vec{a} \cdot \vec{w})</script>, where <script type='math/tex'>\vec{a} := (a_0, a_1, ..., a_n)</script> and <script type='math/tex'>\vec{w} := (w_0, w_1, ..., w_n)</script>.</p>
<p>To complete our definition, here are a few examples of typical activation functions:</p>
<ul>
<li><em>sigmoid:</em> <script type='math/tex'>\sigma(x) = \frac{1}{1 + \exp(-x)}</script>,</li>
<li><em>hyperbolic tangent:</em> <script type='math/tex'>\sigma(x) = \tanh(x)</script>,</li>
<li>plain <em>linear</em> <script type='math/tex'>\sigma(x) = x</script> and so on.</li>
</ul>
<p>Now we can finally start building neural networks.<span id="more-848"></span> The simplest kind of network that we can build is... exactly, one perceptron! Here's how we can train it to classify things!</p>
<p><strong>3. Single-layer neural network</strong></p>
<p>We defined the <em>error</em> earlier as <script type='math/tex'>E := \sum_i (h(\vec{x_i}) - y_i)^2</script>. Obviously, since we are using a single perceptron both our error and the output of the network (<script type='math/tex'>h_{\vec{w}}(\vec{x_i}) = \sigma(\vec{w} \cdot \vec{x_i})</script>) depend on the weights vector <script type='math/tex'>\vec{w}</script>.</p>
<p>Incorporating those observations into the updated error measure we obtain <script type='math/tex'>E(\vec{w}) := \sum_i (h_{\vec{w}}(\vec{x_i}) - y_i)^2</script>.</p>
<p>Our goal is to find such a vector of weights <script type='math/tex'>\vec{w}</script> that <script type='math/tex'>E(\vec{w})</script> is minimised - that way our perceptron will correctly predict the output for all inputs of our training examples!</p>
<p>We will do that by applying the <em>gradient descent</em> algorithm: in essence we will treat the error as a surface in <em>n</em>-dimensional space, then we will find a greatest downwards slope at the current point <script type='math/tex'>\vec{w_t}</script> and will go in that direction to obtain <script type='math/tex'>\vec{w}_{t+1}</script>. This way hopefully we will find a minimum point on the error surface and we will use the coordinates of that point as the final weight vector.</p>
<p>By skipping a great deal of maths on whether the minimum point exists, is it unique and global, can we "overjump" it by accident, what are the conditions for the following partial derivatives to exist, etc, etc; we will dive straight in hoping for the best and will calculate the <em><a href="http://en.wikipedia.org/wiki/Gradient" target="_blank">gradient</a></em> of the error surface at <script type='math/tex'>\vec{w_t}</script>. Then we will take a step in the opposite direction of the gradient (i.e. in the direction of the fastest decreasing slope on the error surface) to obtain <script type='math/tex'>\vec{w}_{t + 1}</script>.</p>
<p>To express it in a slightly more mathematical way, we will start with some <em>randomized (!) </em>weight vector <script type='math/tex'>\vec{w_0}</script> and will train our perceptron by updating the weights</p>
<p>\begin{align} \vec{w}_{t+1} := \vec{w_t} - \eta \frac{\partial E(\vec{w})}{\partial \vec{w}} \bigg|_{\vec{w_t}}, \end{align}</p>
<p>where <script type='math/tex'>\eta</script> is known as a <em>learning rate</em> (a simple scaling factor that typically ranges between zero and one).</p>
<p>Observe that</p>
<p>\begin{align} \frac{\partial E(\vec{w})}{\partial \vec{w}} = \left( \frac{\partial E(\vec{w})}{\partial w_0},\frac{\partial E(\vec{w})}{\partial w_1}, ... ,\frac{\partial E(\vec{w})}{w_n} \right), \end{align}</p>
<p>and we can calculate</p>
<p>\begin{align} \frac{\partial E(\vec{w})}{\partial w_j} &#038;= \frac{\partial}{\partial w_j} \sum_i (h_{\vec{w}}(\vec{x_i}) - y_i)^2 \\ &#038;= \sum_i 2(h_{\vec{w}}(\vec{x_i}) - y_i) \frac{\partial}{\partial w_j} (h_{\vec{w}}(\vec{x_i}) - y_i) \\ &#038;= \sum_i 2(h_{\vec{w}}(\vec{x_i}) - y_i) \frac{\partial}{\partial w_j} \sigma(\vec{x_i} \cdot \vec{w}) \\ &#038;= \sum_i 2(h_{\vec{w}}(\vec{x_i}) - y_i) \; \sigma ' (\vec{x_i} \cdot \vec{w}) \frac{d}{d w_j} \vec{x_i} \cdot \vec{w} \\ &#038;= \sum_i 2(h_{\vec{w}}(\vec{x_i}) - y_i) \; \sigma ' (\vec{x_i} \cdot \vec{w}) \frac{d}{d w_j} \sum_{k=1}^n a_k w_k \\ &#038;= 2 a_j \sum_i (h_{\vec{w}}(\vec{x_i}) - y_i) \; \sigma ' (\vec{x_i} \cdot \vec{w}) \end{align}</p>
<p>for each <script type='math/tex'>0 \leq j \leq n</script>.</p>
<p><strong>3.1. <em>Example single-layer neural network</em></strong></p>
<input type="submit" name="sub_button" onclick="javascript:show_singlelayer_applet()" style="width: 600px;" value="Launch the example single-layer neural network applet" width="600">
<p>In this applet, a perceptron takes two inputs (normalized <em>x</em> and <em>y</em> coordinates, i.e. <script type='math/tex'>a_1 = in_x</script>, <script type='math/tex'>a_2 = in_y</script>) and uses sigmoid as an activation function with the learning rate <script type='math/tex'>\eta = 0.1</script>.</p>
<p>Then, using a previous general result</p>
<p>\begin{align} \frac{\partial E(\vec{w})}{\partial w_j} &#038;= 2 a_j \sum_i (h_{\vec{w}}(\vec{x_i}) - y_i) \; \sigma ' (\vec{x_i} \cdot \vec{w}) \\ &#038;= 2 a_j \sum_i (\sigma(\vec{w} \cdot \vec{x_i}) - y_i) \sigma(\vec{x_i} \cdot \vec{w}) (1 - \sigma(\vec{x_i} \cdot \vec{w})), \end{align}</p>
<p>(since for the sigmoid activation function <script type='math/tex'>\sigma ' (x) = \sigma(x) (1 - \sigma(x))</script>); and thus</p>
<p>\begin{align} \frac{\partial E(\vec{w})}{\partial \vec{w}} = 2 \vec{a} \sum_i (\sigma(\vec{w} \cdot \vec{x_i}) - y_i) \sigma(\vec{x_i} \cdot \vec{w}) (1 - \sigma(\vec{x_i} \cdot \vec{w})), \end{align}</p>
<p>where <script type='math/tex'>\vec{a} = (1, in_x, in_y)</script>.</p>
<p>The final algorithm to update the weight vector <script type='math/tex'>\vec{w} = (w_0, w_1, w_2)</script> (which is initially randomized) then is</p>
<p>\begin{align} \vec{w}_{t+1} := \vec{w_t} - 0.2 \vec{a} \sum_i (h_{\vec{w}_t}(\vec{x_i}) - y_i) h_{\vec{w}_t}(\vec{x_i}) (1 - h_{\vec{w}_t}(\vec{x_i})), \end{align}</p>
<p>where <script type='math/tex'>h_{\vec{w}_t}(\vec{x_i}) = \sigma(\vec{w}_t \cdot \vec{x_i})</script>.</p>
<p>However, a single perceptron is extremely limited in the sense that different classes of examples must be separable with a hyperplane (hence the name, <em>linear </em>classifier), which is usually not the case in real-life applications.</p>
<p>Time to bump things up a notch: let's connect a few of them together to obtain a multilayer feed-forward neural network!</p>
<p><strong>4. Multilayer neural network</strong></p>
<p>Let's consider a general case first: a completely unrestricted feed-forward structure (with the only condition being that there are no loops between the perceptrons to avoid general madness and chaos). </p>
<p>Since it is structurally more complex than just a single perceptron, take a look at the following figure that explains some more notation:</p>
<p><small><div class="wp-caption aligncenter" style="width: 625px"><img title="Multilayer neural network" src="http://blog.zabarauskas.com/img/multilayer.gif" alt="Multilayer neural network" width="615" height="291" /><p class="wp-caption-text">Multilayer neural network</p></div></small></p>
<p>Here the weight <script type='math/tex'>w_{i \rightarrow j}</script> connects perceptrons <script type='math/tex'>i</script> and <script type='math/tex'>j</script>, the sum of the weighed inputs of perceptron <script type='math/tex'>j</script> is denoted by <script type='math/tex'>s_j := \sum_k z_k w_{k \rightarrow j}</script> where <script type='math/tex'>k</script> iterates over all perceptrons connected to <script type='math/tex'>j</script>, and the output of <script type='math/tex'>j</script> is written as <script type='math/tex'>z_j := \sigma(s_j)</script>, where <script type='math/tex'>\sigma</script> is <script type='math/tex'>j</script>'s activation function.</p>
<p>We will use the same error measure <script type='math/tex'>E(\vec{w}) := \sum_i (h_{\vec{w}}(\vec{x_i}) - y_i)^2</script>, except now the weights vector <script type='math/tex'>\vec{w}</script> will contain all the weights in the network, i.e. <script type='math/tex'>\vec{w} = (\;\;w_{i \rightarrow j}\;\;)</script> for all <script type='math/tex'>i, j</script>.</p>
<p>To find <script type='math/tex'>\vec{w}</script> that minimizes <script type='math/tex'>E(\vec{w})</script> using gradient descent we have to calculate <script type='math/tex'>\frac{\partial E(\vec{w})}{\partial \vec{w}}</script> (again). However, this time it is (very slightly) more involved.</p>
<p>First of all let's separate the contributions of individual training examples to the overall error using the following observation:<br />
\begin{align} \frac{\partial E(\vec{w})}{\partial \vec{w}} = \sum_i \frac{\partial E_i(\vec{w})}{\partial \vec{w}}, \end{align}<br />
where <script type='math/tex'>E_i(\vec{w}) = (h_{\vec{w}}(\vec{x_i}) - y_i)^2</script>.</p>
<p>Then</p>
<p>\begin{align} \frac{\partial E_i(\vec{w})}{\partial w_{j \rightarrow k}} &#038;= \frac{\partial}{\partial w_{j \rightarrow k}} (h_{\vec{w}}(\vec{x_i}) - y_i)^2 \\ &#038;= 2 (h_{\vec{w}}(\vec{x_i}) - y_i) \frac{\partial h_{\vec{w}}(\vec{x_i})}{\partial w_{j \rightarrow k}} \\ &#038;=  2 (h_{\vec{w}}(\vec{x_i}) - y_i) \frac{\partial h_{\vec{w}}(\vec{x_i})}{\partial s_k} \frac{\partial s_k}{\partial w_{j \rightarrow k}} \\ &#038;= 2 (h_{\vec{w}}(\vec{x_i}) - y_i) \frac{\partial h_{\vec{w}}(\vec{x_i})}{\partial s_k} z_j. \end{align}</p>
<p>If <script type='math/tex'>k</script> is an output node, then<br />
\begin{align} \frac{\partial h_{\vec{w}}(\vec{x_i})}{\partial s_k} = \frac{d \;\; \sigma(s_k)}{d \; s_k}  = \sigma' (s_k)\end{align}<br />
and thus<br />
\begin{align} \frac{\partial E_i(\vec{w})}{\partial w_{j \rightarrow k}} &#038;= 2 (h_{\vec{w}}(\vec{x_i}) - y_i) \; \sigma ' (s_k)\; z_j. \end{align}</p>
<p>However, if <script type='math/tex'>k</script> is not an output node, then a change in <script type='math/tex'>s_k</script> can affect all the nodes which are connected to <script type='math/tex'>k</script>'s output, i.e.<br />
\begin{align} \frac{\partial h_{\vec{w}}(\vec{x_i})}{\partial s_k} &#038;= \frac{\partial h_{\vec{w}}(\vec{x_i})}{\partial z_k} \frac{\partial z_k}{\partial s_k} \\ &#038;= \frac{\partial h_{\vec{w}}(\vec{x_i})}{\partial z_k} \sigma ' (s_k) \\ &#038;= \sum_{o \in \{ v \; | \; v \text{ is connected to } k \}} \frac{\partial h_{\vec{w}}(\vec{x_i})}{\partial s_o} \frac{\partial s_o}{\partial z_k} \sigma ' (s_k) \\ &#038;= \sum_{o \in \{ v \; | \; v \text{ is connected to } k \}} \frac{\partial h_{\vec{w}}(\vec{x_i})}{\partial s_o} w_{k \rightarrow o} \; \sigma ' (s_k), \end{align}<br />
... and we are almost done! All what is left to do is to place the <script type='math/tex'>i</script><sup>th</sup> example at the inputs of our neural network, calculate <script type='math/tex'>s_k</script> and <script type='math/tex'>z_k</script> for all the nodes (the <em>forward-propagation</em> step) and to work our way backwards from the output node calculating <script type='math/tex'>\frac{\partial h_{\vec{w}}(\vec{x_i})}{\partial s_k}</script> (hence the name, <em>backpropagation</em>).</p>
<p>To summarize, if <script type='math/tex'>k</script> is an output node, then</p>
<p>\begin{align} \frac{\partial E_i(\vec{w})}{\partial w_{j \rightarrow k}} &#038;= 2 (h_{\vec{w}}(\vec{x_i}) - y_i) \; \sigma ' (s_k)\; z_j, \end{align}</p>
<p>otherwise</p>
<p>\begin{align} \frac{\partial E_i(\vec{w})}{\partial w_{j \rightarrow k}} &#038;= 2 (h_{\vec{w}}(\vec{x_i}) - y_i) \; \sigma ' (s_k)\; z_j \sum_{o \in \{ v \; | \; v \text{ conn. to } k \}} \frac{\partial h_{\vec{w}}(\vec{x_i})}{\partial s_o} w_{k \rightarrow o}. \end{align}</p>
<p>Then after the following is obtained<br />
\begin{align} \frac{\partial E_i(\vec{w})}{\partial \vec{w}} = \left( \; \; \frac{\partial E_i(\vec{w})}{\partial w_{j \rightarrow k}}   \; \; \right), \forall j, k \end{align}<br />
the weight vector can either be updated in one go (<em>batch</em> update)<br />
\begin{align} \vec{w}_{t+1} := \vec{w_t} - \eta \frac{\partial E(\vec{w})}{\partial \vec{w}} \bigg|_{\vec{w_t}} =  \vec{w_t} - \eta \sum_i \frac{\partial E_i(\vec{w})}{\partial \vec{w}}\bigg|_{\vec{w_t}}, \end{align}<br />
or it can be updated <em>sequentially</em> using one training example at a time:<br />
\begin{align} \vec{w}_{t+1} := \vec{w_t} - \eta \frac{\partial E_i(\vec{w})}{\partial \vec{w}} \bigg|_{\vec{w_t}}.\end{align}</p>
<p><strong>4.1. <em>Example multilayer network</em></strong></p>
<input type="submit" name="sub_button" onclick="javascript:show_multiplelayer_applet()" style="width: 600px;" value="Launch the example multilayer neural network applet" width="600">
<p>If you launch and play with the applet above, you will see that it is able to separate classes non-linearly (indicating that it's using more than one perceptron). It is built using this two-layer neural network:</p>
<p><small><div class="wp-caption aligncenter" style="width: 440px"><img title="Two-layer neural network example" src="http://blog.zabarauskas.com/img/multilayer_example.gif" alt="Two-layer neural network example" width="430" height="297" /><p class="wp-caption-text">Two-layer neural network example</p></div></small></p>
<p>The weights vector <script type='math/tex'>\vec{w}</script> contains all the weights in the network, i.e.<br />
\begin{align} \vec{w} = ( w_{in_1 \rightarrow 1}, w_{in_x \rightarrow 1}, w_{in_y \rightarrow 1}, w_{in_1 \rightarrow 2}, ..., w_{in_y \rightarrow 5}, w_{in_1 \rightarrow 6}, w_{1 \rightarrow 6}, w_{2 \rightarrow 6}, ..., w_{5 \rightarrow 6}). \end{align}</p>
<p>Each perceptron is using <i>sigmoid</i> as its activation function and the output of the perceptron <script type='math/tex'>6</script> is the output for the whole network, i.e. <script type='math/tex'>h_{\vec{w}}(\vec{x_i}) = z_6</script>.</p>
<p>Then an individual point <i>i</i> (with <i>x</i> and <i>y</i> coordinates normalized) is considered as an <script type='math/tex'>i</script><sup>th</sup> training example and fed through the network. While it's being propagated, each <script type='math/tex'>s_i</script> and <script type='math/tex'>z_i</script> for <script type='math/tex'>i = 1, ..., 6</script> are stored.</p>
<p>Then the gradient of an <script type='math/tex'>i</script><sup>th</sup> error surface is calculated as follows:<br />
\begin{align}<br />
\frac{\partial E_i(\vec{w})}{\partial \vec{w}} &#038;= \left( \frac{\partial E_i(\vec{w})}{\partial w_{in_1 \rightarrow 1}},\frac{\partial E_i(\vec{w})}{\partial w_{in_x \rightarrow 1}}, ..., \frac{\partial E_i(\vec{w})}{\partial w_{in_y \rightarrow 5}},\frac{\partial E_i(\vec{w})}{\partial w_{in_1 \rightarrow 6}},\frac{\partial E_i(\vec{w})}{\partial w_{1 \rightarrow 6}},\frac{\partial E_i(\vec{w})}{\partial w_{2 \rightarrow 6}}, ..., \frac{\partial E_i(\vec{w})}{\partial w_{5 \rightarrow 6}} \right) , \end{align}<br />
where<br />
\begin{align} \frac{\partial E_i(\vec{w})}{\partial w_{in_1 \rightarrow 1}} &#038;= 2 (h_{\vec{w}}(\vec{x_i}) - y_i) \; \sigma ' (s_1)\; \frac{\partial h_{\vec{w}}(\vec{x_i})}{\partial s_6} w_{1 \rightarrow 6} \\<br />
&#038;= 2 (z_6 - y_i) \; \sigma (s_1) \; (1 -  \sigma (s_1)) \; \sigma (s_6) \; (1 - \sigma (s_6)) \; w_{1 \rightarrow 6}, \\<br />
\frac{\partial E_i(\vec{w})}{\partial w_{in_x \rightarrow 1}} &#038;= 2 (z_6 - y_i) \; \sigma (s_1) \; (1 -  \sigma (s_1)) \; {in}_x \; \sigma (s_6) \; (1 - \sigma (s_6)) \; w_{1 \rightarrow 6}, \\<br />
&#038; \vdots \\<br />
\frac{\partial E_i(\vec{w})}{\partial w_{in_y \rightarrow 5}} &#038;= 2 (z_6 - y_i) \; \sigma (s_5) \; (1 -  \sigma (s_5)) \; {in}_y \; \sigma (s_6) \; (1 - \sigma (s_6)) \; w_{5 \rightarrow 6}, \\<br />
\frac{\partial E_i(\vec{w})}{\partial w_{in_1 \rightarrow 6}} &#038;= 2 (h_{\vec{w}}(\vec{x_i}) - y_i) \; \sigma ' (s_6) \\<br />
&#038;= 2 (z_6 - y_i) \; \sigma (s_6) \; (1 -  \sigma (s_6)) , \\<br />
\frac{\partial E_i(\vec{w})}{\partial w_{1 \rightarrow 6}} &#038;= 2 (z_6 - y_i) \; \sigma (s_6) \; (1 -  \sigma (s_6)) \; z_1, \\<br />
\frac{\partial E_i(\vec{w})}{\partial w_{2 \rightarrow 6}} &#038;= 2 (z_6 - y_i) \; \sigma (s_6) \; (1 -  \sigma (s_6)) \; z_2, \\<br />
&#038; \vdots \\<br />
\frac{\partial E_i(\vec{w})}{\partial w_{5 \rightarrow 6}} &#038;= 2 (z_6 - y_i) \; \sigma (s_6) \; (1 -  \sigma (s_6)) \; z_5.<br />
\end{align}</p>
<p>Finally, the network is sequentially trained with the learning rate <script type='math/tex'>\eta = 0.5</script> (starting with a random initial weight vector <script type='math/tex'>w_0</script>)<br />
\begin{align} \vec{w}_{t+1} := \vec{w_t} - 0.5 \frac{\partial E_i(\vec{w})}{\partial \vec{w}} \bigg|_{\vec{w_t}}.\end{align}</p>
<p>That's it, I hope it sheds some light on the backpropagation!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zabarauskas.com/backpropagation-tutorial/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Halfway There</title>
		<link>http://blog.zabarauskas.com/halfway-there/</link>
		<comments>http://blog.zabarauskas.com/halfway-there/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 12:57:39 +0000</pubDate>
		<dc:creator>Manfredas Zabarauskas</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[cambridge university]]></category>
		<category><![CDATA[formal]]></category>
		<category><![CDATA[internship]]></category>
		<category><![CDATA[lent]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[redmoind]]></category>
		<category><![CDATA[sdet]]></category>
		<category><![CDATA[seattle]]></category>
		<category><![CDATA[software development engineer in test]]></category>
		<category><![CDATA[truemobilecoverage]]></category>

		<guid isPermaLink="false">http://blog.zabarauskas.com/?p=729</guid>
		<description><![CDATA[Another term in Cambridge has gone by - four out of nine to go. In the meantime, here's a quick update of what I've been up to in the past few months. 1. Microsoft internship In January I had the opportunity to visit Microsoft's headquarters in Redmond, WA, to interview for the Software Development Engineer [...]]]></description>
			<content:encoded><![CDATA[<p><em>Another term in Cambridge has gone by - four out of nine to go. In the meantime, here's a quick update of what I've been up to in the past few months.</em></p>
<p><strong>1. Microsoft internship</strong></p>
<p><small><div class="wp-caption alignright" style="width: 160px">
<a href="http://blog.zabarauskas.com/img/seattle2.jpg" title="Redmond, WA, 2011" class="thickbox" rel="singlepic39" >
	<img class="ngg-singlepic" src="http://blog.zabarauskas.com/wp-content/gallery/cache/39__150x113_seattle2.jpg" alt="Redmond, WA, 2011" title="Redmond, WA, 2011" />
</a>
<p class="wp-caption-text">Redmond, WA, 2011</p></div></small></p>
<p>In January I had the opportunity to visit <a href="http://www.microsoft.com" target="_blank">Microsoft</a>'s headquarters in Redmond, WA, to interview for the <i>Software Development Engineer in Test</i> intern position in the <a href="http://office.microsoft.com" target="_blank">Office</a> team. In short - a great trip, in every aspect.</p>
<p>I left London Heathrow on January 11th, 2:20 PM and landed in Seattle Tacoma at 4:10 PM (I suspect that there might have been a few time zones in between those two points). I arrived in Mariott Redmond roughly an hour later, which meant that because of my anti-jetlag technique (<i>"do not go to bed until 10-11 PM in the new timezone no matter what"</i>) I had a few hours to kill. Ample time to unpack, grab a dinner in Mariott's restaurant and go for a short stroll around Redmond before going to sleep.</p>
<p>On the next day I had four interviews arranged. The interviews themselves were absolutely stress-free, it felt more like a chance to meet and have a chat with some properly smart (and down-to-earth) folks.<small><div class="wp-caption alignright" style="width: 310px">
<a href="http://blog.zabarauskas.com/img/seattle1_full.jpg" title="Top of the Space Needle. Seattle, WA, 2011" class="thickbox" rel="singlepic38" >
	<img class="ngg-singlepic" src="http://blog.zabarauskas.com/wp-content/gallery/cache/38__300x225_seattle1_full.jpg" alt="Top of the Space Needle. Seattle, WA, 2011" title="Top of the Space Needle. Seattle, WA, 2011" />
</a>
<p class="wp-caption-text">Top of the <a href='http://en.wikipedia.org/wiki/Space_Needle' target='_blank'>Space Needle</a>. Seattle, WA, 2011</p></div></small>  The structure of the interviews seemed fairly typical: each interview consisted of some algorithm/data structure problems, a short discussion about the past experience and the opportunity to ask questions (obviously a great chance to learn more about the team/company/company culture, etc). Since this was my third round of summer internship applications (I have worked as a software engineer for <a href="http://www.wolfsonmicro.com" target="_blank">Wolfson Microelectronics</a> in '09 and <a href="http://www.ms.com" target="_blank">Morgan Stanley</a> in '10), everything made sense and was pretty much what I expected.</p>
<p>My trip ended with a quick visit to Seattle on the next day: a few pictures of the Space Needle, a cup of Seattle's Best Coffee and there I was on my flight back to London, having spent $0.00 (yeap, Microsoft paid for everything - flights, hotel, meals, taxis, etc). Even so, the best thing about Microsoft definitely seemed to be the people working there; since I have received and accepted the offer, we'll see if my opinion remains unchanged after this summer!</p>
<p><strong>2. Lent term v2.0</strong></p>
<p><small><div class="wp-caption alignleft" style="width: 130px"><a href="http://truemobilecoverage.com" target="_blank"><img alt="TrueMobileCoverage group project" src="http://blog.zabarauskas.com/img/tmc1.jpg" title="TrueMobileCoverage group project" width="120" height="120" /></a><p class="wp-caption-text"><a href='http://truemobilecoverage.com' target='_blank'>TrueMobileCoverage</a> group project</p></div></small></p>
<p>Well, things are still picking up the speed. Seven courses with twenty-eight supervisions in under two months, plus managing a <a href="http://truemobilecoverage.com" target="_blank">group project</a> (crowd-sourcing mobile network signal strength, the link is on the left), a few basketball practices each week on top of that and you'll see a reason why this blog has not been updated for a couple of months.</p>
<p>It's not all doom and gloom, of course. Courses themselves are great, lecturers make some decently convoluted material understandable in minutes and an occasional <a href="http://en.wikipedia.org/wiki/Formal_%28university%29" target="_blank">formal hall</a> (e.g. below) also helps. </p>
<p>All in all, my opinion, that Cambridge provides a great opportunity to learn a huge amount of material in a very short timeframe, remains unchanged.</p>
<p><i>There will be more to come about some cool things that I've learnt in separate posts, but now speaking of learning - it's revision time... &#58;-)</i></p>
<p><small><div class="wp-caption alignleft" style="width: 610px"><img alt="Me and Ada at the CompSci formal. Cambridge, England, 2011" src="http://blog.zabarauskas.com/img/formal1.jpg" title="Me and Ada at the CompSci formal hall. Cambridge, England, 2011" width="600" height="500" /><p class="wp-caption-text">Me and Ada at the CompSci formal. Cambridge, England, 2011</p></div></small></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zabarauskas.com/halfway-there/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Conway&#039;s Game of Life (cont.)</title>
		<link>http://blog.zabarauskas.com/conways-game-of-life-cont/</link>
		<comments>http://blog.zabarauskas.com/conways-game-of-life-cont/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 16:40:30 +0000</pubDate>
		<dc:creator>Manfredas Zabarauskas</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[altera]]></category>
		<category><![CDATA[conway]]></category>
		<category><![CDATA[de2]]></category>
		<category><![CDATA[fpga]]></category>
		<category><![CDATA[game of life]]></category>

		<guid isPermaLink="false">http://blog.zabarauskas.com/?p=697</guid>
		<description><![CDATA[&#34;Beauty in things exists in the mind which contemplates them.&#34; - David Hume (1711-1776) Conway's Game of Life theme continues. Here is a short video with the Game of Life, this time running on Altera DE2 FPGA board with custom soft MIPS CPU.]]></description>
			<content:encoded><![CDATA[<p><i>
<p style="text-align: right;">&quot;Beauty in things exists in the mind which contemplates them.&quot;<br />
- David Hume (1711-1776)</p>
<p></i></p>
<p><a href="http://conwaylife.com/wiki/index.php?title=Main_Page" target="_blank">Conway's Game of Life</a> theme <a href="http://blog.zabarauskas.com/conways-game-of-life/" target="_blank">continues</a>. Here is a short video with the Game of Life, this time running on Altera DE2 <a href="http://en.wikipedia.org/wiki/Field-programmable_gate_array" target="_blank">FPGA</a> board with custom soft MIPS CPU.</p>
<p><small><div class="wp-caption alignleft" style="width: 610px"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="600" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/FRU_v3cGjmo?fs=1&amp;hl=en_US&amp;rel=0" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="600" height="344" src="http://www.youtube.com/v/FRU_v3cGjmo?fs=1&amp;hl=en_US&amp;rel=0" allowscriptaccess="always" allowfullscreen="true"></embed></object><p class="wp-caption-text">Game of Life running on Altera DE2 FPGA board.</p></div></small></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zabarauskas.com/conways-game-of-life-cont/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Morgan Stanley Internship</title>
		<link>http://blog.zabarauskas.com/morgan-stanley-internship/</link>
		<comments>http://blog.zabarauskas.com/morgan-stanley-internship/#comments</comments>
		<pubDate>Sat, 23 Oct 2010 21:39:55 +0000</pubDate>
		<dc:creator>Manfredas Zabarauskas</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[globalaxe]]></category>
		<category><![CDATA[internship]]></category>
		<category><![CDATA[majorca]]></category>
		<category><![CDATA[mallorca]]></category>
		<category><![CDATA[morgan stanley]]></category>

		<guid isPermaLink="false">http://blog.zabarauskas.com/?p=649</guid>
		<description><![CDATA[Last week I received a short e-mail from my former manager at Morgan Stanley: "Hi Manfred, Just to let you know that GlobalAxe all went live last week and so far no issues at all." Since the people on the trading floor started using my system and it seems to be standing on its feet [...]]]></description>
			<content:encoded><![CDATA[<p><small><div class="wp-caption alignright" style="width: 310px">
<a href="http://blog.zabarauskas.com/img/ms2.jpg" title="After work (Canary Wharf, 2010)" class="thickbox" rel="singlepic17" >
	<img class="ngg-singlepic" src="http://blog.zabarauskas.com/wp-content/gallery/cache/17__300x400_ms2.jpg" alt="After work (Canary Wharf, 2010)" title="After work (Canary Wharf, 2010)" />
</a>
<p class="wp-caption-text">After work (Canary Wharf, 2010)</p></div></small>Last week I received a short e-mail from my former manager at Morgan Stanley:</p>
<p><em>"Hi Manfred,</em></p>
<p><em>Just to let you know that GlobalAxe all went live last week and so far no issues at all."</em></p>
<p>Since the people on the trading floor started using my system and it seems to be standing on its feet so far, it probably is a good time to recap on what had happened over my ten week internship at Morgan Stanley.</p>
<p>I was working as technology analyst in <a href="http://en.wikipedia.org/wiki/Repurchase_agreement" target="_blank">repo</a> trading team (in institutional securities group). My task was to develop and integrate a new screen into trading software, to create an associated e-mail subsystem generating daily/weekly reports for senior executives and to code a website which would provide access to the data for executives/sales people without the trading software on their machines.</p>
<p>Development-wise it involved working with quite a wide range of technologies, such as C# and <a href="http://en.wikipedia.org/wiki/Composite_UI_Application_Block" target="_blank">CAB</a> for UI development, Java/Spring for e-mail report generation/server backend, MVC under ASP.NET for the website, Transact-SQL for Sybase DB backend; everything interconnected with SOAP/XML and distributed locally over in-house <a href="http://en.wikipedia.org/wiki/Publish/subscribe" target="_blank">pubsub</a> systems or through IBM's MQ for inter-continental data transactions.</p>
<p>Even though working and learning about all these technologies was fun on it's own right, the best thing I would say about my experience was the people. <small><div class="wp-caption alignleft" style="width: 316px">
<a href="http://blog.zabarauskas.com/img/ms1.jpg" title="Night at Canary Wharf, 2010" class="thickbox" rel="singlepic15" >
	<img class="ngg-singlepic" src="http://blog.zabarauskas.com/wp-content/gallery/cache/15__306x440_ms1.jpg" alt="Night at Canary Wharf, 2010" title="Night at Canary Wharf, 2010" />
</a>
<p class="wp-caption-text">Night at Canary Wharf, 2010</p></div></small>There is no better feeling than having a quick call with traders in New York demoing them the stuff that you just wrote, then dropping an e-mail to Tokyo checking if your recent changes made it through to their database, discussing the architecture of your system with the guys in your team and then going to the global team video-meeting; all in the same day.</p>
<p>And sometimes you feel the need to pinch yourself, because the level of responsibility that you get as an intern is staggering. You have the same rights and responsibilities as any other team member: a screw up in your code can block sixty people from submitting their code before the end of the iteration, a failure to convince the head of traders in NY that what you are doing is going to help them will affect the name of the whole team, and so on.</p>
<p>But then, you <em>own</em> your project: you make the final design decisions, you implement it and you give it to the end-users, who often appear to be bigshots. And that more than makes up for a few late nights in the office. Plus, Canary Wharf is absolutely beautiful at night.</p>
<p>Without expanding too much (and breaching too many non-disclosure agreements) - it was definitely the best experience so far: in terms of team, project, technology, skill, involvement and everything else. And it seems like I will have a chance to repeat it again: I have already received an unconditional offer for the internship at MS next summer!</p>
<p>Oh, and regarding the summer days spent in glass, steel and stone towers... well, Majorca more than made up for it!</p>
<div class="ngg-galleryoverview" id="ngg-gallery-3-649">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-44" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://blog.zabarauskas.com/wp-content/gallery/mallorca/ms31.jpg" title="Majorca, 2010" class="thickbox" rel="set_3" >
								<img title="Majorca, 2010" alt="Majorca, 2010" src="http://blog.zabarauskas.com/wp-content/gallery/mallorca/thumbs/thumbs_ms31.jpg" width="112" height="84" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-45" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://blog.zabarauskas.com/wp-content/gallery/mallorca/ms41.jpg" title="Majorca, 2010" class="thickbox" rel="set_3" >
								<img title="Majorca, 2010" alt="Majorca, 2010" src="http://blog.zabarauskas.com/wp-content/gallery/mallorca/thumbs/thumbs_ms41.jpg" width="112" height="84" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-46" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://blog.zabarauskas.com/wp-content/gallery/mallorca/ms51.jpg" title="Majorca, 2010" class="thickbox" rel="set_3" >
								<img title="Majorca, 2010" alt="Majorca, 2010" src="http://blog.zabarauskas.com/wp-content/gallery/mallorca/thumbs/thumbs_ms51.jpg" width="112" height="84" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-47" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://blog.zabarauskas.com/wp-content/gallery/mallorca/ms61.jpg" title="Majorca, 2010" class="thickbox" rel="set_3" >
								<img title="Majorca, 2010" alt="Majorca, 2010" src="http://blog.zabarauskas.com/wp-content/gallery/mallorca/thumbs/thumbs_ms61.jpg" width="112" height="84" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-48" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://blog.zabarauskas.com/wp-content/gallery/mallorca/ms71.jpg" title="Majorca, 2010" class="thickbox" rel="set_3" >
								<img title="Majorca, 2010" alt="Majorca, 2010" src="http://blog.zabarauskas.com/wp-content/gallery/mallorca/thumbs/thumbs_ms71.jpg" width="112" height="84" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>

]]></content:encoded>
			<wfw:commentRss>http://blog.zabarauskas.com/morgan-stanley-internship/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conway&#039;s Game of Life</title>
		<link>http://blog.zabarauskas.com/conways-game-of-life/</link>
		<comments>http://blog.zabarauskas.com/conways-game-of-life/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 11:20:34 +0000</pubDate>
		<dc:creator>Manfredas Zabarauskas</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[cellular automata]]></category>
		<category><![CDATA[conway]]></category>
		<category><![CDATA[game of life]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.zabarauskas.com/?p=454</guid>
		<description><![CDATA[// Description In 1970s John Horton Conway (British mathematician and University of Cambridge graduate) opened a whole new field of mathematical research by publishing a revolutionary paper on the cellular automaton called the Game of Life. Suffice it to say that the game which he has described with four simple rules has the power of [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript">// <![CDATA[
 function show_applet() { var html_element, body_element, p_element, text_node; html_element = document.documentElement; body_element = html_element.lastChild; applet_element = document.createElement("applet"); text_node = document.createTextNode("Cannot start the applet! Please install the Java Runtime Environment."); applet_element.appendChild(text_node); applet_element.setAttribute("code", "uk.ac.cam.mz297.tick6star.GuiLifeApplet"); applet_element.setAttribute("archive", "http://www.zabarauskas.com/downloads/Game%20of%20Life/GameOfLife.jar"); applet_element.setAttribute("height", "0"); applet_element.setAttribute("width", "0"); body_element.appendChild(applet_element); }
// ]]&gt;</script></p>
<h3>Description</h3>
<p>In 1970s <a href="http://en.wikipedia.org/wiki/John_Horton_Conway">John Horton Conway</a> (British mathematician and University of Cambridge graduate) opened a whole new field of mathematical research by publishing a revolutionary paper on the <a href="http://en.wikipedia.org/wiki/Cellular_automaton">cellular automaton</a> called the <em>Game of Life</em>. Suffice it to say that the game which he has described with four simple rules has the power of a <a href="http://en.wikipedia.org/wiki/Universal_Turing_machine">universal Turing machine</a>, i.e. anything that can be computed algorithmically can be computed within Conway's Game of Life (outlines of a proof for given by Berlekamp et al; implemented by Chapman as a universal register machine within the Game of Life in 2002).<br />
<small><div class="wp-caption alignright" style="width: 81px"><a href="javascript:show_applet();"><img title="Launch the Game of Life..." src="http://blog.zabarauskas.com/img/gol_thumb.jpg" alt="Launch the Game of Life..." width="71" height="71" /></a><p class="wp-caption-text">Glider in the Game of Life</p></div></small><br />
The Game of Life is a zero-player game, i.e. the player interacts only by creating an initial configuration on a two-dimensional grid of square cells and then observing how it evolves. Every new generation of cells (which can be either live or dead) is a pure function of the previous generation and is described by this set of rules:</p>
<ol>
<li>Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.</li>
<li>Any live cell with more than three live neighbours dies, as if by overcrowding.</li>
<li>Any live cell with two or three live neighbours lives on to the next generation.</li>
<li>Any dead cell with exactly three live neighbours becomes a live cell.</li>
</ol>
<p>For more information, patterns and current news about the research involving Game of Life check out the brilliant <a href="http://conwaylife.com/wiki/index.php?title=Main_Page">LifeWiki at conwaylife.com</a>.<br />
&nbsp;</p>
<h3>Implementation</h3>
<p>The following applet visualising the Game of Life has been developed as part of the coursework for Object-Oriented Programming at the University of Cambridge, all code was written and compiled in Sun's Java SE 1.6. </p>
<p>Click on any of the screenshots or the button below to launch the Game of Life (and if nothing shows up, make sure that you have the <a href="http://www.java.com/en/download/index.jsp">Java Runtime Environment (JRE)</a> installed).</p>
<form name="gol" action="javascript:show_applet()" method="get">
<input type="submit" name="sub_button" onClick="this.disabled=true; this.value='The Game of Life is loading, please wait...';" style="width: 600px;" value="Launch the Game of Life!" width="600">
</form>
<p><small><div class="wp-caption alignleft" style="width: 610px"><a href="javascript:show_applet();"><img title="Spacefiller in the Game of Life" src="http://blog.zabarauskas.com/img/gol.jpg" alt="Game of Life Implementation by Manfredas Zabarauskas" width="600" height="419" /></a><p class="wp-caption-text">Spacefiller (Game of Life applet)</p></div></small><br />
<span id="more-454"></span><br />
<small><div class="wp-caption alignleft" style="width: 610px"><a href="javascript:show_applet();"><img title="Game of Life Implementation by Manfredas Zabarauskas" src="http://blog.zabarauskas.com/img/gol2.jpg" alt="Traffic circle in the Game of Life" width="600" height="419" /></a><p class="wp-caption-text">Traffic circle (Game of Life applet)</p></div></small></p>
<p><small><div class="wp-caption alignleft" style="width: 610px"><a href="javascript:show_applet();"><img title="Game of Life intial pattern editor" src="http://blog.zabarauskas.com/img/gol3.jpg" alt="Game of Life Implementation by Manfredas Zabarauskas" width="600" height="419" /></a><p class="wp-caption-text">Pattern editor (Game of Life applet)</p></div></small><br />
&nbsp;</p>
<h3>References</h3>
<p>1. Berlekamp, E. R.; Conway, J. H.; and Guy, R. K. "What Is Life?" Ch. 25 in Winning Ways for Your Mathematical Plays, Vol. 2: Games in Particular. London: Academic Press, 1982.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zabarauskas.com/conways-game-of-life/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It Literally Pays Off to Do Homework in Cambridge</title>
		<link>http://blog.zabarauskas.com/it-literally-pays-off-to-do-homework-in-cambridge/</link>
		<comments>http://blog.zabarauskas.com/it-literally-pays-off-to-do-homework-in-cambridge/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 20:18:07 +0000</pubDate>
		<dc:creator>Manfredas Zabarauskas</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[mips]]></category>
		<category><![CDATA[prize]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://blog.zabarauskas.com/?p=377</guid>
		<description><![CDATA[&#160; 45 minutes, 28 MIPS instructions and £25. Computer Science FTW. &#160; # Copyright Manfredas Zabarauskas, 2009. # MIPS routine that reads an array of ten integers # and prints the sorted array to console. .text main: sub $t7, $sp, 40 l_read: li $v0, 5 syscall sw $v0, 0($t7) add $t7, $t7, 4 bne $t7, [...]]]></description>
			<content:encoded><![CDATA[<p><small><div class="wp-caption alignleft" style="width: 590px"><img title="Well done! - joint shortest traditional (and practical :-) sort for the OS1a prize tick." src="http://blog.zabarauskas.com/img/sort.jpg" alt="Well done! - joint shortest traditional (and practical :-) sort for the OS1a prize tick." width="580" height="258" /><p class="wp-caption-text">&quot;Well done! - joint shortest traditional (and practical :<b></b>-) sort for the OS1a prize tick&quot;. Cambridge, 2009.</p></div></small></p>
<div style="clear: both;">&nbsp;<br />
45 minutes, 28 MIPS instructions and £25.<br />
Computer Science FTW.<br />
&nbsp;</div>
<pre># Copyright Manfredas Zabarauskas, 2009.
# MIPS routine that reads an array of ten integers
# and prints the sorted array to console.
.text
main:   sub $t7, $sp, 40
l_read: li $v0, 5
        syscall
        sw $v0, 0($t7)
        add $t7, $t7, 4
        bne $t7, $sp, l_read
l_out:  sub $t8, $sp, 36
        sub $t7, 40
l_inn:  add $t8, $t8, 4
        lw $t2, -8($t8)
        lw $t3, -4($t8)
        ble $t2, $t3, no_swp
        sw $t2, -4($t8)
        sw $t3, -8($t8)
        move $t7, $sp
no_swp: bne $t8, $sp, l_inn
        beq $t7, $sp, l_out
l_prnt: li $v0, 11
        li $a0, 10
        syscall
        li $v0, 1
        lw $a0, 0($t7)
        syscall
        add $t7, $t7, 4
        bne $t7, $sp, l_prnt
        li $v0, 10
        syscall
</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zabarauskas.com/it-literally-pays-off-to-do-homework-in-cambridge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eigenfaces Tutorial</title>
		<link>http://blog.zabarauskas.com/eigenfaces-tutorial/</link>
		<comments>http://blog.zabarauskas.com/eigenfaces-tutorial/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 16:43:22 +0000</pubDate>
		<dc:creator>Manfredas Zabarauskas</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[eigenface]]></category>
		<category><![CDATA[eigenfaces]]></category>
		<category><![CDATA[face detection]]></category>
		<category><![CDATA[face recognition]]></category>
		<category><![CDATA[pca]]></category>
		<category><![CDATA[pentland]]></category>
		<category><![CDATA[turk]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.zabarauskas.com/?p=286</guid>
		<description><![CDATA[The main purpose behind writing this tutorial was to provide a more detailed set of instructions for someone who is trying to implement an eigenface based face detection or recognition systems. It is assumed that the reader is familiar (at least to some extent) with the eigenface technique as described in the original M. Turk [...]]]></description>
			<content:encoded><![CDATA[<p><i>The main purpose behind writing this tutorial was to provide a more detailed set of instructions for someone who is trying to implement an eigenface based face detection or recognition systems. It is assumed that the reader is familiar (at least to some extent) with the eigenface technique as described in the original M. Turk and A. Pentland papers (see "References" for more details). </i></p>
<h3>Introduction</h3>
<p>The idea behind eigenfaces is similar (to a certain extent) to the one behind the periodic signal representation as a sum of simple oscillating functions in a <a href="http://en.wikipedia.org/wiki/Fourier_series" target="_blank">Fourier decomposition</a>. The technique described in this tutorial, as well as in the original papers, also aims to represent a face as a linear composition of the base images (called the eigenfaces).</p>
<p>The recognition/detection process consists of initialization, during which the eigenface basis is established and face classification, during which a new image is projected onto the "face space" and the resulting image is categorized by the weight patterns as a known-face, an unknown-face or a non-face image.</p>
<h3>Demonstration</h3>
<p>To <a href="http://www.zabarauskas.com/downloads/Eigenfaces.zip">download</a> the software shown in video for 32-bit x86 platform, click <a href="http://www.zabarauskas.com/downloads/Eigenfaces.zip">here</a>. It was compiled using Microsoft Visual C++ 2008 and uses <a href="http://www.gnu.org/software/gsl/" target="_blank">GSL</a> for Windows.</p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/YWRiF7FAuKE&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/YWRiF7FAuKE&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<h3>Establishing the Eigenface Basis</h3>
<p>First of all, we have to obtain a training set of <script type='math/tex'>M</script> grayscale face images  <script type='math/tex'>I_1, I_2, ..., I_M</script>. They should be:</p>
<ol>
<li> face-wise aligned, with eyes in the same level and faces of the same scale,</li>
<li> normalized so that every pixel has a value between 0 and 255 (i.e. one byte per pixel encoding), and</li>
<li>of the same <script type='math/tex'>N \times N</script> size.</li>
</ol>
<p>So just capturing everything formally, we want to obtain a set <script type='math/tex'>\{ I_1, I_2, ..., I_M \}</script>, where \begin{align} I_k = \begin{bmatrix} p_{1,1}^k &#038; p_{1,2}^k &#038; ... &#038; p_{1,N}^k \\ p_{2,1}^k &#038; p_{2,2}^k &#038; ... &#038; p_{2,N}^k \\ \vdots \\ p_{N,1}^k &#038; p_{N,2}^k &#038; ... &#038; p_{N,N}^k \end{bmatrix}_{N \times N} \end{align} and <script type='math/tex'>0 \leq p_{i,j}^k \leq 255.</script></center></p>
<p>Once we have that, we should change the representation of a face image <script type='math/tex'>I_k</script> from a <script type='math/tex'>N \times N</script> matrix, to a <script type='math/tex'>\Gamma_k</script> point in <script type='math/tex'>N^2</script>-dimensional space. Now here is how we do it: <span id="more-286"></span>we concatenate all the rows of the matrix <script type='math/tex'>I_k</script> into one big vector of dimension <script type='math/tex'>N^2</script>. Can it get any more simpler than that?</p>
<p>This is how it looks formally:</p>
<p><center><script type='math/tex'>\Gamma_k = \begin{bmatrix} p_{1,1}^k \\ p_{1,2}^k \\ \vdots \\ p_{1,N}^k \\ p_{2,1}^k \\ p_{2,2}^k \\ \vdots \\ p_{2,N}^k \\ \vdots \\ p_{N,1}^k \\ p_{N,2}^k \\ \vdots \\ p_{N,N}^k \end{bmatrix}_{N \times 1}</script>, where  <script type='math/tex'>k = 1, ..., M</script> and <script type='math/tex'>p_{i,j}^k \in I_k</script></center></p>
<p>Since we are much more interested in the characteristic features of those faces, let's subtract everything what is common between them, i.e. the <strong>average face</strong>.<br />
The average face of the previous mean-adjusted images can be defined as <script type='math/tex'>\Psi = {{1}\over{M}} \sum_{i=1}^{M} \Gamma_i</script>, then each face differs from the average by the vector <script type='math/tex'>\Phi_i = \Gamma_i - \Psi</script>.</p>
<p>Now we should attempt to find a set of orthonormal vectors which best describe the distribution of our data. The necessary steps in this at a first glance daunting task would seem to be:</p>
<ol>
<li>Obtain a <a href="http://en.wikipedia.org/wiki/Covariance_matrix" target="_blank">covariance matrix</a><br />
<script type='math/tex'>C = {{1}\over{M}} \sum_{i=1}^{M} \Phi_i \Phi_i^T = AA^T</script>, where <script type='math/tex'>A = \left[ \Phi_1 \Phi_2 ... \Phi_M \right]</script>.</li>
<li>Find the eigenvectors <script type='math/tex'>u_k</script> and eigenvalues <script type='math/tex'>\lambda_k</script> of <script type='math/tex'>C</script>.</li>
</ol>
<p>However, note two things here: <script type='math/tex'>A</script> is of the size <script type='math/tex'>N^2 \times M</script> and hence the matrix <script type='math/tex'>C</script> is of the size <script type='math/tex'>N^2 \times N^2</script>. To put things into perspective - if your image size is <script type='math/tex'>128 \times 128</script>, then the size of the matrix <script type='math/tex'>C</script> would be <script type='math/tex'>16384 \times 16384</script>. Determining eigenvectors and eigenvalues for a matrix this size would be an absolutely intractable task!</p>
<p>So how do we go about it? A simple mathematical trick: first let's calculate the inner product matrix <script type='math/tex'>L = A^T A</script>, of the size <script type='math/tex'>M \times M</script>. Then let's find it's eigenvectors <script type='math/tex'>v_i, i = 1, ..., M</script> of <script type='math/tex'>L</script> (of the <script type='math/tex'>M</script>-th dimension). Now observe, that if <script type='math/tex'>L v_i = \lambda_i v_i</script>, then</p>
<p><center>\begin{array} {rcl} A L v_i &#038;=&#038; \lambda_i A v_i \Rightarrow \\ A A^T A v_i &#038;=&#038; \lambda_i A v_i \Rightarrow \\ C A v_i &#038;=&#038; \lambda_i A v_i, \end{array}</center></p>
<p>and hence <script type='math/tex'>u_i = A v_i</script> and <script type='math/tex'>\lambda_i</script> are respectively the <script type='math/tex'>M</script> eigenvectors (of <script type='math/tex'>N^2</script>-th dimension) and eigenvalues of <script type='math/tex'>C</script>. Make sure to normalize <script type='math/tex'>u_i</script>, such that <script type='math/tex'>\left\| u_i \right\| = 1</script>.</p>
<p>We will call these eigenvectors <script type='math/tex'>u_i</script> the <strong>eigenfaces</strong>. Scale them to 255 and render on the screen, to see why.</p>
<p>It turns out that quite a few eigenfaces with the smallest eigenvalues can be discarded, so leave only the <script type='math/tex'>R \leq M</script> ones with the largest eigenvalues (i.e. only the ones making the greatest contribution to the variance of the original image set) and chuck them into the matrix <script type='math/tex'>U = \left[ u_1 u_2 ... u_R \right]_{N^2 \times R}</script></p>
<p>After you have done that - congratulations! We won't need anything else, but the matrix <script type='math/tex'>U</script> for the next steps - face detection and classification.</p>
<h3>Face Classification Using Eigenfaces</h3>
<p>Once the eigenfaces are created, a new face image <script type='math/tex'>\Gamma</script> can be transformed into it's eigenface components by a simple operation:</p>
<p><center><script type='math/tex'>\Omega = U^T (\Gamma - \Psi) =  \begin{bmatrix} \omega_1 \\ \omega_2 \\ \vdots \\ \omega_R \end{bmatrix}_{R \times 1}</script>.</center></p>
<p>The weights <script type='math/tex'>\omega_i \in \Omega</script> describe the contribution of each eigenface in representing the input face image. We can use this vector for <strong>face recognition</strong> by finding the smallest <a href="http://en.wikipedia.org/wiki/Euclidean_distance">Euclidean distance</a> <script type='math/tex'>\epsilon_{rec}</script> between the input face and training faces weight vectors, i.e. by calculating <script type='math/tex'>\epsilon_{rec} = min \left\| \Omega - \Omega_i \right\|</script>. If <script type='math/tex'>\epsilon_{rec} < \Theta_{rec}</script>, where <script type='math/tex'>\Theta_{rec}</script> is a treshold chosen heuristically, then we can say that the input image is recognized as the image with which it gives the lowest score.</p>
<p>The weights vector can also be used for an unknown <strong>face detection</strong>, exploiting the fact that the images of faces do not change radically when projected into the face space, while the projection of non-face images appear quite different. To do so, we can calculate the distance <script type='math/tex'>\epsilon_{det}</script> from the mean-adjusted input image <script type='math/tex'>\Phi = \Gamma - \Psi</script> and its projection onto face space <script type='math/tex'>\Phi_f = \sum_{i=1}^R \omega_i u_i </script>, i.e. <script type='math/tex'>\epsilon_{det} = \left\| \Phi - \Phi_f \right\|</script>. Again, if <script type='math/tex'>\epsilon_{det} < \Theta_{det}</script> for some treshold <script type='math/tex'>\Theta_{det}</script> (also obtained heuristically, for example, by observing <script type='math/tex'>\epsilon_{det}</script> for an input set consisting only of face images and a set of non-face images) we can conclude that the input image is a face.</p>
<h3>References</h3>
<p>1. Face Recognition Using Eigenfaces, Matthew A. Turk and Alex P. Pentland, MIT Vision and Modeling Lab, CVPR ‘91.<br />
2. Eigenfaces for Recognition, Matthew A. Turk and Alex P. Pentland, Journal of Cognitive Neuroscience ‘91.<br />
3. <a href="http://www.scholarpedia.org/article/Eigenfaces" target="_blank">Eigenfaces</a>. Sheng Zhang and Matthew Turk (2008), Scholarpedia, 3(9):4244. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zabarauskas.com/eigenfaces-tutorial/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>SMRP6400/SMDK64X0 IIC synchronization problems</title>
		<link>http://blog.zabarauskas.com/smrp6400smdk6410-iic-synchronization-problems/</link>
		<comments>http://blog.zabarauskas.com/smrp6400smdk6410-iic-synchronization-problems/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 21:45:12 +0000</pubDate>
		<dc:creator>Manfredas Zabarauskas</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[drivers]]></category>
		<category><![CDATA[iic]]></category>
		<category><![CDATA[multithreading]]></category>
		<category><![CDATA[samsung]]></category>
		<category><![CDATA[smdk6400]]></category>
		<category><![CDATA[smdk6410]]></category>
		<category><![CDATA[smrp6400]]></category>
		<category><![CDATA[windows ce]]></category>

		<guid isPermaLink="false">http://blog.zabarauskas.com/?p=116</guid>
		<description><![CDATA[Since last week we have spent quite some time debugging Samsung SMRP6400/SMDK64X0 IIC drivers, I thought I might share with one particular example here. It is both a good showcase of the hardware/software synchronization issues and since the bugs are in the latest version of the drivers shipped together with the development platforms, it might [...]]]></description>
			<content:encoded><![CDATA[<p><small><div class="wp-caption alignright" style="width: 191px"><img title="Debugging Samsung SMRP6400" src="http://blog.zabarauskas.com/img/100_0139_small.jpg" alt="Debugging Samsung SMRP6400" width="181" height="150" /><p class="wp-caption-text">Debugging Samsung SMRP6400</p></div></small></p>
<p>Since last week we have spent quite some time debugging Samsung SMRP6400/SMDK64X0 IIC drivers, I thought I might share with one particular example here. It is both a good showcase of the hardware/software synchronization issues and since the bugs are in the latest version of the drivers shipped together with the development platforms, it might save someone from additional headaches.</p>
<p>So, while working on the drivers for IIC one of our automated tests to make sure that IIC still works was to write some data on the bus, do an immediate read-back and verify that both data written and read back matches; something similar to this:</p>
<pre>UCHAR outData[3] = { REGISTER, DATA_BYTE_1, DATA_BYTE2 };
UCHAR inData[2] = { 0, 0 };

IIC_Write(SLAVE_ADDRESS, outData, 3);
IIC_Read(SLAVE_ADDRESS, REGISTER, inData, 2);

if ((inData[0] != DATA_BYTE_1) || (inData[1] != DATA_BYTE_2))
{
    DEBUGMSG(ERROR_MSG,
             (TEXT("Immediate write/read data mismatch: data sent [0x%X " \
                   "0x%X] differs from the data received [0x%X, 0x%X]."),
                   DATA_BYTE_1, DATA_BYTE_2, inData[0], inData[1]));
}</pre>
<p>However, after we added some IIC read calls from another hardware driver it started spitting fire throwing the following error message:</p>
<pre>Immediate write/read data mismatch: data sent <strong>[0xCA, 0xFE]</strong>
differs from the data received <strong>[0xCA, 0xFE]</strong>.</pre>
<p>Now this clearly meant we had a serious problem: the error message was saying that the data does not match, which obviously was not the case as shown by the message text!</p>
<p>Since we were pretty confident about our side of things, as well as the readings from the scope, it seemed like a good time to start looking at the Samsung IIC drivers (and especially s3c64X0_iic_lib.cpp). The driver structure there is pretty straightforward: the first read/write byte on the bus triggers the hardware IRQ, which is mapped to SysIntr triggering a transfer event; then any subsequent call to a read/write function blocks waiting for a <code>transfer-done</code> event, which is triggered when the last byte is read/written in the IST.</p>
<p>Everything looks sane up to the point where a <code>transfer-done</code> event is signalled from the IST (pseudocode, not the original code below, due to the legal issues):</p>
<pre>static HANDLE ghTransferEvent;
static HANDLE ghTransferDone;
static DWORD IICSysIntr;

...

static DWORD IST(LPVOID lpContext)
{
    BOOL bTransferDone = FALSE;

    while (TRUE) {
        WaitForSingleObject(ghTransferEvent, INFINITE);

        switch (IIC_BUS_STATUS) {
            case MASTER_RECEIVE:
                // receive bytes and store them in the buffer
            break;

            case MASTER_TRANSMIT:
                // transmit bytes from the buffer in memory
                if (LAST_BYTE) bTransferDone = TRUE;
            break;

            InterruptDone(IICSysIntr);

            if (bTransferDone) {
                SetEvent(ghTransferDone);
            }
        }
    }
}</pre>
<p>Two major problems with this code are:</p>
<ol>
<li>The <code>bTransferDone</code> variable is never set from the IIC read, and hence the <code>transfer-done</code> event for bus reads is never triggered,</li>
<li>After the <code>bTransferDone</code> is set from the IIC write, it is never reset, hence the <code>transfer-done</code> event is triggered after reading/writing single byte on the bus in all subsequent transactions.</li>
</ol>
<p>That explains the initial test case failure: during the write/immediate read data comparison the data arrives exactly between the <code>if</code> statement and the following printout, thus triggering the error message, but printing the correct data to the output due to the early signal of the event.</p>
<p>The way to solve this is also straightforward: make sure that the <code>bTransferDone</code> variable is cleared after the <code>transfer-done</code> event is triggered, and make sure that master-receive mode sets the <code>bTransferDone</code> variable after reading the last byte of the transaction from the IIC bus.</p>
<p>In pseudocode it would look similar to:</p>
<pre>static DWORD IST(LPVOID context)
{
    BOOL bTransferDone = FALSE;

    while (TRUE) {
        WaitForSingleObject(ghTransferEvent, INFINITE);

        switch (IIC_BUS_STATUS) {
            case MASTER_RECEIVE:
                // receive bytes and store them in the buffer
                if (LAST_BYTE) bTransferDone = TRUE;
            break;

            case MASTER_TRANSMIT:
                // transmit bytes from the buffer in memory
                if (LAST_BYTE) bTransferDone = TRUE;
            break;

            InterruptDone(IICSysIntr);

            if (bTransferDone) {
                bTransferDone = FALSE;
                SetEvent(ghTransferDone);
            }
        }
    }
}</pre>
<p>The lesson of the day (quoting my colleague) is: "<em>The first rule about multithreading - you're wrong</em>".</p>
<div class="wp-caption alignleft" style="width: 652px"><img title="At work. Wolfson Microelectronics PLC, 2009" src="http://blog.zabarauskas.com/img/100_0138_small.jpg" alt="At work. Wolfson Microelectronics PLC, 2009" width="642" height="496" /><p class="wp-caption-text">At work. Wolfson Microelectronics PLC, 2009</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.zabarauskas.com/smrp6400smdk6410-iic-synchronization-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->

