Skip to content

Conversation

@pelson
Copy link
Member

@pelson pelson commented Jan 31, 2017

Surprisingly, this approach turns out to be ~4x faster than

cs = scipy.interpolate.CubicSpline(x, y)
ys = cs(xs)

Though the comparison is really apples vs oranges, as the algorithm implemented is different.

There is loads of room for improvement (and potentially even a better algorithm - this is the best I could find in a short search), but this is good enough to be useful already.

@pelson
Copy link
Member Author

pelson commented Jan 31, 2017

Hmmm. Seems to be suffering from over-fitting. May be the algorithm itself... 😞

array([  9.28148594e+04,   9.24955625e+04,   9.20495625e+04,
         9.14780625e+04,   9.07826562e+04,   8.99653906e+04,
         8.90285156e+04,   8.79746719e+04,   8.68069688e+04,
         8.55286875e+04,   8.41435469e+04,   8.26555156e+04,
         8.10689062e+04,   7.93884062e+04,   7.76193594e+04,
         7.57674844e+04,   7.38387656e+04,   7.18393594e+04,
         6.97743281e+04,   6.76511406e+04,   6.54768594e+04,
         6.32554688e+04,   6.09930781e+04,   5.86990938e+04,
         5.63856250e+04,   5.40647812e+04,   5.17401719e+04,
         4.94096406e+04,   4.70854688e+04,   4.47756719e+04,
         4.24794688e+04,   4.02053906e+04,   3.79599375e+04,
         3.57455156e+04,   3.35653594e+04,   3.14246094e+04,
         2.93292969e+04,   2.72865312e+04,   2.53046094e+04,
         2.33863750e+04,   2.15348125e+04,   1.97550469e+04,
         1.80409531e+04,   1.63841406e+04,   1.47842969e+04,
         1.32438281e+04,   1.17663438e+04,   1.03563906e+04,
         9.01753125e+03,   7.77323438e+03,   6.64531250e+03,
         5.62957812e+03,   4.71807812e+03,   3.90075000e+03,
         3.17331250e+03,   2.53498438e+03,   1.98378125e+03,
         1.51645312e+03,   1.12650000e+03,   8.08703125e+02,
         5.59656250e+02,   3.72718750e+02,   2.38671875e+02,
         1.46328125e+02,   8.44218750e+01,   4.56250000e+01,
         2.22500000e+01,   8.79687500e+00,   2.50000000e+00,
         5.15625000e-01])
array([ 301.09375 ,  300.53125 ,  300.015625,  299.4375  ,  298.765625,
        298.      ,  297.140625,  296.1875  ,  295.125   ,  293.953125,
        292.703125,  291.3125  ,  289.921875,  288.4375  ,  287.078125,
        285.5625  ,  284.078125,  282.453125,  280.578125,  279.15625 ,
        277.203125,  274.859375,  272.515625,  270.625   ,  269.5     ,
        268.96875 ,  266.875   ,  263.75    ,  262.6875  ,  259.71875 ,
        256.84375 ,  254.1875  ,  251.21875 ,  247.625   ,  243.890625,
        240.109375,  236.453125,  233.140625,  230.484375,  227.125   ,
        224.65625 ,  222.28125 ,  218.125   ,  213.25    ,  208.578125,
        203.90625 ,  199.796875,  195.921875,  192.28125 ,  195.171875,
        199.015625,  203.625   ,  207.703125,  210.421875,  214.25    ,
        218.203125,  223.078125,  227.640625,  229.859375,  232.703125,
        238.28125 ,  244.84375 ,  255.296875,  261.71875 ,  260.046875,
        271.171875,  243.546875,  208.515625,  170.84375 ,  223.03125 ])
%matplotlib notebook
import numpy as np
xs = np.linspace(0.1, 90000, 1000)[::-1]
print(press.data.shape)
ys_cubic = stratify.interpolate(xs, press.data[::3], temp.data[::3],
                          interpolation='cubic',
                          extrapolation='nan')

ys_linear = stratify.interpolate(xs, press.data[::3], temp.data[::3],
                          interpolation='linear',
                          extrapolation='nan')
plt.plot(ys_cubic, xs, label='cubic')
plt.plot(ys_linear, xs, label='linear')
plt.legend()
plt.gca().invert_yaxis()
plt.show()

download

I'm going to close this until future development is required...

@pelson pelson closed this Jan 31, 2017
@pelson pelson reopened this Feb 1, 2017
interp_and_extrap(shape=(500, 600, 100))
parser = argparse.ArgumentParser(description='Run an interpolation.')
parser.add_argument('--shape', default='500,600,100',
help='The shape of the array to interpolate. Comma separated (no spaces).')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E501 line too long (99 > 79 characters)


def test_inbetween(self):
x = np.linspace(0, 4, 5)
xs = [0.5, 1.25, 2.5, 3.75]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W291 trailing whitespace

@cpelley
Copy link

cpelley commented Oct 31, 2017

Hey @pelson just noticed this. Really cool, is this interest driven? I see you closed it.
If you decide to get this back up, I'll happily take a look for you.

@pelson
Copy link
Member Author

pelson commented Nov 1, 2017

I didn't delete the branch for a reason 😄 .

Seems like an obvious extension to stratify, and one I'd love to see in here. Currently nobody actually needs this though (linear is typically good enough, even with atmospheric pressure, it seems)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants