-
Notifications
You must be signed in to change notification settings - Fork 0
/
ach.go
98 lines (80 loc) · 2.85 KB
/
ach.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
// Copyright (c) 2020, 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 rl
import (
"github.com/PrincetonCompMemLab/neurodiff_emergent/emer"
"github.com/PrincetonCompMemLab/neurodiff_leabra/leabra"
"github.com/goki/ki/kit"
)
// AChLayer is an interface for a layer with acetylcholine neuromodulator on it
type AChLayer interface {
// GetACh returns the acetylcholine level for layer
GetACh() float32
// SetACh sets the acetylcholine level for layer
SetACh(ach float32)
}
// SendACh is a list of layers to send acetylcholine to
type SendACh emer.LayNames
// SendACh sends acetylcholine to list of layers
func (sd *SendACh) SendACh(net emer.Network, ach float32) {
for _, lnm := range *sd {
ml, ok := net.LayerByName(lnm).(AChLayer)
if ok {
ml.SetACh(ach)
}
}
}
// Validate ensures that LayNames layers are valid.
// ctxt is string for error message to provide context.
func (sd *SendACh) Validate(net emer.Network, ctxt string) error {
ln := (*emer.LayNames)(sd)
return ln.Validate(net, ctxt)
}
// Add adds given layer name(s) to list
func (sd *SendACh) Add(laynm ...string) {
*sd = append(*sd, laynm...)
}
// AddAllBut adds all layers in network except those in exlude list
func (sd *SendACh) AddAllBut(net emer.Network, excl []string) {
ln := (*emer.LayNames)(sd)
ln.AddAllBut(net, excl)
}
// Layers that use SendACh should include a Validate check in Build as follows:
// Build constructs the layer state, including calling Build on the projections.
// func (ly *AChSrcLayer) Build() error {
// err := ly.Layer.Build()
// if err != nil {
// return err
// }
// err = ly.SendACh.Validate(ly.Network, ly.Name()+" SendTo list")
// return err
// }
//////////////////////////////////////////////////////////////////////////////////////
// ClampAChLayer
// ClampAChLayer is an Input layer that just sends its activity as the acetylcholine signal
type ClampAChLayer struct {
leabra.Layer
SendACh SendACh `desc:"list of layers to send acetylcholine to"`
ACh float32 `desc:"acetylcholine value for this layer"`
}
var KiT_ClampAChLayer = kit.Types.AddType(&ClampAChLayer{}, leabra.LayerProps)
// AChLayer interface:
func (ly *ClampAChLayer) GetACh() float32 { return ly.ACh }
func (ly *ClampAChLayer) SetACh(ach float32) { ly.ACh = ach }
// Build constructs the layer state, including calling Build on the projections.
func (ly *ClampAChLayer) Build() error {
err := ly.Layer.Build()
if err != nil {
return err
}
err = ly.SendACh.Validate(ly.Network, ly.Name()+" SendTo list")
return err
}
// CyclePost is called at end of Cycle
// We use it to send ACh, which will then be active for the next cycle of processing.
func (ly *ClampAChLayer) CyclePost(ltime *leabra.Time) {
act := ly.Neurons[0].Act
ly.ACh = act
ly.SendACh.SendACh(ly.Network, act)
}