Dont need to save 'savedAgentResultStruct' with RL agent
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
M.Y. C.
le 5 Mar 2021
Modifié(e) : M.Y. C.
le 5 Mar 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
Réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!