def plot_segts_fit(ts, seg_ts, seg_fit = None, imshow=False, shape_symbol_list=None): plt.clf() # iterate each segment and plot for i in range(len(seg_ts)): seg = seg_ts[i] startpoint = seg[0] endpoint = seg[1] plt.plot(range(startpoint, endpoint), ts[startpoint:endpoint], linewidth=1, color='b') if seg_fit is None: plt.plot(range(startpoint, endpoint), fit_shape(ts[startpoint:endpoint])[0], linewidth=1, color='r') else: plt.plot(range(startpoint, endpoint), seg_fit[i], linewidth=1, color='r') # plot vertical line to divide segments, just draw the line in the middle of two segments for seg in seg_ts[:-1]: # seg[1] is the exclusive(!!!) end point seg_boundary = seg[1] - 0.5 plt.axvline(seg_boundary, linewidth=2, color='k') titlestr = "#Segments={k}".format(k=str(len(seg_ts))) # add the text of shape symbol as well if shape_symbol_list: ymin, ymax = plt.ylim() ypos = ymin + (ymax-ymin) * 0.9 for i in range(len(seg_ts)): seg = seg_ts[i] # text_ypos = (seg[0] + seg[1])/2.005 text_ypos = seg[0] + 1 plt.text(text_ypos, ypos, shape_symbol_list[i], fontsize=14, color='green') # display the word in the figure titlestr = titlestr + ", symbolic representation = \"" + "".join(shape_symbol_list) + "\"" plt.title(titlestr, fontsize=15) # TRICK: control if show the figure immediately if imshow: plt.show()
# for x1 in range(50, 2000, 100): original_list = np.arange(x0,x1,1) fit_x = original_list * original_list / 5.0 + 3*original_list print fit_x print fit_x print np.mean(fit_x) print np.std(fit_x, ddof=1) fit_xx = fit_x[::2] print fit_xx print np.mean(fit_xx) print np.std(fit_xx, ddof=1) fit_y, likelihood, shape_ind, shape_dir, std_y, mean_y, theta, alpha = fitting.fit_shape(fit_x) print fit_y, likelihood, shape_ind, shape_dir, alpha x_list = np.linspace(0,1,len(original_list)) print x_list mu = np.mean(np.power(x_list, 2)) std = np.std(np.power(x_list, 2), ddof=1) print mu, std # x_list = np.linspace(0,1,101) # print x_list # mu = np.mean(np.power(x_list, 2)) # std = np.std(np.power(x_list, 2), ddof=1) # print mu, std estimate_y = (((np.power((original_list - x0) / float(x1 - x0 - 1), 2) - mu) / std) * theta )* std_y + mean_y