Skip to content

Commit

Permalink
Backports for v0.12.1 (#2626)
Browse files Browse the repository at this point in the history
* Fix: torch `PoissonOutput` scaling (#2619)

* Remove `dataclasses` requirement (#2623)

* Fix installation docs, fix typos in docstrings (#2625)

---------

Co-authored-by: Kashif Rasul <[email protected]>
  • Loading branch information
lostella and kashif authored Feb 8, 2023
1 parent 2fc78a4 commit a712ba0
Show file tree
Hide file tree
Showing 23 changed files with 62 additions and 50 deletions.
26 changes: 12 additions & 14 deletions docs/getting_started/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ For production usage, we suggest restricting the version when installing
GluonTS:
```sh
pip install gluonts==0.10.*
pip install gluonts==0.12.*
```
````

Expand All @@ -47,7 +47,7 @@ When installing a package, they are passed via ``[...]`` after the package
name, but before the version specifier:

```sh
pip install some-package[extra-1,extra-2]==version
pip install "some-package[extra-1,extra-2]==version"
````

We make extensive use of optional dependencies in GluonTS to keep the amount of
Expand All @@ -61,7 +61,7 @@ offer the ``arrow``-extra, which installs the required packages and can be
simply enabled using:

```sh
pip install gluonts[arrow]
pip install "gluonts[arrow]"
````
### Models
Expand All @@ -78,7 +78,7 @@ to be installed as well.
Both required dependencies are included in the ``torch``-extra:
```sh
pip install gluonts[torch]
pip install "gluonts[torch]"
````


Expand All @@ -88,7 +88,7 @@ MXNet based models require a version of ``mxnet`` to be installed.

```{note}
MXNet provives different package for CPU and GPU usages. Please refer to its
MXNet provides different package for CPU and GPU usages. Please refer to its
[documentation](https://mxnet.apache.org/versions/1.9.1/get_started?) to
select the right version fitting your use-case.
Expand All @@ -97,7 +97,7 @@ select the right version fitting your use-case.
The ``mxnet``-extra will install a CPU-only version:
```sh
pip install gluonts[mxnet]
pip install "gluonts[mxnet]"
````
Expand All @@ -115,22 +115,20 @@ install the `forecast` package:
R -e 'install.packages(c("forecast", "nnfor"), repos="https://cloud.r-project.org")'
```
In addition, we require rpy2 to be installed:
You will also need to install ``R``-extra dependencies with:
```sh
pip install 'rpy2>=2.9.*,<3.*'
pip install "gluonts[R]"
````
##### Prophet
The [Prophet](https://facebook.github.io/prophet/) forecasting library is
available via `gluonts.model.prophet` and requires the ``prophet`` package to
be installed.
The ``prophet``-extra also depends on it:
be installed. You can get it by installing the ``prophet``-extra:
```sh
pip install gluonts[prophet]
pip install "gluonts[prophet]"
```
Expand Down Expand Up @@ -166,7 +164,7 @@ To utilise these, either install the ``pyarrow`` package or use the
``arrow``-extra:
```sh
pip install gluonts[arrow]
pip install "gluonts[arrow]"
```
### Other
Expand All @@ -177,5 +175,5 @@ The ``shell`` module offers integration with Amazon SageMaker and is available
through:
```sh
pip install gluonts[shell]
pip install "gluonts[shell]"
```
2 changes: 0 additions & 2 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ toolz~=0.10

# used for Protocol, can be removed once Python 3.8 is required
typing-extensions~=4.0

dataclasses
4 changes: 2 additions & 2 deletions src/gluonts/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def equals(this: Any, that: Any) -> bool:
In addition, the function dispatches to specialized implementations based
on the type of the first argument, so the above conditions might be
sticter for certain types.
stricter for certain types.
Parameters
----------
Expand Down Expand Up @@ -112,7 +112,7 @@ def equals_default_impl(this: Any, that: Any) -> bool:
1. Their types match.
2. If their initializer are :func:`validated`, their initializer arguments
are pairlise structurally equal.
are pairwise structurally equal.
3. If their initializer are not :func:`validated`, they are referentially
equal (i.e. ``this == that``).
Expand Down
4 changes: 2 additions & 2 deletions src/gluonts/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def __getitem__(self, key):
raise KeyError(key)

def __getattribute__(self, key):
# We check the key, to check whether we want to acces our chainmap
# We check the key, to check whether we want to access our chainmap
# or handle it as a normal attribute.
if key.startswith("_"):
return super().__getattribute__(key)
Expand Down Expand Up @@ -367,7 +367,7 @@ def _inject(self, *keys, **kwargs):
"""
Dependency injection.
This will inject values from settings if avaiable and not passed
This will inject values from settings if available and not passed
directly::
@settings._inject("foo")
Expand Down
2 changes: 1 addition & 1 deletion src/gluonts/dataset/arrow/enc.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _encode_py_to_arrow(val):


@_encode_py_to_arrow.register
def _encode_py_pd_preiod(val: pd.Period):
def _encode_py_pd_period(val: pd.Period):
return val.to_timestamp()


Expand Down
2 changes: 1 addition & 1 deletion src/gluonts/dataset/artificial/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def compute_data_from_recipe(
max_train_length=max_train_length,
prediction_length=self.prediction_length,
# Add 1 time series at a time in the loop for different constant
# valus per time series
# values per time series
num_timeseries=1,
)
generated = data.generate()
Expand Down
12 changes: 6 additions & 6 deletions src/gluonts/dataset/hierarchical.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class HierarchicalTimeSeries:
corresponding to the leaves of the hierarchy.
S
Summation or aggregation matrix whose ordering should be consistent
with the orderig of the columns of `ts_at_all_levels`.
with the ordering of the columns of `ts_at_all_levels`.
In particular, the bottom `k x k` sub-matrix should be identity matrix,
where `k` is the number of leaves of the hierarchy.
"""
Expand Down Expand Up @@ -109,7 +109,7 @@ def aggregate_ts(
corresponding to the leaves of the hierarchy.
S
Summation or aggregation matrix whose ordering should be consistent
with the orderig of the columns of `ts_at_all_levels`.
with the ordering of the columns of `ts_at_all_levels`.
In particular, the bottom `k x k` sub-matrix should be an identity
matrix, where `k` is the number of leaves of the hierarchy.
Expand All @@ -128,7 +128,7 @@ def aggregate_ts(
f"{ts_at_bottom_level.shape}."
)

# Last `num_bottom_ts` rows contain the identity marix.
# Last `num_bottom_ts` rows contain the identity matrix.
assert (S[num_agg_ts:, :] == np.eye(num_bottom_ts)).all(), (
f"The last {num_bottom_ts} rows of aggregation matrix `S`"
f" should contain Identity matrix."
Expand Down Expand Up @@ -168,7 +168,7 @@ def to_dataset(
----------
feat_dynamic_real
A pandas dataframe containing dynamic features as columns.
Note that features of any (or all) time series in the hierachy
Note that features of any (or all) time series in the hierarchy
can be passed here, since all time series are considered together
as a single multivariate time series.
Expand All @@ -184,7 +184,7 @@ def to_dataset(
self.ts_at_all_levels.index[0] == feat_dynamic_real.index[0]
), (
"The staring time point of dynamic features should match "
"with that of the hierarhical time series. "
"with that of the hierarchical time series. "
f"Start of `feat_dynamic_real`: "
f"{feat_dynamic_real.index[0]} and "
f"the start of hierarchical time series: "
Expand All @@ -194,7 +194,7 @@ def to_dataset(
assert feat_dynamic_real.index.intersection(
self.ts_at_all_levels.index
).equals(self.ts_at_all_levels.index), (
"Dynamic features should be provied for all time "
"Dynamic features should be provided for all time "
"points where the target is defined. "
f"Index of `feat_dynamic_real`: {feat_dynamic_real.index}, \n"
f"Index of `ts_at_all_levels` of `hts`: "
Expand Down
2 changes: 1 addition & 1 deletion src/gluonts/dataset/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def from_long_dataframe(
Returns
-------
PandasDataset
Gluonts dataset based on ``pandas.DataFrame``s.
Dataset containing series data from the given long dataframe.
"""
if not isinstance(dataframe.index, DatetimeIndexOpsMixin):
dataframe.index = pd.to_datetime(dataframe.index)
Expand Down
2 changes: 1 addition & 1 deletion src/gluonts/ev/aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Mean(Aggregation):
`partial_result` represents one of two things, depending on the axis:
Case 1 - axis 0 is aggregated (axis is None or 0):
First sum values acoording to axis and keep track of number of entries
First sum values according to axis and keep track of number of entries
summed over (`n`) to divide by in the end.
Case 2 - axis 0 is not being aggregated:
Expand Down
2 changes: 1 addition & 1 deletion src/gluonts/evaluation/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def get_metrics_per_ts(
)
}
except Exception:
logging.warning(f"Error occured when evaluating {k}.")
logging.warning(f"Error occurred when evaluating {k}.")
val = {k: np.nan}

metrics.update(val)
Expand Down
4 changes: 2 additions & 2 deletions src/gluonts/ext/rotbaum/_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,15 @@ def _pre_transform(
time_series_window: list
subtract_mean: bool
Whether or not to subtract the mean of the context window in the
feaurization process.
featurization process.
count_nans: bool
Whether or not to add as a feature the number of nan values in the
context window.
Returns
-------------
tuple
trasnformed time series, dictionary with transformation data (
Transformed time series, dictionary with transformation data (
std, mean, number of lag features, and number of nans of
count_nans)
"""
Expand Down
2 changes: 1 addition & 1 deletion src/gluonts/mx/trainer/learning_rate_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def reset(self) -> None:

def step(self, metric_value: float) -> bool:
if self.exceeded:
raise RuntimeError("Patience alread exceeded.")
raise RuntimeError("Patience already exceeded.")

has_improved = self.objective.update(metric_value)

Expand Down
2 changes: 1 addition & 1 deletion src/gluonts/mx/trainer/model_iteration_averaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def __init__(
epochs
The total number of epochs.
n
The non-montone interval.
The non-monotone interval.
maximize
Whether to maximize or minimize the validation metric.
eta
Expand Down
2 changes: 1 addition & 1 deletion src/gluonts/mx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class HybridContext:
The network whose hybrid mode has to be modified within the enclosing
context.
hybridize
A boolean flag inidicating whether the hybrid mode should be set or
A boolean flag indicating whether the hybrid mode should be set or
not.
kwargs
A dictionary of optional arguments to pass to the `hybridize()` call
Expand Down
16 changes: 16 additions & 0 deletions src/gluonts/torch/distributions/distribution_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,22 @@ def domain_map(cls, rate: torch.Tensor):
rate_pos = F.softplus(rate).clone()
return (rate_pos.squeeze(-1),)

# Overwrites the parent class method. We cannot scale using the affine
# transformation since Poisson should return integers. Instead we scale
# the parameters.
def distribution(
self,
distr_args,
loc: Optional[torch.Tensor] = None,
scale: Optional[torch.Tensor] = None,
) -> Distribution:
(rate,) = distr_args

if scale is not None:
rate *= scale

return Poisson(rate=rate)

@property
def event_shape(self) -> Tuple:
return ()
Expand Down
8 changes: 4 additions & 4 deletions src/gluonts/torch/model/deep_npts/_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def forward(self, features: torch.Tensor):
class DeepNPTSNetwork(nn.Module):
"""Base class implementing a simple feed-forward neural network that takes
in static and dynamic features and produces `num_hidden_nodes` independent
outptus. These outputs are then used by derived classes to construct the
outputs. These outputs are then used by derived classes to construct the
forecast distribution for a single time step.
Note that the dynamic features are just treated as independent features
Expand Down Expand Up @@ -211,7 +211,7 @@ def forward(
class DeepNPTSNetworkDiscrete(DeepNPTSNetwork):
"""
Extends `DeepNTPSNetwork` by implementing the output layer which
converts the ouptuts from the base network into probabilities of length
converts the outputs from the base network into probabilities of length
`context_length`. These probabilities together with the past values in the
context window constitute the one-step-ahead forecast distribution.
Specifically, the forecast is always one of the values observed in the
Expand Down Expand Up @@ -270,7 +270,7 @@ def forward(
class DeepNPTSNetworkSmooth(DeepNPTSNetwork):
"""
Extends `DeepNTPSNetwork` by implementing the output layer which
converts the ouptuts from the base network into a smoothed mixture
converts the outputs from the base network into a smoothed mixture
distribution. The components of the mixture are Gaussians centered around
the observations in the context window. The mixing probabilities as well as
the width of the Gaussians are predicted by the network.
Expand Down Expand Up @@ -320,7 +320,7 @@ def forward(

class DeepNPTSMultiStepNetwork(nn.Module):
"""
Implements multi-step prediction given a trained `DeepNPTSNewtork` model
Implements multi-step prediction given a trained `DeepNPTSNetwork` model
that outputs one-step-ahead forecast distribution.
"""

Expand Down
2 changes: 1 addition & 1 deletion src/gluonts/torch/model/deepar/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def forward(
(Optional) tensor of dynamic real features in the past,
shape: ``(batch_size, prediction_length, num_feat_dynamic_real)``.
num_parallel_samples
How many future sampels to produce.
How many future samples to produce.
By default, self.num_parallel_samples is used.
"""
if num_parallel_samples is None:
Expand Down
2 changes: 1 addition & 1 deletion src/gluonts/torch/model/mqf2/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def forward(
Parameters
----------
feat_static_cat
Static categorial features (batch_size, num_feat_static_cat)
Static categorical features (batch_size, num_feat_static_cat)
feat_static_real
Static real-valued features (batch_size, num_feat_static_real)
past_time_feat
Expand Down
4 changes: 2 additions & 2 deletions src/gluonts/torch/model/simple_feedforward/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

class SimpleFeedForwardEstimator(PyTorchLightningEstimator):
"""
An estimator training a feedforward model for forecasting.
An estimator training a feed-forward model for forecasting.
This class is uses the model defined in ``SimpleFeedForwardModel``,
and wraps it into a ``SimpleFeedForwardLightningModule`` for training
Expand All @@ -73,7 +73,7 @@ class SimpleFeedForwardEstimator(PyTorchLightningEstimator):
Number of time steps prior to prediction time that the model
takes as inputs (default: ``10 * prediction_length``).
hidden_dimensions
Size of hidden layers in the feedforward network
Size of hidden layers in the feed-forward network
(default: ``[20, 20]``).
lr
Learning rate (default: ``1e-3``).
Expand Down
2 changes: 1 addition & 1 deletion src/gluonts/torch/model/simple_feedforward/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SimpleFeedForwardModel(nn.Module):
context_length
Number of time steps prior to prediction time that the model.
hidden_dimensions
Size of hidden layers in the feedforward network.
Size of hidden layers in the feed-forward network.
distr_output
Distribution to use to evaluate observations and sample predictions.
Default: ``StudentTOutput()``.
Expand Down
2 changes: 1 addition & 1 deletion src/gluonts/transform/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def _empirical_cdf_forward_transform(
Returns
-------
quantiles
Empirical CDF quantiles in [0, 1] interval with winzorized cutoff.
Empirical CDF quantiles in [0, 1] interval with winsorized cutoff.
"""
m = sorted_values.shape[0]
quantiles = self._forward_transform(
Expand Down
Loading

0 comments on commit a712ba0

Please sign in to comment.