D N
04/05/2024, 1:00 PMD N
04/05/2024, 1:03 PM[W 2024-04-05 00:06:29,737] Trial 0 failed with parameters: {'n_block': 4, 'learning_rate': 0.0015890374391237493, 'ff_dim': 32, 'scaler_type': 'robust', 'max_steps': 2000, 'batch_size': 32, 'dropout': 0.13504504777188925, 'random_seed': 5, 'input_size': 10, 'step_size': 1} because of the following error: TypeError('ones(): argument \'size\' failed to unpack the object at pos 3 with error "type must be tuple of ints,but got NoneType"').
nickeleres
04/05/2024, 1:13 PMtune.loguniform
with HyperOptSearch
? ive tried a number of times but cant seem to get it to work. is there another way of ranging parameter values during parameter search rather than using pre-defined values? thanksRay -
04/06/2024, 7:12 AMLadan Ghasemi
04/08/2024, 9:47 AMflight 505
04/08/2024, 10:52 AMimport numpy as np
import pandas as pd
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.ensemble import RandomForestRegressor
class TimeSeriesPreprocessor(BaseEstimator, TransformerMixin):
def __init__(self, target_column=None, encode_temporal_distance=False, add_decay=False):
self.target_column = target_column
self.encode_temporal_distance = encode_temporal_distance
self.add_decay = add_decay
self.decay_models = {}
def fit(self, X, y=None):
if self.add_decay:
if self.target_column:
df = X.pivot_table(index=["unique_id", "normalized_time"], columns="component", values="value", aggfunc="first").reset_index()
else:
df = X.pivot_table(index=["unique_id", "normalized_time"], columns="component", aggfunc="first").reset_index()
df = self._simple_missingness_encoding(df)
df = self._encode_temporal_distance(df)
self._estimate_decay_parameters(df, [col for col in df.columns if "_δ" in col])
return self
def _simple_missingness_encoding(self, df):
missingness_indicators = df.isna().astype(int)
missingness_indicators = missingness_indicators.add_suffix('_missing')
df = pd.concat([df, missingness_indicators], axis=1)
return df
def _encode_temporal_distance(self, df):
feature_columns = [col for col in df.columns if col not in ["ds", "first_infusion_date", "unique_id"] and not col.endswith("_missing")]
temporal_distance_data = {}
for col in feature_columns:
if not col.endswith("_δ"):
temporal_distance_data[col + "_δ"] = df.groupby("unique_id")[col].transform(lambda x: x.notna().cumsum().where(x.notna(), 0))
temporal_distance_df = pd.DataFrame(temporal_distance_data, index=df.index)
df = pd.concat([df, temporal_distance_df], axis=1)
return df
def _estimate_decay_parameters(self, df, features):
for feature in features:
feature_delta = feature + "_δ"
if feature_delta in df.columns:
train_df = df.dropna(subset=[feature])
if not train_df.empty:
X_train = train_df[[feature_delta]]
y_train = train_df[feature]
model = RandomForestRegressor()
model.fit(X_train, y_train)
self.decay_models[feature] = model
def _apply_decay(self, df):
for feature, model in self.decay_models.items():
missing_mask = (df[feature].isna()) & (df[f'{feature}_missing'] == 1)
if missing_mask.any():
X_missing = df.loc[missing_mask, feature + "_δ"].values.reshape(-1, 1)
df.loc[missing_mask, feature] = model.predict(X_missing)
return df
def transform(self, X):
X["ds"] = pd.to_datetime(X["ds"])
X["normalized_time"] = X.groupby("unique_id")["ds"].transform(lambda x: (x - x.min()).dt.days)
if self.target_column:
df = X.pivot_table(index=["unique_id", "normalized_time"], columns="component", values="value", aggfunc="first").reset_index()
else:
df = X.pivot_table(index=["unique_id", "normalized_time"], columns="component", aggfunc="first").reset_index()
max_normalized_time = df.groupby("unique_id")["normalized_time"].max()
complete_timeline = pd.concat([pd.DataFrame({"unique_id": unique_id, "normalized_time": np.arange(max_time + 1)}) for unique_id, max_time in max_normalized_time.items()], ignore_index=True)
df = df.reset_index(drop=True)
df = pd.merge(complete_timeline, df, on=["unique_id", "normalized_time"], how="left").set_index(["unique_id", "normalized_time"]).reset_index()
df.rename(columns={'normalized_time': 'ds'}, inplace=True)
df = df.groupby("unique_id", group_keys=False).apply(lambda x: x.ffill()).reset_index(drop=True)
if self.target_column and self.target_column in df.columns:
df = df.rename(columns={self.target_column: 'y'})
if self.encode_temporal_distance or self.add_decay:
df = self._simple_missingness_encoding(df)
df = self._encode_temporal_distance(df)
if self.add_decay:
df = self._apply_decay(df)
return df
preprocessor = TimeSeriesPreprocessor(target_column="Neutrophilocytes_B", encode_temporal_distance=True, add_decay=True)
processed_df = preprocessor.transform(df)
print("Shape of the restructured data:", processed_df.shape)
processed_df.head()
Kin Gtz. Olivares
04/08/2024, 5:24 PMLadan Ghasemi
04/08/2024, 5:32 PMDidier Merk
04/09/2024, 11:29 AMNHITS
and PatchTST
models), is doing this correctly. This is how I instantiate my models:
models = [
NHITS(h=horizon,
input_size= 15 * horizon,
scaler_type='standard',
max_steps=12330,
val_check_steps=1233,
n_freq_downsample=[2, 1, 1]),
PatchTST(h=horizon,
input_size= 15 * horizon,
scaler_type='standard',
max_steps=12330,
patch_len=64,
batch_normalization=True,
val_check_steps=1233)
]
Is there a way to use instance normalization instead of batch normalization? Or do you maybe have any other hints as to what might work?
Thanks in advance already, and thanks in general for the great libraries and documentation provided!Shivam Agrawal
04/10/2024, 5:49 PMrevin
in PatchTST
? I am curious since the revin paper documents improvements while using it. If yes, then for multivariate forecasting with different variates at different scales, are affine parameters learnt per variate?
Thanks for the help!Antoine SCHWARTZ -CROIX-
04/11/2024, 11:59 AMneuralforecast
handles time series that are "too short":
• In theory, for the training phase, series with a length of less than input_size + horizon
are ignored and removed from the pool of selectable series. But unlike in statsforecast
, there is no log indicating this process. Is this also the case for neuralforecast
?
• So, how many "long enough" series must be available for the fit to run with no error, batch_size
? For example, with DeepAR on Sagemaker, if the median length of all dataset series is less than input_size + horizon
, the run is blocked.
• If I've understood correctly, you've added the start_padding_enabled
option to make it possible for the algorithm to "see" all series, even the short ones, thanks to a leading pad with zeros up to a size of input_size + horizon
, is that correct?
• Finally, how does the inference phase work if a series is less than input_size
? Is a padding done by default? And does the start_padding_enabled
training option have any impact?
Thank you in advance for your answers. I also feel that it would be a good thing to enrich the documentation on this point 🙂Vidar Ingason
04/12/2024, 8:35 AMValeriy
04/12/2024, 11:42 AMSimon Lin
04/12/2024, 5:04 PMconfig_nhits = {
"input_size": tune.choice([30, 30*2, 30*3]), # Length of input window
"start_padding_enabled": True,
"n_blocks": 5*[1], # Length of input window
"mlp_units": 5 * [[64, 64]], # Length of input window
"n_pool_kernel_size": tune.choice([5*[1], 5*[2], 5*[4],
[8, 4, 2, 1, 1]]), # MaxPooling Kernel size
"n_freq_downsample": tune.choice([[8, 4, 2, 1, 1],
[1, 1, 1, 1, 1]]), # Interpolation expressivity ratios
"learning_rate": tune.loguniform(1e-4, 1e-2), # Initial Learning rate
"scaler_type": tune.choice(['robust']), # Scaler type
"max_steps": tune.choice([1000,1500]), # Max number of training iterations
"batch_size": tune.choice([1, 4, 10]), # Number of series in batch
"windows_batch_size": tune.choice([128, 256, 512]), # Number of windows in batch
"random_seed": tune.randint(1, 20), # Random seed
"stat_exog_list ": tune.choice([["L","AAM","ARC"],None]),
}
config_lstm = {
"input_size": tune.choice([30, 30*2, 30*3]), # Length of input window
"encoder_hidden_size": tune.choice([64, 128]), # Hidden size of LSTM cells
"encoder_n_layers": tune.choice([2,4]), # Number of layers in LSTM
"learning_rate": tune.loguniform(1e-4, 1e-2), # Initial Learning rate
"scaler_type": tune.choice(['robust']), # Scaler type
"max_steps": tune.choice([800, 500]), # Max number of training iterations
"batch_size": tune.choice([1, 4]), # Number of series in batch
"random_seed": tune.randint(1, 20), # Random seed
"stat_exog_list ": tune.choice([["L","AAM","ARC"],None]),
}
HORIZON = 30
nf = NeuralForecast(
models=[
AutoNHITS(h=HORIZON, config=config_nhits, loss=MQLoss(), num_samples=25),
AutoLSTM(h=HORIZON, config=config_lstm, loss=MQLoss(), num_samples=20),
],
freq='D'
)
nf.fit(df=train_set, static_df=static_df, val_size=30)
Then I get the error about unexpected keyword:
TypeError: Trainer.__init__() got an unexpected keyword argument 'stat_exog_list '
Simon Lin
04/12/2024, 5:06 PMValeriy
04/15/2024, 10:12 AMDoyel De Sarkar
04/15/2024, 1:47 PMnickeleres
04/16/2024, 7:14 PMValeriy
04/17/2024, 11:17 AMHuseyn Zeynalov
04/17/2024, 2:41 PMS P Sharan
04/18/2024, 5:47 AMVítor Barbosa
04/18/2024, 2:31 PMcrossvalidation
method of the NeuralForecast()
object:
How can I specify refit=False?nickeleres
04/18/2024, 2:58 PMSteffen
04/19/2024, 8:50 AMlr_schedulers
to the models? Possibly through the trainer_kwargs
argument?
E.g., torch.optim.lr_scheduler: OneCycleLR to be used within a NBEATSx model.
I gave it some attempts without success.D Tucker
04/20/2024, 9:22 PM/artifacts
and /lightning_logs
files which causes my production build to fail. I've tried passing trainer_kwargs
but doing so throws an error in 1.6.3
which is the version I'm stuck with because my engineering team uses snowflake, and snowflake has only that version available. Is there any way I can disable file writing in version 1.6.3
?Valeriy
04/21/2024, 12:31 PMFil Fil
04/23/2024, 2:46 PMfutr_df
must have one row per id and ds in the forecasting horizon
Someone knows why am I having this error?Doyel De Sarkar
04/24/2024, 7:59 AMDidier Merk
04/24/2024, 1:59 PMnf.fit(df=Y_train_df)
. The error is the following, do you guys have any idea what is going on here?
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
| Name | Type | Params
-----------------------------------------------
0 | loss | MAE | 0
1 | padder_train | ConstantPad1d | 0
2 | scaler | TemporalNorm | 0
3 | blocks | ModuleList | 3.6 M
-----------------------------------------------
3.6 M Trainable params
0 Non-trainable params
3.6 M Total params
14.229 Total estimated model params size (MB)
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
Cell In[14], line 1
----> 1 nf.fit(df=Y_train_df)
[...]
File /layers/paketo-buildpacks_cpython/cpython/lib/python3.10/site-packages/omegaconf/grammar_visitor.py:25
22 from .base import Node # noqa F401
24 try:
---> 25 from omegaconf.grammar.gen.OmegaConfGrammarLexer import OmegaConfGrammarLexer
26 from omegaconf.grammar.gen.OmegaConfGrammarParser import OmegaConfGrammarParser
27 from omegaconf.grammar.gen.OmegaConfGrammarParserVisitor import (
28 OmegaConfGrammarParserVisitor,
29 )
File /layers/paketo-buildpacks_cpython/cpython/lib/python3.10/site-packages/omegaconf/grammar/gen/OmegaConfGrammarLexer.py:257
253 buf.write("\3\2\t\f\2\t\r\2\t\24\2\t\4\2\t\25\2\t\32\2\t\33\2")
254 return buf.getvalue()
--> 257 class OmegaConfGrammarLexer(Lexer):
259 atn = ATNDeserializer().deserialize(serializedATN())
261 decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]
File /layers/paketo-buildpacks_cpython/cpython/lib/python3.10/site-packages/omegaconf/grammar/gen/OmegaConfGrammarLexer.py:259, in OmegaConfGrammarLexer()
257 class OmegaConfGrammarLexer(Lexer):
--> 259 atn = ATNDeserializer().deserialize(serializedATN())
261 decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]
263 VALUE_MODE = 1
File /layers/paketo-buildpacks_cpython/cpython/lib/python3.10/site-packages/antlr4/atn/ATNDeserializer.py:28, in ATNDeserializer.deserialize(self, data)
26 self.data = data
27 self.pos = 0
---> 28 self.checkVersion()
29 atn = self.readATN()
30 self.readStates(atn)
File /layers/paketo-buildpacks_cpython/cpython/lib/python3.10/site-packages/antlr4/atn/ATNDeserializer.py:50, in ATNDeserializer.checkVersion(self)
48 version = self.readInt()
49 if version != SERIALIZED_VERSION:
---> 50 raise Exception("Could not deserialize ATN with version " + str(version) + " (expected " + str(SERIALIZED_VERSION) + ").")
Exception: Could not deserialize ATN with version (expected 4)
I'm specifically stumped with this, since all my code ran fine just last week and I didn't change anything. I have also tried just running a PatchTST and NHITS model from scratch using your tutorials, and I'm getting the same error. Even copying directly your code from the PatchTST usage example, gives this error for me.
Any idea what is going on?Ali Khanafer
04/24/2024, 3:35 PMIndexError: too many indices for tensor of dimension 3
. My data is a simple 3 column dataframe with ds
, unique_id
, and y
as columns, and unique_id having 99 different values
dataset, *_ = TimeSeriesDataset.from_df(test_df)
loader = TimeSeriesLoader(dataset, batch_size=33, shuffle=False)
batch = next(iter(loader))
ts = batch['temporal']
ex = shap.DeepExplainer(nhits, ts)