Skip to content

Commit

Permalink
detector code fully working, and update go.mod
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Aug 20, 2024
1 parent 80c35e4 commit d56b431
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ch2/detector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand Down
36 changes: 33 additions & 3 deletions ch2/detector/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions ch2/neuron/neuron.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}}})
}
Expand Down
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.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 (
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-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=
Expand Down

0 comments on commit d56b431

Please sign in to comment.