-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsim.py
2180 lines (2053 loc) · 110 KB
/
sim.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
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from netpyne import specs, sim
from neuron import h
import numpy as np
import random
from random import randint, sample
from conf import dconf # configuration dictionary
import pandas as pd
import pickle
from collections import OrderedDict
from connUtils import *
from matplotlib import pyplot as plt
import os
import time
import anim
from matplotlib import animation
from cells import intf7
random.seed(1234) # this will not work properly across runs with different number of nodes
sim.davgW = {} # average adjustable weights on a target population
sim.allTimes = []
sim.allRewards = [] # list to store all rewards
sim.allActions = [] # list to store all actions
sim.allProposedActions = [] # list to store all proposed actions
sim.allHits = [] #list to store all hits
sim.allMotorOutputs = [] # list to store firing rate of output motor neurons.
sim.followTargetSign = [] # whether racket moved closer (1) or farther (-1) from y intercept target at each step
sim.ActionsRewardsfilename = 'data/'+dconf['sim']['name']+'ActionsRewards.txt'
sim.MotorOutputsfilename = 'data/'+dconf['sim']['name']+'MotorOutputs.txt'
sim.WeightsRecordingTimes = []
sim.allRLWeights = [] # list to store weights --- should remove that
sim.allNonRLWeights = [] # list to store weights --- should remove that
sim.topologicalConns = dict() # dictionary to save topological connections.
sim.lastMove = dconf['moves']['NOMOVE']
#sim.NonRLweightsfilename = 'data/'+dconf['sim']['name']+'NonRLweights.txt' # file to store weights
sim.plotWeights = 0 # plot weights
sim.saveWeights = 1 # save weights
if 'saveWeights' in dconf['sim']: sim.saveWeights = dconf['sim']['saveWeights']
sim.saveInputImages = 1 #save Input Images (5 game frames)
sim.saveMotionFields = dconf['sim']['saveMotionFields'] # whether to save the motion fields
sim.saveObjPos = 1 # save ball and paddle position to file
sim.saveAssignedFiringRates = dconf['sim']['saveAssignedFiringRates']
recordWeightStepSize = dconf['sim']['recordWeightStepSize']
normalizeWeightStepSize = dconf['sim']['normalizeWeightStepSize']
#recordWeightDT = 1000 # interval for recording synaptic weights (change later)
recordWeightDCells = 1 # to record weights for sub samples of neurons
tstepPerAction = dconf['sim']['tstepPerAction'] # time step per action (in ms)
fid4=None # only used by rank 0
scale = dconf['net']['scale'] # scales the size of the network (only number of neurons)
ETypes = dconf['net']['ETypes'] # excitatory neuron types
ITypes = dconf['net']['ITypes'] # inhibitory neuron types
allpops = list(dconf['net']['allpops'].keys())
EMotorPops = dconf['net']['EMotorPops'] # excitatory neuron motor populations
EVPops = dconf['net']['EVPops'] # excitatory visual populations
EVDirPops = dconf['net']['EVDirPops'] # excitatory visual dir selective populations (corresponds to VD in cmat)
EVLocPops = dconf['net']['EVLocPops'] # excitatory visual location selective populations (corresponds to VL in cmat)
cmat = dconf['net']['cmat'] # connection matrix (for classes, synapses, probabilities [probabilities not used for topological conn])
dnumc = OrderedDict({ty:dconf['net']['allpops'][ty]*scale for ty in allpops}) # number of neurons of a given type
def getpadding ():
# get padding-related parameters -- NB: not used
dnumc_padx = OrderedDict({ty:dconf['net']['allpops'][ty]*0 for ty in allpops}) # a dictionary with zeros to keep number of padded neurons in one dimension
dtopoldivcons = dconf['net']['alltopoldivcons']
dtopolconvcons = dconf['net']['alltopolconvcons']
allpops_withconvtopology = list(dtopolconvcons.keys())
allpops_withdivtopology = list(dtopoldivcons.keys())
# below is the code for updating neuronal pop size to include padding.
if dconf['net']['useNeuronPad']: # PADDING NEEDS TO BE FIXED..... DONT USE IT UNTIL FIXED
# first make dicionary of paddings in each dimension for each pop
for pop in allpops_withconvtopology:
receptive_fields = []
for postpop in list(dtopolconvcons[pop].keys()):
if dnumc[postpop]>0:
receptive_fields.append(dtopolconvcons[pop][postpop])
if len(receptive_fields)>0:
max_receptive_field = np.amax(receptive_fields)
else:
max_receptive_field = 0
if dnumc[pop]>0 and max_receptive_field>0:
dnumc_padx[pop] = max_receptive_field-1
for pop in allpops_withdivtopology:
receptive_fields = []
for postpop in list(dtopoldivcons[pop].keys()):
if dnumc[postpop]>0:
receptive_fields.append(dtopoldivcons[pop][postpop])
if len(receptive_fields)>0:
max_receptive_field = np.amax(receptive_fields)
else:
max_receptive_field = 0
if dnumc[pop]>0 and max_receptive_field>0:
dnumc_padx[pop] = max_receptive_field-1
for pop in allpops:
if dnumc[pop]>0 and dnumc_padx[pop]>0:
dnumc[pop] = int((np.sqrt(dnumc[pop])+dnumc_padx[pop])**2)
dnumc_padx['EMUP'] = 2
dnumc_padx['EMDOWN'] = 2
if dnumc['EMSTAY']>0: dnumc_padx['EMSTAY'] = 2
dnumc['EMUP'] = int((np.sqrt(dnumc['EMUP'])+dnumc_padx['EMUP'])**2)
dnumc['EMDOWN'] = int((np.sqrt(dnumc['EMDOWN'])+dnumc_padx['EMDOWN'])**2)
return dnumc_padx, dtopoldivcons,dtopolconvcons,allpops_withconvtopology,allpops_withdivtopology
dnumc_padx, dtopoldivcons,dtopolconvcons,allpops_withconvtopology,allpops_withdivtopology = getpadding()
def setlrecpop ():
lrecpop = ['EMUP', 'EMDOWN'] # which populations to record from
if dnumc['ESt1']>0:
lrecpop.append('ESt1')
if dnumc['ESt2']>0:
lrecpop.append('ESt2')
if dnumc['EPFC1']>0:
lrecpop.append('EPFC1')
if dnumc['EPFC2']>0:
lrecpop.append('EPFC2')
if cmat['VD']['VD']['conv'] > 0 or \
cmat['VD']['VL']['conv'] > 0 or \
cmat['VL']['VL']['conv'] > 0 or \
cmat['VL']['VD']['conv'] > 0 or \
dconf['net']['VisualFeedback']:
for pop in EVPops:
lrecpop.append(pop)
if dconf['net']['VisualFeedback'] and dnumc['ER']>0: lrecpop.append('ER')
if dnumc['EA']>0 and (dconf['net']['RLconns']['RecurrentANeurons'] or \
dconf['net']['STDPconns']['RecurrentANeurons'] or \
dconf['net']['RLconns']['FeedbackMtoA'] or \
dconf['net']['STDPconns']['FeedbackMtoA']):
lrecpop.append('EA')
if dnumc['EA2']>0 and (dconf['net']['RLconns']['RecurrentA2Neurons'] or \
dconf['net']['STDPconns']['RecurrentA2Neurons'] or \
dconf['net']['RLconns']['FeedbackMtoA2'] or \
dconf['net']['STDPconns']['FeedbackMtoA2']):
lrecpop.append('EA2')
if dconf['net']['RLconns']['Visual'] or dconf['net']['STDPconns']['Visual']:
if lrecpop.count('EV4')==0: lrecpop.append('EV4')
if lrecpop.count('EMT')==0: lrecpop.append('EMT')
recITypes = False
if dconf['net']['RLconns']['EIPlast'] or dconf['net']['STDPconns']['EIPlast']: recITypes = True
elif 'Noise' in dconf['net']['RLconns']:
if dconf['net']['RLconns']['Noise']:
recITypes = True
if recITypes:
for IType in ITypes:
if dnumc[IType] > 0: lrecpop.append(IType)
# this is not needed - since lrecpop has the postsynaptic type
#if dnumc['EN'] > 0 and 'Noise' in dconf['net']['RLconns']:
# if dconf['net']['RLconns']['Noise']: lrecpop.append('EN')
return lrecpop
lrecpop = setlrecpop()
# Network parameters
netParams = specs.NetParams() #object of class NetParams to store the network parameters
netParams.defaultThreshold = 0.0 # spike threshold, 10 mV is NetCon default, lower it for all cells
simConfig = specs.SimConfig() # object of class SimConfig to store simulation configuration
#Simulation options
simConfig.duration = dconf['sim']['duration'] # 100e3 # 0.1e5 # Duration of the simulation, in ms
simConfig.dt = dconf['sim']['dt'] # Internal integration timestep to use
simConfig.hParams['celsius'] = 37 # make sure temperature is set. otherwise we're at squid temperature
simConfig.verbose = dconf['sim']['verbose'] # Show detailed messages
simConfig.recordTraces = {'V_soma':{'sec':'soma','loc':0.5,'var':'v'}} # Dict with traces to record
simConfig.recordCellsSpikes = [-1] # this means record from all neurons - including stim populations, if any
simConfig.recordStep = dconf['sim']['recordStep'] # Step size in ms to save data (e.g. V traces, LFP, etc)
simConfig.filename = 'data/'+dconf['sim']['name']+'simConfig' # Set file output name
simConfig.saveJson = False
simConfig.savePickle = True # Save params, network and sim output to pickle file
simConfig.saveMat = False
simConfig.saveFolder = 'data'
# simConfig.backupCfg = ['sim.json', 'backupcfg/'+dconf['sim']['name']+'sim.json']
simConfig.createNEURONObj = True # create HOC objects when instantiating network
simConfig.createPyStruct = True # create Python structure (simulator-independent) when instantiating network
simConfig.analysis['plotTraces'] = {'include': [(pop, 0) for pop in ['ER','IR','EV1','EV1DE','ID','IV1','EV4','IV4','EMT','IMT','EMDOWN','EMUP','IM','IML','IMUP','IMDOWN','EA','IA','IAL','EA2','IA2','IA2L','EN','ESt1','ESt2','EPFC1','EPFC2']]}
simConfig.analysis['plotRaster'] = {'popRates':'overlay','showFig':dconf['sim']['doplot']}
#simConfig.analysis['plot2Dnet'] = True
#simConfig.analysis['plotConn'] = True # plot connectivity matrix
# simConfig.coreneuron = True
# synaptic weight gain (based on E, I types)
cfg = simConfig
cfg.EEGain = dconf['net']['EEGain'] # E to E scaling factor
cfg.EIGain = dconf['net']['EIGain'] # E to I scaling factor
cfg.IEGain = dconf['net']['IEGain'] # I to E scaling factor
cfg.IIGain = dconf['net']['IIGain'] # I to I scaling factor
### from https://www.neuron.yale.edu/phpBB/viewtopic.php?f=45&t=3770&p=16227&hilit=memory#p16122
cfg.saveCellSecs = bool(dconf['sim']['saveCellSecs']) # if False removes all data on cell sections prior to gathering from nodes
cfg.saveCellConns = bool(dconf['sim']['saveCellConns']) # if False removes all data on cell connections prior to gathering from nodes
###
# weight variance -- check if need to vary the initial weights (note, they're over-written if resumeSim==1)
cfg.weightVar = dconf['net']['weightVar']
cfg.delayMinDend = dconf['net']['delayMinDend']
cfg.delayMaxDend = dconf['net']['delayMaxDend']
cfg.delayMinSoma = dconf['net']['delayMinSoma']
cfg.delayMaxSoma = dconf['net']['delayMaxSoma']
def getInitWeight (weight):
"""get initial weight for a connection
checks if weightVar is non-zero, if so will use a uniform distribution
with range on interval: (1-var)*weight, (1+var)*weight
"""
if cfg.weightVar == 0.0:
return weight
elif weight <= 0.0:
return 0.0
else:
# print('uniform(%g,%g)' % (weight*(1.0-cfg.weightVar),weight*(1.0+cfg.weightVar)))
return 'uniform(%g,%g)' % (max(0,weight*(1.0-cfg.weightVar)),weight*(1.0+cfg.weightVar))
def getCompFromSy (sy):
if sy.count('2') > 0: return 'Dend'
return 'Soma'
def getInitDelay (cmp='Dend'):
a,b = float(dconf['net']['delayMin'+cmp]), float(dconf['net']['delayMax'+cmp])
if a==b:
return a
else:
return 'uniform(%g,%g)' % (a,b)
ECellModel = dconf['net']['ECellModel']
ICellModel = dconf['net']['ICellModel']
def getComp (sy):
if ECellModel == 'INTF7' or ICellModel == 'INTF7':
if sy.count('2') > 0:
return 'Dend'
return 'Soma'
else:
if sy.count('AM') or sy.count('NM'): return 'Dend'
return 'Soma'
#Population parameters
for ty in allpops:
if ty in ETypes:
netParams.popParams[ty] = {'cellType':ty, 'numCells': dnumc[ty], 'cellModel': ECellModel}
else:
netParams.popParams[ty] = {'cellType':ty, 'numCells': dnumc[ty], 'cellModel': ICellModel}
def makeECellModel (ECellModel):
# create rules for excitatory neuron models
EExcitSec = 'dend' # section where excitatory synapses placed
PlastWeightIndex = 0 # NetCon weight index where plasticity occurs
if ECellModel == 'Mainen':
netParams.importCellParams(label='PYR_Mainen_rule', conds={'cellType': ETypes}, fileName='cells/mainen.py', cellName='PYR2')
netParams.cellParams['PYR_Mainen_rule']['secs']['soma']['threshold'] = 0.0
EExcitSec = 'dend' # section where excitatory synapses placed
elif ECellModel == 'IzhiRS': ## RS Izhi cell params
EExcitSec = 'soma' # section where excitatory synapses placed
RScellRule = {'conds': {'cellType': ETypes, 'cellModel': 'IzhiRS'}, 'secs': {}}
RScellRule['secs']['soma'] = {'geom': {}, 'pointps':{}} # soma
RScellRule['secs']['soma']['geom'] = {'diam': 10, 'L': 10, 'cm': 31.831}
RScellRule['secs']['soma']['pointps']['Izhi'] = {
'mod':'Izhi2007b', 'C':1, 'k':0.7, 'vr':-60, 'vt':-40, 'vpeak':35, 'a':0.03, 'b':-2, 'c':-50, 'd':100, 'celltype':1
}
netParams.cellParams['IzhiRS'] = RScellRule # add dict to list of cell properties
elif ECellModel == 'IntFire4':
EExcitSec = 'soma' # section where excitatory synapses placed
simConfig.recordTraces = {'V_soma':{'var':'m'}} # Dict with traces to record
netParams.defaultThreshold = 0.0
for ty in ETypes:
#netParams.popParams[ty]={'cellType':ty,'numCells':dnumc[ty],'cellModel':ECellModel}#, 'params':{'taue':5.35,'taui1':9.1,'taui2':0.07,'taum':20}}
netParams.popParams[ty] = {'cellType':ty, 'cellModel': 'IntFire4', 'numCells': dnumc[ty], 'taue': 1.0} # pop of IntFire4
elif ECellModel == 'INTF7':
EExcitSec = 'soma' # section where excitatory synapses placed
simConfig.recordTraces = {'V_soma':{'var':'Vm'}} # Dict with traces to record
netParams.defaultThreshold = -40.0
for ty in ETypes:
netParams.popParams[ty] = {'cellType':ty, 'cellModel': 'INTF7', 'numCells': dnumc[ty]} # pop of IntFire4
for k,v in intf7.INTF7E.dparam.items(): netParams.popParams[ty][k] = v
PlastWeightIndex = intf7.dsyn['AM2']
elif ECellModel == 'Friesen':
cellRule = netParams.importCellParams(label='PYR_Friesen_rule', conds={'cellType': ETypes, 'cellModel': 'Friesen'},
fileName='cells/friesen.py', cellName='MakeRSFCELL')
cellRule['secs']['axon']['spikeGenLoc'] = 0.5 # spike generator location.
EExcitSec = 'dend' # section where excitatory synapses placed
elif ECellModel == 'HH':
EExcitSec = 'soma'
netParams.importCellParams(label='HHE_rule', conds={'cellType': ETypes}, fileName='cells/hht.py', cellName='HHE')
netParams.cellParams['HHE_rule']['secs']['soma']['threshold'] = -10.0
return EExcitSec,PlastWeightIndex
def makeICellModel (ICellModel):
# create rules for inhibitory neuron models
if ICellModel == 'FS_BasketCell': ## FS Izhi cell params
netParams.importCellParams(label='FS_BasketCell_rule', conds={'cellType': ITypes}, fileName='cells/FS_BasketCell.py', cellName='Bas')
netParams.cellParams['FS_BasketCell_rule']['secs']['soma']['threshold'] = -10.0
elif ICellModel == 'IzhiFS': # defaults to Izhi cell otherwise
FScellRule = {'conds': {'cellType': ITypes, 'cellModel': 'IzhiFS'}, 'secs': {}}
FScellRule['secs']['soma'] = {'geom': {}, 'pointps':{}} # soma
FScellRule['secs']['soma']['geom'] = {'diam': 10, 'L': 10, 'cm': 31.831}
FScellRule['secs']['soma']['pointps']['Izhi'] = {
'mod':'Izhi2007b', 'C':0.2, 'k':1.0, 'vr':-55, 'vt':-40, 'vpeak':25, 'a':0.2, 'b':-2, 'c':-45, 'd':-55, 'celltype':5
}
netParams.cellParams['IzhiFS'] = FScellRule # add dict to list of cell properties
elif ICellModel == 'IntFire4':
simConfig.recordTraces = {'V_soma':{'var':'m'}} # Dict with traces to record
netParams.defaultThreshold = 0.0
for ty in ITypes:
netParams.popParams[ty] = {'cellType':ty, 'cellModel': 'IntFire4', 'numCells': dnumc[ty], 'taue': 1.0} # pop of IntFire4
elif ICellModel == 'INTF7':
EExcitSec = 'soma' # section where excitatory synapses placed
simConfig.recordTraces = {'V_soma':{'var':'Vm'}} # Dict with traces to record
netParams.defaultThreshold = -40.0
for ty in ITypes:
netParams.popParams[ty] = {'cellType':ty, 'cellModel': 'INTF7', 'numCells': dnumc[ty]}
if ty.count('L') > 0: # LTS
for k,v in intf7.INTF7IL.dparam.items(): netParams.popParams[ty][k] = v
else: # FS
for k,v in intf7.INTF7I.dparam.items(): netParams.popParams[ty][k] = v
elif ICellModel == 'Friesen':
cellRule = netParams.importCellParams(label='Bas_Friesen_rule', conds={'cellType': ITypes, 'cellModel': 'Friesen'},
fileName='cells/friesen.py', cellName='MakeFSFCELL')
cellRule['secs']['axon']['spikeGenLoc'] = 0.5 # spike generator location.
elif ICellModel == 'HH':
netParams.importCellParams(label='HHI_rule', conds={'cellType': ITypes}, fileName='cells/hht.py', cellName='HHI')
netParams.cellParams['HHI_rule']['secs']['soma']['threshold'] = -10.0
EExcitSec,PlastWeightIndex = makeECellModel(ECellModel)
print('EExcitSec,PlastWeightIndex:',EExcitSec,PlastWeightIndex)
makeICellModel(ICellModel)
## Synaptic mechanism parameters
# note that these synaptic mechanisms are not used for the INTF7 neurons
# excitatory synaptic mechanism
netParams.synMechParams['AM2'] = netParams.synMechParams['AMPA'] = {'mod': 'Exp2Syn', 'tau1': 0.05, 'tau2': 5.3, 'e': 0}
netParams.synMechParams['NM2'] = netParams.synMechParams['NMDA'] = {'mod': 'Exp2Syn', 'tau1': 0.15, 'tau2': 166.0, 'e': 0} # NMDA
# inhibitory synaptic mechanism
netParams.synMechParams['GA'] = netParams.synMechParams['GABA'] = {'mod': 'Exp2Syn', 'tau1': 0.07, 'tau2': 9.1, 'e': -80}
def readSTDPParams ():
dSTDPparamsRL = {} # STDP-RL parameters for AMPA,NMDA synapses; generally uses shorter/longer eligibility traces
lsy = ['AMPA', 'NMDA']
if 'AMPAI' in dconf['RL']: lsy.append('AMPAI')
if 'AMPAN' in dconf['RL']: lsy.append('AMPAN') # RL for NOISE synapses
for sy,gain in zip(lsy,[cfg.EEGain,cfg.EEGain,cfg.EIGain,cfg.EEGain]):
dSTDPparamsRL[sy] = dconf['RL'][sy]
for k in dSTDPparamsRL[sy].keys():
if k.count('wt') or k.count('wbase') or k.count('wmax'): dSTDPparamsRL[sy][k] *= gain
lsy = ['AMPA', 'NMDA']
if 'AMPAI' in dconf['STDP']: lsy.append('AMPAI')
dSTDPparams = {} # STDPL parameters for AMPA,NMDA synapses; generally uses shorter/longer eligibility traces
for sy,gain in zip(lsy,[cfg.EEGain,cfg.EEGain,cfg.EIGain]):
dSTDPparams[sy] = dconf['STDP'][sy]
for k in dSTDPparams[sy].keys():
if k.count('wt') or k.count('wbase') or k.count('wmax'): dSTDPparams[sy][k] *= gain
dSTDPparamsRL['AM2']=dSTDPparamsRL['AMPA']; dSTDPparamsRL['NM2']=dSTDPparamsRL['NMDA']
dSTDPparams['AM2']=dSTDPparams['AMPA']; dSTDPparams['NM2']=dSTDPparams['NMDA']
return dSTDPparamsRL, dSTDPparams
dSTDPparamsRL, dSTDPparams = readSTDPParams()
def getWeightIndex (synmech, cellModel):
# get weight index for connParams
if cellModel == 'INTF7': return intf7.dsyn[synmech]
return 0
def setupStimMod ():
# setup variable rate NetStim sources (send spikes based on image contents)
lstimty = []
inputPop = 'EV1' # which population gets the direct visual inputs (pixels)
if dnumc['ER']>0: inputPop = 'ER'
stimModLocW = dconf['net']['stimModVL']
stimModDirW = dconf['net']['stimModVD']
if ECellModel == 'IntFire4' or ECellModel == 'INTF7':
lpoty = [inputPop]
for poty in ['EV1D'+Dir for Dir in ['E','NE','N', 'NW','W','SW','S','SE']]: lpoty.append(poty)
wt = stimModLocW
for poty in lpoty:
if dnumc[poty] <= 0: continue
stimty = 'stimMod'+poty
lstimty.append(stimty)
netParams.popParams[stimty] = {'cellModel': 'NSLOC', 'numCells': dnumc[poty],'rate': 'variable', 'noise': 0, 'start': 0}
blist = [[i,i] for i in range(dnumc[poty])]
netParams.connParams[stimty+'->'+poty] = {
'preConds': {'pop':stimty},
'postConds': {'pop':poty},
'weight':wt,
'delay': getInitDelay('STIMMOD'),
'connList':blist, 'weightIndex':getWeightIndex('AMPA',ECellModel)}
wt = stimModDirW # rest of inputs use this weight
else:
# these are the image-based inputs provided to the R (retinal) cells
netParams.stimSourceParams['stimMod'] = {'type': 'NetStim', 'rate': 'variable', 'noise': 0}
netParams.stimTargetParams['stimMod->'+inputPop] = {
'source': 'stimMod',
'conds': {'pop': inputPop},
'convergence': 1,
'weight': stimModLocW,
'delay': 1,
'synMech': 'AMPA'}
for pop in ['EV1D'+Dir for Dir in ['E','NE','N', 'NW','W','SW','S','SE']]:
netParams.stimTargetParams['stimMod->'+pop] = {
'source': 'stimMod',
'conds': {'pop': pop},
'convergence': 1,
'weight': stimModDirW,
'delay': 1,
'synMech': 'AMPA'}
return lstimty
sim.lstimty = setupStimMod() # when using IntFire4 cells lstimty has the NetStim populations that send spikes to EV1, EV1DE, etc.
for ty in sim.lstimty: allpops.append(ty)
# setup stimMod for random activation of neurons in PFC
def setupStimModPFC ():
# setup variable rate NetStim sources (send spikes based on image contents)
lstimpfc = []
wt = dconf['net']['stimModVL']
for poty in ['EPFC1','EPFC2']:
if dnumc[poty] <= 0: continue
stimpfc = 'stimMod'+poty
lstimpfc.append(stimpfc)
netParams.popParams[stimpfc] = {'cellModel': 'NSLOC', 'numCells': dnumc[poty],'rate': 'variable', 'noise': 0, 'start': 0}
blist = [[i,i] for i in range(dnumc[poty])]
netParams.connParams[stimpfc+'->'+poty] = {
'preConds': {'pop':stimpfc},
'postConds': {'pop':poty},
'weight':wt,
'delay': getInitDelay('STIMMOD'),
'connList':blist, 'weightIndex':getWeightIndex('AMPA',ECellModel)}
return lstimpfc
# sim.lstimpfc = setupStimModPFC() # when using IntFire4 cells lstimty has the NetStim populations that send spikes to EV1, EV1DE, etc.
#for ty in sim.lstimpfc: allpops.append(ty)
# Stimulation parameters
def setupNoiseStim ():
lnoisety = []
dnoise = dconf['noise']
# setup noisy NetStim sources (send random spikes)
if ECellModel == 'IntFire4' or ECellModel == 'INTF7':
lpoty = dnoise.keys()
for poty in lpoty:
lsy = dnoise[poty].keys()
for sy in lsy:
Weight,Rate = dnoise[poty][sy]['w'],dnoise[poty][sy]['rate']
if Weight > 0.0 and Rate > 0.0: # only create the netstims if rate,weight > 0
stimty = 'stimNoise'+poty+'_'+sy
netParams.popParams[stimty] = {'cellModel': 'NetStim', 'numCells': dnumc[poty],'rate': Rate, 'noise': 1.0, 'start': 0}
blist = [[i,i] for i in range(dnumc[poty])]
netParams.connParams[stimty+'->'+poty] = {
'preConds': {'pop':stimty},
'postConds': {'pop':poty},
'weight':Weight,
'delay': getInitDelay(getCompFromSy(sy)),
'connList':blist,
'weightIndex':getWeightIndex(sy,ECellModel)}
lnoisety.append(stimty)
else:
# setup noise inputs
lpoty = dnoise.keys()
for poty in lpoty:
lsy = dnoise[poty].keys()
for sy in lsy:
Weight,Rate = dnoise[poty][sy]['w'],dnoise[poty][sy]['rate']
if Weight > 0.0 and Rate > 0.0: # only create the netstims if rate,weight > 0
stimty = poty+'Mbkg'+sy
netParams.stimSourceParams[stimty] = {'type': 'NetStim', 'rate': Rate, 'noise': 1.0}
netParams.stimTargetParams[poty+'Mbkg->all'] = {
'source': stimty, 'conds': {'cellType': EMotorPops}, 'weight': Weight, 'delay': 'max(1, normal(5,2))', 'synMech': sy}
# lnoisety.append(ty+'Mbkg'+sy)
return lnoisety
sim.lnoisety = setupNoiseStim()
for ty in sim.lnoisety: allpops.append(ty)
######################################################################################
#####################################################################################
#Feedforward excitation
#E to E - Feedforward connections
if dconf['sim']['useReducedNetwork']:
if dconf['sim']['captureTwoObjs']:
cLV1toEA, cLV1DEtoEA, cLV1DNEtoEA, cLV1DNtoEA, cLV1DNWtoEA, cLV1DWtoEA, cLV1DSWtoEA, cLV1DStoEA, cLV1DSEtoEA = createConnListV1toEA2(dnumc['EV1'],2) # 3 objects in the game
else:
cLV1toEA, cLV1DEtoEA, cLV1DNEtoEA, cLV1DNtoEA, cLV1DNWtoEA, cLV1DWtoEA, cLV1DSWtoEA, cLV1DStoEA, cLV1DSEtoEA = createConnListV1toEA(dnumc['EV1'],3) # 3 objects in the game
#cLV1toEA, cLV1DEtoEA, cLV1DNEtoEA, cLV1DNtoEA, cLV1DNWtoEA, cLV1DWtoEA, cLV1DSWtoEA, cLV1DStoEA, cLV1DSEtoEA = createConnListV1toEA(60,3)
else:
if dnumc['ER']>0: blistERtoEV1, connCoordsERtoEV1 = connectLayerswithOverlap(NBpreN = dnumc['ER'], NBpostN = dnumc['EV1'], overlap_xdir = dtopolconvcons['ER']['EV1'], padded_preneurons_xdir = dnumc_padx['ER'], padded_postneurons_xdir = dnumc_padx['EV1'])
blistEV1toEV4, connCoordsEV1toEV4 = connectLayerswithOverlap(NBpreN = dnumc['EV1'], NBpostN = dnumc['EV4'], overlap_xdir = dtopolconvcons['EV1']['EV4'], padded_preneurons_xdir = dnumc_padx['EV1'], padded_postneurons_xdir = dnumc_padx['EV4'])
blistEV4toEMT, connCoordsEV4toEMT = connectLayerswithOverlap(NBpreN = dnumc['EV4'], NBpostN = dnumc['EMT'], overlap_xdir = dtopolconvcons['EV4']['EMT'], padded_preneurons_xdir = dnumc_padx['EV4'], padded_postneurons_xdir = dnumc_padx['EMT'])
#E to I - WithinLayer connections
if dnumc['ER']>0: blistERtoIR, connCoordsERtoIR = connectLayerswithOverlap(NBpreN = dnumc['ER'], NBpostN = dnumc['IR'], overlap_xdir = dtopolconvcons['ER']['IR'], padded_preneurons_xdir = dnumc_padx['ER'], padded_postneurons_xdir = dnumc_padx['IR'])
blistEV1toIV1, connCoordsEV1toIV1 = connectLayerswithOverlap(NBpreN = dnumc['EV1'], NBpostN = dnumc['IV1'], overlap_xdir = dtopolconvcons['EV1']['IV1'], padded_preneurons_xdir = dnumc_padx['EV1'], padded_postneurons_xdir = dnumc_padx['IV1'])
blistEV4toIV4, connCoordsEV4toIV4 = connectLayerswithOverlap(NBpreN = dnumc['EV4'], NBpostN = dnumc['IV4'], overlap_xdir = dtopolconvcons['EV4']['IV4'], padded_preneurons_xdir = dnumc_padx['EV4'], padded_postneurons_xdir = dnumc_padx['IV4'])
blistEMTtoIMT, connCoordsEMTtoIMT = connectLayerswithOverlap(NBpreN = dnumc['EMT'], NBpostN = dnumc['IMT'], overlap_xdir = dtopolconvcons['EMT']['IMT'], padded_preneurons_xdir = dnumc_padx['EMT'], padded_postneurons_xdir = dnumc_padx['IMT'])
#I to E - WithinLayer Inhibition
if dnumc['IR']>0: blistIRtoER, connCoordsIRtoER = connectLayerswithOverlapDiv(NBpreN = dnumc['IR'], NBpostN = dnumc['ER'], overlap_xdir = dtopoldivcons['IR']['ER'], padded_preneurons_xdir = dnumc_padx['IR'], padded_postneurons_xdir = dnumc_padx['ER'])
blistIV1toEV1, connCoordsIV1toEV1 = connectLayerswithOverlapDiv(NBpreN = dnumc['IV1'], NBpostN = dnumc['EV1'], overlap_xdir = dtopoldivcons['IV1']['EV1'], padded_preneurons_xdir = dnumc_padx['IV1'], padded_postneurons_xdir = dnumc_padx['EV1'])
blistIV4toEV4, connCoordsIV4toEV4 = connectLayerswithOverlapDiv(NBpreN = dnumc['IV4'], NBpostN = dnumc['EV4'], overlap_xdir = dtopoldivcons['IV4']['EV4'], padded_preneurons_xdir = dnumc_padx['IV4'], padded_postneurons_xdir = dnumc_padx['EV4'])
blistIMTtoEMT, connCoordsIMTtoEMT = connectLayerswithOverlapDiv(NBpreN = dnumc['IMT'], NBpostN = dnumc['EMT'], overlap_xdir = dtopoldivcons['IMT']['EMT'], padded_preneurons_xdir = dnumc_padx['IMT'], padded_postneurons_xdir = dnumc_padx['EMT'])
#Feedbackward excitation
#E to E
if dnumc['ER']>0: blistEV1toER, connCoordsEV1toER = connectLayerswithOverlapDiv(NBpreN = dnumc['EV1'], NBpostN = dnumc['ER'], overlap_xdir = dtopoldivcons['EV1']['ER'], padded_preneurons_xdir = dnumc_padx['EV1'], padded_postneurons_xdir = dnumc_padx['ER'])
blistEV4toEV1, connCoordsEV4toEV1 = connectLayerswithOverlapDiv(NBpreN = dnumc['EV4'], NBpostN = dnumc['EV1'], overlap_xdir = dtopoldivcons['EV4']['EV1'], padded_preneurons_xdir = dnumc_padx['EV4'], padded_postneurons_xdir = dnumc_padx['EV1'])
blistEMTtoEV4, connCoordsEMTtoEV4 = connectLayerswithOverlapDiv(NBpreN = dnumc['EMT'], NBpostN = dnumc['EV4'], overlap_xdir = dtopoldivcons['EMT']['EV4'], padded_preneurons_xdir = dnumc_padx['EMT'], padded_postneurons_xdir = dnumc_padx['EV4'])
#Feedforward inhibition
#I to I
blistIV1toIV4, connCoordsIV1toIV4 = connectLayerswithOverlap(NBpreN = dnumc['IV1'], NBpostN = dnumc['IV4'], overlap_xdir = dtopolconvcons['IV1']['IV4'], padded_preneurons_xdir = dnumc_padx['IV1'], padded_postneurons_xdir = dnumc_padx['IV4'])
blistIV4toIMT, connCoordsIV4toIMT = connectLayerswithOverlap(NBpreN = dnumc['IV4'], NBpostN = dnumc['IMT'], overlap_xdir = dtopolconvcons['IV4']['IMT'], padded_preneurons_xdir = dnumc_padx['IV4'], padded_postneurons_xdir = dnumc_padx['IMT'])
#Feedbackward inhibition
#I to E
if dnumc['IR']>0: blistIV1toER, connCoordsIV1toER = connectLayerswithOverlapDiv(NBpreN = dnumc['IV1'], NBpostN = dnumc['ER'], overlap_xdir = dtopoldivcons['IV1']['ER'], padded_preneurons_xdir = dnumc_padx['IV1'], padded_postneurons_xdir = dnumc_padx['ER'])
blistIV4toEV1, connCoordsIV4toEV1 = connectLayerswithOverlapDiv(NBpreN = dnumc['IV4'], NBpostN = dnumc['EV1'], overlap_xdir = dtopoldivcons['IV4']['EV1'], padded_preneurons_xdir = dnumc_padx['IV4'], padded_postneurons_xdir = dnumc_padx['EV1'])
blistIMTtoEV4, connCoordsIMTtoEV4 = connectLayerswithOverlapDiv(NBpreN = dnumc['IMT'], NBpostN = dnumc['EV4'], overlap_xdir = dtopoldivcons['IMT']['EV4'], padded_preneurons_xdir = dnumc_padx['IMT'], padded_postneurons_xdir = dnumc_padx['EV4'])
#Local excitation
#E to E recurrent connectivity within visual areas
for epop in EVPops:
if dnumc[epop] <= 0: continue # skip rule setup for empty population
prety = poty = epop
repstr = 'VD' # replacement presynaptic type string (VD -> EV1DE, EV1DNE, etc.; VL -> EV1, EV4, etc.)
if prety in EVLocPops: repstr = 'VL'
wAM, wNM = cmat[repstr][repstr]['AM2'], cmat[repstr][repstr]['NM2']
for strty,synmech,weight in zip(['','n'],['AM2', 'NM2'],[wAM*cfg.EEGain, wNM*cfg.EEGain]):
k = strty+prety+'->'+strty+poty
if weight <= 0.0: continue
netParams.connParams[k] = {
'preConds': {'pop': prety},
'postConds': {'pop': poty},
'convergence': getconv(cmat, repstr, repstr, dnumc[prety]),
'weight': getInitWeight(weight),
'delay': getInitDelay('Dend'),
'synMech': synmech,
'sec':EExcitSec, 'loc':0.5,
'weightIndex':getWeightIndex(synmech, ECellModel)
}
useRL = useSTDP = False
if prety in EVDirPops:
if dconf['net']['RLconns']['RecurrentDirNeurons']: useRL = True
if dconf['net']['STDPconns']['RecurrentDirNeurons']: useSTDP = True
if prety in EVLocPops:
if dconf['net']['RLconns']['RecurrentLocNeurons']: useRL = True
if dconf['net']['STDPconns']['RecurrentLocNeurons']: useSTDP = True
if useRL and dSTDPparamsRL[synmech]['RLon']: # only turn on plasticity when specified to do so
netParams.connParams[k]['plast'] = {'mech': 'STDP', 'params': dSTDPparamsRL[synmech]}
elif useSTDP and dSTDPparams[synmech]['STDPon']:
netParams.connParams[k]['plast'] = {'mech': 'STDP', 'params': dSTDPparams[synmech]}
VTopoI = dconf['net']['VTopoI'] # whether visual neurons have topological arrangement
#E to I within area
if dnumc['ER']>0:
netParams.connParams['ER->IR'] = {
'preConds': {'pop': 'ER'},
'postConds': {'pop': 'IR'},
'weight': cmat['ER']['IR']['AM2'] * cfg.EIGain,
'delay': getInitDelay('Dend'),
'synMech': 'AMPA', 'sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex('AM2', ICellModel)}
if VTopoI and dconf['sim']['useReducedNetwork']==0: netParams.connParams['ER->IR']['connList'] = blistERtoIR
else: netParams.connParams['ER->IR']['convergence'] = getconv(cmat, 'ER', 'IR', dnumc['ER'])
netParams.connParams['EV1->IV1'] = {
'preConds': {'pop': 'EV1'},
'postConds': {'pop': 'IV1'},
'weight': cmat['EV1']['IV1']['AM2'] * cfg.EIGain,
'delay': getInitDelay('Dend'),
'synMech': 'AMPA', 'sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex('AM2', ICellModel)}
if VTopoI and dconf['sim']['useReducedNetwork']==0:
netParams.connParams['EV1->IV1']['connList'] = blistEV1toIV1
sim.topologicalConns['EV1->IV1'] = {'blist':blistEV1toIV1, 'coords':connCoordsEV1toIV1}
else:
netParams.connParams['EV1->IV1']['convergence'] = getconv(cmat, 'EV1', 'IV1', dnumc['EV1'])
if dnumc['ID']>0:
EVDirPops = dconf['net']['EVDirPops']
IVDirPops = dconf['net']['IVDirPops']
for prety in EVDirPops:
for poty in IVDirPops:
netParams.connParams[prety+'->'+poty] = {
'preConds': {'pop': prety},
'postConds': {'pop': poty},
'convergence': getconv(cmat, 'VD', 'ID', dnumc[prety]),
'weight': cmat['VD']['ID']['AM2'] * cfg.EIGain,
'delay': getInitDelay('Dend'),
'synMech': 'AMPA', 'sec':'soma', 'loc':0.5, 'weightIndex':getWeightIndex('AM2', ICellModel)}
netParams.connParams['EV4->IV4'] = {
'preConds': {'pop': 'EV4'},
'postConds': {'pop': 'IV4'},
'weight': cmat['EV4']['IV4']['AM2'] * cfg.EIGain,
'delay': getInitDelay('Dend'),
'synMech': 'AMPA', 'sec':'soma', 'loc':0.5, 'weightIndex':getWeightIndex('AM2', ICellModel)}
if VTopoI and dconf['sim']['useReducedNetwork']==0:
netParams.connParams['EV4->IV4']['connList'] = blistEV4toIV4
sim.topologicalConns['EV4->IV4'] = {'blist':blistEV4toIV4, 'coords':connCoordsEV4toIV4}
else:
netParams.connParams['EV4->IV4']['convergence'] = getconv(cmat,'EV4','IV4', dnumc['EV4'])
netParams.connParams['EMT->IMT'] = {
'preConds': {'pop': 'EMT'},
'postConds': {'pop': 'IMT'},
'weight': cmat['EMT']['IMT']['AM2'] * cfg.EIGain,
'delay': getInitDelay('Dend'),
'synMech': 'AMPA', 'sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex('AM2', ICellModel)}
if VTopoI and dconf['sim']['useReducedNetwork']==0:
netParams.connParams['EMT->IMT']['connList'] = blistEMTtoIMT
sim.topologicalConns['EMT->IMT'] = {'blist':blistEMTtoIMT, 'coords':connCoordsEMTtoIMT}
else:
netParams.connParams['EMT->IMT']['convergence'] = getconv(cmat, 'EMT', 'IMT', dnumc['EMT'])
for prety,poty in zip(['EA','EA','EA2','EA2'],['IA','IAL','IA2','IA2L']):
if dnumc[prety] <= 0 or dnumc[poty] <= 0: continue
for sy in ['AM2','NM2']:
if sy not in cmat[prety][poty]: continue
k = prety+'->'+poty+sy
netParams.connParams[k] = {
'preConds': {'pop': prety},
'postConds': {'pop': poty},
'convergence': getconv(cmat, prety, poty, dnumc[prety]),
'weight': cmat[prety][poty][sy] * cfg.EIGain,
'delay': getInitDelay('Dend'),
'synMech': sy, 'sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex(sy, ICellModel)}
if sy.count('AM') > 0:
if dconf['net']['RLconns']['EIPlast'] and dSTDPparamsRL['AMPAI']['RLon']: # only turn on plasticity when specified to do so
netParams.connParams[k]['plast'] = {'mech': 'STDP', 'params': dSTDPparamsRL['AMPAI']}
netParams.connParams[k]['weight'] = getInitWeight(cmat[prety][poty]['AM2'] * cfg.EIGain)
elif dconf['net']['STDPconns']['EIPlast'] and dSTDPparams['AMPAI']['STDPon']:
netParams.connParams[k]['plast'] = {'mech': 'STDP', 'params': dSTDPparams['AMPAI']}
netParams.connParams[k]['weight'] = getInitWeight(cmat[prety][poty]['AM2'] * cfg.EIGain)
for prety in EMotorPops:
if dnumc[prety] <= 0: continue
for poty in ['IM', 'IML']:
if dnumc[poty] <= 0: continue
for sy in ['AM2','NM2']:
if sy not in cmat['EM'][poty]: continue
k = prety+'->'+poty+sy
netParams.connParams[k] = {
'preConds': {'pop': prety},
'postConds': {'pop': poty},
'convergence': getconv(cmat, 'EM', poty, dnumc[prety]),
'weight': cmat['EM'][poty][sy] * cfg.EIGain,
'delay': getInitDelay('Dend'),
'synMech': sy, 'sec':'soma', 'loc':0.5, 'weightIndex':getWeightIndex(sy, ICellModel)}
if sy.count('AM') > 0:
if dconf['net']['RLconns']['EIPlast'] and dSTDPparamsRL['AMPAI']['RLon']: # only turn on plasticity when specified to do so
netParams.connParams[k]['plast'] = {'mech': 'STDP', 'params': dSTDPparamsRL['AMPAI']}
netParams.connParams[k]['weight'] = getInitWeight(cmat['EM'][poty]['AM2'] * cfg.EIGain)
elif dconf['net']['STDPconns']['EIPlast'] and dSTDPparams['AMPAI']['STDPon']:
netParams.connParams[k]['plast'] = {'mech': 'STDP', 'params': dSTDPparams['AMPAI']}
netParams.connParams[k]['weight'] = getInitWeight(cmat['EM'][poty]['AM2'] * cfg.EIGain)
# reciprocal inhibition - only active when all relevant populations created - not usually used
for prety in EMotorPops:
for epoty in EMotorPops:
if epoty == prety: continue # no self inhib here
poty = 'IM' + epoty[2:] # change name to interneuron
k = prety + '->' + poty
netParams.connParams[k] = {
'preConds': {'pop': prety},
'postConds': {'pop': poty},
'convergence': getconv(cmat, 'EM', 'IRecip', dnumc[prety]),
'weight': cmat['EM']['IRecip']['AM2'] * cfg.EIGain,
'delay': getInitDelay('Dend'),
'synMech': 'AMPA', 'sec':'soma', 'loc':0.5, 'weightIndex':getWeightIndex('AM2', ICellModel)}
if dconf['net']['RLconns']['EIPlast'] and dSTDPparamsRL['AMPAI']['RLon']: # only turn on plasticity when specified to do so
netParams.connParams[k]['plast'] = {'mech': 'STDP', 'params': dSTDPparamsRL['AMPAI']}
netParams.connParams[k]['weight'] = getInitWeight(cmat['EM']['IRecip']['AM2'] * cfg.EIGain)
elif dconf['net']['STDPconns']['EIPlast'] and dSTDPparams['AMPAI']['STDPon']:
netParams.connParams[k]['plast'] = {'mech': 'STDP', 'params': dSTDPparams['AMPAI']}
netParams.connParams[k]['weight'] = getInitWeight(cmat['EM']['IRecip']['AM2'] * cfg.EIGain)
#Local inhibition
#I to E within area
if dnumc['ER']>0:
netParams.connParams['IR->ER'] = {
'preConds': {'pop': 'IR'},
'postConds': {'pop': 'ER'},
'weight': cmat['IR']['ER']['GA'] * cfg.IEGain,
'delay': getInitDelay('Soma'),
'synMech': 'GABA', 'sec':'soma', 'loc':0.5, 'weightIndex':getWeightIndex('GA', ICellModel)}
if VTopoI and dconf['sim']['useReducedNetwork']==0:
netParams.connParams['IR->ER']['connList'] = blistIRtoER
sim.topologicalConns['IR->ER'] = {'blist':blistIRtoER, 'coords':connCoordsIRtoER}
else:
netParams.connParams['IR->ER']['convergence'] = getconv(cmat, 'IR', 'ER', dnumc['IR'])
netParams.connParams['IV1->EV1'] = {
'preConds': {'pop': 'IV1'},
'postConds': {'pop': 'EV1'},
'weight': cmat['IV1']['EV1']['GA'] * cfg.IEGain,
'delay': getInitDelay('Soma'),
'synMech': 'GABA', 'sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex('GA', ECellModel)}
if VTopoI and dconf['sim']['useReducedNetwork']==0:
netParams.connParams['IV1->EV1']['connList'] = blistIV1toEV1
sim.topologicalConns['IV1->EV1'] = {'blist':blistIV1toEV1, 'coords':connCoordsIV1toEV1}
else:
netParams.connParams['IV1->EV1']['convergence'] = getconv(cmat, 'IV1', 'EV1', dnumc['IV1'])
if dnumc['ID']>0:
IVDirPops = dconf['net']['IVDirPops']
for prety in IVDirPops:
for poty in EVDirPops:
netParams.connParams[prety+'->'+poty] = {
'preConds': {'pop': prety},
'postConds': {'pop': poty},
'convergence': getconv(cmat, 'ID', 'ED', dnumc['ID']),
'weight': cmat['ID']['ED']['GA'] * cfg.IEGain,
'delay': getInitDelay('Soma'),
'synMech': 'GABA', 'sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex('GA', ECellModel)}
netParams.connParams['IV4->EV4'] = {
'preConds': {'pop': 'IV4'},
'postConds': {'pop': 'EV4'},
'weight': cmat['IV4']['EV4']['GA'] * cfg.IEGain,
'delay': getInitDelay('Soma'),
'synMech': 'GABA', 'sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex('GA', ECellModel)}
if VTopoI and dconf['sim']['useReducedNetwork']==0:
netParams.connParams['IV4->EV4']['connList'] = blistIV4toEV4
sim.topologicalConns['IV4->EV4'] = {'blist':blistIV4toEV4, 'coords':connCoordsIV4toEV4}
else:
netParams.connParams['IV4->EV4']['convergence'] = getconv(cmat,'IV4','EV4', dnumc['IV4'])
netParams.connParams['IMT->EMT'] = {
'preConds': {'pop': 'IMT'},
'postConds': {'pop': 'EMT'},
'weight': cmat['IMT']['EMT']['GA'] * cfg.IEGain,
'delay': getInitDelay('Soma'),
'synMech': 'GABA', 'sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex('GA', ECellModel)}
if VTopoI and dconf['sim']['useReducedNetwork']==0:
netParams.connParams['IMT->EMT']['connList'] = blistIMTtoEMT
sim.topologicalConns['IMT->EMT'] = {'blist':blistIMTtoEMT, 'coords':connCoordsIMTtoEMT}
else:
netParams.connParams['IMT->EMT']['convergence'] = getconv(cmat,'IMT','EMT',dnumc['IMT'])
# I -> E for motor populations
for prety,sy in zip(['IM', 'IML'],['GA','GA2']):
for poty in EMotorPops:
netParams.connParams[prety+'->'+poty] = {
'preConds': {'pop': prety},
'postConds': {'pop': poty},
'convergence': getconv(cmat,prety,'EM', dnumc[prety]),
'weight': cmat[prety]['EM'][sy] * cfg.IEGain,
'delay': getInitDelay(getCompFromSy(sy)),
'synMech': 'GABA', 'sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex(sy, ECellModel)}
for prety,poty,sy in zip(['IA','IAL','IA2','IA2L'],['EA','EA','EA2','EA2'],['GA','GA2','GA','GA2']):
netParams.connParams[prety+'->'+poty] = {
'preConds': {'pop': prety},
'postConds': {'pop': poty},
'convergence': getconv(cmat,prety,poty, dnumc[prety]),
'weight': cmat[prety][poty][sy] * cfg.IEGain,
'delay': getInitDelay(getCompFromSy(sy)),
'synMech': 'GABA', 'sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex(sy, ECellModel)}
#I to I
for preIType in ITypes:
sy = 'GA'
if preIType.count('L') > 0: sy = 'GA2'
for poIType in ITypes:
if preIType not in dnumc or poIType not in dnumc: continue
if dnumc[preIType] <= 0 or dnumc[poIType] <= 0: continue
if poIType not in cmat[preIType] or \
getconv(cmat,preIType,poIType,dnumc[preIType])<=0 or \
cmat[preIType][poIType][sy]<=0: continue
netParams.connParams[preIType+'->'+poIType] = {
'preConds': {'pop': preIType},
'postConds': {'pop': poIType},
'convergence': getconv(cmat,preIType,poIType,dnumc[preIType]),
'weight': cmat[preIType][poIType][sy] * cfg.IIGain,
'delay': getInitDelay(getCompFromSy(sy)),
'synMech': 'GABA', 'sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex(sy, ICellModel)}
#E to E feedforward connections - AMPA,NMDA
lprety,lpoty,lblist,lconnsCoords = [],[],[],[]
if not dconf['sim']['useReducedNetwork']:
if dnumc['ER']>0:
lprety.append('ER')
lpoty.append('EV1')
lblist.append(blistERtoEV1)
lconnsCoords.append(connCoordsERtoEV1)
lprety.append('EV1'); lpoty.append('EV4'); lblist.append(blistEV1toEV4); lconnsCoords.append(connCoordsEV1toEV4)
lprety.append('EV4'); lpoty.append('EMT'); lblist.append(blistEV4toEMT); lconnsCoords.append(connCoordsEV4toEMT)
for prety,poty,blist,connCoords in zip(lprety,lpoty,lblist,lconnsCoords):
for strty,synmech,weight in zip(['','n'],['AM2', 'NM2'],[cmat[prety][poty]['AM2']*cfg.EEGain,cmat[prety][poty]['NM2']*cfg.EEGain]):
k = strty+prety+'->'+strty+poty
if weight <= 0.0: continue
netParams.connParams[k] = {
'preConds': {'pop': prety},
'postConds': {'pop': poty},
'weight': weight ,
'delay': getInitDelay('Dend'),
'synMech': synmech,'sec':EExcitSec, 'loc':0.5,'weightIndex':getWeightIndex(synmech, ECellModel)}
if VTopoI: # topological connections
netParams.connParams[k]['connList'] = blist
sim.topologicalConns[prety+'->'+poty] = {}
sim.topologicalConns[prety+'->'+poty]['blist'] = blist
sim.topologicalConns[prety+'->'+poty]['coords'] = connCoords
else: # random connectivity
netParams.connParams[k]['convergence'] = getconv(cmat,prety,poty,dnumc[prety])
if dconf['net']['RLconns']['Visual'] and dSTDPparamsRL[synmech]['RLon']: # only turn on plasticity when specified to do so
netParams.connParams[k]['weight'] = getInitWeight(weight) # make sure non-uniform weights
netParams.connParams[k]['plast'] = {'mech': 'STDP', 'params': dSTDPparamsRL[synmech]}
elif dconf['net']['STDPconns']['Visual'] and dSTDPparams[synmech]['STDPon']:
netParams.connParams[k]['weight'] = getInitWeight(weight) # make sure non-uniform weights
netParams.connParams[k]['plast'] = {'mech': 'STDP', 'params': dSTDPparams[synmech]}
if dconf['net']['VisualFeedback'] and not dconf['sim']['useReducedNetwork']:
# visual area feedback connections
pretyList = ['EV1','EV4','EMT']
potyList = ['ER','EV1','EV4']
allconnList = [blistEV1toER,blistEV4toEV1,blistEMTtoEV4]
allconnCoords = [connCoordsEV1toER,connCoordsEV4toEV1,connCoordsEMTtoEV4]
for prety,poty,connList,connCoords in zip(pretyList,potyList,allconnList,allconnCoords):
if dnumc[prety] <= 0 or dnumc[poty] <= 0: continue # skip empty pops
for strty,synmech,synweight in zip(['','n'],['AM2', 'NM2'],[cmat[prety][poty]['AM2']*cfg.EEGain, cmat[prety][poty]['NM2']*cfg.EEGain]):
if synweight <= 0.0: continue
k = strty+prety+'->'+strty+poty
netParams.connParams[k] = {
'preConds': {'pop': prety},
'postConds': {'pop': poty},
'connList': connList,
'weight': getInitWeight(synweight),
'delay': getInitDelay('Dend'),
'synMech': synmech,'sec':EExcitSec, 'loc':0.5,'weightIndex':getWeightIndex(synmech, ECellModel)} # 'weight' should be fixed
sim.topologicalConns[prety+'->'+poty] = {}
sim.topologicalConns[prety+'->'+poty]['blist'] = connList
sim.topologicalConns[prety+'->'+poty]['coords'] = connCoords
# only turn on plasticity when specified to do so
if dconf['net']['RLconns']['FeedbackLocNeurons'] and dSTDPparamsRL[synmech]['RLon']:
netParams.connParams[k]['plast'] = {'mech': 'STDP', 'params': dSTDPparamsRL[synmech]}
elif dconf['net']['STDPconns']['FeedbackLocNeurons'] and dSTDPparams[synmech]['STDPon']:
netParams.connParams[k]['plast'] = {'mech': 'STDP', 'params': dSTDPparams[synmech]}
#I to E feedback connections
netParams.connParams['IV1->ER'] = {
'preConds': {'pop': 'IV1'},
'postConds': {'pop': 'ER'},
'connList': blistIV1toER,
'weight': cmat['IV1']['ER']['GA'] * cfg.IEGain,
'delay': getInitDelay('Soma'),
'synMech': 'GABA','sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex('GA', ECellModel)}
sim.topologicalConns['IV1->ER'] = {}
sim.topologicalConns['IV1->ER']['blist'] = blistIV1toER
sim.topologicalConns['IV1->ER']['coords'] = connCoordsIV1toER
netParams.connParams['IV4->EV1'] = {
'preConds': {'pop': 'IV4'},
'postConds': {'pop': 'EV1'},
'connList': blistIV4toEV1,
'weight': cmat['IV4']['EV1']['GA'] * cfg.IEGain,
'delay': getInitDelay('Soma'),
'synMech': 'GABA','sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex('GA', ECellModel)}
sim.topologicalConns['IV4->EV1'] = {}
sim.topologicalConns['IV4->EV1']['blist'] = blistIV4toEV1
sim.topologicalConns['IV4->EV1']['coords'] = connCoordsIV4toEV1
netParams.connParams['IMT->EV4'] = {
'preConds': {'pop': 'IMT'},
'postConds': {'pop': 'EV4'},
'connList': blistIMTtoEV4,
'weight': cmat['IMT']['EV4']['GA'] * cfg.IEGain,
'delay': getInitDelay('Soma'),
'synMech': 'GABA','sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex('GA', ECellModel)}
sim.topologicalConns['IMT->EV4'] = {'blist':blistIMTtoEV4, 'coords':connCoordsIMTtoEV4}
#I to I - between areas
if dconf['sim']['useReducedNetwork']==0:
netParams.connParams['IV1->IV4'] = {
'preConds': {'pop': 'IV1'},
'postConds': {'pop': 'IV4'},
'connList': blistIV1toIV4,
'weight': cmat['IV1']['IV4']['GA'] * cfg.IIGain,
'delay': getInitDelay('Soma'),
'synMech': 'GABA','sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex('GA', ICellModel)}
sim.topologicalConns['IV1->IV4'] = {'blist':blistIV1toIV4, 'coords':connCoordsIV1toIV4}
netParams.connParams['IV4->IMT'] = {
'preConds': {'pop': 'IV4'},
'postConds': {'pop': 'IMT'},
'connList': blistIV4toIMT,
'weight': cmat['IV4']['IMT']['GA'] * cfg.IIGain,
'delay': getInitDelay('Soma'),
'synMech': 'GABA','sec':'soma', 'loc':0.5,'weightIndex':getWeightIndex('GA', ICellModel)}
sim.topologicalConns['IV4->IMT'] = {'blist':blistIV4toIMT, 'coords':connCoordsIV4toIMT}
def connectEVToTarget (lpoty, useTopological):
if dconf['sim']['useReducedNetwork']:
print(cLV1toEA)
synmech = 'AM2'
weight = cfg.EEGain*cmat['VL']['EA']['AM2']
netParams.connParams['EV1->EA'] = {
'preConds': {'pop': 'EV1'},
'postConds': {'pop': 'EA'},
'connList': cLV1toEA,
'weight': getInitWeight(weight),
'delay': getInitDelay('Dend'),
'synMech': synmech,
'sec':EExcitSec, 'loc':0.5,'weightIndex':getWeightIndex(synmech, ECellModel)
}
if dconf['net']['RLconns']['FeedForwardLocNtoA'] and dSTDPparamsRL[synmech]['RLon']:
netParams.connParams['EV1->EA']['plast'] = {'mech': 'STDP', 'params': dSTDPparamsRL[synmech]}
elif dconf['net']['STDPconns']['FeedForwardLocNtoA'] and dSTDPparams[synmech]['STDPon']:
netParams.connParams['EV1->EA']['plast'] = {'mech': 'STDP', 'params': dSTDPparams[synmech]}
weight = cfg.EEGain*cmat['VD']['EA']['AM2']
netParams.connParams['EV1DE->EA'] = {
'preConds': {'pop': 'EV1DE'},
'postConds': {'pop': 'EA'},
'connList': cLV1DEtoEA,
'weight': getInitWeight(weight),
'delay': getInitDelay('Dend'),
'synMech': synmech,
'sec':EExcitSec, 'loc':0.5,'weightIndex':getWeightIndex(synmech, ECellModel)
}
netParams.connParams['EV1DNE->EA'] = {
'preConds': {'pop': 'EV1DNE'},
'postConds': {'pop': 'EA'},
'connList': cLV1DNEtoEA,
'weight': getInitWeight(weight),
'delay': getInitDelay('Dend'),
'synMech': synmech,
'sec':EExcitSec, 'loc':0.5,'weightIndex':getWeightIndex(synmech, ECellModel)
}
netParams.connParams['EV1DN->EA'] = {
'preConds': {'pop': 'EV1DN'},
'postConds': {'pop': 'EA'},
'connList': cLV1DNtoEA,
'weight': getInitWeight(weight),
'delay': getInitDelay('Dend'),
'synMech': synmech,
'sec':EExcitSec, 'loc':0.5,'weightIndex':getWeightIndex(synmech, ECellModel)
}
netParams.connParams['EV1DNW->EA'] = {
'preConds': {'pop': 'EV1DNW'},
'postConds': {'pop': 'EA'},
'connList': cLV1DNWtoEA,
'weight': getInitWeight(weight),
'delay': getInitDelay('Dend'),
'synMech': synmech,
'sec':EExcitSec, 'loc':0.5,'weightIndex':getWeightIndex(synmech, ECellModel)
}
netParams.connParams['EV1DW->EA'] = {
'preConds': {'pop': 'EV1DW'},
'postConds': {'pop': 'EA'},
'connList': cLV1DWtoEA,
'weight': getInitWeight(weight),
'delay': getInitDelay('Dend'),
'synMech': synmech,
'sec':EExcitSec, 'loc':0.5,'weightIndex':getWeightIndex(synmech, ECellModel)
}
netParams.connParams['EV1DSW->EA'] = {
'preConds': {'pop': 'EV1DSW'},
'postConds': {'pop': 'EA'},
'connList': cLV1DSWtoEA,
'weight': getInitWeight(weight),
'delay': getInitDelay('Dend'),
'synMech': synmech,
'sec':EExcitSec, 'loc':0.5,'weightIndex':getWeightIndex(synmech, ECellModel)
}
netParams.connParams['EV1DS->EA'] = {
'preConds': {'pop': 'EV1DS'},
'postConds': {'pop': 'EA'},
'connList': cLV1DStoEA,
'weight': getInitWeight(weight),
'delay': getInitDelay('Dend'),
'synMech': synmech,
'sec':EExcitSec, 'loc':0.5,'weightIndex':getWeightIndex(synmech, ECellModel)
}
netParams.connParams['EV1DSE->EA'] = {
'preConds': {'pop': 'EV1DSE'},
'postConds': {'pop': 'EA'},
'connList': cLV1DSEtoEA,
'weight': getInitWeight(weight),
'delay': getInitDelay('Dend'),
'synMech': synmech,
'sec':EExcitSec, 'loc':0.5,'weightIndex':getWeightIndex(synmech, ECellModel)
}
ldirconns = ['EV1DE->EA','EV1DNE->EA','EV1DN->EA','EV1DNW->EA','EV1DW->EA','EV1DSW->EA','EV1DS->EA','EV1DSE->EA']
if dconf['net']['RLconns']['FeedForwardDirNtoA'] and dSTDPparamsRL[synmech]['RLon']:
for dirconns in ldirconns:
netParams.connParams[dirconns]['plast'] = {'mech': 'STDP', 'params': dSTDPparamsRL[synmech]}
elif dconf['net']['STDPconns']['FeedForwardDirNtoA'] and dSTDPparams[synmech]['STDPon']:
for dirconns in ldirconns:
netParams.connParams[dirconns]['plast'] = {'mech': 'STDP', 'params': dSTDPparams[synmech]}
else:
# connect excitatory visual area neurons to list of postsynaptic types (lpoty)
for prety in EVPops:
if dnumc[prety] <= 0: continue
for poty in lpoty:
if dnumc[poty] <= 0: continue
suffix = 'M'
if poty == 'EA': suffix = 'A'
if poty == 'EA2': suffix = 'A2'
if useTopological:
try: div = dconf['net']['alltopoldivcons'][prety][poty]
except: div = 3
# BE CAREFUL. THERE IS ALWAYS A CHANCE TO USE dnumc[prety] nad dnumc[poty] that produces inaccuracies.
# works fine if used in multiples (400->100; 100->400; 100->100).
blist = []
connCoords = []
if dconf['net']['allpops'][prety]==dconf['net']['allpops'][poty] or dconf['net']['allpops'][prety]>dconf['net']['allpops'][poty]:
blist, connCoords = connectLayerswithOverlap(NBpreN=dnumc[prety],NBpostN=dnumc[poty],overlap_xdir = dtopolconvcons[prety][poty], \
padded_preneurons_xdir = dnumc_padx[prety], padded_postneurons_xdir = dnumc_padx[poty])
elif dconf['net']['allpops'][prety]<dconf['net']['allpops'][poty]:
blist, connCoords = connectLayerswithOverlapDiv(NBpreN=dnumc[prety],NBpostN=dnumc[poty],overlap_xdir = dtopoldivcons[prety][poty], \
padded_preneurons_xdir = dnumc_padx[prety], padded_postneurons_xdir = dnumc_padx[poty])