forked from emer/leabra
-
Notifications
You must be signed in to change notification settings - Fork 1
/
neuron.go
84 lines (68 loc) · 2.41 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
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
// 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 pcore
import (
"fmt"
"unsafe"
"github.com/ccnlab/leabrax/leabra"
)
var (
// NeuronVars are extra neuron variables for pcore
NeuronVars = []string{"DA", "DALrn", "ACh", "Ca", "KCa"}
// NeuronVarsAll is the pcore collection of all neuron-level vars
NeuronVarsAll []string
// SynVarsAll is the pcore collection of all synapse-level vars (includes TraceSynVars)
SynVarsAll []string
)
func init() {
ln := len(leabra.NeuronVars)
NeuronVarsAll = make([]string, len(NeuronVars)+ln)
copy(NeuronVarsAll, leabra.NeuronVars)
copy(NeuronVarsAll[ln:], NeuronVars)
ln = len(leabra.SynapseVars)
SynVarsAll = make([]string, len(TraceSynVars)+ln)
copy(SynVarsAll, leabra.SynapseVars)
copy(SynVarsAll[ln:], TraceSynVars)
}
//////////////////////////////////////////////////////////////////////
// STN neurons
// STNNeuron holds the extra neuron (unit) level variables for STN computation.
type STNNeuron struct {
Ca float32 `desc:"intracellular Calcium concentration -- increased by bursting and elevated levels of activation, drives KCa currents that result in hyperpolarization / inhibition."`
KCa float32 `desc:"Calcium-gated potassium channel conductance level, computed using function from gillies & Willshaw 2006 as function of Ca."`
}
var (
STNNeuronVars = []string{"Ca", "KCa"}
STNNeuronVarsMap map[string]int
)
func init() {
STNNeuronVarsMap = make(map[string]int, len(STNNeuronVars))
for i, v := range STNNeuronVars {
STNNeuronVarsMap[v] = i
}
}
func (nrn *STNNeuron) VarNames() []string {
return STNNeuronVars
}
// STNNeuronVarIdxByName returns the index of the variable in the STNNeuron, or error
func STNNeuronVarIdxByName(varNm string) (int, error) {
i, ok := STNNeuronVarsMap[varNm]
if !ok {
return 0, fmt.Errorf("STNNeuron VarByName: variable name: %v not valid", varNm)
}
return i, nil
}
// VarByIndex returns variable using index (0 = first variable in STNNeuronVars list)
func (nrn *STNNeuron) VarByIndex(idx int) float32 {
fv := (*float32)(unsafe.Pointer(uintptr(unsafe.Pointer(nrn)) + uintptr(4*idx)))
return *fv
}
// VarByName returns variable by name, or error
func (nrn *STNNeuron) VarByName(varNm string) (float32, error) {
i, err := STNNeuronVarIdxByName(varNm)
if err != nil {
return 0, err
}
return nrn.VarByIndex(i), nil
}