mirror of
https://github.com/wassname/DeepRL.git
synced 2026-09-13 12:10:52 +08:00
threading
This commit is contained in:
+10
-1
@@ -43,12 +43,21 @@ class FullyConnectedNet(nn.Module):
|
||||
def predict(self, x):
|
||||
return self.forward(x).cpu().data.numpy()
|
||||
|
||||
def learn_from_raw(self, x, actions, rewards):
|
||||
y = self.forward(x)
|
||||
target = np.copy(y.data.numpy())
|
||||
target[np.arange(target.shape[0]), actions] = np.asarray(rewards)
|
||||
target = Variable(torch.from_numpy(target))
|
||||
loss = self.criterion(y, target)
|
||||
self.zero_grad()
|
||||
loss.backward()
|
||||
self.optimizer.step()
|
||||
|
||||
def learn(self, x, target):
|
||||
target = torch.from_numpy(target)
|
||||
if self.gpu:
|
||||
target = target.cuda()
|
||||
target = Variable(target)
|
||||
|
||||
y = self.forward(x)
|
||||
loss = self.criterion(y, target)
|
||||
self.zero_grad()
|
||||
|
||||
Reference in New Issue
Block a user