-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtestLayers.py
385 lines (337 loc) · 13.2 KB
/
testLayers.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#Testing layers.py
#Mitchell Gronowitz
#Spring 2015
from layers import *
import cells
import random
import matplotlib.pyplot as plt
import math
#####Test 1: Random generation of glom activation levels (testing activateGL_Random())
#Graphical representations of above function
def testGraphGlomActivLvl(mean, sd):
"""Graphically represents the activation levels for all three distributions
given the same glomeruli level."""
_graphHelper("u",mean,sd)
_graphHelper("g",mean,sd)
_graphHelper("e",mean,sd)
def _graphHelper(sel, mean, sd):
"""Graphically represents the activation levels for distribution
specified by sel with mean and sd."""
gl = createGL(1000)
activateGL_Random(gl, sel, mean, sd)
#x-axis
x = [0.0,.1, .2, .3, .4, .5, .6, .7, .8, .9]
#Make the width .09 for each bar
w = [0.09,0.09,0.09,0.09,0.09,0.09,0.09,0.09,0.09,0.09]
#Creating y-axis
y = [0,0,0,0,0,0,0,0,0,0]
count = 0
while count < len(gl):
index = gl[count].getActiv()
index = int(index*10)
if index == 10:
index == 9
y[index] += 1
count += 1
plt.bar(x, y, w)
if sel == "u":
plt.title('Uniform distribution')
elif sel == "g":
plt.title("Gaussian Distribution")
else:
plt.title("Exponential Distribution")
plt.xlabel("Activation Level")
plt.ylabel("# of Glom at given Activation Range")
plt.show()
######Test 2: Generation of similar activation levels in a GL array (testing createGLArray())
#4 test cases: uniform star, uniform series, gaussian star, gaussian series
def testGraphGLArraySimilarity(gl, x, opt, sel, num=0, mean=0, sd=0 ):
"""Draws a graph of the euclidean distance between the activation levels
of the glomeruli in gl and the activation levels in the generated similar GLArray.
x=len(GLArray), opt = star/ser, sel = gaussian or uniform."""
inc = 1
y = []
while inc <= x:
y.append(inc)
inc += 1
layers = createGLArray(gl, x, opt, sel, num, mean, sd)
inc = 0
axis = []
assert x == len(layers), "Worst."
while inc < len(layers):
axis.append(euclideanDistance(gl,layers[inc]))
inc += 1
assert len(axis) == len(y), "AHHHH"
plt.plot(y, axis)
if opt == "ser":
plt.title("Similar Glomeruli Layer Activation Patterns: Series")
else:
plt.title("Similar Glomeruli Layer Activation Patterns: Star")
plt.xlabel("Odor")
plt.ylabel("Euclidean Distance from Original GL")
plt.show()
def testSimilar():
"""Using above functions to test activateGL_Random function"""
gl = createGL(2000)
activateGL_Random(gl, "u")
#Test series where incremented number was chosen uniformly
testGraphGLArraySimilarity(gl, 100, "ser", "u", .01, mean=0, sd=0 )
#Test series with gaussian
testGraphGLArraySimilarity(gl, 100, "ser", "g", .01, mean=.1, sd=.01 )
#Test star with uniform
testGraphGLArraySimilarity(gl, 100, "star", "u", .01, mean=0, sd=0 )
#Test stat with gaussian
testGraphGLArraySimilarity(gl, 100, "star", "g", .01, mean=.1, sd=.01)
######Test 3: Testing Map building (Testing CreateMCLSamplingMap())
def testMapBuidling():
"""Tests createMCLSamplingMap()"""
gl = createGL(5)
mcl = createMCL(5)
print '\n' + "Testing a fixed simple sampling map with cr=3" + '\n'
Map = createMCLSamplingMap(gl, mcl, 3, True, "simple")
for elem in Map:
print "Mitral: " + str(elem[0]) + " Glom: " + str(elem[1]) + " Weight: " + str(elem[2])
print '\n' + "Testing an unfixed simple sampling map with cr=3, sd=2" '\n'
Map = createMCLSamplingMap(gl, mcl, 3, False, "simple", 2, "lin")
for elem in Map:
print "Mitral: " + str(elem[0]) + " Glom: " + str(elem[1]) + " Weight: " + str(elem[2])
print '\n' + "Testing a fixed bias linear sampling map with cr=3" + '\n'
Map = createMCLSamplingMap(gl, mcl, 3, True, "bias", 2, "lin")
for elem in Map:
print "Mitral: " + str(elem[0]) + " Glom: " + str(elem[1]) + " Weight: " + str(elem[2])
print '\n' + "Testing an unfixed bias linear sampling map with cr=3, sd=2" + '\n'
Map = createMCLSamplingMap(gl, mcl, 3, False, "bias", 2, "lin")
for elem in Map:
print "Mitral: " + str(elem[0]) + " Glom: " + str(elem[1]) + " Weight: " + str(elem[2])
print '\n' + "Testing a fixed bias exp sampling map with cr=3" + '\n'
Map = createMCLSamplingMap(gl, mcl, 3, True, "bias", 2, "exp")
for elem in Map:
print "Mitral: " + str(elem[0]) + " Glom: " + str(elem[1]) + " Weight: " + str(elem[2])
print '\n' + "Testing an unfixed bias exp sampling map with cr=3, sd=2" + '\n'
Map = createMCLSamplingMap(gl, mcl, 3, False, "bias", 2, "exp")
for elem in Map:
print "Mitral: " + str(elem[0]) + " Glom: " + str(elem[1]) + " Weight: " + str(elem[2])
def testCreateandLoadFile():
"""Tests createMCLSamplingMap() and loadMCLSamplingMap()"""
#commented out so only MCL load and store is tested
"""print "Testing GL store and load"
gl = createGL(5)
activateGL_Random(gl, "u")
saveGL(gl, "test")
gl2 = loadGL("test.GL")
inc = 0
Bool = True
while inc < len(gl):
if gl[inc].getId() != gl2[inc].getId() or gl[inc].getActiv() != gl2[inc].getActiv():
Bool = False
if gl[inc].getConn() != gl2[inc].getConn() or gl[inc].getLoc()[0] != gl2[inc].getLoc()[0]:
Bool = False
inc+=1
print str(Bool)
print "Testing Map store and load"
gl = createGL(5)
mcl = createMCL(3)
Map = createMCLSamplingMap(gl, mcl, 3, True, "simple")
saveMCLSamplingMap(Map, "test")
Map2 = loadMCLSamplingMap("test.mapGLMCL")
Same = True
inc = 0
while inc < len(Map):
if Map[inc][0] != Map2[inc][0]:
Same = False
print "MCL not equal"
if Map[inc][1] != Map2[inc][1]:
Same = False
print "GL not equal"
####Weights not checked due to rounding issues
inc+=1
print str(Same)"""
print "Testing MCL store and load"
gl = createGL(10)
mcl = createMCL(6)
Map = createMCLSamplingMap(gl, mcl, 4, True, "simple")
ActivateMCLfromGL(gl, mcl, "add", Map)
saveMCL(mcl, "testmcl")
mcl2 = loadMCL("testmcl.mcl")
print "mcl1:"
for m in mcl:
print m
print "mcl2:"
for m in mcl2:
print m
def testApplyMCLSamplingMap():
"""Tests building the connections btwn MCL and GL (created with total number of gloms) given a map"""
gl = createGL(5)
activateGL_Random(gl, "u")
mcl = createMCL(5)
Map = createMCLSamplingMap(gl, mcl, 4, True, "simple")
#print Map
for elem in Map:
print "Mitral: " + str(elem[0]) + " Glom: " + str(elem[1]) + " Weight: " + str(elem[2])
ApplyMCLSamplingMap(gl,mcl,Map)
for mitral in mcl:
print mitral
for glom in gl:
print str(glom) + " # of connections: " + str(glom.getConn())
print "items returns: " + str(mcl[0].getGlom().items())
print "items returns: " + str(mcl[1].getGlom().items())
print "items returns: " + str(mcl[2].getGlom().items())
print "items returns: " + str(mcl[3].getGlom().items())
print "items returns: " + str(mcl[4].getGlom().items())
def testApplyMCLSamplingMapBalanced():
"""Tests building the connections btwn MCL and GL (created with dimensions) given a map using BALANCED RANDOM"""
gl = createGL_dimensions(4,2)
activateGL_Random(gl, "u")
mcl = createMCL(8)
Map = createMCLSamplingMap(gl, mcl, 4, True, "balanced")
#print Map
for elem in Map:
print "Mitral: " + str(elem[0]) + " Glom: " + str(elem[1]) + " Weight: " + str(elem[2])
ApplyMCLSamplingMap(gl,mcl,Map)
for mitral in mcl:
print mitral
print mitral.getLoc()
for glom in gl:
print str(glom) + " # of connections: " + str(glom.getConn())
print glom.getLoc()
print "items returns: " + str(mcl[0].getGlom().items())
print "items returns: " + str(mcl[1].getGlom().items())
print "items returns: " + str(mcl[2].getGlom().items())
print "items returns: " + str(mcl[3].getGlom().items())
print "items returns: " + str(mcl[4].getGlom().items())
print "items returns: " + str(mcl[5].getGlom().items())
print "items returns: " + str(mcl[6].getGlom().items())
print "items returns: " + str(mcl[7].getGlom().items())
def testApplyMCLSamplingMapLocation():
"""Tests building the connections btwn MCL and GL (created with dimensions) given a map using LOCATION"""
gl = createGL_dimensions(4,4)
activateGL_Random(gl, "u")
mcl = createMCL(4)
Map = createMCLSamplingMap(gl, mcl, 10, True, "location")
#print Map
for elem in Map:
print "Mitral: " + str(elem[0]) + " Glom: " + str(elem[1]) + " Weight: " + str(elem[2])
ApplyMCLSamplingMap(gl,mcl,Map)
ActivateMCLfromGL(gl, mcl, "add", Map, "None")
for mitral in mcl:
print mitral
print mitral.getLoc()
for glom in gl:
print str(glom) + " # of connections: " + str(glom.getConn())
print glom.getLoc()
print "items returns: " + str(mcl[0].getGlom().items())
print "items returns: " + str(mcl[1].getGlom().items())
print "items returns: " + str(mcl[2].getGlom().items())
print "items returns: " + str(mcl[3].getGlom().items())
# print "items returns: " + str(mcl[4].getGlom().items())
# print "items returns: " + str(mcl[5].getGlom().items())
# print "items returns: " + str(mcl[6].getGlom().items())
# print "items returns: " + str(mcl[7].getGlom().items())
print "\ndone"
def testGraphGlomActivation():
""" """
gl = createGL_dimensions(10,10)
activateGL_Random(gl, "u")
GraphGlomActivation(gl, gl[0].getDim()[1], gl[0].getDim()[0])
def testGraphMitralActivation():
""" """
gl = createGL_dimensions(4,4)
activateGL_Random(gl, "u")
mcl = createMCL(10)
Map = createMCLSamplingMap(gl, mcl, 10, True, "location")
#print Map
for elem in Map:
print "Mitral: " + str(elem[0]) + " Glom: " + str(elem[1]) + " Weight: " + str(elem[2])
ApplyMCLSamplingMap(gl,mcl,Map)
ActivateMCLfromGL(gl, mcl, "add", Map, "None")
for mitral in mcl:
print mitral
print mitral.getLoc()
for glom in gl:
print str(glom) + " # of connections: " + str(glom.getConn())
print glom.getLoc()
GraphMitralActivation(gl, mcl, 4, 4)
def testActivateMCLfromGL():
"""Testing ActivateMCLfromGL"""
gl = createGL(6)
activateGL_Random(gl, "u")
mcl = createMCL(6)
Map = createMCLSamplingMap(gl, mcl, 3, True, "simple")
for elem in Map:
print "Mitral: " + str(elem[0]) + " Glom: " + str(elem[1]) + " Weight: " + str(elem[2])
print "\n testing add:" + '\n'
ActivateMCLfromGL(gl, mcl, "add", Map, "None")
print "glom: "
for glom in gl:
print glom
# print "OH HELLO " + str(glom.getLoc()[0])
x = 0
#print '\n' + "map: "
#while x<4:
# print Map[x]
# x += 1
print '\n' + "mitral: "
for mitral in mcl:
print mitral
print "\n testing avg:"
ActivateMCLfromGL(gl, mcl, "avg", Map, "u", .01,.01)
print '\n' +"glom: "
for glom in gl:
print glom
x = 0
#print '\n' + "map: "
#while x<4:
# print Map[x]
# x += 1
print '\n' + "mitral: "
for mitral in mcl:
print mitral
def testNormalization():
"""Tests the normalize function"""
mcl = createMCL(6)
mcl[0]._activ = 1.5
mcl[1]._activ = 1
mcl[2]._activ = 1.2
mcl[3]._activ = .3
mcl[4]._activ = .1
mcl[5]._activ = .5
mcl = normalize(mcl)
for m in mcl:
print m
def testgraphLayer():
"""Testing graphLayer for GL then MCL"""
gl = createGL(20)
activateGL_Random(gl, "u")
mcl = createMCL(15)
Map = createMCLSamplingMap(gl, mcl, 4, True, "simple")
ActivateMCLfromGL(gl, mcl, "add", Map, "u", .05)
st = ""
ind = 0
while ind < len(gl):
st = st + str(ind) + ": " + str(gl[ind].getActiv()) + " "
ind += 1
print st
graphLayer(gl, False)
graphLayer(mcl, True)
def testColorMap():
gl = createGL(4)
activateGL_Random(gl, "u")
mcl = createMCL(5)
Map = createMCLSamplingMap(gl, mcl, 2, True, "simple")
ActivateMCLfromGL(gl, mcl, "add", Map, "u", .05)
colorMapWeights(Map,gl,mcl)
def test():
# testGraphGlomActivLvl(.5,.2) #Testing assigning random activation levels to glomeruli
#testSimilar() #Testing assigning similar activation levels to glom array
# testMapBuidling()
#testCreateandLoadFile()
# testApplyMCLSamplingMap()
# testApplyMCLSamplingMapBalanced()
# testApplyMCLSamplingMapLocation()
# testGraphGlomActivation()
testGraphMitralActivation()
# testActivateMCLfromGL()
#testNormalization()
#testgraphLayer()
#testColorMap()
test()