<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>James D. McCaffrey</title>
	<atom:link href="http://jamesmccaffrey.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jamesmccaffrey.wordpress.com</link>
	<description>Software Research, Development, and Testing</description>
	<lastBuildDate>Sun, 19 Feb 2012 19:12:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jamesmccaffrey.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/e007a02c962a4aabf7590da92ed4c1ec?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>James D. McCaffrey</title>
		<link>http://jamesmccaffrey.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jamesmccaffrey.wordpress.com/osd.xml" title="James D. McCaffrey" />
	<atom:link rel='hub' href='http://jamesmccaffrey.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Two Excellent .NET Developer Conferences</title>
		<link>http://jamesmccaffrey.wordpress.com/2012/02/19/two-excellent-net-developer-conferences/</link>
		<comments>http://jamesmccaffrey.wordpress.com/2012/02/19/two-excellent-net-developer-conferences/#comments</comments>
		<pubDate>Sun, 19 Feb 2012 19:10:39 +0000</pubDate>
		<dc:creator>jamesdmccaffrey</dc:creator>
				<category><![CDATA[Software Test Automation]]></category>

		<guid isPermaLink="false">http://jamesmccaffrey.wordpress.com/?p=687</guid>
		<description><![CDATA[There are two excellent conferences coming up for software developers who use Microsoft .NET technology. By sheer coincidence (I asked the organizers), both conferences will be during the same week, March 26 through March 30, in Las Vegas, Nevada. The &#8230; <a href="http://jamesmccaffrey.wordpress.com/2012/02/19/two-excellent-net-developer-conferences/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=687&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are two excellent conferences coming up for software developers who use Microsoft .NET technology. By sheer coincidence (I asked the organizers), both conferences will be during the same week, March 26 through March 30, in Las Vegas, Nevada. The two conferences are DevConnections (<a href="http://www.devconnections.com/home.aspx">http://www.devconnections.com/home.aspx</a>) and Visual Studio Live (<a href="http://vslive.com/Home.aspx">http://vslive.com/Home.aspx</a>). I&#8217;ve spoken at and attended both of these conferences in the past and can recommend both. The best way for you to get a feel for what they&#8217;re like, and how they differ from each other, is to go to the conferences Web sites and examine the schedules and descriptions of talks. I will be presenting short out-of-band talks at both events. My talks will be about artificial intelligence techniques &#8212; things that are probably not immediately useful to most developers but topics that many developers find quite interesting. By the way, my recommendation of these two conferences is not based on the fact that I&#8217;ll be speaking at them &#8212; I wouldn&#8217;t be speaking at the events if I didn&#8217;t believe they delivered a good product to attendees. My two talks will be on &#8220;Simulated Bee Colony Algorithms&#8221; and &#8220;Particle Swarm Optimization&#8221;. Check out the conference sites and if you make it out to Las Vegas be sure to track me down and say hello.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmccaffrey.wordpress.com/687/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmccaffrey.wordpress.com/687/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmccaffrey.wordpress.com/687/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmccaffrey.wordpress.com/687/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmccaffrey.wordpress.com/687/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmccaffrey.wordpress.com/687/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmccaffrey.wordpress.com/687/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmccaffrey.wordpress.com/687/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmccaffrey.wordpress.com/687/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmccaffrey.wordpress.com/687/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmccaffrey.wordpress.com/687/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmccaffrey.wordpress.com/687/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmccaffrey.wordpress.com/687/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmccaffrey.wordpress.com/687/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=687&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamesmccaffrey.wordpress.com/2012/02/19/two-excellent-net-developer-conferences/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/938a11bef8b79c3e2f4389e339e2a9ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesdmccaffrey</media:title>
		</media:content>
	</item>
		<item>
		<title>Demystifying the C# Yield-Return Mechanism</title>
		<link>http://jamesmccaffrey.wordpress.com/2012/02/11/demystifying-the-c-yield-return-mechanism/</link>
		<comments>http://jamesmccaffrey.wordpress.com/2012/02/11/demystifying-the-c-yield-return-mechanism/#comments</comments>
		<pubDate>Sat, 11 Feb 2012 20:59:57 +0000</pubDate>
		<dc:creator>jamesdmccaffrey</dc:creator>
				<category><![CDATA[Software Test Automation]]></category>

		<guid isPermaLink="false">http://jamesmccaffrey.wordpress.com/?p=681</guid>
		<description><![CDATA[In the current February 2012 issue of Visual Studio Magazine, I wrote an article titled &#8220;Demystifying the C# Yield-Return Mechanism&#8221;. My article starts: I remember when the C# language yield-return statement was released as part of C# 2.0 along with &#8230; <a href="http://jamesmccaffrey.wordpress.com/2012/02/11/demystifying-the-c-yield-return-mechanism/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=681&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the current February 2012 issue of Visual Studio Magazine, I wrote an article titled &#8220;Demystifying the C# Yield-Return Mechanism&#8221;. My article starts:</p>
<p>I remember when the C# language yield-return statement was released as part of C# 2.0 along with Visual Studio 2005. Early documentation for the yield-return mechanism made the statement sound exotic and mysterious.   Recent discussions with some of my developer colleagues suggested that several years later now the yield-return statement isn&#8217;t used very often. We suspect this lack of use is not so much because developers don&#8217;t know how to use the yield-return mechanism, but rather mostly because developers aren&#8217;t quite sure exactly when to use yield-return. In this article I&#8217;ll describe three common programming scenarios where you might want to consider using yield-return:    1. Generating a sequence of strings where each string in the sequence depends on the value of the previous string. 2. Processing a text file sequentially where different kinds of lines are treated differently. 3. Sequentially filtering or modifying a large List collection of objects.</p>
<p>You can read the rest of the article online at <a href="http://visualstudiomagazine.com/articles/2012/02/01/demystifying-the-c-yield-return-mechanism.aspx">http://visualstudiomagazine.com/articles/2012/02/01/demystifying-the-c-yield-return-mechanism.aspx</a></p>
<p><a href="http://jamesmccaffrey.files.wordpress.com/2012/02/cover_feb2012.jpg"><img class="alignnone size-full wp-image-682" title="cover_feb2012" src="http://jamesmccaffrey.files.wordpress.com/2012/02/cover_feb2012.jpg?w=640" alt=""   /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmccaffrey.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmccaffrey.wordpress.com/681/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmccaffrey.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmccaffrey.wordpress.com/681/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmccaffrey.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmccaffrey.wordpress.com/681/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmccaffrey.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmccaffrey.wordpress.com/681/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmccaffrey.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmccaffrey.wordpress.com/681/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmccaffrey.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmccaffrey.wordpress.com/681/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmccaffrey.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmccaffrey.wordpress.com/681/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=681&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamesmccaffrey.wordpress.com/2012/02/11/demystifying-the-c-yield-return-mechanism/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/938a11bef8b79c3e2f4389e339e2a9ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesdmccaffrey</media:title>
		</media:content>

		<media:content url="http://jamesmccaffrey.files.wordpress.com/2012/02/cover_feb2012.jpg" medium="image">
			<media:title type="html">cover_feb2012</media:title>
		</media:content>
	</item>
		<item>
		<title>Ant Colony Optimization</title>
		<link>http://jamesmccaffrey.wordpress.com/2012/02/01/ant-colony-optimization/</link>
		<comments>http://jamesmccaffrey.wordpress.com/2012/02/01/ant-colony-optimization/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 14:01:45 +0000</pubDate>
		<dc:creator>jamesdmccaffrey</dc:creator>
				<category><![CDATA[Software Test Automation]]></category>

		<guid isPermaLink="false">http://jamesmccaffrey.wordpress.com/?p=674</guid>
		<description><![CDATA[In the February 2012 issue of MSDN Magazine I wrote an article that presents and explains Ant Colony Optimization (ACO). See http://msdn.microsoft.com/en-us/magazine/hh781027.aspx. ACO is a meta-heuristic (set of guidelines that can be used to create a specific algorithm) which is &#8230; <a href="http://jamesmccaffrey.wordpress.com/2012/02/01/ant-colony-optimization/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=674&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the February 2012 issue of MSDN Magazine I wrote an article that presents and explains Ant Colony Optimization (ACO). See http://msdn.microsoft.com/en-us/magazine/hh781027.aspx. ACO is a meta-heuristic (set of guidelines that can be used to create a specific algorithm) which is intended to solve network graph problems such as the Traveling Salesman Problem (TSP) where the goal is to find the shortest path that visits each city exactly once. ACO models the pheromone laying behavior of ants. Each ant represents a possible solution. As each any visits a node in the graph, it lays an amount of pheromone on the node. Shorter paths are visited more often and so more pheromones are deposited on nodes which are parts of shorter paths. When each ant picks a semi-random path through the graph, at each node the choice of next node to take is influenced by the pheromones on the candidate nodes: nodes with more pheromones are more likely to be selected. Implementing ACO is surprisingly tricky. ACO is a kind of combinatorial optimization technique &#8212; a technique to find the best combination from a large set of possible combinations. In the TSP, each possible path is a combination of cities. I&#8217;ve seen ACO stretched and applied to all kinds of problems, but in my opinion ACO is best suited for problems that very closely resemble TSP while other combinatorial optimization technique such as Simulated Annealing and Simulated Bee Colony algorithms are better suited for more general types of problems.</p>
<p><a href="http://jamesmccaffrey.files.wordpress.com/2012/02/antcolonydemorun.jpg"><img class="alignnone size-medium wp-image-675" title="AntColonyDemoRun" src="http://jamesmccaffrey.files.wordpress.com/2012/02/antcolonydemorun.jpg?w=260&#038;h=300" alt="" width="260" height="300" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmccaffrey.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmccaffrey.wordpress.com/674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmccaffrey.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmccaffrey.wordpress.com/674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmccaffrey.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmccaffrey.wordpress.com/674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmccaffrey.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmccaffrey.wordpress.com/674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmccaffrey.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmccaffrey.wordpress.com/674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmccaffrey.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmccaffrey.wordpress.com/674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmccaffrey.wordpress.com/674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmccaffrey.wordpress.com/674/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=674&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamesmccaffrey.wordpress.com/2012/02/01/ant-colony-optimization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/938a11bef8b79c3e2f4389e339e2a9ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesdmccaffrey</media:title>
		</media:content>

		<media:content url="http://jamesmccaffrey.files.wordpress.com/2012/02/antcolonydemorun.jpg?w=260" medium="image">
			<media:title type="html">AntColonyDemoRun</media:title>
		</media:content>
	</item>
		<item>
		<title>Custom Latitude Longitude Index Interval using Binary Search</title>
		<link>http://jamesmccaffrey.wordpress.com/2012/01/27/custom-latitude-longitude-index-interval-using-binary-search/</link>
		<comments>http://jamesmccaffrey.wordpress.com/2012/01/27/custom-latitude-longitude-index-interval-using-binary-search/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 20:40:58 +0000</pubDate>
		<dc:creator>jamesdmccaffrey</dc:creator>
				<category><![CDATA[Software Test Automation]]></category>

		<guid isPermaLink="false">http://jamesmccaffrey.wordpress.com/?p=667</guid>
		<description><![CDATA[This week I was working on an interesting problem and found an interesting bug. The overall problem was to create a custom indexing scheme for latitude and longitude data by writing a function that accepts a lat-lon and returns a &#8230; <a href="http://jamesmccaffrey.wordpress.com/2012/01/27/custom-latitude-longitude-index-interval-using-binary-search/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=667&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This week I was working on an interesting problem and found an interesting bug. The overall problem was to create a custom indexing scheme for latitude and longitude data by writing a function that accepts a lat-lon and returns a sector ID. As part of that problem I wanted to write a helper function that accepts a latitude (which ranges from -90.0 to +90.0) and returns which 0.1 degree interval the latitude falls in. Let me illustrate using a smaller fake example where &#8220;latitude&#8221; ranges from -1.0 to +10.0. For this example I want the following:</p>
<p>[-1.0 to -0.9) -&gt; 0<br />
[-0.9 to -0.8) -&gt; 1<br />
[-0.8 to -0.7) -&gt; 2<br />
. . .<br />
[-0.1 to  0.0) -&gt; 9<br />
[ 0.0 to  0.1) -&gt; 10<br />
[ 0.1 to  0.2) -&gt; 11<br />
. . .<br />
[ 0.9 to 1.0]  -&gt; 19</p>
<p>Notice that all but the last interval are open intervals, and the last is closed to capture the final 1.0 value. If an input is 0.245 then the output should be 12. I could do a sequential search but I wanted to use a binary search because I was going to call the function millions of times. My first attempt was this:</p>
<p>static int LatIndexOf(double latitude) // small experiment<br />
{<br />
  // input is a fake latitude in [-1.0 +1.0]<br />
  // divide 0.1 degree intervals: [-1.0 -0.9) = 0, etc.</p>
<p>  if (latitude == -1.0) return 0;<br />
  if (latitude == 1.0) return 19;</p>
<p>  int lo = 0;     //<br />
  int hi = 19;<br />
  int mid = (lo + hi) / 2;</p>
<p>  bool found = false;<br />
  while (found == false)<br />
  {<br />
    double left = -1.0 + (0.1 * mid); // left part of interval<br />
    double right = left + 0.1;        // right part of interval<br />
    if (latitude &gt;= left &amp;&amp; latitude &lt; right)<br />
      return mid;<br />
    else if (latitude &lt; left)<br />
    {<br />
      hi = mid &#8211; 1; mid = (lo + hi) / 2;<br />
    }<br />
    else<br />
    {<br />
       lo = mid + 1; mid = (lo + hi) / 2;<br />
    }<br />
  }<br />
  throw new Exception(&quot;LatIndexOf no value&quot;);<br />
}</p>
<p>Because I was going to process hundreds of millions of real lat-lon data, I took the time to run pretty thorough tests on my function. As first written I ran into very nasty floating point errors that gave incorrect results for certain inputs. The hacky-fix was to round all floating point values:</p>
<p>static int LatIndexOf(double latitude)<br />
{<br />
  latitude = Math.Round(latitude, 8); // round to 8 places<br />
  . . .</p>
<p>  double left = -1.0 + (0.1 * mid);<br />
  left = Math.Round(left, 8);<br />
  . . .<br />
  double right = left + 0.1;<br />
  right = Math.Round(right, 8);<br />
  . . .</p>
<p>Moral: watch out for equality comparisons on floating point values.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmccaffrey.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmccaffrey.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmccaffrey.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmccaffrey.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmccaffrey.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmccaffrey.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmccaffrey.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmccaffrey.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmccaffrey.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmccaffrey.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmccaffrey.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmccaffrey.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmccaffrey.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmccaffrey.wordpress.com/667/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=667&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamesmccaffrey.wordpress.com/2012/01/27/custom-latitude-longitude-index-interval-using-binary-search/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/938a11bef8b79c3e2f4389e339e2a9ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesdmccaffrey</media:title>
		</media:content>
	</item>
		<item>
		<title>Calculating Category Utility</title>
		<link>http://jamesmccaffrey.wordpress.com/2012/01/21/calculating-category-utility/</link>
		<comments>http://jamesmccaffrey.wordpress.com/2012/01/21/calculating-category-utility/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 16:22:42 +0000</pubDate>
		<dc:creator>jamesdmccaffrey</dc:creator>
				<category><![CDATA[Software Test Automation]]></category>

		<guid isPermaLink="false">http://jamesmccaffrey.wordpress.com/?p=661</guid>
		<description><![CDATA[Category Utility (CU) is a clever measure of how good a clustering of categorical data is. Here&#8217;s an example of how to calculate category utility. Suppose you have three attributes, color, size, tax. Color can be red, blue, green, or &#8230; <a href="http://jamesmccaffrey.wordpress.com/2012/01/21/calculating-category-utility/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=661&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Category Utility (CU) is a clever measure of how good a clustering of categorical data is. Here&#8217;s an example of how to calculate category utility. Suppose you have three attributes, color, size, tax. Color can be red, blue, green, or yellow. Size can be small, medium, or large. Tax can be false or true. Let&#8217;s say you have five tuples and cluster them into two parts, k= 0 and k = 1, like so:</p>
<p>&#8212;&#8212;&#8212;&#8211;<br />
Red Small True<br />
Red Large False<br />
&#8212;&#8212;&#8212;&#8211;<br />
Blue Medium True<br />
Green Medium True<br />
Green Medium False<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>Step 1 &#8211; Calculate the probability of each cluster.</p>
<p>P(k = 0) = 2/5 = 0.40<br />
P(k = 1) = 3/5 = 0.60</p>
<p>Step 2 &#8211; Calculate the unconditional expectation = sum of squared probabilities of all attribute values across all clusters.</p>
<p>Red (2/5)^2 = 0.16<br />
Blue (1/5)^2 = 0.04<br />
Green (2/5)^2 = 0.16<br />
Yellow (0/5)^2 = 0.00<br />
&#8212;<br />
Small (1/5)^2 = 0.04<br />
Medium (3/5)^2 = 0.36<br />
Large (1/5)^2 = 0.04<br />
&#8212;<br />
False (2/5)^2 = 0.16<br />
True (3/5)^2 = 0.36<br />
&#8212;-<br />
1.32</p>
<p>Step 3 &#8211; Calculate conditional expectations for each cluster.</p>
<p>A. k = 0</p>
<p>Red (2/2)^2 = 1.00<br />
Blue (0/2)^2 = 0.00<br />
Green (0/2)^2 = 0.00<br />
Yellow (0/2)^2 = 0.00<br />
&#8212;<br />
Small (1/2)^2 = 0.25<br />
Medium (0/2)^2 = 0.00<br />
Large (1/2)^2 = 0.25<br />
&#8212;<br />
False (1/2)^2 = 0.25<br />
True (1/2)^2 = 0.25<br />
&#8212;-<br />
2.00<br />
B. k = 1</p>
<p>Red (0/3)^2 = 0.00<br />
Blue (1/3)^2 = 0.11<br />
Green (2/3)^2 = 0.44<br />
Yellow (0/3)^2 = 0.00<br />
&#8212;<br />
Small (0/3)^2 = 0.00<br />
Medium (3/3)^2 = 1.00<br />
Large (0/3)^2 = 0.00<br />
&#8212;<br />
False (1/3)^2 = 0.11<br />
True (2/3)^2 = 0.44<br />
&#8212;-<br />
2.11</p>
<p>Step 4 &#8211; Put it all together.</p>
<p>CU = (0.40 * (2.00 &#8211; 1.32)) + (0.60 * (2.11 &#8211; 1.32)) / 2<br />
= 0.3733</p>
<p>The equation for the last step is too tricky for me to type out. If you search the Internet for Category Utility, you&#8217;ll find the equation in a Wikipedia entry. Coding up a routine to compute category utility is surprisingly tricky. See image below for a demo example.</p>
<p><a href="http://jamesmccaffrey.files.wordpress.com/2012/01/categoryutility.jpg"><img class="alignnone size-medium wp-image-663" title="CategoryUtility" src="http://jamesmccaffrey.files.wordpress.com/2012/01/categoryutility.jpg?w=195&#038;h=300" alt="" width="195" height="300" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmccaffrey.wordpress.com/661/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmccaffrey.wordpress.com/661/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmccaffrey.wordpress.com/661/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmccaffrey.wordpress.com/661/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmccaffrey.wordpress.com/661/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmccaffrey.wordpress.com/661/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmccaffrey.wordpress.com/661/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmccaffrey.wordpress.com/661/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmccaffrey.wordpress.com/661/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmccaffrey.wordpress.com/661/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmccaffrey.wordpress.com/661/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmccaffrey.wordpress.com/661/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmccaffrey.wordpress.com/661/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmccaffrey.wordpress.com/661/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=661&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamesmccaffrey.wordpress.com/2012/01/21/calculating-category-utility/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/938a11bef8b79c3e2f4389e339e2a9ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesdmccaffrey</media:title>
		</media:content>

		<media:content url="http://jamesmccaffrey.files.wordpress.com/2012/01/categoryutility.jpg?w=195" medium="image">
			<media:title type="html">CategoryUtility</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating a Super Simple COM Object</title>
		<link>http://jamesmccaffrey.wordpress.com/2012/01/14/creating-a-super-simple-com-object/</link>
		<comments>http://jamesmccaffrey.wordpress.com/2012/01/14/creating-a-super-simple-com-object/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 14:42:55 +0000</pubDate>
		<dc:creator>jamesdmccaffrey</dc:creator>
				<category><![CDATA[Software Test Automation]]></category>

		<guid isPermaLink="false">http://jamesmccaffrey.wordpress.com/?p=655</guid>
		<description><![CDATA[Every now and then I teach a beginning API test automation class. As part of that class I like to walk students through the process of creating a super simple COM object to test. The idea is to show students &#8230; <a href="http://jamesmccaffrey.wordpress.com/2012/01/14/creating-a-super-simple-com-object/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=655&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Every now and then I teach a beginning API test automation class. As part of that class I like to walk students through the process of creating a super simple COM object to test. The idea is to show students some of the magic behind the scenes which I believe will help them better understand the test automation. Here are the steps for creating a super simple COM object named MathCOMLib housed in file MathCOMLib.dll which contains an Interface named IMathMethods which is exposed as a class MathClass which contains a single method Sum(int x, int y) that returns the sum of integers x and y. It&#8217;s surprisingly tricky in the sense that one bad mouse click means disaster.</p>
<p>Launch an instance of Visual Studio being sure to be using &#8220;Run as administrator&#8221;. I&#8217;m using VS 2010 but most recent versions of VS work the same to create a COM component. Click File | New | Project. Select the C++ | ATL project template, name it MathCOMLib (the name of the project will become the name of the resulting DLL), specify any convenient Location, clear the &#8220;Create directory for solution&#8221; and &#8220;Add to source control&#8221; check boxes, and click OK.</p>
<p>In the Solution Explorer window, right click on the bolded MathCOMLib project (be careful to get the project, not the solution entry), and select Add | Class from the context menu. Select the ATL Simple Object item and click Add.</p>
<p>In the ATL Simple Object Wizard, enter MathClass into the Short Name field. In VS 2008 and earlier, all the remaining fields (including ProgID) will be filled in automatically. But, immensely annoyingly, with VS 2010 you need to manually type in the ProgID field: MathCOMLib.MathClass (the name of the Project + &#8220;.&#8221; + the name of the Class). The ProgID field is used if you want to allow your COM object to be callable from a scripting language like JavaScript. Click Next. Leave all the File Type Handler Options blank, and click Next. Leave the Options default selections alone, and click Finish.</p>
<p>Now in the Solution Explorer window, select the Class View tab. You should see an interface entry named IMathClass. Right click on that interface (not the class as you might expect) and select Add | Add Method. In the Add Method Wizard, enter Sum for the Method Name. Select the &#8220;in&#8221; Parameter Attribute, select LONG for the Parameter Type, enter x for the Parameter Name, and then click the Add button. Repeat for y (&#8220;in&#8221;, &#8220;LONG&#8221;, &#8220;y&#8221;, Add). Now, select the *LONG Parameter Type which enables the retval Parameter Attribute, and check retval, and enter pRes (which stands for pointer to result) as the Parameter Name, and click Add. Click Next.</p>
<p>Leave the IDL Attribute alone, and click Finish. Now go back to the main Solution Explorer window. You should see a MathClass.cpp entry and then double click on it. You will be transferred to auto-generated code that looks like:</p>
<p>STDMETHODIMP CMathClass::Sum(LONG x, LONG y, LONG* pRes)</p>
<p>{</p>
<p>// TODO: Add your implementation code here</p>
<p>return S_OK;</p>
<p>}</p>
<p>Replace the comment line with:</p>
<p>*pRes = x + y;</p>
<p>Notice that return values are passed using a pointer because the regular return is reserved for an HRESULT. Now, on a 32-bit machine you can just Build the library COM object DLL by clicking Build | Build Solution. But on a 64-bit machine you need to set the Build Configuration to 64-bit by Build | Configuration Manager -&gt; Active Solution Platform -&gt; x64. The Build process also registers the COM object on your current machine so you don&#8217;t have to do it by using the regsvr32.exe or regsvr64.exe utility. At this point you can use Windows Explorer and verify that you just created a file named MathCOMLib.dll at wherever you told VS to save it, in the .\MathCOMLib\Debug subdirectory (along with a bazillion other files).</p>
<p>Now you can call your Sum method to test it in several ways. The easiest is from a C# console application. After creating the application you would first Add Reference to the MathCOMLib.dll file. Then calling code would look like this:</p>
<p>MathLib.MathClass mc = new MathLib.MathClass();</p>
<p>int x = 2;</p>
<p>int y = 3;</p>
<p>int sum = mc.Sum(x, y);</p>
<p>Console.WriteLine(sum);</p>
<p>From JavaScript you could call the method like this:</p>
<p>var mc = new ActiveXObject(&#8220;MathCOMLib.MathClass&#8221;);</p>
<p>var x = 2;</p>
<p>var y = 3;</p>
<p>var sum = mc.Sum(x, y);</p>
<p>WScript.Echo(sum);</p>
<p>And of course you could call the Sum method by using C++ if you&#8217;re a real glutton for punishment.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmccaffrey.wordpress.com/655/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmccaffrey.wordpress.com/655/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmccaffrey.wordpress.com/655/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmccaffrey.wordpress.com/655/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmccaffrey.wordpress.com/655/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmccaffrey.wordpress.com/655/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmccaffrey.wordpress.com/655/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmccaffrey.wordpress.com/655/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmccaffrey.wordpress.com/655/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmccaffrey.wordpress.com/655/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmccaffrey.wordpress.com/655/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmccaffrey.wordpress.com/655/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmccaffrey.wordpress.com/655/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmccaffrey.wordpress.com/655/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=655&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamesmccaffrey.wordpress.com/2012/01/14/creating-a-super-simple-com-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/938a11bef8b79c3e2f4389e339e2a9ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesdmccaffrey</media:title>
		</media:content>
	</item>
		<item>
		<title>Simulated Annealing</title>
		<link>http://jamesmccaffrey.wordpress.com/2012/01/05/simulated-annealing/</link>
		<comments>http://jamesmccaffrey.wordpress.com/2012/01/05/simulated-annealing/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 18:32:32 +0000</pubDate>
		<dc:creator>jamesdmccaffrey</dc:creator>
				<category><![CDATA[Software Test Automation]]></category>

		<guid isPermaLink="false">http://jamesmccaffrey.wordpress.com/?p=647</guid>
		<description><![CDATA[In the January 2012 issue of MSDN Magazine I have an article about simulated annealing. Simulated annealing is an artificial intelligence technique that is modeled on the behavior of cooling metals. Simulated annealing can be used to estimate the optimal &#8230; <a href="http://jamesmccaffrey.wordpress.com/2012/01/05/simulated-annealing/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=647&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the January 2012 issue of MSDN Magazine I have an article about simulated annealing. Simulated annealing is an artificial intelligence technique that is modeled on the behavior of cooling metals. Simulated annealing can be used to estimate the optimal solution to difficult or impossible combinatorial optimization problems such as the Traveling Salesman problem where the goal is the find the order in which to visit a set of cities so that the total distance traveled is minimized. Related techniques are Simulated Bee Colony Algorithms and Ant Colony Optimization. However, Genetic Algorithms, Particle Swarm Optimization, and Bacterial Foraging Optimization are more distantly related to Simulated Annealing because they are best suited to solve numeric (rather than combinatorial) optimization problems. You can check the article out at: <a href="http://msdn.microsoft.com/en-us/magazine/hh708758.aspx">http://msdn.microsoft.com/en-us/magazine/hh708758.aspx</a>.</p>
<p><a href="http://jamesmccaffrey.files.wordpress.com/2012/01/sa-demorun1.jpg"><img class="alignnone size-medium wp-image-651" title="SA-DemoRun" src="http://jamesmccaffrey.files.wordpress.com/2012/01/sa-demorun1.jpg?w=248&#038;h=300" alt="" width="248" height="300" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmccaffrey.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmccaffrey.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmccaffrey.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmccaffrey.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmccaffrey.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmccaffrey.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmccaffrey.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmccaffrey.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmccaffrey.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmccaffrey.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmccaffrey.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmccaffrey.wordpress.com/647/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmccaffrey.wordpress.com/647/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmccaffrey.wordpress.com/647/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=647&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamesmccaffrey.wordpress.com/2012/01/05/simulated-annealing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/938a11bef8b79c3e2f4389e339e2a9ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesdmccaffrey</media:title>
		</media:content>

		<media:content url="http://jamesmccaffrey.files.wordpress.com/2012/01/sa-demorun1.jpg?w=248" medium="image">
			<media:title type="html">SA-DemoRun</media:title>
		</media:content>
	</item>
		<item>
		<title>Making a Gradient Background using Paint</title>
		<link>http://jamesmccaffrey.wordpress.com/2011/12/27/making-a-gradient-background-using-paint/</link>
		<comments>http://jamesmccaffrey.wordpress.com/2011/12/27/making-a-gradient-background-using-paint/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 16:21:10 +0000</pubDate>
		<dc:creator>jamesdmccaffrey</dc:creator>
				<category><![CDATA[Software Test Automation]]></category>

		<guid isPermaLink="false">http://jamesmccaffrey.wordpress.com/?p=640</guid>
		<description><![CDATA[You can make a very nice gradient color background using MS Paint. First, open Paint. Resize the white working area to the size you want, for example, 800 x 200 pixels. Pick a color for the right side of the &#8230; <a href="http://jamesmccaffrey.wordpress.com/2011/12/27/making-a-gradient-background-using-paint/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=640&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You can make a very nice gradient color background using MS Paint. First, open Paint. Resize the white working area to the size you want, for example, 800 x 200 pixels. Pick a color for the right side of the gradient, for example green, into Color1 and Color2. Select the rectangle shape and outline and then Fill the entire rectangle with the color. Pick a second color, for example orange, into Color1 and Color2. Select the triangle shape and make a triangle in the lower left part of the image. See first image below.</p>
<p>Now do Ctrl-W and resize the image size in percentage without &#8220;Maintain aspect ratio&#8221; to Vertical = 1% (leave the Horizontal at 100%). Now expand by Ctrl-W, Resize, Vertical = 500%. Now shrink by Ctrl-W, Resize, Vertical = 1%.</p>
<p>At this point expand the image by repeating Ctrl-W, Resize, Vertical = 500% until the image is close to its original size (either 3 or 4 times). Finish with a final resize (without maintaining aspect ratio). Very cool; see result below.</p>
<p><a href="http://jamesmccaffrey.files.wordpress.com/2011/12/gradientcreate1.jpg"><img class="alignnone size-medium wp-image-641" title="GradientCreate1" src="http://jamesmccaffrey.files.wordpress.com/2011/12/gradientcreate1.jpg?w=300&#038;h=158" alt="" width="300" height="158" /></a></p>
<p><a href="http://jamesmccaffrey.files.wordpress.com/2011/12/gradientcreate2.jpg"><img class="alignnone size-medium wp-image-642" title="GradientCreate2" src="http://jamesmccaffrey.files.wordpress.com/2011/12/gradientcreate2.jpg?w=300&#038;h=158" alt="" width="300" height="158" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmccaffrey.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmccaffrey.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmccaffrey.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmccaffrey.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmccaffrey.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmccaffrey.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmccaffrey.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmccaffrey.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmccaffrey.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmccaffrey.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmccaffrey.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmccaffrey.wordpress.com/640/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmccaffrey.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmccaffrey.wordpress.com/640/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=640&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamesmccaffrey.wordpress.com/2011/12/27/making-a-gradient-background-using-paint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/938a11bef8b79c3e2f4389e339e2a9ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesdmccaffrey</media:title>
		</media:content>

		<media:content url="http://jamesmccaffrey.files.wordpress.com/2011/12/gradientcreate1.jpg?w=300" medium="image">
			<media:title type="html">GradientCreate1</media:title>
		</media:content>

		<media:content url="http://jamesmccaffrey.files.wordpress.com/2011/12/gradientcreate2.jpg?w=300" medium="image">
			<media:title type="html">GradientCreate2</media:title>
		</media:content>
	</item>
		<item>
		<title>Neural Network Classification, Categorical Data, Softmax Activation, and Cross Entropy Error</title>
		<link>http://jamesmccaffrey.wordpress.com/2011/12/17/neural-network-classification-categorical-data-softmax-activation-and-cross-entropy-error/</link>
		<comments>http://jamesmccaffrey.wordpress.com/2011/12/17/neural-network-classification-categorical-data-softmax-activation-and-cross-entropy-error/#comments</comments>
		<pubDate>Sat, 17 Dec 2011 18:04:46 +0000</pubDate>
		<dc:creator>jamesdmccaffrey</dc:creator>
				<category><![CDATA[Software Test Automation]]></category>

		<guid isPermaLink="false">http://jamesmccaffrey.wordpress.com/?p=635</guid>
		<description><![CDATA[When using neural networks for classification, there is a relationship between categorical data, using the softmax activation function, and using the cross entropy error function. Suppose you want to use a neural network to classify data that looks like this: &#8230; <a href="http://jamesmccaffrey.wordpress.com/2011/12/17/neural-network-classification-categorical-data-softmax-activation-and-cross-entropy-error/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=635&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When using neural networks for classification, there is a relationship between categorical data, using the softmax activation function, and using the cross entropy error function. Suppose you want to use a neural network to classify data that looks like this:</p>
<p>5.0 7.0 2.0 3.0 red</p>
<p>9.0 8.0 4.0 5.0 blue</p>
<p>2.0 2.0 4.0 7.0 red</p>
<p>6.0 5.0 2.0 8.0 green</p>
<p>8.0 7.0 8.0 7.0 blue</p>
<p>. . .</p>
<p>There are four numeric inputs and one categorical value (red, green, blue) to classify. In this situation it&#8217;s recommended that you use 1-of-N encoding for the categorical data like so:</p>
<p>5.0 7.0 2.0 3.0  1  0  0</p>
<p>9.0 8.0 4.0 5.0  0  0  1</p>
<p>2.0 2.0 4.0 7.0  1  0  0</p>
<p>6.0 5.0 2.0 8.0  0  1  0</p>
<p>8.0 7.0 8.0 7.0  0  0  1</p>
<p>. . .</p>
<p>There&#8217;s a long explanation behind this but just assume this encoding is a good thing. By the way, if there are only two categorical values being predicted you&#8217;d use 1-of-(N-1) encoding, and if you have categorical input you use 1-of-(N-1) encoding on it. Now with this output encoding you want the neural network output layer to have three neurons. In order to compare an output with an input like (0 1 0) instead of using a normal sigmoid or step function, you want the output to be three values between 0.0 and 1.0 that sum to 1.0. Why? Suppose an output is (1.0 1.0 1.0) &#8212; it&#8217;s not entirely clear how to evaluate that against a categorical value of (1 0 0). To get output that sums to 1.0 you can use the softmax function, where you allow arbitrary output values but then compute the sum of their Math.Exp() values and then divide each output by that sum. For example if some output from the neural net is (2.0 -3.0 0.0) their Math.Exp values are (7.39 0.05 1.00) which sum to 8.44 and dividing each by that sum gives a softmax activation output of (0.87 0.01 0.12). By the way, this computation is tricky and you have to guard against numeric overflow.</p>
<p>You can think of softmax outputs as probabilities. But now comparing a softmax output with a training output becomes somewhat of a problem if you use a standard sum of squared deviations (SSD) approach. For example suppose the softmax output is (0.87 0.01 0.12) as above and the training value is (1 0 0). The SSD would be computed as (1 &#8211; 0.87)^2 + (0 &#8211; 0.05)^2 + (0 &#8211; 1.00)^2. You&#8217;d compute all these values and sum them to get the total SSD error. Again there is a huge story here but the net conclusion is that it&#8217;s recommended to use cross entropy error instead of sum of squared deviations error. Cross entropy error, in principle, looks like this:</p>
<p>(1 * Ln(0.87)) + (0 * Ln(0.01)) + (0 * Ln(1.00))</p>
<p>= -0.06 + 0 + 0 = -0.06</p>
<p>You would add all the cross entropies for each training vector up and then multiply by -1. There&#8217;s a lot to understand here but in essence we only look at the 1 term in the training data (multiplying by the 0s has no effect on the sum). If the output is close to 1.0 the Ln is close to zero. To summarize, when using a neural network to classify categorical data, encode the output categorical data using 1-of-N encoding (except if there are only two categories), use the softmax activation function to generate output, and use cross entropy to measure error.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmccaffrey.wordpress.com/635/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmccaffrey.wordpress.com/635/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmccaffrey.wordpress.com/635/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmccaffrey.wordpress.com/635/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmccaffrey.wordpress.com/635/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmccaffrey.wordpress.com/635/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmccaffrey.wordpress.com/635/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmccaffrey.wordpress.com/635/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmccaffrey.wordpress.com/635/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmccaffrey.wordpress.com/635/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmccaffrey.wordpress.com/635/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmccaffrey.wordpress.com/635/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmccaffrey.wordpress.com/635/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmccaffrey.wordpress.com/635/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=635&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamesmccaffrey.wordpress.com/2011/12/17/neural-network-classification-categorical-data-softmax-activation-and-cross-entropy-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/938a11bef8b79c3e2f4389e339e2a9ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesdmccaffrey</media:title>
		</media:content>
	</item>
		<item>
		<title>Plotting Schwefel&#8217;s Function with SciLab</title>
		<link>http://jamesmccaffrey.wordpress.com/2011/12/10/plotting-schwefels-function-with-scilab/</link>
		<comments>http://jamesmccaffrey.wordpress.com/2011/12/10/plotting-schwefels-function-with-scilab/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 16:21:55 +0000</pubDate>
		<dc:creator>jamesdmccaffrey</dc:creator>
				<category><![CDATA[Software Test Automation]]></category>

		<guid isPermaLink="false">http://jamesmccaffrey.wordpress.com/?p=628</guid>
		<description><![CDATA[Schwefel&#8217;s function is often used as a benchmark problem for minimization problems. The function is defined as f(x,y) = (-x * sin(sqrt(abs(x)))) + (-y * sin(sqrt(abs(y)))) The function has a minimum value of 2 * -418.9829 = -837.9658 when both &#8230; <a href="http://jamesmccaffrey.wordpress.com/2011/12/10/plotting-schwefels-function-with-scilab/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=628&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Schwefel&#8217;s function is often used as a benchmark problem for minimization problems. The function is defined as</p>
<p>f(x,y) = (-x * sin(sqrt(abs(x)))) + (-y * sin(sqrt(abs(y))))</p>
<p>The function has a minimum value of 2 * -418.9829 = -837.9658 when both x = 420.9687 and y = 420.9687. The minimum value is hard to find because it is relatively far from the second best solution.</p>
<p>Here are commands to visualize Schwefel&#8217;s function using SciLab, a free open source program similar to MatLab:</p>
<p>x1 = linspace(-500,500,100);</p>
<p>x2 = linspace(-500,500,100);</p>
<p>[X1,X2] = meshgrid(x1,x2);</p>
<p>Z = (-1 * X1. * sin(sqrt(abs(X1)))) + (-1 * X2. * sin(sqrt(abs(X2))));</p>
<p>f = scf();</p>
<p>f.color_map = jetcolormap(64);</p>
<p>plot3d1(x1,x2,Z&#8217;);</p>
<p>SciLab code is close to MatLab code and both are a bit obscure. I generate two vectors of 100 values using linspace, create a cross product of those values using meshgrid (SciLab is case sensitive so X1 is different from x1), defined a function Z (where the dot operator means do a value by value multiplication rather than matrix multiplication), and plot the graph (where the &#8216; operator is the transpose operator). The result is shown below. The minimum value is in the far left corner.</p>
<p><a href="http://jamesmccaffrey.files.wordpress.com/2011/12/schwefelsfunction.jpg"><img class="alignnone size-medium wp-image-629" title="SchwefelsFunction" src="http://jamesmccaffrey.files.wordpress.com/2011/12/schwefelsfunction.jpg?w=300&#038;h=238" alt="" width="300" height="238" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmccaffrey.wordpress.com/628/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmccaffrey.wordpress.com/628/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmccaffrey.wordpress.com/628/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmccaffrey.wordpress.com/628/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmccaffrey.wordpress.com/628/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmccaffrey.wordpress.com/628/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmccaffrey.wordpress.com/628/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmccaffrey.wordpress.com/628/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmccaffrey.wordpress.com/628/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmccaffrey.wordpress.com/628/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmccaffrey.wordpress.com/628/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmccaffrey.wordpress.com/628/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmccaffrey.wordpress.com/628/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmccaffrey.wordpress.com/628/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamesmccaffrey.wordpress.com&amp;blog=16384225&amp;post=628&amp;subd=jamesmccaffrey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamesmccaffrey.wordpress.com/2011/12/10/plotting-schwefels-function-with-scilab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/938a11bef8b79c3e2f4389e339e2a9ba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesdmccaffrey</media:title>
		</media:content>

		<media:content url="http://jamesmccaffrey.files.wordpress.com/2011/12/schwefelsfunction.jpg?w=300" medium="image">
			<media:title type="html">SchwefelsFunction</media:title>
		</media:content>
	</item>
	</channel>
</rss>
