Skip to content

Commit

Permalink
first pass implementation of new standardized 10 cycle CaBin with env…
Browse files Browse the repository at this point in the history
…elope weights integration
  • Loading branch information
rcoreilly committed Jan 22, 2025
1 parent 68ff268 commit 02f148f
Show file tree
Hide file tree
Showing 90 changed files with 1,102 additions and 246 deletions.
5 changes: 3 additions & 2 deletions axon/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ type Context struct { //types:add -setters

// CaBinCycles is the number of cycles for neuron [CaBins] values used in
// computing synaptic calcium values. Total number of bins = ThetaCycles / CaBinCycles.
CaBinCycles int32 `default:"25"`
// This is fixed at 10.
CaBinCycles int32 `default:"10"`

// CyclesTotal is the accumulated cycle count, which increments continuously
// from whenever it was last reset. Typically this is the number of milliseconds
Expand Down Expand Up @@ -102,7 +103,7 @@ func (ctx *Context) Defaults() {
ctx.TimePerCycle = 0.001
ctx.ThetaCycles = 200
ctx.PlusCycles = 50
ctx.CaBinCycles = 25
ctx.CaBinCycles = 10
ctx.SlowInterval = 100
}

Expand Down
2 changes: 1 addition & 1 deletion axon/enumgen.go

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions axon/learn-path.go

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

20 changes: 17 additions & 3 deletions axon/learn-path.goal
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,23 @@ func (pt *PathParams) DWtSyn(ctx *Context, rlay *LayerParams, syni, si, ri, di u
func (pt *PathParams) SynCa(ctx *Context, si, ri, di uint32, syCaP, syCaD *float32) {
nbins := NetworkIxs[0].NCaBins
cadSt := GvCaBinWts+GlobalScalarVars(nbins)
var cp, cd float32
for i := range nbins {
sp := Neurons[ri, di, CaBins + NeuronVars(i)] * Neurons[si, di, CaBins + NeuronVars(i)]

// T0
r0 := Neurons[ri, di, CaBins + NeuronVars(0)]
s0 := Neurons[si, di, CaBins + NeuronVars(0)]
sp := pt.Learn.SynCaBin.SynCaT0(r0, s0)
cp := sp * GlobalScalars[GvCaBinWts + GlobalScalarVars(0), 0]
cd := sp * GlobalScalars[cadSt + GlobalScalarVars(0), 0]

// T1
r1 := Neurons[ri, di, CaBins + NeuronVars(1)]
s1 := Neurons[si, di, CaBins + NeuronVars(1)]
sp = pt.Learn.SynCaBin.SynCaT1(r0, r1, s0, s1)
cp += sp * GlobalScalars[GvCaBinWts + GlobalScalarVars(1), 0]
cd += sp * GlobalScalars[cadSt + GlobalScalarVars(1), 0]

for i := int32(2); i < nbins; i++ {
sp := pt.Learn.SynCaBin.SynCaT(Neurons[ri, di, CaBins + NeuronVars(i)], Neurons[ri, di, CaBins + NeuronVars(i-1)], Neurons[ri, di, CaBins + NeuronVars(i-2)], Neurons[si, di, CaBins + NeuronVars(i)], Neurons[si, di, CaBins + NeuronVars(i-1)], Neurons[si, di, CaBins + NeuronVars(i-2)])
cp += sp * GlobalScalars[GvCaBinWts + GlobalScalarVars(i), 0]
cd += sp * GlobalScalars[cadSt + GlobalScalarVars(i), 0]
}
Expand Down
10 changes: 10 additions & 0 deletions axon/learn.go

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

10 changes: 10 additions & 0 deletions axon/learn.goal
Original file line number Diff line number Diff line change
Expand Up @@ -852,20 +852,30 @@ type LearnSynParams struct {
// trace-based cortical learning rule and for other specialized learning rules.
DWt DWtParams `display:"inline"`

// SynCaBin computes synaptic calcium values as a product of the
// separately-integrated and binned sender and receiver SynCa values.
// Binning always happens at 10 msec intervals, but the product term
// is more robust if computed on a longer effective timescale, which
// is determined by weighting factors for the t-1 and t-2 bins when
// computing the neural SynCa for time bin t.
SynCaBin kinase.SynCaBin `display:"inline"`

// hebbian learning option, which overrides the default learning rules
Hebb HebbParams `display:"inline"`
}

func (ls *LearnSynParams) Update() {
ls.LRate.Update()
ls.DWt.Update()
ls.SynCaBin.Update()
ls.Hebb.Update()
}

func (ls *LearnSynParams) Defaults() {
ls.Learn.SetBool(true)
ls.LRate.Defaults()
ls.DWt.Defaults()
ls.SynCaBin.Defaults()
ls.Hebb.Defaults()
}

Expand Down
3 changes: 1 addition & 2 deletions axon/network.go

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

3 changes: 1 addition & 2 deletions axon/network.goal
Original file line number Diff line number Diff line change
Expand Up @@ -941,10 +941,9 @@ func (nt *Network) SetCaBinWts() {
ctx := nt.Context()
nix := nt.NetIxs()
nBins := int(nix.NCaBins)
nPlusBins := int(ctx.PlusCycles / ctx.CaBinCycles)
cp := make([]float32, nBins)
cd := make([]float32, nBins)
kinase.CaBinWts(nPlusBins, int(ctx.CaBinCycles), cp, cd)
kinase.CaBinWts(int(ctx.PlusCycles), cp, cd)
for i := range nBins {
nt.GlobalScalars[GvCaBinWts+GlobalScalarVars(i), 0] = cp[i]
nt.GlobalScalars[GvCaBinWts+GlobalScalarVars(nBins+i), 0] = cd[i]
Expand Down
4 changes: 2 additions & 2 deletions axon/neuron.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ const (

// CaBins is a vector of values starting here, with aggregated [CaSyn] values
// in time bins of [Context.CaBinCycles] across the theta cycle,
// for computing synaptic calcium efficiently. There can be a variable number
// of bins depending on bin width and total number of cycles.
// for computing synaptic calcium efficiently. Each bin = Sum(CaSyn) / CaBinCycles.
// Total number of bins = [Context.ThetaCycles] / CaBinCycles.
// Synaptic calcium is integrated from sender * receiver CaBins values,
// with weights for CaP vs CaD that reflect their faster vs. slower time constants,
// respectively. CaD is used for the credit assignment factor, while CaP - CaD is
Expand Down
18 changes: 18 additions & 0 deletions axon/shaders/ApplyExtsNeuron.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,23 @@ struct CaSpikeParams {
Dt: CaDtParams,
}

//////// import: "kinase-syncabin.go"
alias SynCaBinEnvelopes = i32; //enums:enum
const Env30: SynCaBinEnvelopes = 0;
const Env25: SynCaBinEnvelopes = 1;
const Env20: SynCaBinEnvelopes = 2;
const Env10: SynCaBinEnvelopes = 3;
struct SynCaBin { //types:add
Envelope: SynCaBinEnvelopes,
Wt1: f32,
Wt2: f32,
Wt11: f32,
Wt10: f32,
WtT0: f32,
WtT1: f32,
WtT2: f32,
}

//////// import: "layerparams.go"
struct LayerIndexes {
NPools: u32,
Expand Down Expand Up @@ -842,6 +859,7 @@ struct LearnSynParams {
pad2: i32,
LRate: LRateParams,
DWt: DWtParams,
SynCaBin: SynCaBin,
Hebb: HebbParams,
}

Expand Down
18 changes: 18 additions & 0 deletions axon/shaders/Beta1Neuron.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,23 @@ struct CaSpikeParams {
Dt: CaDtParams,
}

//////// import: "kinase-syncabin.go"
alias SynCaBinEnvelopes = i32; //enums:enum
const Env30: SynCaBinEnvelopes = 0;
const Env25: SynCaBinEnvelopes = 1;
const Env20: SynCaBinEnvelopes = 2;
const Env10: SynCaBinEnvelopes = 3;
struct SynCaBin { //types:add
Envelope: SynCaBinEnvelopes,
Wt1: f32,
Wt2: f32,
Wt11: f32,
Wt10: f32,
WtT0: f32,
WtT1: f32,
WtT2: f32,
}

//////// import: "layerparams.go"
struct LayerIndexes {
NPools: u32,
Expand Down Expand Up @@ -787,6 +804,7 @@ struct LearnSynParams {
pad2: i32,
LRate: LRateParams,
DWt: DWtParams,
SynCaBin: SynCaBin,
Hebb: HebbParams,
}

Expand Down
18 changes: 18 additions & 0 deletions axon/shaders/Beta2Neuron.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,23 @@ struct CaSpikeParams {
Dt: CaDtParams,
}

//////// import: "kinase-syncabin.go"
alias SynCaBinEnvelopes = i32; //enums:enum
const Env30: SynCaBinEnvelopes = 0;
const Env25: SynCaBinEnvelopes = 1;
const Env20: SynCaBinEnvelopes = 2;
const Env10: SynCaBinEnvelopes = 3;
struct SynCaBin { //types:add
Envelope: SynCaBinEnvelopes,
Wt1: f32,
Wt2: f32,
Wt11: f32,
Wt10: f32,
WtT0: f32,
WtT1: f32,
WtT2: f32,
}

//////// import: "layerparams.go"
struct LayerIndexes {
NPools: u32,
Expand Down Expand Up @@ -787,6 +804,7 @@ struct LearnSynParams {
pad2: i32,
LRate: LRateParams,
DWt: DWtParams,
SynCaBin: SynCaBin,
Hebb: HebbParams,
}

Expand Down
18 changes: 18 additions & 0 deletions axon/shaders/BetweenGi.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,23 @@ struct CaSpikeParams {
Dt: CaDtParams,
}

//////// import: "kinase-syncabin.go"
alias SynCaBinEnvelopes = i32; //enums:enum
const Env30: SynCaBinEnvelopes = 0;
const Env25: SynCaBinEnvelopes = 1;
const Env20: SynCaBinEnvelopes = 2;
const Env10: SynCaBinEnvelopes = 3;
struct SynCaBin { //types:add
Envelope: SynCaBinEnvelopes,
Wt1: f32,
Wt2: f32,
Wt11: f32,
Wt10: f32,
WtT0: f32,
WtT1: f32,
WtT2: f32,
}

//////// import: "layerparams.go"
struct LayerIndexes {
NPools: u32,
Expand Down Expand Up @@ -807,6 +824,7 @@ struct LearnSynParams {
pad2: i32,
LRate: LRateParams,
DWt: DWtParams,
SynCaBin: SynCaBin,
Hebb: HebbParams,
}

Expand Down
18 changes: 18 additions & 0 deletions axon/shaders/CycleInc.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,23 @@ struct CaSpikeParams {
Dt: CaDtParams,
}

//////// import: "kinase-syncabin.go"
alias SynCaBinEnvelopes = i32; //enums:enum
const Env30: SynCaBinEnvelopes = 0;
const Env25: SynCaBinEnvelopes = 1;
const Env20: SynCaBinEnvelopes = 2;
const Env10: SynCaBinEnvelopes = 3;
struct SynCaBin { //types:add
Envelope: SynCaBinEnvelopes,
Wt1: f32,
Wt2: f32,
Wt11: f32,
Wt10: f32,
WtT0: f32,
WtT1: f32,
WtT2: f32,
}

//////// import: "layerparams.go"
struct LayerIndexes {
NPools: u32,
Expand Down Expand Up @@ -783,6 +800,7 @@ struct LearnSynParams {
pad2: i32,
LRate: LRateParams,
DWt: DWtParams,
SynCaBin: SynCaBin,
Hebb: HebbParams,
}

Expand Down
18 changes: 18 additions & 0 deletions axon/shaders/CycleNeuron.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,23 @@ fn CaSpikeParams_CaSynFromSpike(sp: CaSpikeParams, spike: f32, caSyn: f32) -> f3
var ca = sp.SpikeCaSyn * spike;return caSyn + sp.CaSynDt*(ca-caSyn);
}

//////// import: "kinase-syncabin.go"
alias SynCaBinEnvelopes = i32; //enums:enum
const Env30: SynCaBinEnvelopes = 0;
const Env25: SynCaBinEnvelopes = 1;
const Env20: SynCaBinEnvelopes = 2;
const Env10: SynCaBinEnvelopes = 3;
struct SynCaBin { //types:add
Envelope: SynCaBinEnvelopes,
Wt1: f32,
Wt2: f32,
Wt11: f32,
Wt10: f32,
WtT0: f32,
WtT1: f32,
WtT2: f32,
}

//////// import: "layerparams.go"
struct LayerIndexes {
NPools: u32,
Expand Down Expand Up @@ -1689,6 +1706,7 @@ struct LearnSynParams {
pad2: i32,
LRate: LRateParams,
DWt: DWtParams,
SynCaBin: SynCaBin,
Hebb: HebbParams,
}

Expand Down
18 changes: 18 additions & 0 deletions axon/shaders/CyclePost.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,23 @@ struct CaSpikeParams {
Dt: CaDtParams,
}

//////// import: "kinase-syncabin.go"
alias SynCaBinEnvelopes = i32; //enums:enum
const Env30: SynCaBinEnvelopes = 0;
const Env25: SynCaBinEnvelopes = 1;
const Env20: SynCaBinEnvelopes = 2;
const Env10: SynCaBinEnvelopes = 3;
struct SynCaBin { //types:add
Envelope: SynCaBinEnvelopes,
Wt1: f32,
Wt2: f32,
Wt11: f32,
Wt10: f32,
WtT0: f32,
WtT1: f32,
WtT2: f32,
}

//////// import: "layerparams.go"
struct LayerIndexes {
NPools: u32,
Expand Down Expand Up @@ -925,6 +942,7 @@ struct LearnSynParams {
pad2: i32,
LRate: LRateParams,
DWt: DWtParams,
SynCaBin: SynCaBin,
Hebb: HebbParams,
}

Expand Down
Loading

0 comments on commit 02f148f

Please sign in to comment.