quantlab.model.torch_training.masked_mse#

quantlab.model.torch_training.masked_mse(pred, y, mask)[source]#

Mean squared error over the entries where mask is True.

Parameters:
predtorch.Tensor

Predictions, mask.shape + (L,), for example [S_t, L].

ytorch.Tensor

Targets of the same shape.

masktorch.Tensor

Booleans over the sample dimensions (typically batch.mask), or of the same shape as pred to mask single labels.

Returns:
torch.Tensor

The scalar mean; NaN when no entry is valid.

Examples

>>> masked_mse(torch.tensor([[1.0], [5.0]]), torch.tensor([[0.0], [0.0]]),
...            torch.tensor([True, False]))
tensor(1.)