Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RL: Debugging Reward.C_TYPE_EVERY_AGENT #862

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/mlpro/rl/models_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@
## -- 2023-02-20 1.9.0 DA Class RLScenario: new methods load(), _save()
## -- 2023-03-09 1.9.1 DA Class RLTrainingResults: removed parameter p_path
## -- 2023-03-26 2.0.0 DA Class RLScenario: refactoring persistence
## -- 2023-09-25 2.0.1 SY Class RLScenario: debugging reward storing in _run_cycle
## -------------------------------------------------------------------------------------------------

"""
Ver. 2.0.0 (2023-03-26)
Ver. 2.0.1 (2023-09-25)

This module provides model classes to define and run rl scenarios and to train agents inside them.
"""
Expand Down Expand Up @@ -529,13 +530,22 @@ def _run_cycle(self):
ts = self._timer.get_time()
reward.set_tstamp(ts)
if self._ds_rewards is not None:
if (reward.get_type() == Reward.C_TYPE_OVERALL) or (reward.get_type() == Reward.C_TYPE_EVERY_AGENT):

if reward.get_type() == Reward.C_TYPE_OVERALL:
reward_values = np.zeros(self._ds_rewards.get_space().get_num_dim())

for i, agent_id in enumerate(self._ds_rewards.get_space().get_dim_ids()):
reward_values[i] = reward.get_agent_reward(i)

self._ds_rewards.memorize_row(self._cycle_id, ts, reward_values)

elif reward.get_type() == Reward.C_TYPE_EVERY_AGENT:
reward_values = np.zeros(len(reward.agent_ids))

for i, agent_id in enumerate(reward.agent_ids):
reward_values[i] = reward.get_agent_reward(agent_id)

self._ds_rewards.memorize_row(self._cycle_id, ts, reward_values)


# 5 Agent: adapt policy
Expand Down