|
| 1 | +"""NBeats package container.""" |
| 2 | + |
| 3 | +from pytorch_forecasting.base._base_pkg import Base_pkg |
| 4 | + |
| 5 | + |
| 6 | +class NBeats_pkg_v2(Base_pkg): |
| 7 | + """NBeats package container.""" |
| 8 | + |
| 9 | + _tags = { |
| 10 | + "info:name": "NBeats", |
| 11 | + "authors": ["jdb78"], |
| 12 | + "capability:exogenous": False, |
| 13 | + "capability:multivariate": False, |
| 14 | + "capability:pred_int": True, |
| 15 | + "capability:flexible_history_length": False, |
| 16 | + } |
| 17 | + |
| 18 | + @classmethod |
| 19 | + def get_cls(cls): |
| 20 | + """Get model class.""" |
| 21 | + from pytorch_forecasting.models.nbeats._nbeats_v2 import NBeats |
| 22 | + |
| 23 | + return NBeats |
| 24 | + |
| 25 | + @classmethod |
| 26 | + def get_datamodule_cls(cls): |
| 27 | + """Get the underlying DataModule class.""" |
| 28 | + from pytorch_forecasting.data.data_module import ( |
| 29 | + EncoderDecoderTimeSeriesDataModule, |
| 30 | + ) |
| 31 | + |
| 32 | + return EncoderDecoderTimeSeriesDataModule |
| 33 | + |
| 34 | + @classmethod |
| 35 | + def get_test_train_params(cls): |
| 36 | + """Return testing parameter settings for the trainer. |
| 37 | +
|
| 38 | + Returns |
| 39 | + ------- |
| 40 | + params : dict or list of dict, default = {} |
| 41 | + Parameters to create testing instances of the class |
| 42 | + Each dict are parameters to construct an "interesting" test instance, i.e., |
| 43 | + `MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance. |
| 44 | + `create_test_instance` uses the first (or only) dictionary in `params` |
| 45 | + """ |
| 46 | + from pytorch_forecasting.metrics import QuantileLoss |
| 47 | + |
| 48 | + params = [ |
| 49 | + {}, |
| 50 | + dict( |
| 51 | + stack_types=["generic"], |
| 52 | + num_blocks=[1], |
| 53 | + num_block_layers=[4], |
| 54 | + widths=[16], |
| 55 | + backcast_loss_ratio=1.0, |
| 56 | + ), |
| 57 | + dict( |
| 58 | + stack_types=["trend", "seasonality"], |
| 59 | + num_blocks=[2, 2], |
| 60 | + widths=[16, 32], |
| 61 | + backcast_loss_ratio=0.5, |
| 62 | + ), |
| 63 | + dict( |
| 64 | + loss=QuantileLoss(quantiles=[0.1, 0.5, 0.9]), |
| 65 | + stack_types=["generic"], |
| 66 | + num_blocks=[1], |
| 67 | + widths=[16], |
| 68 | + ), |
| 69 | + ] |
| 70 | + |
| 71 | + default_dm_cfg = {"max_encoder_length": 8, "max_prediction_length": 2} |
| 72 | + |
| 73 | + for param in params: |
| 74 | + current_dm_cfg = param.get("datamodule_cfg", {}) |
| 75 | + default_dm_cfg.update(current_dm_cfg) |
| 76 | + |
| 77 | + param["datamodule_cfg"] = default_dm_cfg |
| 78 | + |
| 79 | + return params |
0 commit comments