def singleShiftRerun(parameter_string): params = parameter_string.split(', ') # Data Sets baseLine = 0.0 num_streams = [int(params[0].split()[-1])] # n SNRs = [int(params[1].split()[-1])] # snr anomaly_lengths = [int(params[2].split()[-1])] # l anomaly_magnitudes = [int(params[3].split()[-1])] # m initial_conditions = 20 # i # Algorithm Parameters thresholds = params[4].split()[-1].split(',') e_highs = [float(thresholds[1][0:-1])] # eh e_lows = [float(thresholds[0][1:])] # el alphas = [float(params[5].split()[-1])] # a holdOffs = [int(params[6].split()[-1])] # h # Algorithm flags run_spirit = 0 run_frahst = 1 run_frahst_pedro = 0 #=============================================================================== # Initialise Data sets #========-======================================================================= # For Profiling start = time.time() for n in num_streams: for snr in SNRs: for l in anomaly_lengths: for m in anomaly_magnitudes: A = 0 for i in range(initial_conditions): # Seed random number generator np.random.seed(i) # Two ts that have anomalous shift s0 = Tseries(0) s1 = Tseries(0) s0.makeSeries([1,3,1],[100, l, 200 - l],[baseLine, baseLine, baseLine + m], gradient = float(m)/float(l), noise_type ='none') s1.makeSeries([1,4,1],[200, l, 100 - l],[baseLine, baseLine, baseLine - m], gradient = float(m)/float(l), noise_type ='none') # The rest of the ts for k in range(2, n) : name = 's'+ str(k) vars()[name] = Tseries(0) vars()[name].makeSeries([1], [300], [baseLine], noise_type ='none') # Concat into one matrix S = scipy.c_[s0] for k in range(1, n) : S = scipy.c_[ S, vars()['s'+ str(k)] ] # Concatonate to 3d array, timesteps x streams x initial condition if type(A) == int: A = S else: A = np.dstack((A, S)) # Calculate the noise Ps = np.sum(A[:,:,0] ** 2) Pn = Ps / (10. ** (snr/10.)) scale = Pn / (n * 300.) noise = np.random.randn(A.shape[0], A.shape[1], A.shape[2]) * np.sqrt(scale) A = A + noise #=============================================================================== # Ground Truths #=============================================================================== # # time step | length ground_truths = np.array([[100, l], [200, l]]) #============================================================================== # Run Algorithm #============================================================================== alg_count = 1 for eh in e_highs : for el in e_lows : for a in alphas : for h in holdOffs : print 'Running Algorithm(s) with:\nE_Thresh = (' + str(el) + ',' + str(eh) + ')\n' + \ 'alpha = ' + str(a) + '\nHoldOff = ' + str(h) SPIRIT_metricList = [] FRAHST_metricList = [] PEDRO_FRAHST_metricList = [] for i in range(initial_conditions): # Load Data streams = A[:,:,i] if run_spirit == 1: # SPIRIT res_sp = SPIRIT(streams, a, [el, eh], evalMetrics = 'F', reorthog = False, holdOffTime = h) res_sp['Alg'] = 'SPIRIT: alpha = ' + str(a) + \ ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' pltSummary2(res_sp, streams, (el, eh)) SPIRIT_metricList.append(analysis(res_sp, ground_truths, 300 )) # data = res_sp # Title = 'SPIRIT alpha = ' + str(a) + ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' # # plot_4x1(streams, data['hidden'], data['e_ratio'], data['orthog_error'], # ['Input Data','Hidden\nVariables', # 'Energy Ratio', 'Orthogonality\nError (dB)'] , 'Time Steps', Title) # plot_4x1(streams, data['hidden'], data['orthog_error'], data['subspace_error'], # ['Input Data','Hidden\nVariables', 'Orthogonality\nError (dB)','Subspace\nError (dB)'], # 'Time Steps', Title) # if run_frahst == 1: # My version of Frahst res_fr = FRAHST_V3_1(streams, alpha=a, e_low=el, e_high=eh, holdOffTime=h, fix_init_Q = 1, r = 1, evalMetrics = 'F') res_fr['Alg'] = 'MyFrahst: alpha = ' + str(a) + ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' FRAHST_metricList.append(analysis(res_fr, ground_truths, 300 )) pltSummary2(res_fr, streams, (el, eh)) # # data = res_fr # Title = 'My Frahst with alpha = ' + str(a) + ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' # plot_4x1(streams, data['hidden'], data['orthog_error'], data['subspace_error'], # ['Input Data','Hidden\nVariables', 'Orthogonality\nError (dB)','Subspace\nError (dB)'], # 'Time Steps', Title) if run_frahst_pedro == 1: # Pedros version of Frahst res_frped = frahst_pedro(streams, alpha=a, e_low=el, e_high=eh, holdOffTime=h, r = 1, evalMetrics = 'F') res_frped['Alg'] = 'Pedros Frahst: alpha = ' + str(a) + \ ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' PEDRO_FRAHST_metricList.append(analysis(res_frped, ground_truths, 300 )) pltSummary2(res_frped, streams, (el, eh)) # # data = res_frped # Title = 'Pedros Frahst: alpha = ' + str(a) + \ # ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' # # plot_4x1(streams, data['hidden'], data['orthog_error'], data['subspace_error'], # ['Input Data','Hidden\nVariables', 'Orthogonality\nError (dB)','Subspace\nError (dB)'], # 'Time Steps', Title) finish = time.time() - start print 'Runtime = ' + str(finish) + 'seconds\n' print 'In H:M:S = ' + GetInHMS(finish)
# -*- coding: utf-8 -*- """ Created on Sat Mar 05 23:19:11 2011 THIS IS THE VERSION TO RUN ON MAC, NOT WINDOWS @author: musselle """ from numpy import eye, zeros, dot, sqrt, log10, trace, arccos, nan, arange, ones import numpy as np import scipy as sp import numpy.random as npr from numpy.linalg import qr, eig, norm, solve from matplotlib.pyplot import plot, figure, title, step, ylim from artSigs import genCosSignals_no_rand , genCosSignals import scipy.io as sio from utils import analysis, QRsolveA, pltSummary2 from PedrosFrahst import frahst_pedro_original from Frahst_v3_1 import FRAHST_V3_1 from Frahst_v3_3 import FRAHST_V3_3 from Frahst_v3_4 import FRAHST_V3_4 from Frahst_v4_0 import FRAHST_V4_0 from load_syn_ping_data import load_n_store from QR_eig_solve import QRsolve_eigV from create_Abilene_links_data import create_abilene_links_data from MAfunctions import MA_over_window from ControlCharts import Tseries def FRAHST_V6_3(data, r=1, alpha=0.96, L = 1, holdOffTime=0, evalMetrics = 'F', EW_mean_alpha = 0.1, EWMA_filter_alpha = 0.3, residual_thresh = 0.1, F_min = 0.9, epsilon = 0.05, static_r = 0, r_upper_bound = None,
v3_4 = 0 v3_3 = 0 v3_1 = 0 pedro = 0 if v6_4: '''EWMA detection with F_min-epsilon thresholding''' res_v6_4 = FRAHST_V6_4(data, r=1, alpha=alpha, L = L, holdOffTime=holdOFF, evalMetrics = 'F', EW_mean_alpha = EW_mean_alpha, EWMA_filter_alpha = EWMA_filter_alpha, residual_thresh = residual_thresh, F_min = F_min, epsilon = epsilon, static_r = 0, r_upper_bound = None, fix_init_Q = 1, ignoreUp2 = ignoreUp2) res_v6_4['Alg'] = 'My FRAUST V6.4 Eigen-Adaptive' pltSummary2(res_v6_4, data, (F_min + epsilon, F_min)) ylim(F_min - 0.05 , 1.02) if v6_4_fix: '''EWMA detection with F_min-epsilon thresholding''' res_v6_4f = FRAHST_V6_4(data, r=R, alpha=alpha, L = L, holdOffTime=holdOFF, evalMetrics = 'F', EW_mean_alpha = EW_mean_alpha, EWMA_filter_alpha = EWMA_filter_alpha, residual_thresh = residual_thresh, F_min = F_min, epsilon = epsilon, static_r = 1, r_upper_bound = None, fix_init_Q = 1, ignoreUp2 = ignoreUp2) res_v6_4f['Alg'] = 'My FRAUST V6.4 Fixed' pltSummary2(res_v6_4f, data, (F_min + epsilon, F_min)) ylim(F_min - 0.05 , 1.02)
if run_spirit == 1: # SPIRIT res_sp = SPIRIT( streams, a, [el, eh], evalMetrics="F", reorthog=False, holdOffTime=h ) res_sp["Alg"] = ( "SPIRIT: alpha = " + str(a) + " ,E_Thresh = (" + str(el) + "," + str(eh) + ")" ) pltSummary2(res_sp, streams, (el, eh)) SPIRIT_RawResults.append(res_sp) SPIRIT_metricList.append(analysis(res_sp, ground_truths, 3 * interval_length)) # data = res_sp # Title = 'SPIRIT alpha = ' + str(a) + ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' # # plot_4x1(streams, data['hidden'], data['e_ratio'], data['orthog_error'], # ['Input Data','Hidden\nVariables', # 'Energy Ratio', 'Orthogonality\nError (dB)'] , 'Time Steps', Title) # plot_4x1(streams, data['hidden'], data['orthog_error'], data['subspace_error'], # ['Input Data','Hidden\nVariables', 'Orthogonality\nError (dB)','Subspace\nError (dB)'], # 'Time Steps', Title)
alpha=alpha, L=L, holdOffTime=holdOFF, evalMetrics='F', EW_mean_alpha=EW_mean_alpha, EWMA_filter_alpha=EWMA_filter_alpha, residual_thresh=residual_thresh, F_min=F_min, epsilon=epsilon, static_r=0, r_upper_bound=None, fix_init_Q=1, ignoreUp2=ignoreUp2) res_v6_4['Alg'] = 'My FRAUST V6.4 Eigen-Adaptive' pltSummary2(res_v6_4, data, (F_min + epsilon, F_min)) ylim(F_min - 0.05, 1.02) if v6_4_fix: '''EWMA detection with F_min-epsilon thresholding''' res_v6_4f = FRAHST_V6_4(data, r=R, alpha=alpha, L=L, holdOffTime=holdOFF, evalMetrics='F', EW_mean_alpha=EW_mean_alpha, EWMA_filter_alpha=EWMA_filter_alpha, residual_thresh=residual_thresh, F_min=F_min, epsilon=epsilon,
# Use Passive Normal #data, ant, time = prime_data('SYN', 'PN', useCol = range(2,8), use2time = 7000) """PARAMETERS""" e_high = 0.98 e_low = 0.85 alpha = 0.9 holdOFF = 0 '''My latest version''' res_new = FRAHST_V3_3(data, alpha=alpha, e_low=e_low, e_high=e_high, holdOffTime=holdOFF, fix_init_Q = 1, r = 1, evalMetrics = 'F') res_new['Alg'] = 'My Latest Implimentation of FRAUST ' pltSummary2(res_new, data, (e_high, e_low)) '''My older version''' res_old = FRAHST_V3_1(data, alpha=alpha, e_low=e_low, e_high=e_high, holdOffTime=holdOFF, fix_init_Q = 1, r = 1, evalMetrics = 'F') res_old['Alg'] = 'My Older Implimentation of FRAUST ' pltSummary2(res_old, data, (e_high, e_low)) '''Pedros Version''' res_ped = frahst_pedro_original(data, r=1, alpha=alpha, e_low=e_low, e_high=e_high, holdOffTime=holdOFF, evalMetrics='F') res_ped['Alg'] = 'Pedros Original Implimentation of FRAUST' pltSummary2(res_ped, data, (e_high, e_low))
if run_spirit == 1: # SPIRIT 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'],
streams = streams - Maved_data_MAwindow if run_spirit == 1: # SPIRIT res_sp = SPIRIT(streams, a, [el, eh], evalMetrics = 'F', reorthog = False, holdOffTime = h) res_sp['Alg'] = 'SPIRIT: alpha = ' + str(a) + \ ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' # Store algInfo = 'SPIRIT: E_Thresh = (' + str(el) + ',' + str(eh) + ')\n' + \ 'alpha = ' + str(a) + '\nHoldOff = ' + str(h) results.append({'info': {'data': dataInfo, 'alg' : algInfo}, 'data' : res_sp}) # Plot pltSummary2(res_sp, streams, (el, eh)) if run_frahst_v5_0 == 1: # Multiple Auto Correlation Frahsts for n in range(streams.shape[1]): res_name = 'res_ACF' + str(n) vars()[res_name] = FRAHST_V5_0(streams, data_column = n, L = win_L, alpha=a, e_low=el, e_high=eh, holdOffTime=h, fix_init_Q = 1, r = 1, evalMetrics = 'T', ignoreUp2 = ignoreUp2, static_r = 0, r_upper_bound = upper_bound) vars()[res_name]['Alg'] = res_name + 'alpha = ' + str(a) + ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' pltSummary2(vars()[res_name], streams[:,n] , (eh, el)) # Store algInfo = res_name + ': E_Thresh = (' + str(el) + ',' + str(eh) + ')\n' + \ 'alpha = ' + str(a) + '\nHoldOff = ' + str(h) results.append({'info': {'data': dataInfo, 'alg' : algInfo},
streams, 0.9) original = streams streams = streams - Maved_data_MAwindow if run_spirit == 1: # SPIRIT res_sp = SPIRIT(streams, a, [el, eh], evalMetrics='F', reorthog=False, holdOffTime=h) res_sp['Alg'] = 'SPIRIT: alpha = ' + str(a) + \ ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' pltSummary2(res_sp, streams, (el, eh)) SPIRIT_RawResults.append(res_sp) SPIRIT_metricList.append( analysis(res_sp, ground_truths, 3 * interval_length)) # data = res_sp # Title = 'SPIRIT alpha = ' + str(a) + ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' # # plot_4x1(streams, data['hidden'], data['e_ratio'], data['orthog_error'], # ['Input Data','Hidden\nVariables', # 'Energy Ratio', 'Orthogonality\nError (dB)'] , 'Time Steps', Title) # plot_4x1(streams, data['hidden'], data['orthog_error'], data['subspace_error'],
res['anomalies'] = [] else: # stack values for all keys 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]
def singleShiftRerun(parameter_string): params = parameter_string.split(', ') # Data Sets baseLine = 0.0 num_streams = [int(params[0].split()[-1])] # n SNRs = [int(params[1].split()[-1])] # snr anomaly_lengths = [int(params[2].split()[-1])] # l anomaly_magnitudes = [int(params[3].split()[-1])] # m initial_conditions = 20 # i # Algorithm Parameters thresholds = params[4].split()[-1].split(',') e_highs = [float(thresholds[1][0:-1])] # eh e_lows = [float(thresholds[0][1:])] # el alphas = [float(params[5].split()[-1])] # a holdOffs = [int(params[6].split()[-1])] # h # Algorithm flags run_spirit = 0 run_frahst = 1 run_frahst_pedro = 0 #=============================================================================== # Initialise Data sets #========-======================================================================= # For Profiling start = time.time() for n in num_streams: for snr in SNRs: for l in anomaly_lengths: for m in anomaly_magnitudes: A = 0 for i in range(initial_conditions): # Seed random number generator np.random.seed(i) # Two ts that have anomalous shift s0 = Tseries(0) s1 = Tseries(0) s0.makeSeries([1, 3, 1], [100, l, 200 - l], [baseLine, baseLine, baseLine + m], gradient=float(m) / float(l), noise_type='none') s1.makeSeries([1, 4, 1], [200, l, 100 - l], [baseLine, baseLine, baseLine - m], gradient=float(m) / float(l), noise_type='none') # The rest of the ts for k in range(2, n): name = 's' + str(k) vars()[name] = Tseries(0) vars()[name].makeSeries([1], [300], [baseLine], noise_type='none') # Concat into one matrix S = scipy.c_[s0] for k in range(1, n): S = scipy.c_[S, vars()['s' + str(k)]] # Concatonate to 3d array, timesteps x streams x initial condition if type(A) == int: A = S else: A = np.dstack((A, S)) # Calculate the noise Ps = np.sum(A[:, :, 0]**2) Pn = Ps / (10.**(snr / 10.)) scale = Pn / (n * 300.) noise = np.random.randn(A.shape[0], A.shape[1], A.shape[2]) * np.sqrt(scale) A = A + noise #=============================================================================== # Ground Truths #=============================================================================== # # time step | length ground_truths = np.array([[100, l], [200, l]]) #============================================================================== # Run Algorithm #============================================================================== alg_count = 1 for eh in e_highs: for el in e_lows: for a in alphas: for h in holdOffs: print 'Running Algorithm(s) with:\nE_Thresh = (' + str(el) + ',' + str(eh) + ')\n' + \ 'alpha = ' + str(a) + '\nHoldOff = ' + str(h) SPIRIT_metricList = [] FRAHST_metricList = [] PEDRO_FRAHST_metricList = [] for i in range(initial_conditions): # Load Data streams = A[:, :, i] if run_spirit == 1: # SPIRIT res_sp = SPIRIT(streams, a, [el, eh], evalMetrics='F', reorthog=False, holdOffTime=h) res_sp['Alg'] = 'SPIRIT: alpha = ' + str(a) + \ ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' pltSummary2( res_sp, streams, (el, eh)) SPIRIT_metricList.append( analysis( res_sp, ground_truths, 300)) # data = res_sp # Title = 'SPIRIT alpha = ' + str(a) + ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' # # plot_4x1(streams, data['hidden'], data['e_ratio'], data['orthog_error'], # ['Input Data','Hidden\nVariables', # 'Energy Ratio', 'Orthogonality\nError (dB)'] , 'Time Steps', Title) # plot_4x1(streams, data['hidden'], data['orthog_error'], data['subspace_error'], # ['Input Data','Hidden\nVariables', 'Orthogonality\nError (dB)','Subspace\nError (dB)'], # 'Time Steps', Title) # if run_frahst == 1: # My version of Frahst res_fr = FRAHST_V3_1( streams, alpha=a, e_low=el, e_high=eh, holdOffTime=h, fix_init_Q=1, r=1, evalMetrics='F') res_fr[ 'Alg'] = 'MyFrahst: alpha = ' + str( a ) + ' ,E_Thresh = (' + str( el) + ',' + str(eh) + ')' FRAHST_metricList.append( analysis( res_fr, ground_truths, 300)) pltSummary2( res_fr, streams, (el, eh)) # # data = res_fr # Title = 'My Frahst with alpha = ' + str(a) + ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' # plot_4x1(streams, data['hidden'], data['orthog_error'], data['subspace_error'], # ['Input Data','Hidden\nVariables', 'Orthogonality\nError (dB)','Subspace\nError (dB)'], # 'Time Steps', Title) if run_frahst_pedro == 1: # Pedros version of Frahst res_frped = frahst_pedro( streams, alpha=a, e_low=el, e_high=eh, holdOffTime=h, r=1, evalMetrics='F') res_frped['Alg'] = 'Pedros Frahst: alpha = ' + str(a) + \ ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' PEDRO_FRAHST_metricList.append( analysis( res_frped, ground_truths, 300)) pltSummary2( res_frped, streams, (el, eh)) # # data = res_frped # Title = 'Pedros Frahst: alpha = ' + str(a) + \ # ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' # # plot_4x1(streams, data['hidden'], data['orthog_error'], data['subspace_error'], # ['Input Data','Hidden\nVariables', 'Orthogonality\nError (dB)','Subspace\nError (dB)'], # 'Time Steps', Title) finish = time.time() - start print 'Runtime = ' + str(finish) + 'seconds\n' print 'In H:M:S = ' + GetInHMS(finish)
# -*- coding: utf-8 -*- """ Created on Sat Mar 05 23:19:11 2011 THIS IS THE VERSION TO RUN ON MAC, NOT WINDOWS @author: musselle """ from numpy import eye, zeros, dot, sqrt, log10, trace, arccos, nan, arange, ones import numpy as np import scipy as sp import numpy.random as npr from numpy.linalg import qr, eig, norm, solve from matplotlib.pyplot import plot, figure, title, step, ylim from artSigs import genCosSignals_no_rand , genCosSignals import scipy.io as sio from utils import analysis, QRsolveA, pltSummary2 from PedrosFrahst import frahst_pedro_original from Frahst_v3_1 import FRAHST_V3_1 from Frahst_v3_3 import FRAHST_V3_3 from Frahst_v3_4 import FRAHST_V3_4 from Frahst_v4_0 import FRAHST_V4_0 from load_syn_ping_data import load_n_store from QR_eig_solve import QRsolve_eigV from create_Abilene_links_data import create_abilene_links_data from MAfunctions import MA_over_window def FRAHST_V6_2(data, r=1, alpha=0.96, EW_mean_alpha = 0.1, EWMA_filter_alpha = 0.3, residual_thresh = 0.1, epsilon = 0.05, e_low = 0.96, e_high = 0.98, fix_init_Q = 0, holdOffTime=0, evalMetrics = 'F', static_r = 0, r_upper_bound = None, L = 5, ignoreUp2 = 0, data_norm_window = 50): """
res['anomalies'] = [] else: # stack values for all keys 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)):
alpha = valA e_low = valB print 'Running Alpha =', valA, ' and e_low = ', valB if run_spirit == 1: # SPIRIT res_sp = SPIRIT(streams, alpha, [e_low, e_high], evalMetrics = 'F', 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)) if run_frahst == 1: # My version of Frahst res_fr = FRAHST_V3_1(streams, alpha=alpha, e_low=e_low, e_high=e_high, holdOffTime=holdOff, fix_init_Q = 1, r = 1, evalMetrics = 'F') res_fr['Alg'] = 'Frahst with alpha = ' + str(valA) + ' and e_low = ' + str(valB) #plot_31(res_fr['RSRE'], res_fr['e_ratio'], res_fr['orthog_error'], # ['RSRE','Energy Ratio','Orthogonality\nError (dB)'], 'Time Steps', # 'Error Analysis of FRAHST' ) # metric_me, sets_me, anom_det_tab_me = analysis(res_me, AbileneMat['P_g_truth_tab'], n) pltSummary2(res_fr, streams, (e_low, e_high))
'r_hist': k_hist, # history of r values 'W_hist': W_hist, # history of Weights 'anomalies': anomalies } res.update(res2) return res if __name__ == '__main__': #A1 = np.mat(np.sin(np.arange(1,1001)/20.0)).T #A11 = A1 * npm.rand((1,10)) #plt.figure() #plt.plot(A11) #a1 = np.sin(npm.arange(1,1001)/10.0) #a2 = np.sin(npm.arange(1,1001)/50.0) #A2 = np.mat([a1,a2]).T * npm.rand((2,10)) #plt.figure() #plt.plot(A2) data = load_data('chlorine') data[1500:2000, 0:4] = 0.7 data = data[:, :15] res = SPIRIT(data, 1, [0.8, 0.99]) res['Alg'] = 'SPIRIT' pltSummary2(res, data, (0.8, 0.99))
holdOffTime=h) res_sp['Alg'] = 'SPIRIT: alpha = ' + str(a) + \ ' ,E_Thresh = (' + str(el) + ',' + str(eh) + ')' # Store algInfo = 'SPIRIT: E_Thresh = (' + str(el) + ',' + str(eh) + ')\n' + \ 'alpha = ' + str(a) + '\nHoldOff = ' + str(h) results.append({ 'info': { 'data': dataInfo, 'alg': algInfo }, 'data': res_sp }) # Plot pltSummary2( res_sp, streams, (el, eh)) if run_frahst_v5_0 == 1: # Multiple Auto Correlation Frahsts for n in range(streams.shape[1]): res_name = 'res_ACF' + str(n) vars()[res_name] = FRAHST_V5_0( streams, data_column=n, L=win_L, alpha=a, e_low=el, e_high=eh, holdOffTime=h, fix_init_Q=1, r=1,
# -*- coding: utf-8 -*- """ Created on Sat Mar 05 23:19:11 2011 THIS IS THE VERSION TO RUN ON MAC, NOT WINDOWS @author: musselle """ from numpy import eye, zeros, dot, sqrt, log10, trace, arccos, nan, arange, ones import numpy as np from numpy.random import rand from numpy.linalg import qr, eig, norm, solve from matplotlib.pyplot import plot, figure, title, step from artSigs import genCosSignals_no_rand , genCosSignals import scipy.io as sio from utils import analysis, QRsolveA, pltSummary2 from PedrosFrahst import frahst_pedro_original from Frahst_v3_1 import FRAHST_V3_1 from Frahst_v3_3 import FRAHST_V3_3 from Frahst_v3_4 import FRAHST_V3_4 from load_syn_ping_data import load_n_store from QR_eig_solve import QRsolve_eigV def FRAHST_V4_0(data, r=1, alpha=0.96, e_low=0.96, e_high=0.98, fix_init_Q = 0, holdOffTime=0, evalMetrics = 'F', static_r = 0, r_upper_bound = None, L = 5, ignoreUp2 = 0): """ Fast Rank Adaptive Householder Subspace Tracking Algorithm (FRAHST) Version 4.0 - Now also approximates eigenvalues for the approximated tracked basis for the eignevectors - Approach uses an orthogonal iteration arround X.T - Note, only a good approximation if alpha ~< 1. Used as its the fastest method as X.T b --> b must be solved anyway. - New entries in res
# -*- coding: utf-8 -*- """ Created on Sat Mar 05 23:19:11 2011 THIS IS THE VERSION TO RUN ON MAC, NOT WINDOWS @author: musselle """ from numpy import eye, zeros, dot, sqrt, log10, trace, arccos, nan, arange, ones import numpy as np import scipy as sp from numpy.random import rand from numpy.linalg import qr, eig, norm, solve from matplotlib.pyplot import plot, figure, title, step from artSigs import genCosSignals_no_rand , genCosSignals import scipy.io as sio from utils import analysis, QRsolveA, pltSummary2 from PedrosFrahst import frahst_pedro_original from Frahst_v3_1 import FRAHST_V3_1 from Frahst_v3_3 import FRAHST_V3_3 from Frahst_v3_4 import FRAHST_V3_4 from Frahst_v4_0 import FRAHST_V4_0 from load_syn_ping_data import load_n_store from QR_eig_solve import QRsolve_eigV def FRAHST_V6_0(data, r=1, alpha=0.96, EW_alpha = 0.1, e_low = 0.96, e_high = 0.98, fix_init_Q = 0, holdOffTime=0, evalMetrics = 'F', static_r = 0, r_upper_bound = None, L = 5, ignoreUp2 = 0, data_norm_window = 50): """ Fast Rank Adaptive Householder Subspace Tracking Algorithm (FRAHST) Version 6.0 - Different rank adjusting mechanism compares sum of r eigenvalues to variance of entire data.
"r_hist": k_hist, # history of r values "W_hist": W_hist, # history of Weights "anomalies": anomalies, } res.update(res2) return res if __name__ == "__main__": # A1 = np.mat(np.sin(np.arange(1,1001)/20.0)).T # A11 = A1 * npm.rand((1,10)) # plt.figure() # plt.plot(A11) # a1 = np.sin(npm.arange(1,1001)/10.0) # a2 = np.sin(npm.arange(1,1001)/50.0) # A2 = np.mat([a1,a2]).T * npm.rand((2,10)) # plt.figure() # plt.plot(A2) data = load_data("chlorine") data[1500:2000, 0:4] = 0.7 data = data[:, :15] res = SPIRIT(data, 1, [0.8, 0.99]) res["Alg"] = "SPIRIT" pltSummary2(res, data, (0.8, 0.99))
# -*- coding: utf-8 -*- """ Created on Sat Mar 05 23:19:11 2011 THIS IS THE VERSION TO RUN ON MAC, NOT WINDOWS @author: musselle """ from numpy import eye, zeros, dot, sqrt, log10, trace, arccos, nan, arange import numpy as np from numpy.random import rand from numpy.linalg import qr, eig, norm, solve from matplotlib.pyplot import plot, figure, title, step from artSigs import genCosSignals_no_rand , genCosSignals import scipy.io as sio from utils import analysis, QRsolveA, pltSummary2 from PedrosFrahst import frahst_pedro_original from Frahst_v3_1 import FRAHST_V3_1 from Frahst_v3_3 import FRAHST_V3_3 from load_syn_ping_data import load_n_store def FRAHST_V3_4(data, r=1, alpha=0.96, e_low=0.96, e_high=0.98, fix_init_Q = 0, holdOffTime=0, evalMetrics = 'F', static_r = 0, r_upper_bound = None, L = 5, ignoreUp2 = 0): """ Fast Rank Adaptive Householder Subspace Tracking Algorithm (FRAHST) VErsion 3.4 - input data z is time lagged series up to length l. - Algorithm is essentially same as 3.3, just adds pre processing to data vector - input Vector z_t is now of length (N times L) where L is window length - Q is increased accordingly Version 3.3 - Add decay of S and in the event of vanishing inputs - Make sure rank of S does not drop (and work out what that means!) - stops S going singular
# -*- coding: utf-8 -*- """ Created on Sat Mar 05 23:19:11 2011 THIS IS THE VERSION TO RUN ON MAC, NOT WINDOWS @author: musselle """ from numpy import eye, zeros, dot, sqrt, log10, trace, arccos, nan, arange import numpy as np import numpy.random as npr import scipy as sp from numpy.random import rand from numpy.linalg import qr, eig, norm, solve from matplotlib.pyplot import plot, figure, title, step from artSigs import genCosSignals_no_rand, genCosSignals import scipy.io as sio from utils import analysis, QRsolveA, pltSummary2 from PedrosFrahst import frahst_pedro_original from Frahst_v3_1 import FRAHST_V3_1 from load_syn_ping_data import load_n_store def FRAHST_V3_3(data, r=1, alpha=0.96, e_low=0.96, e_high=0.98, fix_init_Q=0, holdOffTime=0, evalMetrics='F', static_r=0, r_upper_bound=None,