plt.subplot(212) plt.plot(pup_m,'-o', color='k', alpha=0.5, lw=2) plt.plot(diff, '-o', color='g') plt.legend(['pup', 'rN-r0']) plt.xlabel('pip trials') plt.title('corr coef btwn rN-r0 and pupil: %s' %(np.corrcoef(diff, pup_m)[0][1])) print('Comparing different models...') def onpick3(event): ind = event.ind print('onpick3 scatter:', cellids[ind][0]) rN_perf = eval_fit(resp, fullModel) r0_perf = eval_fit(resp, pred) x = np.linspace(-1,1,3) ncols = 8 nrows = 10 cellcount = resp.shape[-1] repcount = resp.shape[1] bincount = resp.shape[0] spontonly=0 fs=100 stim=0 color = np.arange(cellcount) fig = plt.figure() for rep in range(0, repcount): ax = fig.add_subplot(nrows,ncols,rep+1)
a_p_unwrapped = list(np.tile(a_p, (30, 1)).T.reshape(repcount * stimcount)) pupil_unwrapped = np.nanmean(pupil, 0).reshape(repcount * stimcount) rN = NRF_fit(r=resp, r0_strf=pred, model='NRF_STRF', spontonly=False) fig = plt_perf_by_trial(resp, rN, pred, combine_stim=False, a_p=a_p_unwrapped, pupil=pupil, pop_state={ 'method': 'SVD', 'dims': 5 }) # Evaluate r0 and rN cc_rN = eval_fit(resp, rN) cc_r0 = eval_fit(resp, pred) cc_rN_flat = cc_rN['bytrial'].reshape(repcount * stimcount, cellcount) cc_r0_flat = cc_r0['bytrial'].reshape(repcount * stimcount, cellcount) import statsmodels.api as sm import pandas as pd reg_in = pd.DataFrame(np.vstack((a_p_unwrapped, pupil_unwrapped)).T, columns=['behavior', 'pupil']) reg_out = pd.DataFrame(cc_rN_flat - cc_r0_flat, columns=cellids) for cid in reg_out: if (np.any(np.isnan(reg_out[cid]))): for i, val in enumerate(reg_out[cid]): if np.isnan(val):
inds = [] for ind in np.argwhere(np.isnan(pupil[0, :, :])): inds.append(ind[0]) inds = np.array(inds) drop_inds = np.unique(inds) keep_inds = [x for x in np.arange(0, len(resp[0, :, 0, 0])) if x not in inds] a_p = np.array(a_p)[keep_inds] resp = resp[:, keep_inds, :, :] pred = pred[:, keep_inds, :, :] pupil = pupil[:, keep_inds, :] pup = pupil from NRF_tools import NRF_fit, eval_fit rN = NRF_fit(resp, r0_strf=pred, model="NRF_STRF", spontonly=0, shuffle=True) rN_perf = eval_fit(resp, rN) r0_perf = eval_fit(resp, pred) #cc_rN_all = np.empty((resp.shape[1], resp.shape[2], resp.shape[-1])) #cc_r0_all = np.empty((resp.shape[1], resp.shape[2], resp.shape[-1])) cc_rN_all = rN_perf['bytrial'] cc_r0_all = r0_perf['bytrial'] for i in range(0, resp.shape[1]): for stim in range(0, resp.shape[2]): for cell in range(0, resp.shape[-1]): cc_rN_all[i, stim, cell] = np.corrcoef(rN[:, i, stim, cell], resp[:, i, stim, cell])[0][1] cc_r0_all[i, stim, cell] = np.corrcoef(pred[:, i, stim, cell], resp[:, i, stim, cell])[0][1]
inds = [] for ind in np.argwhere(np.isnan(pupil[0, :, :])): inds.append(ind[0]) inds = np.array(inds) drop_inds = np.unique(inds) keep_inds = [x for x in np.arange(0, len(resp[0, :, 0, 0])) if x not in inds] a_p = np.array(a_p)[keep_inds] resp = resp[:, keep_inds, :, :] pred = pred[:, keep_inds, :, :] pupil = pupil[:, keep_inds, :] pup = pupil from NRF_tools import NRF_fit, eval_fit rN = NRF_fit(resp, r0_strf=pred, model="NRF_STRF", spontonly=0, shuffle=True) rN_perf = eval_fit(resp, rN) r0_perf = eval_fit(resp, pred) cc_rN_all = np.empty((resp.shape[1], resp.shape[2], resp.shape[-1])) cc_r0_all = np.empty((resp.shape[1], resp.shape[2], resp.shape[-1])) for i in range(0, resp.shape[1]): for stim in range(0, resp.shape[2]): for cell in range(0, resp.shape[-1]): cc_rN_all[i, stim, cell] = np.corrcoef(rN[:, i, stim, cell], resp[:, i, stim, cell])[0][1] cc_r0_all[i, stim, cell] = np.corrcoef(pred[:, i, stim, cell], resp[:, i, stim, cell])[0][1] cc_rN = np.mean(cc_rN_all[:, :, :], 1)