-
Notifications
You must be signed in to change notification settings - Fork 755
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
Nonnegative predictions for deepar mxnet #2957
Merged
melopeo
merged 14 commits into
awslabs:dev
from
melopeo:nonnegative_predictions_for_deepar-mxnet
Aug 11, 2023
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
017f3f8
setup nonnegative predictions for DeepAR-mxnet
dfb671c
add tests for nonnegative_pred_samples
2931d70
rename test_nonnegative_fcsts to test_nonnegative_pred_samples
82d7ca7
clean tests
5bfa512
clean tests
a00db3e
clean tests
ac3d8dd
Merge branch 'dev' into nonnegative_predictions_for_deepar-mxnet
melopeo ea3fee5
Merge branch 'dev' into nonnegative_predictions_for_deepar-mxnet
melopeo dfbbb8d
Update test/mx/model/deepar/test_nonnegative_pred_samples.py
melopeo 8da27d2
Update test/mx/model/deepar/test_nonnegative_pred_samples.py
melopeo 2995322
improve tests
40d305b
from F.Actiation to F.relu
4d3a37d
add symbolic testing
68e649c
Merge branch 'dev' into nonnegative_predictions_for_deepar-mxnet
melopeo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). | ||
# You may not use this file except in compliance with the License. | ||
# A copy of the License is located at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
# express or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from gluonts.mx import DeepAREstimator | ||
from gluonts.mx.distribution import StudentTOutput | ||
from gluonts.mx.trainer import Trainer | ||
from gluonts.testutil.dummy_datasets import make_dummy_datasets_with_features | ||
|
||
|
||
@pytest.mark.parametrize("datasets", [make_dummy_datasets_with_features()]) | ||
@pytest.mark.parametrize("distr_output", [StudentTOutput()]) | ||
@pytest.mark.parametrize("dtype", [np.float32, np.float64]) | ||
@pytest.mark.parametrize("impute_missing_values", [False, True]) | ||
@pytest.mark.parametrize("symbol_block_predictor", [False, True]) | ||
def test_deepar_nonnegative_pred_samples( | ||
distr_output, | ||
datasets, | ||
dtype, | ||
impute_missing_values, | ||
symbol_block_predictor, | ||
): | ||
estimator = DeepAREstimator( | ||
distr_output=distr_output, | ||
dtype=dtype, | ||
impute_missing_values=impute_missing_values, | ||
nonnegative_pred_samples=True, | ||
freq="D", | ||
prediction_length=3, | ||
trainer=Trainer(epochs=1, num_batches_per_epoch=1), | ||
) | ||
|
||
dataset_train, dataset_test = datasets | ||
predictor = estimator.train(dataset_train) | ||
|
||
if symbol_block_predictor: | ||
predictor = predictor.as_symbol_block_predictor(dataset=dataset_test) | ||
|
||
forecasts = list(predictor.predict(dataset_test)) | ||
assert all([forecast.samples.dtype == dtype for forecast in forecasts]) | ||
assert len(forecasts) == len(dataset_test) | ||
|
||
for forecast in forecasts: | ||
assert (forecast.samples >= 0).all() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
To ensure the added feature also works in symbolic mode, you can call
as_symbol_block_predictor
on the predictor object, seegluonts/src/gluonts/mx/model/predictor.py
Line 316 in a818f69