Sending episode number to simulink during training

18 ビュー (過去 30 日間)
Esan freedom
Esan freedom 2023 年 1 月 24 日
Hello every one,
I am using reinforcement learning with two agents and I am going to laod the number of episode from workspace in simulink by "from workspace block". I tried trainingStats.EpisodeIndex(1) but I recieved error. As trainingStats would appear after terminating episode 1, I dont have any idea to find the episode number in simulink.
I would appreciate any help.
  3 件のコメント
Benjamin Thompson
Benjamin Thompson 2023 年 1 月 24 日
Can you provide a listing of the error message and more examples of what you are doing and how you are doing it?
Esan freedom
Esan freedom 2023 年 1 月 24 日
Thanks at first.
For my reinforcement learning agent, I need to build a special reward for my reinforcement learning agent that starts giving a penalty after episode 100th. For that, I need to read the number of episode in Simulink and if it is below the 100th episode, then the reward is set to zero, and after the 100th episode, It starts getting a penalty.
I have to agents and for example after 4 episods in the Workspace I have this index in the below Fig.

サインインしてコメントする。

採用された回答

Emmanouil Tzorakoleftherakis
Emmanouil Tzorakoleftherakis 2023 年 1 月 24 日
編集済み: Emmanouil Tzorakoleftherakis 2023 年 1 月 24 日
The training stats are not available until after training is done, so you cannot use trainingStats.EpisodeIndex during training. The easiest way to accomplish what you want is by using the reset function. Take a look at this example.
The reset function is called before every episode, so you can use it to create a counter for the episode number and assign it either to a workspace variable, or directly to e.g. a Constant block in Simulink.
Hope that helps
  4 件のコメント
Esan freedom
Esan freedom 2023 年 1 月 25 日
Dear Emmanouil, you are the best.
I am grateful for your help and time. Thank you so much. By the following code, I have solved my problem.
  • function in= localResetFcn(in)
  • persistent n
  • if isempty(n)
  • n = 0;
  • end
  • n = n+1
  • blk = 'PV/Control_rll/count';
  • in = setBlockParameter(in,blk,'Value',num2str(n));
  • end
Emmanouil Tzorakoleftherakis
Emmanouil Tzorakoleftherakis 2023 年 1 月 25 日
編集済み: Emmanouil Tzorakoleftherakis 2023 年 1 月 25 日
Glad it was helpful

サインインしてコメントする。

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2023 年 1 月 24 日
Try the Constant block and specify the value as trainingStats.EpisodeIndex(1). Read the document of the "From Workspace" block to see if it is what you needed.
  1 件のコメント
Esan freedom
Esan freedom 2023 年 1 月 24 日
Thanks for your help. I received the following error:
Error evaluating parameter 'Value' in 'PV/Control_rll/Constant34'
Error using rl.env.SimulinkEnvWithAgent>localHandleSimoutErrors (line 668)
Unable to resolve the name trainingStats.EpisodeIndex.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTraining and Simulation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by