Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions cmd/tablecat/tablecat.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,9 @@ func AvgCat(files []string) {
fmt.Println("No files or files are empty, exiting")
return
}
// todo: need meantables
// avgdt := stats.MeanTables(dts)
// tensor.SetPrecision(avgdt, LogPrec)
// avgdt.SaveCSV(core.Filename(Output), tensor.Tab, table.Headers)
avgdt := stats.MeanTables(dts)
tensor.SetPrecision(avgdt, LogPrec)
avgdt.SaveCSV(core.Filename(Output), tensor.Tab, table.Headers)
}

// AvgByColumn computes average by given column for given files
Expand Down
2 changes: 1 addition & 1 deletion docs/content/tensorfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ There are also a few other variants of the `Value` functionality:
* `ValueType` takes a `reflect.Kind` arg for the data type, which can then be a variable.
* `SetTensor` sets a tensor to a node of given name, creating the node if needed. This is also available as the `Set` method on a directory node.

`DirTable` returns a [[table]] with all the tensors under a given directory node, which can then be used for making plots or doing other forms of data analysis. This works best when each tensor has the same outer-most row dimension. The table is persistent and very efficient, using direct pointers to the underlying tensor values.
`tensorfs.DirTable` returns a [[table]] with all the tensors under a given directory node, which can then be used for making plots or doing other forms of data analysis. This works best when each tensor has the same outer-most row dimension. The table is persistent and very efficient, using direct pointers to the underlying tensor values.

## Directories

Expand Down
9 changes: 9 additions & 0 deletions examples/simmer/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions examples/simmer/config.goal
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ type FilterResults struct {
// File name contains this string, e.g., "_epoch" or "_run"
FileContains string `width:"60"`

// extension of files, e.g., .tsv
// extension of files, e.g., .tsv
Ext string

// if true, fetch results before opening.
Fetch bool
}

func (fp *FilterResults) Defaults() {
fp.FileContains = "_epc"
fp.Ext = ".tsv"
fp.Fetch = true
}

// SubmitParams specifies the parameters for submitting a job.
Expand Down Expand Up @@ -136,7 +140,11 @@ type Configuration struct {

// Server has server parameters.
Server ServerParams


// GroupColumns are the column(s) to use for grouping result data, for PlotMean.
// e.g., Epoch for epoch-level results.
GroupColumns []string

// FetchFiles is a glob expression for files to fetch from server,
// for Fetch command. Is *.tsv by default.
FetchFiles string
Expand Down Expand Up @@ -199,6 +207,7 @@ func (cf *Configuration) Defaults() {
cf.FetchFiles = "*.tsv"
cf.Filter.Defaults()
cf.TimeFormat = "2006-01-02 15:04:05 MST"
cf.GroupColumns = []string{"Epoch"}
}

func (cf *Configuration) Update() {
Expand Down
56 changes: 56 additions & 0 deletions examples/simmer/results.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions examples/simmer/results.goal
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ package main
import (
"fmt"
"path/filepath"
"reflect"
"strings"

"cogentcore.org/core/base/fsx"
"cogentcore.org/core/core"
"cogentcore.org/core/styles"
"cogentcore.org/lab/lab"
"cogentcore.org/lab/plot"
"cogentcore.org/lab/stats/stats"
"cogentcore.org/lab/table"
"cogentcore.org/lab/tensor"
"cogentcore.org/lab/tensorfs"
)

// FindResult finds an existing result record for given job id and path,
Expand Down Expand Up @@ -86,6 +89,14 @@ func (sr *Simmer) Results() { //types:add
sr.Config.Filter.Ext = ".tsv"
}
lab.PromptStruct(sr, &sr.Config.Filter, "Open results data for files", func() {
if sr.Config.Filter.Fetch {
core.MessageSnackbar(sr, "Fetching jobs..")
for _, jid := range jobs {
sr.FetchJob(jid, false)
}
core.MessageSnackbar(sr, "Fetch Jobs completed")
sr.UpdateSims()
}
sr.OpenResultFiles(jobs, sr.Config.Filter)
})
}
Expand Down Expand Up @@ -140,6 +151,51 @@ func (sr *Simmer) Plot() { //types:add
ts.PlotTable("Plot", AggTable)
}

// PlotMean concatenates selected Results data files and generates a plot
// of the resulting data, computing the mean over the values in
// [Config.GroupColumns] to group values (e.g., across Epochs).
func (sr *Simmer) PlotMean() { //types:add
ts := sr.Tabs.AsLab()
tv := sr.ResultsTableView
jis := tv.SelectedIndexesList(false)
if len(jis) == 0 {
fmt.Println("No Results rows selected")
return
}
nc := len(sr.Config.GroupColumns)
rdir := "Stats/" + sr.Config.GroupColumns[nc-1] // results dir
var AggTable *table.Table
for _, i := range jis {
res := sr.ResultsList[i]
jid := res.JobID
label := res.Label
dir, _ := tensorfs.NewDir("root")
rdt := res.Table
stats.TableGroups(dir, rdt, sr.Config.GroupColumns...)
var fcols []string
for ci, cl := range rdt.Columns.Values {
if cl.DataType() != reflect.Float32 && cl.DataType() != reflect.Float64 {
continue
}
fcols = append(fcols, rdt.Columns.Keys[ci])
}
stats.TableGroupStats(dir, stats.StatMean, rdt, fcols...)
edir := dir.Dir(rdir)
sdt := tensorfs.DirTable(edir, nil)
dt := sdt.InsertKeyColumns("JobID", jid, "JobLabel", label) // this clones the table
if AggTable == nil {
AggTable = dt
plot.SetFirstStyler(dt.Columns.Values[0], func(s *plot.Style) {
s.Role = plot.Split
s.On = true
})
} else {
AggTable.AppendRows(dt)
}
}
ts.PlotTable("Plot", AggTable)
}

func (sr *Simmer) styleResults() {
tv := sr.ResultsTableView
tv.ShowIndexes = true
Expand Down
3 changes: 3 additions & 0 deletions examples/simmer/simmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ func (sr *Simmer) MakeToolbar(p *tree.Plan) {
tree.Add(p, func(w *core.FuncButton) {
w.SetFunc(sr.Plot).SetIcon(icons.ShowChart)
})
tree.Add(p, func(w *core.FuncButton) {
w.SetFunc(sr.PlotMean).SetIcon(icons.ShowChart)
})
tree.Add(p, func(w *core.FuncButton) {
w.SetFunc(sr.Cancel).SetIcon(icons.Refresh)
})
Expand Down
Loading