Skip to content

Commit

Permalink
add LayerRT threshold and GatedRT stat, track in bg-dorsal
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Dec 26, 2024
1 parent 8e43d8e commit 459b9cd
Show file tree
Hide file tree
Showing 42 changed files with 310 additions and 178 deletions.
8 changes: 6 additions & 2 deletions axon/act-layer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions axon/act-layer.goal
Original file line number Diff line number Diff line change
Expand Up @@ -747,10 +747,13 @@ func (ly *LayerParams) CyclePost(ctx *Context, di uint32) {
// CyclePostLayer is called for all layer types
func (ly *LayerParams) CyclePostLayer(ctx *Context, lpi, di uint32) {
casp := PoolAvgMax(AMCaP, AMCycle, Max, lpi, di)
if ctx.Cycle >= ly.Acts.Dt.MaxCycStart && casp > 0.5 { // todo: param
if LayerStates[ly.Index, di, LayerRT] <= 0 {
if ctx.Cycle >= ly.Acts.Dt.MaxCycStart {
if casp > ly.Inhib.ActAvg.RTThr && LayerStates[ly.Index, di, LayerRT] <= 0 {
LayerStates[ly.Index, di, LayerRT] = float32(ctx.Cycle)
}
if PoolsInt[lpi, di, PoolGated] > 0 && LayerStates[ly.Index, di, GatedRT] <= 0 {
LayerStates[ly.Index, di, GatedRT] = float32(ctx.Cycle)
}
}
}

Expand Down Expand Up @@ -884,6 +887,7 @@ func (ly *LayerParams) NewStateLayer(ctx *Context) {
ly.Acts.Clamp.IsInput.SetBool(ly.IsInput())
ly.Acts.Clamp.IsTarget.SetBool(ly.IsTarget())
LayerStates[ly.Index, di, LayerRT] = -1.0
LayerStates[ly.Index, di, GatedRT] = -1.0

for spi := uint32(0); spi < np; spi++ {
pi := ly.PoolIndex(spi)
Expand Down
10 changes: 5 additions & 5 deletions axon/enumgen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 44 additions & 7 deletions axon/inhib.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 39 additions & 7 deletions axon/inhib.goal
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,64 @@ import (
// average activity within a target range.
type ActAvgParams struct {

// nominal estimated average activity level in the layer, which is used in computing the scaling factor on sending pathways from this layer. In general it should roughly match the layer ActAvg.ActMAvg value, which can be logged using the axon.LogAddDiagnosticItems function. If layers receiving from this layer are not getting enough Ge excitation, then this Nominal level can be lowered to increase pathway strength (fewer active neurons means each one contributes more, so scaling factor goes as the inverse of activity level), or vice-versa if Ge is too high. It is also the basis for the target activity level used for the AdaptGi option -- see the Offset which is added to this value.
// Nominal is the estimated average activity level in the layer, which is
// used in computing the scaling factor on sending pathways from this layer.
// In general it should roughly match the layer ActAvg.ActMAvg value, which
// can be logged using the axon.LogAddDiagnosticItems function.
// If layers receiving from this layer are not getting enough Ge excitation,
// then this Nominal level can be lowered to increase pathway strength
// (fewer active neurons means each one contributes more, so scaling factor
// goes as the inverse of activity level), or vice-versa if Ge is too high.
// It is also the basis for the target activity level used for the AdaptGi
// option: see the Offset which is added to this value.
Nominal float32 `min:"0" step:"0.01"`

// enable adapting of layer inhibition Gi multiplier factor (stored in layer GiMult value) to maintain a target layer level of ActAvg.Nominal. This generally works well and improves the long-term stability of the models. It is not enabled by default because it depends on having established a reasonable Nominal + Offset target activity level.
// RTThr is the reaction time (RT) threshold activity level in the layer,
// in terms of the maximum CaP level of any neuron in the layer. The
// LayerStates LayerRT value is recorded for the cycle at which this
// level is exceeded within a theta cycle, after Acts.Dt.MaxCycStart cycles.
RTThr float32 `default:"0.5"`

// AdaptGi enables adapting of layer inhibition Gi multiplier factor
// (stored in layer GiMult value) to maintain a target layer level of
// ActAvg.Nominal. This generally works well and improves the long-term
// stability of the models. It is not enabled by default because it depends
// on having established a reasonable Nominal + Offset target activity level.
AdaptGi slbool.Bool

// offset to add to Nominal for the target average activity that drives adaptation of Gi for this layer. Typically the Nominal level is good, but sometimes Nominal must be adjusted up or down to achieve desired Ge scaling, so this Offset can compensate accordingly.
// Offset is added to Nominal for the target average activity that drives
// adaptation of Gi for this layer. Typically the Nominal level is good,
// but sometimes Nominal must be adjusted up or down to achieve desired Ge
// scaling, so this Offset can compensate accordingly.
Offset float32 `default:"0" min:"0" step:"0.01"`

// tolerance for higher than Target target average activation as a proportion of that target value (0 = exactly the target, 0.2 = 20% higher than target) -- only once activations move outside this tolerance are inhibitory values adapted.
// HiTol is the tolerance for higher than Target target average activation
// as a proportion of that target value (0 = exactly the target, 0.2 = 20%
// higher than target). Only once activations move outside this tolerance
// are inhibitory values adapted.
HiTol float32 `default:"0"`

// tolerance for lower than Target target average activation as a proportion of that target value (0 = exactly the target, 0.5 = 50% lower than target) -- only once activations move outside this tolerance are inhibitory values adapted.
// LoTol is the tolerance for lower than Target target average activation
// as a proportion of that target value (0 = exactly the target, 0.5 = 50%
// lower than target). Only once activations move outside this tolerance are
// inhibitory values adapted.
LoTol float32 `default:"0.8"`

// rate of Gi adaptation as function of AdaptRate * (Target - ActMAvg) / Target -- occurs at spaced intervals determined by Network.SlowInterval value -- slower values such as 0.01 may be needed for large networks and sparse layers.
// AdaptRate is the rate of Gi adaptation as function of
// AdaptRate * (Target - ActMAvg) / Target. This occurs at spaced intervals
// determined by Network.SlowInterval value. Slower values such as 0.01 may
// be needed for large networks and sparse layers.
AdaptRate float32 `default:"0.1"`

pad, pad1 float32
pad float32
}

func (aa *ActAvgParams) Update() {
}

func (aa *ActAvgParams) Defaults() {
aa.Nominal = 0.1
aa.RTThr = 0.5
aa.Offset = 0
aa.HiTol = 0
aa.LoTol = 0.8
Expand Down
1 change: 1 addition & 0 deletions axon/init-layer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions axon/init-layer.goal
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func (ly *Layer) InitWeights(ctx *Context, nt *Network) { //types:add
LayerStates[li, di, LayerPhaseDiffAvg] = 0
LayerStates[li, di, LayerPhaseDiffVar] = 0
LayerStates[li, di, LayerRT] = -1
LayerStates[li, di, GatedRT] = -1
LayerStates[li, di, LayerRewPredPos] = 0
LayerStates[li, di, LayerRewPredNeg] = 0
}
Expand Down
6 changes: 5 additions & 1 deletion axon/layervars.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ const (
LayerPhaseDiffVar

// LayerRT is the reaction time for this layer in cycles, which is -1 until the
// Max CaP level (after MaxCycStart) exceeds the Act.Attn.RTThr threshold.
// Max CaP level (after MaxCycStart) exceeds the Inhib.ActAvg.RTThr threshold.
LayerRT

// GatedRT is the reaction time for this layer in cycles, which is -1 until the
// Layer-level [PoolGated] is true.
GatedRT

// LayerRewPredPos is the positive-valued Reward Prediction value, for
// RL specific layers: [RWPredLayer], [TDPredLayer].
// For [TDIntegLayer], this is the plus phase current integrated reward prediction.
Expand Down
9 changes: 5 additions & 4 deletions axon/shaders/ApplyExtsNeuron.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ const GlobalScalarVarsN: GlobalScalarVars = 57;
const GlobalVectorVarsN: GlobalVectorVars = 10;
const GPUVarsN: GPUVars = 23;
const LayerTypesN: LayerTypes = 30;
const LayerVarsN: LayerVars = 11;
const LayerVarsN: LayerVars = 12;
const ViewTimesN: ViewTimes = 7;
const DAModTypesN: DAModTypes = 4;
const ValenceTypesN: ValenceTypes = 3;
Expand Down Expand Up @@ -621,13 +621,13 @@ struct HipPathParams {
//////// import: "inhib.go"
struct ActAvgParams {
Nominal: f32,
RTThr: f32,
AdaptGi: i32,
Offset: f32,
HiTol: f32,
LoTol: f32,
AdaptRate: f32,
pad: f32,
pad1: f32,
}
struct InhibParams {
ActAvg: ActAvgParams,
Expand Down Expand Up @@ -774,8 +774,9 @@ const LayerPhaseDiff: LayerVars = 5;
const LayerPhaseDiffAvg: LayerVars = 6;
const LayerPhaseDiffVar: LayerVars = 7;
const LayerRT: LayerVars = 8;
const LayerRewPredPos: LayerVars = 9;
const LayerRewPredNeg: LayerVars = 10;
const GatedRT: LayerVars = 9;
const LayerRewPredPos: LayerVars = 10;
const LayerRewPredNeg: LayerVars = 11;

//////// import: "learn-layer.go"

Expand Down
Loading

0 comments on commit 459b9cd

Please sign in to comment.