Skip to content

Commit

Permalink
first pass update does everything except make the netview layers..
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Jun 14, 2024
1 parent 92661e7 commit 96b5da7
Show file tree
Hide file tree
Showing 32 changed files with 614 additions and 471 deletions.
12 changes: 6 additions & 6 deletions actrf/actrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ type RF struct {
Name string

// computed receptive field, as SumProd / SumSrc -- only after Avg has been called
RF tensor.Float32 `view:"no-inline"`
RF tensor.Float32 `display:"no-inline"`

// unit normalized version of RF per source (inner 2D dimensions) -- good for display
NormRF tensor.Float32 `view:"no-inline"`
NormRF tensor.Float32 `display:"no-inline"`

// normalized version of SumSrc -- sum of each point in the source -- good for viewing the completeness and uniformity of the sampling of the source space
NormSrc tensor.Float32 `view:"no-inline"`
NormSrc tensor.Float32 `display:"no-inline"`

// sum of the products of act * src
SumProd tensor.Float32 `view:"no-inline"`
SumProd tensor.Float32 `display:"no-inline"`

// sum of the sources (denomenator)
SumSrc tensor.Float32 `view:"no-inline"`
SumSrc tensor.Float32 `display:"no-inline"`

// temporary destination sum for MPI -- only used when MPISum called
MPITmp tensor.Float32 `view:"no-inline"`
MPITmp tensor.Float32 `display:"no-inline"`
}

// Init initializes this RF based on name and shapes of given
Expand Down
14 changes: 7 additions & 7 deletions confusion/confusion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ import (
type Matrix struct { //git:add

// normalized probability of confusion: Row = ground truth class, Col = actual response for that class.
Prob tensor.Float64 `view:"no-inline"`
Prob tensor.Float64 `display:"no-inline"`

// incremental sums
Sum tensor.Float64 `view:"no-inline"`
Sum tensor.Float64 `display:"no-inline"`

// counts per ground truth (rows)
N tensor.Float64 `view:"no-inline"`
N tensor.Float64 `display:"no-inline"`

// visualization using SimMat
Vis simat.SimMat `view:"no-inline"`
Vis simat.SimMat `display:"no-inline"`

// true pos/neg, false pos/neg for each class, generated from the confusion matrix
TFPN tensor.Float64 `view:"no-inline"`
TFPN tensor.Float64 `display:"no-inline"`

// precision, recall and F1 score by class
ClassScores tensor.Float64 `view:"no-inline"`
ClassScores tensor.Float64 `display:"no-inline"`

// micro F1, macro F1 and weighted F1 scores for entire matrix ignoring class
MatrixScores tensor.Float64 `view:"no-inline"`
MatrixScores tensor.Float64 `display:"no-inline"`
}

// Init initializes the Matrix for given number of classes,
Expand Down
4 changes: 2 additions & 2 deletions decoder/linear.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Linear struct {
Inputs []float32

// for holding layer values
ValuesTsrs map[string]*tensor.Float32 `view:"-"`
ValuesTsrs map[string]*tensor.Float32 `display:"-"`

// synaptic weights: outer loop is units, inner loop is inputs
Weights tensor.Float32
Expand All @@ -52,7 +52,7 @@ type Linear struct {
PoolIndex int

// mpi communicator -- MPI users must set this to their comm -- do direct assignment
Comm *mpi.Comm `view:"-"`
Comm *mpi.Comm `display:"-"`

// delta weight changes: only for MPI mode -- outer loop is units, inner loop is inputs
MPIDWts tensor.Float32
Expand Down
4 changes: 2 additions & 2 deletions decoder/softmax.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ type SoftMax struct {
Target int

// for holding layer values
ValuesTsrs map[string]*tensor.Float32 `view:"-"`
ValuesTsrs map[string]*tensor.Float32 `display:"-"`

// synaptic weights: outer loop is units, inner loop is inputs
Weights tensor.Float32

// mpi communicator -- MPI users must set this to their comm -- do direct assignment
Comm *mpi.Comm `view:"-"`
Comm *mpi.Comm `display:"-"`

// delta weight changes: only for MPI mode -- outer loop is units, inner loop is inputs
MPIDWts tensor.Float32
Expand Down
8 changes: 4 additions & 4 deletions econfig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ The [Cogent Core](https://cogentcore.org/core) GUI processes `default:"value"` s

# Standard Config Example

Here's the `Config` struct from [axon/examples/ra25](https://github.com/emer/axon), which can provide a useful starting point. It uses Params, Run and Log sub-structs to better organize things. For sims with extensive Env config, that should be added as a separate sub-struct as well. The `view:"add-fields"` struct tag shows all of the fields in one big dialog in the GUI -- if you want separate ones, omit that.
Here's the `Config` struct from [axon/examples/ra25](https://github.com/emer/axon), which can provide a useful starting point. It uses Params, Run and Log sub-structs to better organize things. For sims with extensive Env config, that should be added as a separate sub-struct as well. The `display:"add-fields"` struct tag shows all of the fields in one big dialog in the GUI -- if you want separate ones, omit that.

```Go
// ParamConfig has config parameters related to sim params
Expand Down Expand Up @@ -179,13 +179,13 @@ type Config struct {
Debug bool

// parameter related configuration options
Params ParamConfig `view:"add-fields"`
Params ParamConfig `display:"add-fields"`

// sim running related configuration options
Run RunConfig `view:"add-fields"`
Run RunConfig `display:"add-fields"`

// data logging related configuration options
Log LogConfig `view:"add-fields"`
Log LogConfig `display:"add-fields"`
}

func (cfg *Config) IncludesPtr() *[]string { return &cfg.Includes }
Expand Down
4 changes: 2 additions & 2 deletions econfig/include.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func includesStackImpl(clone Includeser, includes []string) ([]string, error) {
var errs []error
for _, inc := range incs {
*clone.IncludesPtr() = nil
err := tomlx.OpenFromPaths(clone, inc, IncludePaths)
err := tomlx.OpenFromPaths(clone, inc, IncludePaths...)
if err == nil {
includes, err = includesStackImpl(clone, includes)
if err != nil {
Expand Down Expand Up @@ -88,7 +88,7 @@ func includeStackImpl(clone Includer, includes []string) ([]string, error) {
includes = append(includes, inc)
var errs []error
*clone.IncludePtr() = ""
err := tomlx.OpenFromPaths(clone, inc, IncludePaths)
err := tomlx.OpenFromPaths(clone, inc, IncludePaths...)
if err == nil {
includes, err = includeStackImpl(clone, includes)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions econfig/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// Is equivalent to Open if there are no Includes.
// Returns an error if any of the include files cannot be found on IncludePath.
func OpenWithIncludes(cfg any, file string) error {
err := tomlx.OpenFromPaths(cfg, file, IncludePaths)
err := tomlx.OpenFromPaths(cfg, file, IncludePaths...)
if err != nil {
return err
}
Expand All @@ -40,13 +40,13 @@ func OpenWithIncludes(cfg any, file string) error {
}
for i := ni - 1; i >= 0; i-- {
inc := incs[i]
err = tomlx.OpenFromPaths(cfg, inc, IncludePaths)
err = tomlx.OpenFromPaths(cfg, inc, IncludePaths...)
if err != nil {
mpi.Println(err)
}
}
// reopen original
tomlx.OpenFromPaths(cfg, file, IncludePaths)
tomlx.OpenFromPaths(cfg, file, IncludePaths...)
if hasIncludes {
*incsObj.IncludesPtr() = incs
} else {
Expand Down
6 changes: 3 additions & 3 deletions egui/grids.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func (gui *GUI) SetGrid(name string, tg *tensorcore.TensorGrid) {

// ConfigRasterGrid configures a raster grid for given layer name.
// Uses Raster_laynm and given Tensor that has the raster data.
func (gui *GUI) ConfigRasterGrid(lay *core.Layout, laynm string, rast *tensor.Float32) *tensorcore.TensorGrid {
func (gui *GUI) ConfigRasterGrid(lay *core.Frame, laynm string, rast *tensor.Float32) *tensorcore.TensorGrid {
tg := gui.Grid(laynm)
tg.SetName(laynm + "Raster")
core.NewText(lay, laynm, laynm+":")
core.NewText(lay).SetText(laynm + ":")
lay.AddChild(tg)
core.NewSpace(lay, laynm+"_spc")
core.NewSpace(lay)
rast.SetMetaData("grid-fill", "1")
tg.SetTensor(rast)
return tg
Expand Down
30 changes: 16 additions & 14 deletions egui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ type GUI struct {
CycleUpdateInterval int

// true if the GUI is configured and running
Active bool `view:"-"`
Active bool `display:"-"`

// true if sim is running
IsRunning bool `view:"-"`
IsRunning bool `display:"-"`

// flag to stop running
StopNow bool `view:"-"`
StopNow bool `display:"-"`

// plots by scope
Plots map[etime.ScopeKey]*plotcore.PlotEditor
Expand All @@ -40,19 +40,19 @@ type GUI struct {
Grids map[string]*tensorcore.TensorGrid

// the view update for managing updates of netview
ViewUpdate *netview.ViewUpdate `view:"-"`
ViewUpdate *netview.ViewUpdate `display:"-"`

// net data for recording in nogui mode, if !nil
NetData *netview.NetData `view:"-"`
NetData *netview.NetData `display:"-"`

// displays Sim fields on left
StructView *core.Form `view:"-"`
StructView *core.Form `display:"-"`

// tabs for different view elements: plots, rasters
Tabs *core.Tabs `view:"-"`
Tabs *core.Tabs `display:"-"`

// Body is the content of the sim window
Body *core.Body `view:"-"`
Body *core.Body `display:"-"`
}

// UpdateWindow triggers an update on window body,
Expand All @@ -61,7 +61,7 @@ type GUI struct {
func (gui *GUI) UpdateWindow() {
tb := gui.Body.GetTopAppBar()
if tb != nil {
tb.ApplyStyleUpdate()
tb.Restyle()
}
gui.Body.Scene.NeedsRender()
// todo: could update other stuff but not really neccesary
Expand All @@ -75,7 +75,7 @@ func (gui *GUI) GoUpdateWindow() {

tb := gui.Body.GetTopAppBar()
if tb != nil {
tb.ApplyStyleUpdate()
tb.Restyle()
}
gui.Body.Scene.NeedsRender()
// todo: could update other stuff but not really neccesary
Expand All @@ -101,13 +101,15 @@ func (gui *GUI) MakeBody(sim any, appname, title, about string) {

gui.Body = core.NewBody(appname).SetTitle(title)
// gui.Body.App().About = about
split := core.NewSplits(gui.Body, "split")
split := core.NewSplits(gui.Body)
split.Name = "split"
gui.StructView = core.NewForm(split).SetStruct(sim)
gui.StructView.Name = "sv"
if tb, ok := sim.(core.Toolbarer); ok {
gui.Body.AddAppBar(tb.ConfigToolbar)
if tb, ok := sim.(core.ToolbarMaker); ok {
gui.Body.AddAppBar(tb.MakeToolbar)
}
gui.Tabs = core.NewTabs(split, "tv")
gui.Tabs = core.NewTabs(split)
gui.Tabs.Name = "tv"
split.SetSplits(.2, .8)
}

Expand Down
107 changes: 58 additions & 49 deletions egui/loopctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (

// AddLooperCtrl adds toolbar control for looper.Stack
// with Run, Step controls.
func (gui *GUI) AddLooperCtrl(tb *core.Toolbar, loops *looper.Manager, modes []etime.Modes) {
gui.AddToolbarItem(tb, ToolbarItem{Label: "Stop",
func (gui *GUI) AddLooperCtrl(p *core.Plan, loops *looper.Manager, modes []etime.Modes) {
gui.AddToolbarItem(p, ToolbarItem{Label: "Stop",
Icon: icons.Stop,
Tooltip: "Interrupts running. running / stepping picks back up where it left off.",
Active: ActiveRunning,
Expand All @@ -30,65 +30,74 @@ func (gui *GUI) AddLooperCtrl(tb *core.Toolbar, loops *looper.Manager, modes []e

for _, m := range modes {
mode := m
core.NewButton(tb).SetText(mode.String() + " Run").SetIcon(icons.PlayArrow).
SetTooltip("Run the " + mode.String() + " process").
StyleFirst(func(s *styles.Style) { s.SetEnabled(!gui.IsRunning) }).
OnClick(func(e events.Event) {
if !gui.IsRunning {
gui.IsRunning = true
tb.ApplyStyleUpdate()
go func() {
loops.Run(mode)
gui.Stopped()
}()
}
})
core.AddAt(p, mode.String()+"-run", func(w *core.Button) {
w.SetText(mode.String() + " Run").SetIcon(icons.PlayArrow).
SetTooltip("Run the " + mode.String() + " process").
FirstStyler(func(s *styles.Style) { s.SetEnabled(!gui.IsRunning) }).
OnClick(func(e events.Event) {
if !gui.IsRunning {
gui.IsRunning = true
// tb.Restyle() // todo: need obj on plan
go func() {
loops.Run(mode)
gui.Stopped()
}()
}
})
})

//stepLevel := evalLoops.Step.Default
stepN := make(map[string]int)
steps := loops.Stacks[mode].Order
stringToEnumTime := make(map[string]etime.Times)
for _, st := range steps {
stepN[st.String()] = 1
stringToEnumTime[st.String()] = st
}
core.NewButton(tb).SetText("Step").SetIcon(icons.SkipNext).
SetTooltip("Step the " + mode.String() + " process according to the following step level and N").
StyleFirst(func(s *styles.Style) {
s.SetEnabled(!gui.IsRunning)
s.SetAbilities(true, abilities.RepeatClickable)
}).
OnClick(func(e events.Event) {
if !gui.IsRunning {
gui.IsRunning = true
tb.ApplyStyleUpdate()
go func() {
stack := loops.Stacks[mode]
loops.Step(mode, stepN[stack.StepLevel.String()], stack.StepLevel)
gui.Stopped()
}()
}
})

scb := core.NewChooser(tb, "step")
stepStrs := []string{}
for _, s := range steps {
stepStrs = append(stepStrs, s.String())
}
scb.SetStrings(stepStrs...)
stack := loops.Stacks[mode]
scb.SetCurrentValue(stack.StepLevel.String())

sb := core.NewSpinner(tb, "step-n").SetTooltip("number of iterations per step").
SetStep(1).SetMin(1).SetValue(1)
sb.OnChange(func(e events.Event) {
stepN[scb.CurrentItem.Value.(string)] = int(sb.Value)
core.AddAt(p, mode.String()+"-step", func(w *core.Button) {
w.SetText("Step").SetIcon(icons.SkipNext).
SetTooltip("Step the " + mode.String() + " process according to the following step level and N").
FirstStyler(func(s *styles.Style) {
s.SetEnabled(!gui.IsRunning)
s.SetAbilities(true, abilities.RepeatClickable)
}).
OnClick(func(e events.Event) {
if !gui.IsRunning {
gui.IsRunning = true
// tb.Restyle()
go func() {
stack := loops.Stacks[mode]
loops.Step(mode, stepN[stack.StepLevel.String()], stack.StepLevel)
gui.Stopped()
}()
}
})
})

scb.OnChange(func(e events.Event) {
var chs *core.Chooser
core.AddAt(p, mode.String()+"-level", func(w *core.Chooser) {
chs = w
stepStrs := []string{}
for _, s := range steps {
stepStrs = append(stepStrs, s.String())
}
w.SetStrings(stepStrs...)
stack := loops.Stacks[mode]
stack.StepLevel = stringToEnumTime[scb.CurrentItem.Value.(string)]
sb.Value = float32(stepN[stack.StepLevel.String()])
w.SetCurrentValue(stack.StepLevel.String())
})

core.AddAt(p, mode.String()+"-n", func(w *core.Spinner) {
w.SetStep(1).SetMin(1).SetValue(1)
w.SetTooltip("number of iterations per step").
OnChange(func(e events.Event) {
stepN[chs.CurrentItem.Value.(string)] = int(w.Value)
})

w.OnChange(func(e events.Event) {
stack := loops.Stacks[mode]
stack.StepLevel = stringToEnumTime[chs.CurrentItem.Value.(string)]
w.Value = float32(stepN[stack.StepLevel.String()])
})
})
}
}
Loading

0 comments on commit 96b5da7

Please sign in to comment.