-
Notifications
You must be signed in to change notification settings - Fork 904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add quantile loss metric #1559
Add quantile loss metric #1559
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I don't have enough experience to comment the line you highlighted in darts/darts/utils/likelihood_models.py, I'll try to think more about it and circle back to you.
In the last commit I used simple mean across all values instead of the previously used reduction param, because it wasn't passing darts/darts/tests/metrics/test_metrics.py Line 112 in e1c8d34
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, the reduction argument is actually supposed to be used when reducing the metrics for multivariate ts (thanks to the decorator) and should not be used inside the metric itself.
I mentioned it because I managed to stumble into it and it's somewhat connected to the PR. It's nothing crucial for now, so it might be a good idea to put together a separate issue for it to keep the PR small and focused on just the metric, let me know what you think |
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## master #1559 +/- ##
==========================================
- Coverage 94.09% 94.05% -0.04%
==========================================
Files 125 125
Lines 11185 11182 -3
==========================================
- Hits 10524 10517 -7
- Misses 661 665 +4
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, only small comments.
@JanFidor thanks for the PR! Regarding the operation darts/darts/utils/likelihood_models.py Line 1126 in e1c8d34
I would have to dive into it a little more, but I think this is intended. We are first summing the losses over the last dimensions, so that the final loss for each sample is the sum of the losses for each quantile; note that when training the gradients will flow backward on this sum and be redistributed to the individual "quantile heads" of the neural network, in order to tune them to predict the individual quantiles correctly. The last mean() call is simply to take the mean over the batch dimension. So at first sight nothing there looks suspicious to me, but I might be missing something of course.
Finally, I think your averaging in Numpy over the time dimension is correct, as we want to return the mean quantile loss (over time). |
…Fidor/darts into feature/quantile-loss-metric
…Fidor/darts into feature/quantile-loss-metric
Thanks for the explanation, I wasn't looking at the big picture with back-prop, it makes sense now |
Hmmm, I think macos failure might be unrelated to the code as ubuntu passes, please let me know if there's something I should change or if the CI's flaky |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
Thanks for the reviews @madtoinou @hrzn ! |
* first implementation of quantile loss * add quantile loss to metrics ___init__ and tests * refactor * rename pinball loss to quantile loss * black * use reduction to aggregate losses and update docs * black + isort * rollback to simple mean instead of reduction param * change overlooked copy-paste comment * black enter * docs changes * flake8 --------- Co-authored-by: Julien Herzen <julien@unit8.co> Co-authored-by: madtoinou <32447896+madtoinou@users.noreply.github.com> Co-authored-by: Dennis Bader <dennis.bader@gmx.ch>
Fixes #1367
Summary
Add quantile loss metric with tests
I found an already existing implementation of quantile loss here:
darts/darts/utils/likelihood_models.py
Line 1121 in e1c8d34
and used it for refactoring. Substituting that implementation with the new metric function would definitely be in line with DRY, but for now it doesn't support CUDA, while the QuantileRegression does. I'm not certain whether it actually needs it or if it was just an implementation quirk, so I left it as is for now. I could add support for multiple tau values as a parameter and returning their mean loss.
Other Information
While we're at the topic of the QuantileRegression , while browsing it I stumbled upon this line:
darts/darts/utils/likelihood_models.py
Line 1126 in e1c8d34
I'll be honest I've been looking at it for quite a while now and I just can't wrap my head around why it takes that sum before returning the mean. It would be penalizing the amount of quantiles the model optimizes for, which would kind of work as a regularization technique. Also if we have quantiles q and 1 - q we optimize for, they negate each other and give us 2 instances with quantile 0.5, so we could try to skip those unnecessary operations, I'm not certain if the speed-up would be meaningful though. Please let me know what you think