main content

store data in the internal memory of a (file or monitor) logger object -凯发k8网页登录

store data in the internal memory of a (file or monitor) logger object

since r2022b

description

example

store(lgr,context,data,iter) stores data into lgr internal memory, grouped in a variable named context and associated with iteration iter.

examples

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

data logger object, specified as either a filelogger or a monitorlogger object.

name of the saved variable, specified as either a string or character vector. all data associated with iteration iter and the name context is vertically concatenated in a single matlab® variable named context. this variable is then written to the logger target (either a mat-file or a trainingprogressmonitor object) when write is invoked for lgr.

data to be saved, specified as any fundamental matlab datatype. data associated with the same iteration and the same context name is grouped in a single variable.

iteration number, specified as a positive integer. when store is executed multiple times with the same iteration number, data is appended to the memory entry for that iteration. this memory entry, which can contain several context variables, is then written to the logger target as a single unit (for example as a single mat-file) when write is invoked for lgr.

version history

introduced in r2022b

网站地图