def PerformanceProfile(A, th_max, file_name, alg_legend, n_intervals=100, markevery=1): """ Modified from https://github.com/StevenElsworth/PerformanceProfiles """ m, n = A.shape minA = np.min(A, 1) fig, ax = myfigure(nrows=1, ncols=1, fig_ratio=0.71, fig_scale=1.6) # Use definition at some points theta n_intervals = 100 p_step = 1 # increase to make plot look smoother. theta = np.linspace(1, th_max, num=n_intervals) T = np.zeros([n_intervals, 1]) linestyle = ['-', '--', '-.', ':'] marker = ['o', '^', '*', 'x', 'v', '<', 'h', 'p'] for j in np.arange(0, n): for k in np.arange(0, n_intervals): T[k] = np.sum(A[:, j] <= theta[k] * minA) / m plt.plot(theta, T, linestyle=linestyle[j % 4], marker=marker[j % 8], markevery=markevery) plt.xlim([1, th_max]) plt.ylim([0, 1.01]) plt.xlabel(r'$\theta$') plt.ylabel(r'$p$') plt.grid() if not alg_legend == None: plt.legend(alg_legend, loc=4) plt.tight_layout() plt.savefig(file_name, facecolor='w', edgecolor='w')
ABBA_patches = abba.get_patches(ts, pieces, string, centers) # Construct mean of each patch d = {} for key in ABBA_patches: d[key] = list(np.mean(ABBA_patches[key], axis=0)) # Stitch patches together patched_ts = np.array([ts[0]]) for letter in string: patch = d[letter] patch -= patch[0] - patched_ts[-1] # shift vertically patched_ts = np.hstack((patched_ts, patch[1:])) # Plot SAX representation fig, (ax1, ax2) = myfigure(nrows=2, ncols=1, fig_ratio=0.71, fig_scale=1) ax1.plot(ts, color='k', label='original time series') ax1.plot(APLA, '--', label='reconstruction after compression') ax1.plot(reconstructed_ts, ':', label='reconstruction after digitization') ax1.legend() print('Symbolic representation:', string) ax2.plot(ts[0:250], color='k', label='original time series') next(ax2._get_lines.prop_cycler) ax2.plot(reconstructed_ts[0:250], ':', label='standard reconstruction') ax2.plot(patched_ts[0:250], '-.', label='patched reconstruction') ax2.legend() plt.savefig('patches.pdf', dpi=300, transparent=True)
np.zeros([32, 1]), np.ones([6, 1]), np.zeros([27, 1]) ]) # Normalise t11 = t11 - np.mean(t11) t11 /= np.std(t11, ddof=1) t12 = t12 - np.mean(t12) t12 /= np.std(t12, ddof=1) t21 = t21 - np.mean(t21) t21 /= np.std(t21, ddof=1) t22 = t22 - np.mean(t22) t22 /= np.std(t22, ddof=1) fig, ax = myfigure(nrows=1, ncols=1, fig_ratio=0.5, fig_scale=1.7) ax.axis([0, 100, -1, 3.5]) ax.plot(t21) ax.plot(t22) ax.plot([]) ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) plt.tight_layout() plt.savefig('shift_in_time.pdf') fig, ax = myfigure(nrows=1, ncols=1, fig_ratio=0.5, fig_scale=1.7) ax.axis([0, 100, -1, 3.5]) ax.plot(t11) ax.plot(t12) ax.plot([]) ax.spines['top'].set_visible(False)
abba = ABBA(tol=tolerance, min_k=10, max_k=30) string, centres = abba.transform(ts) ts_new = np.array(abba.inverse_transform(string, centres, ts[0])) pieces = abba.compress(ts) ts_con = abba.inverse_compress(ts[0], pieces) print('np.linalg.norm(ts_con-ts) =', np.linalg.norm(ts_con-ts)) print('should be bounded by = ', np.sqrt(len(ts))*tolerance) print('dtw(ts_con - ts_new) = ', dtw(ts_con, ts_new)) print('dtw(ts - ts_new) = ', dtw(ts, ts_new)) # Plot ABBA representation fig, ax = myfigure(nrows=1, ncols=1, fig_ratio=0.71, fig_scale=1.6) plt.plot(ts, color='k') plt.plot(ts_con, color='#D95319', linestyle='--') plt.plot(ts_new, color='#0072BD', linestyle=':') plt.xlim([1, 7200]) plt.ylim([-2.3, 2.3]) plt.legend(['original time series', 'reconstruction after compression', 'reconstruction after digitization'], loc=9) plt.savefig('decoke_'+str(abba.tol)+'_scl'+str(abba.scl)+'.pdf') # Construct list of vertical errors v_error = np.zeros((len(string), 1)) for ind, letter in enumerate(string): pc = centres[ord(letter)-97,:] v_error[ind] = pieces[ind][1]-pc[1]
import SAX from ABBA import ABBA import matplotlib.pyplot as plt np.random.seed(0) from util import myfigure # Construct noisy sine wave with linear trend linspace = np.linspace(0, 16 * 2 * np.pi, 500) ts = np.sin(linspace) ts += 0.2 * np.random.randn(500) ts += np.linspace(0, 4, 500) # Plot SAX representation fig, (ax1, ax2, ax3, ax4) = myfigure(nrows=4, ncols=1, fig_ratio=0.71, fig_scale=1) plt.subplots_adjust(left=0.125, bottom=None, right=0.95, top=None, wspace=None, hspace=None) ts1 = ts ts1 -= np.mean(ts1) ts1 /= np.std(ts1) reduced_ts = SAX.compress(ts1, width=4) symbolic_ts = SAX.digitize(reduced_ts, number_of_symbols=9) print('SAX representation length:', len(symbolic_ts)) reduced_ts = SAX.reverse_digitize(symbolic_ts, number_of_symbols=9) ts_SAX = SAX.reconstruct(reduced_ts, width=4)