Skip to content

Commit

Permalink
add missing WtFromDWtLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Nov 26, 2024
1 parent 5c76015 commit b8ac3b8
Show file tree
Hide file tree
Showing 32 changed files with 1,650 additions and 66 deletions.
3 changes: 2 additions & 1 deletion axon/act-net.go

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

3 changes: 2 additions & 1 deletion axon/act-net.goal
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ func (nt *Network) PlusPhaseStart() {
RunPlusPhaseStartNeuron(nd)
}

// PlusPhase does updating after end of plus phase
// PlusPhase does updating after end of plus phase.
// On GPU this is when we finally sync back Layers and Neurons.
func (nt *Network) PlusPhase() {
nix := nt.NetIxs()
ctx := nt.Context()
Expand Down
43 changes: 43 additions & 0 deletions axon/gosl.go

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

41 changes: 23 additions & 18 deletions axon/learn-layer.go

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

41 changes: 23 additions & 18 deletions axon/learn-layer.goal
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ package axon

import "cogentcore.org/core/math32"

//gosl:start

// DTrgSubMean subtracts the mean from DTrgAvg values
// Called by TrgAvgFromD
func (ly *Layer) DTrgSubMean(ctx *Context) {
submean := ly.Params.Learn.TrgAvgAct.SubMean
func (ly *LayerParams) DTrgSubMean(ctx *Context) {
submean := ly.Learn.TrgAvgAct.SubMean
if submean == 0 {
return
}
if ly.Params.HasPoolInhib() && ly.Params.Learn.TrgAvgAct.Pool.IsTrue() {
np := ly.NPools
if ly.HasPoolInhib() && ly.Learn.TrgAvgAct.Pool.IsTrue() {
np := ly.Indexes.NPools
for spi := uint32(1); spi < np; spi++ {
pi := ly.Params.PoolIndex(spi) // only for idxs
pi := ly.PoolIndex(spi)
nsi := PoolsInt[pi, 0, PoolNeurSt]
nei := PoolsInt[pi, 0, PoolNeurEd]
nn := 0
avg := float32(0)
for lni := nsi; lni < nei; lni++ {
ni := ly.NeurStIndex + uint32(lni)
ni := ly.Indexes.NeurSt + uint32(lni)
if NeuronIsOff(ni) {
continue
}
Expand All @@ -35,7 +37,7 @@ func (ly *Layer) DTrgSubMean(ctx *Context) {
avg /= float32(nn)
avg *= submean
for lni := nsi; lni < nei; lni++ {
ni := ly.NeurStIndex + uint32(lni)
ni := ly.Indexes.NeurSt + uint32(lni)
if NeuronIsOff(ni) {
continue
}
Expand All @@ -45,8 +47,9 @@ func (ly *Layer) DTrgSubMean(ctx *Context) {
} else {
nn := 0
avg := float32(0)
for lni := uint32(0); lni < ly.NNeurons; lni++ {
ni := ly.NeurStIndex + lni
tn := ly.Indexes.NNeurons
for lni := uint32(0); lni < tn; lni++ {
ni := ly.Indexes.NeurSt + lni
if NeuronIsOff(ni) {
continue
}
Expand All @@ -58,8 +61,8 @@ func (ly *Layer) DTrgSubMean(ctx *Context) {
}
avg /= float32(nn)
avg *= submean
for lni := uint32(0); lni < ly.NNeurons; lni++ {
ni := ly.NeurStIndex + lni
for lni := uint32(0); lni < tn; lni++ {
ni := ly.Indexes.NeurSt + lni
if NeuronIsOff(ni) {
continue
}
Expand All @@ -69,32 +72,34 @@ func (ly *Layer) DTrgSubMean(ctx *Context) {
}

// TrgAvgFromD updates TrgAvg from DTrgAvg -- called in PlusPhasePost
func (ly *Layer) TrgAvgFromD(ctx *Context) {
lr := ly.Params.LearnTrgAvgErrLRate()
func (ly *LayerParams) TrgAvgFromD(ctx *Context) {
lr := ly.LearnTrgAvgErrLRate()
if lr == 0 {
return
}
ly.DTrgSubMean(ctx)
nn := ly.NNeurons
nn := ly.Indexes.NNeurons
for lni := uint32(0); lni < nn; lni++ {
ni := ly.NeurStIndex + lni
ni := ly.Indexes.NeurSt + lni
if NeuronIsOff(ni) {
continue
}
ntrg := NeuronAvgs[ni, TrgAvg] + NeuronAvgs[ni, DTrgAvg]
ntrg = ly.Params.Learn.TrgAvgAct.TrgRange.ClipValue(ntrg)
ntrg = ly.Learn.TrgAvgAct.TrgRange.ClipValue(ntrg)
NeuronAvgs[ni, TrgAvg] = ntrg
NeuronAvgs[ni, DTrgAvg] = 0
NeuronAvgs[ni, DTrgAvg] = 0.0
}
}

// WtFromDWtLayer does weight update at the layer level.
// does NOT call main pathway-level WtFromDWt method.
// in base, only calls TrgAvgFromD
func (ly *Layer) WtFromDWtLayer(ctx *Context) {
func (ly *LayerParams) WtFromDWtLayer(ctx *Context) {
ly.TrgAvgFromD(ctx)
}

//gosl:end

// SlowAdapt is the layer-level slow adaptation functions.
// Calls AdaptInhib and AvgDifFromTrgAvg for Synaptic Scaling.
// Does NOT call pathway-level methods.
Expand Down
25 changes: 11 additions & 14 deletions axon/learn-net.go

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

Loading

0 comments on commit b8ac3b8

Please sign in to comment.