[SciPy-User] Splines in scipy.signal vs scipy.interpolation
Dag Sverre Seljebotn
dagss@student.matnat.uio...
Fri Feb 5 17:00:03 CST 2010
Tony S Yu wrote:
> On Jan 28, 2010, at 5:14 PM, Tony S Yu wrote:
>
>
>> On Jan 28, 2010, at 9:20 AM, denis wrote:
>>
>>
>>> On Jan 20, 11:56 pm, Tony S Yu <ton...@MIT.EDU> wrote:
>>>
>>>> I'm having trouble making splines from scipy.signal work with those in scipy.interpolation.
>>>>
>>>> Both packages have functions for creating (`signal.cspline1d`/`interpolate.splrep`) and evaluating (`signal.cspline1d_eval`/`interpolate.splev`) splines. There are, of course, huge differences between these functions, which is why I'm trying to get them to talk to each other.
>>>>
>>>> In particular, I'd like to create a smoothing spline using `cspline1d` (which allows easier smoothing) and evaluate using `splev` (which allows me to get derivatives of the spline).
>>>>
>>> Tony,
>>> bouncing between two murky packages doesn't sound as though it'll
>>> converge ...
>>>
>> Agreed. This was more of a naive attempt to try and get the results that I wanted.
>>
>>
>>> interpolate though has both smoothing and derivs --
>>> interpolator = interpolate.UnivariateSpline( x, y, k=3, s=s )
>>> # s=0 interpolates
>>> yy = interpolator( xx )
>>> y1 = interpolator( xx, 1 ) # deriv
>>>
>> You're right. When I originally read the docs for splrep, I had it in my head that the splines in scipy.interpolation didn't provide the "right" type of smoothing (don't ask me what "right" means---I have no idea). After taking some time to understand the interpolation module, I realize it does what I want. Thanks, Denis!
>>
>
> I think I spoke too soon. I believe what I need are called a smoothing splines, which is what scipy.signal provides; on the other I hand, scipy.interpolate creates what I think are called regression splines. The difference being that regression splines smooth the data using fewer knots than the number of observed data, while smoothing splines have knots which match the (abscissa) location of the original data. (I don't use splines often, so please correct me if I'm misinterpreting what I've read about the topic.)
>
> It's possible to specify knots or smoothing with interpolate.splrep, but when specifying both, the smoothing parameter is ignored and the knot placement (plus the error metric) determines the smoothness of the spline.
>
> I'm trying to re-implement some matlab code (which uses matlab's spaps function) for spline optimization, and the algorithm requires smoothing splines (as opposed to regression splines). Any suggestions?
>
I literally *just now* (the last hour) wrapped a small subset of the GSL
splines in Cython. If you're interested tell me and I'll make available
what I've got. Note that GSL is GPL.
http://www.gnu.org/software/gsl/manual/html_node/Interpolation.html
Dag Sverre
More information about the SciPy-User
mailing list