Skip to content

Commit

Permalink
first pass update of netview for new core
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Jun 14, 2024
1 parent 96708b8 commit 92661e7
Show file tree
Hide file tree
Showing 17 changed files with 321 additions and 410 deletions.
2 changes: 1 addition & 1 deletion egui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Here's an `ActiveRunning` case:
## Tensor Grid (e.g., of an Image)
```Go
tg := ss.GUI.TabView.AddNewTab(tensorview.KiT_TensorGrid, "Image").(*tensorview.TensorGrid)
tg := ss.GUI.TabView.AddNewTab(tensorcore.KiT_TensorGrid, "Image").(*tensorcore.TensorGrid)
tg.SetStretchMax()
ss.GUI.SetGrid("Image", tg)
tg.SetTensor(&ss.TrainEnv.Img.Tsr)
Expand Down
18 changes: 9 additions & 9 deletions egui/grids.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@ package egui
import (
"cogentcore.org/core/core"
"cogentcore.org/core/tensor"
"cogentcore.org/core/tensor/tensorview"
"cogentcore.org/core/tensor/tensorcore"
"github.com/emer/emergent/v2/actrf"
)

// Grid gets tensor grid view of given name, creating if not yet made
func (gui *GUI) Grid(name string) *tensorview.TensorGrid {
func (gui *GUI) Grid(name string) *tensorcore.TensorGrid {
if gui.Grids == nil {
gui.Grids = make(map[string]*tensorview.TensorGrid)
gui.Grids = make(map[string]*tensorcore.TensorGrid)
}
tsr, ok := gui.Grids[name]
if !ok {
tsr = &tensorview.TensorGrid{}
tsr = &tensorcore.TensorGrid{}
gui.Grids[name] = tsr
}
return tsr
}

// SetGrid sets tensor grid view to given name
func (gui *GUI) SetGrid(name string, tg *tensorview.TensorGrid) {
func (gui *GUI) SetGrid(name string, tg *tensorcore.TensorGrid) {
if gui.Grids == nil {
gui.Grids = make(map[string]*tensorview.TensorGrid)
gui.Grids = make(map[string]*tensorcore.TensorGrid)
}
gui.Grids[name] = tg
}

// 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) *tensorview.TensorGrid {
func (gui *GUI) ConfigRasterGrid(lay *core.Layout, laynm string, rast *tensor.Float32) *tensorcore.TensorGrid {
tg := gui.Grid(laynm)
tg.SetName(laynm + "Raster")
core.NewText(lay, laynm, laynm+":")
Expand All @@ -47,7 +47,7 @@ func (gui *GUI) ConfigRasterGrid(lay *core.Layout, laynm string, rast *tensor.Fl

// SaveActRFGrid stores the given TensorGrid in Grids under given name,
// and configures the grid view for ActRF viewing.
func (gui *GUI) SaveActRFGrid(tg *tensorview.TensorGrid, name string) {
func (gui *GUI) SaveActRFGrid(tg *tensorcore.TensorGrid, name string) {
gui.SetGrid(name, tg)
}

Expand All @@ -56,7 +56,7 @@ func (gui *GUI) AddActRFGridTabs(arfs *actrf.RFs) {
for _, rf := range arfs.RFs {
nm := rf.Name
tf := gui.Tabs.NewTab(nm)
tg := tensorview.NewTensorGrid(tf)
tg := tensorcore.NewTensorGrid(tf)
gui.SaveActRFGrid(tg, nm)
}
}
Expand Down
18 changes: 9 additions & 9 deletions egui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ package egui

import (
"cogentcore.org/core/core"
"cogentcore.org/core/plot/plotview"
"cogentcore.org/core/tensor/tensorview"
"cogentcore.org/core/views"
"cogentcore.org/core/plot/plotcore"
"cogentcore.org/core/tensor/tensorcore"
"github.com/emer/emergent/v2/etime"
"github.com/emer/emergent/v2/netview"
// _ "cogentcore.org/core/vgpu/gosl/slboolview" // include to get gui views
Expand All @@ -32,13 +31,13 @@ type GUI struct {
StopNow bool `view:"-"`

// plots by scope
Plots map[etime.ScopeKey]*plotview.PlotView
Plots map[etime.ScopeKey]*plotcore.PlotEditor

// plots by scope
TableViews map[etime.ScopeKey]*tensorview.TableView
TableViews map[etime.ScopeKey]*tensorcore.Table

// tensor grid views by name -- used e.g., for Rasters or ActRFs -- use Grid(name) to access
Grids map[string]*tensorview.TensorGrid
Grids map[string]*tensorcore.TensorGrid

// the view update for managing updates of netview
ViewUpdate *netview.ViewUpdate `view:"-"`
Expand All @@ -47,7 +46,7 @@ type GUI struct {
NetData *netview.NetData `view:"-"`

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

// tabs for different view elements: plots, rasters
Tabs *core.Tabs `view:"-"`
Expand Down Expand Up @@ -98,12 +97,13 @@ func (gui *GUI) Stopped() {

// MakeBody returns default window Body content
func (gui *GUI) MakeBody(sim any, appname, title, about string) {
views.NoSentenceCaseFor = append(views.NoSentenceCaseFor, "github.com/emer")
core.NoSentenceCaseFor = append(core.NoSentenceCaseFor, "github.com/emer")

gui.Body = core.NewBody(appname).SetTitle(title)
// gui.Body.App().About = about
split := core.NewSplits(gui.Body, "split")
gui.StructView = views.NewStructView(split, "sv").SetStruct(sim)
gui.StructView = core.NewForm(split).SetStruct(sim)
gui.StructView.Name = "sv"
if tb, ok := sim.(core.Toolbarer); ok {
gui.Body.AddAppBar(tb.ConfigToolbar)
}
Expand Down
36 changes: 18 additions & 18 deletions egui/plots.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (

"cogentcore.org/core/base/errors"
"cogentcore.org/core/colors"
"cogentcore.org/core/plot/plotview"
"cogentcore.org/core/tensor/tensorview"
"cogentcore.org/core/plot/plotcore"
"cogentcore.org/core/tensor/tensorcore"
"github.com/emer/emergent/v2/elog"
"github.com/emer/emergent/v2/etime"
)

// AddPlots adds plots based on the unique tables we have,
// currently assumes they should always be plotted
func (gui *GUI) AddPlots(title string, lg *elog.Logs) {
gui.Plots = make(map[etime.ScopeKey]*plotview.PlotView)
gui.Plots = make(map[etime.ScopeKey]*plotcore.PlotEditor)
// for key, table := range Log.Tables {
for _, key := range lg.TableOrder {
modes, times := key.ModesAndTimes()
Expand All @@ -41,7 +41,7 @@ func (gui *GUI) AddPlots(title string, lg *elog.Logs) {
}
}

func ConfigPlotFromLog(title string, plt *plotview.PlotView, lg *elog.Logs, key etime.ScopeKey) {
func ConfigPlotFromLog(title string, plt *plotcore.PlotEditor, lg *elog.Logs, key etime.ScopeKey) {
_, times := key.ModesAndTimes()
time := times[0]
lt := lg.Tables[key] // LogTable struct
Expand Down Expand Up @@ -74,12 +74,12 @@ func ConfigPlotFromLog(title string, plt *plotview.PlotView, lg *elog.Logs, key
}

// Plot returns plot for mode, time scope
func (gui *GUI) Plot(mode etime.Modes, time etime.Times) *plotview.PlotView {
func (gui *GUI) Plot(mode etime.Modes, time etime.Times) *plotcore.PlotEditor {
return gui.PlotScope(etime.Scope(mode, time))
}

// PlotScope returns plot for given scope
func (gui *GUI) PlotScope(scope etime.ScopeKey) *plotview.PlotView {
func (gui *GUI) PlotScope(scope etime.ScopeKey) *plotcore.PlotEditor {
if !gui.Active {
return nil
}
Expand All @@ -92,15 +92,15 @@ func (gui *GUI) PlotScope(scope etime.ScopeKey) *plotview.PlotView {
}

// SetPlot stores given plot in Plots map
func (gui *GUI) SetPlot(scope etime.ScopeKey, plt *plotview.PlotView) {
func (gui *GUI) SetPlot(scope etime.ScopeKey, plt *plotcore.PlotEditor) {
if gui.Plots == nil {
gui.Plots = make(map[etime.ScopeKey]*plotview.PlotView)
gui.Plots = make(map[etime.ScopeKey]*plotcore.PlotEditor)
}
gui.Plots[scope] = plt
}

// UpdatePlot updates plot for given mode, time scope
func (gui *GUI) UpdatePlot(mode etime.Modes, time etime.Times) *plotview.PlotView {
func (gui *GUI) UpdatePlot(mode etime.Modes, time etime.Times) *plotcore.PlotEditor {
plot := gui.Plot(mode, time)
if plot != nil {
plot.GoUpdatePlot()
Expand All @@ -109,7 +109,7 @@ func (gui *GUI) UpdatePlot(mode etime.Modes, time etime.Times) *plotview.PlotVie
}

// UpdatePlotScope updates plot at given scope
func (gui *GUI) UpdatePlotScope(scope etime.ScopeKey) *plotview.PlotView {
func (gui *GUI) UpdatePlotScope(scope etime.ScopeKey) *plotcore.PlotEditor {
plot := gui.PlotScope(scope)
if plot != nil {
plot.GoUpdatePlot()
Expand All @@ -119,7 +119,7 @@ func (gui *GUI) UpdatePlotScope(scope etime.ScopeKey) *plotview.PlotView {

// UpdateCyclePlot updates cycle plot for given mode.
// only updates every CycleUpdateInterval
func (gui *GUI) UpdateCyclePlot(mode etime.Modes, cycle int) *plotview.PlotView {
func (gui *GUI) UpdateCyclePlot(mode etime.Modes, cycle int) *plotcore.PlotEditor {
plot := gui.Plot(mode, etime.Cycle)
if plot == nil {
return plot
Expand All @@ -133,17 +133,17 @@ func (gui *GUI) UpdateCyclePlot(mode etime.Modes, cycle int) *plotview.PlotView
// NewPlotTab adds a new plot with given key for Plots lookup
// and using given tab label. For ad-hoc plots, you can
// construct a ScopeKey from any two strings using etime.ScopeStr.
func (gui *GUI) NewPlotTab(key etime.ScopeKey, tabLabel string) *plotview.PlotView {
plt := plotview.NewSubPlot(gui.Tabs.NewTab(tabLabel))
func (gui *GUI) NewPlotTab(key etime.ScopeKey, tabLabel string) *plotcore.PlotEditor {
plt := plotcore.NewSubPlot(gui.Tabs.NewTab(tabLabel))
gui.Plots[key] = plt
return plt
}

// AddTableView adds a table view of given log,
// typically particularly useful for Debug logs.
func (gui *GUI) AddTableView(lg *elog.Logs, mode etime.Modes, time etime.Times) *tensorview.TableView {
func (gui *GUI) AddTableView(lg *elog.Logs, mode etime.Modes, time etime.Times) *tensorcore.Table {
if gui.TableViews == nil {
gui.TableViews = make(map[etime.ScopeKey]*tensorview.TableView)
gui.TableViews = make(map[etime.ScopeKey]*tensorcore.Table)
}

key := etime.Scope(mode, time)
Expand All @@ -154,15 +154,15 @@ func (gui *GUI) AddTableView(lg *elog.Logs, mode etime.Modes, time etime.Times)
}

tt := gui.Tabs.NewTab(mode.String() + " " + time.String() + " ")
tv := tensorview.NewTableView(tt)
tv := tensorcore.NewTableView(tt)
gui.TableViews[key] = tv
tv.SetReadOnly(true)
tv.SetTable(lt.Table)
return tv
}

// TableView returns TableView for mode, time scope
func (gui *GUI) TableView(mode etime.Modes, time etime.Times) *tensorview.TableView {
func (gui *GUI) TableView(mode etime.Modes, time etime.Times) *tensorcore.Table {
if !gui.Active {
return nil
}
Expand All @@ -176,7 +176,7 @@ func (gui *GUI) TableView(mode etime.Modes, time etime.Times) *tensorview.TableV
}

// UpdateTableView updates TableView for given mode, time scope
func (gui *GUI) UpdateTableView(mode etime.Modes, time etime.Times) *tensorview.TableView {
func (gui *GUI) UpdateTableView(mode etime.Modes, time etime.Times) *tensorcore.Table {
tv := gui.TableView(mode, time)
if tv != nil {
tv.GoUpdateView()
Expand Down
2 changes: 1 addition & 1 deletion elog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ First, initialize the ActRFs in the `ConfigLogs` function, using strings that sp
To add tabs in the gui to visualize the resulting RFs, add this in your `ConfigGUI` (note also adding a tab to visualize the input Image that is being presented to the network):
```Go
tg := ss.GUI.TabView.AddNewTab(tensorview.KiT_TensorGrid, "Image").(*tensorview.TensorGrid)
tg := ss.GUI.TabView.AddNewTab(tensorcore.KiT_TensorGrid, "Image").(*tensorcore.TensorGrid)
tg.SetStretchMax()
ss.GUI.SetGrid("Image", tg)
tg.SetTensor(&ss.TrainEnv.Vis.ImgTsr)
Expand Down
2 changes: 1 addition & 1 deletion elog/stditems.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func (lg *Logs) RunStats(stats ...string) {
lt := lg.TableDetailsScope(sk)
ix, _ := lt.NamedIndexView("RunStats")

spl := split.GroupBy(ix, []string{"RunName"})
spl := split.GroupBy(ix, "RunName")
for _, st := range stats {
split.DescColumn(spl, st)
}
Expand Down
20 changes: 10 additions & 10 deletions estats/plots.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@
package estats

import (
"cogentcore.org/core/plot/plotview"
"cogentcore.org/core/plot/plotcore"
"cogentcore.org/core/tensor/stats/clust"
"cogentcore.org/core/tensor/stats/metric"
"cogentcore.org/core/tensor/stats/simat"
"cogentcore.org/core/tensor/table"
)

func ConfigPCAPlot(plt *plotview.PlotView, dt *table.Table, nm string) {
func ConfigPCAPlot(plt *plotcore.PlotEditor, dt *table.Table, nm string) {
plt.Params.Title = nm
col1 := dt.ColumnName(1)
plt.Params.XAxisColumn = col1
plt.SetTable(dt)
plt.Params.Lines = false
plt.Params.Points = true
// order of params: on, fixMin, min, fixMax, max
plt.SetColParams(dt.ColumnName(0), plotview.On, plotview.FloatMin, 0, plotview.FloatMax, 0)
plt.SetColParams(col1, plotview.Off, plotview.FloatMin, -3, plotview.FloatMax, 3)
plt.SetColParams(dt.ColumnName(2), plotview.On, plotview.FloatMin, -3, plotview.FloatMax, 3)
plt.SetColParams(dt.ColumnName(0), plotcore.On, plotcore.FloatMin, 0, plotcore.FloatMax, 0)
plt.SetColParams(col1, plotcore.Off, plotcore.FloatMin, -3, plotcore.FloatMax, 3)
plt.SetColParams(dt.ColumnName(2), plotcore.On, plotcore.FloatMin, -3, plotcore.FloatMax, 3)
}

// ClustPlot does one cluster plot on given table column name
// and label name
func ClustPlot(plt *plotview.PlotView, ix *table.IndexView, colNm, lblNm string) {
func ClustPlot(plt *plotcore.PlotEditor, ix *table.IndexView, colNm, lblNm string) {
nm, _ := ix.Table.MetaData["name"]
smat := &simat.SimMat{}
smat.TableCol(ix, colNm, lblNm, false, metric.Euclidean64)
pt := &table.Table{}
clust.Plot(pt, clust.Glom(smat, clust.ContrastDist), smat)
plt.InitName(plt, colNm)
plt.Name = colNm
plt.Params.Title = "Cluster Plot of: " + nm + " " + colNm
plt.Params.XAxisColumn = "X"
plt.SetTable(pt)
// order of params: on, fixMin, min, fixMax, max
plt.SetColParams("X", plotview.Off, plotview.FixMin, 0, plotview.FloatMax, 0)
plt.SetColParams("Y", plotview.On, plotview.FixMin, 0, plotview.FloatMax, 0)
plt.SetColParams("Label", plotview.On, plotview.FixMin, 0, plotview.FloatMax, 0)
plt.SetColParams("X", plotcore.Off, plotcore.FixMin, 0, plotcore.FloatMax, 0)
plt.SetColParams("Y", plotcore.On, plotcore.FixMin, 0, plotcore.FloatMax, 0)
plt.SetColParams("Label", plotcore.On, plotcore.FixMin, 0, plotcore.FloatMax, 0)
}
14 changes: 7 additions & 7 deletions estats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"fmt"

"cogentcore.org/core/base/timer"
"cogentcore.org/core/plot/plotview"
"cogentcore.org/core/plot/plotcore"
"cogentcore.org/core/tensor"
"cogentcore.org/core/tensor/stats/pca"
"cogentcore.org/core/tensor/stats/simat"
Expand Down Expand Up @@ -42,7 +42,7 @@ type Stats struct {
SimMats map[string]*simat.SimMat

// analysis plots -- created by analysis routines
Plots map[string]*plotview.PlotView
Plots map[string]*plotcore.PlotEditor

// one PCA object can be reused for all PCA computations
PCA pca.PCA
Expand Down Expand Up @@ -75,7 +75,7 @@ func (st *Stats) Init() {
st.F64Tensors = make(map[string]*tensor.Float64)
st.IntTensors = make(map[string]*tensor.Int)
st.SimMats = make(map[string]*simat.SimMat)
st.Plots = make(map[string]*plotview.PlotView)
st.Plots = make(map[string]*plotcore.PlotEditor)
st.LinDecoders = make(map[string]*decoder.Linear)
st.SoftMaxDecoders = make(map[string]*decoder.SoftMax)
st.Timers = make(map[string]*timer.Time)
Expand Down Expand Up @@ -385,12 +385,12 @@ func (st *Stats) SimMat(name string) *simat.SimMat {
return sm
}

// Plot returns an plotview.PlotView of given name, creating if not yet made
func (st *Stats) Plot(name string) *plotview.PlotView {
// Plot returns an plotcore.PlotEditor of given name, creating if not yet made
func (st *Stats) Plot(name string) *plotcore.PlotEditor {
pl, has := st.Plots[name]
if !has {
pl = &plotview.PlotView{}
pl.InitName(pl, name) // any Ki obj needs this
pl = plotcore.NewPlotEditor()
pl.Name = name // any Ki obj needs this
st.Plots[name] = pl
}
return pl
Expand Down
Loading

0 comments on commit 92661e7

Please sign in to comment.