res_sp = SPIRIT(streams, alpha, [e_low, e_high], evalMetrics = 'T', reorthog = False, holdOffTime = holdOff) res_sp['Alg'] = 'SPIRIT with alpha = ' + str(valA) + ' and e_low = ' + str(valB) #plot_31(res_sp['RSRE'], res_sp['e_ratio'], res_sp['orthog_error'], # ['RSRE','Energy Ratio','Orthogonality\nError (dB)'], 'Time Steps', # 'Error Analysis of SPIRIT' ) pltSummary2(res_sp, streams, (e_low, e_high)) data = res_sp Title = 'SPIRIT with alpha = ' + str(valA) + ' and e_low = ' + str(valB) plot_4x1(streams, data['hidden'], data['e_ratio'], data['orthog_error'], ['Input Data','Hidden\nVariables', 'Energy Ratio', 'Orthogonality\nError (dB)'] , 'Time Steps', Title) #TODO # Why does changing the above for this plot_4x1(streams, data['hidden'], data['orthog_error'], data['subspace_error'], ['Input Data','Hidden\nVariables', 'Orthogonality\nError (dB)','Subspace\nError (dB)'], 'Time Steps', Title) # Have such a big effect????? # plot_4x1(streams, data['hidden'], data['orthog_error'], # data['subspace_error'], # ['Input Data','Hidden\nVariables', # 'Orthogonality\nError (dB)','Subspace\nError (dB)'] , 'Time Steps', Title)
for k in tracked_values: res[k] = np.vstack((res[k], st[k])) if st['anomaly'] == True: print 'Found Anomaly at t = {0}'.format(st['t']) res['anomalies'].append(st['t']) # increment time st['t'] += 1 res['Alg'] = 'My FRAHST' res['hidden'] = res['ht'] res['r_hist'] = res['r'] pltSummary2(res, data, (p['F_min'] + p['epsilon'], p['F_min'])) #res['rec_dsn'] = res['pred_dsn'] # only needed to test prediction error t stat method plot_4x1(data, res['ht'], res['rec_dsn'], res['t_stat'], ['']*4, ['']*4) plt.hlines(p['x_thresh'], 0, 1000) plt.hlines(-p['x_thresh'], 0, 1000) plt.ylim(-p['x_thresh']-5, p['x_thresh']+5) #N = 20 #a = res['recon_err_norm']**2 #b = np.zeros_like(a) #for i in range(1,len(a)): #b[i] = a[i] - a[i-1] #c = np.atleast_1d(b[::2]) #means = [0.0]*(len(c)/N)
valA) + ' and e_low = ' + str(valB) #plot_31(res_sp['RSRE'], res_sp['e_ratio'], res_sp['orthog_error'], # ['RSRE','Energy Ratio','Orthogonality\nError (dB)'], 'Time Steps', # 'Error Analysis of SPIRIT' ) pltSummary2(res_sp, streams, (e_low, e_high)) data = res_sp Title = 'SPIRIT with alpha = ' + str(valA) + ' and e_low = ' + str( valB) plot_4x1(streams, data['hidden'], data['e_ratio'], data['orthog_error'], [ 'Input Data', 'Hidden\nVariables', 'Energy Ratio', 'Orthogonality\nError (dB)' ], 'Time Steps', Title) #TODO # Why does changing the above for this plot_4x1(streams, data['hidden'], data['orthog_error'], data['subspace_error'], [ 'Input Data', 'Hidden\nVariables', 'Orthogonality\nError (dB)', 'Subspace\nError (dB)' ], 'Time Steps', Title) # Have such a big effect????? # plot_4x1(streams, data['hidden'], data['orthog_error'], # data['subspace_error'],
from pylab import * from plot_utils import plot_4x1 # Must Define # data2plot # EH # EL ylims = (4, 0.92, 1.0) # Title = r'$SNR = -9$' plot_4x1(streams, results[0]['data']['hidden'], results[0]['data']['r_hist'], results[0]['data']['e_ratio'], ['Input Data', 'Hidden\nVariables', 'Rank', 'Energy\nRatio'], 'Time steps', ylims=ylims) fig = gcf() # dashed lines fig.axes[0].axvline(x=300, ls='--', c='k') fig.axes[0].axvline(x=600, ls='--', c='k') fig.axes[1].axvline(x=300, ls='--', c='k') fig.axes[1].axvline(x=600, ls='--', c='k') fig.axes[2].axvline(x=300, ls='--', c='k') fig.axes[2].axvline(x=600, ls='--', c='k') fig.axes[3].axvline(x=300, ls='--', c='k') fig.axes[3].axvline(x=600, ls='--', c='k')
def plot_res(self, var, xname="time steps", ynames=None, title=None, hline=1, anom=1): if ynames is None: ynames = [""] * 4 if title is None: title = self.p["version"] # Preprocessing if "exp_ht" in var: res["exp_ht"][res["exp_ht"] == 0.0] = np.nan if "S" in self.A_version: thresh = self.p["t_thresh"] elif "T" in self.A_version: thresh = self.p["x_thresh"] elif "eng" in self.A_version: thresh = (self.p["e_high"] - self.p["e_low"]) / 2 num_plots = len(var) for i, v in enumerate(var): if type(v) == str: var[i] = getattr(self, "res")[v] if num_plots == 1: plt.figure() plt.plot(var[0]) plt.title(title) if anom == 1: for x in self.res["anomalies"]: plt.axvline(x, ymin=0.25, color="r") elif num_plots == 2: plot_2x1(var[0], var[1], ynames[:2], xname, main_title=title) if hline == 1: plt.hlines(-thresh, 0, self.res["ht"].shape[0], linestyles="dashed") plt.hlines(+thresh, 0, self.res["ht"].shape[0], linestyles="dashed") plt.ylim(-2 * thresh, 2 * thresh) if anom == 1: f = plt.gcf() for ax in f.axes[:-1]: for x in self.res["anomalies"]: ax.axvline(x, ymin=0.25, color="r") elif num_plots == 3: plot_3x1(var[0], var[1], var[2], ynames[:3], xname, main_title=title) if hline == 1: plt.hlines(-thresh, 0, self.res["ht"].shape[0], linestyles="dashed") plt.hlines(+thresh, 0, self.res["ht"].shape[0], linestyles="dashed") plt.ylim(-2 * thresh, 2 * thresh) if anom == 1: f = plt.gcf() for ax in f.axes[:-1]: for x in self.res["anomalies"]: ax.axvline(x, ymin=0.25, color="r") elif num_plots == 4: plot_4x1(var[0], var[1], var[2], var[3], ynames[:4], xname, main_title=title) plt.title(title) if hline == 1: plt.hlines(-thresh, 0, self.res["ht"].shape[0], linestyles="dashed") plt.hlines(+thresh, 0, self.res["ht"].shape[0], linestyles="dashed") plt.ylim(-2 * thresh, 2 * thresh) if anom == 1: f = plt.gcf() for ax in f.axes[:-1]: for x in self.res["anomalies"]: ax.axvline(x, ymin=0.25, color="r")
for k in tracked_values: res[k] = np.vstack((res[k], st[k])) if st['anomaly'] == True: print 'Found Anomaly at t = {0}'.format(st['t']) res['anomalies'].append(st['t']) # increment time st['t'] += 1 res['Alg'] = 'My FRAHST' res['hidden'] = res['ht'] res['r_hist'] = res['r'] pltSummary2(res, data, (p['F_min'] + p['epsilon'], p['F_min'])) #res['rec_dsn'] = res['pred_dsn'] # only needed to test prediction error t stat method plot_4x1(data, res['ht'], res['rec_dsn'], res['t_stat'], [''] * 4, [''] * 4) plt.hlines(p['x_thresh'], 0, 1000) plt.hlines(-p['x_thresh'], 0, 1000) plt.ylim(-p['x_thresh'] - 5, p['x_thresh'] + 5) #N = 20 #a = res['recon_err_norm']**2 #b = np.zeros_like(a) #for i in range(1,len(a)): #b[i] = a[i] - a[i-1] #c = np.atleast_1d(b[::2]) #means = [0.0]*(len(c)/N)
def plot_res(self, var, xname = 'Time Steps', ynames = None, title = None, hline= 1, anom = 1): """Plots each of the elements given in var. var = list of variables. Maximum = 4. if string, will look for them in self.res structure hline = whether to plot threshold values on final plot. anom = whether to plot anomalous time ticks. """ if ynames is None: ynames = ['']*4 if title is None: title = (self.p['version']) if 'SRE' in self.A_version: thresh = self.p['t_thresh'] num_plots = len(var) for i, v in enumerate(var): if type(v) == str : var[i] = getattr(self, 'res')[v] if num_plots == 1: plt.figure() plt.plot(var[0]) plt.title(title) if anom == 1: for x in self.res['anomalies']: plt.axvline(x, ymin=0.9, color='r') elif num_plots == 2: plot_2x1(var[0], var[1], ynames[:2], xname, main_title = title) if hline == 1: plt.hlines(-thresh, 0, self.res['ht'].shape[0], linestyles = 'dashed') plt.hlines(+thresh, 0, self.res['ht'].shape[0], linestyles = 'dashed') plt.ylim(-3*thresh,3*thresh) if anom == 1: f = plt.gcf() for ax in f.axes[:-1]: for x in self.res['anomalies']: ax.axvline(x, ymin=0.9, color='r') elif num_plots == 3: plot_3x1(var[0], var[1], var[2], ynames[:3] , xname, main_title = title) if hline == 1: plt.hlines(-thresh, 0, self.res['ht'].shape[0], linestyles = 'dashed') plt.hlines(+thresh, 0, self.res['ht'].shape[0], linestyles = 'dashed') plt.ylim(-3*thresh,3*thresh) if anom == 1: f = plt.gcf() for ax in f.axes[:-1]: for x in self.res['anomalies']: ax.axvline(x, ymin=0.9, color='r') elif num_plots == 4: plot_4x1(var[0], var[1], var[2], var[3], ynames[:4], xname, main_title = title) plt.title(title) if hline == 1: plt.hlines(-thresh, 0, self.res['ht'].shape[0], linestyles = 'dashed') plt.hlines(+thresh, 0, self.res['ht'].shape[0], linestyles = 'dashed') plt.ylim(-3*thresh,3*thresh) if anom == 1: f = plt.gcf() for ax in f.axes[:-1]: for x in self.res['anomalies']: ax.axvline(x, ymin=0.9, color='r') plt.draw()
from pylab import * from plot_utils import plot_4x1 # Must Define # data2plot # EH # EL ylims = (4,0.92,1.0) # Title = r'$SNR = -9$' plot_4x1(streams, results[0]['data']['hidden'], results[0]['data']['r_hist'], results[0]['data']['e_ratio'], ['Input Data', 'Hidden\nVariables', 'Rank', 'Energy\nRatio'], 'Time steps', ylims = ylims) fig = gcf() # dashed lines fig.axes[0].axvline(x = 300, ls = '--', c = 'k') fig.axes[0].axvline(x = 600, ls = '--', c = 'k') fig.axes[1].axvline(x = 300, ls = '--', c = 'k') fig.axes[1].axvline(x = 600, ls = '--', c = 'k') fig.axes[2].axvline(x = 300, ls = '--', c = 'k') fig.axes[2].axvline(x = 600, ls = '--', c = 'k') fig.axes[3].axvline(x = 300, ls = '--', c = 'k') fig.axes[3].axvline(x = 600, ls = '--', c = 'k') fig.axes[3].axhline(y=EH, ls = '--') fig.axes[3].axhline(y=EL, ls = '--')