Linear interpolation as a Theano Op?

I want to transform one variable into another within my model, but the transformation function is not analytic. Linear interpolation based on a lookup table will do as an approximation. I can create such a function very easily in scipy,

f = scipy.interpolate.interp1d(x, y) 

where x and y are from the lookup table. I guess I can wrap f inside a Theano Op, but I also need the gradient for NUTS to sample, right? Is there an easy way to calculate this?

There is a SplineWrapper(theano.Op) which creates a theano operation from scipy.interpolate.UnivariateSpline:


Great, thanks. I’ll try it out.

do you have some example for how to use this SplineWrapper(theano.Op)? thanks~