def forward(self, prediction, target): squared_error = (prediction - target).square() weights = torch.where( prediction < target, self.under_prediction_weight, 1.0, ) return (weights * squared_error).mean()