Skip to content

Commit

Permalink
first pass choose convert runs
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Dec 19, 2024
1 parent bd89784 commit 51d624c
Show file tree
Hide file tree
Showing 9 changed files with 681 additions and 1,273 deletions.
8 changes: 8 additions & 0 deletions axon/simstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ func StatsNode(statsDir *tensorfs.Node, mode, level enums.Enum) *tensorfs.Node {
return modeDir.RecycleDir(level.String())
}

func StatsLayerValues(net *Network, curDir *tensorfs.Node, mode enums.Enum, di int, layName, varName string) *tensor.Float32 {
curModeDir := curDir.RecycleDir(mode.String())
ly := net.LayerByName(layName)
tsr := curModeDir.Float32(layName+"_"+varName, ly.Shape.Sizes...)
ly.UnitValuesTensor(tsr, varName, di)
return tsr
}

// LogFilename returns a standard log file name as netName_runName_logName.tsv
func LogFilename(netName, runName, logName string) string {
return netName + "_" + runName + "_" + logName + ".tsv"
Expand Down
45 changes: 21 additions & 24 deletions examples/choose/armaze/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"cogentcore.org/core/events"
"cogentcore.org/core/icons"
"cogentcore.org/core/math32"
"cogentcore.org/core/plot"
"cogentcore.org/core/plot/plotcore"
"cogentcore.org/core/styles"
"cogentcore.org/core/styles/abilities"
Expand Down Expand Up @@ -494,43 +495,38 @@ func (vw *GUI) ConfigView3D(se *xyz.Scene) {
}

func (vw *GUI) ConfigUSPlots() {
dp := table.NewTable()
dp := table.New()
dp.AddStringColumn("US")
dp.AddFloat64Column("Drive")
dp.AddFloat64Column("OFC")
dp.AddFloat64Column("USin")
dp.SetNumRows(vw.Env.Config.NDrives + 1)

vw.USposData = dp
vw.USposPlot.Options.Type = plotcore.Bar
vw.USposPlot.Options.Title = "Positive USs"
vw.USposPlot.Options.Scale = 1
vw.USposPlot.Options.XAxis = "US"
// vw.USposPlot.Options.Type = plotcore.Bar
// vw.USposPlot.Options.Title = "Positive USs"
// vw.USposPlot.Options.Scale = 1
// vw.USposPlot.Options.XAxis = "US"

dn := table.NewTable()
dn := table.New()
dn.AddStringColumn("US")
dn.AddFloat64Column("OFC")
dn.AddFloat64Column("USin")
dn.SetNumRows(vw.Env.Config.NNegUSs + 2)

vw.USnegData = dn
vw.USnegPlot.Options.Type = plotcore.Bar
vw.USnegPlot.Options.Title = "Negative USs"
vw.USnegPlot.Options.Scale = 1
vw.USnegPlot.Options.XAxis = "US"
// vw.USnegPlot.Options.Type = plotcore.Bar
// vw.USnegPlot.Options.Title = "Negative USs"
// vw.USnegPlot.Options.Scale = 1
// vw.USnegPlot.Options.XAxis = "US"

cols := []string{"Drive", "USin", "OFC"}
for i, cl := range cols {
dp.SetMetaData(cl+":On", "true")
dp.SetMetaData(cl+":FixMin", "true")
dp.SetMetaData(cl+":FixMax", "true")
dp.SetMetaData(cl+":Max", "1")
if i > 0 {
dn.SetMetaData(cl+":On", "true")
dn.SetMetaData(cl+":FixMin", "true")
dn.SetMetaData(cl+":FixMax", "true")
dn.SetMetaData(cl+":Max", "1")
}
for _, cl := range cols {
plot.SetFirstStylerTo(cl, func(s *plot.Style) {
s.On = true
s.Range.SetMin(0).SetMax(1)

})
}
vw.USposPlot.SetTable(dp)
vw.USnegPlot.SetTable(dn)
Expand Down Expand Up @@ -595,9 +591,10 @@ func (vw *GUI) ConfigWorldView(tg *tensorcore.TensorGrid) {
}
colormap.AvailableMaps[cnm] = cm
}
tg.Display.Defaults()
tg.Display.ColorMap = core.ColorMapName(cnm)
tg.Display.GridFill = 1
tensorcore.AddGridStylerTo(tg, func(s *tensorcore.GridStyle) {
s.ColorMap = core.ColorMapName(cnm)
s.GridFill = 1
})
}

func (vw *GUI) UpdateWorld(ctx *axon.Context, ev *Env, net *axon.Network, state TraceStates) {
Expand Down
26 changes: 15 additions & 11 deletions examples/choose/armaze/maze.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ package armaze
//go:generate core generate -add-types

import (
"fmt"

"cogentcore.org/core/base/randx"
"cogentcore.org/core/cli"
"cogentcore.org/core/math32/minmax"
"cogentcore.org/core/tensor"
"github.com/emer/emergent/v2/econfig"
)

// Actions is a list of mutually exclusive states
Expand Down Expand Up @@ -119,10 +121,12 @@ type Env struct {

func (ev *Env) Label() string { return ev.Name }

func (ev *Env) String() string { return fmt.Sprintf("%d_%d_%d", ev.Arm, ev.Pos, ev.Dist) }

// Defaults sets default params
func (ev *Env) Defaults() {
ev.Config.Defaults()
econfig.SetFromDefaults(&ev.Config)
cli.SetFromDefaults(&ev.Config)
ev.Config.Update()
}

Expand Down Expand Up @@ -159,16 +163,16 @@ func (ev *Env) Init(run int) {
ev.UpdateMaxLength()

ev.States = make(map[string]*tensor.Float32)
ev.States["CS"] = tensor.NewFloat32([]int{cfg.Params.NYReps, cfg.NArms})
ev.States["Pos"] = tensor.NewFloat32([]int{cfg.Params.NYReps, ev.MaxLength + 1})
ev.States["Dist"] = tensor.NewFloat32([]int{cfg.Params.NYReps, ev.MaxLength + 1})
ev.States["Action"] = tensor.NewFloat32([]int{cfg.Params.NYReps, int(ActionsN)})
ev.States["CS"] = tensor.NewFloat32(cfg.Params.NYReps, cfg.NArms)
ev.States["Pos"] = tensor.NewFloat32(cfg.Params.NYReps, ev.MaxLength+1)
ev.States["Dist"] = tensor.NewFloat32(cfg.Params.NYReps, ev.MaxLength+1)
ev.States["Action"] = tensor.NewFloat32(cfg.Params.NYReps, int(ActionsN))

ev.NewStart()
ev.JustConsumed = true // will trigger a new start again on Step
}

func (ev *Env) State(el string) tensor.Tensor {
func (ev *Env) State(el string) tensor.Values {
return ev.States[el]
}

Expand Down Expand Up @@ -301,7 +305,7 @@ func (ev *Env) RenderLocalist(name string, val int) {
return
}
for y := 0; y < ev.Config.Params.NYReps; y++ {
st.Set([]int{y, val}, 1.0)
st.Set(1.0, y, val)
}
}

Expand All @@ -310,7 +314,7 @@ func (ev *Env) RenderLocalist4D(name string, val int) {
st := ev.States[name]
st.SetZeros()
for y := 0; y < ev.Config.Params.NYReps; y++ {
st.Set([]int{0, val, y, 0}, 1.0)
st.Set(1.0, 0, val, y, 0)
}
}

Expand Down Expand Up @@ -341,7 +345,7 @@ func (ev *Env) DecodeLocalist(vt *tensor.Float32) int {
for i := 0; i < dx; i++ {
var sum float32
for j := 0; j < ev.Config.Params.NYReps; j++ {
sum += vt.Value([]int{j, i})
sum += vt.Value(j, i)
}
if sum > max {
max = sum
Expand All @@ -353,7 +357,7 @@ func (ev *Env) DecodeLocalist(vt *tensor.Float32) int {

// Action records the LastAct and renders it, but does not
// update the state accordingly.
func (ev *Env) Action(action string, nop tensor.Tensor) {
func (ev *Env) Action(action string, nop tensor.Values) {
act := None
act.SetString(action)
ev.LastAct = act
Expand Down
2 changes: 1 addition & 1 deletion examples/choose/armaze/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (tr *StateTrace) AddRec(ctx *axon.Context, di uint32, ev *Env, net *axon.Ne
rec.Time = ctx.Time
rec.Trial = int(ctx.TrialsTotal)
for i := 0; i < ev.Config.NDrives; i++ {
rec.Drives[i] = axon.GlbUSposV(ctx, di, axon.GvDrives, uint32(1+i))
rec.Drives[i] = axon.GlobalVectors.Value(int(axon.GvDrives), int(1+i), int(di))
}
}

Expand Down
Loading

0 comments on commit 51d624c

Please sign in to comment.