如何使用 Q-Learning 训练神经网络

How to train a neural network with Q-Learning

我刚刚在没有神经网络的情况下实现了 Q-Learning,但我一直坚持用神经网络来实现它们。

我会给你一个伪代码来展示我的 Q-Learning 是如何实现的:

train(int iterations)
    buffer = empty buffer
    for i = 0 while i < iterations:

         move = null
         if random(0,1) > threshold:
             move = random_move()                 
         else
             move = network_calculate_move()

         input_to_network = game.getInput()
         output_of_network = network.calculate(input_to_network)

         game.makeMove(move)
         reward = game.getReward()

         maximum_next_q_value = max(network.calculate(game.getInput()))

         if reward is 1 or -1:            //either lost or won
             output_of_network[move] = reward
         else:
             output_of_network[move] = reward + discount_factor * max


         buffer.add(input_to_network, output_of_network)
         if buffer is full: 
             buffer.remove_oldest()
             train_network()


train_network(buffer b):
     batch = b.extract_random_batch(batch_size) 
     for each input,output in batch:
          network.train(input, output, learning_rate)  //one forward/backward pass

我现在的问题是这段代码适用于小于 200 的缓冲区大小。 对于任何超过 200 的缓冲区,我的代码不再有效,所以我有几个问题:

  1. 这个实现是否正确? (理论上)
  2. 批量大小与缓冲区大小相比应该有多大
  3. 通常如何训练网络?多长时间?直到达到整个批次的特定 MSE?

Is this implementation correct? (In theory)

是的,你的伪代码确实有正确的方法。

How big should the batch size be compared to the buffer size

从算法上讲,在随机梯度下降中使用更大的批次可以减少随机梯度更新的方差(通过取批次中梯度的平均值),这反过来又可以让你采取更大的步骤-大小,这意味着优化算法将取得更快的进展。

经验回放缓冲区存储固定数量的近期记忆,随着新的进入,旧的被移除。到了训练的时候,我们只需从缓冲区中抽取一批统一的随机记忆,然后用它们训练我们的网络。

虽然相关,但批量大小与缓冲区大小没有标准值。试验这些超参数是深度强化学习的乐趣之一。

How would one usually train the network? For how long? Until a specific MSE of the whole batch is reached?

网络通常会被训练到 "converge,",这意味着 Q-table 在 episode

之间反复没有有意义的变化]