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: https://github.com/pymc-devs/pymc3/blob/fb156af4cf32fd1b2af6a073a2cac9707c933152/pymc3/distributions/dist_math.py#L251

2 Likes

Great, thanks. I’ll try it out.

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