Dont need to save 'savedAgentResultStruct' with RL agent
2 次查看(过去 30 天)
显示 更早的评论
When I am saving agents during RL iterations using 'EpisodeReward' criteria, matlab is also saving 'savedAgentResultStruct' along with the agent which is increasing the file size. Is there any option to turn off saving the 'savedAgentResultStruct' file.
Thanks
4 个评论
M.Y. C.
2021-3-5
编辑:M.Y. C.
2021-3-5
Unfortunately, there is no direct solution. Luckily, I found an indirect solution by manipulating reset function. My code includes getlatestfile.m function but not in function format. You may find the related code below, copy & paste the code as localResetFcn(in). The code takes apart your 'Agent__.mat' file into 2 .mat files: 'Agent__.mat' and 'savedAgentResultStruct.mat'. 'Agent__.mat' file contains only trained agent at given iteration. On the other hand, 'savedAgentResultStruct.mat' file is overwritten at every iteration. My code is not optimized, so you should set 'SaveAgentValue' at rlTrainingOptions to '-inf'. If you optimized the code, please share under this question.
function in = localResetFcn(in)
persistent a
if ~isempty(a)
%This function returns the latest file from the directory passsed as input
%argument
%Get the directory contents
dirc = dir('savedAgents');
%Filter out all the folders.
dirc = dirc(find(~cellfun(@isdir,{dirc(:).name})));
%I contains the index to the biggest number which is the latest file
[A,I] = max([dirc(:).datenum]);
if ~isempty(I)
latestfile = dirc(I).name;
% Simplify agent
FileName = latestfile
FolderName = 'savedAgents';
File = fullfile(FolderName, FileName)
load(File)
ResultFile = fullfile(FolderName, 'savedAgentResultStruct')
save(ResultFile,'savedAgentResultStruct')
save(File, 'saved_agent','-mat')
end
end
a = 1;
% Define random inital values as your simulation requires.
end
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!