def calculate_breaking_points(quant_list):
MAX_ERROR = 5
RANGE = 5
CENTER = 50
BRAKE_POINTS = dict()
# right to left window
for x_iter in range(100, CENTER, -1):
x_proj = range(x_iter - RANGE, x_iter)
# pylab.plot(x_proj, quant[x-RANGE:x], 'k',alpha=0.5)
y_subset = quant_list[x_iter - RANGE:x_iter]
slope, intercept, r_value, p_value, std_err = stats.linregress(x_proj, y_subset)
g, l = calculate_error(slope, intercept, x_proj, y_subset)
# print x-RANGE,x, slope, intercept, y[0], f(x, slope, intercept), l,r
if l > MAX_ERROR:
BRAKE_POINTS[x_iter - RANGE / 2] = {"error":l, "slope":slope, "offset":intercept}
# left to right window
for x_iter in range(0, CENTER, 1):
x_proj = range(x_iter, x_iter + RANGE)
# pylab.plot(x_proj, quant_list[x_iter:x_iter + RANGE], 'k', alpha=0.3)
y_subset = quant_list[x_iter:x_iter + RANGE]
slope, intercept, r_value, p_value, std_err = stats.linregress(x_proj, y_subset)
g, l = calculate_error(slope, intercept, x_proj, y_subset)
# print x,x+RANGE, slope, intercept, y[0], f(x, slope, intercept), l,r
if l > MAX_ERROR:
if ((x_iter - RANGE + x_iter) / 2) not in BRAKE_POINTS.keys():
BRAKE_POINTS[x_iter + (RANGE / 2)] = {"error":l, "slope":slope, "offset":intercept}
# pylab.plot([x_iter, x_iter + RANGE, ], [ f(x_iter, slope, intercept), f(x_iter + RANGE, slope, intercept)], "b", alpha=0.3)
return BRAKE_POINTS
评论列表
文章目录