Agent 结构:
class Environment:
def __init__(self) # 环境初始化内部状态
def get_observation(self) # 向agent返回当前环境的observation
def get_actions(self) # 用作让agent 获取可执行的action
def is_done(self) # 用作判断一个episode是否结束
def action(self, action) # 用于执行动作,并返回该动作对应的reward
class Agent:
def __init__(self) # 可以用作初始化计数器来计算所有奖励
def step(self, env) # 用于获取环境,获取 选择 并 执行动作,得到当前步骤的奖励
Gym 中的 environment 由 Env class 表示
action_space # 环境中的所有action
observationn_space # 包含环境中的observation
reset() # 重置环境到最初的状态
# 没有输入,创建环境后调用
step() # 允许agent给出动作,返回动作的结果:下一个observation,当前的reward,episode结束标志
# 输入是action,返回( observation, reward, done, extra_info)
Gym 中环境创建
make(env_name)
Gym 中的 Wrapper,用于拓展 environment 的功能,其中有多个子类
ObservationWrapper 需要重写 observation(obs) 方法,obs是 an observation from the wrapped environment,方法返回的是 给agent的observation
RewardWrapper 公开了reward(rew)方法,可以修改给agent的reward
ActionWrapper 重写 action(act) 方法,可以tweak the action passed to the wrapped environment to the agent.