def draw_pairwise_weights_vs_dist(agg): wdf = export_pairwise_decoder_weights(agg) r2_thresh = 0.20 # aprops = ALL_ACOUSTIC_PROPS aprops = ['meanspect', 'stdspect', 'sal', 'maxAmp'] aprop_clrs = {'meanspect':'#FF8000', 'stdspect':'#FFBF00', 'sal':'#088A08', 'maxAmp':'k'} print wdf.decomp.unique() # get scatter data for weights vs distance scatter_data = dict() for decomp in ['full_psds+full_cfs', 'spike_rate+spike_sync']: i = wdf.decomp == decomp assert i.sum() > 0 df = wdf[i] for n,aprop in enumerate(aprops): ii = (df.r2 > r2_thresh) & (df.aprop == aprop) & ~np.isnan(df.dist) & ~np.isinf(df.dist) d = df.dist[ii].values w = df.w[ii].values scatter_data[(decomp, aprop)] = (d, w) decomp_labels = {'full_psds+full_cfs':'LFP Pairwise Correlations', 'spike_rate+spike_sync':'Spike Synchrony'} figsize = (14, 5) fig = plt.figure(figsize=figsize) fig.subplots_adjust(left=0.10, right=0.98) for k,decomp in enumerate(['full_psds+full_cfs', 'spike_rate+spike_sync']): ax = plt.subplot(1, 2, k+1) for aprop in aprops: d,w = scatter_data[(decomp, aprop)] wz = w**2 wz /= wz.std(ddof=1) xcenter, ymean, yerr, ymean_cs = compute_mean_from_scatter(d, wz, bins=5, num_smooth_points=300) # plt.plot(xcenter, ymean, '-', c=aprop_clrs[aprop], linewidth=7.0, alpha=0.7) plt.errorbar(xcenter, ymean, linestyle='-', yerr=yerr, c=aprop_clrs[aprop], linewidth=9.0, alpha=0.7, elinewidth=8., ecolor='#d8d8d8', capsize=0.) plt.axis('tight') plt.ylabel('Decoder Weight Effect') plt.xlabel('Pairwise Distance (mm)') plt.title(decomp_labels[decomp]) aprop_lbls = [ACOUSTIC_PROP_NAMES[aprop] for aprop in aprops] aclrs = [aprop_clrs[aprop] for aprop in aprops] leg = custom_legend(aclrs, aprop_lbls) plt.legend(handles=leg, loc='lower left') fname = os.path.join(get_this_dir(), 'pairwise_decoder_effect_vs_dist.svg') plt.savefig(fname, facecolor='w', edgecolor='none') plt.show()
def draw_rate_weight_by_dist(agg): wdf = get_encoder_weight_data_for_psd(agg, include_sync=False, write_to_file=False) def exp_func(_x, _a, _b, _c): return _a * np.exp(-_b * _x) + _c # plot the average encoder weight as a function of distance from predicted electrode freqs = [15, 55, 135] band_labels = ['0-30Hz', '30-80Hz', '80-190Hz'] clrs = {15:'k', 55:'r', 135:'b'} for f in freqs: i = ~np.isnan(wdf.dist_from_electrode.values) & (wdf.r2 > 0.05) & (wdf.dist_from_electrode > 0) & (wdf.f == f) x = wdf.dist_from_electrode[i].values y = (wdf.w[i].values)**2 popt, pcov = curve_fit(exp_func, x, y) ypred = exp_func(x, *popt) ysqerr = (y - ypred)**2 sstot = np.sum((y - y.mean())**2) sserr = np.sum(ysqerr) r2 = 1. - (sserr / sstot) print 'f=%dHz, a=%0.6f, space_const=%0.6f, bias=%0.6f, r2=%0.2f: ' % (f, popt[0], 1. / popt[1], popt[2], r2) npts = 100 xreg = np.linspace(x.min()+1e-1, x.max()-1e-1, npts) yreg = exp_func(xreg, *popt) # approximate sqrt(err) with a cubic spline for plotting err_xcenter, err_ymean, err_yerr, err_ymean_cs = compute_mean_from_scatter(x, np.sqrt(ysqerr), bins=4, num_smooth_points=npts) # yerr = err_ymean_cs(xreg) # plt.plot(x, y, 'ko', alpha=0.7) plt.plot(xreg, yreg, clrs[f], alpha=0.7, linewidth=5.0) # plt.errorbar(xreg, yreg, yerr=err_ymean, c=clrs[f], alpha=0.7, linewidth=5.0, ecolor='#b5b5b5') # plt.show() # plot_mean_from_scatter(x, y, bins=4, num_smooth_points=200, alpha=0.7, color=clrs[f], ecolor='#b5b5b5', bin_by_quantile=False) plt.xlabel('Distance From Predicted Electrode (mm)') plt.ylabel('Encoder Weight^2') plt.axis('tight') freq_clrs = [clrs[f] for f in freqs] leg = custom_legend(colors=freq_clrs, labels=band_labels) plt.legend(handles=leg, loc='lower right')