Documentation
¶
Overview ¶
Package plotly uses GoNB plotly support (`github.com/janpfeifer/gonb/gonbui/plotly`) to plot both on dynamic plots while training or to quickly plot the results of a previously saved plot results in a checkpoints directory.
In either case it allows adding baseline plots of previous checkpoints.
The advantage of `plotly` over `margaid` plots is that it uses Javascript to make the plot interactive (it displays information on mouse hover).
The disadvantage is that saving of the notebook doesn't include the Javascript -- but exporting to HTML does.
See New to get started and an example.
Index ¶
- Variables
- type PlotConfig
- func (pc *PlotConfig) AddPoint(pt plots.Point)
- func (pc *PlotConfig) Dynamic() *PlotConfig
- func (pc *PlotConfig) DynamicPlot(final bool)
- func (pc *PlotConfig) DynamicSampleDone(incomplete bool)
- func (pc *PlotConfig) LoadCheckpointData(dataDirOrFile string, filters ...PointFilter) error
- func (pc *PlotConfig) Plot() error
- func (pc *PlotConfig) ScheduleEveryNSteps(loop *train.Loop, n int) *PlotConfig
- func (pc *PlotConfig) ScheduleExponential(loop *train.Loop, startStep int, stepFactor float64) *PlotConfig
- func (pc *PlotConfig) ScheduleNTimes(loop *train.Loop, numPoints int) *PlotConfig
- func (pc *PlotConfig) WithBatchNormalizationAveragesUpdate(oneEpochDS train.Dataset) *PlotConfig
- func (pc *PlotConfig) WithCheckpoint(checkpoint *checkpoints.Handler) *PlotConfig
- func (pc *PlotConfig) WithCustomMetricFn(fn plots.CustomMetricFn) *PlotConfig
- func (pc *PlotConfig) WithDatasets(datasets ...train.Dataset) *PlotConfig
- type PointFilter
Constants ¶
This section is empty.
Variables ¶
var ( // ParamPlots is the context parameter to trigger generating of plot points and // displaying them. // A boolean value that defaults to false. ParamPlots = "plots" )
Functions ¶
This section is empty.
Types ¶
type PlotConfig ¶
type PlotConfig struct {
// EvalDatasets registered to be used during evaluation when dynamically capturing points during training.
EvalDatasets []train.Dataset
// contains filtered or unexported fields
}
PlotConfig hold the configuration object that will generate the plot. Create it with New.
func New ¶
func New() *PlotConfig
New creates a new PlotConfig, that can be used to generate plots.
This is used when configuring the train.Loop, and a typical use example, triggered by a "plots" parameter, might look like:
usePlots := context.GetParamOr(ctx, plotly.ParamPlots, false)
...
if usePlots {
_ = plotly.New().
WithCheckpoint(checkpoint).
Dynamic().
WithDatasets(evalOnTrainDS, evalOnTestDS).
ScheduleExponential(loop, 200, 1.2).
WithBatchNormalizationAveragesUpdate(evalOnTrainDS)
}
func (*PlotConfig) AddPoint ¶
func (pc *PlotConfig) AddPoint(pt plots.Point)
AddPoint add one point to the plots.
Usually not called directly, instead use [LoadCheckpointData] or [Dynamic], which will attach to a training loop and call this automatically.
func (*PlotConfig) Dynamic ¶
func (pc *PlotConfig) Dynamic() *PlotConfig
Dynamic sets plot to be dynamically updated and new data comes in. It's a no-op if not running in a GoNB notebook.
It should be followed by a call to [ScheduleExponential] or [SchedulePeriodic] (or both) to schedule capturing points to plot, and [WithCheckpoint] to save the captured points.
It returns itself to allow cascading configuration method calls.
func (*PlotConfig) DynamicPlot ¶
func (pc *PlotConfig) DynamicPlot(final bool)
DynamicPlot is called everytime a new metrics comes in, if configured for dynamic updates. Usually, not called directly by the user. Simply use [Dynamic] and schedule updates and this function will be called automatically.
If `final` is true, it clears the transient area, and it plots instead in the definitive version.
func (*PlotConfig) DynamicSampleDone ¶
func (pc *PlotConfig) DynamicSampleDone(incomplete bool)
DynamicSampleDone is called after all the data points recorded for this sample (evaluation at a time step). The value `incomplete` is set to true if any of the evaluations are NaN or infinite.
If in a notebook, this would trigger a redraw of the plot.
It implements [plot.Plotter]
func (*PlotConfig) LoadCheckpointData ¶
func (pc *PlotConfig) LoadCheckpointData(dataDirOrFile string, filters ...PointFilter) error
LoadCheckpointData loads plotting data from a checkpoint path. Notice this only works if the model was trained with plotting, with the metrics saved into the file `training_plot_points.json` (plots.TrainingPlotFileName). Notice that if `dataDirOrFile` is a file it reads from that instead.
The `filters` are an optional list of filters to apply (in order) to each of the points read: it allows points to be modified arbitrarily -- in particular useful to change names (like adding a prefix) of metrics or metrics types.
Each filter can also eliminate points by returning false -- only points for which filters returned true are included.
func (*PlotConfig) Plot ¶
func (pc *PlotConfig) Plot() error
Plot all figures with current data. If not in a notebook, this is a no-op.
func (*PlotConfig) ScheduleEveryNSteps ¶
func (pc *PlotConfig) ScheduleEveryNSteps(loop *train.Loop, n int) *PlotConfig
ScheduleEveryNSteps to collect metrics.
It returns itself to allow cascading configuration method calls.
func (*PlotConfig) ScheduleExponential ¶
func (pc *PlotConfig) ScheduleExponential(loop *train.Loop, startStep int, stepFactor float64) *PlotConfig
ScheduleExponential collection of plot points, starting at `startStep` and with an increasing step factor of `stepFactor`. Typical values where could be 100 and 1.1.
It returns itself to allow cascading configuration method calls.
func (*PlotConfig) ScheduleNTimes ¶
func (pc *PlotConfig) ScheduleNTimes(loop *train.Loop, numPoints int) *PlotConfig
ScheduleNTimes of collection of plot points.
It returns itself to allow cascading configuration method calls.
func (*PlotConfig) WithBatchNormalizationAveragesUpdate ¶
func (pc *PlotConfig) WithBatchNormalizationAveragesUpdate(oneEpochDS train.Dataset) *PlotConfig
WithBatchNormalizationAveragesUpdate configures a dataset to use to update the averages (of mean and variance) for batch normalization.
The oneEpochDS dataset (typically, the same as a training data evaluation dataset) should be a 1-epoch training data dataset, and it can use evaluation batch sizes. If oneEpochDS is nil, it disabled the updating of the averages.
If the model is not using batch normalization this is a no-op and nothing is executed.
func (*PlotConfig) WithCheckpoint ¶
func (pc *PlotConfig) WithCheckpoint(checkpoint *checkpoints.Handler) *PlotConfig
WithCheckpoint uses the checkpoint both to load data points and to save any new data points. Usually, used with PlotConfig.Dynamic. If checkpoint is nil, it's a no-op.
New data-points are saved asynchronously -- not to slow down training, with the downside of potentially having I/O issues reported asynchronously.
It returns itself to allow cascading configuration method calls.
func (*PlotConfig) WithCustomMetricFn ¶
func (pc *PlotConfig) WithCustomMetricFn(fn plots.CustomMetricFn) *PlotConfig
WithCustomMetricFn registers the given function to run at every step it collects metrics. Only one function can be registered. Set to nil to reset.
It returns itself to allow cascading configuration method calls.
func (*PlotConfig) WithDatasets ¶
func (pc *PlotConfig) WithDatasets(datasets ...train.Dataset) *PlotConfig
WithDatasets configures the datasets to evaluate at each collecting step (see `Schedule*` methods).
type PointFilter ¶
PointFilter can change any plots.Point arbitrarily. If it returns false means the point should be dropped.