-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstc.py
27 lines (22 loc) · 902 Bytes
/
stc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue May 16 13:28:17 2017
@author: ycan
Spike-triggered covariance
"""
from datetime import datetime
execution_timer=datetime.now()
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):
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))