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
examples
log data to disk in a custom training loop
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
lgr
— date logger object
filelogger
object | monitorlogger
object | ...
data logger object, specified as either a filelogger
or a
monitorlogger
object.
context
— name of the saved variable
string
| char
vector | ...
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
— data to be saved
any fundamental matlab datatype | ...
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.
iter
— iteration number
positive integer | ...
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
打开示例
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
matlab 命令
您点击的链接对应于以下 matlab 命令:
请在 matlab 命令行窗口中直接输入以执行命令。web 浏览器不支持 matlab 命令。
select a web site
choose a web site to get translated content where available and see local events and offers. based on your location, we recommend that you select: .
you can also select a web site from the following list:
how to get best site performance
select the china site (in chinese or english) for best site performance. other mathworks country sites are not optimized for visits from your location.
americas
- (español)
- (english)
- (english)
europe
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
asia pacific
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)