Pausing reinforcement learning by forcing
4 views (last 30 days)
Show older comments
SHromaneko
on 2 Jan 2024
Edited: SHromaneko
on 10 Jan 2024
I'm running reinforcement learning, but I think there are times when I think it's not going well and want to stop it.
If you stop today's learning agent executed with the code below with Training stopped, simulink will freeze and stop working.
Repeatedly hitting the escape key doesn't work either.
so that you can stop it properly
Is there something wrong with the code?
numObs = 9;
obsInfo = rlNumericSpec([numObs 1]);
obsInfo.Name = "observations";
mdl = "kineticmodel_wIAVFBC_IncS2Ea_NH3FBC";
open_system(mdl)
numAct = 1;
actInfo = rlNumericSpec([numAct 1],LowerLimit=0,UpperLimit=1);
actInfo.Name = "NH3";
blk = mdl + "/RL agent/RL Agent";
env = rlSimulinkEnv(mdl,blk,obsInfo,actInfo);
Ts = 1
agent = createDDPGAgent(numObs,obsInfo,numAct,actInfo,Ts);
maxEpisodes = 2000;
Tf = 1240*3
maxSteps = floor(Tf/Ts);
trainOpts = rlTrainingOptions(...
MaxEpisodes=maxEpisodes,...
MaxStepsPerEpisode=maxSteps,...
ScoreAveragingWindowLength=250,...
Verbose=false,...
Plots="training-progress",...
StopTrainingCriteria="EpisodeCount",...
StopTrainingValue=maxEpisodes,...
SaveAgentCriteria="EpisodeCount",...
SaveAgentValue=maxEpisodes);
doTraining = true;
if doTraining
% Train the agent.
trainingStats = train(agent,env,trainOpts);
else
% Load a pretrained agent for the selected agent type.
if strcmp(AgentSelection,"DDPG")
load("rlWalkingBipedRobotDDPG.mat","agent")
else
load("rlWalkingBipedRobotTD3.mat","agent")
end
end
0 Comments
Accepted Answer
Emmanouil Tzorakoleftherakis
on 9 Jan 2024
The proper way to stop it would be through the Episode Manager (top right of the window). Does this not work for you?
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!