Skip to content

Commit

Permalink
neuron fully functional and ready for further testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Aug 20, 2024
1 parent f034763 commit 21993ca
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 35 deletions.
75 changes: 74 additions & 1 deletion ch2/neuron/neuron.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"cogentcore.org/core/core"
"cogentcore.org/core/icons"
"cogentcore.org/core/math32/minmax"
"cogentcore.org/core/plot/plotcore"
"cogentcore.org/core/tree"
"github.com/emer/emergent/v2/egui"
"github.com/emer/emergent/v2/elog"
Expand Down Expand Up @@ -135,6 +136,7 @@ func (ss *Sim) New() {
}

func (ss *Sim) Defaults() {
ss.SpikeParams.Defaults()
ss.Params.Config(ParamSets, "", "", ss.Net)
ss.UpdateInterval = 10
ss.Cycle = 0
Expand Down Expand Up @@ -285,6 +287,54 @@ func (ss *Sim) Stop() {
ss.GUI.StopNow = true
}

// SpikeVsRate runs comparison between spiking vs. rate-code
func (ss *Sim) SpikeVsRate() {
row := 0
nsamp := 100
// ss.KNaAdapt = false
tcl := ss.Logs.Table(etime.Test, etime.Cycle)
svr := ss.Logs.MiscTable("SpikeVsRate")
for gbarE := 0.1; gbarE <= 0.7; gbarE += 0.025 {
ss.GbarE = float32(gbarE)
spike := float64(0)
ss.Noise = 0.1 // RunCycles calls SetParams to set this
ss.Spike = true
for ns := 0; ns < nsamp; ns++ {
tcl.Rows = 0
ss.RunCycles()
if ss.GUI.StopNow {
break
}
act := tcl.Float("Act", 159)
spike += act
}
rate := float64(0)
ss.Spike = false
// ss.Noise = 0 // doesn't make much diff
for ns := 0; ns < nsamp; ns++ {
tcl.Rows = 0
ss.RunCycles()
if ss.GUI.StopNow {
break
}
act := tcl.Float("Act", 159)
rate += act
}
if ss.GUI.StopNow {
break
}
spike /= float64(nsamp)
rate /= float64(nsamp)
svr.AddRows(1)
svr.SetFloat("GBarE", row, gbarE)
svr.SetFloat("Spike", row, spike)
svr.SetFloat("Rate", row, rate)
row++
}
ss.Defaults()
ss.GUI.Plots[etime.ScopeKey("SpikeVsRate")].UpdatePlot()
}

/////////////////////////////////////////////////////////////////////////
// Params setting

Expand All @@ -304,16 +354,23 @@ func (ss *Sim) SetParams(sheet string, setMsg bool) {
ly.Act.Update()
ss.SpikeParams.ActParams = ly.Act // keep sync'd
ss.SpikeParams.KNa.On = ss.KNaAdapt
ly.UpdateParams()
}

func (ss *Sim) ConfigLogs() {
ss.ConfigLogItems()
ss.Logs.CreateTables()

ss.Logs.PlotItems("Vm", "Spike")
ss.Logs.PlotItems("Ge", "Inet", "Vm", "Act", "Spike", "Gk")

ss.Logs.SetContext(&ss.Stats, ss.Net)
ss.Logs.ResetLog(etime.Test, etime.Cycle)

svr := ss.Logs.MiscTable("SpikeVsRate")
svr.AddFloat64Column("GBarE")
svr.AddFloat64Column("Spike")
svr.AddFloat64Column("Rate")
svr.SetMetaData("Rate:On", "+")
}

func (ss *Sim) ConfigLogItems() {
Expand Down Expand Up @@ -375,6 +432,14 @@ func (ss *Sim) ConfigGUI() {

ss.GUI.AddPlots(title, &ss.Logs)

svr := "SpikeVsRate"
dt := ss.Logs.MiscTable(svr)
plt := plotcore.NewSubPlot(ss.GUI.Tabs.NewTab(svr + " Plot"))
ss.GUI.Plots[etime.ScopeKey(svr)] = plt
plt.Options.Title = svr
plt.Options.XAxis = "GBarE"
plt.SetTable(dt)

ss.GUI.Body.AddAppBar(func(p *tree.Plan) {
ss.GUI.AddToolbarItem(p, egui.ToolbarItem{Label: "Init", Icon: icons.Update,
Tooltip: "Initialize everything including network weights, and start over. Also applies current params.",
Expand Down Expand Up @@ -415,6 +480,14 @@ func (ss *Sim) ConfigGUI() {
ss.GUI.UpdateWindow()
},
})
ss.GUI.AddToolbarItem(p, egui.ToolbarItem{Label: "Spike Vs Rate", Icon: icons.PlayArrow,
Tooltip: "Generate a plot of actual spiking rate vs computed NXX1 rate code.",
Active: egui.ActiveStopped,
Func: func() {
ss.SpikeVsRate()
ss.GUI.UpdateWindow()
},
})

ss.GUI.AddToolbarItem(p, egui.ToolbarItem{Label: "Defaults", Icon: icons.Update,
Tooltip: "Restore initial default parameters.",
Expand Down
31 changes: 0 additions & 31 deletions ch2/neuron/neuron.params

This file was deleted.

9 changes: 9 additions & 0 deletions ch2/neuron/typegen.go

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

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22
require (
cogentcore.org/core v0.3.3-0.20240819201856-14e5d78556c3
github.com/emer/emergent/v2 v2.0.0-dev0.1.0.0.20240819205648-250dd483d63c
github.com/emer/leabra/v2 v2.0.0-20240819212512-f7f5a1a9993a
github.com/emer/leabra/v2 v2.0.0-20240820071506-d51ea1f829b7
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxK
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/emer/emergent/v2 v2.0.0-dev0.1.0.0.20240819205648-250dd483d63c h1:lNof7cfU4uKjimEbe9+V8iZUOkU3WWr01PIAbBmcXwQ=
github.com/emer/emergent/v2 v2.0.0-dev0.1.0.0.20240819205648-250dd483d63c/go.mod h1:xSMtRuFkyD27pk5+o9BupztSxz/B2rwVL8AGmTFK/6U=
github.com/emer/leabra/v2 v2.0.0-20240819212512-f7f5a1a9993a h1:PpBtaHDf4GUApN0NFN8fXXXJ9Y8bFEog3kQAgQCtBkg=
github.com/emer/leabra/v2 v2.0.0-20240819212512-f7f5a1a9993a/go.mod h1:+3sD+Lq2GLyd1bMRU9aNn3fiBkwyKrjfYUb6TBWn1ro=
github.com/emer/leabra/v2 v2.0.0-20240820071506-d51ea1f829b7 h1:+U/neEki4ohcFXxdcGKNtonLkS5z8wTlmErF0Kv7PUE=
github.com/emer/leabra/v2 v2.0.0-20240820071506-d51ea1f829b7/go.mod h1:+3sD+Lq2GLyd1bMRU9aNn3fiBkwyKrjfYUb6TBWn1ro=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
Expand Down

0 comments on commit 21993ca

Please sign in to comment.