-
Notifications
You must be signed in to change notification settings - Fork 1
/
syncode.hoc
1607 lines (1498 loc) · 54 KB
/
syncode.hoc
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
// $Id: syncode.hoc,v 1.412 2011/07/29 18:56:31 billl Exp $
print "Loading syncode.hoc..."
//* setup
{load_file("grvec.hoc")}
{load_file("labels.hoc")}
{load_file("nqs.hoc")}
strdef syn1,syn2
thresh = -20
objref cp,svs,ncq,intf,vq
objref ivspks,vspks,wvspks,ncl[1][1][1]
objref sp[3], c[1], ce, nc[1], cells[10] // enough room for 10 cell types
objref vite
double numc[CTYPi],ix[CTYPi],ixe[CTYPi],wmat[CTYPi][CTYPi][STYPi],wd0[CTYPi][CTYPi][STYPi]
Incol=2
ncl = new List()
sp = new NQS()
//* iterator ixt(),ctt(),stt()
// ctt() iterates over all cells; eg for ctt() print ii
iterator ctt () { local jj // global ii
if (argtype(2)==3) $&2=0 else i1=0
for jj=0,CTYPi-1 if (numc[jj]!=0) {
if (ce!=nil) if (ix[jj]<ce.count()) {
if (argtype(1)==1) $o1=ce.o(ix[jj]) else XO=ce.o(ix[jj])
}
if (argtype(1)==3) $&1=jj else ii=jj
iterator_statement
if (argtype(2)==3) $&2+=1 else i1+=1
}
}
//* iterator cttr() -- reverse iterator of ctt
iterator cttr () { local jj // global ii
if (argtype(2)==3) $&2=0 else i1=0
for(jj=CTYPi-1;jj>=0;jj-=1) if (numc[jj]!=0) {
if (ce!=nil) if (ix[jj]<ce.count()) {
if (argtype(1)==1) $o1=ce.o(ix[jj]) else XO=ce.o(ix[jj])
}
if (argtype(1)==3) $&1=jj else ii=jj
iterator_statement
if (argtype(2)==3) $&2+=1 else i1+=1
}
}
// stt() iterates over all synapse types
iterator stt () { local ia,ja,ka,ib,jb,im,jm // global ii,jj,kk
i1=ib=jb=0 im=jm=CTYPi-1
if (argtype(1)==0) if ($1>=0) ib=im=$1
if (argtype(2)==0) if ($2>=0) jb=jm=$2
if (argtype(4)==3) $&4=0
for ia=ib,im for ja=jb,jm if (numc[ia]!=0 && numc[ja]!=0) {
if (ce!=nil) if (ix[ia]<ce.count()) {XO=ce.o(ix[ia]) YO=ce.o(ix[ja])}
for ka=0,STYPi-1 if (wmat[ia][ja][ka]!=0) {
if (argtype(3)==3) { $&1=ia $&2=ja $&3=ka } else { ii=ia jj=ja kk=ka }
iterator_statement
if (argtype(4)==3) $&4+=1 else i1+=1
}
}
}
ixi=ixj=0 // ixi steps through cell#s and ixj is consecutive
for ii=0,CTYPi-1 ixe[ii]=-1
// ctype(#,TYPE)
func ctype () { local ii
if (numarg()==2) {
return ($1>=ix[$2] && $1<=ixe[$2])
} else {
for ii=0,CTYPi-1 if ($1>=ix[ii] && $1<=ixe[ii]) return ii
return -1
}
}
// ixt(type[,col,vec]); ixt(type,&x); ixt(type,col,&x)
iterator ixt () { local ty,col,a,lfl,ixa,i localobj o
ty=$1 lfl=0
if (argtype(2)==0) col=$2 else { col=-1 if (argtype(2)==3) lfl=2 }
if (argtype(3)==1) { o=$o3 vrsz(numc[ty],o,"O") } else if (argtype(3)==3) lfl=3
i=lfl
if (col<0) {
for ({ixa=ix[ty] ixj=0};ixa<=ixe[ty];{ixa+=1 ixj+=1}) { XO=ce.o(ixa)
if (lfl) $&i=ixa else ixi=ixa
iterator_statement
}
} else {
if (col>=ncols) printf("ixt ERR: Only %d columns (%d)\n",ncols,col) else {
a=ix[ty]+col*numc[ty]/ncols
for ({ixa=a ixj=0};ixa<a+numc[ty]/ncols;{ixa+=1 ixj+=1}) { XO=ce.o(ixa)
if (XO.col!=col) printf("ixt ERR: XO.col!=col, %d %d\n",XO.col,col)
if (lfl) $&i=ixa else ixi=ixa
iterator_statement
}
}
}
if (o!=nil) stat(o)
}
// for ltr(XO,cvode.netconlist("", "", "")) print XO.precell,XO.postcell,XO.syn
//* synapse linking -- old routines not using NQS
//** geolink(s1,s2,s3) s1 for presyns and s2 for postsyns, connect s3's
// only checks for INTF as a possible pre/post point process
// connects a layer to another assuming 1 dim netgeom
proc geolink() { local i,ii,a,sav,nowrap,noself
if (numarg()==0) { print "\tgeolink(s1,s2,s3,DEFCON)"
print " make connections from s1 to s2 connecting onto s3 type PPs."
print " DEFCON struct defines connection"
return
}
// default to yes wrap; yes within-column connect unless $s1==$s2
nowrap = !$o4.wrap noself=!$o4.self
if (strcmp($s1,$s2)==0) $o4.self=0
tmpobj=new List($s1)
// object containing a receive/event PP need fflag=1 and intf as name of PP
if (tmpobj.object(0).fflag) { // presynaptic object flag
sprint(temp_string_,"ncl.append(new NetCon(XO.intf, YO.%s))",$s3)
} else {
sprint(temp_string_,"XO.soma ncl.append(new NetCon(&v(.5), YO.%s))",$s3)
}
for ltr (XO,tmpobj,&y) { // presyn list
$o4.grot(y)
for lvtr (YO,&x,new List($s2),$o4.scr) { // postsyn list and vector
if (x==1) { // connect
print "connecting ",XO," to ",YO
execute(temp_string_)
}
}
}
XO=nil YO=nil
}
//** glink() same as geolink but takes lists statt strings
proc glink() { local i,ii,a,sav,nowrap,noself
if (numarg()==0) { print "\tgeolink(l1,l2,DEFCON)"
print " make connections from items in l1 to items in l2."
print " DEFCON struct defines connection"
return
}
// default to yes wrap; yes within-column connect unless $s1==$s2
nowrap = !$o4.wrap noself=!$o4.self
// object containing a receive/event PP need fflag=1 and intf as name of PP
if ($o1.object(0).fflag) { // presynaptic object flag
sprint(temp_string_,"ncl.append(new NetCon(XO.intf, YO.%s))",$s3)
} else {
sprint(temp_string_,"XO.soma ncl.append(new NetCon(&v(.5), YO.%s))",$s3)
}
for ltr (XO,$o1,&y) { // presyn list
$o4.grot(y)
for lvtr (YO,&x,$o2,$o4.scr) { // postsyn list and vector
if (x==1) { // connect
// print "connecting ",XO," to ",YO
execute(temp_string_)
}
}
}
XO=nil YO=nil
}
//** synlink(s1,s2,s3,[gmax,del]) s1 for presyns and s2 for postsyns, connect s3's
// eg synlink("PYR","INH","AMPA")
// provides full connectivity
proc synlink() { local gm,dl
if (numarg()==0) { print "\tsynlink(s1,s2,s3)"
print " make connections from all of type s1 to one of type s2 "
print " only connecting onto s3 type PPs."
print " Matching done with regexps."
return
}
if (numarg()==5) { gm=$4 dl=$5 } else { gm=0 dl=1 }
tmplist = new List($s3) // list of postsyn point processes
for ltr (XO,new List($s1)) { // presyn list
for ltr (YO,tmplist) {
if (pp_loc(YO,$s2,syn2)) {
sfunc.head(syn2,"\\.",syn2)
sprint(syn1,"%s",XO)
if (strcmp(syn1,syn2)!=0) { // don't allow self connects
print "connecting ",XO," to ",syn2
XO.soma ncl.append(new NetCon(&v(.5), YO, thresh, gm, dl))
}
}
}
}
}
// run NQS.mo(1) first to set up PRIDv ... vectors
//** simple netconnect routines: netconn(), netgen()
proc netconn () { local pre,post,syn,pri,poi
pre=$1 post=$2
if (numarg()==5) { syn=$3 pri=$4 poi=$5 } else { syn=0 pri=$3 poi=$4 }
cells[pre].object(pri).conn(cells[post].object(poi).syns[syn])
}
proc netgen () { ncl.append(new NetCon($o1, $o2)) }
//** syncopy() copies from one set of syns to another for colocalization
proc syncopy () {
if (numarg()==0) { printf("syncopy(to_type,[]): copy from type, post/type, pre/post/type\n") return }
sprint(temp_string_,"XO.precell.soma ncl.append(new NetCon(&v(.5),XO.postcell.%s",$s1)
if (numarg()==1) tmplist = cvode.netconlist("", "" , $s2)
if (numarg()==2) tmplist = cvode.netconlist("", $s2, $s3)
if (numarg()==3) tmplist = cvode.netconlist($s2, $s3, $s4)
for ltr(XO,tmplist) execute(temp_string_)
}
//** syn1to1(PRE,POST,SYN)
proc syn1to1 () { local pre,post,syn
pre=$1 post=$2
if (numarg()==3) syn=$3 else syn=0
if (cells[pre].count !=cells[post].count) {
printf("\tERROR: 1-to-1 connectivity requires same # of %s (=%d) and %s (=%d).\n",\
CTYP.object(pre).s,cells[pre].count,CTYP.object(post).s,cells[post].count) return }
for ltr2(XO,YO,cells[pre],cells[post]) {
printf("SRC: %s -> TRG: %s (%s)\n",XO,YO,YO.syns(syn))
XO.conn(YO.syns[syn])
}
}
//* synconn() synapse linking -- NQS routines
//** synconn(preid,postid,pre#,post#,%div)
// eg synconn(PYRi,PYRi,AMPAi,pmat[PYR][PYR])
// provides % connectivity based on C/pre==%div==%conv==D/post
// S==C*post==D*pre %conv=S/(post*pre)=C/pre=D/post
objref convec,convec1,convec2 // vectors to count how much div is from each nrn
convec = new Vector(1e3)
convec1 = convec.c // a scratch vector
convec2 = convec.c // copy of convec to blot out self-connect and redundent connects
proc synconn () { local preid,posid,pdiv,con,div,ii,jj,prn,pon,targ,sz,styp1,styp2
if (numarg()==0) { print "\tsynconn(preid,postid,prn,pon,pdiv)" return }
preid=$1 posid=$2 prn=$3 pon=$4 pdiv=$5
CODEv=sp.v[sp.fi("CODE")] PRv=sp.v[sp.fi("PR")] POv=sp.v[sp.fi("PO")]
sz=PRv.size
if (pdiv==1) {
if (preid==posid) div=pon-1 else div=pon
con=div
} else {
con=int(pdiv*prn+1) div=int(pdiv*pon)
}
if (isobj(CTYP,"List")) {
printf("%s->%s:\tdiv=%d,conv=%d (%d syns)\n",CTYP.object(preid).s,CTYP.object(posid).s,div,con,prn*div)
} else {
printf("%d->%d:\tdiv=%d,conv=%d (%d syns)\n",preid,posid,div,con,prn*div)
}
if (prn*div==0) return
sp.pad(sz+prn*div)
if (pdiv==1) {
convec.indgen(0,pon-1,1)
for ii=0,prn-1 {
if (preid==posid) {convec.indgen(0,pon-1,1) convec.remove(ii)}
POv.copy(convec,sz+ii*div)
PRv.fill(ii,sz+ii*div,sz+(ii+1)*div-1)
}
} else {
convec.resize(pon) convec.fill(0) // counter for convergence
for ii=0,prn-1 { // sources
convec2.copy(convec)
if (preid==posid) convec2.x[ii]=1e10 // block self-connect
for jj=1,div POv.set(sz+ii*div+jj-1,pickpost(pon,con)) // pick desired target
PRv.fill(ii,sz+ii*div,sz+(ii+1)*div-1)
}
}
CODEv.fill(mkcodf(preid,posid,0,0,0),sz,PRv.size-1)
}
proc syncnn () { local preb,pree,posb,pose,pdiv,con,div,ii,jj,prn,pon,targ,sz,styp1,styp2
if (numarg()==0) { print "\tsyncnn(preb,pree,posb,pose,pdiv)" return }
preb=$1 pree=$2 posb=$3 pose=$4 pdiv=$5
CODEv=sp.v[sp.fi("CODE")] PRv=sp.v[sp.fi("PR")] POv=sp.v[sp.fi("PO")]
sz=PRv.size
prn=pree-preb+1 pon=pose-posb+1
if (pdiv==1) {
if (preid==posid) div=pon-1 else div=pon
con=div
} else {
con=int(pdiv*prn+1) div=int(pdiv*pon)
}
if (isobj(CTYP,"List")) {
printf("%s->%s:\tdiv=%d,conv=%d (%d syns)\n",CTYP.object(preid).s,CTYP.object(posid).s,div,con,prn*div)
} else {
printf("%d->%d:\tdiv=%d,conv=%d (%d syns)\n",preid,posid,div,con,prn*div)
}
if (prn*div==0) return
sp.pad(sz+prn*div)
if (pdiv==1) {
convec.indgen(0,pon-1,1)
for ii=0,prn-1 {
if (preid==posid) {convec.indgen(0,pon-1,1) convec.remove(ii)}
POv.copy(convec,sz+ii*div)
PRv.fill(ii,sz+ii*div,sz+(ii+1)*div-1)
}
} else {
convec.resize(pon) convec.fill(0) // counter for convergence
for ii=0,prn-1 { // sources
convec2.copy(convec)
if (preid==posid) convec2.x[ii]=1e10 // block self-connect
for jj=1,div POv.set(sz+ii*div+jj-1,pickpost(pon,con)) // pick desired target
PRv.fill(ii,sz+ii*div,sz+(ii+1)*div-1)
}
}
PRv.add(preb) POv.add(posb)
CODEv.fill(mkcodf(preid,posid,0,0,0),sz,PRv.size-1)
}
//** synconn2() uses elimrepeats() and shuffle methods
proc synconn2 () { local preid,posid,pdiv,con,div,ii,jj,prn,pon
if (numarg()==0) { print "\tsynconn2(preid,postid,prn,pon,pdiv)" return }
preid=$2 posid=$3 prn=$4 pon=$5 pdiv=$6
$o1.clear()
PRv=$o1.v[$o1.fi("PR")] POv=$o1.v[$o1.fi("PO")]
con=int(pdiv*prn+1) div=int(pdiv*pon)
if (prn*div==0) return
printf("%s->%s:\tdiv=%d,conv=%d (%d syns)\n",CTYP.object(preid).s,CTYP.object(posid).s,div,con,prn*div)
if (pdiv==1) {
$o1.pad(prn*div)
convec.indgen(0,pon-1,1)
for ii=0,prn-1 {
POv.copy(convec,ii*div)
PRv.fill(ii,ii*div,(ii+1)*div-1)
}
} else {
$o1.pad(1.5*prn*div)
rdm.discunif(0,prn-1) PRv.setrand(rdm)
rdm.discunif(0,pon-1) POv.setrand(rdm)
$o1.elimrepeats("PR","PO")
$o1.shuffle()
$o1.pad(prn*div)
}
$o1.fill("CODE",1,preid) $o1.fill("CODE",2,posid)
}
//** synconn3() doesn't worry about eliminating repeats
proc synconn3 () { local preid,posid,pdiv,con,div,ii,jj,prn,pon
if (numarg()==0) { print "\tsynconn2(preid,postid,prn,pon,pdiv)" return }
preid=$2 posid=$3 prn=$4 pon=$5 pdiv=$6
$o1.clear()
PRv=$o1.v[$o1.fi("PR")] POv=$o1.v[$o1.fi("PO")]
con=int(pdiv*prn+1) div=int(pdiv*pon)
if (prn*div==0) return
printf("%s->%s:\tdiv=%d,conv=%d (%d syns)\n",CTYP.object(preid).s,CTYP.object(posid).s,div,con,prn*div)
$o1.pad(prn*div)
rdm.discunif(0,prn-1) PRv.setrand(rdm)
rdm.discunif(0,pon-1) POv.setrand(rdm)
$o1.fill("CODE",1,preid) $o1.fill("CODE",2,posid)
}
//*** pickpost() tries to reduce divergence variance
// pickpost(postlist,maxcon,YO)
// maxcon == -1 means to ignore convergence
// MUST do convec.resize() and convec.fill(0) before using
func pickpost () { local ran, maxcon, maxpo, min, indx
maxcon = $2 // max convergence to be allowed
maxpo = $1 // number of postsyn choices
min = convec2.min // convec should start all 0's
if (min >= maxcon) { // all full up
printf("Pickpost full WARNING: %d %d\n",min,maxcon) vlk(convec2) }
convec1.indvwhere(convec2,"==",min) // look for all the smallest to fill up first
inx = convec1.x[rdm.discunif(0,convec1.size-1)]
convec.x[inx]+=1
convec2.x[inx]=1e10 // block from reconnecting here
return inx
}
//** smap()
// excitatory cells project to AMPA and inhibitory cells to GABA
// assumes PRIDv ... defined by sp.mo(1)
objref pro,poo // pre and post pointers
func smap () { local ct,sy,conv,prdx,podx,prx,pox,delx,w0x,w1x localobj nc,ty
ty=new Union()
ct=cp.fi("PRID") sy=cp.fi("STYP")
sp.resize("NC")
sp.odec("NC")
sp.pad()
sp.mo(1)
for ii=0,PRv.size-1 {
uncodf(CODEv.x[ii],&prdx,&podx) prx=PRv.x[ii] pox=POv.x[ii]
delx=DELv.x[ii] w0x=WT0v.x[ii] w1x=WT1v.x[ii]
pro=c[prdx].object(prx) poo=c[podx].object(pox)
NCv.x[ii]=sp.fcdo.append(nc=smap1(prdx))-1
for kk=0,nc.wcnt-1 nc.weight[kk]=0
x=cp.fetch(ct,prdx,sy)
syntyp(x,ty)
nc.weight[ty.x]=w0x
if (ty.x[1]>-1) nc.weight[ty.x[1]]=w1x
nc.delay=delx
}
return ii
}
//*** smap1(SYN#) poo has postsyn and pro has pre
obfunc smap1 () { localobj si
if (poo.fflag) { YO=poo
} else {
YO=poo.po[$1]
if (isobj(YO,"List")) {
snsr($1,poo)
YO=YO.object(YO.count-1)
}
}
if (pro.fflag) { si=new NetCon(pro, YO)
} else { pro.soma si=new NetCon(&v(0.5),YO) }
return si
}
//*** snsr() handles situation where multiple PPs must be hung onto postsyn objref
proc snsr () {
printf("PROBLEM: replace snsr() which uses an execute\n")
if (isobj($o2.po[$1],"List")) {
sprint(tstr,"%s.soma %s.po[%d].append(new %s(0.5))",$o2,$o2,$1,STYP.object($1).s)
} else {
sprint(tstr,"%s.soma %s.po[%d] = new %s(0.5)",$o2,$o2,$1,STYP.object($1).s)
}
execute(tstr)
}
//** umbrella(preid,postid,max,width[,shift])
// set lateral projections from pre to post out to width
// sets direct connection (jj==ii) iff preid!=posid
proc umbrella () { local ii,jj,preid,posid,width,sh,max,sz,styp1,styp2
preid=$1 posid=$2 max=$3 width=$4
if (numarg()>=5) sh=$5 else sh=0
sz=PRv.size styp1=styp2=-1
if (width) {
for ii=0,max-1 for jj=ii-width+sh,ii+width+sh {
if (jj>=0 && jj<max && (preid!=posid || jj!=ii)) {
PRv.append(ii) POv.append(jj)
PRIDv.append(preid) POIDv.append(posid)
}
}
} else { // just within column connections
for ii=0,max-1 { PRv.append(ii) POv.append(ii) PRIDv.append(preid) POIDv.append(posid) }
}
sp.pad()
// WID0v.fill(styp1,sz,PRv.size-1)
// WID1v.fill(styp2,sz,PRv.size-1)
}
//** umbflow(preid,postid,max,width[,shift])
// like umbrella but does 'flow' boundary conditions -- reflects back on sides
proc umbflow () { local ii,jj,ja,preid,posid,width,sh,max,sz,styp1,styp2
preid=$1 posid=$2 max=$3 width=$4
if (numarg()>=5) sh=$5 else sh=0
sz=PRv.size styp1=styp2=-1
if (width) {
for ii=0,max-1 for jj=ii-width+sh,ii+width+sh {
if (preid!=posid || jj!=ii) { ja=jj
if (jj<0) ja=-jj
if (jj>max-1) ja=2*max-jj-2
PRv.append(ja) POv.append(ii)
PRIDv.append(preid) POIDv.append(posid)
}
}
} else { // just within column connections
for ii=0,max-1 { PRv.append(ii) POv.append(ii) PRIDv.append(preid) POIDv.append(posid) }
}
sp.pad()
// WID0v.fill(styp1,sz,PRv.size-1)
// WID1v.fill(styp2,sz,PRv.size-1)
}
//** nqdiv(PRID,POID,PR,PO0[,PO1,...])
// nqdiv(PRID,POID,PR,POBEG,..,POEND)
proc nqdiv () { local i,beg,end
if (numarg()==0) {
print "nqdiv(PRID,POID,PR,PO0[,PO1,...])\nnqdiv(PRID,POID,PR,POBEG,\"..\",POEND)" return }
if (numarg()==6 && argtype(5)==2) {
beg=$4 end=$6
for i=beg,end sp.append("CODE",EQU1,$1,"CODE",EQU2,$2,"PR",$3,"PO",i)
} else for i=4,numarg() sp.append("CODE",EQU1,$1,"CODE",EQU2,$2,"PR",$3,"PO",$i)
sp.pad()
}
//** nqconv(POID,PRID,PO,PR0[,PR1,...])
// nqconv(POID,PRID,PO,PRBEG,..,PREND)
proc nqconv () { local i,beg,end
if (numarg()==0) {
print "nqconv(POID,PRID,PO,PR0[,PR1,...])\nnqconv(POID,PRID,PO,PRBEG,\"..\",PREND)" return }
if (numarg()==6 && argtype(5)==2) {
beg=$4 end=$6
for i=beg,end sp.append("PRID",$2,"POID",$1,"PR",i,"PO",$3)
} else for i=4,numarg() sp.append("PRID",$2,"POID",$1,"PR",$i,"PO",$3)
sp.pad()
}
//** proc nq1to1(PRID,POID,num)
proc nq1to1 () { umbrella($1,$2,$3,0) }
//* direct weight setting routines
//** scale gmax
proc synscgmax () {
for ltr(XO,cvode.netconlist("" , "", $s1)) { XO.weight *= $2 }
}
//** set/get gmax
proc synsetgmax () {
if (numarg()==0) { print "synsetgmax(pre,post,type,wt)"
} else if (numarg()==2) {for ltr(XO,cvode.netconlist("" , "", $s1)) XO.weight=$2
} else if (numarg()==3) {for ltr(XO,cvode.netconlist("" , $s1, $s2)) XO.weight=$3
} else if (numarg()==4) {for ltr(XO,cvode.netconlist($s1 , $s2, $s3)) XO.weight=$4
} else { print "ERROR: too many args" }
if (i1==0) printf("WARNING: nothing set in synsetgmax(%s ...)\n",$s1)
}
// synnormgmax() -- like synsetgmax except normalizes the wt by convergence
proc synnormgmax () {
for ltr(XO,cvode.netconlist($s1 , $s2, $s3)) {
XO.weight=$4/cvode.netconlist($s1,XO.postcell,$s3).count
}
}
proc syngetgmax () {
if (numarg()==1) {
if (strcmp($s1,"help")==0) { printf("type,post/type,pre/post/type\n") } else {
for ltr(XO,cvode.netconlist("" , "", $s1)) printf("%g ",XO.weight) }
} else if (numarg()==2) {for ltr(XO,cvode.netconlist("" , $s1, $s2)) printf("%g ",XO.weight)
} else if (numarg()==3) {for ltr(XO,cvode.netconlist($s1 , $s2, $s3)) printf("%g ",XO.weight)
} else for ltr(XO,cvode.netconlist("","","")) printf("%g ",XO.weight)
print ""
}
//** set/get delay
proc synsetdel () {
if (numarg()==2) {for ltr(XO,cvode.netconlist("" , "", $s1)) XO.delay=$2
} else if (numarg()==3) {for ltr(XO,cvode.netconlist("" , $s1, $s2)) XO.delay=$3
} else if (numarg()==4) {for ltr(XO,cvode.netconlist($s1 , $s2, $s3)) XO.delay=$4
} else { print "ERROR: too many args" }
if (i1==0) printf("WARNING: nothing set in synsetdel(%s ...)\n",$s1)
}
proc syngetdel () {
if (numarg()==1) {for ltr(XO,cvode.netconlist("" , "", $s1)) printf("%g ",XO.delay)
} else if (numarg()==2) {for ltr(XO,cvode.netconlist("" , $s1, $s2)) printf("%g ",XO.delay)
} else if (numarg()==3) {for ltr(XO,cvode.netconlist($s1 , $s2, $s3)) printf("%g ",XO.delay)
} else for ltr(XO,cvode.netconlist("","","")) printf("%g ",XO.delay)
print ""
}
//** set/get thresh
proc synsetthr () {
if (numarg()==1) {for ltr(XO,cvode.netconlist("" , "", "")) XO.threshold=$1
} else if (numarg()==2) {for ltr(XO,cvode.netconlist($s1 , "", "")) XO.threshold=$2
} else if (numarg()==3) {for ltr(XO,cvode.netconlist($s1, "", $s2)) XO.threshold=$3
} else if (numarg()==4) {for ltr(XO,cvode.netconlist($s1 , $s2, $s3)) XO.threshold=$4
} else { print "ERROR: too many args" }
if (i1==0) printf("WARNING: nothing set in synsetthr(%s ...)\n",$s1)
}
proc syngetthr () {
if (numarg()==1) {for ltr(XO,cvode.netconlist($s1 , "", "")) printf("%g ",XO.threshold)
} else if (numarg()==2) {for ltr(XO,cvode.netconlist($s1, "", $s2)) printf("%g ",XO.threshold)
} else if (numarg()==3) {for ltr(XO,cvode.netconlist($s1 , $s2, $s3)) printf("%g ",XO.threshold)
} else for ltr(XO,cvode.netconlist("","","")) printf("%g ",XO.threshold)
print ""
}
//** synremove: remove post, pre/post, pre/post/type; synshow
proc synremove () {
if (numarg()==0) { printf("synremove: remove post, pre/post, pre/post/type\n") return }
if (numarg()==1) tmplist = cvode.netconlist("", $s1 , "")
if (numarg()==2) tmplist = cvode.netconlist("", $s1, $s2)
if (numarg()==3) tmplist = cvode.netconlist($s1 , $s2, $s3)
if (tmplist.count>0) for ltr(XO,tmplist) ncl.remove(ncl.index(XO))
tmplist = nil // need to remove these references too
if (numarg()==1) tmplist = cvode.netconlist("", $s1 , "")
if (numarg()==2) tmplist = cvode.netconlist("", $s1, $s2)
if (numarg()==3) tmplist = cvode.netconlist($s1 , $s2, $s3)
if (tmplist.count>0) for ltr(XO,tmplist) printf("ERROR: %s removed from ncl but still exists\n",XO)
tmplist = nil
}
proc synshow () {
sprint(temp_string_,"x=XO.%s",$s2)
for ltr(XO,cvode.netconlist("" , "", $s1)) { execute(temp_string_) printf("%g ",x) }
print ""
}
//* weight setting routines using NQS
//** stwt(PREID,POSTID,WT0[,WT1,norm])
// stwtnorm() causes dividing by individual convergence values
proc stwt () { local w0,w1
if (sp.select(-1,"CODE",EQU1,$1,"CODE",EQU2,$2) ==0) {
printf("WARNING NO CONNECTS FROM %d TO %d\n",$1,$2) return }
w0=$3
if (numarg()>=5) { w0=$3/$5 w1=$4/$5 } else if (numarg()>=4) { w1=$4 }
if (numarg()>=4) sp.fillin("WT0",w0,"WT1",w1) else sp.fillin("WT0",w0)
}
//** strwt(PREID,POSTID,WT0,WT1,psdev[,norm])
proc strwt () { local w0,w1,psdev
cnt=sp.select("CODE",EQU1,$1,"CODE",EQU2,$2)
if (cnt==0) {printf("WARNING NO CONNECTS FROM %d TO %d\n",$1,$2) return }
if (numarg()>=6) { w0=$3/$6 w1=$4/$6 } else { w0=$3 w1=$4 }
psdev=$5
rdm.lognormal(w0,psdev*psdev*w0*w0)
sp.out.v[sp.fi("WT0")].setrand(rdm)
if (w1!=0) {
rdm.lognormal(w1,psdev*psdev*w1*w1)
sp.out.v[sp.fi("WT1")].setrand(rdm)
}
sp.delect()
}
//** strwt2(NQS,WT0,WT1,psdev[,norm])
proc strwt2 () { local w0,w1,psdev
if (numarg()>=5) { w0=$2/$5 w1=$3/$5 } else { w0=$2 w1=$3 }
psdev=$4
rdm.lognormal(w0,psdev*psdev*w0*w0)
$o1.v[$o1.fi("WT0")].setrand(rdm)
if (w1!=0) {
rdm.lognormal(w1,psdev*psdev*w1*w1)
$o1.v[$o1.fi("WT1")].setrand(rdm)
}
}
//** strdel(PREID,POSTID,del,psdev)
proc strdel () { local del0,psdev
if (numarg()==4) {
cnt=sp.select("CODE",EQU1,$1,"CODE",EQU2,$2)
if (cnt==0) {printf("WARNING NO CONNECTS FROM %d TO %d\n",$1,$2) return }
del0=$3 psdev=$4
rdm.lognormal(del0,psdev*psdev*del0*del0)
sp.out.v[sp.fi("DEL")].setrand(rdm)
sp.delect()
} else { del0=$2 psdev=$3
rdm.lognormal(del0,psdev*psdev*del0*del0)
$o1.v[sp.fi("DEL")].setrand(rdm)
}
}
//** clrwt(PRID,POID,%clr)
proc clrwt () { local n
n=round($3*sp.select("CODE",EQU1,$1,"CODE",EQU2,$2))
sp.out.v[sp.fi("WT0")].fill(0,0,n)
sp.delect()
}
//** chksp() confirm correspondance between sp and ncl -- defunct if using multiple ncl
proc chksp () { local prid,poid,pr,po
for ltr(XO,ncl,&x) {
prid=sp.v[0].x[x] poid=sp.v[1].x[x] pr=sp.v[2].x[x] po=sp.v[3].x[x]
if (XO.pre.id!=pr || XO.pre.type!=prid || XO.syn.id!=po || XO.syn.type!=poid) {
printf("%d %d %d %d %d %d %d %d\n",XO.pre.id,pr,XO.pre.type,prid,XO.syn.id,po,XO.syn.type,poid) }}
}
//** swtmap() -- redund code to permit it to run relatively fast
// no longer overloaded to set delay, delmap() or to clr clrwts()
proc swtmap () { local ii,ct,sy,conv,prx,pox,delx,w0x,w1x localobj nc,ty
ty=new Union()
ct=cp.fi("PRID") sy=cp.fi("STYP")
if (PRv.size!=$o1.count) {
printf("swtmap ERR: size discrepency: %d vs %d\n",PRv.size,$o1.count)
return }
for ii=0,PRv.size-1 {
prdx=PRIDv.x[ii] podx=POIDv.x[ii] prx=PRv.x[ii] pox=POv.x[ii]
delx=DELv.x[ii] w0x=WT0v.x[ii] w1x=WT1v.x[ii]
nc=$o1.object(ii)
poo=nc.syn
x=cp.fetch(ct,prdx,sy)
syntyp(x,ty)
nc.weight[ty.x]=w0x
if (ty.x[1]>-1) nc.weight[ty.x[1]]=w1x
nc.delay=delx
}
}
//** wmul(PRID,POID,SYNID,MUL) multiplies set of syns by a factor
// resets from weights stored in sp
for ii=0,CTYPi-1 for jj=0,CTYPi-1 for kk=0,STYPi-1 wd0[ii][jj][kk]=1
proc wmul () { local ii,pr1,po1,sy1,w1,wd,sy2
pr1=$1 po1=$2 sy1=$3 w1=$4
if (wd0[pr1][po1][sy1]==0) {
if (w1!=0) printf("\nWARNING: %s->%s(%s) set to 0 can't reset\n",\
CTYP.o(pr1).s,CTYP.o(po1).s,STYP.o(sy1).s)
return
}
wd=w1/wd0[pr1][po1][sy1]
if (wd!=1) {
XO=ncl[pr1][po1][0]
for ii=0,XO.count-1 XO.o(ii).weight[sy1]*=wd
wd0[pr1][po1][sy1]=w1
} else printf(".")
}
//** wset(PRID,POID,SYNID,WT) resets weights to gaussian dist similar to strwt()
// uses sp to determine how many weights are needed
proc wset () { local num,prx,pox,sox,wet,a,err,psdev localobj v1
prx=$1 pox=$2 sox=$3 wet=$4
if (numarg()==5) psdev=$5*$5 else psdev=0
err=0 a=allocvecs(v1)
if (cp.fetch("PRID",prx,"STYP")==EX && !(sox==AM || sox==NM)) err=1
if (cp.fetch("PRID",prx,"STYP")==IX && !(sox==GA || sox==GB)) err=1
if (err) { printf("cell/syn discrepancy: %d -> %d\n",prx,sox) return }
if (Incol==2) num=sp.select(-1,"CODE",EQU1,prx,"CODE",EQU2,pox) else {
num=sp.select(-1,"CODE",EQU1,prx,"CODE",EQU2,pox,"CODE",EQU3,Incol)
}
v1.resize(num)
if (psdev) {
rdm.normal(wet,psdev*wet*wet)
v1.setrand(rdm)
} else v1.fill(wet)
vwtmap(v1,sp,sox)
dealloc(a)
}
//** wbim(PRID,POID,SYNID,PSDEV,%A,WTA,%B,WTB,...) bimodal weight setting routines
// uses sp to determine how many weights are needed
proc wbim () { local fsz,i,prx,pox,sox,wet,a,err,psdev,pcw,ptot localobj v1,v2
prx=$1 pox=$2 sox=$3 psdev=$4*$4 pcw=$5 wet=$6 ptot=0
err=0 a=allocvecs(v1,v2)
if (cp.fetch("PRID",prx,"STYP")==EX && !(sox==AM || sox==NM)) err=1
if (cp.fetch("PRID",prx,"STYP")==IX && !(sox==GA || sox==GB)) err=1
if (err) { printf("cell/syn discrepancy: %d -> %d\n",prx,sox) return }
fsz=sp.select(-1,"CODE",EQU1,prx,"CODE",EQU2,pox)
for i=5,numarg() {
pcw=$i i+=1 wet=$i //
if (pcw*fsz != int(pcw*fsz)){
printf("wbim WARNING: %d->%d non-int %gx%g=%g\n",prx,sox,pcw,fsz,pcw*fsz) }
v2.resize(int(pcw*fsz))
rdm.normal(wet,psdev*wet*wet)
v2.setrand(rdm)
v1.append(v2)
ptot+=pcw // keep track of percent filled
}
if (ptot!=1) printf("wbim WARNING: %d->%d only %g filled\n",prx,pox,ptot)
if (v1.size!=fsz) {
printf("wbim WARNING: %d->%d size error %d->%d\n",prx,sox,v1.size,fsz)
v1.resize(fsz) }
vwtmap(v1,sp,sox)
dealloc(a)
}
//** vwtmap(VEC,NQS) -- copy weights from a vector onto ncl
// vwtmap(NQS,VEC) -- copy weights from ncl into vector
func vwtmap () { local wix
if (numarg()==3) wix=$3 else wix=0
if (isojt($o2,sp)) { // copy from vector to sp.fcdo weights
if ($o1.size!=$o2.ind.size){
printf("vwtmap ERR: size discrepency: %d vs %d\n",$o1.size,$o2.ind.size)
return 0}
for ii=0,$o1.size-1 $o2.fcdo.o[$o2.ind.x[ii]].weight[wix]=$o1.x[ii]
return $o1.size
} else { // copy from ncl weights to vector
if ($o1.ind.size!=$o2.size){printf("vwtmap WARNING: resizing vec\n") $o2.resize($o1.ind.size)}
for ii=0,$o2.size-1 $o2.x[ii]=$o1.o[$o1.ind.x[ii]].weight[wix]
return $o2.size
}
}
//** wtstat(WIX) -- check id of weights directly from the ncs
// assume that have already been selected in sp.out
proc wtstat () { local wix,a,sz,fnc localobj v1
a=allocvecs(v1)
if (!eqojt(sp.cob,sp.out)) print "WARNING: no sp.select() done"
sz=sp.size(1) fnc=sp.fi("NC")
v1.resize(sz) v1.resize(0)
if (numarg()==1) wix=$1 else wix=0
// for sp.qt(XO,"NC") v1.append(XO.weight[wix]) // 5x slower
for ii=0,sz-1 v1.append(sp.fcdo.o(sp.out.v[fnc].x[ii]).weight[wix])
stat(v1)
dealloc(a)
}
// need to set delays
proc delmap () { local ii,deli,nc0,nc1
nc0=$o1.fi("NC0") nc1=$o1.fi("NC1","NOERR") deli=$o1.fi("DEL")
for ii=0,$o1.v.size-1 {
ncl.object($o1.v[nc0].x[ii]).delay=$o1.v[deli].x[ii]
if (nc1!=-1) if ($o1.v[nc1].x[ii]!=-1) {
ncl.object($o1.v[nc1].x[ii]).delay=$o1.v[deli].x[ii] }
}
}
// clrwtmap
proc clrwts () { local ii,jj,nc0,wt0,deli,nc1,wt1,typ,sy2,wid0,wid1,clr
nc0=$o1.fi("NC0") wt0=$o1.fi("WT0") deli=$o1.fi("DEL")
wid0=$o1.fi("WID0") typ=$o1.fi("TYPE")
nc1=$o1.fi("NC1","NOERR") wt1=$o1.fi("WT1","NOERR") wid1=$o1.fi("WID1","NOERR")
tobj=ncl.object($o1.v[nc0].x[ii])
for ii=0,$o1.v.size-1 {
tobj=ncl.object($o1.v[nc0].x[ii])
for jj=0,tobj.wcnt-1 tobj.weight[jj]=0 // clear
tobj.delay=1 tobj.threshold=0
if (nc1!=-1) if ($o1.v[nc1].x[ii]!=-1) for jj=0,tobj.wcnt-1 tobj.weight[jj]=0 // clear
}
}
// swtchk(sp,"WT0","NC0") compare weights to sp weights
func swtchk () { local ii,jj,nc0,wt0,n
nc0=$o1.fi($s3) wt0=$o1.fi($s2) n=0
for ii=0,$o1.v.size-1 {
if ($o1.v[nc0].x[ii]==-1) continue
tobj=ncl.object($o1.v[nc0].x[ii])
if ($o1.v[wt0].x[ii]==tobj.weight) n+=1 else {
printf("Mismatch %d: %g %g\n",ii,$o1.v[wt0].x[ii],tobj.weight) }
}
tobj=nil
return n/ii
}
// synchk() look for internal consistency
proc synchk () {
for ltr(XO,cvode.netconlist("","","")) if (isassigned(XO.postcell) && XO.weight<0) {
printf("Error for %s with wt %g\n",XO.syn,XO.weight)
}
}
//** getwt() useful in eg sp.spr("<NC0>.c.apply('getwt')")
func getwt () { return NetCon[$1].weight }
spnormflag = 0 // set this flag to normalize weights by number of projections
//** actumb(PRID,POID,WIDTH) -- clears umbrella and then set sp.ind to chosen umbrella
proc actumb () { local width,flag,divisor
width=$3
if (width==-1) flag=1 else flag=0
sp.select(-1,"CODE",EQU1,$1,"CODE",EQU2,$2)
if (! flag) { // width=-1 is flag for full connection
if (sp.fi("WT1")!=-1) sp.fillin("WT0",0,"WT1",0) else sp.fillin("WT0",0)
sp.select(-1,"CODE",EQU1,$1,"CODE",EQU2,$2,"DIST","()",-width,width)
}
if (! spnormflag) { // just set the values
if (sp.fi("WT1")!=-1 && numarg()==5) sp.fillin("WT0",$4,"WT1",$5) else sp.fillin("WT0",$4)
} else { // need to calculate convergence for individual cells here
}
}
//** inline(PRID,POID,WT) sets the in-column weights
proc inline () { local a
sp.select(-1,"CODE",EQU1,$1,"CODE",EQU2,$2,"PR",EQV,"PO")
if (numarg()==4) sp.fillin("WT0",$3,"WT1",$4) else sp.fillin("WT0",$3)
}
// stwtnorm(PREID,POSTID,WT0[,WT1,CONVVEC])
func stwtnorm () { local cv,a,b,ret
a=b=allocvecs(2) b+=1
if (sp.select("CODE",EQU1,$1,"CODE",EQU2,$2)==0) {
printf("WARNING NO CONNECTS FROM %d TO %d\n",$1,$2) return 0 }
sp.uniq("PO") // only retains unique values of PO => cv>0
mso[a].copy(sp.out.v[sp.fi("PO")])
for vtr(&x,mso[a]) {
cv=sp.select(-1,"CODE",EQU1,$1,"CODE",EQU2,$2,"PO",x) // do select without copy to out
mso[b].append(cv)
if (cv>0) {
if (numarg()==4) sp.fillin("WT0",$3/cv,"WT1",$4/cv) else sp.fillin("WT0",$3/cv)
}
}
ret=mso[b].mean // mean convergence
if (numarg()==4) if (argtype(4)==1) $o4.copy(mso[b])
if (numarg()==5) if (argtype(5)==1) $o5.copy(mso[b])
dealloc(a)
return ret
}
// wtnorm(PREID,POSTID) -- normalize the values according to convergence
func wtnorm () { local cv,a,b,ret,wt0,wt1
wt0=sp.fi("WT0") wt1=sp.fi("WT1")
if (sp.select(-1,"CODE",EQU1,$1,"CODE",EQU2,$2)==0) {
printf("WARNING NO CONNECTS FROM %d TO %d\n",$1,$2) return }
a=b=allocvecs(2) b+=1
sp.uniq("PO") // only retains unique values of PO => cv>0
mso[a].copy(sp.out.v[sp.fi("PO")])
for vtr(&x,mso[a]) {
cv=sp.select("CODE",EQU1,$1,"CODE",EQU2,$2,"PO",x)
mso[b].append(cv)
if (cv>0) {
sp.out.v[wt0].div(cv)
if (wt1>-1) sp.out.v[wt1].div(cv)
sp.delect()
}
}
ret=mso[b].mean // mean convergence
dealloc(a)
return ret
}
proc setdist () { sp.spr("DIST","<PR>.c.sub(<PO>).apply('abs')") }
proc stwtvar() { local a,idr
if (numarg()==5) idr=1 else idr=0
a=allocvecs(1)
mso[a].resize(sp.ind.size)
rdm.uniform($3*(1-$4),$3*(1+$4))
mso[a].setrand(rdm)
if (spnormflag) mso[a].div(sp.ind.size)
sp.wt[idr].indset(sp.ind,mso[a])
dealloc(a)
}
//** snc() -- set the actual netcons to the params in sp
DEL=DELD=1
proc snc () { local ii
for ii=0,sp.size-1 {
nc[sp.nc.x[ii]].threshold=0
nc[sp.nc.x[ii]].weight=sp.wt.x[ii]
nc[sp.nc.x[ii]].delay=DEL+DELD*sp.dist.x[ii]
if (sp.nc[1].x[ii]>-1) {
nc[sp.nc[1].x[ii]].weight=sp.wt[1].x[ii]
nc[sp.nc[1].x[ii]].delay=DEL+DELD*sp.dist.x[ii]
}
}
}
//** snci() -- take a vec of indices (eg sp.ind) as arg
proc snci () { local ii,jj
for jj=0,$o1.size-1 {
ii=$o1.x[jj]
nc[sp.nc.x[ii]].weight=sp.wt.x[ii]
nc[sp.nc.x[ii]].delay=DEL+DELD*sp.dist.x[ii]
if (sp.nc[1].x[ii]>-1) {
nc[sp.nc[1].x[ii]].weight=sp.wt[1].x[ii]
nc[sp.nc[1].x[ii]].delay=DEL+DELD*sp.dist.x[ii]
}
}
}
//* informational procs
//** proc print_pp_location(PP), from doc/html/refman/nocmodl.html
proc print_pp_location() { local x //arg1 must be a point process
x = $o1.get_loc()
sectionname(section)
printf("%s located at %s(%g)\n", $o1, section, x)
pop_section()
}
//** pp_loc(PP,LOC,SCRATCH) returns true if point process PP is located in LOC (regexp match)
func pp_loc () { local x //arg1 must be a point process
x = 0
$o1.get_loc()
if (numarg()==3) { sectionname($s3) }
ifsec $s2 { x = 1 }
pop_section()
return x
}
//* ndivo, ncono, sdivo, scono: objects; ndivs, ncons, sdivs, scons: strings
//** for use with INTF
iterator divr () { local ii
for ii=0,ncl.count-1 {
XO=ncl.object(ii)
if (object_id(sfunc.obj(XO.pre.p))==object_id(cells[$1].object($2))) {
iterator_statement
}
}
}
iterator conr () { local ii
for ii=0,ncl.count-1 {
XO=ncl.object(ii)
if (object_id(sfunc.obj(XO.syn.p))==object_id(cells[$1].object($2))) {
iterator_statement
}
}
}
//** iterators
// eg for syt("ns[0]","ns[1]") print XO,YO,nco
iterator syt () { local num,err
err=0
canobj($o1,"XO") canobj($o2,"YO") // canobj -- canonical object
if ((num=cvode.netconlist(XO,"",YO).count)!=1) {
printf("syt() ERROR num==%d (%s,%s)\n",num,XO,YO) err=1 }
if (!err) {
nco=cvode.netconlist(XO,"",YO).object(0)
iterator_statement
}
XO=nil YO=nil nco=nil
}
// nca makes list backwards -- syn, then postcell, then precell
iterator nca () { local ii
tmplist.remove_all
if (numarg()==0) { cvode.netconlist("", "", "",tmplist)}
if (numarg()==1) { cvode.netconlist("", "", $s1,tmplist)}
if (numarg()==2) { cvode.netconlist("", $s2, $s1,tmplist)}
if (numarg()==3) { cvode.netconlist($s3, $s2, $s1,tmplist)}
for ii=0,tmplist.count-1 {
XO=tmplist.object(ii)
iterator_statement
}
}
func wtvec () {
revec(vec)
for nca($s1) vec.append(XO.weight)
vlk(vec)
return vec.size
}
func dlyvec () {
revec(vec)
for nca($s1) vec.append(XO.delay)
vlk(vec)
return vec.size
}
iterator prtr () { local ii
tmplist.remove_all
for ii=0,cvode.netconlist("", $s1, "").count-1 {
nco=cvode.netconlist("", $s1, "").object(ii)
iterator_statement
}
}