<?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>Neural Network Design blog &#187; debugging</title>
	<atom:link href="http://janbogaerts.name/index.php/tag/debugging/feed/" rel="self" type="application/rss+xml" />
	<link>http://janbogaerts.name</link>
	<description>My take on neural networks, AI and more</description>
	<lastBuildDate>Wed, 28 Jul 2010 18:21:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Debugging networks: split paths</title>
		<link>http://janbogaerts.name/index.php/2010/03/04/debugging-networks-split-paths/</link>
		<comments>http://janbogaerts.name/index.php/2010/03/04/debugging-networks-split-paths/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 16:54:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Getting started]]></category>
		<category><![CDATA[N²D]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[debugging]]></category>

		<guid isPermaLink="false">http://janbogaerts.name/index.php/2010/03/04/debugging-networks-split-paths/</guid>
		<description><![CDATA[ An annoying side effect of this type of resonating network, is, when you have a bug in the code, you generally don’t get 0 answers, but a whole lot. This can sometimes be very confusing to debug. Why does a certain path give a positive result, when it shouldn’t? And more importantly (from NND’s [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://janbogaerts.name/wp-content/uploads/2010/03/image4.png"><img style="border-right-width: 0px; margin: 0px 0px 0px 5px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="right" src="http://janbogaerts.name/wp-content/uploads/2010/03/image_thumb4.png" width="362" height="323" /></a> An annoying side effect of this type of resonating network, is, when you have a bug in the code, you generally don’t get 0 answers, but a whole lot. This can sometimes be very confusing to debug. Why does a certain path give a positive result, when it shouldn’t? And more importantly (from NND’s point of view at least), how can you follow the construction of that specific result, without the clutter of all the other processors? Enter ‘<em>split paths</em>’. </p>
<p><em><font color="#808080">A split path represent the route that a result took, from start to now, expressed in the neurons that the path chose during all the splits. </font></em></p>
<p>As example, if only 1 split was executed to get to a result, and there were 2 neurons in that split, the path of the result only has 1 node and can have 2 possible values, those that were used in the split. In the real world though, a path usually has many, many nodes.</p>
<p>To record a split path, you first need to put a break point at a position where you know you will get many invalid results. That’s because a split path can only be recorded when the processors are still running, not when the result has already been calculated. </p>
<p><a href="http://janbogaerts.name/wp-content/uploads/2010/03/image6.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://janbogaerts.name/wp-content/uploads/2010/03/image_thumb6.png" width="400" height="246" /></a>In the aici demo, it’s best to put a breakpoint in the ‘<em>Stage 1.1</em>’ code, in the if, second part (GetClusterMeaning(CurrentTo) == flow), if you drill down a bit further, you get the ‘Add split result’ instruction, which is basically the end point of the flow recognition&#160; algorithm. (see picture below).</p>
<p><em><font color="#808080">Put breakpoints on ‘Add split result’ instructions to find </font></em><em><font color="#808080">invalid split paths.</font></em></p>
<p>Once you have a processor that is producing an invalid result at your breakpoint, you can store the split path. Select the processor, open the context menu (right mouse button on a processor in the debugger overview) and select ‘<em>Store split path</em>’.&#160; This will produce a new entry in the tree on the ‘<em>Debugger</em>’ page (see 3th image). The root item will be ‘path for x’ where x is the name of the processor. The children are all the neurons that were selected for the path during a split instruction.</p>
<p>I usually kill everything after I have the path, the other processors will produce invalid results anyway, and you need to start a new run before it’s&#160; possible to actually use the path anyway. <a href="http://janbogaerts.name/wp-content/uploads/2010/03/image2.png"><img style="border-right-width: 0px; margin: 0px 0px 5px 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="right" src="http://janbogaerts.name/wp-content/uploads/2010/03/image_thumb2.png" width="383" height="91" /></a></p>
<p><a href="http://janbogaerts.name/wp-content/uploads/2010/03/image5.png"><img style="border-bottom: 0px; border-left: 0px; margin: 5px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://janbogaerts.name/wp-content/uploads/2010/03/image_thumb5.png" width="294" height="310" /></a>So, finally we can start using the data to debug our network. The basic idea is to&#160; use the path for finding the processors that are following the specified path, so we can take a closer look at the code. In short, a split path provide a shortcut: instead of manually stepping through all the code and individually deciding which processors to follow, we can jump to the ones we are interested in. These will be highlighted in green and will pause when they have reached a split that is selected in the path. Off course, we first need to select the path in the debugger, and at least 1 child node, otherwise there wont be anything to see. </p>
<p>&#160;<em><font color="#808080">Processors that follow a selected split path will show up in green and pause whenever they reach a split that produces a neuron which is selected in the path.</font></em></p>
<p><a href="http://janbogaerts.name/wp-content/uploads/2010/03/image2.png"></a></p>
<p><a href="http://janbogaerts.name/wp-content/uploads/2010/03/image2.png">&#160;</a>One last note perhaps, once you have the processor you want, you can use the ‘Kill all but this’ command to stop all the other processors. This way there is less distraction in the debugger.</p>
]]></content:encoded>
			<wfw:commentRss>http://janbogaerts.name/index.php/2010/03/04/debugging-networks-split-paths/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The debugger</title>
		<link>http://janbogaerts.name/index.php/2009/06/09/the-debugger/</link>
		<comments>http://janbogaerts.name/index.php/2009/06/09/the-debugger/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 18:36:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Getting started]]></category>
		<category><![CDATA[N²D]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[code editor]]></category>
		<category><![CDATA[debugging]]></category>

		<guid isPermaLink="false">http://janbogaerts.name/index.php/2009/06/09/the-debugger/</guid>
		<description><![CDATA[This is the very first debugger I have written, and I am pretty proud about it! It’s not a masterpiece, but functional.&#160; The code definitely could use some tidying up and some speed tuning wouldn’t hurt at all, but you can trace bugs, inspect values and follow the program flow, and that’s already something I [...]]]></description>
			<content:encoded><![CDATA[<p>This is the very first debugger I have written, and I am pretty proud about it! It’s not a masterpiece, but functional.&#160; The code definitely could use some tidying up and some speed tuning wouldn’t hurt at all, but you can trace bugs, inspect values and follow the program flow, and that’s already something I guess. To explain the debugger to you, I thought it perhaps best to do it using some of the demo’s.&#160; Simply open the ‘<em>Echo words</em>’ project to get started.</p>
<h4>Set up</h4>
<p>Before we send some input to the network, we need to set up the designer so that it is ready to debug:</p>
<ol>
<li>We need to&#160; put a breakpoint&#160; on a statement. You can do this in a code editor. The very first code block that gets called in this network is the <em>rules</em> code on the ‘<em>Contains Word</em>’ neuron, so simply double click on the ‘<em>Code: Contains Word</em>’ node in the <em>Projects</em> tab.       <br />To set the breakpoint on the first statement, expand the ‘<em>CheckStartTextBlock – space insertion</em>’ code block and click in the little circle on the ‘<em>if</em>’ statement. This should make it turn red. </li>
<li>The designer also needs to be set in design mode.&#160; You can do this by the drop down box on the main toolbar or on the debugger tab’s toolbar. There are 3 possible modes:
<ul>
<li>Off: no debugging is possible.&#160; This mode runs faster. </li>
<li>Normal: The debugger stops whenever a breakpoint is encountered. When a breakpoint is encountered or a processor was paused, it is possible to inspect values.&#160; This is how most other debuggers provide debug capabilities. </li>
<li>Slow motion: In this mode, the debugger automatically pauses and continues on every statement, creating a <em>movie</em> of the execution process. You can use the throttle bar on the left of the combo box to select the speed, which is updated real time. It’s possible to pause and continue this movie using the pause and play buttons on the debugger tab’s menu.&#160; I have included this type of debugging mode because I believe it is sometimes useful to see the path that is taken to a specific point of interest. With this feature, you don’t have to keep pressing <em>F6</em> to advance. </li>
</ul>
</li>
<li>It’s also possible, but not required, to let a processor stop when an error was encountered. This is done by activating the ‘<em>Break on error</em>’ button. This only works when the error happened on a processor in debug mode. </li>
</ol>
<p></p>
<p><a href="http://janbogaerts.name/wp-content/uploads/2009/06/image15.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 0px; border-right-width: 0px" height="615" alt="image" src="http://janbogaerts.name/wp-content/uploads/2009/06/image-thumb15.png" width="768" border="0" /></a> </p>
</p>
<p>Note that it is not possible to switch between different modes while a processor is running. You can only specify the debug mode for newly created processors. </p>
<p>An overview of all the breakpoints in the project can be found on the right side of the debugger tab. Currently it simply lists all the breakpoints, but new features should be added to this list shortly.</p>
<h4>Start a processor</h4>
<p><a href="http://janbogaerts.name/wp-content/uploads/2009/06/image16.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 0px 0px 10px; border-right-width: 0px" height="473" alt="image" src="http://janbogaerts.name/wp-content/uploads/2009/06/image-thumb16.png" width="378" align="right" border="0" /></a> To get started, we need to send&#160; some data to the network through it’s text-sin (sensory interface), so make certain that the ‘<em>Echo channel</em>’ is opened (a communication&#160; channel is the visual interface for a sin). Go to <em>View/Communication Channels/Echo channel</em>, and make certain it is checked (and that the tab is selected).</p>
<p>Once the channel is open, type some text in the input section and send it to the network by pressing enter (or the <em>send</em> button). You should see a neuron appear in the left upper screen, which represents the input event (the neuron that will be solved by the processor). Your text will also appear as a string in the centre dialog screen. There will also appear an object in the centre screen of the debugger tab. This represents the processor that was started and which is handling the input event. </p>
</p>
<p>The processor overview contains 2 numbers. The first number represents the name of the processor. This value can be changed and is used to identify it between multiple processors. The second number represents the number of neurons that are left on the stack + the current neuron that&#160; is being solved. </p>
<p>The buttons represent, from left to right:</p>
<ul>
<li>a toggle button that can be used to open and close the detailed view for the processor.&#160; </li>
<li>An indicator that is selected when the processor is paused. This is used to inform you on the run state, it’s not an interactive button. </li>
<li>An indicator that lets you know that the processor is still running or not. When this is no longer selected, an irrecoverable error occurred in the processor and it is actually dead (in other words, you’ve got a problem when this is no longer selected). </li>
</ul>
<p>Once a processor is started, the middle square in the right side group on the status bar will be blue.&#160; This will remain so for as long as the network has still a processor running. </p>
<h4>Detailed view</h4>
<p>If you press the first toggle button, a detailed view of the processor should open in a new tab (using the same name as that of the processor). </p>
<p><a href="http://janbogaerts.name/wp-content/uploads/2009/06/image17.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 0px; border-right-width: 0px" height="484" alt="image" src="http://janbogaerts.name/wp-content/uploads/2009/06/image-thumb17.png" width="637" border="0" /></a>&#160;</p>
<p>This tab is divided into 3 sections (from left to right):</p>
<ul>
<li>The content of the execution stack.&#160; This stack contains the neurons that have to be solved by the processor.&#160; You can add and remove neurons from/to this stack using the Pop and Push instructions (The first neuron is automatically added). In our demo, there is only 1 item currently on the stack, that’s the one being solved. This item displays&#160; a square in the stack UI element. </li>
<li>All the neurons that were assigned as meaning to the links starting from the solvable neuron. The top one will be executed first.&#160; A special case is the ‘Actions’ neuron, which will only be solved when all the others have been, no matter where it is found in the list. </li>
<li>A stack containing all the processor frames.&#160; A frame represents a single cluster’s code that is being executed by the processor. Since some statements call other clusters, like conditional statements, code blocks,… a processor will usually have a number of frames active. This provides an exact view of the processor’s current execution location.      <br />The following info is provided for each frame, from top to bottom
<ul>
<li>The code, in textual form. Each code unit can easily be selected separately for debugging purposes (check out the context menu on each item to see what you can do with it).&#160; It’s not possible to edit in this window though (you have to open the editor for this). </li>
<li>The name (or id when no name is defined) of the neuron that defines all the code. </li>
<li>The relationship between the neuron that defines the code and the actual cluster containing the code.&#160; This can be:
<ul>
<li>Children: in this case, the neuron that defines the code, is the cluster that contains the code. </li>
<li>Rules: the neuron that defines the code has a link with meaning ‘Actions’ to a code cluster. </li>
<li>Actions: the neuron that defines the code has a link with meaning ‘Actions’ to a code cluster. </li>
</ul>
</li>
</ul>
</li>
</ul>
<p>The detailed view is great to have an overview of where we are in the processing stage, but it isn’t very useful to&#160; debug a program flow. It’s better to use the code editor for this because it provides a better overview of the connection between the statements.&#160; To do this, open the editor containing the code and make certain the the processor in the debugger tab’s center screen is selected.&#160; This last action is very important for the following reason: a detailed view is opened for a specific processor, so a single tab always links to a single processor.&#160; Code however is not specific to a processor, it can be called by many processors. So it needs to know the processor context for displaying debug information.&#160; It uses the processor that is selected in the&#160; debugger overview for this purpose.&#160; This has a nice&#160; side effect: when you have multiple processors running, you can quickly switch between active processor and view where each one is in the code. Note that the code editor will put a red square around the statement that will be executed next, to indicate execution location.</p>
<h4>Do the debug</h4>
</p>
</p>
<p> <a href="http://janbogaerts.name/wp-content/uploads/2009/06/image18.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 0px; border-right-width: 0px" height="669" alt="image" src="http://janbogaerts.name/wp-content/uploads/2009/06/image-thumb18.png" width="801" border="0" /></a><br />
<h5>Code flow</h5>
<p>We are ready now to start debugging the network. The first thing you can do is walk through the code using the following commands:</p>
<ul>
<li><strong>Run (F5)</strong>: continue execution until the next breakpoint or until the processor is finished (only active when paused). </li>
<li><strong>Next step (F6)</strong>: execute the next step only and&#160; pause again (only active when paused). Note, when&#160; you do a <em>step next</em> on a split instruction that creates multiple sub processors, all sub processors will also wait on the next statement, they wont run wild, but wait until you tell them what to do, which is very useful for inspecting stuff. </li>
<li><strong>Pause</strong>: stop execution and wait until the <em>Run</em> or <em>Next step</em> command have been given (only active when running). </li>
<li><strong>Stop</strong>: Ok, this sounds silly, I know, but I haven’t yet implemented the stop.&#160; I’ve always been able to stop in other ways (I’m running the debugger inside another debugger which is great for creating a schizoid coding mind). If you feel an urgent need for this command, let me know, otherwise, it’ll get in there,&#160; I just have absolutely no time frame for this. </li>
</ul>
<h5>Inspecting values</h5>
<p><a href="http://janbogaerts.name/wp-content/uploads/2009/06/image19.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 0px 0px 10px; border-right-width: 0px" height="186" alt="image" src="http://janbogaerts.name/wp-content/uploads/2009/06/image-thumb19.png" width="275" align="right" border="0" /></a> When a processor is paused, it is possible to inspect the value of any item that returns a result, this includes: variables, globals, result statements, bool expressions and ByRefs. You can do this by selecting the item you want to inspect with the mouse, and pressing <strong>F7</strong> or through it’s context menu (Inspect value). This opens a dialog with the debug info of the result.&#160; This can be empty, 1 or multiple neurons.</p>
<p>Debug info for a neuron contains the following info:</p>
<ul>
<li>All the incoming links, where they point to and the meaning of the link (note that the meaning UI element still has to be changed into a debug neuron). </li>
<li>All the outgoing links, where they point to and the meaning of&#160; the link. </li>
<li>All the clusters that contain the parent node. </li>
<li>When the parent node is a cluster, all it’s children. </li>
<li>When the parent is a cluster, the meaning of the cluster is depicted, in brackets, after it’s name.&#160; This is also a debug UI element. </li>
</ul>
<p>The debug info is depicted recursively for all neurons. This type of debug visualization is used in multiple places throughout the designer.&#160; You might have noticed that the <em>echo channel</em> uses this UI element to depict the incoming and outgoing neurons. The detailed view of a processor also uses it to depict most of the neurons. </p>
<h5>Watches</h5>
<p><a href="http://janbogaerts.name/wp-content/uploads/2009/06/image20.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 10px 0px 0px; border-right-width: 0px" height="162" alt="image" src="http://janbogaerts.name/wp-content/uploads/2009/06/image-thumb20.png" width="451" align="left" border="0" /></a> A final feature of the debugger is watches.&#160; These allow you to observe the content of variables and globals in a list for a single processor or across all processors for those that are paused.&#160; </p>
<p>This feature is best experienced using the ‘<em>English language definition</em>’ demo since this performs some splits while processing text input. I have put a breakpoint in the ‘<em>Code: Stage 1.1</em>’ page on the second <em>if</em> statement&#160; (first child <em>if</em> in the left-side path of the only root <em>if</em>) and ran it until ‘<em>Found == Sentence(flow</em>)’ to get the screenshot on the left.</p>
<p>To add watches, drag a variable or global and drop it in the left part of the debugger tab.&#160; This will add it at the bottom of the list. If you are dragging it from a code editor, it is best to hold the <em>ctrl</em> key pressed, so that the item stays at it’s original position.&#160; Note that it’s currently not yet possible to drag from the toolbox.&#160; This is a small bug that still needs fixing. Also note that it’s not yet&#160; possible to remove variables (except by editing the designer file).&#160; This command will be added very soon (just goes to show how fresh the debugger still is).</p>
<p>By default, a list of watches with their values for the selected processor is depicted.&#160; The left side is the name of the variable (or it’s id if no name has yet been assigned). To the right of the name, the content of the variable is displayed. This can be empty, 1 or more neurons, all of which are depicted using the debug UI element for neurons.</p>
<p><a href="http://janbogaerts.name/wp-content/uploads/2009/06/image21.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 0px 0px 10px; border-right-width: 0px" height="207" alt="image" src="http://janbogaerts.name/wp-content/uploads/2009/06/image-thumb21.png" width="521" align="right" border="0" /></a> </p>
</p>
</p>
<p>If you switch to variable view, the left section of the debugger tab will only display a radio button for each watch. The middle section, which contains processor info, will now display the contents of the selected watch for each processor.&#160; </p>
<p>Also note that, when a processor gets split up into multiple sub procs, the view will switch to a tree.&#160; The root node shows the number of processors contained by the node. If a new input event is sent to the network before the previous has been processed, it is added as a list item, at end of the list. If sub processors split up, more sub nodes are created as children of the nodes that triggered the split (tree structure). This allows you to see how processors are related to each other.&#160; At the moment you can only see the current state, through the tree/list structure.&#160; In the future, an extra view might be added that shows a line view over time to show when and how may processors did a split and when they died out, although that’s just an idea at the moment, so don’t put your hopes up to see it any time soon, there are still far more important things to do.</p>
<h5>Errors and warnings</h5>
<p>If there are any errors generated by the code, either through the <em>Error</em> or <em>Warning</em> instruction or because of an error in the code, you can view exactly where it occurred. All messages are stored in the log tab. When they are blue, you can double click on them. This will open a code editor with the statement selected&#160; that caused the log item (note: if it is somewhere in a sub section, this is not expanded automatically) Because you can use the same statement in multiple locations, only the first few will be selected, this is to take care of some problems with WPF’s standard controls (will be fixed in the future).</p>
<p>As you can see, it’s all still fresh,&#160; but functional. The debugger has already become a central point of usage for me and I suspect this will only increase, so this will get some extensive testing early on. There are plenty of things that still need adding like conditional breakpoints, counts on breakpoints, enabling-disabling of breakpoints, more commands on the breakpoints-list (like clear, enable/disable all,…),… These things will probably be added as needed.</p>
<p>I am certain there is plenty more to say about NND’s debugger, I just can’t think of anything&#160; anymore, so I guess I’ll leave it by this for today. It’s already turned out a long enough post.</p>
]]></content:encoded>
			<wfw:commentRss>http://janbogaerts.name/index.php/2009/06/09/the-debugger/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
