From d56b43110202bb40c8136e347b855a5a04f78ebd Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Tue, 20 Aug 2024 10:09:36 -0700 Subject: [PATCH] detector code fully working, and update go.mod --- ch2/detector/README.md | 4 ++-- ch2/detector/detector.go | 36 +++++++++++++++++++++++++++++++++--- ch2/neuron/neuron.go | 5 ++--- go.mod | 2 +- go.sum | 4 ++-- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/ch2/detector/README.md b/ch2/detector/README.md index ff4426ae..f352ac30 100644 --- a/ch2/detector/README.md +++ b/ch2/detector/README.md @@ -9,7 +9,7 @@ We will see how a particular pattern of weights makes a simulated neuron respond # The Network and Input Patterns -We begin by examining the `NetView` tab, showing the Detector network. The network has an `Input` layer that will have patterns of activation in the shape of different digits, and these input neurons are connected to the receiving neuron (`RecvNeuron`) via a set of weighted synaptic connections. We can view the pattern of weights (synaptic strengths) that this receiving unit has from the input, which should give us an idea about what this unit will detect. +We begin by examining the `Network` tab, showing the Detector network. The network has an `Input` layer that will have patterns of activation in the shape of different digits, and these input neurons are connected to the receiving neuron (`RecvNeuron`) via a set of weighted synaptic connections. We can view the pattern of weights (synaptic strengths) that this receiving unit has from the input, which should give us an idea about what this unit will detect. * Select `r.Wt` as the value you want to display (on the left side of the 3D network view) and then click on the `RecvNeuron` to view its receiving weights. @@ -23,7 +23,7 @@ The display that comes up shows all of the different *input patterns* that will To see the receiving neuron respond to these input patterns, we will present them one-by-one, and determine why the neuron responds as it does given its weights. Thus, we need to view the activations again in the network window. -* Select `Act` in the `NetView` to view activations, then click `Test Trial` in the toolbar at the top of the window. +* Select `Act` in the `Network` to view activations, then click `Test Trial` in the toolbar at the top of the window. This activates the pattern of a `0` (zero) in the `Input`, and shows 20 cycles of **settling** process where the activation of the receiving unit is iteratively updated over a series of **cycles** according to the point neuron activation function (just as the unit in the `neuron` simulation was updated over time). We have selected 20 cycles as enough time for the receiving neuron to fully respond to the input. diff --git a/ch2/detector/detector.go b/ch2/detector/detector.go index 6398f495..fefb50d6 100644 --- a/ch2/detector/detector.go +++ b/ch2/detector/detector.go @@ -13,10 +13,12 @@ package main import ( "embed" "log" + "reflect" "cogentcore.org/core/base/randx" "cogentcore.org/core/core" "cogentcore.org/core/icons" + "cogentcore.org/core/math32/minmax" "cogentcore.org/core/tensor/table" "cogentcore.org/core/tree" "github.com/emer/emergent/v2/egui" @@ -111,7 +113,7 @@ type Sim struct { // New creates new blank elements and initializes defaults func (ss *Sim) New() { ss.Defaults() - ss.Net = leabra.NewNetwork("RA25") + ss.Net = leabra.NewNetwork("Detector") ss.Params.Config(ParamSets, "", "", ss.Net) ss.Stats.Init() ss.Pats = &table.Table{} @@ -333,11 +335,28 @@ func (ss *Sim) ConfigLogs() { ss.Logs.AddCounterItems(etime.Trial, etime.Cycle) ss.Logs.AddStatStringItem(etime.Test, etime.Trial, "TrialName") - ss.Logs.AddLayerTensorItems(ss.Net, "Act", etime.Test, etime.Trial, "InputLayer") + // ss.Logs.AddLayerTensorItems(ss.Net, "Act", etime.Test, etime.Trial, "InputLayer") + + ly := ss.Net.LayerByName("RecvNeuron") + vars := []string{"Ge", "Act"} + + for _, vnm := range vars { + ss.Logs.AddItem(&elog.Item{ + Name: vnm, + Type: reflect.Float64, + FixMax: false, + Range: minmax.F32{Max: 1}, + Write: elog.WriteMap{ + etime.Scope(etime.Test, etime.Trial): func(ctx *elog.Context) { + vl := ly.UnitValue(vnm, []int{0, 0}, 0) + ctx.SetFloat32(vl) + }}}) + } ss.Logs.CreateTables() ss.Logs.SetContext(&ss.Stats, ss.Net) - ss.Logs.NoPlot(etime.Test, etime.Run) + ss.Logs.NoPlot(etime.Test, etime.Cycle) + ss.Logs.PlotItems("Ge", "Act") } // Log is the main logging function, handles special things for different scopes @@ -377,6 +396,7 @@ func (ss *Sim) ConfigGUI() { nv.SetNet(ss.Net) ss.ViewUpdate.Config(nv, etime.AlphaCycle, etime.AlphaCycle) ss.GUI.ViewUpdate = &ss.ViewUpdate + nv.Current() // nv.SceneXYZ().Camera.Pose.Pos.Set(0, 1, 2.75) // more "head on" than default which is more "top down" // nv.SceneXYZ().Camera.LookAt(math32.Vec3(0, 0, 0), math32.Vec3(0, 1, 0)) @@ -407,6 +427,16 @@ func (ss *Sim) ConfigGUI() { }, }) //////////////////////////////////////////////// + ss.GUI.AddToolbarItem(p, egui.ToolbarItem{Label: "Defaults", Icon: icons.Update, + Tooltip: "Restore initial default parameters.", + Active: egui.ActiveStopped, + Func: func() { + ss.Defaults() + ss.Init() + ss.GUI.SimForm.Update() + ss.GUI.UpdateWindow() + }, + }) tree.Add(p, func(w *core.Separator) {}) ss.GUI.AddToolbarItem(p, egui.ToolbarItem{Label: "README", Icon: icons.FileMarkdown, diff --git a/ch2/neuron/neuron.go b/ch2/neuron/neuron.go index 1cb11f58..753cf400 100644 --- a/ch2/neuron/neuron.go +++ b/ch2/neuron/neuron.go @@ -390,15 +390,14 @@ func (ss *Sim) ConfigLogItems() { vars := []string{"Ge", "Inet", "Vm", "Act", "Spike", "Gk", "ISI", "AvgISI"} for _, vnm := range vars { - cvnm := vnm // closure lg.AddItem(&elog.Item{ - Name: cvnm, + Name: vnm, Type: reflect.Float64, FixMax: false, Range: minmax.F32{Max: 1}, Write: elog.WriteMap{ etime.Scope(etime.Test, etime.Cycle): func(ctx *elog.Context) { - vl := ly.UnitValue(cvnm, []int{0, 0}, 0) + vl := ly.UnitValue(vnm, []int{0, 0}, 0) ctx.SetFloat32(vl) }}}) } diff --git a/go.mod b/go.mod index cac1a62d..f50f00ce 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22 require ( cogentcore.org/core v0.3.3-0.20240820000827-b7efbcd96c73 github.com/emer/emergent/v2 v2.0.0-dev0.1.0.0.20240819205648-250dd483d63c - github.com/emer/leabra/v2 v2.0.0-20240820071506-d51ea1f829b7 + github.com/emer/leabra/v2 v2.0.0-20240820170610-78a264a7af82 ) require ( diff --git a/go.sum b/go.sum index 09b4c764..d268a61c 100644 --- a/go.sum +++ b/go.sum @@ -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-20240820071506-d51ea1f829b7 h1:+U/neEki4ohcFXxdcGKNtonLkS5z8wTlmErF0Kv7PUE= -github.com/emer/leabra/v2 v2.0.0-20240820071506-d51ea1f829b7/go.mod h1:+3sD+Lq2GLyd1bMRU9aNn3fiBkwyKrjfYUb6TBWn1ro= +github.com/emer/leabra/v2 v2.0.0-20240820170610-78a264a7af82 h1:BdaL5rOartUXnBEprYKGm9OchXRqbVIN4YN9FU9PTHA= +github.com/emer/leabra/v2 v2.0.0-20240820170610-78a264a7af82/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=