我正在一个强化学习程序中工作,我使用这篇文章作为参考文献。我使用python和keras(theano)来创建神经网络,我为这个程序使用的伪代码是
Do a feedforward pass for the current state s to get predicted Q-values for all actions.
Do a feedforward pass for the next state s’ and calculate maximum overall network outputs max a’ Q(s’, a’).
Set Q-value target for action to r + γmax a’ Q(s’, a’) (use the max calculated in step 2). For all other actions, set the Q-value target to the same as originally returned from step 1, making the error 0 for those outputs.
Update the weights using backpropagation.这里的损失函数方程是

如果我的奖励是+1,maxQ(s',a') =0.8375,Q(s,a)=0.6892
我的L会是1/2*(1+0.8375-0.6892)^2=0.659296445
现在,如果我的模型结构是这样的,我应该如何使用上面的损失函数值来更新我的模型神经网络权重
model = Sequential()
model.add(Dense(150, input_dim=150))
model.add(Dense(10))
model.add(Dense(1,activation='sigmoid'))
model.compile(loss='mse', optimizer='adam')发布于 2017-01-05 02:49:55
假设NN正在建模Q值函数,则只需将目标传递给网络即可。例如:
model.train_on_batch(state_action_vector, target)其中state_action_vector是一些预处理向量,表示对网络的状态动作输入。由于您的网络使用的是MSE损失函数,它将使用前传的状态动作来计算预测项,然后根据目标更新权重。
https://stackoverflow.com/questions/39951502
复制相似问题