-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory_testbench.py
630 lines (557 loc) · 36.6 KB
/
memory_testbench.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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
import math
import configparser
import tools
import time
import numpy as np
def decimal_to_binary(num, list):
"""
Convert a decimal number to a list of the binary values
@param num: number to convert to binary
@param list: list to store the binary sequence
@return:
"""
if num >= 1:
decimal_to_binary(num // 2, list)
list.append(num % 2)
def decimal_to_binary_list(decimalList):
"""
Convert a list of decimal numbers to a list of binary numbers, each binary value is a list of 0's and 1's
@param decimalList: list of decimal values
@return:
"""
# Create the list of cues in binary
binaryValues = [[] for i in range(len(decimalList))]
for index, value in enumerate(decimalList):
# Get the binary representation of the current cue
decimal_to_binary(value, binaryValues[index])
return binaryValues
def complement_binary_list(binaryList):
"""
Complement all values in binary list
@param binaryList: list of binary values
@return:
"""
complementList = [[] for i in range(len(binaryList))]
for indexNeuron, binValues in enumerate(binaryList):
for value in binValues:
if value == 1:
complementList[indexNeuron].append(0)
else:
complementList[indexNeuron].append(1)
return complementList
def format_cue_vectors(binaryCueValues, cueSizeInBin):
"""
Format the input list of binary values to have the same size of numbers of neuron in the input cue population
@param binaryCueValues: input cue values in binary
@param cueSizeInBin: input cue size in binary
@return:
"""
for index in range(len(binaryCueValues)):
# Fix it to have cueSizeInBin binary numbers
if len(binaryCueValues[index]) < cueSizeInBin:
# If it has less values, fill with 0's at the begining
binaryCueValues[index] = [0] * (cueSizeInBin - len(binaryCueValues[index])) + binaryCueValues[index]
elif len(binaryCueValues[index]) > cueSizeInBin:
binaryCueValues[index] = binaryCueValues[index][len(binaryCueValues[index]) - cueSizeInBin:]
return binaryCueValues
def create_cue_input_vector(cue, binaryCueValues, currentOperationTime, operationTime, holdingTime, numOperations):
"""
Take a list of binary values to assign them to the correct cue neuron in the correct time stamp to do the operation
@param cue: cue values list
@param binaryCueValues: input cue values in binary
@param currentOperationTime: current units of time of the test
@param operationTime: array of units of time needed to get to the next operation
@param holdingTime: number of unit time to hold the value
@param numOperations: cont of the number of operation
@return:
"""
# Associate each binary value of each cue as an activation of a neuron input
for indexCue, inputBinaryCue in enumerate(binaryCueValues):
for indexValue, binaryValue in enumerate(inputBinaryCue):
# Only put "active" values (1 in binary)
if binaryValue == 1:
# Hold the values as time as the operation need
for holdingIndex in range(holdingTime):
cue[indexValue].append(currentOperationTime + holdingIndex)
# Add to the current operation time the minimum time to begin the next operation
currentOperationTime = currentOperationTime + operationTime
numOperations = numOperations + 1
return cue, numOperations, currentOperationTime
def create_alternate_cue_input_vector(cue, binaryCueValues, currentOperationTime, operationTime, holdingTime, numOperations):
"""
Take a list of binary values to assign them to the correct cue neuron in the correct time stamp to do the operation
adding 2 times the value once for writing and once for reading it
@param cue: cue values list
@param binaryCueValues: input cue size in binary values
@param currentOperationTime: current units of time of the test
@param operationTime: array of units of time needed to get to the next operation
@param holdingTime: number of unit time to hold the value
@param numOperations: cont of the number of operation
@return:
"""
# Associate each binary value of each cue as an activation of a neuron input
for indexCue, inputBinaryCue in enumerate(binaryCueValues):
# + For the writing operation
for indexValue, binaryValue in enumerate(inputBinaryCue):
# Only put "active" values (1 in binary)
if binaryValue == 1:
# Hold the values as time as the operation need
for holdingIndex in range(holdingTime[0]):
cue[indexValue].append(currentOperationTime + holdingIndex)
# Add to the current operation time the minimum time to begin the next operation
currentOperationTime = currentOperationTime + operationTime[0]
numOperations = numOperations + 1
# + For the reading operation
for indexValue, binaryValue in enumerate(inputBinaryCue):
# Only put "active" values (1 in binary)
if binaryValue == 1:
# Hold the values as time as the operation need
for holdingIndex in range(holdingTime[1]):
cue[indexValue].append(currentOperationTime + holdingIndex)
currentOperationTime = currentOperationTime + operationTime[1]
numOperations = numOperations + 1
return cue, numOperations, currentOperationTime
def create_cont_input_vector(cont, contBinValues, currentOperationTime, operationTime, holdingTime):
"""
Take a list of binary values to assign them to the correct content neuron in the correct time stamp to do the operation
@param cont: content values list
@param contBinValues: input cont size in binary
@param currentOperationTime: current units of time of the test
@param operationTime: array of units of time needed to get to the next operation
@param holdingTime: number of unit time to hold the value
@return:
"""
# Associate each binary value of each cue as an activation of a neuron input
for indexCont, contBinValue in enumerate(contBinValues):
for indexValue, binaryValue in enumerate(contBinValue):
# Only put "active" values (1 in binary)
if binaryValue == 1:
# Hold the values as time as the operation need
for holdingIndex in range(holdingTime):
cont[indexValue].append(currentOperationTime + holdingIndex)
# Add to the current operation time the minimum time to begin the next operation
currentOperationTime = currentOperationTime + operationTime
return cont, currentOperationTime
def create_input_vector_from_operations(cont, cue, operations, contBinValues, binaryCueValues, currentOperationTime, operationTime, holdingTime, numberOfOperations):
"""
Take a list of binary cue and cont values to assign them to the correct cont and cue neuron in the correct time
stamp to do the operations passed
@param cont: content values list
@param cue: cue values list
@param operations: operations to do
@param contBinValues: input cont size in binary
@param binaryCueValues: input cue size in binary values
@param currentOperationTime: current units of time of the test
@param operationTime: array of units of time needed to get to the next operation
@param holdingTime: number of unit time to hold the value
@param numberOfOperations: cont of the number of operation
@return:
"""
# For each operation:
for indexOperation, operation in enumerate(operations):
# Associate the cue values to neurons
for indexValue, binaryValue in enumerate(binaryCueValues[indexOperation]):
# Only put "active" values (1 in binary)
if binaryValue == 1:
# Hold the values as time as the operation need
for holdingIndex in range(holdingTime[operation]):
cue[indexValue].append(currentOperationTime + holdingIndex)
# Associate the memories values to neurons if writing operation
if operation == 0:
for indexValue, binaryValue in enumerate(contBinValues[indexOperation]):
# Only put "active" values (1 in binary)
if binaryValue == 1:
# Hold the values as time as the operation need
for holdingIndex in range(holdingTime[operation]):
cont[indexValue].append(currentOperationTime + holdingIndex)
# Add to the current operation time the minimum time to begin the next operation
currentOperationTime = currentOperationTime + operationTime[operation]
numberOfOperations = numberOfOperations + 1
return cue, cont, currentOperationTime, numberOfOperations
def tb_piramidal_sequence(cueSize, contSize, cueSizeInBin, readingOperationTime, readingOperationDataHolding, writingOperationTime, writingOperationDataHolding):
"""
Create the following sequence: for each cue write the cue as a memory, read all cues, write them
but complemented, read all cues, write them but complemented again and read all cues.
@param cueSize: Max number of patterns to store
@param contSize: Size of patterns to store (number of bits)
@param cueSizeInBin: input cue size in binary
@param readingOperationTime: Time to begin the next operation after a read operation
@param readingOperationDataHolding: Data holding time at the input for a reading operation
@param writingOperationTime: Time to begin the next operation after a write operation
@param writingOperationDataHolding: Data holding time at the input for a writing operation
@return:
"""
## 1) Writing all cues
# * Create the empty cue vector
cue = [[] for i in range(cueSizeInBin)]
# * Create the list of cues in decimal
decimalCue = [i + 1 for i in range(cueSize)]
# * Convert the cue from decimal to binary and fix it to the correct input size
binaryCue = format_cue_vectors(decimal_to_binary_list(decimalCue), cueSizeInBin)
# * Assign the binary values to each input cue neuron on the correct timestamp
currentOperationTime = 1
numOperations = 0
cue, numOperations, currentOperationTime = create_cue_input_vector(cue, binaryCue, currentOperationTime, writingOperationTime,
writingOperationDataHolding, numOperations)
# + Create the input cont activity vector
# * Create the empty cont vector
cont = [[] for i in range(contSize)]
# * Create the list of content in decimal
numOperationsCont = numOperations
decimalCont = [(i + 1) % (2 ** contSize) for i in range(numOperationsCont)]
# * Convert the cont from decimal to binary and fix it to the correct input size
binaryCont = format_cue_vectors(decimal_to_binary_list(decimalCont), contSize)
# * Generate the data to store
currentOperationTimeCont = 1
cont, currentOperationTime = create_cont_input_vector(cont, binaryCont, currentOperationTimeCont, writingOperationTime,
writingOperationDataHolding)
## 2) Reading all cues
cue, numOperations, currentOperationTime = create_cue_input_vector(cue, binaryCue, currentOperationTime, readingOperationTime,
readingOperationDataHolding, numOperations)
## 3) Write the complementary of the current content
# * Cue
currentOperationTimeCont = currentOperationTime
cue, numOperations, currentOperationTime = create_cue_input_vector(cue, binaryCue, currentOperationTime,
writingOperationTime,
writingOperationDataHolding, numOperations)
# * Content (complemented)
binaryCont = complement_binary_list(binaryCont)
cont, currentOperationTime = create_cont_input_vector(cont, binaryCont, currentOperationTimeCont, writingOperationTime,
writingOperationDataHolding)
## 4) Read all cues
cue, numOperations, currentOperationTime = create_cue_input_vector(cue, binaryCue, currentOperationTime,
readingOperationTime,
readingOperationDataHolding, numOperations)
## 5) Write the complementary of the current content
# * Cue
currentOperationTimeCont = currentOperationTime
cue, numOperations, currentOperationTime = create_cue_input_vector(cue, binaryCue, currentOperationTime,
writingOperationTime,
writingOperationDataHolding, numOperations)
# * Content (complemented)
binaryCont = complement_binary_list(binaryCont)
cont, currentOperationTime = create_cont_input_vector(cont, binaryCont, currentOperationTimeCont,
writingOperationTime,
writingOperationDataHolding)
## 6) Read all cues
cue, numOperations, currentOperationTime = create_cue_input_vector(cue, binaryCue, currentOperationTime,
readingOperationTime,
readingOperationDataHolding, numOperations)
return cue, cont, currentOperationTime, numOperations
def tb_piramidal_reinforced(cueSize, contSize, cueSizeInBin, readingOperationTime, readingOperationDataHolding, writingOperationTime, writingOperationDataHolding):
"""
Create the following sequence: for each cue write the cue as a content and read it at the same time (reinforced writing),
read all cues, reinforced write them but complemented, read all cues, reinforced write them but complemented again
and read all cues.
@param cueSize: Max number of patterns to store
@param contSize: Size of patterns to store (number of bits)
@param cueSizeInBin: input cue size in binary
@param readingOperationTime: Time to begin the next operation after a read operation
@param readingOperationDataHolding: Data holding time at the input for a reading operation
@param writingOperationTime: Time to begin the next operation after a write operation
@param writingOperationDataHolding: Data holding time at the input for a writing operation
@return:
"""
# 1) Write and read all memories alternatively
# + Create the input cue activity vector
# * Create the empty cue vector
cue = [[] for i in range(cueSizeInBin)]
# * Create the list of cues in decimal
decimalCue = [i + 1 for i in range(cueSize)]
# * Convert the cue from decimal to binary and fix it to the correct input size
binaryCue = format_cue_vectors(decimal_to_binary_list(decimalCue), cueSizeInBin)
# * Assign the binary values to each input cue neuron on the correct timestamp
currentOperationTime = 1
numOperations = 0
cue, numOperations, currentOperationTime = create_alternate_cue_input_vector(cue, binaryCue, currentOperationTime,
[writingOperationTime,
readingOperationTime],
[writingOperationDataHolding,
readingOperationDataHolding],
numOperations)
# + Create the input cont activity vector
# * Create the empty cont vector
cont = [[] for i in range(contSize)]
# * Create the list of contents in decimal
numOperationsCont = int(numOperations / 2)
decimalCont = [(i + 1) % (2 ** contSize) for i in range(numOperationsCont)]
# * Convert the cont from decimal to binary and fix it to the correct input size
binaryCont = format_cue_vectors(decimal_to_binary_list(decimalCont), contSize)
# * Generate the data to store
currentOperationTimeCont = 1
cont, currentOperationTime = create_cont_input_vector(cont, binaryCont, currentOperationTimeCont,
writingOperationTime + readingOperationTime,
writingOperationDataHolding)
# 2) Read all cues
cue, numOperations, currentOperationTime = create_cue_input_vector(cue, binaryCue, currentOperationTime,
readingOperationTime,
readingOperationDataHolding, numOperations)
# 3) Write and read the complementary
# * Cue
currentOperationTimeCont = currentOperationTime
cue, numOperations, currentOperationTime = create_alternate_cue_input_vector(cue, binaryCue, currentOperationTime,
[writingOperationTime,
readingOperationTime],
[writingOperationDataHolding,
readingOperationDataHolding],
numOperations)
# * Content (complemented)
binaryCont = complement_binary_list(binaryCont)
cont, currentOperationTime = create_cont_input_vector(cont, binaryCont, currentOperationTimeCont,
writingOperationTime + readingOperationTime,
writingOperationDataHolding)
# 4) Read all cues
cue, numOperations, currentOperationTime = create_cue_input_vector(cue, binaryCue, currentOperationTime,
readingOperationTime,
readingOperationDataHolding, numOperations)
# 5) Write and read the complementary
# * Cue
currentOperationTimeCont = currentOperationTime
cue, numOperations, currentOperationTime = create_alternate_cue_input_vector(cue, binaryCue, currentOperationTime,
[writingOperationTime,
readingOperationTime],
[writingOperationDataHolding,
readingOperationDataHolding],
numOperations)
# * Content (complemented)
binaryCont = complement_binary_list(binaryCont)
cont, currentOperationTime = create_cont_input_vector(cont, binaryCont, currentOperationTimeCont,
writingOperationTime + readingOperationTime,
writingOperationDataHolding)
# 6) Read all cues
cue, numOperations, currentOperationTime = create_cue_input_vector(cue, binaryCue, currentOperationTime,
readingOperationTime,
readingOperationDataHolding, numOperations)
return cue, cont, currentOperationTime, numOperations
def tb_stress_reinforced(cueSize, contSize, cueSizeInBin, readingOperationTime, readingOperationDataHolding, writingOperationTime, writingOperationDataHolding):
"""
Create the same sequence that tb_piramidal_reinforced but adding at the end 3 reading of all cues and 3 reinforced
writings operations to try to stress the network
@param cueSize: Max number of patterns to store
@param contSize: Size of patterns to store (number of bits)
@param cueSizeInBin: input cue size in binary
@param readingOperationTime: Time to begin the next operation after a read operation
@param readingOperationDataHolding: Data holding time at the input for a reading operation
@param writingOperationTime: Time to begin the next operation after a write operation
@param writingOperationDataHolding: Data holding time at the input for a writing operation
@return:
"""
# 1) Write and read all memories alternatively
# + Create the input cue activity vector
# * Create the empty cue vector
cue = [[] for i in range(cueSizeInBin)]
# * Create the list of cues in decimal
decimalCue = [i + 1 for i in range(cueSize)]
# * Convert the cue from decimal to binary and fix it to the correct input size
binaryCue = format_cue_vectors(decimal_to_binary_list(decimalCue), cueSizeInBin)
# * Assign the binary values to each input cue neuron on the correct timestamp
currentOperationTime = 1
numOperations = 0
cue, numOperations, currentOperationTime = create_alternate_cue_input_vector(cue, binaryCue, currentOperationTime,
[writingOperationTime, readingOperationTime],
[writingOperationDataHolding,readingOperationDataHolding], numOperations)
# + Create the input cont activity vector
# * Create the empty cont vector
cont = [[] for i in range(contSize)]
# * Create the list of contents in decimal
numOperationsCont = int(numOperations/2)
decimalCont = [(i + 1) % (2 ** contSize) for i in range(numOperationsCont)]
# * Convert the cont from decimal to binary and fix it to the correct input size
binaryCont = format_cue_vectors(decimal_to_binary_list(decimalCont), contSize)
# * Generate the data to store
currentOperationTimeCont = 1
cont, currentOperationTime = create_cont_input_vector(cont, binaryCont, currentOperationTimeCont,
writingOperationTime + readingOperationTime,
writingOperationDataHolding)
# 2) Read all cues
cue, numOperations, currentOperationTime = create_cue_input_vector(cue, binaryCue, currentOperationTime,
readingOperationTime,
readingOperationDataHolding, numOperations)
# 3) Write and read the complementary
# * Cue
currentOperationTimeCont = currentOperationTime
cue, numOperations, currentOperationTime = create_alternate_cue_input_vector(cue, binaryCue, currentOperationTime,
[writingOperationTime, readingOperationTime],
[writingOperationDataHolding,readingOperationDataHolding], numOperations)
# * Content (complemented)
binaryCont = complement_binary_list(binaryCont)
cont, currentOperationTime = create_cont_input_vector(cont, binaryCont, currentOperationTimeCont,
writingOperationTime + readingOperationTime,
writingOperationDataHolding)
# 4) Read all cues
cue, numOperations, currentOperationTime = create_cue_input_vector(cue, binaryCue, currentOperationTime,
readingOperationTime,
readingOperationDataHolding, numOperations)
# 5) Write and read the complementary
# * Cue
currentOperationTimeCont = currentOperationTime
cue, numOperations, currentOperationTime = create_alternate_cue_input_vector(cue, binaryCue, currentOperationTime,
[writingOperationTime, readingOperationTime],
[writingOperationDataHolding,readingOperationDataHolding], numOperations)
# * Content (complemented)
binaryCont = complement_binary_list(binaryCont)
cont, currentOperationTime = create_cont_input_vector(cont, binaryCont, currentOperationTimeCont,
writingOperationTime + readingOperationTime,
writingOperationDataHolding)
# 6) Read all cues 3 times
for i in range(3):
cue, numOperations, currentOperationTime = create_cue_input_vector(cue, binaryCue, currentOperationTime,
readingOperationTime,
readingOperationDataHolding, numOperations)
# 7) Write and read all memories alternatively and complemented 3 times
for i in range(3):
# * Cue
currentOperationTimeCont = currentOperationTime
cue, numOperations, currentOperationTime = create_alternate_cue_input_vector(cue, binaryCue, currentOperationTime,
[writingOperationTime,
readingOperationTime],
[writingOperationDataHolding,
readingOperationDataHolding],
numOperations)
# * Content (complemented)
binaryCont = complement_binary_list(binaryCont)
cont, currentOperationTime = create_cont_input_vector(cont, binaryCont, currentOperationTimeCont,
writingOperationTime + readingOperationTime,
writingOperationDataHolding)
return cue, cont, currentOperationTime, numOperations
def tb_random_operations(cueSize, contSize, cueSizeInBin, readingOperationTime, readingOperationDataHolding, writingOperationTime, writingOperationDataHolding, numberOfOperations):
"""
Generate a random sequence of reading and writing operations with random cues and contents values in the limits
of the network parameters
@param cueSize: Max number of patterns to store
@param contSize: Size of patterns to store (number of bits)
@param cueSizeInBin: input cue size in binary
@param readingOperationTime: Time to begin the next operation after a read operation
@param readingOperationDataHolding: Data holding time at the input for a reading operation
@param writingOperationTime: Time to begin the next operation after a write operation
@param writingOperationDataHolding: Data holding time at the input for a writing operation
@param numberOfOperations: number of random operation for the random test
@return:
"""
# Create the vector of random operations: 0 = learning and 1 = recalling
operations = np.random.randint(0, 2, numberOfOperations)
numLearning = np.count_nonzero(operations==0)
numRecalling = np.count_nonzero(operations==1)
# Create the vector of random operations and content values
decimalCue = np.random.randint(1, cueSize + 1, numberOfOperations)
decimalCont = np.random.randint(1, 2 ** contSize, numberOfOperations)
# Convert the content and cue from decimal to binary and fix it to the correct input size
binaryCue = format_cue_vectors(decimal_to_binary_list(decimalCue), cueSizeInBin)
binaryCont = format_cue_vectors(decimal_to_binary_list(decimalCont), contSize)
# Create the empty cue and cont vector
cue = [[] for i in range(cueSizeInBin)]
cont = [[] for i in range(contSize)]
# Associate values to neurons
currentOperationTime = 1
numOperations = 0
cue, cont, currentOperationTime, numOperations = create_input_vector_from_operations(cont, cue, operations, binaryCont,
binaryCue, currentOperationTime,
[writingOperationTime,
readingOperationTime],
[writingOperationDataHolding,
readingOperationDataHolding],
numOperations)
return cue, cont, currentOperationTime, numOperations, numLearning, numRecalling
def testbench(cueSize, contSize, cueSizeInBin, readingOperationTime, readingOperationDataHolding, writingOperationTime, writingOperationDataHolding, tbPath, numberOfOperations):
"""
Call a battery of memory testbench to generate the input sequence to the spike memory
@param cueSize: Max number of patterns to store
@param contSize: Size of patterns to store (number of bits)
@param cueSizeInBin: input cue size in binary
@param readingOperationTime: Time to begin the next operation after a read operation
@param readingOperationDataHolding: Data holding time at the input for a reading operation
@param writingOperationTime: Time to begin the next operation after a write operation
@param writingOperationDataHolding: Data holding time at the input for a writing operation
@param tbPath: path to store the testbench
@param numberOfOperations: number of random operation for the random test
@return:
"""
# Create the directory to store the tb if it isn't exist
tools.check_and_create_folder(tbPath)
tbBasePath = tools.check_and_create_folder(tbPath + "tb_" + time.strftime("%Y_%m_%d__%H_%M_%S") + "/")
# Testbench 1 -> create a piramidal sequence of input
cue_seq, cont_seq, minTimeSim, numOperations = tb_piramidal_sequence(cueSize, contSize, cueSizeInBin, readingOperationTime, readingOperationDataHolding, writingOperationTime, writingOperationDataHolding)
print("Testbench 1: piramidal sequence")
print("Min simulation time to simulate all operations = " + str(minTimeSim) + " ms")
print("Num of operations = " + str(numOperations))
# Write the results
tb_data = "[input_cue]\nInputSpikesCue = " + str(cue_seq) + "\n[input_cont]\nInputSpikesCont = " + str(cont_seq)
tbFullPath = tools.check_and_create_folder(tbBasePath + "tb1_piramidal/")
path, filename = tools.write_file(tbFullPath, "input_spikes", ".ini", tb_data)
print(path + "\n\n")
# Testbench 2 -> create a piramidal sequence of input with reinforced writing (write and read in the same cue at the same time)
cue_seq, cont_seq, minTimeSim, numOperations = tb_piramidal_reinforced(cueSize, contSize, cueSizeInBin,
readingOperationTime,
readingOperationDataHolding,
writingOperationTime,
writingOperationDataHolding)
print("Testbench 2: piramidal sequence with reinforced writing")
print("Min simulation time to simulate all operations = " + str(minTimeSim) + " ms")
print("Num of operations = " + str(numOperations))
# Write the results
tb_data = "[input_cue]\nInputSpikesCue = " + str(cue_seq) + "\n[input_cont]\nInputSpikesCont = " + str(cont_seq)
tbFullPath = tools.check_and_create_folder(tbBasePath + "tb2_piramidal_reinforced/")
path, filename = tools.write_file(tbFullPath, "input_spikes", ".ini", tb_data)
print(path + "\n\n")
# Testbench 3 -> create alternate operation in memory (write and read in the same cue)
cue_seq, cont_seq, minTimeSim, numOperations = tb_stress_reinforced(cueSize, contSize, cueSizeInBin,
readingOperationTime,
readingOperationDataHolding,
writingOperationTime,
writingOperationDataHolding)
print("Testbench 3: stress the network with reinforced writing")
print("Min simulation time to simulate all operations = " + str(minTimeSim) + " ms")
print("Num of operations = " + str(numOperations))
# Write the results
tb_data = "[input_cue]\nInputSpikesCue = " + str(cue_seq) + "\n[input_cont]\nInputSpikesCont = " + str(cont_seq)
tbFullPath = tools.check_and_create_folder(tbBasePath + "tb3_stress_reinforced/")
path, filename = tools.write_file(tbFullPath, "input_spikes", ".ini", tb_data)
print(path + "\n\n")
# Testbench 4 -> random operations
cue_seq, cont_seq, minTimeSim, numOperations, numLearning, numRecalling = tb_random_operations(cueSize, contSize, cueSizeInBin,
readingOperationTime,
readingOperationDataHolding,
writingOperationTime,
writingOperationDataHolding, numberOfOperations)
print("Testbench 4: random operations")
print("Min simulation time to simulate all operations = " + str(minTimeSim) + " ms")
print("Num of operations = " + str(numOperations))
print(" - Learning = " + str(numLearning))
print(" - Recalling = " + str(numRecalling))
# Write the results
tb_data = "[input_cue]\nInputSpikesCue = " + str(cue_seq) + "\n[input_cont]\nInputSpikesCont = " + str(cont_seq)
tbFullPath = tools.check_and_create_folder(tbBasePath + "tb4_random_operations/")
path, filename = tools.write_file(tbFullPath, "input_spikes", ".ini", tb_data)
print(path + "\n\n")
if __name__ == "__main__":
# * Open configparser object interface to read config files
config = configparser.ConfigParser()
# + Check the active config file directory
config.read("config_files/configFileParameters.ini")
activeConfigFilePath = "config_files/" + eval(config["configFileParameters"]["activeConfigFiles"]) + "/"
# + Input memory parameters
config.read(activeConfigFilePath + "memory_config.ini")
# - Max number of patterns to store
cueSize = eval(config["memory"]["cueSize"])
# - Size of patterns to store (number of bits)
contSize = eval(config["memory"]["contSize"])
# - Calculate the input cue size in binary
cueSizeInBin = math.ceil(math.log2(cueSize + 1))
# + Memory times
config.read(activeConfigFilePath + "simulation_config.ini")
# - Time to begin the next operation after a read operation
readingOperationTime = eval(config["testbench"]["readingOperationTime"])
# - Time to begin the next operation after a write operation
writingOperationTime = eval(config["testbench"]["writingOperationTime"])
# + Data holding time at the input
# - Read
readingOperationDataHolding = eval(config["testbench"]["readingOperationDataHolding"])
# - Write
writingOperationDataHolding = eval(config["testbench"]["writingOperationDataHolding"])
# + Path to store the testbench txt
tbPath = eval(config["testbench"]["tbPath"])
# + Number of randoms operations for the random testbench
numberOfOperations = eval(config["testbench"]["numberOfOperations"])
# * Create battery of test input sequence
testbench(cueSize, contSize, cueSizeInBin, readingOperationTime, readingOperationDataHolding, writingOperationTime,
writingOperationDataHolding, tbPath, numberOfOperations)