margaid

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package margaid implements automatic plotting of all metrics registered in a trainer, using the Margaid library (https://github.com/erkkah/margaid/) to draw SVG, and GoNB (https://github.com/janpfeifer/gonb/) to display it in a Jupyter Notebook.

Example usage:

```go

```

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Plot

type Plot struct {
	MetricType string

	// Flat maps a plot name to
	PerName map[string]*mg.Series
	// contains filtered or unexported fields
}

Plot holds the series to different metrics that share the same Y axis. They are organized per name of the metric.

func (*Plot) AddPoint

func (p *Plot) AddPoint(metricName string, step, value float64)

AddPoint adds a point for the given metric. The x-axis is given by step and the y-axis is given by value.

func (*Plot) PlotToHTML

func (p *Plot) PlotToHTML(width, height int) string

PlotToHTML all series for a metric type associated with Plot, returning the HTML code for it (which includes the SVG).

type Plots

type Plots struct {
	// Image dimensions.
	Width, Height int

	// EvalDatasets will be evaluated with `train.Trainer.Eval()` and its metrics collected.
	EvalDatasets []train.Dataset

	// Plot per metric name.
	PerMetricType map[string]*Plot
	// contains filtered or unexported fields
}

Plots holds many plots for different metrics. They are organized per "metric type", where metric type is a unit/quantity unique name. It's assumed that series of the same "metric type" can share the same Y-Axis and hence the same plot.

func New

func New(width, height int, evalDatasets ...train.Dataset) *Plots

New creates new Margaid plots structure.

It starts empty and can have the points added manually with Plots.AddPoint or automatically with Plots.Attach.

Use Plots.Plot() to actually generate the

func (*Plots) AddPoint

func (ps *Plots) AddPoint(metricName, metricType string, step, value float64)

AddPoint adds a point for the given metric. The x-axis is given by step and the y-axis is given by value.

func (*Plots) Attach

func (ps *Plots) Attach(loop *train.Loop, numPoints int)

Attach plots to the given loop, collecting metric values for plot. For each EvalDatasets given to `Plots.New()`, their metrics are evaluated and also plotted. It automatically calls Plots.Plot at the end of the loop (`loop.OnEnd()`).

func (*Plots) DynamicPlot

func (ps *Plots) DynamicPlot()

DynamicPlot will plot on a transient area that gets overwritten each time there is a new data point.

func (*Plots) DynamicUpdates

func (ps *Plots) DynamicUpdates() *Plots

DynamicUpdates configure the Plots to dynamically generate the plot as new points are included. It starts displaying the plot as soon as there are at least 3 points. It returns itself, so calls can be cascaded.

func (*Plots) Plot

func (ps *Plots) Plot()

Plot a graph for each metric type. You don't need to call this if you called Attach -- it is called automatically at the end of the loop.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL