[SciPy-User] an exercise in spline basis functions

josef.pktd at gmail.com josef.pktd at gmail.com
Fri Dec 9 12:53:45 EST 2011


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
)

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.)

Thanks,

Josef

>
> 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