diff --git a/LNP_model b/LNP_model index 37194ba..ac84f4b 100644 --- a/LNP_model +++ b/LNP_model @@ -9,19 +9,19 @@ Created on Tue May 9 18:11:51 2017 import numpy as np from scipy.stats.mstats import mquantiles -total_frames=400000 +total_frames=10000 dt=0.001 # Time step t=np.arange(0,total_frames*dt,dt) # Time vector filter_time=.6 # The longest feature RGCs respond to is ~600ms filter_length=int(filter_time/dt) # Filter is filter_length frames long -cweight=.5 # The weight of combination for the two filters +cweight=1 # The weight of combination for the two filters def make_noise(): # Generate gaussian noise for stimulus return np.random.normal(0,9,total_frames) -stimulus=make_noise() +#stimulus=make_noise() -filter_index1=1 # Change filter type here +filter_index1=2 # Change filter type here filter_index2=1 def linear_filter(t,filter_index): # Define filter according to choice diff --git a/stc.py b/stc.py index aef2ad3..ff05260 100644 --- a/stc.py +++ b/stc.py @@ -7,13 +7,21 @@ Spike-triggered covariance """ +from datetime import datetime +execution_timer=datetime.now() -def stc(spikes,stimulus,filter_length): - covariance=np.matrix(np.zeros(filter_length,filter_length)) - sta=sta(spikes,stimulus,filter_length) +sta_temp=sta(spikes,stimulus,filter_length) +def stc(spikes,stimulus,filter_length,sta_temp): + covariance=np.matrix(np.zeros((filter_length,filter_length))) + for i in range(filter_length,total_frames): - snippet=stimulus[i:i-filter_length:-1] - # Snippets are inverted before being added - snpta=[snippet-sta] - covariance=covariance+snpta.T*snpta*spikes[i] - return covariance/fil \ No newline at end of file + if spikes[i]!=0: + snippet=stimulus[i:i-filter_length:-1] + # Snippets are inverted before being added + snpta=np.matrix(snippet-sta_temp) + covariance=covariance+(snpta.T*snpta)*spikes[i] + return covariance/(sum(spikes)+filter_length-1) + +recovered_stc=stc(spikes,stimulus,filter_length,sta(spikes,stimulus,filter_length)) +runtime=str(datetime.now()-execution_timer).split('.')[0] +print('Duration: {}'.format(runtime))