Skip to content Skip to sidebar Skip to footer

Fixing Inflexion Point Estimate Using Python

I am trying to find the inflexion points on a curve using python. The data for the curve is here: https://www.dropbox.com/s/rig8frgewde8i5n/fitted.txt?dl=0. Please note that the cu

Solution 1:

Any reason not to use uni-variate spline directly on the gradient?

from scipy.interpolate import UnivariateSpline

#raw datadata = np.genfromtxt('ww.txt')

plt.plot(np.gradient(data), '+')

spl = UnivariateSpline(np.arange(len(data)), np.gradient(data), k=5)
spl.set_smoothing_factor(1000)
plt.plot(spl(np.arange(len(data))), label='Smooth Fct 1e3')
spl.set_smoothing_factor(10000)
plt.plot(spl(np.arange(len(data))), label='Smooth Fct 1e4')
plt.legend(loc='lower left')

max_idx = np.argmax(spl(np.arange(len(data))))
plt.vlines(max_idx, -5, 9, linewidth=5, alpha=0.3)

enter image description here

Also we can solve for the maximum numerically:

In [122]:

import scipy.optimize as so
F = lambda x: -spl(x)
so.fmin(F, 102)
Optimization terminated successfully.
         Currentfunctionvalue: -3.339112
         Iterations: 20Function evaluations: 40Out[122]:
array([ 124.91303558])

Post a Comment for "Fixing Inflexion Point Estimate Using Python"