-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiOdorTest.py
56 lines (48 loc) · 1.57 KB
/
multiOdorTest.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
from lib import epl
from lib import OSN
from lib import readout
from lib import plots
import numpy as np
import pickle
#Load Data
rf = open('./data/multiOdorTest.pi', 'rb');
trainingOdors = np.array(pickle.load(rf));
testOdors = np.array(pickle.load(rf));
rf.close();
nOdors = len(trainingOdors);
nTestPerOdor = len(testOdors)/nOdors;
print("Number of odors to train = " + str(len(trainingOdors)));
print("Number of odors to test = " + str(len(testOdors)));
#Network initialization
nMCs = len(trainingOdors[0]);
GCsPerNeurogenesis = 5;
nGCs = nMCs*GCsPerNeurogenesis*nOdors; #every MC has 5 GCs per odor
epl = epl.EPL(nMCs, nGCs, GCsPerNeurogenesis);
#Sniff
def sniff(odor, learn_flag=0, nGammaPerOdor=5, gPeriod=40):
sensorInput = OSN.OSN_encoding(odor);
for j in range(0, nGammaPerOdor):
for k in range(0, gPeriod):
epl.update(sensorInput, learn_flag=learn_flag);
pass;
epl.reset();
#Training
t1 = time.time();
for i in range(0, len(trainingOdors)):
print("Training odor " + str(i+1))
sniff(trainingOdors[i], learn_flag=1);
epl.GClayer.invokeNeurogenesis();
sniff(trainingOdors[i], learn_flag=0);
#Testing
for i in range(0, len(testOdors)):
sniff(testOdors[i], learn_flag=0);
if(i%10==0 and i!=0):
print(str(i) + " odors tested");
t2 = time.time();
print("Simulation Duration = " + str(t2-t1) + "s")
#Readout
sMatrix = readout.readout(epl.gammaCode, nOdors, nTestPerOdor)
#Plots
plots.plotFigure4a(epl.gammaCode);
plots.plotFigure4b(sMatrix);
plots.plotFigure4d(epl.gammaCode, sMatrix);