首页 > 解决方案 > 为具有延迟奖励和连续时间的强化学习问题创建自定义环境

问题描述

我想为进一步的 RL 任务创建一个自定义环境。环境的一个特点是我不知道如何处理。也就是说,奖励不是在动作之后立即记录,而是在一段时间后记录。(既然有“时间”,那么可能需要一个“时钟”来安排离散事件的顺序?)。

我在某处寻找了一些教程,并将其总结为伪代码,如下所示。然而,大部分开源代码是针对传统 RL 环境的,这意味着奖励是在行动之后立即记录的。我对如何处理该def step(self, action):功能感到困惑。

class env():

    def __init__(self):
        self.current_hour = 0
        
    #states
        self.observation = 0

    #actions
        self.actions = ['action1', 'action2']   #action space
        self.n_actions = len(self.actions)   #number of possible actions

    #rewards
        self.reward = 0    #reward
        self.done = False 

    def step(self, action):
        #1. Update the environment state based on the action chosen
        #2. Calculate the reward for the new state
        #3. Store the new observation for the state
        #4. Check if the episode is over and store as done
        return self.observation, self.reward, self.done
        
    def reset(self): #Reset the environment's state. Returns observation.
        self.done = False
        self.observation = 0        
        return self.observation

标签: reinforcement-learning

解决方案


推荐阅读