<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="new0">
  <name>Introduction to Splines</name>
  <metadata>
  <md:version>2.0</md:version>
  <md:created>2003/05/05</md:created>
  <md:revised>2003/05/05</md:revised>
  <md:authorlist>
      <md:author id="ixmocane">
      <md:firstname>Alena</md:firstname>
      <md:othername>Ixmocane</md:othername>
      <md:surname>Scott</md:surname>
      <md:email>oetting@stat.rice.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="ixmocane">
      <md:firstname>Alena</md:firstname>
      <md:othername>Ixmocane</md:othername>
      <md:surname>Scott</md:surname>
      <md:email>oetting@stat.rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="sujesh">
      <md:firstname>Sujesh</md:firstname>
      
      <md:surname>Sreedharan</md:surname>
      <md:email>sujesh@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="rebecca">
      <md:firstname>Rebecca</md:firstname>
      
      <md:surname>Willett</md:surname>
      <md:email>willett@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="jago">
      <md:firstname>Adan</md:firstname>
      
      <md:surname>Galvan</md:surname>
      <md:email>jago@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="charlet">
      <md:firstname>Charlet</md:firstname>
      
      <md:surname>Reedstrom</md:surname>
      <md:email>charlet@rice.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist>
    <md:keyword>B-splines</md:keyword>
    <md:keyword>interpolation</md:keyword>
    <md:keyword>piecewise polynomials</md:keyword>
    <md:keyword>smoothing</md:keyword>
    <md:keyword>Splines</md:keyword>
    <md:keyword>wavelets</md:keyword>
  </md:keywordlist>

  <md:abstract>Basic introduction to splines. Link to other modules.</md:abstract>
</metadata>



  <content>
    <para id="para1">
      Suppose that you are given a data set 
      <m:math>
	<m:apply>
	  <m:eq/>
	  <m:ci>D</m:ci>
	  <m:set>
	    <m:list>
	      <m:ci><m:msub>
		  <m:mi>x</m:mi>
		  <m:mn>1</m:mn>
		</m:msub></m:ci>
	      <m:ci><m:msub>
		  <m:mi>y</m:mi>
		  <m:mn>1</m:mn>
		</m:msub></m:ci>
	    </m:list>
	    <m:ci>…</m:ci>
	    <m:list>
	      <m:ci><m:msub>
		  <m:mi>x</m:mi>
		  <m:mi>m</m:mi>
		</m:msub></m:ci>
	      <m:ci><m:msub>
		  <m:mi>y</m:mi>
		  <m:mi>m</m:mi>
		</m:msub></m:ci>
	    </m:list>
	  </m:set>
	</m:apply>
      </m:math> in
      <m:math>
	<m:apply>
	  <m:power/>
	  <m:reals/>
	  <m:cn>2</m:cn>
	</m:apply>
      </m:math> and that you must find a <emphasis>smooth</emphasis>
      curve to these points.  There are many solutions to such a
      problem.  Most simply, you could "eyeball it" and draw in a
      curve that <emphasis>looks good</emphasis>; however, this
      solution is too subjective, not very precise.  You could just
      connect the dots, but this will probably not give a smooth line.
      You could fit a polynomial, but this fitted polynomial may
      <emphasis>wiggle</emphasis> too much.  Or you could use splines.
    </para>

    <para id="para2">
      <term>Splines</term> are piecewise polynomials with pieces
      smoothly connected together.  The joining points of the
      polynomial pieces are called <term>knots</term>.  Knots do not
      have to be evenly spaced.  When each segment of a spline is a
      polynomial of degree <m:math><m:ci>n</m:ci></m:math>, we say
      that the spline is a <term>spline of degree n</term>.
    </para>

    <para id="para3">
      We need to add some constraints to ensure smoothness.  For a
      spline of degree <m:math><m:ci>n</m:ci></m:math>, we require
      that the spline has continuous derivatives up to order 
      <m:math>
	<m:apply>
	  <m:minus/>
	  <m:ci>n</m:ci>
	  <m:cn>1</m:cn>
	</m:apply>
      </m:math> at each of the knots, i.e. a spline of degree
      <m:math><m:ci>n</m:ci></m:math> is in 
      <m:math>
	<m:apply>
	  <m:power/>
	  <m:ci>C</m:ci>
	  <m:apply>
	    <m:minus/>
	    <m:ci>n</m:ci>
	    <m:cn>1</m:cn>
	  </m:apply>
	</m:apply>
      </m:math>.
    </para>

    <para id="para4">
      Remember our problem of fitting a curve to the data?  There are
      generally two ways of approaching this problem:  interpolation
      and smoothing.
    </para>

    <para id="para5">
      We can fit a spline to <term>interpolate</term> the data; i.e. 
      <m:math>
	<m:apply>
	  <m:forall/>
	  <m:bvar><m:ci>i</m:ci></m:bvar>
	  <m:condition>
	    <m:apply>
	      <m:in/>
	      <m:ci>i</m:ci>
	      <m:set>
		<m:cn>1</m:cn>
		<m:ci>…</m:ci>
		<m:ci>m</m:ci>
	      </m:set>
	    </m:apply>
	  </m:condition>
	  <m:apply>
	    <m:eq/>
	    <m:apply>
	      <m:ci type="fn">f</m:ci>
	      <m:ci><m:msub>
		  <m:mi>x</m:mi>
		  <m:mi>i</m:mi>
		</m:msub></m:ci>
	    </m:apply>
	    <m:ci><m:msub>
		<m:mi>y</m:mi>
		<m:mi>i</m:mi>
	      </m:msub></m:ci>
	  </m:apply>
	</m:apply>
      </m:math>
    </para>

    <para id="para6">
      We can fit a <term>smoothing spline</term>: i.e. find
      <m:math><m:ci>f</m:ci></m:math> to minimize 

      <m:math display="block">
	<m:apply>
	  <m:plus/>
	  <m:apply>
	    <m:times/>
	    <m:apply>
	      <m:divide/>
	      <m:cn>1</m:cn>
	      <m:ci>n</m:ci>
	    </m:apply>
	    <m:apply>
	      <m:sum/>
	      <m:bvar><m:ci>i</m:ci></m:bvar>
	      <m:lowlimit>
		<m:cn>1</m:cn>
	      </m:lowlimit>
	      <m:uplimit>
		<m:ci>n</m:ci>
	      </m:uplimit>
	      <m:apply>
		<m:power/>
		<m:apply>
		  <m:minus/>
		  <m:ci><m:msub>
		      <m:mi>y</m:mi>
		      <m:mi>i</m:mi>
		    </m:msub></m:ci>
		  <m:apply>
		    <m:ci type="fn">f</m:ci>
		    <m:ci><m:msub>
			<m:mi>x</m:mi>
			<m:mi>i</m:mi>
		      </m:msub></m:ci>
		  </m:apply>
		</m:apply>
		<m:cn>2</m:cn>
	      </m:apply>
	    </m:apply>
	  </m:apply>
	  <m:apply>
	    <m:times/>
	    <m:ci>λ</m:ci>
	    <m:apply>
	      <m:int/>
	      <m:bvar><m:ci>u</m:ci></m:bvar>
	      <m:lowlimit>
		<m:ci><m:msub>
		    <m:mi>x</m:mi>
		    <m:mn>1</m:mn>
		  </m:msub></m:ci>
	      </m:lowlimit>
	      <m:uplimit>
		<m:ci><m:msub>
		    <m:mi>x</m:mi>
		    <m:mi>m</m:mi>
		  </m:msub></m:ci>
	      </m:uplimit>
	      <m:apply>
		<m:power/>
		<m:apply>
		  <m:times/>
		  <m:apply>
		    <m:power/>
		    <m:apply>
		      <m:ci type="fn">f</m:ci>
		      <m:ci>x</m:ci>
		    </m:apply>
		    <m:ci>m</m:ci>
		  </m:apply>
		  <m:ci>u</m:ci>
		</m:apply>
		<m:cn>2</m:cn>
	      </m:apply>
	    </m:apply>
	  </m:apply>
	</m:apply>
      </m:math>
      The first term measures the closeness of the fitted function to
      the data, while the second penalizes the curvature in the
      function.  <m:math><m:ci>λ</m:ci></m:math> established
      the trade off between the two.  For 
      <m:math>
	<m:apply>
	  <m:lt/>
	  <m:cn>0</m:cn>
	  <m:ci>λ</m:ci>
	  <m:infinity/>
	</m:apply>
      </m:math>, this constraint is minimized by a natural spline of
      degree 
      <m:math>
	<m:apply>
	  <m:plus/>
	  <m:ci>m</m:ci>
	  <m:cn>1</m:cn>
	</m:apply>
      </m:math> (
      <!-- if you would like to reference this, just put
<note type='footnote'>put reference here </note>-->
Schoenberg).  If 
      <m:math>
	<m:apply>
	  <m:eq/>
	  <m:ci>λ</m:ci>
	  <m:cn>0</m:cn>
	</m:apply>
      </m:math>, then <m:math><m:ci>f</m:ci></m:math> can be any
      function which interpolates the data.  If 
      <m:math>
	<m:apply>
	  <m:eq/>
	  <m:ci>λ</m:ci>
	  <m:infinity/>
	</m:apply>
      </m:math> and 
      <m:math>
	<m:apply>
	  <m:plus/>
	  <m:ci>m</m:ci>
	  <m:cn>2</m:cn>
	</m:apply>
      </m:math>, then this is the simple <term>least squares
      line</term> fit, since no second derivative can be tolerated.
    </para> 
  </content>
  
</document>
