Hi,
I understand that you want to limit the training process of your RL PPO agent based on the elapsed time. According to my knowledge and the documentation for ‘rlTrainingOptions’, there is no predefined option in the ‘StopTrainingCriteria’ property which can achieve this directly. However, a possible workaround is to use the custom stop criteria by specifying ‘StopTrainingValue’ as a function name or handle. Here is the documentation link for reference:
Below is an example code snippet demonstrating this approach:
function stopTraining = customStopFunction(trainingStats)
elapsedTime = toc(startTime);
if elapsedTime > maxTrainingTime
disp(['Stopping training after ', num2str(elapsedTime), ' seconds.']);
trainingOptions = rlTrainingOptions(...
'MaxEpisodes', 10000, ...
'MaxStepsPerEpisode', 500, ...
'ScoreAveragingWindowLength', 100, ...
'Plots', 'training-progress', ...
'StopOnError', 'off', ...
'SaveAgentCriteria', 'EpisodeReward', ...
'SaveAgentValue', 500, ...
'StopTrainingCriteria', 'Custom', ...
'StopTrainingValue', @customStopFunction);
trainStats = train(agent, env, trainingOptions);
Here is the reference to the ‘tic’ and ‘toc’ functions used in the ‘customStopFunction’ to capture time:
I hope this gives you a direction for taking the next steps to achieve the desired result.