Main Content

write

Transfer stored data from the internal logger memory to the logging target

    Description

    example

    write(lgr) transfers all stored logging contexts into the logger's target (either a MAT file or a trainingProgressMonitor object).

    Examples

    collapse all

    This example shows how to log data to disk when training an agent using a custom training loop.

    Create a FileLogger object using rlDataLogger.

    flgr = rlDataLogger();

    Set up the logger object. This operation initializes the object performing setup tasks such as, for example, creating the directory to save the data files.

    setup(flgr);

    Within a custom training loop, you can now store data to the logger object memory and write data to file.

    For this example, store random numbers to the file logger object, grouping them in the variables Context1 and Context2. When you issue a write command, a MAT file corresponding to an iteration and containing both variables is saved with the name specified in flgr.LoggingOptions.FileNameRule, in the folder specified by flgr.LoggingOptions.LoggingDirectory.

    for iter = 1:10
    
        % Store three random numbers in memory 
        % as elements of the variable "Context1"
        for ct = 1:3
            store(flgr, "Context1", rand, iter);
        end
    
        % Store a random number in memory 
        % as the variable "Context2"
        store(flgr, "Context2", rand, iter);
    
        % Write data to file every 4 iterations
        if mod(iter,4)==0
            write(flgr);
        end
    
    end

    Clean up the logger object. This operation performs clean up tasks like for example writing to file any data still in memory.

    cleanup(flgr);

    Input Arguments

    collapse all

    Data logger object, specified as either a FileLogger or a MonitorLogger object.

    Version History

    Introduced in R2022b