patrick-kidger / torchcubicspline

Interpolating natural cubic splines. Includes batching, GPU support, support for missing values, evaluating derivatives of the spline, and backpropagation.
Apache License 2.0
198 stars 18 forks source link

Differentiation with respect to coefficients #2

Closed apisarek closed 3 years ago

apisarek commented 3 years ago

Hi!

I would like to ask whether it's possible and what would be the best approach to use your implementation to differentiate with respect to coefficients and/or coordinates of interpolated points.

from torchcubicspline import(natural_cubic_spline_coeffs, 
                             NaturalCubicSpline)

length, channels = 7, 3
t = torch.linspace(0, 1, length)
x = torch.rand(length, channels)
coeffs = natural_cubic_spline_coeffs(t, x)
spline = NaturalCubicSpline(coeffs)
point = torch.tensor(0.4)
out = spline.evaluate(point)

Looking at the provided simple example I would like to backpropagate from out to x - is it possible?

patrick-kidger commented 3 years ago

Yup, I think so - if I've written this correctly then everything should be differentiable. :)

Gravifer commented 3 years ago

I think this thread should be closed by now? Your work is for now by far the best solution for this problem! ;)

patrick-kidger commented 3 years ago

Yeah, it probably can. And thanks!