<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>ProgramError</title>
	
	<link>http://programerror.com</link>
	<description />
	<lastBuildDate>Thu, 11 Mar 2010 08:57:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<atom:link rel="next" href="http://programerror.com/feed/?page=2" />

		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/programerror" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="programerror" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Fun with Filters and Brushes</title>
		<link>http://programerror.com/2010/03/fun-with-filters-and-brushes/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=fun-with-filters-and-brushes</link>
		<comments>http://programerror.com/2010/03/fun-with-filters-and-brushes/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 03:57:55 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Photography]]></category>

		<guid isPermaLink="false">http://programerror.com/?p=157</guid>
		<description><![CDATA[<a href="http://programerror.com/2010/03/fun-with-filters-and-brushes/" title="Fun with Filters and Brushes"><img src="http://programerror.com/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=157&amp;w=180" width="180" height="120" alt="Fun with Filters and Brushes" style="float:left;padding:0 10px 10px 0;" /></a>This photo was taken this past fall and had what I thought to be a nice composition.  The colors were, however unremarkable, except for the windows on the crosswalk.  Since I recently upgraded to Aperture 3.0, I decided to play around with the new brushed filters.  A few brush strokes and a [...]]]></description>
			<content:encoded><![CDATA[<a href="http://programerror.com/2010/03/fun-with-filters-and-brushes/" title="Fun with Filters and Brushes"><img src="http://programerror.com/wp-content/plugins/yet-another-photoblog/YapbThumbnailer.php?post_id=157&amp;w=180" width="180" height="120" alt="Fun with Filters and Brushes" style="float:left;padding:0 10px 10px 0;" /></a><p>This photo was taken this past fall and had what I thought to be a nice composition.  The colors were, however unremarkable, except for the windows on the crosswalk.  Since I recently upgraded to Aperture 3.0, I decided to play around with the new brushed filters.  A few brush strokes and a number of tweaks to the B+W filter and the color, and voila.  Perhaps not the most stunning color isolation, but I think it worked well.</p>
]]></content:encoded>
			<wfw:commentRss>http://programerror.com/2010/03/fun-with-filters-and-brushes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Elena thinks exercise is hilarious</title>
		<link>http://programerror.com/2010/01/elena-thinks-exercise-is-hilarious/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=elena-thinks-exercise-is-hilarious</link>
		<comments>http://programerror.com/2010/01/elena-thinks-exercise-is-hilarious/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 07:13:02 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Elena]]></category>
		<category><![CDATA[Family]]></category>

		<guid isPermaLink="false">http://programerror.com/?p=143</guid>
		<description><![CDATA[




]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
	QT_WritePoster_XHTML('Click to Play', '/wp-content/uploads/2010/01/IPK71044-poster.jpg',
		'/wp-content/uploads/2010/01/IPK71044.mov',
		'500', '296', '',
		'controller', 'true',
		'autoplay', 'true',
		'bgcolor', 'black',
		'scale', 'aspect');
//-->
</script><br />
<noscript><br />
<object width="853" height="496" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="/wp-content/uploads/2010/01/IPK71044-poster.jpg" /><param name="href" value="/wp-content/uploads/2010/01/IPK71044.mov" /><param name="target" value="myself" /><param name="controller" value="false" /><param name="autoplay" value="false" /><param name="scale" value="aspect" /><embed width="500" height="296" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"<br />
		src="/wp-content/uploads/2010/01/IPK71044-poster.jpg"<br />
		href="/wp-content/uploads/2010/01/IPK71044.mov"<br />
		target="myself"<br />
		controller="false"<br />
		autoplay="false"<br />
		scale="aspect"></embed></object><br />
</noscript></p>
]]></content:encoded>
			<wfw:commentRss>http://programerror.com/2010/01/elena-thinks-exercise-is-hilarious/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hmm… is this really food?</title>
		<link>http://programerror.com/2009/12/hmm-is-this-really-food/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=hmm-is-this-really-food</link>
		<comments>http://programerror.com/2009/12/hmm-is-this-really-food/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 03:16:55 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://programerror.com/?p=139</guid>
		<description><![CDATA[<a href="http://programerror.com/2009/12/hmm-is-this-really-food/" title="Hmm&#8230; is this really food?"><img src="http://programerror.com/wp-content/uploads/yapb_cache/ipk70955.1enggcd9kff2wgsskwg4ocwk8.a9sxxja1njre4og884ksckowg.th.jpeg" width="180" height="119" alt="Hmm&#8230; is this really food?" style="float:left;padding:0 10px 10px 0;" /></a>Check out the rest of the shots, along with many others that needed to be uploaded at my MobileMe gallery.
]]></description>
			<content:encoded><![CDATA[<a href="http://programerror.com/2009/12/hmm-is-this-really-food/" title="Hmm&#8230; is this really food?"><img src="http://programerror.com/wp-content/uploads/yapb_cache/ipk70955.1enggcd9kff2wgsskwg4ocwk8.a9sxxja1njre4og884ksckowg.th.jpeg" width="180" height="119" alt="Hmm&#8230; is this really food?" style="float:left;padding:0 10px 10px 0;" /></a><p>Check out the rest of the shots, along with many others that needed to be uploaded at my <a href="http://gallery.me.com/brysonda#100173">MobileMe gallery</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://programerror.com/2009/12/hmm-is-this-really-food/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sportin’ a new outfit</title>
		<link>http://programerror.com/2009/12/sportin-a-new-outfit/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sportin-a-new-outfit</link>
		<comments>http://programerror.com/2009/12/sportin-a-new-outfit/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 06:57:46 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Elena]]></category>
		<category><![CDATA[Family]]></category>

		<guid isPermaLink="false">http://programerror.com/?p=135</guid>
		<description><![CDATA[<a href="http://programerror.com/2009/12/sportin-a-new-outfit/" title="Sportin&#8217; a new outfit"><img src="http://programerror.com/wp-content/uploads/yapb_cache/ipk70922.8huulwdw089log4ocs4owsswg.a9sxxja1njre4og884ksckowg.th.jpeg" width="180" height="218" alt="Sportin&#8217; a new outfit" style="float:left;padding:0 10px 10px 0;" /></a>]]></description>
			<content:encoded><![CDATA[<a href="http://programerror.com/2009/12/sportin-a-new-outfit/" title="Sportin&#8217; a new outfit"><img src="http://programerror.com/wp-content/uploads/yapb_cache/ipk70922.8huulwdw089log4ocs4owsswg.a9sxxja1njre4og884ksckowg.th.jpeg" width="180" height="218" alt="Sportin&#8217; a new outfit" style="float:left;padding:0 10px 10px 0;" /></a>]]></content:encoded>
			<wfw:commentRss>http://programerror.com/2009/12/sportin-a-new-outfit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Happy Holidays 2009!</title>
		<link>http://programerror.com/2009/12/happy-holidays-2009/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=happy-holidays-2009</link>
		<comments>http://programerror.com/2009/12/happy-holidays-2009/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 16:57:08 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Elena]]></category>
		<category><![CDATA[Family]]></category>

		<guid isPermaLink="false">http://programerror.com/?p=132</guid>
		<description><![CDATA[<a href="http://programerror.com/2009/12/happy-holidays-2009/" title="Happy Holidays 2009!"><img src="http://programerror.com/wp-content/uploads/yapb_cache/ipk70915.2x2wrthvgs3q4g0ogcs480sc8.a9sxxja1njre4og884ksckowg.th.jpeg" width="180" height="225" alt="Happy Holidays 2009!" style="float:left;padding:0 10px 10px 0;" /></a>]]></description>
			<content:encoded><![CDATA[<a href="http://programerror.com/2009/12/happy-holidays-2009/" title="Happy Holidays 2009!"><img src="http://programerror.com/wp-content/uploads/yapb_cache/ipk70915.2x2wrthvgs3q4g0ogcs480sc8.a9sxxja1njre4og884ksckowg.th.jpeg" width="180" height="225" alt="Happy Holidays 2009!" style="float:left;padding:0 10px 10px 0;" /></a>]]></content:encoded>
			<wfw:commentRss>http://programerror.com/2009/12/happy-holidays-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Elena learning piano at Thanksgiving</title>
		<link>http://programerror.com/2009/11/elena-learning-piano-at-thanksgiving/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=elena-learning-piano-at-thanksgiving</link>
		<comments>http://programerror.com/2009/11/elena-learning-piano-at-thanksgiving/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 00:23:20 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Elena]]></category>
		<category><![CDATA[Family]]></category>

		<guid isPermaLink="false">http://programerror.com/?p=130</guid>
		<description><![CDATA[<a href="http://programerror.com/2009/11/elena-learning-piano-at-thanksgiving/" title="Elena learning piano at Thanksgiving"><img src="http://programerror.com/wp-content/uploads/yapb_cache/ipk70889.2qkr7ka5m9jgzoooo00c0c4gg.a9sxxja1njre4og884ksckowg.th.jpeg" width="180" height="271" alt="Elena learning piano at Thanksgiving" style="float:left;padding:0 10px 10px 0;" /></a>]]></description>
			<content:encoded><![CDATA[<a href="http://programerror.com/2009/11/elena-learning-piano-at-thanksgiving/" title="Elena learning piano at Thanksgiving"><img src="http://programerror.com/wp-content/uploads/yapb_cache/ipk70889.2qkr7ka5m9jgzoooo00c0c4gg.a9sxxja1njre4og884ksckowg.th.jpeg" width="180" height="271" alt="Elena learning piano at Thanksgiving" style="float:left;padding:0 10px 10px 0;" /></a>]]></content:encoded>
			<wfw:commentRss>http://programerror.com/2009/11/elena-learning-piano-at-thanksgiving/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A beautiful butterfly!</title>
		<link>http://programerror.com/2009/10/a-beautiful-butterfly/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=a-beautiful-butterfly</link>
		<comments>http://programerror.com/2009/10/a-beautiful-butterfly/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 12:44:56 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Elena]]></category>

		<guid isPermaLink="false">http://programerror.com/?p=128</guid>
		<description><![CDATA[<a href="http://programerror.com/2009/10/a-beautiful-butterfly/" title="A beautiful butterfly!"><img src="http://programerror.com/wp-content/uploads/yapb_cache/ipk70839.ds6yigcgselsowock08o4448c.a9sxxja1njre4og884ksckowg.th.jpeg" width="180" height="119" alt="A beautiful butterfly!" style="float:left;padding:0 10px 10px 0;" /></a>]]></description>
			<content:encoded><![CDATA[<a href="http://programerror.com/2009/10/a-beautiful-butterfly/" title="A beautiful butterfly!"><img src="http://programerror.com/wp-content/uploads/yapb_cache/ipk70839.ds6yigcgselsowock08o4448c.a9sxxja1njre4og884ksckowg.th.jpeg" width="180" height="119" alt="A beautiful butterfly!" style="float:left;padding:0 10px 10px 0;" /></a>]]></content:encoded>
			<wfw:commentRss>http://programerror.com/2009/10/a-beautiful-butterfly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Iterative calculation of lies, er stats</title>
		<link>http://programerror.com/2009/10/iterative-calculation-of-lies-er-stats/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=iterative-calculation-of-lies-er-stats</link>
		<comments>http://programerror.com/2009/10/iterative-calculation-of-lies-er-stats/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 15:49:12 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://programerror.com/?p=122</guid>
		<description><![CDATA[A few weeks ago I wrote about my adventures in cross platform floating point consistency in Avida.  The main routine responsible for the deviation at the time was a statistics output function that calculated the skewness and kurtosis for various properties.  My first thought at the time was that perhaps the compilers were [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I wrote about my adventures in cross platform floating point consistency in Avida.  The main routine responsible for the deviation at the time was a statistics output function that calculated the skewness and kurtosis for various properties.  My first thought at the time was that perhaps the compilers were reordering operations differently, leading to rounding variations.   Ultimately I worked around the problem (see <a href="http://programerror.com/2009/09/when-gccs-ffast-math-isnt/">how</a>), but in the process I took a good long look skewness and kurtosis methods.</p>
<p>The class in question, <code>cDoubleSum</code>, is intended to be a lightweight iterative/running statistics utility.  Values can be added to the collection as they are observed and the statistical properties, such as variance, skewness, and kurtosis, are updated accordingly.  The implementation does this by keeping a running tally of the sum, sum of squared values, sum of cubed values, and the sum of x^4.  The values are then used to calculate the desired values.</p>
<pre class="subtopic">
void Add(double value, double weight = 1.0)
{
  double w_val = value * weight;
  n += weight;
  s1 += w_val;
  s2 += w_val * w_val;
  s3 += w_val * w_val * w_val;
  s4 += w_val * w_val * w_val * w_val;
}
</pre>
<p>The skewness and kurtosis methods are implemented as the following:</p>
<pre class="subtopic">
double cDoubleSum::Skewness() const
{
  return (n > 2.0) ?
    (n * s3 - (3.0 * s2) * s1 + ((2.0 * s1) * s1) * s1 / n) /
      ((n - 1.0) * (n - 2.0))
    : INF_ERR;
}
double cDoubleSum::Kurtosis() const {
  return (n > 3.0) ?
    (n + 1.0) * (n * s4 - (4.0 * s3) * s1 + (((6.0 * s2) * s1) * s1) /
      n - (((((3.0 * s1) * s1) * s1) / n) * s1) / n) /
      ((n - 1.0) * (n - 2.0) * (n - 3.0))
    : INF_ERR;
}
</pre>
<p>Since the code has existed for quite a few years, its exact lineage is unknown.  I have done extensive searching to try to understand how these equations work and to find where they came from.  In asking around it was suggested that the source might have been &#8220;Numerical Recipes in C&#8221;.  However, the book only describes the basic two pass method that requires all values exist in memory during calculation.  Even worse, the equations used by <code>cDoubleSum</code> do not seem to calculate correct values.</p>
<p>After starring at the code and many versions of the equations, I decided it would be better to go ahead and implement my own version of the class.   The result was <code>cRunningStats</code>. </p>
<pre class="subtopic">
class cRunningStats
{
private:
  double m_n;  // count
  double m_m1; // mean
  double m_m2; // second moment
  double m_m3; // third moment
  double m_m4; // fourth moment

public:
  cRunningStats() : m_n(0.0), m_m1(0.0), m_m2(0.0), m_m3(0.0), m_m4(0.0)
    { ; }

  void Push(double x)
  {
    m_n++;
    double d = (x - m_m1);
    double d_n = d / m_n;
    double d_n2 = d_n * d_n;

    m_m4 += d * d_n2 * d_n * ((m_n - 1) * ((m_n * m_n) - 3 * m_n + 3)) +
            6 * d_n2 * m_m2 - 4 * d_n * m_m3;
    m_m3 += d * d_n2 * ((m_n - 1) * (m_n - 2)) - 3 * d_n * m_m2;
    m_m2 += d * d_n * (m_n - 1);
    m_m1 += d_n;
  }
  double Mean() { return m_m1; }
  double StdDeviation() { return sqrt(Variance()); }
  double StdError() { return (m_n > 1.0) ? sqrt(Variance() / m_n) : 0.0; }
  double Variance() { return (m_n > 1.0) ? (m_m2 / (m_n - 1.0)) : 0.0; }
  double Skewness() { return sqrt(m_n) * m_m3 / pow(m_m2, 1.5); }
  double Kurtosis() { return m_n * m_m4 / (m_m2 * m_m2); }
};
</pre>
<p>I have examined various primary sources, however the wikipedia page &quot;<a href="http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance">Algorithms for calculating variance</a>&quot; is a good starting place if you are interested in where the math comes from.   The methods used should be numerically stable (i.e. not prone to severe loss of precision), reasonably high performance (only a single divide operation during update), and, best of all, return correct values.   There are a number of good pages on the web that describe pieces of this problem, including some that provide details for how such equations can be used to parallelize variance calculation.   Still, I thought it would be useful to have a nice concise presentation in C++ code.  Note that there are a few more methods, <code>inline</code>, and <code>const</code> qualifiers in the actual Avida implementation, but the math is the same.</p>
<p>A quick performance comparison has <code>cRunningStats</code> taking about 20% more time on a set of 100M random numbers versus <code>cDoubleSum</code> (same random number seed).  The value correctness tradeoff is, of course, well worth the cost.   However, if anyway knows how to make the cDoubleSum methods work correctly, I&#8217;d love to know the answer.  As things stand now, I have simply removed the bad code.</p>
<div class="warn">
<em>License Note:</em> Feel free to use cRunningStats code as public domain.  An in source code attribution comment with a referral URL would be nice, but is not required.  The full class is available in Avida, licensed under the GPL.
</div>
]]></content:encoded>
			<wfw:commentRss>http://programerror.com/2009/10/iterative-calculation-of-lies-er-stats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A little fall color 3</title>
		<link>http://programerror.com/2009/10/a-little-fall-color-3/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=a-little-fall-color-3</link>
		<comments>http://programerror.com/2009/10/a-little-fall-color-3/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 21:06:28 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Photography]]></category>
		<category><![CDATA[fall (season)]]></category>

		<guid isPermaLink="false">http://programerror.com/?p=118</guid>
		<description><![CDATA[<a href="http://programerror.com/2009/10/a-little-fall-color-3/" title="A little fall color 3"><img src="http://programerror.com/wp-content/uploads/yapb_cache/ipk707511.8c3cfn08rsmkcgs4gsokg4woc.a9sxxja1njre4og884ksckowg.th.jpeg" width="180" height="271" alt="A little fall color 3" style="float:left;padding:0 10px 10px 0;" /></a>]]></description>
			<content:encoded><![CDATA[<a href="http://programerror.com/2009/10/a-little-fall-color-3/" title="A little fall color 3"><img src="http://programerror.com/wp-content/uploads/yapb_cache/ipk707511.8c3cfn08rsmkcgs4gsokg4woc.a9sxxja1njre4og884ksckowg.th.jpeg" width="180" height="271" alt="A little fall color 3" style="float:left;padding:0 10px 10px 0;" /></a>]]></content:encoded>
			<wfw:commentRss>http://programerror.com/2009/10/a-little-fall-color-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A little fall color 2</title>
		<link>http://programerror.com/2009/10/a-little-fall-color-2/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=a-little-fall-color-2</link>
		<comments>http://programerror.com/2009/10/a-little-fall-color-2/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 14:20:53 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Photography]]></category>
		<category><![CDATA[fall (season)]]></category>

		<guid isPermaLink="false">http://programerror.com/?p=113</guid>
		<description><![CDATA[<a href="http://programerror.com/2009/10/a-little-fall-color-2/" title="A little fall color 2"><img src="http://programerror.com/wp-content/uploads/yapb_cache/ipk70749.abfklh0j3qboso0swc00ow4gk.a9sxxja1njre4og884ksckowg.th.jpeg" width="180" height="119" alt="A little fall color 2" style="float:left;padding:0 10px 10px 0;" /></a>]]></description>
			<content:encoded><![CDATA[<a href="http://programerror.com/2009/10/a-little-fall-color-2/" title="A little fall color 2"><img src="http://programerror.com/wp-content/uploads/yapb_cache/ipk70749.abfklh0j3qboso0swc00ow4gk.a9sxxja1njre4og884ksckowg.th.jpeg" width="180" height="119" alt="A little fall color 2" style="float:left;padding:0 10px 10px 0;" /></a>]]></content:encoded>
			<wfw:commentRss>http://programerror.com/2009/10/a-little-fall-color-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
