Compute the summed squared-error loss and its gradient with respect to predictions, using aligned target values.
L=i∑(pi−yi)2 gi=2(pi−yi)Here p is predictions, y is targets, i indexes every tensor entry, L is the total loss, and g is its gradient with respect to predictions. Do not average over the entries. Empty tensors have zero loss and an empty gradient.
Return a tuple containing a zero-dimensional loss tensor and a gradient tensor with the same shape as predictions. Both are PyTorch tensors that preserve the common input dtype and device.
Input: predictions = [1,-1], targets = [1,1]
Output: (4.0, [0.0, -4.0])
Explanation: The second prediction differs from its target by -2, contributing a loss of 4 and a gradient of -4.
Input: predictions = [0.5], targets = [0.5]
Output: (0.0, [0.0])
Input: predictions = [], targets = []
Output: (0.0, [])
torch.sum reduces all tensor entries when no dimension is supplied.
Elementwise operations retain the shape of predictions.
Accepts: array, number
Accepts: array, number
Compute the summed squared-error loss and its gradient with respect to predictions, using aligned target values.
L=i∑(pi−yi)2 gi=2(pi−yi)Here p is predictions, y is targets, i indexes every tensor entry, L is the total loss, and g is its gradient with respect to predictions. Do not average over the entries. Empty tensors have zero loss and an empty gradient.
Return a tuple containing a zero-dimensional loss tensor and a gradient tensor with the same shape as predictions. Both are PyTorch tensors that preserve the common input dtype and device.
Input: predictions = [1,-1], targets = [1,1]
Output: (4.0, [0.0, -4.0])
Explanation: The second prediction differs from its target by -2, contributing a loss of 4 and a gradient of -4.
Input: predictions = [0.5], targets = [0.5]
Output: (0.0, [0.0])
Input: predictions = [], targets = []
Output: (0.0, [])
torch.sum reduces all tensor entries when no dimension is supplied.
Elementwise operations retain the shape of predictions.
Accepts: array, number
Accepts: array, number