forked from emer/leabra
-
Notifications
You must be signed in to change notification settings - Fork 1
/
neuron.go
57 lines (46 loc) · 1.68 KB
/
neuron.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
// Copyright (c) 2019, 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 deep
import (
"fmt"
"unsafe"
"github.com/ccnlab/leabrax/leabra"
)
var (
// NeuronVars are for full list across all deep Layer types
NeuronVars = []string{"Burst", "BurstPrv", "Attn", "CtxtGe"}
// SuperNeuronVars are for SuperLayer directly
SuperNeuronVars = []string{"Burst", "BurstPrv", "Attn"}
SuperNeuronVarsMap map[string]int
// NeuronVarsAll is full integrated list across inherited layers and NeuronVars
NeuronVarsAll []string
)
func init() {
SuperNeuronVarsMap = make(map[string]int, len(SuperNeuronVars))
for i, v := range SuperNeuronVars {
SuperNeuronVarsMap[v] = i
}
ln := len(leabra.NeuronVars)
NeuronVarsAll = make([]string, len(NeuronVars)+ln)
copy(NeuronVarsAll, leabra.NeuronVars)
copy(NeuronVarsAll[ln:], NeuronVars)
}
// SuperNeuron has the neuron values for SuperLayer
type SuperNeuron struct {
Burst float32 `desc:"5IB bursting activation value, computed by thresholding regular activation"`
BurstPrv float32 `desc:"previous bursting activation -- used for context-based learning"`
Attn float32 `desc:"attentional signal from TRC layer"`
}
// SuperNeuronVarIdxByName returns the index of the variable in the SuperNeuron, or error
func SuperNeuronVarIdxByName(varNm string) (int, error) {
i, ok := SuperNeuronVarsMap[varNm]
if !ok {
return 0, fmt.Errorf("SuperNeuron VarIdxByName: variable name: %v not valid", varNm)
}
return i, nil
}
func (sn *SuperNeuron) VarByIdx(idx int) float32 {
fv := (*float32)(unsafe.Pointer(uintptr(unsafe.Pointer(sn)) + uintptr(4*idx)))
return *fv
}