-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcore_layers.go
451 lines (390 loc) · 14.7 KB
/
pcore_layers.go
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
// Copyright (c) 2022, The Emergent Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package axon
import (
"log"
"strings"
"cogentcore.org/core/base/num"
"cogentcore.org/core/vgpu/gosl/slbool"
)
//gosl:start pcore_layers
// MatrixParams has parameters for BG Striatum Matrix MSN layers
// These are the main Go / NoGo gating units in BG.
// DA, ACh learning rate modulation is pre-computed on the recv neuron
// RLRate variable via NeuroMod. Also uses Pool.Gated for InvertNoGate,
// updated in PlusPhase prior to DWt call.
// Must set Learn.NeuroMod.DAMod = D1Mod or D2Mod via SetBuildConfig("DAMod").
type MatrixParams struct {
// threshold on layer Avg SpkMax for Matrix Go and VThal layers to count as having gated
GateThr float32 `default:"0.05"`
// is this a ventral striatum (VS) matrix layer? if true, the gating status of this layer is recorded in the Global state, and used for updating effort and other factors.
IsVS slbool.Bool
// index of other matrix (Go if we are NoGo and vice-versa). Set during Build from BuildConfig OtherMatrixName
OtherMatrixIndex int32 `edit:"-"`
// index of thalamus layer that we gate. needed to get gating information. Set during Build from BuildConfig ThalLay1Name if present -- -1 if not used
ThalLay1Index int32 `edit:"-"`
// index of thalamus layer that we gate. needed to get gating information. Set during Build from BuildConfig ThalLay2Name if present -- -1 if not used
ThalLay2Index int32 `edit:"-"`
// index of thalamus layer that we gate. needed to get gating information. Set during Build from BuildConfig ThalLay3Name if present -- -1 if not used
ThalLay3Index int32 `edit:"-"`
// index of thalamus layer that we gate. needed to get gating information. Set during Build from BuildConfig ThalLay4Name if present -- -1 if not used
ThalLay4Index int32 `edit:"-"`
// index of thalamus layer that we gate. needed to get gating information. Set during Build from BuildConfig ThalLay5Name if present -- -1 if not used
ThalLay5Index int32 `edit:"-"`
// index of thalamus layer that we gate. needed to get gating information. Set during Build from BuildConfig ThalLay6Name if present -- -1 if not used
ThalLay6Index int32 `edit:"-"`
pad, pad1, pad2 int32
}
func (mp *MatrixParams) Defaults() {
mp.GateThr = 0.05
}
func (mp *MatrixParams) Update() {
}
// GPLayerTypes is a GPLayer axon-specific layer type enum.
type GPLayerTypes int32 //enums:enum
// The GPLayer types
const (
// GPePr is the set of prototypical GPe neurons, mediating classical NoGo
GPePr GPLayerTypes = iota
// GPeAk is arkypallidal layer of GPe neurons, receiving inhibition from GPePr
// and projecting inhibition to Mtx
GPeAk
// GPi is the inner globus pallidus, functionally equivalent to SNr,
// receiving from MtxGo and GPePr, and sending inhibition to VThal
GPi
)
// GPLayer represents a globus pallidus layer, including:
// GPePr, GPeAk (arkypallidal), and GPi (see GPType for type).
// Typically just a single unit per Pool representing a given stripe.
type GPParams struct {
// type of GP Layer -- must set during config using SetBuildConfig of GPType.
GPType GPLayerTypes
pad, pad1, pad2 uint32
}
func (gp *GPParams) Defaults() {
}
func (gp *GPParams) Update() {
}
//gosl:end pcore_layers
// MatrixGated is called after std PlusPhase, on CPU, has Pool info
// downloaded from GPU, to set Gated flag based on SpkMax activity
func (ly *Layer) MatrixGated(ctx *Context) {
if ly.Params.Learn.NeuroMod.DAMod != D1Mod {
oly := ly.Network.Layers[int(ly.Params.Matrix.OtherMatrixIndex)]
// note: NoGo layers don't track gating at the sub-pool level!
for di := uint32(0); di < ctx.NetIndexes.NData; di++ {
ly.Pool(0, di).Gated = oly.Pool(0, di).Gated
}
return
}
// todo: Context requires data parallel state!
for di := uint32(0); di < ctx.NetIndexes.NData; di++ {
mtxGated, poolIndex := ly.GatedFromSpkMax(di, ly.Params.Matrix.GateThr)
thalGated := false
if ly.Params.Matrix.ThalLay1Index >= 0 {
tly := ly.Network.Layers[int(ly.Params.Matrix.ThalLay1Index)]
gt, _ := tly.GatedFromSpkMax(di, ly.Params.Matrix.GateThr)
thalGated = thalGated || gt
}
if ly.Params.Matrix.ThalLay2Index >= 0 {
tly := ly.Network.Layers[int(ly.Params.Matrix.ThalLay2Index)]
gt, _ := tly.GatedFromSpkMax(di, ly.Params.Matrix.GateThr)
thalGated = thalGated || gt
}
if ly.Params.Matrix.ThalLay3Index >= 0 {
tly := ly.Network.Layers[int(ly.Params.Matrix.ThalLay3Index)]
gt, _ := tly.GatedFromSpkMax(di, ly.Params.Matrix.GateThr)
thalGated = thalGated || gt
}
if ly.Params.Matrix.ThalLay4Index >= 0 {
tly := ly.Network.Layers[int(ly.Params.Matrix.ThalLay4Index)]
gt, _ := tly.GatedFromSpkMax(di, ly.Params.Matrix.GateThr)
thalGated = thalGated || gt
}
if ly.Params.Matrix.ThalLay5Index >= 0 {
tly := ly.Network.Layers[int(ly.Params.Matrix.ThalLay5Index)]
gt, _ := tly.GatedFromSpkMax(di, ly.Params.Matrix.GateThr)
thalGated = thalGated || gt
}
if ly.Params.Matrix.ThalLay6Index >= 0 {
tly := ly.Network.Layers[int(ly.Params.Matrix.ThalLay6Index)]
gt, _ := tly.GatedFromSpkMax(di, ly.Params.Matrix.GateThr)
thalGated = thalGated || gt
}
mtxGated = mtxGated && thalGated
// note: in principle with multi-pool GP, could try to establish
// a correspondence between thal and matrix pools, such that
// a failure to gate at the thal level for a given pool would veto
// just the one corresponding pool. However, we're not really sure
// that this will make sense and not doing yet..
if !mtxGated { // nobody did if thal didn't
for pi := uint32(0); pi < ly.NPools; pi++ {
pl := ly.Pool(uint32(pi), di)
pl.Gated.SetBool(false)
}
}
if ctx.PlusPhase.IsTrue() && ly.Params.Matrix.IsVS.IsTrue() {
SetGlbV(ctx, di, GvVSMatrixJustGated, num.FromBool[float32](mtxGated))
if mtxGated {
SetGlbUSposV(ctx, di, GvVSMatrixPoolGated, uint32(poolIndex), 1)
}
}
}
}
// GatedFromSpkMax updates the Gated state in Pools of given layer,
// based on Avg SpkMax being above given threshold.
// returns true if any gated, and the pool index if 4D layer (0 = first).
func (ly *Layer) GatedFromSpkMax(di uint32, thr float32) (bool, int) {
anyGated := false
poolIndex := -1
if ly.Is4D() {
for pi := uint32(1); pi < ly.NPools; pi++ {
pl := ly.Pool(pi, di)
spkavg := pl.AvgMax.SpkMax.Cycle.Avg
gthr := spkavg > thr
if gthr {
anyGated = true
if poolIndex < 0 {
poolIndex = int(pi) - 1
}
}
pl.Gated.SetBool(gthr)
}
} else {
spkavg := ly.Pool(0, di).AvgMax.SpkMax.Cycle.Avg
if spkavg > thr {
anyGated = true
}
}
ly.Pool(0, di).Gated.SetBool(anyGated)
return anyGated, poolIndex
}
// AnyGated returns true if the layer-level pool Gated flag is true,
// which indicates if any of the layers gated.
func (ly *Layer) AnyGated(di uint32) bool {
return ly.Pool(0, di).Gated.IsTrue()
}
func (ly *Layer) MatrixDefaults() {
ly.Params.Acts.Decay.Act = 1
ly.Params.Acts.Decay.Glong = 1 // prevent carryover of NMDA
ly.Params.Acts.Kir.Gbar = 10
ly.Params.Acts.GabaB.Gbar = 0 // Kir replaces GabaB
// ly.Params.Acts.NMDA.Gbar = 0 // Matrix needs nmda, default is fine
ly.Params.Inhib.Layer.FB = 0 // pure FF
ly.Params.Inhib.Layer.Gi = 0.5
ly.Params.Inhib.Pool.On.SetBool(true) // needs both pool and layer if has pools
ly.Params.Inhib.Pool.FB = 0 // pure FF
ly.Params.Inhib.Pool.Gi = 0.5
ly.Params.Inhib.ActAvg.Nominal = 0.25 // pooled should be lower
ly.Params.Learn.RLRate.On.SetBool(true) // key: sig deriv used outside of rew trials
ly.Params.Learn.RLRate.Diff.SetBool(false)
ly.Params.Learn.TrgAvgAct.RescaleOn.SetBool(false) // major effect
// ly.Params.Learn.NeuroMod.DAMod needs to be set via BuildConfig
ly.Params.Learn.NeuroMod.DALRateSign.SetBool(true) // critical
ly.Params.Learn.NeuroMod.DALRateMod = 1
ly.Params.Learn.NeuroMod.AChLRateMod = 0
ly.Params.Learn.NeuroMod.DAModGain = 0
ly.Params.Learn.NeuroMod.BurstGain = 0.1
ly.Params.Learn.RLRate.SigmoidMin = 0.001
if ly.Cls == "VSMatrixLayer" {
ly.Params.Inhib.Layer.On.SetBool(true)
ly.Params.Matrix.IsVS.SetBool(true)
ly.Params.Acts.Dend.ModBase = 0
ly.Params.Acts.Dend.ModGain = 2 // for VS case -- otherwise irrelevant
ly.Params.Learn.NeuroMod.AChDisInhib = 5
ly.Params.Learn.NeuroMod.BurstGain = 1
} else {
ly.Params.Inhib.Layer.On.SetBool(false)
ly.Params.Matrix.IsVS.SetBool(false)
ly.Params.Acts.Dend.ModBase = 1
ly.Params.Acts.Dend.ModGain = 0
ly.Params.Learn.NeuroMod.AChDisInhib = 0
}
// important: user needs to adjust wt scale of some PFC inputs vs others:
// drivers vs. modulators
for _, pj := range ly.RcvPaths {
pj.Params.SWts.Init.SPct = 0
if pj.Send.LayerType() == GPLayer { // GPeAkToMtx
pj.Params.SetFixedWts()
pj.Params.PathScale.Abs = 3
pj.Params.SWts.Init.Mean = 0.75
pj.Params.SWts.Init.Var = 0.0
if ly.Cls == "DSMatrixLayer" {
if strings.Contains(ly.Nm, "No") {
pj.Params.PathScale.Abs = 6
}
}
}
}
}
func (ly *Layer) MatrixPostBuild() {
ly.Params.Matrix.ThalLay1Index = ly.BuildConfigFindLayer("ThalLay1Name", false) // optional
ly.Params.Matrix.ThalLay2Index = ly.BuildConfigFindLayer("ThalLay2Name", false) // optional
ly.Params.Matrix.ThalLay3Index = ly.BuildConfigFindLayer("ThalLay3Name", false) // optional
ly.Params.Matrix.ThalLay4Index = ly.BuildConfigFindLayer("ThalLay4Name", false) // optional
ly.Params.Matrix.ThalLay5Index = ly.BuildConfigFindLayer("ThalLay5Name", false) // optional
ly.Params.Matrix.ThalLay6Index = ly.BuildConfigFindLayer("ThalLay6Name", false) // optional
ly.Params.Matrix.OtherMatrixIndex = ly.BuildConfigFindLayer("OtherMatrixName", true)
dm, err := ly.BuildConfigByName("DAMod")
if err == nil {
err = ly.Params.Learn.NeuroMod.DAMod.SetString(dm)
if err != nil {
log.Println(err)
}
}
}
////////////////////////////////////////////////////////////////////
// GP
func (ly *Layer) GPDefaults() {
// GP is tonically self-active and has no FFFB inhibition
// Defaults are for GPePr, Ak has special values below
ly.Params.Acts.Init.GeBase = 0.4
ly.Params.Acts.Init.GeVar = 0.2
ly.Params.Acts.Init.GiVar = 0.1
ly.Params.Acts.Decay.Act = 0
ly.Params.Acts.Decay.Glong = 1
ly.Params.Acts.NMDA.Gbar = 0 // carryover of NMDA was causing issues!
ly.Params.Acts.GabaB.Gbar = 0
ly.Params.Inhib.ActAvg.Nominal = 1 // very active!
ly.Params.Inhib.Layer.On.SetBool(false)
ly.Params.Inhib.Pool.On.SetBool(false)
if ly.Params.GP.GPType == GPeAk {
ly.Params.Acts.Init.GeBase = 0.2 // definitely lower in bio data, necessary
ly.Params.Acts.Init.GeVar = 0.1
}
for _, pj := range ly.RcvPaths {
pj.Params.SetFixedWts()
pj.Params.SWts.Init.Mean = 0.75 // 0.75 -- very similar -- maybe a bit more reliable with 0.8 / 0
pj.Params.SWts.Init.Var = 0.25 // 0.25
switch ly.Params.GP.GPType {
case GPePr:
switch pj.Send.LayerType() {
case MatrixLayer:
pj.Params.PathScale.Abs = 1 // MtxNoToGPePr -- primary NoGo pathway
case GPLayer:
pj.Params.PathScale.Abs = 4 // 4 best for DS; GPePrToGPePr -- must be very strong
case STNLayer:
pj.Params.PathScale.Abs = 0.5 // STNToGPePr
}
case GPeAk:
switch pj.Send.LayerType() {
case MatrixLayer:
pj.Params.PathScale.Abs = 0.5 // MtxGoToGPeAk
case GPLayer:
pj.Params.PathScale.Abs = 1 // GPePrToGPeAk
case STNLayer:
pj.Params.PathScale.Abs = 0.1 // STNToGPAk
}
}
}
if ly.Params.GP.GPType == GPi {
ly.GPiDefaults()
}
}
func (ly *Layer) GPiDefaults() {
ly.Params.Acts.Init.GeBase = 0.3
ly.Params.Acts.Init.GeVar = 0.1
ly.Params.Acts.Init.GiVar = 0.1
// note: GPLayer took care of STN input paths
for _, pj := range ly.RcvPaths {
pj.Params.SetFixedWts()
pj.Params.SWts.Init.Mean = 0.75 // 0.75 see above
pj.Params.SWts.Init.Var = 0.25 // 0.25
if pj.Send.LayerType() == MatrixLayer { // MtxGoToGPi
if pj.Send.Cls == "VSMatrixLayer" {
pj.Params.PathScale.Abs = 0.2
} else {
pj.Params.PathScale.Abs = 1
}
} else if pj.Send.LayerType() == GPLayer { // GPePrToGPi
pj.Params.PathScale.Abs = 1
} else if pj.Send.LayerType() == STNLayer { // STNToGPi
pj.Params.PathScale.Abs = 0.2
}
}
}
func (ly *Layer) GPPostBuild() {
gpnm, err := ly.BuildConfigByName("GPType")
if err == nil {
err = ly.Params.GP.GPType.SetString(gpnm)
if err != nil {
log.Println(err)
}
}
}
////////////////////////////////////////////////////////////////////
// STN
func (ly *Layer) STNDefaults() {
// STN is tonically self-active and has no FFFB inhibition
ly.Params.Acts.Init.GeBase = 0.1 // was 0.3
ly.Params.Acts.Init.GeVar = 0.1
ly.Params.Acts.Init.GiVar = 0.1
ly.Params.Acts.SKCa.Gbar = 2
ly.Params.Acts.SKCa.CaRDecayTau = 80 // 80 > 150 for longer theta windows
ly.Params.Acts.Kir.Gbar = 10 // 10 > 5 -- key for pause
ly.Params.Acts.Decay.Act = 0
ly.Params.Acts.Decay.Glong = 0
ly.Params.Acts.Decay.LearnCa = 1 // key for non-spaced trials, to refresh immediately
ly.Params.Acts.Dend.SSGi = 0
ly.Params.Acts.NMDA.Gbar = 0 // fine with 0
ly.Params.Acts.GabaB.Gbar = 0
ly.Params.Inhib.Layer.On.SetBool(true)
ly.Params.Inhib.Layer.Gi = 0.5
ly.Params.Inhib.Layer.FB = 0
ly.Params.Inhib.Pool.On.SetBool(false)
ly.Params.Inhib.Pool.Gi = 0.5
ly.Params.Inhib.Pool.FB = 0
ly.Params.Inhib.ActAvg.Nominal = 0.15
ly.Params.Learn.NeuroMod.AChDisInhib = 0 // was 2,
// if ly.Cls == "VSTNLayer" {
// ly.Params.Inhib.Layer.On.SetBool(false)
// } else {
// ly.Params.Inhib.Layer.On.SetBool(true)
// }
for _, pj := range ly.RcvPaths {
pj.Params.SetFixedWts()
pj.Params.SWts.Init.Mean = 0.75
pj.Params.SWts.Init.Var = 0.25
if pj.Send.LayerType() == GPLayer { // GPePrToSTN
pj.Params.PathScale.Abs = 0.5
} else {
pj.Params.PathScale.Abs = 2.0 // pfc inputs
}
}
}
////////////////////////////////////////////////////////////////////
// BGThal
func (ly *Layer) BGThalDefaults() {
// note: not tonically active
// ly.Params.Acts.NMDA.Gbar = 0 // needs NMDA
ly.Params.Acts.Decay.Act = 1
ly.Params.Acts.Decay.Glong = 0.6
ly.Params.Acts.Dend.SSGi = 0
ly.Params.Inhib.ActAvg.Nominal = 0.1
ly.Params.Inhib.Layer.On.SetBool(true)
ly.Params.Inhib.Layer.Gi = 0.6
ly.Params.Inhib.Pool.On.SetBool(false)
ly.Params.Inhib.Pool.Gi = 0.6
ly.Params.Learn.NeuroMod.AChDisInhib = 1
for _, pj := range ly.RcvPaths {
pj.Params.SetFixedWts()
pj.Params.SWts.Init.Mean = 0.75
pj.Params.SWts.Init.Var = 0.0
if strings.HasSuffix(pj.Send.Name(), "GPi") { // GPiToBGThal
pj.Params.PathScale.Abs = 5 // can now be much stronger with PTMaint mod and maint dynamics
pj.AddClass("GPiToBGThal")
}
}
}
////////////////////////////////////////////////////////////////////
// VSGated
func (ly *LayerParams) VSGatedDefaults() {
ly.Inhib.ActAvg.Nominal = 0.5
ly.Inhib.Layer.On.SetBool(true)
ly.Inhib.Layer.Gi = 1
ly.Inhib.Pool.On.SetBool(false)
ly.Inhib.Pool.Gi = 1
ly.Acts.Decay.Act = 1
ly.Acts.Decay.Glong = 1
}