[SciPy-User] an exercise in spline basis functions

josef.pktd at gmail.com josef.pktd at gmail.com
Fri Dec 9 13:32:39 EST 2011


On Fri, Dec 9, 2011 at 1:19 PM, Charles R Harris
<charlesr.harris at gmail.com> wrote:
>
>
> On Fri, Dec 9, 2011 at 10:53 AM, <josef.pktd at gmail.com> wrote:
>>
>> On Fri, Dec 9, 2011 at 12:00 PM, Charles R Harris
>> <charlesr.harris at gmail.com> wrote:
>> >
>> >
>> > On Thu, Dec 8, 2011 at 11:53 PM, <josef.pktd at gmail.com> wrote:
>> >>
>> >> Trying to understand spline basis functions, I always wanted to have
>> >> something simple to play with (that is not hidden in C or Fortran code
>> >> behind a lot of numerical sophistication).
>> >>
>> >> Here is a very simple example, coded straight from a beginner's
>> >> explanation. And it even works.
>> >>
>> >>
>> >>
>> >> https://picasaweb.google.com/106983885143680349926/Joepy#5684006069657083426
>> >>
>> >>
>> >> https://picasaweb.google.com/106983885143680349926/Joepy#5684006072774057874
>> >>
>> >> Motivation
>> >> If we have the basis functions directly, then we can just treat them
>> >> like regular regressors, e.g. for robust fitting, have more control
>> >> and information over variable selection than using scipy's splines, or
>> >> include them at the same time as other regressors.
>> >> (I'm thinking mainly of noisy data with a small number of
>> >> breaks/knots.)
>> >> (and because I was looking at what's left of the old stats.models
>> >> spline code, where most of it got removed because it was crashing C
>> >> code.)
>> >>
>> >> This was mainly to see if it works.
>> >> Is there better code to get the spline basis functions (and maybe the
>> >> derivatives, ...) available somewhere?
>> >>
>> >
>> > Looks like you are using uniform b-splines. You might want to look at
>> > the
>> > non-uniform variety also. If you want a complete set both require extra
>> > knot
>> > points outside the interior of the domain, but for the non-uniform
>> > variety
>> > the added knot points are just repeats of the end points.
>>
>> uniform (integer) knots was the easiest to get started. I will extend
>> it to non-uniform knots, but I wasn't sure what the support of each
>> basis function is. (But I just found it in
>>
>> http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/bspline-basis.html
>> )
based on this the non-uniform case was actually easy
https://picasaweb.google.com/106983885143680349926/Joepy#5684197321179952226

Josef
>>
>> Also the recursive function calls repeat some calculations and won't
>> be memory friendly.
>>
>> I was hoping someone already has done a more general version in Python.
>>
>> (BTW: I figured out how your multivariate Bernstein polynomials work
>> but didn't find an application for it yet.)
>>
>
> I'm going to extend that capability to the polynomials in numpy.
>
> Chuck
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list