Skip to content

Commit

Permalink
kinaseq is just for testing learned regress eqs; cleanup a few things.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Jun 13, 2024
1 parent e39a5a5 commit 435276b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 473 deletions.
2 changes: 1 addition & 1 deletion examples/deep_fsa/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var ParamSets = netparams.Sets{
"Path.SWts.Adapt.LRate": "0.01", // 0.01 or 0.0001 music
"Path.SWts.Init.SPct": "1.0", // 1 works fine here -- .5 also ok
"Path.Com.PFail": "0.0",
"Path.Learn.Trace.Tau": "2", // 2 > 1 still 1.7.19
"Path.Learn.Trace.Tau": "1", // 1 >> 2 v0.0.9
}},
{Sel: ".BackPath", Desc: "top-down back-pathways MUST have lower relative weight scale, otherwise network hallucinates",
Params: params.Params{
Expand Down
23 changes: 0 additions & 23 deletions examples/kinaseq/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,6 @@ package main

// ParamConfig has config parameters related to sim params
type ParamConfig struct {

// gain multiplier on spike for computing CaSpk: increasing this directly affects the magnitude of the trace values, learning rate in Target layers, and other factors that depend on CaSpk values: RLRate, UpdateThr. Path.KinaseCa.SpikeG provides an additional gain factor specific to the synapse-level trace factors, without affecting neuron-level CaSpk values. Larger networks require higher gain factors at the neuron level -- 12, vs 8 for smaller.
SpikeG float32 `default:"8"`

// time constant for integrating spike-driven calcium trace at sender and recv neurons, CaSyn, which then drives synapse-level integration of the joint pre * post synapse-level activity, in cycles (msec). Note: if this param is changed, then there will be a change in effective learning rate that can be compensated for by multiplying PathParams.Learn.KinaseCa.SpikeG by sqrt(30 / sqrt(SynTau)
SynTau float32 `default:"30" min:"1"`

// rate = 1 / tau
SynDt float32 `view:"-" json:"-" xml:"-" edit:"-"`

// learning rate for decoder
LRate float32 `default:"0.001"`

// network parameters
Network map[string]any

// Extra Param Sheet name(s) to use (space separated if multiple) -- must be valid name as listed in compiled-in params or loaded params
Sheet string

Expand All @@ -41,15 +25,8 @@ type ParamConfig struct {
Good bool `nest:"+"`
}

func (pc *ParamConfig) Update() {
pc.SynDt = 1.0 / pc.SynTau
}

// RunConfig has config parameters related to running the sim
type RunConfig struct {
// Neuron runs the standard Neuron update equations, vs. Kinase experimental equations
Neuron bool `default:"false"`

// use the GPU for computation -- only for testing in this model -- not faster
GPU bool `default:"false"`

Expand Down
60 changes: 10 additions & 50 deletions examples/kinaseq/kinaseq.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (kn *KinaseNeuron) StartTrial() {

// Cycle does one cycle of neuron updating, with given exponential spike interval
// based on target spiking firing rate.
func (kn *KinaseNeuron) Cycle(expInt float32, params *ParamConfig, cyc int) {
func (ss *Sim) Cycle(kn *KinaseNeuron, expInt float32, cyc int) {
kn.Spike = 0
bin := cyc / 50
if expInt > 0 {
Expand All @@ -66,7 +66,7 @@ func (kn *KinaseNeuron) Cycle(expInt float32, params *ParamConfig, cyc int) {
kn.SpikeBins[bin] += 1
}
}
kn.CaSyn += params.SynDt * (params.SpikeG*kn.Spike - kn.CaSyn)
kn.CaSyn += ss.NeurCa.SynDt * (ss.NeurCa.SpikeG*kn.Spike - kn.CaSyn)
}

func (kn *KinaseNeuron) SetInput(inputs []float32, off int) {
Expand Down Expand Up @@ -102,9 +102,6 @@ func (ks *KinaseSynapse) Init() {
// KinaseState is basic Kinase equation state
type KinaseState struct {

// if true, training decoder
Train bool

// SSE for decoder
SSE float32

Expand Down Expand Up @@ -159,7 +156,6 @@ func (ss *Sim) ConfigKinase() {

// Sweep runs a sweep through minus-plus ranges
func (ss *Sim) Sweep() {
ss.Kinase.Train = false
// hz := []float32{25, 50, 100}
// nhz := len(hz)

Expand Down Expand Up @@ -196,7 +192,6 @@ func (ss *Sim) Run() {

// RunImpl runs NTrials, recording to RunLog and TrialLog
func (ss *Sim) RunImpl(minusHz, plusHz float32, ntrials int) {
ss.Kinase.Train = false
ss.Kinase.Init()
for trl := 0; trl < ntrials; trl++ {
ss.Kinase.Trial = trl
Expand Down Expand Up @@ -248,14 +243,12 @@ func (ss *Sim) TrialImpl(minusHz, plusHz float32) {
Sint = math32.Exp(-1000.0 / float32(shz))
}
for t := 0; t < maxcyc; t++ {
ks.Send.Cycle(Sint, &cfg.Params, ks.Cycle)
ks.Recv.Cycle(Rint, &cfg.Params, ks.Cycle)
ss.Cycle(&ks.Send, Sint, ks.Cycle)
ss.Cycle(&ks.Recv, Rint, ks.Cycle)

ca := ks.Send.CaSyn * ks.Recv.CaSyn
ss.CaParams.FromCa(ca, &ks.StdSyn.CaM, &ks.StdSyn.CaP, &ks.StdSyn.CaD)
if !ks.Train {
ss.Logs.LogRow(etime.Test, etime.Cycle, ks.Cycle)
}
ss.SynCa.FromCa(ca, &ks.StdSyn.CaM, &ks.StdSyn.CaP, &ks.StdSyn.CaD)
ss.Logs.LogRow(etime.Test, etime.Cycle, ks.Cycle)
ks.Cycle++
}
}
Expand All @@ -265,36 +258,12 @@ func (ss *Sim) TrialImpl(minusHz, plusHz float32) {
ks.SpikeBins[i] = 0.1 * (ks.Recv.SpikeBins[i] * ks.Send.SpikeBins[i])
}

ss.CaParams.FinalCa(ks.SpikeBins[0], ks.SpikeBins[1], ks.SpikeBins[2], ks.SpikeBins[3], &ks.LinearSyn.CaM, &ks.LinearSyn.CaP, &ks.LinearSyn.CaD)
ss.LinearSynCa.FinalCa(ks.SpikeBins[0], ks.SpikeBins[1], ks.SpikeBins[2], ks.SpikeBins[3], &ks.LinearSyn.CaP, &ks.LinearSyn.CaD)
ks.LinearSyn.DWt = ks.LinearSyn.CaP - ks.LinearSyn.CaD

if ks.Train {
ss.Logs.LogRow(etime.Train, etime.Cycle, 0)
ss.GUI.UpdatePlot(etime.Train, etime.Cycle)
ss.Logs.LogRow(etime.Train, etime.Trial, ks.Trial)
ss.GUI.UpdatePlot(etime.Train, etime.Trial)
} else {
ss.GUI.UpdatePlot(etime.Test, etime.Cycle)
ss.Logs.LogRow(etime.Test, etime.Trial, ks.Trial)
ss.GUI.UpdatePlot(etime.Test, etime.Trial)
}
}

// Train trains the linear decoder
func (ss *Sim) Train() {
ss.Kinase.Train = true
ss.Kinase.Init()
for epc := 0; epc < ss.Config.Run.NEpochs; epc++ {
ss.Kinase.Condition = epc
for trl := 0; trl < ss.Config.Run.NTrials; trl++ {
ss.Kinase.Trial = trl
minusHz := 100 * rand.Float32()
plusHz := 100 * rand.Float32()
ss.TrialImpl(minusHz, plusHz)
}
ss.Logs.LogRow(etime.Train, etime.Condition, ss.Kinase.Condition)
ss.GUI.UpdatePlot(etime.Train, etime.Condition)
}
ss.GUI.UpdatePlot(etime.Test, etime.Cycle)
ss.Logs.LogRow(etime.Test, etime.Trial, ks.Trial)
ss.GUI.UpdatePlot(etime.Test, etime.Trial)
}

func (ss *Sim) ConfigKinaseLogItems() {
Expand Down Expand Up @@ -346,15 +315,6 @@ func (ss *Sim) ConfigKinaseLogItems() {
ctx.SetAgg(ctx.Mode, times[ti+1], stats.Mean)
}
} else {
itm.Write[etime.Scope(etime.Train, times[ti])] = func(ctx *elog.Context) {
fany := value.Interface()
switch fkind {
case reflect.Int:
ctx.SetFloat32(float32(fany.(int)))
case reflect.String:
ctx.SetString(fany.(string))
}
}
itm.Write[etime.Scope(etime.Test, times[ti])] = func(ctx *elog.Context) {
fany := value.Interface()
switch fkind {
Expand Down
215 changes: 0 additions & 215 deletions examples/kinaseq/neuron.go

This file was deleted.

Loading

0 comments on commit 435276b

Please sign in to comment.