Skip to content

Commit 4126386

Browse files
kashifJasper Zschiegner
andauthored
Remove mandatory freq attribute of Predictor. (#2017)
* Remove freq from Predictor Co-authored-by: Jasper Zschiegner <schjaspe@amazon.de>
1 parent 2784ac0 commit 4126386

File tree

81 files changed

+112
-288
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+112
-288
lines changed

docs/tutorials/advanced_topics/howto_pytorch_lightning.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def mean_abs_scaling(context, min_scale=1e-5):
7171
class FeedForwardNetwork(nn.Module):
7272
def __init__(
7373
self,
74-
freq: str,
7574
prediction_length: int,
7675
context_length: int,
7776
hidden_dimensions: List[int],
@@ -85,7 +84,6 @@ class FeedForwardNetwork(nn.Module):
8584
assert context_length > 0
8685
assert len(hidden_dimensions) > 0
8786

88-
self.freq = freq
8987
self.prediction_length = prediction_length
9088
self.context_length = context_length
9189
self.hidden_dimensions = hidden_dimensions
@@ -123,7 +121,6 @@ class FeedForwardNetwork(nn.Module):
123121
def get_predictor(self, input_transform, batch_size=32, device=None):
124122
return PyTorchPredictor(
125123
prediction_length=self.prediction_length,
126-
freq=self.freq,
127124
input_names=["past_target"],
128125
prediction_net=self,
129126
batch_size=batch_size,
@@ -168,7 +165,6 @@ We can now instantiate the training network, and explore its set of parameters.
168165

169166

170167
```python
171-
freq = "1H"
172168
context_length = 2 * 7 * 24
173169
prediction_length = dataset.metadata.prediction_length
174170
hidden_dimensions = [96, 48]
@@ -177,7 +173,6 @@ hidden_dimensions = [96, 48]
177173

178174
```python
179175
net = LightningFeedForwardNetwork(
180-
freq=freq,
181176
prediction_length=prediction_length,
182177
context_length=context_length,
183178
hidden_dimensions=hidden_dimensions,

docs/tutorials/advanced_topics/trainer_callbacks.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ from gluonts.mx.trainer.callback import TrainingHistory
2626
history = TrainingHistory()
2727

2828
trainer = Trainer(epochs=3, callbacks=[history])
29-
estimator = SimpleFeedForwardEstimator(prediction_length=prediction_length, freq=freq, trainer=trainer)
29+
estimator = SimpleFeedForwardEstimator(prediction_length=prediction_length, trainer=trainer)
3030

3131
predictor = estimator.train(dataset.train, num_workers=None)
3232
```
@@ -49,7 +49,7 @@ warm_start = WarmStart(predictor=predictor)
4949

5050
trainer=Trainer(epochs=3, callbacks=[history, warm_start])
5151

52-
estimator = SimpleFeedForwardEstimator(prediction_length=prediction_length, freq=freq, trainer=trainer)
52+
estimator = SimpleFeedForwardEstimator(prediction_length=prediction_length, trainer=trainer)
5353

5454
predictor = estimator.train(dataset.train, num_workers=None)
5555
```
@@ -222,7 +222,7 @@ Note that we're running an extremely short number of epochs, simply to keep the
222222
feel free to increase the number of epochs to properly test the effectiveness of the callback.
223223

224224
```python
225-
estimator = SimpleFeedForwardEstimator(prediction_length=prediction_length, freq=freq)
225+
estimator = SimpleFeedForwardEstimator(prediction_length=prediction_length)
226226
training_network = estimator.create_training_network()
227227
transformation = estimator.create_transformation()
228228

docs/tutorials/data_manipulation/synthetic_data_generation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ print_dicts(
128128
)
129129
```
130130

131-
Note that you may create and use intermediate random varibles such as `stddev2` in the above example without including them in the output.
131+
Note that you may create and use intermediate random variables such as `stddev2` in the above example without including them in the output.
132132

133133

134134
```python

docs/tutorials/forecasting/extended_tutorial.md

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ GluonTS comes with a number of pre-built models. All the user needs to do is con
563563

564564
### Configuring an estimator
565565

566-
We will begin with GulonTS'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.
566+
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.
567567

568568
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.
569569

@@ -583,7 +583,6 @@ estimator = SimpleFeedForwardEstimator(
583583
num_hidden_dimensions=[10],
584584
prediction_length=custom_ds_metadata['prediction_length'],
585585
context_length=2*custom_ds_metadata['prediction_length'],
586-
freq=custom_ds_metadata['freq'],
587586
trainer=Trainer(
588587
ctx="cpu",
589588
epochs=5,
@@ -788,7 +787,7 @@ The estimator should also include the following methods:
788787
- `create_transformation`, defining all the data pre-processing transformations (like adding features)
789788
- `create_training_data_loader`, constructing the data loader that gives batches to be used in training, out of a given dataset
790789
- `create_training_network`, returning the training network configured with any necessary hyperparameters
791-
- `create_predictor`, creting the prediction network, and returning a `Predictor` object
790+
- `create_predictor`, creating the prediction network, and returning a `Predictor` object
792791

793792
If a validation dataset is to be accepted, for some validation metric to be computed, then also the following should be defined:
794793

@@ -871,15 +870,13 @@ class MyEstimator(GluonEstimator):
871870
self,
872871
prediction_length: int,
873872
context_length: int,
874-
freq: str,
875873
num_cells: int,
876874
batch_size: int = 32,
877875
trainer: Trainer = Trainer()
878876
) -> None:
879877
super().__init__(trainer=trainer, batch_size=batch_size)
880878
self.prediction_length = prediction_length
881879
self.context_length = context_length
882-
self.freq = freq
883880
self.num_cells = num_cells
884881

885882
def create_transformation(self):
@@ -937,7 +934,6 @@ class MyEstimator(GluonEstimator):
937934
input_transform=transformation + prediction_splitter,
938935
prediction_net=prediction_network,
939936
batch_size=self.trainer.batch_size,
940-
freq=self.freq,
941937
prediction_length=self.prediction_length,
942938
ctx=self.trainer.ctx,
943939
)
@@ -950,7 +946,6 @@ After defining the training and prediction network, as well as the estimator cla
950946
estimator = MyEstimator(
951947
prediction_length=custom_ds_metadata['prediction_length'],
952948
context_length=2*custom_ds_metadata['prediction_length'],
953-
freq=custom_ds_metadata['freq'],
954949
num_cells=40,
955950
trainer=Trainer(
956951
ctx="cpu",
@@ -1104,7 +1099,6 @@ class MyProbEstimator(GluonEstimator):
11041099
self,
11051100
prediction_length: int,
11061101
context_length: int,
1107-
freq: str,
11081102
distr_output: DistributionOutput,
11091103
num_cells: int,
11101104
num_sample_paths: int = 100,
@@ -1114,7 +1108,6 @@ class MyProbEstimator(GluonEstimator):
11141108
super().__init__(trainer=trainer, batch_size=batch_size)
11151109
self.prediction_length = prediction_length
11161110
self.context_length = context_length
1117-
self.freq = freq
11181111
self.distr_output = distr_output
11191112
self.num_cells = num_cells
11201113
self.num_sample_paths = num_sample_paths
@@ -1178,7 +1171,6 @@ class MyProbEstimator(GluonEstimator):
11781171
input_transform=transformation + prediction_splitter,
11791172
prediction_net=prediction_network,
11801173
batch_size=self.trainer.batch_size,
1181-
freq=self.freq,
11821174
prediction_length=self.prediction_length,
11831175
ctx=self.trainer.ctx,
11841176
)
@@ -1189,7 +1181,6 @@ class MyProbEstimator(GluonEstimator):
11891181
estimator = MyProbEstimator(
11901182
prediction_length=custom_ds_metadata['prediction_length'],
11911183
context_length=2*custom_ds_metadata['prediction_length'],
1192-
freq=custom_ds_metadata['freq'],
11931184
distr_output=GaussianOutput(),
11941185
num_cells=40,
11951186
trainer=Trainer(
@@ -1369,7 +1360,6 @@ class MyProbEstimator(GluonEstimator):
13691360
self,
13701361
prediction_length: int,
13711362
context_length: int,
1372-
freq: str,
13731363
distr_output: DistributionOutput,
13741364
num_cells: int,
13751365
num_sample_paths: int = 100,
@@ -1380,7 +1370,6 @@ class MyProbEstimator(GluonEstimator):
13801370
super().__init__(trainer=trainer, batch_size=batch_size)
13811371
self.prediction_length = prediction_length
13821372
self.context_length = context_length
1383-
self.freq = freq
13841373
self.distr_output = distr_output
13851374
self.num_cells = num_cells
13861375
self.num_sample_paths = num_sample_paths
@@ -1461,7 +1450,6 @@ class MyProbEstimator(GluonEstimator):
14611450
input_transform=transformation + prediction_splitter,
14621451
prediction_net=prediction_network,
14631452
batch_size=self.trainer.batch_size,
1464-
freq=self.freq,
14651453
prediction_length=self.prediction_length,
14661454
ctx=self.trainer.ctx,
14671455
)
@@ -1472,7 +1460,6 @@ class MyProbEstimator(GluonEstimator):
14721460
estimator = MyProbEstimator(
14731461
prediction_length=custom_ds_metadata['prediction_length'],
14741462
context_length=2*custom_ds_metadata['prediction_length'],
1475-
freq=custom_ds_metadata['freq'],
14761463
distr_output=GaussianOutput(),
14771464
num_cells=40,
14781465
trainer=Trainer(
@@ -1747,7 +1734,6 @@ class MyProbRNNEstimator(GluonEstimator):
17471734
self,
17481735
prediction_length: int,
17491736
context_length: int,
1750-
freq: str,
17511737
distr_output: DistributionOutput,
17521738
num_cells: int,
17531739
num_layers: int,
@@ -1759,7 +1745,6 @@ class MyProbRNNEstimator(GluonEstimator):
17591745
super().__init__(trainer=trainer, batch_size=batch_size)
17601746
self.prediction_length = prediction_length
17611747
self.context_length = context_length
1762-
self.freq = freq
17631748
self.distr_output = distr_output
17641749
self.num_cells = num_cells
17651750
self.num_layers = num_layers
@@ -1842,7 +1827,6 @@ class MyProbRNNEstimator(GluonEstimator):
18421827
input_transform=transformation + prediction_splitter,
18431828
prediction_net=prediction_network,
18441829
batch_size=self.trainer.batch_size,
1845-
freq=self.freq,
18461830
prediction_length=self.prediction_length,
18471831
ctx=self.trainer.ctx,
18481832
)
@@ -1853,7 +1837,6 @@ class MyProbRNNEstimator(GluonEstimator):
18531837
estimator = MyProbRNNEstimator(
18541838
prediction_length=24,
18551839
context_length=48,
1856-
freq="1H",
18571840
num_cells=40,
18581841
num_layers=2,
18591842
distr_output=GaussianOutput(),

docs/tutorials/forecasting/quick_start_tutorial.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ test_ds = ListDataset(
120120

121121
GluonTS comes with a number of pre-built models. All the user needs to do is configure some hyperparameters. The existing models focus on (but are not limited to) probabilistic forecasting. Probabilistic forecasts are predictions in the form of a probability distribution, rather than simply a single point estimate.
122122

123-
We will begin with GulonTS'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.
123+
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.
124124

125125
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.
126126

@@ -140,7 +140,6 @@ estimator = SimpleFeedForwardEstimator(
140140
num_hidden_dimensions=[10],
141141
prediction_length=dataset.metadata.prediction_length,
142142
context_length=100,
143-
freq=dataset.metadata.freq,
144143
trainer=Trainer(
145144
ctx="cpu",
146145
epochs=5,

examples/GluonTS_SageMaker_SDK_Tutorial.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@
406406
"source": [
407407
"my_estimator = SimpleFeedForwardEstimator(\n",
408408
" prediction_length=prediction_length,\n",
409-
" freq=freq,\n",
410409
" trainer=Trainer(ctx=general_instance_type, epochs=5) # optional\n",
411410
" )"
412411
]

examples/evaluate_model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
estimator = SimpleFeedForwardEstimator(
3333
prediction_length=dataset.metadata.prediction_length,
34-
freq=dataset.metadata.freq,
3534
trainer=Trainer(epochs=5, num_batches_per_epoch=10),
3635
)
3736

examples/persist_model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
estimator = SimpleFeedForwardEstimator(
3131
prediction_length=dataset.metadata.prediction_length,
32-
freq=dataset.metadata.freq,
3332
trainer=Trainer(epochs=5, num_batches_per_epoch=10),
3433
)
3534

examples/run_rolling_forecast_backtest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
estimator = SimpleFeedForwardEstimator(
3030
prediction_length=dataset.metadata.prediction_length,
31-
freq=dataset.metadata.freq,
3231
trainer=Trainer(epochs=5, num_batches_per_epoch=10),
3332
)
3433

examples/warm_start.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
# First train a model
3232
estimator = SimpleFeedForwardEstimator(
3333
prediction_length=dataset.metadata.prediction_length,
34-
freq=dataset.metadata.freq,
3534
trainer=Trainer(epochs=10, num_batches_per_epoch=10),
3635
)
3736

@@ -46,7 +45,6 @@ def copy_params(net):
4645

4746
estimator = SimpleFeedForwardEstimator(
4847
prediction_length=dataset.metadata.prediction_length,
49-
freq=dataset.metadata.freq,
5048
trainer=Trainer(
5149
epochs=5, num_batches_per_epoch=10, post_initialize_cb=copy_params
5250
),

0 commit comments

Comments
 (0)