Reputation: 103
I am trying to calculate the smoothness of cubic splines generated using scipy.interpolate.CubicSpline
. The way I want to calculate the smoothness is by taking the integral of the square of the second derivative:
The SciPy CubicSpline
accepts the integrate
and derivative
methods, but they are not enough for the calculation above. What I can easily do is .derivative(2).integrate(0,20)**2
, but this is not quite what I need (I am taking the square after the integral is being calculated).
Is there an easy way to perform the calculation above? Am I missing something stupid?
Upvotes: 0
Views: 165
Reputation: 26090
You're almost there: you need to cook up a callable for the second derivative squared:
>>> spl = CubicSpline(x, y)
>>> der = spl.derivative(2)
>>> from scipy.integrate import quad
>>> quad(lambda x: der(x)**2, 0, 1) # <--- here
Upvotes: 1