繁体   English   中英

合并和拆分来自 TF-agents 的时间和动作步骤

[英]Merging and splitting time and action steps from TF-agents

我正在尝试在一个简单的多代理非合作并行游戏中使用 TF 代理。 为简化起见,我有两个用 TF 代理定义的代理。 我定义了一个自定义的健身房环境,它将代理的组合动作作为输入并返回一个观察结果。 代理的策略不应将全部观察作为输入,而应仅将其一部分作为输入。 所以我需要做两件事:

  • 拆分 TF-agents 环境包装器返回的time_step实例,以独立提供给代理的策略
  • 合并来自代理策略的action_step实例以提供环境。

如果agent1_policyagent2_policy是两个 TF-agents 策略并且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)

然后将traj1traj2添加到用于训练两个代理的缓冲区中。

在这个例子中我应该如何定义函数mergesplit

这可以通过在环境 class 中定义正确的action_specobservation_spec来完成。 有关生成作为张量字典的观察的示例,请参阅此文档 类似的方法可用于接受作为字典或元组的操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM