MCPcopy
hub / github.com/ddbourgin/numpy-ml / torch_mse_grad

Function torch_mse_grad

numpy_ml/tests/nn_torch_models.py:41–48  ·  view source on GitHub ↗
(y, z, act_fn)

Source from the content-addressed store, hash-verified

39
40
41def torch_mse_grad(y, z, act_fn):
42 y = torch.FloatTensor(y)
43 z = torch.autograd.Variable(torch.FloatTensor(z), requires_grad=True)
44 y_pred = act_fn(z)
45 loss = F.mse_loss(y_pred, y, reduction="sum") # size_average=False).sum()
46 loss.backward()
47 grad = z.grad.numpy()
48 return grad
49
50
51class TorchVAELoss(nn.Module):

Callers

nothing calls this directly

Calls 1

backwardMethod · 0.45

Tested by

no test coverage detected