<?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>CenterSpace Blog</title>
	<atom:link href="http://www.centerspace.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.centerspace.net/blog</link>
	<description>The CenterSpace blog about our NMath mathematical and statistical libraries in .NET/C#, and object-oriented numerics in general.</description>
	<lastBuildDate>Wed, 21 Jul 2010 19:53:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Searching for Roots in Univariate Functions</title>
		<link>http://www.centerspace.net/blog/nmath/nmath-tutorial/searching-for-roots-in-univariate-functions/</link>
		<comments>http://www.centerspace.net/blog/nmath/nmath-tutorial/searching-for-roots-in-univariate-functions/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 17:56:39 +0000</pubDate>
		<dc:creator>Paul Shirkey</dc:creator>
				<category><![CDATA[NMath Tutorial]]></category>
		<category><![CDATA[finding roots]]></category>
		<category><![CDATA[finding roots .NET]]></category>
		<category><![CDATA[finding roots c#]]></category>
		<category><![CDATA[Newton's method c#]]></category>
		<category><![CDATA[Newton-Raphson c#]]></category>
		<category><![CDATA[NMath root finding]]></category>
		<category><![CDATA[Ridder's method c#]]></category>
		<category><![CDATA[Secant method c#]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=2412</guid>
		<description><![CDATA[<img src="http://www.centerspace.net/blog/wp-content/uploads/2010/07/sinxx-xxx-2.png" alt="Example root finding function." title="sin(x)/x - x*x*x - 2" width="500" height="400" class="excerpt" /> Finding the roots of a <em>univariate</em> function is a basic numerical procedure that nearly all engineers and scientists encounters at some point.  I will demonstrate three well known univariate root finding algorithms: Newton-Raphson, Ridders, and Secant.  All three methods require a delegate to the function and a bracketed range where a root is expected to reside, additionally, Newton-Raphson requires a continuous, non-zero derivative of <code>f(x)</code> in the region of the root. ]]></description>
			<content:encoded><![CDATA[<p>Finding the roots of a <em>univariate</em> function is a basic numerical procedure that nearly all engineers and scientists encounters at some point, because the root finding question addresses the basic equation,<br />
<center><img src="http://latex.codecogs.com/gif.latex?f(x) = 0" title="f(x) = 0" /></center><br />
where, <code>x</code> can be a real or complex variable.  Or more generally, we can solve,</p>
<p><center><img src="http://latex.codecogs.com/gif.latex?f(x) = g(x)" title="f(x) = g(x)" /></center> </p>
<p>by finding the roots to,</p>
<p><center> <img src="http://latex.codecogs.com/gif.latex?f(x) - g(x) = 0" title="f(x) - g(x) = 0" /></center></p>
<h3> Algorithms </h3>
<p>I will demonstrate three well known univariate root finding algorithms, Newton-Raphson, Ridders, and Secant.  All three methods require a delegate to the function and a bracketed range where a root is expected to reside, additionally, Newton-Raphson requires a continuous, non-zero derivative of <code>f(x)</code>in the region of the root.  None of these methods are recommended for finding roots of polynomials in general, although Newton-Raphson will work well if the polynomial isn&#8217;t ill-conditioned by containing an even number of duplicated roots  (Bracketing such roots isn&#8217;t possible because the function doesn&#8217;t change sign in the region of these roots.), or by containing root pairs extremely close together.  </p>
<table>
<th> Name </th>
<th> Convergence Rate </th>
<th> Root remains bracketed? </th>
<th> Comments </th>
<tr>
<td> Newton-Raphson
<td> Quadratic
<td> Yes
<td>Often used for root polishing. </p>
<tr>
<td> Secant
<td> Golden Ration &#8211; 1.618
<td> No
<td> Fast in locally linear regions.</p>
<tr>
<td> Ridders
<td> Quadratic
<td> Yes
<td> Frequently competitive with the more complex Brent&#8217;s method<br />
</table>
<h4> C# Example with NMath </h4>
<p>All of these roots finders have a similar interface and properties in NMath, so exchanging one with the other is easy.  As seen in the example below, both the Ridders and Secant root finders implement the <code>IOneVariableRootFinder</code> interface, and the Newton-Raphson root finder implements the slightly different <code>IOneVariableDRootFinder,</code> where the &#8216;D&#8217; stands for derivative.   </p>
<p>Using Wolfram|Alpha&#8217;s online services, I&#8217;ve computed and graphed the roots of the following non-linear univariate function.<br />
<a href="http://www.centerspace.net/blog/wp-content/uploads/2010/07/9logxsinx-xxx.png"><img src="http://www.centerspace.net/blog/wp-content/uploads/2010/07/9logxsinx-xxx.png" alt="Root finding test function" title="9*log(x)*sin(x) - x*x*x" width="500" height="400" class="size-full wp-image-2449" /></a></p>
<p>The code block below demonstrates the use of each of these root finders, and shows the how to define a function delegate using a lamda expression.  I find lamda expressions are convenient  for defining delegates to mathematical expressions and that they create very readable code.  (As an aside, lamda expressions are a C# language feature, and are not part of the .NET framework.  Therefore, applications targeting the .NET 2.0 framework can leverage lamda expressions as long as the compiler supports them, as VS9 and VS10 both do.).</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">CenterSpace.NMath.Analysis</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">void</span> RootFindingExample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
&nbsp;
     <span style="color: #008080; font-style: italic;">// Create the function delegate with a lamda expression, </span>
     <span style="color: #008080; font-style: italic;">// and the interval which contains a root.</span>
      OneVariableFunction f <span style="color: #008000;">=</span> 
        <span style="color: #008000;">new</span> OneVariableFunction<span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> <span style="color: #FF0000;">9</span> <span style="color: #008000;">*</span> Math.<span style="color: #0000FF;">Log</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> Math.<span style="color: #0000FF;">Sin</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span> <span style="color: #008000;">-</span> x <span style="color: #008000;">*</span> x <span style="color: #008000;">*</span> x<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      Interval bracket <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Interval<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">1.5</span>, Interval.<span style="color: #0000FF;">Type</span>.<span style="color: #0000FF;">Closed</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      IOneVariableDRootFinder nrRoots <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NewtonRaphsonRootFinder<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #FF0000;">Double</span> rootnewton <span style="color: #008000;">=</span> nrRoots.<span style="color: #0000FF;">Find</span><span style="color: #000000;">&#40;</span>f, f.<span style="color: #0000FF;">Derivative</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, bracket<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Newton-Raphson root is = {0}&quot;</span>, rootnewton<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      IOneVariableRootFinder rootFinder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> RiddersRootFinder<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #FF0000;">Double</span> rootridder <span style="color: #008000;">=</span> rootFinder.<span style="color: #0000FF;">Find</span><span style="color: #000000;">&#40;</span>f, bracket<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Ridder's root is = {0}&quot;</span>, rootridder<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      rootFinder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SecantRootFinder<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #FF0000;">Double</span> rootsecant <span style="color: #008000;">=</span> rootFinder.<span style="color: #0000FF;">Find</span><span style="color: #000000;">&#40;</span>f, bracket<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Secant root is = {0}&quot;</span>, rootsecant<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span></pre></div></div>

<p>With each root finder limited to just 3 iterations, this program creates the output,</p>
<pre class="code">
Newton-Raphson root is = 1.26760302048967
Ridder's root is = 1.26760302063032
Secant root is = 1.3334994219432
</pre>
<p>Where Newton-Raphson found the first root most accurately with it&#8217;s knowledge of derivative information.  Besides specifying the maximum number of iterations, a root tolerance can also be used to control convergence effort.</p>
<p>A second somewhat more difficult example which can cause problems for both the Secant and Newton-Raphson methods.<br />
<a href="http://www.centerspace.net/blog/wp-content/uploads/2010/07/sinxx-xxx-2.png"><img src="http://www.centerspace.net/blog/wp-content/uploads/2010/07/sinxx-xxx-2.png" alt="Example root finding function." title="sin(x)/x - x*x*x - 2" width="500" height="400" class="size-full wp-image-2456" /></a></p>
<p>I gave the Secant method 1000 iterations, and still it&#8217;s root estimate was very poor &#8211; in fact with an initial bracket of [-5, -0.01], the Secant method will never converge on the root.  There is a stable orbit around which the Secant method spins forever, preventing convergence.  Because the Newton-Raphson requires a continuous derivative any starting bracket that contains the origin will cause an exception to be thrown because of the discontinuous derivative at zero.  </p>
<pre class="code">
Newton-Raphson root is = -1.05539938820662 (with 8 iterations)
Ridder's root is = -1.05539938548287 (with 8 iterations)
Secant root is = -0.0912954387917323 (with 1000 iterations)
</pre>
<p>As a general recommendation, I would start my root search using Ridder&#8217;s method and then finish up by polishing with Newton-Raphson.</p>
<p>-Happy Computing,<br />
<em> Paul </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/nmath/nmath-tutorial/searching-for-roots-in-univariate-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>We&#8217;ve Moved to a New Larger Location</title>
		<link>http://www.centerspace.net/blog/centerspace/weve-moved-2/</link>
		<comments>http://www.centerspace.net/blog/centerspace/weve-moved-2/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 23:20:37 +0000</pubDate>
		<dc:creator>Amy</dc:creator>
				<category><![CDATA[CenterSpace]]></category>
		<category><![CDATA[centerspace news]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=2302</guid>
		<description><![CDATA[<img src="http://www.centerspace.net/blog/wp-content/uploads/2010/06/creesbldgsignage-300x180.jpg" alt="Crees Building Signage" title="Crees Building Signage"class="excerpt" />
CenterSpace Software is excited to announce that we have moved to our new Corvallis offices.  " We were busting at the seams so it was time for a move." said CenterSpace CEO Trevor Misfeldt  "Our team is growing so we can expand the functionality of the NMath software and provide more consulting services to our customers."]]></description>
			<content:encoded><![CDATA[<p>CenterSpace Software is excited to announce that we have moved to our new Corvallis offices.</p>
<p>&#8221; We were busting at the seams so it was time for a move.&#8221; said CenterSpace CEO Trevor Misfeldt  &#8220;Our team is growing so we can expand the functionality of the NMath software and provide more consulting services to our customers.&#8221;</p>
<p>Our new location is located on the third floor of the historic Crees Building in downtown Corvallis Oregon. </p>
<blockquote><table>
<tr>
<td>CenterSpace Software </td>
</tr>
<tr>
<td>230 SW 3rd Street</td>
</tr>
<tr>
<td>Corvallis OR, 97330</td>
</tr>
<tr>
<td> +1.541.896.1301</td>
</tr>
</table>
</blockquote>
<div id="attachment_2316" class="wp-caption alignright" style="width: 360px"><a href="http://www.centerspace.net/blog/wp-content/uploads/2010/06/creesbldgfrontaddress.jpg"><img src="http://www.centerspace.net/blog/wp-content/uploads/2010/06/creesbldgfrontaddress.jpg" alt="Crees Building front address" title="Crees Building front address" width="350" class="size-full wp-image-2316" /></a><p class="wp-caption-text">Art Deco Crees Building Front Address</p></div>
<p>At the time of its construction in 1926, the Crees Building was the largest commercial building to ever be built in downtown Corvallis and it has played a major role in the commerce of the area.   Visitors can take a ride to our offices on the third floor in the oldest working (we hope!) elevator in Corvallis.<br />
<div id="attachment_2334" class="wp-caption alignright" style="width: 210px"><a href="http://www.centerspace.net/blog/wp-content/uploads/2010/06/creesbldgsignage.jpg"><img src="http://www.centerspace.net/blog/wp-content/uploads/2010/06/creesbldgsignage-300x180.jpg" alt="Crees Building Signage" title="Crees Building Signage" width="200"  class="size-medium wp-image-2334" /></a><p class="wp-caption-text">Crees Building Signage</p></div></p>
<p>&#8220;With almost twice the square footage of our former location, we will not only be able to handle the growth of our staff but also provide a unique environment for our new series of quarterly training classes starting in August 2010.&#8221; says Misfeldt</p>
<p><strong>About CenterSpace Software</strong><br />
CenterSpace Software is a leading provider of enterprise class numerical component libraries for the .NET platform. Developers worldwide use CenterSpace products to develop .NET financial, engineering, and scientific applications. CenterSpace Software has offices in Corvallis, OR, and can be found on the Internet at <a href="http://www.centerspace.net/">http://www.centerspace.net</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/centerspace/weve-moved-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>July Release of NMath and NMath Stats</title>
		<link>http://www.centerspace.net/blog/nmath/july-release-of-nmath-and-nmath-stats/</link>
		<comments>http://www.centerspace.net/blog/nmath/july-release-of-nmath-and-nmath-stats/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 23:24:36 +0000</pubDate>
		<dc:creator>Paul Shirkey</dc:creator>
				<category><![CDATA[CenterSpace]]></category>
		<category><![CDATA[NMath]]></category>
		<category><![CDATA[NMath Stats]]></category>
		<category><![CDATA[.NET math library]]></category>
		<category><![CDATA[C# math library]]></category>
		<category><![CDATA[NMath release]]></category>
		<category><![CDATA[NMath Stats release]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=2219</guid>
		<description><![CDATA[<img src="http://www.centerspace.net/blog/wp-content/uploads/2010/06/centerspace-software-logo.png" alt="CenterSpace" title="CenterSpace Software" class="excerpt" />We are currently working hard on our upcoming July release of NMath and NMath Stats.  This release will add many new features from <em>Runge-Kutta</em> to automatic <em>Peak Finding</em> algorithms as well as address our most frequent support requests.  Developers using our math libraries currently will find the new release build-compatible with the prior release.  Upgrades are provided free of charge to customers with current annual maintenance contracts. ]]></description>
			<content:encoded><![CDATA[<p>We are currently working hard on our upcoming July release of our NMath and NMath Stats C# math libraries.  This release will add many new features from <em>Runge-Kutta</em> to automatic <em>Peak Finding</em> algorithms as well as address our most frequent support requests.  Developers using our math libraries currently will find the new release build-compatible with the prior release.  Upgrades are provided free of charge to customers with current annual maintenance contracts.   Maintenance contracts are available through our <a href="http://www.centerspace.net/order/how-to-order/?" target="_blank">webstore</a>.</p>
<h3>Pure C#</h3>
<p>Both libraries are now supported by a new pure C# math kernel doing away with our old C++ kernel.  Because we are now a pure .NET assembly, deployment of NMath based applications is simplified by eliminating the Microsoft C++ runtime library dependency.  As with all releases we will be posting our updated performance benchmarks at the time of the release.</p>
<h3>Full Control</h3>
<p>Additionally, our libraries have been re-architected to dynamically link to both native numerical libraries and ( and perhaps more importantly for our customers ) the Intel OMP threading library (<em>libiomp.dll</em>) .  This means that our customers will have complete control over the threading library. In the past, we statically linked in OMP. Now, we are picking up OMP dynamically and thereby avoid collisions between statically and dynamically linked OMP libraries.  In a nutshell, NMath will now play more nicely with libraries from other vendors.</p>
<h3>New Features</h3>
<p>Now for the fun stuff.  The table below summarized the new features in <em>NMath 4.1</em> and <em>NMath Stats 3.2</em>.</p>
<table>
<tbody>
<tr>
<th> Product</th>
<th> Feature</th>
<th align="center"> Summary</th>
</tr>
<tr>
<td>NMath 4.1</td>
<td style="font-weight: bold;">Savitzky-Golay derivatives</td>
<td>Class generates correlation coefficients to compute the smoothed Savizky-Golay derivatives of sampled data.</td>
</tr>
<tr>
<td></td>
<td style="font-weight: bold;">Savitzky-Golay smoothing</td>
<td><a href="http://www.centerspace.net/blog/statistics/savtizky-golay-smoothing/"> See blog article on SG smoothing </a></td>
</tr>
<tr>
<td></td>
<td style="font-weight: bold;">Peak Finding</td>
<td>Class finds peaks in sampled data using Savitzky-Golay smoothed polynomials and their derivatives.</td>
</tr>
<tr>
<td></td>
<td style="font-weight: bold;">Runge-Kutta ODE solver</td>
<td>Class for solving ODE&#8217;s</td>
</tr>
<tr>
<td></td>
<td style="font-weight: bold;">Bounded function fitting</td>
<td>Class for fitting general nonlinear models with bounds on the parameters. Also see this <a href="http://www.centerspace.net/blog/nmath/non-linear-curve-fitting/">blog article</a> for code examples of bounded nonlinear curving fitting.</td>
</tr>
<tr>
<td></td>
<td style="font-weight: bold;">Correlated random number generators</td>
<td>Class creates streams of induced correlated random numbers typically for simulation studies using Monte Carlo.</td>
</tr>
<tr>
<td>NMath Stats 3.2</td>
<td style="font-weight: bold;">Johnson System of distributions</td>
<td>The Johnson system of distributions is based on three possible transformations of a normal distribution&#8211;exponential, logistic, and hyperbolic sine&#8211;plus the identity transformation:</p>
<p>X = xi + (lambda * T((z &#8211; gamma) / delta))</p>
<p>where z is a standard normal random variable, xi and lambda are shape parameters, delta is a scale parameter, gamma is a location parameter, and T is the transformation.</td>
</tr>
<tr>
<td></td>
<td style="font-weight: bold;">Kruskal-Wallis rank sum test</td>
<td>The Kruskal-Wallis rank sum test is a non-parametric test for equality of population medians among groups. It is a non-parametric version of the classical one-way ANOVA.</td>
</tr>
<tr>
<td></td>
<td style="font-weight: bold;">Regression statistics for PolynomialLeastSquares</td>
<td>[see below]</td>
</tr>
<tr>
<td></td>
<td style="font-weight: bold;">Regression statistics for OneVariableFunctionFitter</td>
<td>Class provides a variety of regression statistics including the residual sum of squares, R squared, adjusted R squared, F statistic, and others.</td>
</tr>
</tbody>
</table>
<p>I hope you find these new additions to the library useful in your application work.  If you are looking for something specific that isn&#8217;t currently supported in our library, please <a href="mailto: support@centerspace.net">contact us</a>.  We build custom numeric classes for existing and new customers on a regular basis.</p>
<p>Happy Computing,<br />
<em> Paul </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/nmath/july-release-of-nmath-and-nmath-stats/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New Cloud Bioinformatics Partnership with Floragenex</title>
		<link>http://www.centerspace.net/blog/uncategorized/floragenex-centerspace-partnership/</link>
		<comments>http://www.centerspace.net/blog/uncategorized/floragenex-centerspace-partnership/#comments</comments>
		<pubDate>Wed, 12 May 2010 04:20:44 +0000</pubDate>
		<dc:creator>Paul Shirkey</dc:creator>
				<category><![CDATA[CenterSpace]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bioinformatics in the cloud]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[floragenex partnership]]></category>
		<category><![CDATA[genomics in the cloud]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=2156</guid>
		<description><![CDATA[FOR IMMEDIATE RELEASE
Partnership with Innovative Genomic Services Company
Corvallis, Oregon (May 13, 2009) &#8211; CenterSpace Software, a leading provider of enterprise class numerical component libraries for the .NET platform, and Floragenex, an innovative genomic research services company, today announced that they have teamed up to build a flexible genomics data analysis pipeline in the cloud.
Rapid growth...]]></description>
			<content:encoded><![CDATA[<p>FOR IMMEDIATE RELEASE</p>
<h3 style="padding-bottom:20px">Partnership with Innovative Genomic Services Company</h3>
<p>Corvallis, Oregon (May 13, 2009) &#8211; CenterSpace Software, a leading provider of enterprise class numerical component libraries for the .NET platform, and Floragenex, an innovative genomic research services company, today announced that they have teamed up to build a flexible <em>genomics data analysis pipeline in the cloud</em>.</p>
<p>Rapid growth of the research services business at Floragenex requires expansion of computing resources beyond the company’s current infrastructure. CenterSpace has deep knowledge of high-powered analytical software and experience developing applications utilizing the cloud computing power of Amazon Web Services. Together, the two companies are working to build a cloud-computing infrastructure to improve ease of use, lower costs, and accelerate data throughput for Floragenex.</p>
<p>&#8220;The new system retrieves genetic sequence data from the sequencing facility of choice, places it into storage in the cloud and runs analysis based on the particular needs of the project. The Floragenex end user can login to a web page to select their data, choose their parameters and run their analysis. The work is done on Amazon Elastic Compute Cloud (EC2) computers and results are archived on Amazon S3 for easy retrieval. The costs are small and the benefits large,&#8221; says Trevor Misfeldt, CEO of CenterSpace Software.</p>
<p>“The massive volume of data that genome sequencers produce has required us to look for creative ways to scale our business. Working with CenterSpace allows us to lay the foundation for continued growth without making capital investments in IT hardware,” says Nathan Lillegard, CEO of Floragenex. “The bioinformatics work we do for our customers is particularly well suited to cloud computing, with large sets of data requiring intensive but discreet data processing. Building a cloud infrastructure now will allow us to grow our business and expand our service offerings more responsively.”</p>
<h3 style="padding-bottom:30px"> About the Companies </h3>
<p><img src="../themes/centerspace/images/centerspace-software-logo.png" alt="" width="195" />CenterSpace Software is a leading provider of enterprise class numerical component libraries for the .NET platform. Developers worldwide use CenterSpace products to develop .NET financial, engineering, and scientific applications.  CenterSpace Software has offices in Corvallis, OR, and can be found on the Internet at <a href="http://www.centerspace.net">www.centerspace.net</a>.<br />
<br />
<a href="http://www.floragenex.com"><img src="http://www.centerspace.net/blog/wp-content/uploads/2010/05/floragenex-logo.png" alt="" title="floragenex-logo" width="210" class="alignleft size-full wp-image-2182" /></a><br />
Floragenex is a research services company focused on genomic technology applications in plant sciences.  Floragenex enables scientists to do more, expanding their capability using a suite of advanced genomic services matched to the specific resources and goals of each project. Floragenex is based in Eugene, OR, and can be found on the internet at <a href="http://www.floragenex.com">www.floragenex.com</a>.</p>
<p>###</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.centerspace.net%2Fblog%2Funcategorized%2Ffloragenex-centerspace-partnership%2F&amp;linkname=New%20Cloud%20Bioinformatics%20Partnership%20with%20Floragenex"><img src="http://www.centerspace.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/uncategorized/floragenex-centerspace-partnership/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Infragistics CenterSpace Partnership</title>
		<link>http://www.centerspace.net/blog/centerspace/infragistics-centerspace-partnership/</link>
		<comments>http://www.centerspace.net/blog/centerspace/infragistics-centerspace-partnership/#comments</comments>
		<pubDate>Tue, 04 May 2010 18:39:45 +0000</pubDate>
		<dc:creator>Paul Shirkey</dc:creator>
				<category><![CDATA[CenterSpace]]></category>
		<category><![CDATA[c# charting math tools]]></category>
		<category><![CDATA[c# charting software]]></category>
		<category><![CDATA[Infragistics]]></category>
		<category><![CDATA[Infragistics partnership]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=1858</guid>
		<description><![CDATA[<img src="http://www.centerspace.net/blog/wp-content/uploads/2010/01/SGPkFndrExplPeriodogram.jpg" alt="" title="Periodogram Example" class="excerpt" />
<a href="http://www.infragistics.com/">Infragistics</a> and CenterSpace Software have created a partnership to provide our customers with sample projects that demonstrate the power of integrating Infragistic's visualization with CenterSpace Software's math and statistical libraries.  Please stop by our <a href="http://www.centerspace.net/partners/infragistics">partnership page</a> and check out the examples if you need high quality visualization tools to complement your computational projects.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.infragistics.com/">Infragistics</a> and CenterSpace Software have created a partnership to provide our customers with sample projects that demonstrate the power of integrating Infragistic&#8217;s visualization with CenterSpace Software&#8217;s math and statistical libraries.  Please stop by our <a href="http://www.centerspace.net/partners/infragistics">partnership page</a> and check out the examples if you need high quality visualization tools to complement your computational projects.</p>
<h3> Free Examples </h3>
<p>Currently there are two free examples, one using the Infragistics .NET WinForm&#8217;s Chart tool and a second using Infragisitcs .NET WPF Chart tool each deriving data from CenterSpace&#8217;s math libraries.  The two example are summarized below.</p>
<ul>
<li>The Window Forms C# example demonstrates Savitzy-Golay data smoothing in a single Infragsitics chart along with two filtering controls. This sample includes a helper class to organize NMath Vectors into a data table with column headers that is consumed by the Infragistics chart.
<li> <div id="attachment_1163" class="wp-caption alignright" style="width: 280px"><a href="http://www.centerspace.net/blog/wp-content/uploads/2010/01/SGPkFndrExplPeriodogram.jpg"><img src="http://www.centerspace.net/blog/wp-content/uploads/2010/01/SGPkFndrExplPeriodogram.jpg" alt="" title="Periodogram Example" width="270" class="size-full wp-image-1163" /></a><p class="wp-caption-text">Periodogram of sun spot data.</p></div>The WPF C# example demonstrates estimating the power spectral density of historic sun spot data using NMath&#8217;s FFT and filtering classes. The raw sun spot data, periodogram, and the power spectral density are shown in a series of three WPF Infragistics charts.
</li>
</ul>
<p>In order to compile and run either of these examples, please follow the links from the <a href="http://www.centerspace.net/partners/infragistics">partnership page</a> and download trial versions of both the CenterSpace &#038; Infragistics .NET toolsets.</p>
<h3> Feedback </h3>
<p>Please let us know if you have found these examples helpful and what else you&#8217;d like to see cooked up.  Customers frequently ask us about visualization tools sets and we hope through this partnership to provide information and code examples to accelerate your development projects.<br />
</p>
<p>Happy Computing,</p>
<p><em> Paul </em></p>
<p><strong>   Resources </strong></p>
<ul>
<li> CenterSpace Software&#8217;s <a href="http://www.centerspace.net/order/partners">partners</a>.
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/centerspace/infragistics-centerspace-partnership/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Non-linear Curve Fitting</title>
		<link>http://www.centerspace.net/blog/nmath/non-linear-curve-fitting/</link>
		<comments>http://www.centerspace.net/blog/nmath/non-linear-curve-fitting/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 21:25:47 +0000</pubDate>
		<dc:creator>Paul Shirkey</dc:creator>
				<category><![CDATA[NMath]]></category>
		<category><![CDATA[NMath Stats]]></category>
		<category><![CDATA[c# logistic model]]></category>
		<category><![CDATA[curving fitting with parameter bounds]]></category>
		<category><![CDATA[dose response C#]]></category>
		<category><![CDATA[dose response model]]></category>
		<category><![CDATA[goodness of fit]]></category>
		<category><![CDATA[non-linear curve fitting]]></category>
		<category><![CDATA[non-linear curve fitting c#]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=1932</guid>
		<description><![CDATA[<img src="http://www.centerspace.net/blog/wp-content/uploads/2010/04/Non-linear-curve-fit-with-logistic-model.png" alt="Non-linear curve fit with logistic model" title="Non-linear curve fit with logistic model"  class="excerpt" />
Modeling a dose-response system with a logistic curve is one important special case of the more general non-linear curve fitting problem.  The logistic model is a fundamental non-linear model for many systems, and is widely used in the life sciences, medicine, and environmental toxicology.  In a previous <a href="http://www.centerspace.net/blog/nmath/nmath-tutorial/excel-trendlines/">blog post</a>, Ken outlined the techniques for using NMath for computing various common linear trend lines and non-linear trend lines linearizable via a simple variable substitution.  This post extends that curve fitting article to the non-linear case using the logistic as the running example.


]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.siga.com/">SIGA</a>, a public biotechnology company, recently hired CenterSpace consultants to refine their logistic modeling capabilities.  Modeling a  dose-response system with a logistic curve  is one important special case of the more general non-linear curve fitting problem.  If you are familiar with linear regression and related statistics, the non-linear case closely parallels the linear case making the jump to non-linear curve fitting easier.  </p>
<table horizonal-align="alignright">
<tr>
<td>
<img src="http://www.centerspace.net/blog/wp-content/uploads/2010/04/SIGA_logo.gif" alt="SIGA Human BioArmor" title="SIGA logo" height="45" class="alignright size-full wp-image-1980" /><br />
SIGA is a world leader in designing and developing novel countermeasures to prevent and treat serious infectious diseases, with an emphasis on biological warfare defense.<br />
</table>
<p>
In a previous <a href="http://www.centerspace.net/blog/nmath/nmath-tutorial/excel-trendlines/">blog post</a>, Ken outlined the techniques for using NMath to compute various common linear trend lines and non-linear trend lines linearizable via a simple variable substitution.  This post extends that curve fitting article to the non-linear case.</p>
<h3>Non-linear Curving Fitting &#8211; The Logistic</h3>
<p>The logistic model is a fundamental non-linear model for many systems, and is widely used in the life sciences, medicine, and environmental toxicology.</p>
<table>
<tr>
<td align="center">
<div id="attachment_1989" class="wp-caption aligncenter" style="width: 460px"><a href="http://www.centerspace.net/blog/wp-content/uploads/2010/04/Non-linear-curve-fit-with-logistic-model.png"><img src="http://www.centerspace.net/blog/wp-content/uploads/2010/04/Non-linear-curve-fit-with-logistic-model.png" alt="Non-linear curve fit with logistic model" title="Non-linear curve fit with logistic model" height="200" class="size-full wp-image-1989" /></a><p class="wp-caption-text">Non-linear curve fit with logistic model</p></div><br />
</table>
<p>This image shows a fit of a 4-parameter logistic model to the measured inhibitory response of an infectious agent to a treatment at various drug dose levels &#8211; this is a classic <strong>dose-response curve</strong>.  The 4-parameter model was used here because the underlying physical process is expected to be symmetric, and is defined as:</p>
<pre class="code">
<table>
<tr>
<td rowspan="5"><img src="http://latex.codecogs.com/gif.latex?y = d + \frac{a - d}{1 + (\frac{x}{c})^b}" title="y = d + \frac{a - d}{1 + (\frac{x}{c})^b}" />
<tr>
<td> a - response at x = 0
<tr>
<td> b - slope factor
<tr>
<td> c - mid-range (50%) concentration
<tr>
<td> d - response as x -> infinity
</table>
</pre>
<p>The 5-parameter logistic adds an additional asymmetry parameter that allow the leading and trailing tails to have different curvatures. It is defined as:</p>
<pre class="code">
<table>
<tr>
<td rowspan="6"><img src="http://latex.codecogs.com/gif.latex?y = d + \frac{a - d}{[1 + (\frac{x}{c})^b]^g}" title="y = d + \frac{a - d}{[1 + (\frac{x}{c})^b]^g}" />
<tr>
<td> a - response at x = 0
<tr>
<td> b - slope factor
<tr>
<td> c - mid-range (50%) concentration
<tr>
<td> d - response as x -> infinity
<tr>
<td> g - asymmetry factor
</table>
</pre>
<p> Using NMath the following C# code fits the four-parameter logistic to the given data.  By extending the initial conditions vector by one element, and changing the model function delegate we could use the same code to fit the <code> FiveParameterLogistic </code> function.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">CenterSpace.NMath.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">CenterSpace.NMath.Analysis</span><span style="color: #008000;">;</span>
&nbsp;
 <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> NonlinearFitExampleCode<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
 <span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Make some synthetic data</span>
    DoubleVector xValues <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;30000 10000 3000 500 200 60  25 10&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    DoubleVector yValues <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;112.8 115 131 118 26 1.7 -0.8 -1.4&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// This is the function delegate that the curve fitting </span>
    <span style="color: #008080; font-style: italic;">// class will use - any delegate can be used.</span>
    NMathFunctions.<span style="color: #0000FF;">GeneralizedDoubleUnaryFunction</span> f 
      <span style="color: #008000;">=</span> AnalysisFunctions.<span style="color: #0000FF;">FourParameterLogistic</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// The starting point in the function parameter space.</span>
    DoubleVector start <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;0.1 0.1 0.1 0.1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Construct a curve fitting object for our function, then perform the fit.</span>
    OneVariableFunctionFitter fitter 
      <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> OneVariableFunctionFitter<span style="color: #000000;">&#40;</span>f<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    DoubleVector solution <span style="color: #008000;">=</span> fitter.<span style="color: #0000FF;">Fit</span><span style="color: #000000;">&#40;</span>xValues, yValues, start<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Display solution</span>
    Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;4 Parameter Logistic Model Parameters: {0}&quot;</span>, solution.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;0.####&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The model parameters are returned in a vector, in the order defined above [a, b, c, d].</p>
<pre class="code">
4 Parameter Logistic Model Parameters:
  [ -0.1755 6.0556 246.8343 119.6108 ]
</pre>
<p>The fitting class <code> OneVariableFunctionFitter </code> is based on the Trust Region algorithm which is an extension of the Levenberg-Marquardt minimization algorithm.  As used in the example above, the partial derivatives with respect to the parameters are numerically estimated.  In our experience numerically estimating the partials works very well.  However, for improved precision and performance it is also possible to explicitly specify delegates for the partials, using the property: </p>
<pre class="code"> NMathFunctions.GeneralizedDoubleUnaryFunction[] PartialDeriviates </pre>
<p>If the curvature of the function surface is low, as is typically the case for the logistic model, and the local linearized estimate closely approximates the function surface during the minimization process, the partial derivatives are not even evaluated for performance reasons.   </p>
<h3>Bounded Parameters</h3>
<p>Because the <code> OneVariableFunctionFitter  </code> is based on the Trust Region algorithm, it is possible to place bounds on the parameters.  This is a very powerful feature, which is frequently employed when modeling a dose-response curve with a logistic.  There&#8217;s an old debate between the chemists and biologists regarding the dose-response curve on whether the curve should be relative or absolute.  In the image above, a <strong>relative</strong> dose-response curve is shown, as there were no bounds placed on the four parameters.  However, we can create an <strong>absolute</strong> dose-response curve by adding the constraints <code> 100 >= a >= 0 </code> and <code> 0 <= d <= 100 </code> and re-fitting the curve.  This will enforce all predicted responses to be between 0% and 100%. </p>
<div id="attachment_1998" class="wp-caption aligncenter" style="width: 460px"><a href="http://www.centerspace.net/blog/wp-content/uploads/2010/04/Logistic-model-fit-with-parameter-bounds-.png"><img src="http://www.centerspace.net/blog/wp-content/uploads/2010/04/Logistic-model-fit-with-parameter-bounds-.png" alt="Logistic model fit with parameter bounds" title="Logistic model fit with parameter bounds" height="200" class="size-full wp-image-1998" /></a><p class="wp-caption-text">Logistic model fit with parameter bounds <code> 100 >= a >= 0 </code> and <code> 0 <= d <= 100 </code> </code></p></div>
<p>Here is a C# code example on how to do this with NMath.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">CenterSpace.NMath.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">CenterSpace.NMath.Analysis</span><span style="color: #008000;">;</span>
&nbsp;
 <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> BoundedNonlinearFitExampleCode<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
 <span style="color: #000000;">&#123;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// Make some synthetic data</span>
  DoubleVector xValues <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;30000 10000 3000 500 200 60  25 10&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  DoubleVector yValues <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;112.8 115 131 118 26 1.7 -0.8 -1.4&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// The starting point in the function parameter space.</span>
  DoubleVector start <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;0.1 0.1 0.1 100.0&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// 4-parameter bounds in the order of a, b, c, &amp; d</span>
  DoubleVector lowerBounds <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;0.0 0.0 0.0 0.0&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  DoubleVector upperBounds <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;100.0 100000.0 100000.0 100.0&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// Convert the 4-parameter logistic to a Func&lt;&gt;</span>
  Func<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">Double</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span>, <span style="color: #FF0000;">Double</span>, <span style="color: #FF0000;">Double</span><span style="color: #008000;">&gt;</span> fitFunction <span style="color: #008000;">=</span> 
    <span style="color: #008000;">new</span> Func<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">double</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span>, <span style="color: #FF0000;">double</span>, <span style="color: #FF0000;">double</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">double</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> soln, <span style="color: #FF0000;">Double</span> x<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span> AnalysisFunctions.<span style="color: #0000FF;">FourParameterLogisticFunction</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span>   DoubleVector<span style="color: #000000;">&#40;</span>soln<span style="color: #000000;">&#41;</span>, x<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// This class is not included with the current release.</span>
  FunctionFitterWithBounds fitter <span style="color: #008000;">=</span> 
    <span style="color: #008000;">new</span> FunctionFitterWithBounds<span style="color: #000000;">&#40;</span>fitFunction, lowerBounds, upperBounds<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">//Now define and fit the data as shown above.</span>
  DoubleVector solution <span style="color: #008000;">=</span> fitter.<span style="color: #0000FF;">Fit</span><span style="color: #000000;">&#40;</span>xValues, yValues, start<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// Display solution</span>
   Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;4 Parameter Logistic Model Parameters: {0}&quot;</span>, solution.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;0.####&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The bounded model parameters returned, in the order defined above [a, b, c, d] are:</p>
<pre class="code">
4 Parameter Logistic Model Parameters: [ 0 0.1652 0.787 100 ]
</pre>
<p>Note that the first and last parameters are now within the specified bounds.</p>
<p> The class <code> FunctionFitterWithBounds </code> is unreleased (and won't be in this form) but you can download it and use it if you have the latest release of NMath installed.   The non-linear curving fitting NMath API will be extended and refined in our next NMath release, and bounded non-linear curve fitting will be more clearly accessible.</p>
<ul>
<li> <strong>Click <a href="http://www.centerspace.net/pub/FunctionFitterWithBounds.zip">here</a> to download the free C# <code> FunctionFitterWithBounds </code> class.</strong></li>
</ul>
<h3>Goodness-Of-Fit Model Statistics</h3>
<p>After we are done fitting our model, the fit may look good, but really how good is the fit?  To better understand the goodness-of-fit of our model, we need to analyze the residuals of the fit and related statistics.   The next release of NMath Stats (expected in June) will offer a new class <code> GoodnessOfFit </code> that will provide a complete set of statistical measures that can be used to assess the goodness-of-fit for a non-linear model, including the F-Statistic, t-Statistic, and parameter confidence intervals.  Please contact us if  you are interested in obtaining an advanced copy of this class.</p>
<p>Happy Computing,<br />
<em> Paul </em></p>
<p><strong> Resources </strong></p>
<ul>
<li><a href="http://www.esbatech.raab.me.uk/papers/5pl.pdf">The five-parameter logistic</a>: A characterization and comparison with the four-parameter logistic, Paul G. Gotschalk, John R. Dunn, Analytical Biochemistry 343 (2005) pp 54-65.
<li><a href="http://www.bio-rad.com/LifeScience/pdf/Bulletin_2861.pdf">Principles of Curve Fitting for Multiplex Sandwich Immunoassys</a>, D. Davis, A. Zhang, C. Etienne, I. Huang, &#038; M. Malit, tech note 2861.
<li>A brief technical introduction to <a href="http://www.google.com/url?sa=t&#038;source=web&#038;ct=res&#038;cd=7&#038;ved=0CCsQFjAG&#038;url=http%3A%2F%2Fwww.math.mtu.edu%2F~msgocken%2Fma5630spring2003%2Flectures%2Ftr%2Ftr.pdf&#038;ei=7x-9S-qfF5LOsgPR9cTsBA&#038;usg=AFQjCNEJEqNuY1H4Izo3MTuMUpG1f6anIg&#038;sig2=TD_JKzyl_b6fMnbG_G4f3w">Trust Region methods</a>, by Mark S. Gockenbach<br />
]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/nmath/non-linear-curve-fitting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Nevron Partnership</title>
		<link>http://www.centerspace.net/blog/corporate/nevron-partnership/</link>
		<comments>http://www.centerspace.net/blog/corporate/nevron-partnership/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 16:00:57 +0000</pubDate>
		<dc:creator>Paul Shirkey</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Corporate]]></category>
		<category><![CDATA[charting with NMath]]></category>
		<category><![CDATA[data smoothing]]></category>
		<category><![CDATA[data visualization]]></category>
		<category><![CDATA[linear regression]]></category>
		<category><![CDATA[math charts]]></category>
		<category><![CDATA[Nevron Partnership]]></category>
		<category><![CDATA[polyfit]]></category>
		<category><![CDATA[process control charts]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=1903</guid>
		<description><![CDATA[<img src="http://www.centerspace.net/blog/wp-content/uploads/2010/03/Nevron_ex1_polyfit-300x216.png" alt="" title="Fitting a polynomial to some sample data."  class="excerpt" />  All of us at CenterSpace software are proud to announce a partnership with <a href="http://www.nevron.com">Nevron</a>, leaders in data visualization.   Nevron builds .NET components which enable developers to quickly build clean, enterprise quality, user interfaces incorporating well rendered maps, gauges, diagrams, or charts.  Check out our <a href="http://www.centerspace.net/partners/nevron" >partnership page</a> for more information and free examples.]]></description>
			<content:encoded><![CDATA[<p>All of us at CenterSpace software are proud to announce a partnership with <a href="http://www.nevron.com">Nevron</a>, leaders in data visualization.  <img src="http://www.centerspace.net/blog/wp-content/uploads/2010/03/NevronChartArt.jpg" alt="Nevron Chart Visualizations" title="NevronChartArt" width="308" height="239" class="alignright size-full wp-image-1905" /> Nevron builds .NET components which enable developers to quickly build clean, enterprise quality, user interfaces incorporating well rendered maps, gauges, diagrams, or charts.  Nevron has built it&#8217;s visualization framework with the developer in mind and has created components that are powerful, yet quick to pick up and work with.  </p>
<h3> Free Project Examples </h3>
<p>As part of of this partnership our software engineers are working together to develop a series of example applications to help our customers quickly become productive using our tool set.  Our first example demonstrates how to use the Nevron .NET chart component with some of NMath Stat&#8217;s fundamental capabilities: regression and prediction, polynomial curve fitting, and data smoothing.  <a href="http://www.centerspace.net/blog/wp-content/uploads/2010/03/Nevron_ex1_polyfit.png"><img src="http://www.centerspace.net/blog/wp-content/uploads/2010/03/Nevron_ex1_polyfit-300x216.png" alt="" title="Fitting a polynomial to some sample data." width="300" height="216" class="alignleft size-medium wp-image-1907" /></a> To build and run this example, you&#8217;ll need to download this VS8 project, along with evaluation copies of the CenterSpace NMath Suite and the Nevron .NET Chart package. All of this is freely available from our <a href="http://www.centerspace.net/partners/nevron">partnership page</a>.</p>
<p>As I mentioned this is the first in a series of examples that we will be jointly developing.  Our next example application is in the planning stages, and will cover the building of common charts in statistical process control.  Statistical process control is employed across many industries ranging from manufacturing to medicine and has been an area of interest by customers of both companies.  We&#8217;ll post up a blog article about the example once it&#8217;s finished and you&#8217;ll see a tweet about it if you are <a href="http://twitter.com/centerspacesoft">following us</a>.  </p>
<p>If you have an idea for an example using Nevon&#8217;s and CenterSpace&#8217;s tools together, which would help speed along your own project, leave a comment or drop us an email.   We just may cook it up!</p>
<h3> Discount Bundle </h3>
<p>As part of our partnership with Nevron, we are able to offer a substantial discount on package licenses.  If you are interested, please email our <a href="mailto:sales@centerspace.net">sales</a> staff and request the Nevron partnership discount.</p>
<p>Thanks for reading,</p>
<p><em>-The CenterSpace Team</em><br />
<br />
<b> Resources </b></p>
<ul>
<li>CenterSpace partnership information <a href="http://www.centerspace.net/partners/nevron">partnership page</a>.
<li>Nevron technology partnership information <a href="http://www.nevron.com/Nevron.Company.Partners.TechnologyPartners.aspx">page</a>.
<li>Nevron&#8217;s .NET Chart <a href="http://www.nevron.com/Products.ChartFor.NET.Overview.aspx"> home page</a>.
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/corporate/nevron-partnership/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excel Trendlines</title>
		<link>http://www.centerspace.net/blog/nmath/nmath-tutorial/excel-trendlines/</link>
		<comments>http://www.centerspace.net/blog/nmath/nmath-tutorial/excel-trendlines/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 14:45:35 +0000</pubDate>
		<dc:creator>Ken Baldwin</dc:creator>
				<category><![CDATA[NMath Tutorial]]></category>
		<category><![CDATA[.NET exponential regression]]></category>
		<category><![CDATA[.NET linear regression]]></category>
		<category><![CDATA[.NET logarithmic regression]]></category>
		<category><![CDATA[.NET moving average filter]]></category>
		<category><![CDATA[.NET polynomial regression]]></category>
		<category><![CDATA[.NET power regression]]></category>
		<category><![CDATA[C# exponential regression]]></category>
		<category><![CDATA[C# linear regression]]></category>
		<category><![CDATA[C# logarithmic regression]]></category>
		<category><![CDATA[C# moving average filter]]></category>
		<category><![CDATA[C# polynomial regression]]></category>
		<category><![CDATA[C# power regression]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=1870</guid>
		<description><![CDATA[<img src="http://s84547.gridserver.com/blog/./blog/wp-content/uploads/2010/02/233px-Microsoft_Excel_Icon.svg_.png" alt="" title="Excel Icon"  class="excerpt" />
We are sometimes asked how to reproduce the various Excel Trendline types in NMath: Linear, Logarithmic, Exponential, Power, Polynomial, and Moving Average. In this post, we show you how to compute each trendline using NMath, including printing out the form of the equation and the R2 value (coefficient of determination). ]]></description>
			<content:encoded><![CDATA[<p>We are sometimes asked how to reproduce the various Excel Trendline types in NMath, including printing out the form of the equation and the R2 value (coefficient of determination). Excel offers these trend types:</p>
<ul>
<li>Linear</li>
<li>Logarithmic</li>
<li>Exponential</li>
<li>Power</li>
<li>Polynomial</li>
<li>Moving Average</li>
</ul>
<p>These can all be easily computed using NMath. Let&#8217;s see how. First, let&#8217;s start with a simple data series:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">DoubleVector x <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">11</span>, <span style="color: #FF0000;">15</span>, <span style="color: #FF0000;">18</span>, <span style="color: #FF0000;">23</span>, <span style="color: #FF0000;">26</span>, <span style="color: #FF0000;">31</span>, <span style="color: #FF0000;">39</span>, <span style="color: #FF0000;">44</span>, <span style="color: #FF0000;">54</span>, <span style="color: #FF0000;">64</span>, <span style="color: #FF0000;">74</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
DoubleVector y <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleVector<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0.00476</span>, <span style="color: #FF0000;">0.0105</span>, <span style="color: #FF0000;">0.0207</span>, <span style="color: #FF0000;">0.0619</span>, <span style="color: #FF0000;">0.337</span>, <span style="color: #FF0000;">0.74</span>, <span style="color: #FF0000;">1.7</span>, <span style="color: #FF0000;">2.45</span>, <span style="color: #FF0000;">3.5</span>, <span style="color: #FF0000;">4.5</span>, <span style="color: #FF0000;">5.09</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>These data represent <a href="http://online.redwoods.cc.ca.us/instruct/darnold/DIFFEQ/logistic/logistic.pdf">the evolution of an algal bloom in the Adriatic Sea</a>. The x-values are time expressed in days, and the y-values are the size of the surface of the bloom in mm<sup>2</sup>.</p>
<h3>Linear</h3>
<p>The Linear trendline fits a line, <code>y = a*x + b</code>, to the data. This is easily computed using the LinearRegression class in NMath Stats, as shown in the following C# code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">bool</span> addIntercept <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
LinearRegression lr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LinearRegression<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> DoubleMatrix<span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span>, y, addIntercept<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
LinearRegressionAnova lrAnova <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LinearRegressionAnova<span style="color: #000000;">&#40;</span>lr<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">double</span> a <span style="color: #008000;">=</span> lr.<span style="color: #0000FF;">Parameters</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">double</span> b <span style="color: #008000;">=</span> lr.<span style="color: #0000FF;">Parameters</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">double</span> r2 <span style="color: #008000;">=</span> lrAnova.<span style="color: #0000FF;">RSquared</span><span style="color: #008000;">;</span>
&nbsp;
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;y = {0}x + {1}&quot;</span>, a, b<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;r2 = {0}&quot;</span>, r2<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Output</p>
<pre class="code">y = -1.63908651994092x + 0.0913403802489977
r2 = 0.967828167696715</pre>
<p>Note that to compute the coefficient of determination (R2), we construct a LinearRegressionAnova object from the LinearRegression instance. This class tests overall model significance for regressions computed by LinearRegression.</p>
<h3>Logarithmic</h3>
<p>The Logarithmic trendline fits a line to ln(x), y&#8211;that is, <code>y = a*ln(x) + b</code>. Again, we can use the LinearRegression class for this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">DoubleVector logX <span style="color: #008000;">=</span> NMathFunctions.<span style="color: #0000FF;">Log</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
lr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LinearRegression<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> DoubleMatrix<span style="color: #000000;">&#40;</span>logX<span style="color: #000000;">&#41;</span>, y, addIntercept<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
a <span style="color: #008000;">=</span> lr.<span style="color: #0000FF;">Parameters</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
b <span style="color: #008000;">=</span> lr.<span style="color: #0000FF;">Parameters</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
r2 <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LinearRegressionAnova<span style="color: #000000;">&#40;</span>lr<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">RSquared</span><span style="color: #008000;">;</span>
&nbsp;
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;y = {0}ln(x) + {1}&quot;</span>, a, b<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;r2 = {0}&quot;</span>, r2<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Output:</p>
<pre class="code">y = -8.17805531083818ln(x) + 2.87283105614145
r2= 0.840393353070466</pre>
<h3>Exponential</h3>
<p>The Exponential trendline fits the function <code>y = a * e ^(b * x)</code>. This can also be computed using LinearRegression by fitting a line to x, ln(y). Taking the log of both sides of the function  gives:</p>
<pre>ln(y) = ln(a * e ^(b * x)) = ln(a) + bx</pre>
<p>The following C# code does this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">DoubleVector logY <span style="color: #008000;">=</span> NMathFunctions.<span style="color: #0000FF;">Log</span><span style="color: #000000;">&#40;</span>y<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
lr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LinearRegression<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> DoubleMatrix<span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span>, logY, addIntercept<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
a <span style="color: #008000;">=</span> Math.<span style="color: #0000FF;">Exp</span><span style="color: #000000;">&#40;</span>lr.<span style="color: #0000FF;">Parameters</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
b <span style="color: #008000;">=</span> lr.<span style="color: #0000FF;">Parameters</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
r2 <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LinearRegressionAnova<span style="color: #000000;">&#40;</span>lr<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">RSquared</span><span style="color: #008000;">;</span>
&nbsp;
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;y = {0}e^{1}x&quot;</span>, a, b<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;r2 = {0}&quot;</span>, r2<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Output:</p>
<pre class="code">y = 0.00552689525130073e^0.112876522212724x
r2 = 0.812366433832176</pre>
<p>Note that because the intercept of the fitted line is the natural log of the &#8220;a&#8221; parameter in the exponential function, we need to take the exponential of the found intercept (using <code>Math.Exp</code>) to recover the value of &#8220;a&#8221;.</p>
<h3>Power</h3>
<p>The Power trendline fits the function <code>y = a * x^b</code>. This can be computed using LinearRegression by fitting a line to ln(x), ln(y). Taking the log of both sides of the equation gives:</p>
<pre>ln(y) = ln(a * x^b) = ln(a) + b * ln(x)</pre>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">lr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LinearRegression<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> DoubleMatrix<span style="color: #000000;">&#40;</span>logX<span style="color: #000000;">&#41;</span>, logY, addIntercept<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
lrAnova <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LinearRegressionAnova<span style="color: #000000;">&#40;</span>lr<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
a <span style="color: #008000;">=</span> Math.<span style="color: #0000FF;">Exp</span><span style="color: #000000;">&#40;</span>lr.<span style="color: #0000FF;">Parameters</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
b <span style="color: #008000;">=</span> lr.<span style="color: #0000FF;">Parameters</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
r2 <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LinearRegressionAnova<span style="color: #000000;">&#40;</span>lr<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">RSquared</span><span style="color: #008000;">;</span>
&nbsp;
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;y = {0}x^{1}&quot;</span>, a, b<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;r2 = {0}&quot;</span>, r2<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Output:</p>
<pre class="code">y = 2.46993343563889E-07x^4.11443630332377
r2 = 0.947447653331871</pre>
<p>Again, we recover the value of parameter &#8220;a&#8221; by taking the exponential of the found intercept.</p>
<h3>Polynomial</h3>
<p>NMath provides class PolynomialLeastSquares for fitting a polynomial of the specified degree to paired vectors of x- and y-values. For example, this code fits a cubic to our data:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">int</span> degree <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">;</span>
PolynomialLeastSquares pls <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PolynomialLeastSquares<span style="color: #000000;">&#40;</span>degree, x, y<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// compute R2</span>
DoubleVector predictions <span style="color: #008000;">=</span> pls.<span style="color: #0000FF;">FittedPolynomial</span>.<span style="color: #0000FF;">Evaluate</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">double</span> regressionSumOfSquares <span style="color: #008000;">=</span> StatsFunctions.<span style="color: #0000FF;">SumOfSquares</span><span style="color: #000000;">&#40;</span>predictions <span style="color: #008000;">-</span> StatsFunctions.<span style="color: #0000FF;">Mean</span><span style="color: #000000;">&#40;</span>y<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">double</span> residualSumOfSquares <span style="color: #008000;">=</span> pls.<span style="color: #0000FF;">LeastSquaresSolution</span>.<span style="color: #0000FF;">Residuals</span>.<span style="color: #0000FF;">TwoNormSquared</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
r2 <span style="color: #008000;">=</span> regressionSumOfSquares <span style="color: #008000;">/</span> <span style="color: #000000;">&#40;</span>regressionSumOfSquares <span style="color: #008000;">+</span> residualSumOfSquares<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;y = &quot;</span> <span style="color: #008000;">+</span> pls.<span style="color: #0000FF;">FittedPolynomial</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;r2 = {0}&quot;</span>, r2<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Output:</p>
<pre class="code">
y = -4.68278158094222E-05x^3 + 0.00640408381023593x^2 -
      0.1643720340709x + 1.12703300920657
r2 = 0.998634459376868</pre>
<p>Note that PolynomialLeastSquares does not currently provide the R2 value, so in the code above we compute it directly.</p>
<h3>Moving Average</h3>
<p>Unlike the trendlines we&#8217;ve examined so far, a moving average does not fit a functional form to data. Rather, it filters data in order to smooth out noise. NMath provides class MovingWindowFilter for this purpose.</p>
<p>Class MovingWindowFilter replaces data points with a linear combination of the data points immediately to the left and right of each point, based on a given set of coefficients to use in the linear combination. Static class methods are provided for generating coefficients to implement a moving average filter and a Savitzky-Golay smoothing filter.</p>
<p>For example, the following C# code filters the data using a window of width 3 (the &#8220;period&#8221; parameter in Excel):</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">int</span> numberLeft <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">int</span> numberRight <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
DoubleVector movingAvgCoefficents <span style="color: #008000;">=</span> MovingWindowFilter.<span style="color: #0000FF;">MovingAverageCoefficients</span><span style="color: #000000;">&#40;</span>numberLeft, numberRight<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
MovingWindowFilter filter <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MovingWindowFilter<span style="color: #000000;">&#40;</span>numberLeft, numberRight, movingAvgCoefficents<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
DoubleVector yfiltered <span style="color: #008000;">=</span> filter.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>y, MovingWindowFilter.<span style="color: #0000FF;">BoundaryOption</span>.<span style="color: #0000FF;">DoNotFilterBoundaryPoints</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;yfiltered = &quot;</span> <span style="color: #008000;">+</span> yfiltered<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Output:</p>
<pre class="code">
yfiltered = [ 0.00476 0.0119866666666667 0.0310333333333333
              0.139866666666667 0.379633333333333 0.925666666666667 1.63
              2.55 3.48333333333333 4.36333333333333 5.09 ]</pre>
<h3>Advanced Curve Fitting</h3>
<p>That covers the simple trendlines produced by Excel. For advanced curve fitting, NMath provides class OneVariableFunctionFitter which fits arbitrary one variable functions to a set of points. (You must supply at least as many data points to fit as your function has parameters.) In a future post, we&#8217;ll take a look at this class. In the meantime, see <a href="http://www.centerspace.net/examples/nmath/csharp/analysis/one-variable-curve-fitting-example.php">this page</a> for an example demonstrating the use of OneVariableFunctionFitter, including how to define your own function.</p>
<p>Ken</p>
]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/nmath/nmath-tutorial/excel-trendlines/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using NMath in .NET 4.0 Applications</title>
		<link>http://www.centerspace.net/blog/nmath/using-nmath-in-net-4-0-applications/</link>
		<comments>http://www.centerspace.net/blog/nmath/using-nmath-in-net-4-0-applications/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 15:53:34 +0000</pubDate>
		<dc:creator>Ken Baldwin</dc:creator>
				<category><![CDATA[NMath]]></category>
		<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[useLegacyV2RuntimeActivationPolicy]]></category>

		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=1859</guid>
		<description><![CDATA[Version 4.0 of the .NET Framework introduced a new runtime activation policy, which enables an application to activate multiple versions of the common language runtime (CLR) in the same process. (See here  for more information.)
Because of this support for side-by-side runtimes, .NET 4.0 has changed the way that it binds to older mixed-mode assemblies,...]]></description>
			<content:encoded><![CDATA[<p>Version 4.0 of the .NET Framework introduced a new runtime activation policy, which enables an application to activate multiple versions of the common language runtime (CLR) in the same process. (See <a href="ttp://msdn.microsoft.com/en-us/library/dd233115(VS.100).aspx">here </a> for more information.)</p>
<p>Because of this support for side-by-side runtimes, .NET 4.0 has changed the way that it binds to older mixed-mode assemblies, such as the NMath Kernel assembly, which is written in C++\CLI and uses the Intel Math Kernel Library internally.</p>
<p>When using NMath in .NET 4.0 applications, the NMath Kernel fails to load, because it was built against an earlier version of .NET and includes unmanaged code. The error is:</p>
<pre>System.TypeInitializationException : The type initializer for
'CenterSpace.NMath.Core.NMathKernel' threw an exception.
----&gt; CenterSpace.NMath.Core.KernelLoadException : Could
not load kernel assembly NMathKernelx86</pre>
<p>There are two solutions:</p>
<ol>
<li>Activate the v2.0 runtime activation policy by adding the following lines to your app.config when using runtime v4.0:
<pre>&lt;configuration&gt;
  &lt;startup useLegacyV2RuntimeActivationPolicy="true"&gt;
    &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/&gt;
  &lt;/startup&gt;
&lt;/configuration&gt;</pre>
<p>See <a href="http://msdn.microsoft.com/en-us/library/bbx34a2h(VS.100).aspx">here</a> for more information on the &lt;startup&gt; element.</li>
<li>Request assemblies for .NET 3.5  from <a href="/services/support/">Centerspace Technical Support</a>. (see below for correction)</li>
</ol>
<p>In the next release of NMath, the shipping assemblies will be built against .NET 3.5. (Assemblies for .NET 2.0 will remain available upon request.) &lt;&lt; see below for correction</p>
<p>Ken</p>
<p><strong>Update</strong></p>
<p>This issue can only be solved with the application config change or with assemblies built with .NET 4.0.</p>
<p>If you are widely deploying your application, you should probably target .NET 3.5 or earlier. In this case, the application config is the best solution.</p>
<p>If you know your application will be run within .NET 4.0 or later and don&#8217;t wish to make the application config change, please contact us at support@centerspace.net. We can send you NMath assemblies built and tested with .NET 4.0.</p>
<p>Since we don&#8217;t use any .NET 3.5 features and it&#8217;s too early to target .NET 4.0 with a class library, we will be targeting .NET 2.0 in the next release (expected in June, 2010).</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.centerspace.net%2Fblog%2Fnmath%2Fusing-nmath-in-net-4-0-applications%2F&amp;linkname=Using%20NMath%20in%20.NET%204.0%20Applications"><img src="http://www.centerspace.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/nmath/using-nmath-in-net-4-0-applications/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Principal Components Regression: Part 2 &#8211; The Problem With Linear Regression</title>
		<link>http://www.centerspace.net/blog/statistics/priniciple-components-regression-in-csharp/</link>
		<comments>http://www.centerspace.net/blog/statistics/priniciple-components-regression-in-csharp/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 17:17:07 +0000</pubDate>
		<dc:creator>Steve Sneller</dc:creator>
				<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Theory]]></category>
		<category><![CDATA[PCR]]></category>
		<category><![CDATA[PCR c#]]></category>
		<category><![CDATA[PCR estimator]]></category>
		<category><![CDATA[principal component analysis C#]]></category>
		<category><![CDATA[principal component regression]]></category>

		<guid isPermaLink="false">http://centerspace.net/blog/?p=1816</guid>
		<description><![CDATA[Multiple Linear Regression (MLR) is a powerful approach to modeling the relationship between one or two or more <em>explanatory</em> variables and a <em>response </em>variable by fitting a linear equation to observed data.  This is the second part in a three part series on PCR. ]]></description>
			<content:encoded><![CDATA[<p><small> This is the second part in a three part series on PCR, the first article on the topic can be found <a href="http://centerspace.net/blog/statistics/theoretical-motivation-behind-pcr/">here</a>.</small></p>
<h3><strong>The Linear Regression Model</strong></h3>
<p>Multiple Linear Regression (MLR) is a common approach to modeling the relationship between one or two or more <em>explanatory</em> variables and a <em>response </em>variable by fitting a linear equation to observed data. First let&#8217;s set up some notation. I will be rather brief, assuming the audience is somewhat familiar with MLR.</p>
<p>In multiple linear regression it is assumed that a <em>response variable</em>, <img title="Y" src="http://latex.codecogs.com/gif.latex?Y" alt="" /> depends on k <em>explanatory variables</em>, <img title="X_1,...X_k" src="http://latex.codecogs.com/gif.latex?X_1,...,X_k" alt="" />, by way of a linear relationship:</p>
<p><img title="Y=b_1X_1+b_2X_2...+b_kX_k" src="http://latex.codecogs.com/gif.latex?Y=b_1X_1+b_2X_2...+b_kX_k" alt="" /></p>
<p>The idea is to perform several observations of the response and explanatory variables and then to chose the linear coefficients <img title="b_1,...b_k" src="http://latex.codecogs.com/gif.latex?b_1,...b_k" alt="" /> which best fit the observed data.</p>
<p>Thus, a multiple linear regression model is:</p>
<p><img title="y_{i} = c + x_{i1}b_{1} + \cdots + x_{ik}b_{k} + f" src="http://latex.codecogs.com/gif.latex?y_{i} = c + x_{i1}b_{1} + \cdots + x_{ik}b_{k} + f_{i}" alt="" /><br />
<img title="i = 1,\cdots,n,\textrm{ where:}" src="http://latex.codecogs.com/gif.latex?i = 1,\cdots,n,\textrm{ where:}" alt="" /><br />
<img title="y_{i}\textrm{ is the }i\textrm{th value of the response variable}" src="http://latex.codecogs.com/gif.latex?y_{i}\textrm{ is the }i\textrm{th value of the response variable}" alt="" /><br />
<img title="x_{ij}\textrm{ is the }i\textrm{th value of the }j\textrm{th explanatory variable}" src="http://latex.codecogs.com/gif.latex?x_{ij}\textrm{ is the }i\textrm{th value of the }j\textrm{th explanatory variable}" alt="" /><br />
<img title="n \textrm{ is the sample size}" src="http://latex.codecogs.com/gif.latex?n \textrm{ is the sample size}" alt="" /><br />
<img title="k \textrm{ is the number of }x \textrm{-variables}" src="http://latex.codecogs.com/gif.latex?k \textrm{ is the number of }x \textrm{-variables}" alt="" /><br />
<img title="c \textrm{ is the intercpet of the regression model}" src="http://latex.codecogs.com/gif.latex?c \textrm{ is the intercpet of the regression model}" alt="" /><br />
<img title="b_{j} \textrm{ is the regression coefficient for the }j\textrm{th explanatory variable}" src="http://latex.codecogs.com/gif.latex?b_{j} \textrm{ is the regression coefficient for the }j\textrm{th explanatory variable}" alt="" /><br />
<img title="f\textrm{ is the random noise term, assumed independent, with zero mean and common variance }\sigma ^{2}" src="http://latex.codecogs.com/gif.latex?f\textrm{ is the random noise term, assumed independent, with zero mean and common variance }\sigma ^{2}" alt="" /><br />
<img title="c, b_{1},\cdots,b_{k}\textrm{ and }\sigma^{2}\textrm{ are unknown parameters, to be estimated from the data.}" src="http://latex.codecogs.com/gif.latex?c, b_{1},\cdots,b_{k}\textrm{ and }\sigma^{2}\textrm{ are unknown parameters, to be estimated from the data.}" alt="" /></p>
<p></p>
<p>In matrix notation we have</p>
<p><img title="Xb = y" src="http://latex.codecogs.com/gif.latex?\textrm{(1)  }Xb = y + f" alt="" /></p>
<p>where</p>
<p><img title="X = (x_{ij})\textrm{, } y = (y_{i}) \textrm{, and } f = f_{i}" src="http://latex.codecogs.com/gif.latex?X = (x_{ij})\textrm{, } y = (y_{i}) \textrm{, and } f = f_{i}" alt="" />.</p>
<p>The solution for the coefficient vector <img title="b" src="http://latex.codecogs.com/gif.latex?b" alt="" /> which &#8220;best&#8221; fits the data is given by the so called &#8220;normal equations&#8221;</p>
<p><img title="\textrm{(2)  }\beta=(X'X)^{-1}X'y" src="http://latex.codecogs.com/gif.latex?\textrm{(2)  }\beta=(X'X)^{-1}X'y" alt="" /></p>
<p>This is known as the least squares solution to the problem because it minimizes the sum of the squares of the errors.</p>
<p>Now, consider the following example in which<br />
<img title="X=\begin{bmatrix} 1 &amp; 1.9\ 1 &amp; 2.1\ 1 &amp; 2\\ 1&amp; 2\\ 1 &amp; 1.8 \end{bmatrix}" src="http://latex.codecogs.com/gif.latex?X=\begin{bmatrix} 1 &amp; 1.9\\ 1 &amp; 2.1\\ 1 &amp; 2\\ 1&amp; 2\\ 1 &amp; 1.8 \end{bmatrix}" alt="" /></p>
<p>and</p>
<p><img title="y=\begin{bmatrix} 6.0521\\ 7.0280\\ 7.1230\\ 4.4441\\ 5.0813 \end{bmatrix}" src="http://latex.codecogs.com/gif.latex?y=\begin{bmatrix} 6.0521\\ 7.0280\\ 7.1230\\ 4.4441\\ 5.0813 \end{bmatrix}" alt="" /></p>
<p>Solving this simple linear regression model using the normal equations yields</p>
<p><img title="\widehat{b}=\begin{bmatrix} -4.2489\\ 5.2013 \end{bmatrix}" src="http://latex.codecogs.com/gif.latex?\widehat{b}=\begin{bmatrix} -4.2489\\ 5.2013 \end{bmatrix}" alt="" /></p>
<p>which is quite far off from the actual solution</p>
<p><img title="b=\begin{bmatrix} 2\\ 2 \end{bmatrix}" src="http://latex.codecogs.com/gif.latex?b=\begin{bmatrix} 2\\ 2 \end{bmatrix}" alt="" /></p>
<p>The reason behind this is the fact that the matrix <img title="X'X" src="http://latex.codecogs.com/gif.latex?X'X" alt="" /> is ill conditioned. Since the second column of <img title="X" src="http://latex.codecogs.com/gif.latex?X" alt="" /> is approximately twice the first, the matrix <img title="X'X" src="http://latex.codecogs.com/gif.latex?X'X" alt="" /> is almost singular.</p>
<p>One solution to this problem would be to change the model. Since the second column is approximately twice the first, these two explanatory variables encode basically the same information, thus we could remove one of them from the model.<br />
However, it is usually not so easy to identify the source of the bad conditioning as it is in this example.</p>
<p>Another method for removing information from a model that is responsible for impreciseness in the least squares solution is offered by the technique of <em>principal component regression </em>(PCR). Henceforth we shall assume that the data in the matrix <img title="X" src="http://latex.codecogs.com/gif.latex?X" alt="" /> is <em>centered</em>. By this we mean that the mean of each explanatory variable has been subtracted from each column of X so that the explanatory variables all have mean zero. In particular this implies that the matrix <img title="X'X" src="http://latex.codecogs.com/gif.latex?X'X" alt="" /> is proportional to the covariance matrix for the explanatory variables.</p>
<h3>Removing the Source of Imprecision</h3>
<p>Let <img title="X" src="http://latex.codecogs.com/gif.latex?X" alt="" /> be an mxn matrix, and recall from the part 1 of this series that we can write <img title="X^TX" src="http://latex.codecogs.com/gif.latex?X^TX" alt="" /> as</p>
<p><img title="X^TX=V \Lambda V^T" src="http://latex.codecogs.com/gif.latex?X^TX=V \Lambda V^T" alt="" /></p>
<p>where <img title="\Lambda" src="http://latex.codecogs.com/gif.latex?\Lambda" alt="" /> is a diagonal matrix containing the eigenvalues (in ascending order down the diagonal) of <img title="X^TX" src="http://latex.codecogs.com/gif.latex?X^TX" alt="" />, and <img title="V" src="http://latex.codecogs.com/gif.latex?V" alt="" /> is orthogonal. The condition number <img title="\kappa (X^TX)" src="http://latex.codecogs.com/gif.latex?\kappa (X^TX)" alt="" /> for <img title="X^TX" src="http://latex.codecogs.com/gif.latex?X^TX" alt="" /> is just the absolute value of the ratio of the largest and smallest eigenvalues:</p>
<p><img title="\kappa(X^TX)=\left | \frac{\lambda_{max}}{\lambda_{min}} \right |" src="http://latex.codecogs.com/gif.latex?\kappa(X^TX)=\left | \frac{\lambda_{max}}{\lambda_{min}} \right |" alt="" /></p>
<p>Thus we can see that if the smallest eigenvalue is much smaller than the largest eigenvalue, we get a very large condition number which implies a poorly conditioned matrix. The idea then is to remove these small eigenvalues from <img title="X^TX" src="http://latex.codecogs.com/gif.latex?X^TX" alt="" /> thus giving us an approximation to <img title="X^TX" src="http://latex.codecogs.com/gif.latex?X^TX" alt="" /> that is better conditioned. To this end, suppose that we wish to retain the r (r less than or equal to n) largest eigenvalues of <img title="X^TX" src="http://latex.codecogs.com/gif.latex?X^TX" alt="" /> in our approximation, and thus write</p>
<p><img title="X^TX=(V_1,V_2)\begin{pmatrix} \Lambda_1 &amp; 0 \\ 0 &amp; \Lambda_2 \end{pmatrix} \begin{pmatrix} V_1^T \\ V_2^T \end{pmatrix}" src="http://latex.codecogs.com/gif.latex?X^TX=(V_1,V_2)\begin{pmatrix} \Lambda_1 &amp; 0 \\ 0 &amp; \Lambda_2 \end{pmatrix} \begin{pmatrix} V_1^T \\ V_2^T \end{pmatrix}" alt="" />,</p>
<p>where</p>
<p><img title="\Lambda_1" src="http://latex.codecogs.com/gif.latex?\Lambda_1" alt="" /> is an r x r diagonal matrix consisting of the r largest eigenvalues of <img title="X^TX" src="http://latex.codecogs.com/gif.latex?X^TX" alt="" />, <img title="\Lambda_2" src="http://latex.codecogs.com/gif.latex?\Lambda_2" alt="" /> is a (n-r) x (n-r) diagonal matrix consisting of the remaining n &#8211; r eigenvalues of <img title="X^TX" src="http://latex.codecogs.com/gif.latex?X^TX" alt="" />, and the n x n matrix <img title="V=(V_1,V_2)" src="http://latex.codecogs.com/gif.latex?V=(V_1,V_2)" alt="" /> is orthogonal with <img title="V_1=(v_1,...v_r)" src="http://latex.codecogs.com/gif.latex?V_1=(v_1,...v_r)" alt="" /> consisting of the first  r columns of  <img title="V" src="http://latex.codecogs.com/gif.latex?V" alt="" />, and <img title="V_2=(v_{r+1},...v_n)" src="http://latex.codecogs.com/gif.latex?V_2=(v_{r+1},...v_n)" alt="" /> consisting of the remaining n &#8211; r columns of  <img title="V" src="http://latex.codecogs.com/gif.latex?V" alt="" />. Using this formulation we can write an approximation <img title="\widehat{X^TX}" src="http://latex.codecogs.com/gif.latex?\widehat{X^TX}" alt="" /> to <img title="X^TX" src="http://latex.codecogs.com/gif.latex?X^TX" alt="" /> using the r largest eigenvalues as</p>
<p><img title="\widehat{X^TX}=V_1 \Lambda_1 V_1^T" src="http://latex.codecogs.com/gif.latex?\widehat{X^TX}=V_1 \Lambda_1 V_1^T" alt="" />.</p>
<p>If we substitute this approximation into the normal equations 2, and do some simplification, we end up with the <em>principal components estimator</em></p>
<p><img title="\textrm{(3) }\widehat{\beta^{(r)}}=V_1 \Lambda_1^{-1} V_1^T X^T y" src="http://latex.codecogs.com/gif.latex?\textrm{(3) }\widehat{\beta^{(r)}}=V_1 \Lambda_1^{-1} V_1^T X^T y" alt="" />.</p>
<p>While we could use equation 3 directly, it is usually not the best way to perform principal components regression. The next article in this series will illustrate an algorithm for PCR and implement it using the NMath libraries.</p>
<p>-Steve</p>
]]></content:encoded>
			<wfw:commentRss>http://www.centerspace.net/blog/statistics/priniciple-components-regression-in-csharp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
