How to check the change of weight in reinforcement learning training?

1 次查看(过去 30 天)
I have read the example "tune PI controller using reinforcement learning". And I wonder how to check the change of weights of the actor network every step? Could anyone help me? Thanks very much!

回答(1 个)

Nithin
Nithin 2025-4-9
To monitor the change in weights of the actor network at every step during training in the example "Tune PI Controller Using Reinforcement Learning", you can use a custom callback function to record the model weights at each step.
You can create a custom callback function to extract and log the weights of the actor network which will be called at each training step.
global weightsHistory;
weightsHistory = [];
% Custom callback function to log actor weights
function stop = logActorWeights(agent, ~, ~)
global weightsHistory;
actor = getActor(agent);
parameters = getLearnableParameters(actor);
% Append the current weights to the history
weightsHistory = [weightsHistory; parameters{1}(:)'];
stop = false;
end
"logActorWeights" function is defined to extract the learnable parameters (weights) of the actor network and append them to "weightsHistory".
Then, add the callback function to the training options
trainOpts = rlTrainingOptions(...
MaxEpisodes=maxepisodes, ...
MaxStepsPerEpisode=maxsteps, ...
ScoreAveragingWindowLength=100, ...
Verbose=false, ...
Plots="training-progress", ...
StopTrainingCriteria="AverageReward", ...
StopTrainingValue=-355, ...
Callbacks=@logActorWeights); % Add the callback function
Hope this answers your query.

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by