Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions pytorch_forecasting/models/mlp/_decodermlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,53 @@ class DecoderMLP(BaseModelWithCovariates):
"""MLP on the decoder.

MLP that predicts output only based on information available in the decoder.

Examples
--------
Train on a small synthetic time series and make predictions:

>>> import pandas as pd
>>> import torch
>>> from lightning.pytorch import Trainer
>>> from pytorch_forecasting import DecoderMLP, TimeSeriesDataSet
>>> _ = torch.manual_seed(0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a specific reason for setting a seed here? I mean it is just an example, it doesnt need to be reproducible :)

>>> data = pd.DataFrame(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also use stallion dataset here?

... {
... "time_idx": range(12),
... "series": ["A"] * 12,
... "target": [float(i) for i in range(12)],
... }
... )
>>> dataset = TimeSeriesDataSet(
... data,
... time_idx="time_idx",
... target="target",
... group_ids=["series"],
... max_encoder_length=4,
... max_prediction_length=2,
... time_varying_known_reals=["time_idx"],
... time_varying_unknown_reals=["target"],
... )
>>> dataloader = dataset.to_dataloader(train=True, batch_size=4, num_workers=0)
>>> model = DecoderMLP.from_dataset(
... dataset, hidden_size=8, n_hidden_layers=1, dropout=0.0
... )
>>> trainer_kwargs = dict(
... accelerator="cpu",
... logger=False,
... enable_progress_bar=False,
... enable_model_summary=False,
... )
>>> trainer = Trainer(fast_dev_run=True, **trainer_kwargs)
>>> trainer.fit(model, train_dataloaders=dataloader)
>>> predictions = model.predict(
... dataset,
... fast_dev_run=True,
... batch_size=4,
... trainer_kwargs=trainer_kwargs,
... )
>>> predictions.shape
torch.Size([4, 2])
"""

@classmethod
Expand Down
11 changes: 10 additions & 1 deletion pytorch_forecasting/models/mlp/_decodermlp_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@


class DecoderMLP_pkg(_BasePtForecaster):
"""DecoderMLP package container."""
"""DecoderMLP package container.

Examples
--------
Resolve the package container to the user-facing model class:

>>> from pytorch_forecasting.models.mlp import DecoderMLP_pkg
>>> DecoderMLP_pkg.get_cls().__name__
'DecoderMLP'
"""

_tags = {
"info:name": "DecoderMLP",
Expand Down
Loading