-
Notifications
You must be signed in to change notification settings - Fork 612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
y_range argument cannot be passed when creating a multi-step TSForecaster #726
Comments
Hi @Samcro5C, from tsai.basics import *
ts = get_forecasting_time_series("Sunspots").values
X, y = SlidingWindow(60, horizon=1)(ts)
splits = TimeSplitter(235)(y)
batch_tfms = TSStandardize()
dls = get_ts_dls(X, y, splits=splits, path='models', batch_tfms=batch_tfms, bs=512)
fcst = ts_learner(dls, arch="TSTPlus", y_range=(0, 300), metrics=mae, cbs=ShowGraph())
fcst.fit_one_cycle(50, 1e-3)
fcst.export("fcst.pkl") from tsai.basics import *
ts = get_forecasting_time_series("Sunspots").values
X, y = SlidingWindow(60, horizon=1)(ts)
splits = TimeSplitter(235)(y)
batch_tfms = TSStandardize()
fcst = TSForecaster(X, y, splits=splits, path='models', batch_tfms=batch_tfms, bs=512, arch="TSTPlus", arch_config=dict(y_range=(0, 300)), metrics=mae, cbs=ShowGraph())
fcst.fit_one_cycle(50, 1e-3)
fcst.export("fcst.pkl") In either case you can confirm the y_range is being applied by printing fcst.head. |
Thanks for the fast reply. I tried your code snippet and first of all, I could not download the sunspots dataset (returned HTTP 404) but that is another issue. So I just generated some random data to get the code running and also for this example I do not see any effect of the y_range parameter. At least I thought the head should include a Sigmoid layer which it does not. tsai version 0.3.1 (also holds for 0.3.5) |
The datasets are not stored directly in Sequential(
(0): GELU(approximate='none')
(1): fastai.layers.Flatten(full=False)
(2): LinBnDrop(
(0): Linear(in_features=7680, out_features=1, bias=True)
)
(3): fastai.layers.SigmoidRange(low=0, high=300)
) Could you please share the output of running this: from tsai.imports import my_setup
my_setup() |
Okay, I checked again with your example and there was a difference when using random data. Since I want to create multistep forecasts, my
So what I intend is to have a y_range on all of the individual forecast predictions, i.e. each lead time. I am not sure if this is not supposed to work but in my opinion there is no reason why not.
|
Hi @Samcro5C, from tsai.basics import *
from tsai.models.layers import *
def lin_nd_head_with_y_range(n_in, n_out, seq_len=None, d=None, flatten=False, use_bn=False, fc_dropout=0., y_range=None):
layers = [lin_nd_head(n_in, n_out, seq_len=seq_len, d=d, flatten=flatten, use_bn=use_bn, fc_dropout=fc_dropout)]
if y_range is not None:
layers += [SigmoidRange(*y_range)]
return nn.Sequential(*layers)
xb = torch.randn(8, 32, 50)
head = lin_nd_head_with_y_range(32, 1, 50, (20, 3), y_range=(-40, 350)) # remember to always leave some margin
output = head(xb)
output.shape, output.min(), output.max()
# output: (torch.Size([8, 20, 3]), tensor(11.8317, grad_fn=<MinBackward1>), tensor(298.8748, grad_fn=<MaxBackward1>)) You could pass this layer this way: custom_head = partial(lin_nd_head_with_y_range, y_range=(0, 300)) Note: it's important that any code you use for training must be available at inference time. That means that if you add |
Thank you so much, right now I do not see the need for other arguments for my use-case, but maybe it makes sense to check which arguments there exist for creating heads when using the Plus models. |
When trying to set the allowed range of the predictions by passing the
y_range
argument, I noticed that there is no way to set this parameter using tsai API although many models likeTSTPlus
accept them.Neither
TSForecaster
norts_learner
accepty_range
as a parameter which makes sense as they both callbuild_ts_model
which also does not accepty_range
.The problem is that there is also no workaround by setting a partial custom_head function (e.g.
create_mlp_head
), since this would require a function that accepts a parameterd
which is expected when creating the head in thebuild_ts_model
function (line 160 in models/utils.py).I think this is a bug, since this parameter y_range cannot be set anywhere although it is part of many models.
The text was updated successfully, but these errors were encountered: