首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从TF-代理合并和拆分时间和操作步骤

从TF-代理合并和拆分时间和操作步骤
EN

Stack Overflow用户
提问于 2021-03-30 11:34:56
回答 1查看 100关注 0票数 0

我试图在一个简单的多智能体非合作并行游戏中使用TF-agent。为了简化,我有两个代理,用TF-代理定义。我定义了一个自定义健身房环境,它将代理的组合动作作为输入,并返回一个观察结果。代理人的政策不应将充分的观察作为投入,而应只是其中的一部分。所以我需要做两件事:

  • 拆分TF-agent环境包装器返回的time_step实例,以独立地向代理的策略提供信息。
  • 合并来自代理策略的action_step实例以满足环境需求。

如果agent1_policyagent2_policy是TF-agent策略,而environment是TF-agents环境,那么我希望能够这样做来收集步骤:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2021-10-14 03:58:36

这可以通过在环境类中定义适当的action_specobservation_spec来实现。请参阅这份文件,以获得生成张量字典的观察结果的示例。类似的方法可以用于接受作为字典或元组的操作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66870225

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档