Main Content

recordMetrics

Record metric values in experiment results table and training plot

    Description

    recordMetrics(monitor,xValue,metricName=yValue)records the specified metric value for a trial in theExperiment Managerresults table and training plot.

    example

    recordMetrics(monitor,xValue,metricName1=yValue1,...,metricNameN=yValueN)records multiple metric values for a trial.

    example

    recordMetrics(monitor,xValue,structure)records the metric values specified by the structurestructure.

    Examples

    collapse all

    Use anexperiments.Monitorobject to track the progress of the training, display information and metric values in the experiment results table, and produce training plots for custom training experiments.

    Before starting the training, specify the names of the information and metric columns of the Experiment Manager results table.

    monitor.Info = ["GradientDecayFactor","SquaredGradientDecayFactor"]; monitor.Metrics = ["TrainingLoss","ValidationLoss"];

    Specify the horizontal axis label for the training plot. Group the training and validation loss in the same subplot.

    monitor.XLabel ="Iteration"; groupSubPlot(monitor,"Loss",["TrainingLoss","ValidationLoss"]);

    Update the values of the gradient decay factor and the squared gradient decay factor for the trial in the results table.

    updateInfo(monitor,...GradientDecayFactor=gradientDecayFactor,...SquaredGradientDecayFactor=squaredGradientDecayFactor);

    After each iteration of the custom training loop, record the value of training and validation loss for the trial in the results table and the training plot.

    recordMetrics(monitor,iteration,...TrainingLoss=trainingLoss,...ValidationLoss=validationLoss);

    Update the training progress for the trial based on the fraction of iterations completed.

    monitor.Progress = (iteration/numIterations) * 100;

    Use a structure to record metric values in the results table and the training plot.

    structure.TrainingLoss = trainingLoss; structure.ValidationLoss = validationLoss); recordMetrics(monitor,iteration,structure);

    Input Arguments

    collapse all

    Experiment monitor for the trial, specified as anexperiments.Monitorobject. When you run a custom training experiment, Experiment Manager passes this object as the second input argument of the training function.

    x-coordinate for the training plot, specified as a numeric scalar. Use this value to record the custom training loop iteration or epoch number for your data points.

    Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|fi

    指标名称,指定为一个年代tring or character vector. This name must be an element of theMetricsproperty of theexperiments.Monitorobjectmonitor.

    Data Types:char|string

    Metric value, specified as a numeric scalar. Experiment Manager uses this value as the y-coordinate for the training plot.

    Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|fi

    Metric names and values, specified as astructure. Names must be elements of theMetricsproperty of theexperiments.Monitorobjectmonitorand can appear in any order in the structure.

    Example:struct(TrainingLoss=trainingLoss,ValidationLoss=validationLoss)

    Data Types:struct

    Tips

    • Both information and metric columns display values in the results table for your experiment. Additionally, the training plot shows a record of the metric values. Use information columns for text and for numerical values that you want to display in the results table but not in the training plot.

    • Use thegroupSubPlotfunction to define your training subplots before calling the functionrecordMetrics.

    Version History

    Introduced in R2021a