https://github.com/nixtla logo
#neural-forecast
Error with futr_exog_list in NHITS
# neural-forecast
b

BWBarber

09/08/2023, 2:33 AM
I'm attempting to modify the code here (https://nixtla.github.io/neuralforecast/examples/hierarchicalnetworks.html#fit-and-predict-hint) to also use a known covariate. To test, I modified the example code to have a random feature:
Copy code
Y_df['noise'] = np.random.rand(len(Y_df))


# split to train and test
Y_train_df = Y_df[:-horizon]
Y_test_df = Y_df[-horizon:]
# Instantiate HINT
# BaseNetwork + Distribution + Reconciliation
nhits = NHITS(h=horizon,
           input_size=24,
           loss=GMM(n_components=10, level=level),
           hist_exog_list=['month'],
           futr_exog_list=['noise'],
           max_steps=2000,
           early_stop_patience_steps=10,
           val_check_steps=50,
           scaler_type='robust',
           learning_rate=1e-3,
           valid_loss=sCRPS(level=level))

model = HINT(h=horizon, S=S_df.values,
         model=nhits,  reconciliation='BottomUp')

# Fit and Predict
nf = NeuralForecast(models=[model], freq='MS')
nf.fit(df=Y_train_df, val_size=12)
Y_hat_df = nf.predict(Y_test_df)
When I run this code, I receive the error: "RuntimeError: normal expects all elements of std >= 0.0" Has this been seen before? Not sure exactly what's going on. Everything works fine when I comment out futr_exog_list
k

Kin Gtz. Olivares

09/08/2023, 8:20 AM
Hey @BWBarger, We added a numerical protection for the case when series dataset are completely zeros, some reconciliation methods make divisions using standard deviations. Here is an example where we add some minor noise to make the algorithms work:
Copy code
# MinT along other methods require a positive definite covariance matrix
# for the residuals, when dealing with 0s as residuals the methods break
# data is augmented with minimal normal noise to avoid this error.
Y_df['y'] = Y_df['y'] + np.random.normal(loc=0.0, scale=0.01, size=len(Y_df))
b

BWBarber

09/08/2023, 1:58 PM
I still see this error with the small noise added to y. As I mentioned before, I only see this error when I try to include futr_exog_list
Wanted to check if this has been looked into further. I'm experiencing this issue in the google colab environment (https://colab.research.google.com/github/Nixtla/neuralforecast/blob/main/nbs/examples/HierarchicalNetworks.ipynb) as well, so I don't think it has anything to do with my personal setup. Are there any full samples of NHITS working with future exogenous features? Do we need to create an issue in github?
23 Views