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

Feat/stochastic inputs #833

Merged
merged 4 commits into from Mar 8, 2022
Merged

Feat/stochastic inputs #833

merged 4 commits into from Mar 8, 2022

Conversation

hrzn
Copy link
Contributor

@hrzn hrzn commented Mar 3, 2022

Handle stochastic series for fit() and predict() in Torch-based models.

When fitting: a sample is drawn from the series uniformly at random (instead of taking always the 1st sample, as before). This way the training procedure can naturally be carried over the stochastic samples.

When predicting: one sample is drawn from the series uniformly at random. Unfortunately at the moment it would be quite complicated to batch the forward passes over all of a series' samples, so each call to predict() will only return the forecast related to this one sample. However, calling sample() many times and concatenating the results allows to get stochastic forecasts even with deterministic models (not using a likelihood) when predicting stochastic series (or using stochastic covariates). Here's an example:

image

@codecov-commenter
Copy link

Codecov Report

Merging #833 (cde0184) into master (cbe49bf) will decrease coverage by 0.01%.
The diff coverage is 90.90%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #833      +/-   ##
==========================================
- Coverage   91.33%   91.32%   -0.02%     
==========================================
  Files          69       69              
  Lines        6869     6872       +3     
==========================================
+ Hits         6274     6276       +2     
- Misses        595      596       +1     
Impacted Files Coverage Δ
darts/timeseries.py 88.00% <80.00%> (-0.05%) ⬇️
darts/utils/data/horizon_based_dataset.py 100.00% <100.00%> (ø)
darts/utils/data/inference_dataset.py 94.54% <100.00%> (ø)
darts/utils/data/shifted_dataset.py 84.61% <100.00%> (ø)
...arts/models/forecasting/torch_forecasting_model.py 89.10% <0.00%> (-0.05%) ⬇️
darts/models/forecasting/nbeats.py 99.27% <0.00%> (ø)
darts/models/forecasting/rnn_model.py 97.46% <0.00%> (ø)
darts/models/forecasting/tcn_model.py 96.84% <0.00%> (ø)
darts/models/forecasting/tft_model.py 96.80% <0.00%> (ø)
darts/models/forecasting/block_rnn_model.py 98.14% <0.00%> (ø)
... and 3 more

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 cbe49bf...cde0184. Read the comment docs.

Copy link
Collaborator

@dennisbader dennisbader left a comment

Choose a reason for hiding this comment

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

Looks good, thanks :) I had a question about a potential additional option for randomly sampling the quantiles

preds = [model.predict(series=stochastic_series, n=10) for _ in range(2)]

# random samples should differ
self.assertFalse(np.alltrue(preds[0].values() == preds[1].values()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is nitpicking but isn't there a slim chance that the predictions will be identical? :D we could add a seed to make sure they are not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, normally there is a seed earlier in the file which I believe should apply here :)

@@ -1176,6 +1176,28 @@ def values(self, copy=True, sample=0) -> np.ndarray:
else:
return self._xa.values[:, :, sample]

def random_component_values(self, copy=True) -> np.array:
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think about an additional optional to randomly sample a quantile per sample?

I would assume this is similar to quantile regression based on stochastic input (without needing QuantileRegression as a likelihood)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, you mean returning the exact quantile instead of sampling a sample at random? That's an interesting idea :) But would require a bit of adaptation elsewhere as we would still need to ensure this is applied on the output targets only, and not e.g. on the inputs or covariates. Let's keep the idea though.

@hrzn hrzn merged commit ae47aba into master Mar 8, 2022
@madtoinou madtoinou deleted the feat/stochastic-inputs branch July 5, 2023 21:55
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.

None yet

3 participants