Skip to content

Commit

Permalink
Backports v0.10.7 (#2326)
Browse files Browse the repository at this point in the history
Co-authored-by: Jasper <[email protected]>
Co-authored-by: Sigrid Passano Hellan <[email protected]>
  • Loading branch information
3 people authored Sep 27, 2022
1 parent c0463d4 commit 470c337
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 21 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
[![GitHub](https://img.shields.io/github/license/awslabs/gluonts.svg?style=flat-square&color=df7e66)](./LICENSE)
[![Static](https://img.shields.io/static/v1?label=docs&message=stable&color=edc775&style=flat-square)](https://ts.gluon.ai/)
[![Static](https://img.shields.io/static/v1?label=docs&message=dev&color=edc775&style=flat-square)](https://ts.gluon.ai/dev/)
[![PyPI Downloads](https://img.shields.io/pypi/dm/gluonts?style=flat-square&color=94b594)](https://pypi.org/project/gluonts/)
[![PyPI Downloads](https://img.shields.io/pypi/dm/gluonts?style=flat-square&color=94b594)](https://pepy.tech/project/gluonts)

GluonTS is a Python package for probabilistic time series modeling, focusing on deep learning based models.
GluonTS is a Python package for probabilistic time series modeling, focusing on deep learning based models, based on PyTorch and MXNet.


## Installation
Expand All @@ -17,10 +17,10 @@ GluonTS requires Python 3.6 or newer, and the easiest way to install it is via `

```bash
# support for mxnet models, faster datasets
pip install gluonts[mxnet,pro]
pip install "gluonts[mxnet,pro]"

# support for torch models, faster datasets
pip install gluonts[torch,pro]
pip install "gluonts[torch,pro]"
```

## Simple Example
Expand All @@ -35,6 +35,7 @@ of data.


```py
import matplotlib.pyplot as plt
from gluonts.dataset.util import to_pandas
from gluonts.dataset.pandas import PandasDataset
from gluonts.dataset.repository.datasets import get_dataset
Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ apidoc:

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: apidoc Makefile
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
6 changes: 6 additions & 0 deletions docs/_static/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
.sidebar-brand-text, .hide-on-website {
display: none;
}

@media (prefers-color-scheme: dark) {
body:not([data-theme="light"]) .highlight {
border-left: 2px solid #94b594;
}
}
13 changes: 13 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "default"
pygments_dark_style = "gluonts-dark"

# -- Options for HTML output -------------------------------------------------

Expand All @@ -79,6 +80,18 @@
"color-announcement-text": colors.GREEN,
"color-announcement-background": "var(--color-background-secondary)",
},
"footer_icons": [
{
"name": "GitHub",
"url": "https://github.com/awslabs/gluonts/",
"html": """
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path>
</svg>
""",
"class": "",
},
],
}

if os.environ.get("GITHUB_REF_NAME") == "dev":
Expand Down
16 changes: 6 additions & 10 deletions docs/tutorials/forecasting/quick_start_tutorial.md.template
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# Quick Start Tutorial

The GluonTS toolkit contains components and tools for building time series models using MXNet. The models that are currently included are forecasting models but the components also support other time series use cases, such as classification or anomaly detection.

The toolkit is not intended as a forecasting solution for businesses or end users but it rather targets scientists and engineers who want to tweak algorithms or build and experiment with their own models.

GluonTS contains:

* A number of pre-built models
* Components for building new models (likelihoods, feature processing pipelines, calendar features etc.)
* Data loading and processing
* A number of pre-built models
* Plotting and evaluation facilities
* Artificial and real datasets (only external datasets with blessed license)

Expand Down Expand Up @@ -49,7 +45,7 @@ dataset = get_dataset("m4_hourly")

In general, the datasets provided by GluonTS are objects that consists of three main members:

- `dataset.train` is an iterable collection of data entries used for training. Each entry corresponds to one time series
- `dataset.train` is an iterable collection of data entries used for training. Each entry corresponds to one time series.
- `dataset.test` is an iterable collection of data entries used for inference. The test dataset is an extended version of the train dataset that contains a window in the end of each time series that was not seen during training. This window has length equal to the recommended prediction length.
- `dataset.metadata` contains metadata of the dataset such as the frequency of the time series, a recommended prediction horizon, associated features, etc.

Expand Down Expand Up @@ -122,7 +118,7 @@ GluonTS comes with a number of pre-built models. All the user needs to do is con

We will begin with GluonTS's pre-built feedforward neural network estimator, a simple but powerful forecasting model. We will use this model to demonstrate the process of training a model, producing forecasts, and evaluating the results.

GluonTS's built-in feedforward neural network (`SimpleFeedForwardEstimator`) accepts an input window of length `context_length` and predicts the distribution of the values of the subsequent `prediction_length` values. In GluonTS parlance, the feedforward neural network model is an example of `Estimator`. In GluonTS, `Estimator` objects represent a forecasting model as well as details such as its coefficients, weights, etc.
GluonTS's built-in feedforward neural network (`SimpleFeedForwardEstimator`) accepts an input window of length `context_length` and predicts the distribution of the values of the subsequent `prediction_length` values. In GluonTS parlance, the feedforward neural network model is an example of an `Estimator`. In GluonTS, `Estimator` objects represent a forecasting model as well as details such as its coefficients, weights, etc.

In general, each estimator (pre-built or custom) is configured by a number of hyperparameters that can be either common (but not binding) among all estimators (e.g., the `prediction_length`) or specific for the particular estimator (e.g., number of layers for a neural network or the stride in a CNN).

Expand Down Expand Up @@ -214,7 +210,7 @@ dataset_test_entry = next(iter(dataset.test))
dataset_test_entry['target'][:5]
```

The entries in the `forecast` list are a bit more complex. They are objects that contain all the sample paths in the form of `numpy.ndarray` with dimension `(num_samples, prediction_length)`, the start date of the forecast, the frequency of the time series, etc. We can access all these information by simply invoking the corresponding attribute of the forecast object.
The entries in the `forecast` list are a bit more complex. They are objects that contain all the sample paths in the form of `numpy.ndarray` with dimension `(num_samples, prediction_length)`, the start date of the forecast, the frequency of the time series, etc. We can access all this information by simply invoking the corresponding attribute of the forecast object.


```python
Expand All @@ -230,7 +226,7 @@ print(f"Start date of the forecast window: {forecast_entry.start_date}")
print(f"Frequency of the time series: {forecast_entry.freq}")
```

We can also do calculations to summarize the sample paths, such computing the mean or a quantile for each of the 48 time steps in the forecast window.
We can also do calculations to summarize the sample paths, such as computing the mean or a quantile for each of the 48 time steps in the forecast window.


```python
Expand Down Expand Up @@ -273,7 +269,7 @@ evaluator = Evaluator(quantiles=[0.1, 0.5, 0.9])
agg_metrics, item_metrics = evaluator(tss, forecasts)
```

Aggregate metrics aggregate both across time-steps and across time series.
The aggregate metrics, `agg_metrics`, aggregate both across time-steps and across time series.


```python
Expand Down
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ def run(self):
"shell": shell_require,
"torch": torch_require,
},
entry_points=dict(
gluonts_forecasters=[
entry_points={
"gluonts_forecasters": [
"deepar=gluonts.model.deepar:DeepAREstimator",
"DeepAR=gluonts.model.deepar:DeepAREstimator",
"DeepFactor=gluonts.model.deep_factor:DeepFactorEstimator",
Expand Down Expand Up @@ -281,8 +281,11 @@ def run(self):
"WaveNet=gluonts.model.wavenet:WaveNetEstimator",
# "r=gluonts.model.r_forecast:RForecastPredictor [R]",
# "prophet=gluonts.model.prophet:ProphetPredictor [Prophet]",
],
"pygments.styles": [
"gluonts-dark=gluonts.meta.style:Dark",
]
),
},
cmdclass={
"type_check": TypeCheckCommand,
"style_check": StyleCheckCommand,
Expand Down
45 changes: 45 additions & 0 deletions src/gluonts/meta/style.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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.

from pygments.style import Style
from pygments.token import Comment, Keyword, Name, String, Number, Operator

from . import colors


class Dark(Style):
# transparent
background_color = "rgba(0, 0, 0, 0.0)"

styles = {
Comment: "italic #888",
Comment.Preproc: "noitalic #888",
Keyword: f"bold {colors.SALMON}",
Keyword.Pseudo: "nobold",
Keyword.Type: f"nobold {colors.SALMON}",
Operator: f"bold {colors.SALMON}",
Operator.Word: f"bold {colors.SALMON}",
Name.Builtin: colors.YELLOW,
Name.Function: f"{colors.GREEN}",
Name.Class: f"bold {colors.GREEN}",
Name.Namespace: f"bold {colors.GREEN}",
Name.Variable: colors.YELLOW,
Name.Constant: colors.RED,
Name.Label: colors.YELLOW,
Name.Attribute: colors.YELLOW,
Name.Tag: f"bold {colors.SALMON}",
Name.Decorator: colors.SALMON,
String: colors.SALMON,
String.Doc: "italic",
Number: colors.GREEN,
}
3 changes: 1 addition & 2 deletions src/gluonts/model/seq2seq/_mq_dnn_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,8 @@ def __init__(
assert dilation_seq is None or all(
d > 0 for d in dilation_seq
), "Elements of `dilation_seq` should be > 0"
# TODO: add support for kernel size=1
assert kernel_size_seq is None or all(
d > 1 for d in kernel_size_seq
d > 0 for d in kernel_size_seq
), "Elements of `kernel_size_seq` should be > 0"
assert quantiles is None or all(
0 <= d <= 1 for d in quantiles
Expand Down
3 changes: 2 additions & 1 deletion src/gluonts/mx/block/cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def hybrid_forward(self, F, data: Tensor) -> Tensor:
"""
ct = self.conv1d(data)
if self.kernel_size > 0:
ct = F.slice_axis(ct, axis=2, begin=0, end=-self.padding)
end_ = -self.padding if self.padding != 0 else None
ct = F.slice_axis(ct, axis=2, begin=0, end=end_)
return ct


Expand Down

0 comments on commit 470c337

Please sign in to comment.