Skip to content
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

Fix/linear quantile interpolation #899

Merged
merged 10 commits into from Apr 13, 2022
Merged

Conversation

gnwhr
Copy link
Contributor

@gnwhr gnwhr commented Apr 7, 2022

Fixes #869 .

Summary

Now quantile sampling samples uniformly between fitted quantiles. RegressionModels now correctly construct paths when generating samples.

@codecov-commenter
Copy link

codecov-commenter commented Apr 7, 2022

Codecov Report

Merging #899 (b585f1b) into master (60fcb3b) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #899      +/-   ##
==========================================
+ Coverage   91.67%   91.70%   +0.03%     
==========================================
  Files          74       74              
  Lines        7375     7402      +27     
==========================================
+ Hits         6761     6788      +27     
  Misses        614      614              
Impacted Files Coverage Δ
darts/models/forecasting/gradient_boosted_model.py 100.00% <100.00%> (ø)
...arts/models/forecasting/linear_regression_model.py 94.91% <100.00%> (+0.17%) ⬆️
darts/models/forecasting/regression_model.py 97.23% <100.00%> (+0.11%) ⬆️
darts/utils/likelihood_models.py 96.20% <100.00%> (+0.10%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 60fcb3b...b585f1b. Read the comment docs.

Copy link
Contributor

@hrzn hrzn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, thanks 👍
I just have a couple of minor comments.


# linear interpolation
weights = (probs - left_q) / (right_q - left_q)
inter = left_value + weights * (right_value - left_value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, definitely an improvement 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :)

model_output is of shape (n_series * n_samples, output_chunk_length, n_components, n_quantiles)
"""
num_samples, n_timesteps, n_components, n_quantiles = model_output.shape
model_output = model_output.reshape(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, will remove


def _quantile_sampling(self, model_output: np.ndarray) -> np.ndarray:
"""
Select a quantile (for each batch example) and return this quantile (over time and components).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this docstring correct? Don't you rather return an interpolation between the quantiles?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I forgot to update the docstrings

@gnwhr gnwhr merged commit 7a6355c into master Apr 13, 2022
@madtoinou madtoinou deleted the fix/linear-quantile-interpolation branch July 5, 2023 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix quantiles-sampling to sample uniformly at random between quantile values
3 participants