Documentation ¶
Overview ¶
Package track provides tooling for tracking agent metrics.
Index ¶
- Variables
- func WithAggregator(aggregator Aggregator) func(TrackedValue)
- func WithDir(dir string) func(*Tracker)
- func WithIndex(index int) func(TrackedValue)
- func WithLogger(logger *log.Logger) func(*Tracker)
- func WithNamespace(namespace string) func(TrackedValue)
- type Aggregable
- type AggregableSlices
- type Aggregables
- type AggregatedValue
- type AggregatedValues
- type Aggregates
- type Aggregator
- type AggregatorName
- type ChainAggregator
- type Chartjs
- type ChartjsXY
- type ChartjsXYs
- type CummulativeRangeSlicer
- type Episode
- func (e *Episode) Data() *History
- func (e *Episode) GetValue(name string) (TrackedValue, error)
- func (e *Episode) Log()
- func (e *Episode) Steps(num int) Timesteps
- func (e *Episode) TrackScalar(name string, value interface{}, opts ...TrackedValueOpt) *TrackedScalarValue
- func (e *Episode) TrackValue(name string, value interface{}, opts ...TrackedValueOpt) TrackedValue
- type EpisodeHistories
- type Episodes
- type EpisodicSlicer
- type HistoricalValue
- type HistoricalValues
- type Histories
- type History
- type MaxAggregator
- type MeanAggregator
- type ModeAggregator
- type Slicer
- type Timestep
- type Timesteps
- type TrackedNodeValue
- type TrackedScalarValue
- func (t *TrackedScalarValue) Aggregator() Aggregator
- func (t *TrackedScalarValue) Data(episode, timestep int) *HistoricalValue
- func (t *TrackedScalarValue) Get() interface{}
- func (t *TrackedScalarValue) Inc(amount interface{})
- func (t *TrackedScalarValue) Name() string
- func (t *TrackedScalarValue) Print()
- func (t *TrackedScalarValue) Scalar() float64
- func (t *TrackedScalarValue) Set(v interface{})
- type TrackedValue
- type TrackedValueOpt
- type Tracker
- func (t *Tracker) AggregateValuesHandler(w http.ResponseWriter, req *http.Request)
- func (t *Tracker) AggregatorsHandler(w http.ResponseWriter, req *http.Request)
- func (t *Tracker) ApplyHandlers(mux *http.ServeMux)
- func (t *Tracker) Clear() error
- func (t *Tracker) Data() *History
- func (t *Tracker) GetEpisodeHistories() (EpisodeHistories, error)
- func (t *Tracker) GetHistory(name string) (HistoricalValues, error)
- func (t *Tracker) GetHistoryAll() ([]HistoricalValues, error)
- func (t *Tracker) GetValue(name string) (TrackedValue, error)
- func (t *Tracker) IncValue(name string, scalar interface{}) error
- func (t *Tracker) LogStep(episode, timestep int) error
- func (t *Tracker) MakeEpisodes(num int) Episodes
- func (t *Tracker) PrintAll()
- func (t *Tracker) PrintHistoryAll() error
- func (t *Tracker) PrintValue(name string)
- func (t *Tracker) TrackValue(name string, value interface{}, opts ...TrackedValueOpt) TrackedValue
- func (t *Tracker) ValueNames() []string
- func (t *Tracker) ValuesHandler(w http.ResponseWriter, req *http.Request)
- func (t *Tracker) Write() error
- func (t *Tracker) ZeroValue(name string) error
- type TrackerOpt
Constants ¶
This section is empty.
Variables ¶
var AggregatorNames = []AggregatorName{MeanAggregatorName, ModeAggregatorName, MaxAggregatorName}
AggregatorNames holds all of the current aggregator names.
var DefaultCummulativeSlicer = &CummulativeRangeSlicer{back: 100, start: 0, end: -1}
DefaultCummulativeSlicer is the default slicer for cummulative slices.
var DefaultRateAggregator = NewMeanAggregator(DefaultCummulativeSlicer)
DefaultRateAggregator is a default aggregator to take the rate of a value, uses the mean of the last 100 episodes.
var Max = &MaxAggregator{SingleEpisodeSlicer}
Max aggregator.
var Mean = &MeanAggregator{SingleEpisodeSlicer}
Mean aggregator.
var Mode = &ModeAggregator{SingleEpisodeSlicer}
Mode aggregator.
var SingleEpisodeSlicer = &EpisodicSlicer{}
SingleEpisodeSlicer slices all historical data by single epidodes.
Functions ¶
func WithAggregator ¶
func WithAggregator(aggregator Aggregator) func(TrackedValue)
WithAggregator sets an aggregator to use with the value. Default to MeanAggregator.
func WithIndex ¶
func WithIndex(index int) func(TrackedValue)
WithIndex sets an index to use if the given value is non scalar. Defaults to 0.
func WithLogger ¶
WithLogger adds a logger to the tracker.
func WithNamespace ¶
func WithNamespace(namespace string) func(TrackedValue)
WithNamespace adds a namespace to the tracked value.
Types ¶
type Aggregable ¶
type Aggregable interface { // Scalar value. Scalar() float64 // Ep is the episode for this value. // Note: this is shortened to deal with name conflicts. Ep() int }
Aggregable is a value that can be aggregated.
type AggregableSlices ¶
type AggregableSlices map[int]Aggregables
AggregableSlices are slices of historical values.
func (AggregableSlices) Sort ¶
func (h AggregableSlices) Sort() []Aggregables
Sort the historical value slices returning an ordered list.
type AggregatedValue ¶
type AggregatedValue struct {
// contains filtered or unexported fields
}
AggregatedValue is an aggregated value.
func (*AggregatedValue) Ep ¶
func (a *AggregatedValue) Ep() int
Ep is the episode this value is linked to.
type AggregatedValues ¶
type AggregatedValues []AggregatedValue
AggregatedValues is a slice of aggregated value.
type Aggregates ¶
type Aggregates struct {
// contains filtered or unexported fields
}
Aggregates are generic aggregated values.
func NewAggregates ¶
func NewAggregates(xLabel, yLabel string) *Aggregates
NewAggregates returns a new aggregates.
func (Aggregates) Chartjs ¶
func (a Aggregates) Chartjs() *Chartjs
Chartjs returns the data for a ChartJS chart.
func (Aggregates) ChartjsXYs ¶
func (a Aggregates) ChartjsXYs() ChartjsXYs
ChartjsXYs returns the episode aggregates as gonum xy pairs.
func (Aggregates) GonumXYs ¶
func (a Aggregates) GonumXYs() plotter.XYs
GonumXYs returns the episode aggregates as gonum xy pairs.
type Aggregator ¶
type Aggregator interface { // Aggregate the values. Aggregate(vals Aggregables) *Aggregates }
Aggregator aggregates historical values into a single value.
func AggregatorFromName ¶
func AggregatorFromName(name string) (Aggregator, error)
AggregatorFromName returns an aggregator from its name.
type AggregatorName ¶
type AggregatorName string
AggregatorName is the name of an aggregator.
const ( // MeanAggregatorName is the name of the mean aggregator. MeanAggregatorName AggregatorName = "mean" // ModeAggregatorName is the name of the mode aggregator. ModeAggregatorName AggregatorName = "mode" // MaxAggregatorName is the name of the max aggregator. MaxAggregatorName AggregatorName = "max" )
type ChainAggregator ¶
type ChainAggregator struct {
// contains filtered or unexported fields
}
ChainAggregator is a chain of aggregators.
func NewChainAggregator ¶
func NewChainAggregator(aggregators ...Aggregator) *ChainAggregator
NewChainAggregator returns a new chain aggregator.
func (*ChainAggregator) Aggregate ¶
func (c *ChainAggregator) Aggregate(vals Aggregables) (retVal *Aggregates)
Aggregate the values.
type Chartjs ¶
type Chartjs struct { // XLabel is the label for the x values. XLabel string `json:"xLabel"` // YLabel is the label for the y values. YLabel string `json:"yLabel"` // XYS are the xy values. XYs ChartjsXYs `json:"xys"` }
Chartjs is a ChartJS chart.
type ChartjsXYs ¶
type ChartjsXYs []ChartjsXY
ChartjsXYs conforms to the expected set of point data structure for chartjs charts.
type CummulativeRangeSlicer ¶
type CummulativeRangeSlicer struct {
// contains filtered or unexported fields
}
CummulativeRangeSlicer slices cummulative episodes i.e. each slice will contain the current episode plus however many episodes back are specified.
func NewCummulativeRangeSlicer ¶
func NewCummulativeRangeSlicer(back, start, end int) *CummulativeRangeSlicer
NewCummulativeRangeSlicer returns a new cummulative slicer.
func (*CummulativeRangeSlicer) Label ¶
func (e *CummulativeRangeSlicer) Label() string
Label applied to slice.
func (*CummulativeRangeSlicer) Slice ¶
func (e *CummulativeRangeSlicer) Slice(vals Aggregables) AggregableSlices
Slice the values.
type Episode ¶
type Episode struct { I int Values map[string]TrackedValue // contains filtered or unexported fields }
Episode represents a training episode.
func (*Episode) GetValue ¶
func (e *Episode) GetValue(name string) (TrackedValue, error)
GetValue a tracked value by name.
func (*Episode) TrackScalar ¶
func (e *Episode) TrackScalar(name string, value interface{}, opts ...TrackedValueOpt) *TrackedScalarValue
TrackScalar tracks a scarlar value for only an episode.
func (*Episode) TrackValue ¶
func (e *Episode) TrackValue(name string, value interface{}, opts ...TrackedValueOpt) TrackedValue
TrackValue tracks a value for only an episode.
type EpisodeHistories ¶
EpisodeHistories is a history of episodes
type EpisodicSlicer ¶
type EpisodicSlicer struct{}
EpisodicSlicer slices episodes.
func NewEpisodicSlicer ¶
func NewEpisodicSlicer() *EpisodicSlicer
NewEpisodicSlicer returns a new episodic slicer.
func (*EpisodicSlicer) Slice ¶
func (e *EpisodicSlicer) Slice(vals Aggregables) AggregableSlices
Slice the values.
type HistoricalValue ¶
type HistoricalValue struct { // Name of the value. Name string `json:"name"` // TrackedValue of the value. TrackedValue float64 `json:"value"` // Timestep at which the value occurred. Timestep int `json:"timestep"` // Episode at which the value occurred. Episode int `json:"episode"` }
HistoricalValue is a historical value.
func (*HistoricalValue) Ep ¶
func (h *HistoricalValue) Ep() int
Ep is the episode in which value occurred.
type HistoricalValues ¶
type HistoricalValues []*HistoricalValue
HistoricalValues is a slice of historical values.
func (HistoricalValues) Aggregables ¶
func (h HistoricalValues) Aggregables() Aggregables
Aggregables returns the values as aggregables.
func (HistoricalValues) Aggregate ¶
func (h HistoricalValues) Aggregate(aggregator Aggregator) *Aggregates
Aggregate the values.
func (HistoricalValues) Scalar ¶
func (h HistoricalValues) Scalar() []float64
Scalar of the historical values.
type History ¶
type History struct { // Values in the history. Values []*HistoricalValue `json:"values"` // Timestep of this history. Timestep int `json:"timestep"` // Episode of this history. Episode int `json:"episode"` }
History is the historical representation of a set of tracked values.
func (*History) Get ¶
func (h *History) Get(name string) HistoricalValues
Get the value history with the given name.
type MaxAggregator ¶
type MaxAggregator struct{ Slicer }
MaxAggregator returns the max of the historical values.
func NewMaxAggregator ¶
func NewMaxAggregator(slicer Slicer) *MaxAggregator
NewMaxAggregator returns a new max aggregator.
func (*MaxAggregator) Aggregate ¶
func (m *MaxAggregator) Aggregate(vals Aggregables) *Aggregates
Aggregate the values.
type MeanAggregator ¶
type MeanAggregator struct{ Slicer }
MeanAggregator returns the mean of the historical values.
func NewMeanAggregator ¶
func NewMeanAggregator(slicer Slicer) *MeanAggregator
NewMeanAggregator returns a new mode aggregator.
func (*MeanAggregator) Aggregate ¶
func (m *MeanAggregator) Aggregate(vals Aggregables) *Aggregates
Aggregate the values.
type ModeAggregator ¶
type ModeAggregator struct{ Slicer }
ModeAggregator returns the most common of the historical values.
func NewModeAggregator ¶
func NewModeAggregator(slicer Slicer) *ModeAggregator
NewModeAggregator returns a new mode aggregator.
func (*ModeAggregator) Aggregate ¶
func (m *ModeAggregator) Aggregate(vals Aggregables) *Aggregates
Aggregate the values.
type Slicer ¶
type Slicer interface { // Slice the data. Slice(vals Aggregables) AggregableSlices // Label for these slices of data. Label() string }
Slicer slices historical data into chunks that are then aggregated.
type Timestep ¶
type Timestep struct { I int // contains filtered or unexported fields }
Timestep represents a training timestep.
type TrackedNodeValue ¶
type TrackedNodeValue struct {
// contains filtered or unexported fields
}
TrackedNodeValue is a tracked node value.
func NewTrackedNodeValue ¶
func NewTrackedNodeValue(name string, opts ...TrackedValueOpt) *TrackedNodeValue
NewTrackedNodeValue returns a new tracked value.
func (*TrackedNodeValue) Aggregator ¶
func (t *TrackedNodeValue) Aggregator() Aggregator
Aggregator returns the aggregator for this value.
func (*TrackedNodeValue) Data ¶
func (t *TrackedNodeValue) Data(episode, timestep int) *HistoricalValue
Data converts the value to a historical value.
type TrackedScalarValue ¶
type TrackedScalarValue struct {
// contains filtered or unexported fields
}
TrackedScalarValue is a tracked value that can be convertible to float64.
func NewTrackedScalarValue ¶
func NewTrackedScalarValue(name string, value interface{}, opts ...TrackedValueOpt) *TrackedScalarValue
NewTrackedScalarValue returns a new tracked value.
func (*TrackedScalarValue) Aggregator ¶
func (t *TrackedScalarValue) Aggregator() Aggregator
Aggregator returns the aggregator for this value.
func (*TrackedScalarValue) Data ¶
func (t *TrackedScalarValue) Data(episode, timestep int) *HistoricalValue
Data takes the current tracked value and returns a historical value.
func (*TrackedScalarValue) Inc ¶
func (t *TrackedScalarValue) Inc(amount interface{})
Inc increments value.
type TrackedValue ¶
type TrackedValue interface { // Name of the value. Name() string // Scalar value. Scalar() float64 // Print the value. Print() // Data converts the value to a historical value. Data(episode, timestep int) *HistoricalValue // Aggregator is the aggregator for this value. Aggregator() Aggregator }
TrackedValue is a value being tracked.
type TrackedValueOpt ¶
type TrackedValueOpt func(TrackedValue)
TrackedValueOpt is an option for a tracked value.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker is a means of tracking values on a graph.
func NewTracker ¶
func NewTracker(opts ...TrackerOpt) (*Tracker, error)
NewTracker returns a new tracker for a graph.
func (*Tracker) AggregateValuesHandler ¶
func (t *Tracker) AggregateValuesHandler(w http.ResponseWriter, req *http.Request)
AggregateValuesHandler is an HTTP handler for the tracker serving aggregates.
func (*Tracker) AggregatorsHandler ¶
func (t *Tracker) AggregatorsHandler(w http.ResponseWriter, req *http.Request)
AggregatorsHandler returns all possible aggregators.
func (*Tracker) ApplyHandlers ¶
ApplyHandlers applies tracker handlers to a mux.
func (*Tracker) GetEpisodeHistories ¶
func (t *Tracker) GetEpisodeHistories() (EpisodeHistories, error)
GetEpisodeHistories returns the episode history.
func (*Tracker) GetHistory ¶
func (t *Tracker) GetHistory(name string) (HistoricalValues, error)
GetHistory gets all the history for a value.
func (*Tracker) GetHistoryAll ¶
func (t *Tracker) GetHistoryAll() ([]HistoricalValues, error)
GetHistoryAll gets the history of all values.
func (*Tracker) GetValue ¶
func (t *Tracker) GetValue(name string) (TrackedValue, error)
GetValue a tracked value by name.
func (*Tracker) LogStep ¶
LogStep logs tracked values to store for the given timestep. TODO: make time more pluggable so this can be used in other environments.
func (*Tracker) MakeEpisodes ¶
MakeEpisodes creates a number of episodes.
func (*Tracker) PrintHistoryAll ¶
PrintHistoryAll prints the history of all values.
func (*Tracker) TrackValue ¶
func (t *Tracker) TrackValue(name string, value interface{}, opts ...TrackedValueOpt) TrackedValue
TrackValue tracks a graph node or any other scalar value.
func (*Tracker) ValueNames ¶
ValueNames is the name for all values.
func (*Tracker) ValuesHandler ¶
func (t *Tracker) ValuesHandler(w http.ResponseWriter, req *http.Request)
ValuesHandler is an HTTP handler for revealing what values are tracked over the network.