Skip to content

Commit

Permalink
elog.AddStdAggs adds standard aggregation for a given item. key helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Apr 19, 2024
1 parent 8348f60 commit 81369d6
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions elog/stditems.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ func (lg *Logs) AddCounterItems(ctrs ...etime.Times) {
}
}

// AddStdAggs adds standard aggregation items for times up to the penultimate
// time step provided, for given stat item that was created for the final timescale.
func (lg *Logs) AddStdAggs(itm *Item, mode etime.Modes, times []etime.Times) {
ntimes := len(times)
for i := ntimes - 2; i >= 0; i-- {
tm := times[i]
if tm == etime.Run || tm == etime.Condition {
itm.Write[etime.Scope(mode, tm)] = func(ctx *Context) {
ix := ctx.LastNRows(ctx.Mode, times[i+1], 5) // cached
ctx.SetFloat64(agg.Mean(ix, ctx.Item.Name)[0])
}
} else {
itm.Write[etime.Scope(mode, times[i])] = func(ctx *Context) {
ctx.SetAgg(ctx.Mode, times[i+1], agg.AggMean)
}
}
}
}

// AddStatAggItem adds a Float64 stat that is aggregated
// with agg.Mean across the given time scales,
// ordered from higher to lower, e.g., Run, Epoch, Trial.
Expand All @@ -61,20 +80,7 @@ func (lg *Logs) AddStatAggItem(statName string, times ...etime.Times) *Item {
etime.Scope(etime.AllModes, times[ntimes-1]): func(ctx *Context) {
ctx.SetFloat64(ctx.Stats.Float(statName))
}}})
for i := ntimes - 2; i >= 0; i-- {
i := i
tm := times[i]
if tm == etime.Run || tm == etime.Condition {
itm.Write[etime.Scope(etime.Train, tm)] = func(ctx *Context) {
ix := ctx.LastNRows(ctx.Mode, times[i+1], 5) // cached
ctx.SetFloat64(agg.Mean(ix, ctx.Item.Name)[0])
}
} else {
itm.Write[etime.Scope(etime.AllModes, times[i])] = func(ctx *Context) {
ctx.SetAgg(ctx.Mode, times[i+1], agg.AggMean)
}
}
}
lg.AddStdAggs(itm, etime.AllModes, times)
return itm
}

Expand Down

0 comments on commit 81369d6

Please sign in to comment.