From 07825213a54f628d661fd9bcb8218ef5dacdf119 Mon Sep 17 00:00:00 2001 From: ycanerol Date: Tue, 23 May 2017 15:39:17 +0200 Subject: [PATCH] Add NLT recovery to STC function. Fix index problem in model, now able to recover NLT from different eigenvectors --- __pycache__/lnp.cpython-36.pyc | Bin 2066 -> 2857 bytes lnp.py | 17 +++++++++++++++-- stc.py | 2 +- with_real_data.py | 26 ++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/__pycache__/lnp.cpython-36.pyc b/__pycache__/lnp.cpython-36.pyc index 0b8702c5f86c4758446aba722b90585a98d1468f..2f28bd96876bfd9b100766d75f5015b3e5e071a8 100644 GIT binary patch delta 1231 zcmZXTOKVd>6vt=gz9#pPm$6N7)dxbLDx&zJma4Vxx)CXrma3VgB#lWsxeY~5$RgIA zpl0pHow(AE;KvB=ToreI0P8uEv|jLD=ASwLIWv=)-?<;MpQq-oMUnsM&iuyj3}Zi8 z;<2&6jIHzR{oM7dT=^=e@;kN)YeGdT{hB|OirjOmFmW>~i*8DZ$E&wg$H1CDxONuVTx@Vufurdnp`G zm6#H{mR`Wj6uzR!lzU`hwhun8XM^7dIS?QVtcWIB4)`F8Y{0SaDyG;GZio{C@XUmu z;X!~i%;E($&3fMc!aBoI2{=pfBD;Vd=B64xcmuvEdSNfZIDinxaYf~szmSFy(xpD@ zg%FK5g0$I+k~vs$2+n|;(`Jn0CY+*S|7Nwl>OFH z3`D^CicjMi(auc%M5-nhS)9fbCLFv-2ke2pDIlB7gIqFt$IV^ffglUHnvIa<+88hb zWFxzF&}^3Z$bQ*YRecF99XO;U<;?Jl`*3+=HLIu8ic1daGl4>CRq#w_0f*v|@^f zTVBbfEtnXBSL$1Nj<3k`DK7Y|SQMJ-uR?`LkB{xFD8FMcK_&2R#;9E5I9Q&i4%GsO zq$3R~laWAW$Bycof&=@MRqW#TBZyV(1x#5JRFlGlF)G=hT2FWg%Z_~m%S++`nT+;V z)^RsPITSyOg{{ zVrbo>-VDhy$vu+$Bsr3Tk>M{db=yTQ+pXpXIvs+|5XTrw5s~OsbdLX=oSc}d(T^}3 g*N;E^=q&Sr>l6zS5!6-?3sJOkx#F}jcZJA=E8>Bz=2uu) zh<`?G{R8?Be2EtBvTtYJdo%m-Jo}Wi*W=i{FLzGki0G644Mx0+HQat|Z^Xt$_jINm zA5+)9K6L!?rT=G+u~+e4W&Q$;XrP3J`&_8pAF+^BxmPrtny0*ZdpGjxocHPCIuD=+ z^W^x-%X)AInA{@gO+2`@X!L7{mS(}yOsNG9%-FA}78MFf(~+YI4n#pHeq9g_0tr!4 zH&1Dfa{s1xLQu7!%BdDDf`d0481V~r&bi4WOgAy-;rJqung6v>Ij*eR#vsH6SGm+ diff --git a/lnp.py b/lnp.py index cee0e43..e22c27e 100644 --- a/lnp.py +++ b/lnp.py @@ -51,7 +51,8 @@ def q_nlt_recovery(spikes, filtered_recovery, bin_nr, dt): return quantiles, spikecount_in_bins -def stc(spikes, stimulus, filter_length, total_frames, dt): +def stc(spikes, stimulus, filter_length, total_frames, dt, + eigen_indices=[0, 1, -2, -1], bin_nr=60): covariance = np.zeros((filter_length, filter_length)) sta_temp = sta(spikes, stimulus, filter_length, total_frames)[1] # Unscaled STA @@ -70,4 +71,16 @@ def stc(spikes, stimulus, filter_length, total_frames, dt): eigenvalues = eigenvalues[sorted_eig] eigenvectors = eigenvectors[:, sorted_eig] - return eigenvalues, eigenvectors + # Calculating nonlinearities + generator_stc = np.zeros((total_frames, len(eigen_indices))) + bins_stc = np.zeros((bin_nr, len(eigen_indices))) + spikecount_stc = np.zeros((bin_nr, len(eigen_indices))) + + for i in range(len(eigen_indices)): + generator_stc[:, i] = np.convolve(eigenvectors[:, eigen_indices[i]], + stimulus, + mode='full')[:-filter_length+1] + bins_stc[:, i], spikecount_stc[:, i] = \ + q_nlt_recovery(spikes, generator_stc[:, i], 60, dt) + + return eigenvalues, eigenvectors, bins_stc, spikecount_stc diff --git a/stc.py b/stc.py index c3fb615..5997ed1 100644 --- a/stc.py +++ b/stc.py @@ -43,7 +43,7 @@ def stc(spikes, stimulus, filter_length, total_frames): filtered_recovery_stc1 = np.convolve(v[:, eigen_indices[0]], stimulus, mode='full')[:-filter_length+1] -filtered_recovery_stc2 = np.convolve(v[:, eigen_indices[0]], stimulus, +filtered_recovery_stc2 = np.convolve(v[:, eigen_indices[1]], stimulus, mode='full')[:-filter_length+1] logbins_stc1, spikecount_in_logbins_stc1 = log_nlt_recovery(spikes, diff --git a/with_real_data.py b/with_real_data.py index 06d99d7..7a3f8af 100644 --- a/with_real_data.py +++ b/with_real_data.py @@ -10,7 +10,7 @@ Importing lnp only works if the directory containing LNP functions is added to the python path variable like the following. -sys.path.append('/Users/ycan/Documents/official/gottingen/lab rotations \ +sys.path.append('/Users/ycan/Documents/official/gottingen/lab rotations\ /LR3 Gollisch/scripts/') This only needs to be done once. @@ -62,17 +62,35 @@ generator = np.convolve(sta, stimulus, mode='full')[:-filter_length+1] -logbins_sta, spikecount_in_logbins_sta = lnp.q_nlt_recovery(spikes, generator, +bins_sta, spikecount_sta = lnp.q_nlt_recovery(spikes, generator, 60, dt) plt.plot(sta) plt.show() -plt.scatter(logbins_sta,spikecount_in_logbins_sta,s=6,alpha=.6) +plt.plot(bins_sta,spikecount_sta,'.',alpha=.6) plt.show() #%% -w, v = lnp.stc(spikes, stimulus, filter_length, total_frames, dt) +w, v, bins_stc, spikecount_stc = lnp.stc(spikes, stimulus, + filter_length, total_frames, dt) + +#eigen_indices = [0, 1, -2, -1] # First two, last two eigenvalues +# +#bin_nr = 60 +# +#generator_stc = np.zeros((total_frames, len(eigen_indices))) +#bins_stc = np.zeros((bin_nr, len(eigen_indices))) +#spikecount_stc = np.zeros((bin_nr, len(eigen_indices))) +# +#for i in range(len(eigen_indices)): +# generator_stc[:, i] = np.convolve(v[:, eigen_indices[i]], stimulus, +# mode='full')[:-filter_length+1] +# bins_stc[:, i], spikecount_stc[:, i] = lnp.q_nlt_recovery(spikes, +# generator_stc[: ,i], +# 60, dt) +plt.plot(bins_stc, spikecount_stc) +plt.plot(w,'.') # #eigen_indices=np.where(np.abs(w-1)>.05)[0] #manual_eigen_indices = [0, -1]