合并和拆分来自 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 (将#修改为@)