def agg_FR_stats(save=False, fname=None, return_=False): file_dict = run_main_sim_gen.all_exec(filenames_only=True) MN = [] FF = [] RW = [] for k in file_dict.keys(): hdf = tables.openFile(file_dict[k]) rew_cnt = len(np.nonzero(hdf.root.task_msgs[:]['msg']=='reward')[0]) RW.append(rew_cnt) mn, ff = get_sim_tuning.get_FR_stats(hdf, save=False, return_=True, plot=False) MN.append(mn) FF.append(ff) MN = np.hstack((MN)) FF = np.hstack((FF)) f, ax = plt.subplots(nrows=2) ax[0].hist(MN, 20) ax[0].set_title('Mean FR. Hist.') ax[0].set_ylabel('Counts') ax[0].set_xlabel('Mean FR.') ax[1].hist(FF, 20) ax[1].set_title('FF Hist.') ax[1].set_ylabel('Counts') ax[1].set_xlabel('Fano Factor') plt.tight_layout() if save: d = dict(mean_fr = MN, ff = FF) sio.savemat(fname, d) if return_: return MN, FF, RW
def plot_vfb_stats(nf_dict =None, sot_dict=None, use_vfb_files=True): if (nf_dict is None) or (sot_dict is None): no_flag = True vfb_files = run_main_sim_gen.all_exec(vfb_files=True, filenames_only=True) keys = np.vstack((vfb_files.keys())) priv_noise_lev = np.unique(keys[:,0]) priv_tun_rat = np.unique(keys[:,1]) inputs = np.unique(keys[:,2]) fa_dict = {} nf_dict = {} sot_dict = {} else: no_flag = False keys = np.vstack((nf_dict)) priv_noise_lev = np.unique(keys[:,0]) priv_tun_rat = np.unique(keys[:,1]) fa_dict = {} for pnl in priv_noise_lev: f, axx = plt.subplots(nrows=2) print 'add plt' for ptr in priv_tun_rat: if no_flag: h5 = vfb_files[float(pnl), float(ptr), 'vfb'] #Use file to calc. SOT and n_factors hdf = tables.openFile(h5) dim_red_dict = factor_analysis_tasks.FactorBMIBase.generate_FA_matrices(None, hdf=hdf,dec=decoder) #LL, ax = pa.FA_all_targ_ALLms(hdf, iters=10, max_k=20,) #fa_dict[pnl, ptr] = FA nf_dict[pnl, ptr] = dim_red_dict['fa_main_shar_n_dim'] num_factors = nf_dict[pnl, ptr] #Calculate S.O.T Cov_Priv = np.trace(dim_red_dict['Psi']) U = np.mat(dim_red_dict['U']) Cov_Shar = np.trace(U*U.T) sot = Cov_Shar/(Cov_Shar+Cov_Priv) sot_dict[pnl, ptr] = sot else: num_factors = nf_dict[pnl, ptr] sot = sot_dict[pnl, ptr] print ptr, num_factors, sot axx[0].plot(np.float(ptr), num_factors, 'g.') axx[1].plot(np.float(ptr), sot, 'b.') axx[0].set_title('Num Factors: PNL: '+str(pnl)) axx[1].set_title('SOT : PNL: '+str(pnl)) return fa_dict, nf_dict, sot_dict
def sat_scatter3(color='priv_noise_lev', metric1='avg_speed', metric2 = 'path_error', inp='all', ax=None, stat='mn', size2=None): ''' ''' cmap = plt.get_cmap('gist_heat') file_dict = run_main_sim_gen.all_exec(filenames_only=True) keys = np.vstack((file_dict.keys())) priv_noise_lev = np.unique(keys[:,0]) priv_tun_rat = np.unique(keys[:,1]) inputs = np.unique(keys[:,2]) #Metric map: # metric_map = {} # metric_map['path_length'] = [(1, 0), 'cm'] # metric_map['path_error'] = [(1, 1), 'cm'] # metric_map['time2targ'] = [(0, 0), 'sec'] # metric_map['avg_speed'] = [(0, 1), 'cm/sec'] # print_metric=dict(path_length='Path Length', path_error='Path Error', time2targ= 'Time to Target', avg_speed='Avg. Speed') #Colormap for input type: #cmap_dict = dict(all='black', shared_scaled='steelblue',private_scaled='maroon') major_dict = {} #dx = .1/2 #Create figures; # if x_axis == 'sot': if ax is None: f, ax = plt.subplots() scat_x = [] scat_sdx = [] scat_y = [] scat_sdy = [] scat_col = [] scat_pnl = [] scat_xcol = [] size_arr = [] for pnl in priv_noise_lev: print 'PRIV NOISE LEVEL: ', pnl # if x_axis == 'priv_tun_rat': # f, ax = plt.subplots(nrows=2, ncols=2) for ptr in priv_tun_rat: priv_in = pnl.astype(float) + ((1-pnl.astype(float)-0.2)*ptr.astype(float)) sot_in = 1 - priv_in tun_in = 1 - pnl.astype(float) try: h5 = file_dict[float(pnl), float(ptr), inp] cont = True except: print 'missing files: ', str(float(pnl)), str(float(ptr)), inp cont = False major_dict[pnl, ptr, inp, 'cont'] = cont if cont: try: mat = sio.loadmat(h5[:-4]+'_metrics.mat') except: mat = dict() metric_map = dict(avg_speed=0, path_error=0,path_length=0, time2targ=0) for metric in metric_map.keys(): mat[metric] = np.array([0]) mat['output_sot'] = 0. #spd = np.squeeze(mat[metric]) if metric1 == 'path_error': acc = -1*np.squeeze(mat[metric1]) elif metric1 == 'avg_speed': acc = np.squeeze(mat[metric1])/(1/60.) elif metric1 == 'trials_per_min': h5_file = tables.openFile(h5) nrew = np.sum(h5_file.root.task_msgs[:]['msg']=='reward') acc = float(nrew)/(len(h5_file.root.task)/60./60.) #acc = np.squeeze(mat[metric]) elif metric1 == 'sot_out': acc = float(np.squeeze(mat['output_sot'])) elif metric1 == 'sot_in': acc = sot_in elif metric1 == 'ptr': acc = float(ptr) if metric2 == 'path_error': acc2 = -1*np.squeeze(mat[metric2]) elif metric2 == 'avg_speed': acc2 = np.squeeze(mat[metric2])/(1/60.) elif metric2 == 'sot_out': acc2 = float(np.squeeze(mat['output_sot'])) #cmap(np. elif metric2 == 'sot_in': acc2 = sot_in elif metric2 == 'fit_qr': dat = pickle.load(open(h5[:-4]+'.pkl')) acc2 = dat.fit_qr else: acc2 = np.squeeze(mat[metric2]) if color == 'sot_in': col = sot_in #cmap(sot_in) elif color == 'sot_out': col = float(np.squeeze(mat['output_sot'])) #cmap(np.squeeze(mat['sot_out'])) elif color == 'tuning': col = tun_in #cmap(tun_in) elif color == 'priv_to_tot_tuning': col = float(ptr) elif color == 'priv_noise_lev': col = float(pnl) elif color == None: col = 0. if size2 == 'ptr': sz = 2500*(float(ptr)+.1)**2 else: sz = -1 #print spd, acc, col try: denom = np.sqrt(len(acc2)) except: denom = 1 if stat == 'mn': fcn = np.mean elif stat == 'se': fcn = std_err scat_x.append(np.mean(acc)) try: scat_sdx.append(std_err(acc)) except: scat_sdx.append(0) scat_y.append(fcn(acc2)) try: scat_sdy.append(std_err(acc2)) except: scat_sdy.append(0) scat_col.append(col) size_arr.append(sz) if inp[:3]=='all': mark = '.' sz_ = 300 elif inp == 'shared_scaled': mark = '>' sz_ = 300 if len(np.nonzero(np.array(size_arr) <0)[0]) > 0: sz = sz_ else: sz = np.array(size_arr) #plt.errorbar(np.array(scat_x), np.array(scat_y), fmt=None,yerr=scat_sdy,err=scat_sdx, ecolor=scat_col) cax = plt.scatter(np.array(scat_x), np.array(scat_y), c=np.array(scat_col), s=sz, vmin=0, vmax=1, cmap=cmap, marker=mark) #ix = np.nonzero(np.array(scat_y)>6.)[0] ix = np.arange(len(scat_y)) slp, intc, r2, pvalue,yy = scipy.stats.linregress(np.array(scat_x)[ix], np.array(scat_y)[ix]) print slp, intc, r2, pvalue x_ = np.arange(0, 1.2, .1) y_ = (slp*x_)+intc plt.plot(x_, y_, 'k-') plt.colorbar(cax) #cbar = f.colorbar(cax, ticks=[0, 1]) plt.xlabel(metric1) plt.ylabel(metric2) try: plt.title('Color: '+color+', R2:'+str(r2**2)+'p: '+str(pvalue)) except: pass #plt.ylim([6.2, 7.8]) #plt.xlim([0.1, 1.0]) plt.tight_layout() return ax
def sat_scatter2(xaxis='priv_to_tot_tuning', color='priv_noise_lev', metric1='avg_speed', metric2 = 'path_error', inp='all', ax=None, stat='mn', cbar=True): ''' ''' cmap = plt.get_cmap('gist_heat') file_dict = run_main_sim_gen.all_exec(filenames_only=True) keys = np.vstack((file_dict.keys())) priv_noise_lev = np.unique(keys[:,0]) priv_tun_rat = np.unique(keys[:,1]) inputs = np.unique(keys[:,2]) #Metric map: # metric_map = {} # metric_map['path_length'] = [(1, 0), 'cm'] # metric_map['path_error'] = [(1, 1), 'cm'] # metric_map['time2targ'] = [(0, 0), 'sec'] # metric_map['avg_speed'] = [(0, 1), 'cm/sec'] # print_metric=dict(path_length='Path Length', path_error='Path Error', time2targ= 'Time to Target', avg_speed='Avg. Speed') #Colormap for input type: #cmap_dict = dict(all='black', shared_scaled='steelblue',private_scaled='maroon') major_dict = {} #dx = .1/2 #Create figures; # if x_axis == 'sot': if ax is None: f, ax = plt.subplots(figsize=(7.,9.3), nrows=2) scat_x = [] scat_sdx = [] scat_y = [] scat_sdy = [] scat_col = [] scat_pnl = [] scat_xcol = [] for pnl in priv_noise_lev: print 'PRIV NOISE LEVEL: ', pnl # if x_axis == 'priv_tun_rat': # f, ax = plt.subplots(nrows=2, ncols=2) for ptr in priv_tun_rat: priv_in = pnl.astype(float) + ((1-pnl.astype(float)-0.2)*ptr.astype(float)) sot_in = 1 - priv_in tun_in = 1 - pnl.astype(float) try: h5 = file_dict[float(pnl), float(ptr), inp] cont = True except: print 'missing files: ', str(float(pnl)), str(float(ptr)), inp cont = False major_dict[pnl, ptr, inp, 'cont'] = cont if cont: try: mat = sio.loadmat(h5[:-4]+'_metrics.mat') except: mat = dict() metric_map = dict(avg_speed=0, path_error=0,path_length=0, time2targ=0) for metric in metric_map.keys(): mat[metric] = np.array([0]) mat['output_sot'] = 0. #spd = np.squeeze(mat[metric]) if metric1 == 'path_error': acc = -1*np.squeeze(mat[metric1]) elif metric1 == 'avg_speed': acc = np.squeeze(mat[metric1])/(1/60.) elif metric1 == 'trials_per_min': h5_file = tables.openFile(h5) nrew = np.sum(h5_file.root.task_msgs[:]['msg']=='reward') acc = float(nrew)/(len(h5_file.root.task)/60./60.) #acc = np.squeeze(mat[metric]) if metric2 == 'path_error': acc2 = -1*np.squeeze(mat[metric2]) elif metric2 == 'avg_speed': acc2 = np.squeeze(mat[metric2])/(1/60.) else: acc2 = np.squeeze(mat[metric2]) if color == 'sot_in': col = sot_in #cmap(sot_in) elif color == 'sot_out': col = float(np.squeeze(mat['output_sot'])) #cmap(np.squeeze(mat['sot_out'])) elif color == 'tuning': col = tun_in #cmap(tun_in) elif color == 'priv_to_tot_tuning': col = float(ptr) elif color == 'priv_noise_lev': col = float(pnl) if xaxis == 'sot_in': xcol = sot_in #cmap(sot_in) elif xaxis == 'sot_out': xcol = float(np.squeeze(mat['output_sot'])) #cmap(np.squeeze(mat['sot_out'])) elif xaxis == 'tuning': xcol = tun_in #cmap(tun_in) elif xaxis == 'priv_to_tot_tuning': xcol = float(ptr) elif xaxis == 'priv_noise_lev': xcol = float(pnl) #print spd, acc, col try: denom = np.sqrt(len(acc2)) except: denom = 1 if stat == 'mn': fcn = np.mean elif stat == 'se': fcn = std_err scat_x.append(np.mean(acc)) try: scat_sdx.append(std_err(acc)) except: scat_sdx.append(0) scat_y.append(fcn(acc2)) try: scat_sdy.append(std_err(acc2)) except: scat_sdy.append(0) scat_col.append(col) scat_xcol.append(xcol) if inp[:3]=='all': mark = '.' sz = 150 elif inp == 'shared_scaled': mark = '>' sz = 150 plt.subplot(2, 1, 1) #plt.errorbar(np.array(scat_xcol), np.array(scat_x), fmt=None,yerr=scat_sdx, ecolor=scat_col) cax = plt.scatter(np.array(scat_xcol), np.array(scat_x), c=np.array(scat_col), s=sz, vmin=0, vmax=1, cmap=cmap, marker=mark) if cbar: plt.colorbar(cax) #cbar = f.colorbar(cax, ticks=[0, 1]) plt.xlabel(xaxis) plt.ylabel(metric1) plt.title('Color: '+color) #plt.ylim([5.5, 12.5]) plt.subplot(2, 1, 2) #plt.errorbar(np.array(scat_xcol), np.array(scat_y), fmt=None,yerr=scat_sdy, ecolor=scat_col) cax = plt.scatter(np.array(scat_xcol), np.array(scat_y), c=np.array(scat_col), s=sz, vmin=0, vmax=1, cmap=cmap, marker=mark) if cbar: plt.colorbar(cax) #cbar = f.colorbar(cax, ticks=[0, 1]) plt.xlabel(xaxis) plt.ylabel(metric2) plt.title('Color: '+color) plt.tight_layout() return ax
def sat_scatter(color='sot_in', inp='all', ax=None): ''' Summary: method to create plot speed vs. accuracy (path error) tradeoff for each sim Input param: color: can be 'sot_in' or 'sot_out' or 'tuning' or 'priv_to_tot_tuning' ''' cmap = plt.get_cmap('gist_heat') file_dict = run_main_sim_gen.all_exec(filenames_only=True) keys = np.vstack((file_dict.keys())) priv_noise_lev = np.unique(keys[:,0]) priv_tun_rat = np.unique(keys[:,1]) inputs = np.unique(keys[:,2]) #Metric map: # metric_map = {} # metric_map['path_length'] = [(1, 0), 'cm'] # metric_map['path_error'] = [(1, 1), 'cm'] # metric_map['time2targ'] = [(0, 0), 'sec'] # metric_map['avg_speed'] = [(0, 1), 'cm/sec'] # print_metric=dict(path_length='Path Length', path_error='Path Error', time2targ= 'Time to Target', avg_speed='Avg. Speed') #Colormap for input type: #cmap_dict = dict(all='black', shared_scaled='steelblue',private_scaled='maroon') major_dict = {} #dx = .1/2 #Create figures; # if x_axis == 'sot': if ax is None: f, ax = plt.subplots() else: plt.sca(ax) scat_x = [] scat_sdx = [] scat_y = [] scat_sdy = [] scat_col = [] for pnl in priv_noise_lev: print 'PRIV NOISE LEVEL: ', pnl # if x_axis == 'priv_tun_rat': # f, ax = plt.subplots(nrows=2, ncols=2) for ptr in priv_tun_rat: priv_in = pnl.astype(float) + ((1-pnl.astype(float)-0.2)*ptr.astype(float)) sot_in = 1 - priv_in tun_in = 1 - pnl.astype(float) try: h5 = file_dict[float(pnl), float(ptr), inp] cont = True except: print 'missing files: ', str(float(pnl)), str(float(ptr)), inp cont = False major_dict[pnl, ptr, inp, 'cont'] = cont if cont: try: mat = sio.loadmat(h5[:-4]+'_metrics.mat') except: mat = dict() metric_map = dict(avg_speed=0, path_error=0) for metric in metric_map.keys(): mat[metric] = np.array([0]) mat['output_sot'] = 0. spd = np.squeeze(mat['avg_speed']) acc = np.squeeze(mat['path_error']) if color == 'sot_in': col = sot_in #cmap(sot_in) elif color == 'sot_out': col = float(np.squeeze(mat['output_sot'])) #cmap(np.squeeze(mat['sot_out'])) elif color == 'tuning': col = tun_in #cmap(tun_in) elif color == 'priv_to_tot_tuning': col = float(ptr) elif color == 'priv_noise_lev': col = float(pnl) print spd, acc, col scat_x.append(np.mean(spd)) try: scat_sdx.append(np.std(spd)/np.sqrt(len(spd))) except: scat_sdx.append(0) scat_y.append(np.mean(acc)) try: scat_sdy.append(np.std(acc)/np.sqrt(len(acc))) except: scat_sdy.append(0) scat_col.append(col) if inp[:3]=='all': mark = '.' sz = 150 elif inp == 'shared_scaled': mark = '>' sz = 150 cax = plt.scatter(np.array(scat_x), -1*np.array(scat_y), c=np.array(scat_col), s=sz, vmin=0, vmax=1, cmap=cmap, marker=mark) #plt.errorbar(scat_x, scat_y, xerr=scat_sdx, yerr=scat_sdy, ecolor=scat_col) plt.colorbar(cax) #cbar = f.colorbar(cax, ticks=[0, 1]) plt.xlabel('Speed') plt.ylabel('Accuracy') plt.title('Color: '+color) plt.tight_layout() return ax
def plot_scatter_sot(master_encoder): file_dict = run_main_sim_gen.all_exec(filenames_only=True) keys = np.vstack((file_dict.keys())) priv_noise_lev = np.unique(keys[:,0]) priv_tun_rat = np.unique(keys[:,1]) inputs = np.unique(keys[:,2]) #Metric map: metric_map = {} metric_map['path_length'] = [(1, 0), 'cm'] metric_map['path_error'] = [(1, 1), 'cm'] metric_map['time2targ'] = [(0, 0), 'sec'] metric_map['avg_speed'] = [(0, 1), 'cm/sec'] #Colormap for input type: cmap_dict = dict(all='black', shared_scaled='cornflowerblue',private_scaled='maroon') major_dict = {} dx = .1/2 n_samples = 600 from riglib.bmi.state_space_models import StateSpaceEndptVel2D ssm = StateSpaceEndptVel2D() A, _, W = ssm.get_ssm_matrices() mean = np.zeros(A.shape[0]) mean[-1] = 1 state_samples = np.random.multivariate_normal(mean, W, n_samples) units = master_encoder.get_units() n_units = len(units) dat_dict = {} lamb_arr = np.array([0.1, 0.25, 0.5, 1., 2.5, 5., 10., 20.]) spike_counts = np.zeros([n_units, n_samples]) master_encoder.call_ds_rate = 1 master_dict = {} #Create figures; for pnl in priv_noise_lev: f, ax = plt.subplots(nrows=2, ncols=2) for ptr in priv_tun_rat: tun = 1 - .15 - float(pnl) p_tun = float(ptr)*tun s_tun = tun - p_tun master_encoder.wt_sources = np.array([float(pnl), p_tun, .15, s_tun]) for k in range(n_samples): spike_counts[:,k] = np.array(master_encoder(state_samples[k], mode='counts')).ravel() zscore_X, mu = pa.zscore_spks(spike_counts.T) log_lik, _ = pa.find_k_FA(zscore_X, iters=5, max_k = 20, plot=False) num_factors = 1+(np.argmax(np.mean(log_lik, axis=0))) FA = skdecomp.FactorAnalysis(n_components=num_factors) #Samples x features: FA.fit(zscore_X) Cov_Priv = np.sum(FA.noise_variance_) U = np.mat(FA.components_).T Cov_Shar = np.trace(U*U.T) sot = Cov_Shar/(Cov_Shar+Cov_Priv) master_dict[pnl, ptr, 'sot'] = sot master_dict[pnl, ptr, 'nf'] = num_factors print 'SOT: ', sot, pnl, ptr inp_cnt = -1*(dx) for inp in inputs: inp_cnt += dx h5 = file_dict[float(pnl), float(ptr), inp] try: mat = sio.loadmat(h5[:-4]+'_metrics.mat') except: mat = dict() for metric in metric_map.keys(): mat[metric] = np.array([0]) for metric in metric_map.keys(): x = mat[metric] axi = ax[metric_map[metric][0][0], metric_map[metric][0][1]] axi.set_title('Priv Noise: '+pnl+', Met:'+metric) mn = np.mean(x) master_dict[pnl, ptr, inp, metric] = mn sem = np.std(x)/np.sqrt(len(x)) #rect = axi.errorbar(sot, mn, sem, fmt='.', markersize=15, color=cmap_dict[inp]) rect = axi.plot(sot, mn, '.', markersize=15, color=cmap_dict[inp]) #axi.errorbar(np.float(ptr)+inp_cnt, mn, sem, fmt='.', markersize=15, color=inp_dict[inp]) axi.set_ylabel(metric_map[metric][1]) if metric == 'path_error': axi.legend(list(inputs),fontsize=8) axi.set_xlabel('Shared over Total Fraction') elif metric == 'path_length': axi.set_xlabel('Shared over Total Fraction') plt.tight_layout() return master_dict
def perf_plots_bar(x_axis='sot',stats=False): ''' Summary: method to create figure 4 in EMBC paper Input param: x_axis: can be 'sot' or 'priv_tun_rat' Output param: ''' file_dict = run_main_sim_gen.all_exec(filenames_only=True) keys = np.vstack((file_dict.keys())) priv_noise_lev = np.unique(keys[:,0]) priv_tun_rat = np.unique(keys[:,1]) inputs = np.unique(keys[:,2]) #Metric map: metric_map = {} metric_map['path_length'] = [(1, 0), 'cm'] metric_map['path_error'] = [(1, 1), 'cm'] metric_map['time2targ'] = [(0, 0), 'sec'] metric_map['avg_speed'] = [(0, 1), 'cm/sec'] print_metric=dict(path_length='Path Length', path_error='Path Error', time2targ= 'Time to Target', avg_speed='Avg. Speed') #Colormap for input type: cmap_dict = dict(all='black', sha='steelblue',pri='maroon') major_dict = {} dx = .1/2 #Create figures; if x_axis == 'sot': f, ax = plt.subplots(nrows=2, ncols=2) for pnl in priv_noise_lev: print 'PRIV NOISE LEVEL: ', pnl if x_axis == 'priv_tun_rat': f, ax = plt.subplots(nrows=2, ncols=2) for ptr in priv_tun_rat: inp_cnt = -1*(dx) for inp in inputs: inp_cnt += dx #major_dict[pnl, ptr, inp, 'x'] = float(ptr)+inp_cnt try: h5 = file_dict[float(pnl), float(ptr), inp] cont = True except: print 'missing files: ', str(float(pnl)), str(float(ptr)), inp cont = False major_dict[pnl, ptr, inp, 'cont'] = cont if cont: try: mat = sio.loadmat(h5[:-4]+'_metrics.mat') except: mat = dict() for metric in metric_map.keys(): mat[metric] = np.array([0]) mat['output_sot'] = 0. for metric in metric_map.keys(): x = mat[metric] if x_axis == 'priv_tun_rat': xaxis = [float(ptr)+inp_cnt] elif x_axis == 'sot': xaxis = [float(np.squeeze(mat['output_sot']))] axi = ax[metric_map[metric][0][0], metric_map[metric][0][1]] #axi.set_title('Priv Noise: '+pnl+', Met:'+metric) axi.set_title('Metric :'+print_metric[metric]) major_dict[pnl, ptr, inp, metric] = np.squeeze(x) mn = np.mean(x) sem = np.std(x)/np.sqrt(len(x)) perc_tun = 1. - float(pnl) - float(0.2) rect = axi.bar(xaxis, mn, 0.02, color=color[int(perc_tun*NUM_COLORS)], ecolor=cmap_dict[inp[:3]], yerr=sem, alpha=.6) major_dict[pnl, ptr, inp, metric, 'ymax'] = mn+sem #axi.errorbar(np.float(ptr)+inp_cnt, mn, sem, fmt='.', markersize=15, color=inp_dict[inp]) axi.set_ylabel(metric_map[metric][1]) if metric == 'path_error': axi.legend(list(inputs),fontsize=8) if x_axis == 'priv_tun_rat': axi.set_xlabel('Priv. Tuning / Total Tuning') elif x_axis == 'sot': axi.set_xlabel('Output Shared / Total') axi.set_title('PRIV NOISE LEV: '+str(pnl)) elif metric == 'path_length': if x_axis == 'priv_tun_rat': axi.set_xlabel('Priv. Tuning / Total Tuning') elif x_axis == 'sot': axi.set_xlabel('Output Shared / Total') for metric in metric_map.keys(): axi = ax[metric_map[metric][0][0], metric_map[metric][0][1]] stat_args = [] for inp in inputs: if major_dict[pnl, ptr, inp, 'cont']: stat_args.append(major_dict[pnl, ptr, inp, metric]) else: print 'skipping: ', major_dict[pnl, ptr, inp, 'cont'] if stats: try: kw = stats.mstats.kruskalwallis(*stat_args) if kw[1] < 0.05: print 'pass KW for ', metric, ' Noise Level: ', pnl, ' Ratio: ', ptr for i, inp1 in enumerate(inputs): x = major_dict[pnl, ptr, inp1, metric] for inp2 in inputs[i:]: print 'preey;' y = major_dict[pnl, ptr, inp2, metric] u, p = stats.mannwhitneyu(x,y) if 2*p < 0.05: if (2*p)<0.05 and (2*p) > 0.01: star = '*' elif (2*p) <= 0.01 and (2*p) > 0.001: star = '**' elif (2*p) <= 0.001: star = '***' x1 = major_dict[pnl, ptr, inp1, 'x'] x2 = major_dict[pnl, ptr, inp2, 'x'] y = [] for inp in inputs: y.append(major_dict[pnl, ptr, inp, metric, 'ymax']) print 'pre_label' #label_diff(x1, x2, star, y, axi, dx) #print inp1, inp2, 2*p except: 'pass :( , ', metric plt.tight_layout()
def perf_plots(metric): file_dict = run_main_sim_gen.all_exec(filenames_only=True) keys = np.vstack((file_dict.keys())) priv_noise_lev = np.unique(keys[:,0]) priv_tun_rat = np.unique(keys[:,1]) inputs = np.unique(keys[:,2]) #Metric map: metric_map = {} metric_map['output_sot'] = [(1, 0), 'fraction'] metric_map['path_error'] = [(1, 1), 'cm'] metric_map['time2targ'] = [(0, 0), 'sec'] metric_map['avg_speed'] = [(0, 1), 'cm/sec'] #Colormap for input type: cmap_list = ['maroon', 'orangered', 'darkgoldenrod', 'olivedrab', 'teal', 'steelblue', 'midnightblue', 'darkmagenta', 'darkgray','maroon'] inp_dict = {} for j, i in enumerate(inputs): inp_dict[i]=cmap_list[(2*j)+1] major_dict = {} #Create figures; for pnl in priv_noise_lev: f, ax = plt.subplots(nrows=2, ncols=2) for ptr in priv_tun_rat: inp_cnt = 0 for inp in inputs: inp_cnt += .1/6 try: h5 = file_dict[float(pnl), float(ptr), inp] try: mat = sio.loadmat(h5[:-4]+'_metrics.mat') except: mat = dict() for metric in metric_map.keys(): mat[metric] = np.array([0]) for metric in metric_map.keys(): x = mat[metric] axi = ax[metric_map[metric][0][0], metric_map[metric][0][1]] axi.set_title('Priv Noise: '+pnl+', Met:'+metric) major_dict[pnl, ptr, inp, metric] = np.squeeze(x) mn = np.mean(x) sem = np.std(x)/np.sqrt(len(x)) axi.errorbar(np.float(ptr)+inp_cnt, mn, sem, fmt='.', markersize=15, color=inp_dict[inp]) axi.set_ylabel(metric_map[metric][1]) if metric == 'path_error': axi.legend(list(inputs),fontsize=12) axi.set_xlabel('Priv. Tuning / Total Tuning') elif metric == 'path_length': axi.set_xlabel('Priv. Tuning / Total Tuning') except: print 'skipping: ', pnl, ptr, inp for metric in metric_map.keys(): stat_args = [] for inp in inputs: try: stat_args.append(major_dict[pnl, ptr, inp, metric]) except: pass try: kw = stats.mstats.kruskalwallis(*stat_args) if kw[1] < 0.05: print 'pass KW for ', metric, ' Noise Level: ', pnl, ' Ratio: ', ptr for inp1 in inputs: x = major_dict[pnl, ptr, inp1, metric] for inp2 in inputs: y = major_dict[pnl, ptr, inp2, metric] u, p = stats.mannwhitneyu(x,y) if 2*p < 0.05: print inp1, inp2, 2*p except: 'pass :( , ', metric plt.tight_layout()