Convert priorities to numpy data
@@ -69,7 +69,7 @@ def calc_loss(batch, batch_weights, net, tgt_net, gamma, cuda=False):
actions_v = Variable(torch.from_numpy(actions))
rewards_v = Variable(torch.from_numpy(rewards))
done_mask = torch.ByteTensor(dones)
- batch_weights_v = Variable(torch.from_numpy(np.array(batch_weights, dtype=np.float32)))
+ batch_weights_v = Variable(torch.from_numpy(batch_weights))
if cuda:
states_v = states_v.cuda()
next_states_v = next_states_v.cuda()
@@ -85,7 +85,7 @@ def calc_loss(batch, batch_weights, net, tgt_net, gamma, cuda=False):
expected_state_action_values = next_state_values * gamma + rewards_v
losses_v = batch_weights_v * (state_action_values - expected_state_action_values) ** 2
- return losses_v.mean(), losses_v
+ return losses_v.mean(), losses_v.data.cpu().numpy()
if __name__ == "__main__":
@@ -132,7 +132,7 @@ if __name__ == "__main__":
optimizer.zero_grad()
batch, batch_indices, batch_weights = buffer.sample(params['batch_size'], beta)
- loss_v, sample_prios_v = calc_loss(batch, batch_weights, net, tgt_net.target_model,
+ loss_v, sample_prios = calc_loss(batch, batch_weights, net, tgt_net.target_model,
params['gamma'], cuda=args.cuda)
loss_v.backward()
optimizer.step()
