Please find the attached graph. I need to find the points "a" and "b". Kindly suggest any methods in python.
Graph is plotted by obtaining run times, which are observed as below:
x = ([1000, 2000, 3000, 4000, 5000, 6000,7000, 8000, 9000])
and
y = ([2314,802,519,417,358,318,302,284,280])
Need to find out "a" and "b" points so that i can use them individually for other tasks
Full code:
def piecewise_linear(x, x0, y0, k1, k2):
return np.piecewise(x, [x < x0], [lambda x:k1*x + y0-k1*x0, lambda x:k2*x + y0-k2*x0])
perr_min = np.inf
p_best = None
for n in range(100):
k = np.random.rand(10)*20
p , e = optimize.curve_fit(piecewise_linear, x, y)
perr = np.sum(np.abs(y-piecewise_linear(x, *p)))
if(perr < perr_min):
print "success"
perr_min = perr
p_best = p
xd = np.linspace(min(x), max(x), 100)
plt.figure()
plt.plot(x, y, "bo")
y_out = piecewise_linear(xd, *p_best)
plt.plot(xd, y_out)
plt.ylabel('Number of KeyFrames')
plt.xlabel('Threshold Values')
plt.show()
I don't exactly understand your question. Do you want code to extract relevant data points from that graph image using some computer vision or do you just want the coordinates of the data points using the defined
x
andy
lists? If latter is the case, you can do something like:This prints
(2000, 802)
. Is there anything that defines the green line? Otherwise, here I've set a ratio threshold to add only points which change the slope by a 'large enough' (in this case, by a factor of 5) amount.Also, the parenthesis in your
x
andy
initialisations are redundant. Just use square brackets.