我试图在一个简单的多智能体非合作并行游戏中使用TF-agent。为了简化,我有两个代理,用TF-代理定义。我定义了一个自定义健身房环境,它将代理的组合动作作为输入,并返回一个观察结果。代理人的政策不应将充分的观察作为投入,而应只是其中的一部分。所以我需要做两件事:
time_step实例,以独立地向代理的策略提供信息。action_step实例以满足环境需求。如果agent1_policy和agent2_policy是TF-agent策略,而environment是TF-agents环境,那么我希望能够这样做来收集步骤:
from tf_agents.trajectories import trajectory
time_step = environment.current_time_step()
# Split the time_step to have partial observability
time_step1, time_step2 = split(time_step)
# Get action from each agent
action_step1 = agent1_policy.action(time_step1)
action_step2 = agent2_policy.action(time_step2)
# Merge the independent actions
action_merged = merge(action_step1, action_step2)
# Use the merged actions to have the next step
next_time_step = environment.step(action_merged)
# Split the next step too
next_time_step1, next_time_step2 = split(next_time_step)
# Build two distinct trajectories
traj1 = trajectory.from_transition(time_step1, action_step1, next_time_step1)
traj2 = trajectory.from_transition(time_step2, action_step2, next_time_step2)然后将traj1和traj2添加到用于训练这两个代理的缓冲区中。
在这个例子中,我应该如何定义函数merge和split?
发布于 2021-10-14 03:58:36
这可以通过在环境类中定义适当的action_spec和observation_spec来实现。请参阅这份文件,以获得生成张量字典的观察结果的示例。类似的方法可以用于接受作为字典或元组的操作。
https://stackoverflow.com/questions/66870225
复制相似问题