为什么双Q学习的奖励会波动?

时间:2019-04-20 07:01:58

标签: deep-learning reinforcement-learning q-learning

我正在尝试使用Keras库中的神经网络来实施Double Q学习。当我初次尝试简单DQN时,奖励的图形波动很大,因此我实现了Double DQN。但是,我得到的结果几乎相同(波动很大)。

我尝试过更改网络的超参数,但是问题仍然存在。

Reward Graph

我的代码:
class DQNAgent:
    def __init__(self, state_size, action_size):
        self.state_size = state_size
        self.action_size = action_size
        self.memory = deque(maxlen=2000)
        self.gamma = GAMMA   
        self.epsilon = START_EPSILON  
        self.epsilon_min = EPSILON_MIN
        self.epsilon_decay = EPSILON_DECAY
        self.learning_rate = LEARNING_RATE
        self.model = self.build_model()
        self.target_model = self.build_model()

    def build_model(self):
        model = Sequential()
        model.add(Dense(16, input_dim=self.state_size, activation='relu'))
        model.add(Dense(32, activation='relu'))
        model.add(Dense(self.action_size, activation='linear'))
        model.compile(loss='mse',optimizer=Adam(lr=self.learning_rate))
        return model

    def remember(self, state, action, reward, next_state, done):
        self.memory.append((state, action, reward, next_state, done))

    def act(self, state):
        if np.random.rand() <= self.epsilon:
            return random.randrange(self.action_size)
        self.model.set_weights(self.target_model.get_weights())
        act_values = self.model.predict(state)
        return np.argmax(act_values[0])  

    def replay(self, batch_size):
        minibatch = random.sample(self.memory, batch_size)
        for state, action, reward, next_state, done in minibatch:
            action_t = np.argmax(self.model.predict(state)[0])
            target = reward
            if not done:
                target = (reward + self.gamma *
                          (self.target_model.predict(next_state)[0][action_t]))
            target_f = self.target_model.predict(state)
            target_f[0][action] = target
            self.target_model.fit(state, target_f, epochs=1, verbose=0)
        if self.epsilon > self.epsilon_min:
            self.epsilon *= self.epsilon_decay

我在上述代码中对Double Q-Learning算法的实现是否正确?

0 个答案:

没有答案