Skip to content

Commit

Permalink
convenience methods for misc plots and tables; use new xyz text rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Aug 23, 2024
1 parent 2fdedc8 commit 0b16fb3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
21 changes: 20 additions & 1 deletion egui/plots.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ func (gui *GUI) AddPlots(title string, lg *elog.Logs) {
}
}

// AddMiscPlotTab adds a misc (non log-generated) plot with a new
// tab and plot of given name.
func (gui *GUI) AddMiscPlotTab(name string) *plotcore.PlotEditor {
tab := gui.Tabs.NewTab(name)
plt := plotcore.NewSubPlot(tab)
gui.SetPlotByName(name, plt)
return plt
}

func ConfigPlotFromLog(title string, plt *plotcore.PlotEditor, lg *elog.Logs, key etime.ScopeKey) {
_, times := key.ModesAndTimes()
time := times[0]
Expand Down Expand Up @@ -89,14 +98,24 @@ func (gui *GUI) PlotScope(scope etime.ScopeKey) *plotcore.PlotEditor {
return plot
}

// SetPlot stores given plot in Plots map
// PlotByName returns a misc plot by name (instead of scope key).
func (gui *GUI) PlotByName(name string) *plotcore.PlotEditor {
return gui.PlotScope(etime.ScopeKey(name))
}

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

// SetPlotByName stores given misc plot by name (instead of scope key) in Plots map.
func (gui *GUI) SetPlotByName(name string, plt *plotcore.PlotEditor) {
gui.SetPlot(etime.ScopeKey(name), plt)
}

// UpdatePlot updates plot for given mode, time scope.
// This version should be called in the GUI event loop, e.g., for direct
// updating in a toolbar action. Use [GoUpdatePlot] if being called from
Expand Down
2 changes: 1 addition & 1 deletion elog/stditems.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (lg *Logs) AddLayerTensorItems(net emer.Network, varNm string, mode etime.M
lg.AddItem(&Item{
Name: itmNm,
Type: reflect.Float32,
CellShape: cly.AsEmer().SampleShape.Sizes,
CellShape: cly.AsEmer().GetSampleShape().Sizes,
FixMin: true,
Range: minmax.F32{Max: 1},
Write: WriteMap{
Expand Down
25 changes: 25 additions & 0 deletions emer/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"compress/gzip"
"fmt"
"io"
"io/fs"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -66,6 +67,30 @@ func (nt *NetworkBase) OpenWeightsJSON(filename core.Filename) error { //types:a
}
}

// OpenWeightsFS opens network weights (and any other state that adapts with learning)
// from a JSON-formatted file, in filesystem.
// If filename has .gz extension, then file is gzip uncompressed.
func (nt *NetworkBase) OpenWeightsFS(fsys fs.FS, filename string) error {
fp, err := fsys.Open(filename)
defer fp.Close()
if err != nil {
log.Println(err)
return err
}
ext := filepath.Ext(filename)
if ext == ".gz" {
gzr, err := gzip.NewReader(fp)
defer gzr.Close()
if err != nil {
log.Println(err)
return err
}
return nt.ReadWeightsJSON(gzr)
} else {
return nt.ReadWeightsJSON(bufio.NewReader(fp))
}
}

// todo: proper error handling here!

// WriteWeightsJSON writes the weights from this network
Expand Down
1 change: 0 additions & 1 deletion netview/netview.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@ func (nv *NetView) UpdateLayers() {
txt.NetView = nv
txt.SetText(ly.StyleName())
txt.Pose.Scale = math32.Vector3Scalar(nv.Params.LayNmSize).Div(lg.Pose.Scale)
txt.Pose.RotateOnAxis(0, 1, 0, 180)
txt.Styles.Background = colors.Uniform(colors.Transparent)
txt.Styles.Text.Align = styles.Start
txt.Styles.Text.AlignV = styles.Start
Expand Down

0 comments on commit 0b16fb3

Please sign in to comment.