Dont need to save 'savedAgentResultStruct' with RL agent

3 visualizaciones (últimos 30 días)
Sayak Mukherjee
Sayak Mukherjee el 22 de Feb. de 2021
Comentada: Sayak Mukherjee el 2 de Dic. de 2021
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 comentarios
M.Y. C.
M.Y. C. el 5 de Mzo. de 2021
Editada: M.Y. C. el 5 de Mzo. de 2021
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
Sayak Mukherjee
Sayak Mukherjee el 2 de Dic. de 2021
Hi M.Y.C.
Were you able to optimize the code?

Iniciar sesión para comentar.

Respuestas (0)

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by