微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决合并和拆分来自 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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。