Main Content

yscale

Set training plot y-axis scale (linear or logarithmic)

Since R2024a

    Description

    yscale(monitor,axesName,scale) specifies the y-axis scale as linear or logarithmic in the axes specified by axesName. Specify scale as "linear" or "log".

    Note

    To switch the y-axis scale, you can also click the log scale button in the axes toolbar.

    Axes toolbar with a button to turn on log scale for the y-axis.

    example

    Examples

    collapse all

    Use a TrainingProgressMonitor object to track training progress and produce training plots for custom training loops.

    Create a TrainingProgressMonitor object. The monitor automatically tracks the start time and the elapsed time. The timer starts when you create the object.

    Tip

    To ensure that the elapsed time accurately reflects the training time, make sure you create the TrainingProgressMonitor object close to the start of your custom training loop.

    monitor = trainingProgressMonitor;

    Before you start the training, specify names for the information and metric values.

    monitor.Info = ["LearningRate","Epoch","Iteration"];
    monitor.Metrics = ["TrainingLoss","ValidationLoss","TrainingAccuracy","ValidationAccuracy"];

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

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

    Specify a logarithmic scale for the loss. You can also switch the y-axis scale by clicking the log scale button in the axes toolbar.

    yscale(monitor,"Loss","log")

    During training:

    • Evaluate the Stop property at the start of each step in your custom training loop. When you click the Stop button in the Training Progress window, the Stop property changes to 1. Training stops if your training loop exits when the Stop property is 1.

    • Update the information values. The updated values appear in the Training Progress window.

    • Record the metric values. The recorded values appear in the training plot.

    • Update the training progress percentage based on the fraction of iterations completed.

    Note

    The following example code is a template. You must edit this training loop to compute your metric and information values. For a complete example that you can run in MATLAB, see Monitor Custom Training Loop Progress During Training.

    epoch = 0;
    iteration = 0;
    
    monitor.Status = "Running";
    
    while epoch < maxEpochs && ~monitor.Stop
        epoch = epoch + 1;
    
        while hasData(mbq) && ~monitor.Stop
            iteration = iteration + 1;
    
            % Add code to calculate metric and information values.
            % lossTrain = ...
    
           updateInfo(monitor, ...
                LearningRate=learnRate, ...
                Epoch=string(epoch) + " of " + string(maxEpochs), ...
                Iteration=string(iteration) + " of " + string(numIterations));
    
           recordMetrics(monitor,iteration, ...
                TrainingLoss=lossTrain, ...
                TrainingAccuracy=accuracyTrain, ...
                ValidationLoss=lossValidation, ...
                ValidationAccuracy=accuracyValidation);
    
            monitor.Progress = 100*iteration/numIterations;
        end
    end

    The Training Progress window shows animated plots of the metrics, as well as the information values, training progress bar, and elapsed time.

    Training Progress window. The first plot shows the training and validation loss and the second plot shows the training and validation accuracy.

    Use an experiments.Monitor object 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"]);

    Specify a logarithmic scale for the loss. You can also switch the y-axis scale by clicking the log scale button in the axes toolbar.

    yscale(monitor,"Loss","log")

    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 = 100 * (iteration/numIterations);

    Input Arguments

    collapse all

    Metric monitor, specified as a TrainingProgressMonitor or an experiments.Monitor object.

    Name of plot axes, specified as a string or a character array. The name of the axes must match the name of a metric. If you use the groupSubPlot function to group metrics, then axesName must be the name of the group.

    Data Types: char | string

    Axis scale, specified as one of these values.

    ValueDescriptionExample
    "linear"

    Linear scale

    Axis with the scale set to "linear". The tick values that start at 0 and increment by adding 100 to the previous value.

    "log"

    Log scale

    Note

    When you specify a logarithmic scale, the axes might exclude coordinates in some cases:

    • If the coordinates include positive and negative values, only the positive values are displayed.

    • If the coordinates are all negative, all of the values are displayed on a logarithmic scale with the appropriate sign.

    • Zero values are not displayed.

    Axis with the scale set to "log". The tick values start at 1 (10 raised to 0). Each major tick value increases by a factor of 10.

    Version History

    Introduced in R2024a