-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq3_new.py
61 lines (44 loc) · 1.89 KB
/
q3_new.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import parameters_q3_new as p
from injectIntoSingleNeurone import *
import matplotlib.pyplot as plt
import numpy as np
from copy import deepcopy
from itertools import product
from plotting import *
plt.close("all")
def generateNeuronalPopulation():
return [deepcopy(p.singleNeuron) for i in range(p.populationSize)]
def generateCurrentToInject():
if(p.plotGraphsForQuestion == 1):
print("Not configured question 1 plotting.")
pass
else:
return np.ones(p.timeSteps.size) * (0.5*p.I_0*(1 + np.cos(2*np.pi*p.f*p.timeSteps)))
def splitActivityIntoBins(neuronalPopulation):
binnedSpikes = np.mean([n['isSpikingAtTime'].reshape(
p.binWidth, -1).sum(axis=1) for n in neuronalPopulation], axis=0)
return binnedSpikes
def plotQuestion1(currentToInject):
# Question 1
plt.figure()
plt.plot(p.timeSteps, currentToInject)
plt.xlabel('time (s)')
plt.ylabel('I_ext (A)')
plt.title('Current injected (I_ext) into each neurone over time')
currentToInject = generateCurrentToInject()
# Loop through each seed and coEfficientVariation
for coEfficientOfVariation in p.coEfficientOfVariations:
binnedSpikesBySeed = np.zeros((len(p.seeds), p.binnedTime.size))
for seedIndex, seed in enumerate(p.seeds):
p.setSeed(seed)
neuronalPopulation = [p.generateNeurone(scale=p.getSd(
coEfficientOfVariation)) for i in range(p.populationSize)]
for neuroneIndex, neurone in enumerate(neuronalPopulation):
print('Injecting neurone: '+str(neuroneIndex) +
'/'+str(len(neuronalPopulation)))
neurone = injectIntoSingleNeuron(neurone=neurone, current=currentToInject)
binnedSpikesBySeed[seedIndex] = splitActivityIntoBins(neuronalPopulation)
plotQuestion2(binnedSpikesBySeed, neuronalPopulation)
# Question 3
plotQuestion3()
plt.show()