jdb78 / pytorch-forecasting

Time series forecasting with PyTorch
https://pytorch-forecasting.readthedocs.io/
MIT License
3.77k stars 600 forks source link

RMSE defined as MSE #1541

Open jenkoj opened 4 months ago

jenkoj commented 4 months ago

Noticed discrepancy related to metric definition. RMSE is actually MSE, which makes sense as RMSE tends to be very unstable.

Definiton:

class RMSE(MultiHorizonMetric):
  """
  Root mean square error

  Defined as ``(y_pred - target)**2``
  """

  def __init__(self, reduction="sqrt-mean", **kwargs):
   super().__init__(reduction=reduction, **kwargs)

  def loss(self, y_pred: Dict[str, torch.Tensor], target):
    loss = torch.pow(self.to_prediction(y_pred) - target, 2)
    return loss

source: https://github.com/jdb78/pytorch-forecasting/blob/68a0eb5f1701801142ce976fa50305b29507845a/pytorch_forecasting/metrics/point.py#L137C1-L149C20

AlexVeuthey commented 2 months ago

The documentation isn't very clear, but I believe the root is applied by the reduction function, thus making it RMSE. A bit risky since the reduction function doesn't have to be "sqrt-mean"...