Skip to content

Commit

Permalink
- Add timer for LNP model
Browse files Browse the repository at this point in the history
- Iterative plotting for STC recovered filters
  • Loading branch information
ycanerol committed May 18, 2017
1 parent a64541d commit 095e74f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
18 changes: 12 additions & 6 deletions LNP_model
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ Created on Tue May 9 18:11:51 2017
# %%
import numpy as np
from scipy.stats.mstats import mquantiles
from datetime import datetime

total_frames = 400000
execution_timer = datetime.now()

total_frames = 100000
dt = 0.01 # Time step
t = np.arange(0, total_frames*dt, dt) # Time vector
filter_time = .6 # The longest feature RGCs respond to is ~600ms
Expand All @@ -21,10 +24,10 @@ cweight = .5 # The weight of combination for the two filters
def make_noise(): # Generate gaussian noise for stimulus
return np.random.normal(0, 1, total_frames)

stimulus = make_noise()
#stimulus = make_noise()

filter_index1 = 3 # Change filter type here
filter_index2 = 1
filter_index1 = 4 # Change filter type here
filter_index2 = 3


def linear_filter(t, filter_index): # Define filter according to choice
Expand All @@ -49,8 +52,8 @@ filtered2 = np.convolve(filter_kernel2, stimulus,
mode='full')[:-filter_length+1]

k = np.linspace(-5, 5, 1001)
nlt_index1 = 2
nlt_index2 = 4
nlt_index1 = 6
nlt_index2 = 6

# %%
def nlt(k, nlt_index):
Expand Down Expand Up @@ -123,3 +126,6 @@ for i in range(bin_nr): # Sorts values into bins
(bindices == i)])))

runfile('/Users/ycan/Documents/official/gottingen/lab rotations/LR3 Gollisch/scripts/plotLNP.py', wdir='/Users/ycan/Documents/python')

runtime = str(datetime.now()-execution_timer).split('.')[0]
print('Duration: {}'.format(runtime))
4 changes: 2 additions & 2 deletions plotLNP.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
fig = plt.figure(figsize=(8, 8.5))

plt.subplot(rows, columns, 1)
plt.plot(filter_kernel1, alpha=.2)
plt.plot(filter_kernel1, alpha=.4)
#plt.title()

plt.subplot(rows, columns, 1)
plt.plot(filter_kernel2, alpha=.2)
plt.plot(filter_kernel2, alpha=.4)

plt.subplot(rows, columns, 1)
plt.plot(cweight*filter_kernel1+(1-cweight)*filter_kernel2, alpha=.6)
Expand Down
19 changes: 10 additions & 9 deletions stc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
Spike-triggered covariance
"""
from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt
execution_timer = datetime.now()

sta_temp = sta(spikes, stimulus, filter_length)

Expand All @@ -21,14 +19,12 @@ def stc(spikes, stimulus, filter_length, sta_temp):
if spikes[i] != 0:
snippet = stimulus[i:i-filter_length:-1]
# Snippets are inverted before being added
snpta = np.array(snippet-sta_temp)[np.newaxis,:]
snpta = np.array(snippet-sta_temp)[np.newaxis, :]
covariance = covariance+np.dot(snpta.T, snpta)*spikes[i]
return covariance/(sum(spikes)-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))

# %%
w, v = np.linalg.eig(recovered_stc)
Expand All @@ -44,11 +40,16 @@ def stc(spikes, stimulus, filter_length, sta_temp):
plt.xlabel('Eigenvalue index')
plt.ylabel('Variance')

eigen_indices = [0, 1, 2]
eigen_legends = []

plt.subplot(1, 2, 2)
plt.plot(v[:, 0])
plt.plot(v[:, 1])
plt.plot(recovered_kernel)
plt.legend(['Eigenvector 0', 'Eigenvector 1', 'STA'], fontsize='x-small')
for i in eigen_indices:
plt.plot(v[:, i])
eigen_legends.append(str('Eigenvector '+str(i)))
plt.plot(recovered_kernel,':')
eigen_legends.append('STA')
plt.legend(eigen_legends, fontsize='x-small')
plt.title('Filters recovered by STC')
plt.xlabel('?')
plt.ylabel('?')
Expand Down
6 changes: 3 additions & 3 deletions zoooftransformations
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Zoo of linear filters and non-linear transformations
import matplotlib.pyplot as plt
import matplotlib

rows = 1
columns = 2
fig = plt.figure(figsize=(12, 4))
rows = 2
columns = 1
fig = plt.figure(figsize=(6, 8))

plt.subplot(rows, columns, 1)
filter_legends = []
Expand Down

0 comments on commit 095e74f

Please sign in to comment.