Skip to content
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

Dilation greater than zero #922

Open
Yurnerosk opened this issue Sep 24, 2024 · 2 comments
Open

Dilation greater than zero #922

Yurnerosk opened this issue Sep 24, 2024 · 2 comments

Comments

@Yurnerosk
Copy link

I have a time series dataframe containing 80 features, 29922 rows, and the idea was to first use MINIROCKET for feature creation, and then use a linear regressor to reconstruct a target column. I'm doing:

import pandas as pd
import torch
from tsai.models.MINIROCKET_Pytorch import *
from sklearn.linear_model import LinearRegression  # You can choose another regressor
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split

...


X = df.drop(columns=[target_column]).values  # Feature matrix (80 columns - target)
y = df[target_column].values  # Target vector

# Step 2: Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Step 3: Initialize and fit MiniRocket
num_samples, num_features = X_train.shape
time_steps = 1  # Assuming you have 1 time step

# Reshape to 3D format
X_train_reshaped = X_train.reshape(num_samples, time_steps, num_features)
X_test_reshaped = X_test.reshape(X_test.shape[0], time_steps, num_features)

To finally:

# Initialize MiniRocket
mrf = MiniRocketFeatures(num_features, time_steps).to(torch.device('cpu'))
mrf.fit(X_train_reshaped)

However, it seems that the dilation cannot be greater than 1.

---> [74](file:///C:/Users.../.venv/Lib/site-packages/tsai/models/MINIROCKET_Pytorch.py:74) C = F.conv1d(x, self.kernels, padding=padding, dilation=dilation, groups=self.c_in)
     [75](file:///C:/Users.../.venv/Lib/site-packages/tsai/models/MINIROCKET_Pytorch.py:75) if self.c_in > 1: # multivariate
     [76](file:///C:/Users.../.venv/Lib/site-packages/tsai/models/MINIROCKET_Pytorch.py:76)     C = C.reshape(x.shape[0], self.c_in, self.num_kernels, -1)

RuntimeError: dilation should be greater than zero

What should I do?

Python 3.12.2
Windows 10
tsai 0.3.9
torch 2.2.2

@Yurnerosk
Copy link
Author

I think I wasn't too specific in my question, but what i'm trying to do is:

print(X_train_reshaped.shape)
print(y_train.shape)
# (23937, 1, 79) num samples, timesteps, num_features
# (23937,)

# Initialize MiniRocket
mrf = MiniRocketFeatures(c_in=num_features, seq_len=time_steps).to(torch.device('cpu'))
mrf.dilations
# array([-2147483648,           0])

mrf.fit(X_train_reshaped)
File c:\Users\wilso\OneDrive\Documentos\GitHub\Colhedora\Dados_season_2024\.venv\Lib\site-packages\torch\nn\modules\module.py:1520, in Module._call_impl(self, *args, **kwargs)
   [1515](file:///C:/Users/wilso/OneDrive/Documentos/GitHub/Colhedora/Dados_season_2024/.venv/Lib/site-packages/torch/nn/modules/module.py:1515) # If we don't have any hooks, we want to skip the rest of the logic in
   [1516](file:///C:/Users/wilso/OneDrive/Documentos/GitHub/Colhedora/Dados_season_2024/.venv/Lib/site-packages/torch/nn/modules/module.py:1516) # this function, and just call forward.
   [1517](file:///C:/Users/wilso/OneDrive/Documentos/GitHub/Colhedora/Dados_season_2024/.venv/Lib/site-packages/torch/nn/modules/module.py:1517) if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   [1518](file:///C:/Users/wilso/OneDrive/Documentos/GitHub/Colhedora/Dados_season_2024/.venv/Lib/site-packages/torch/nn/modules/module.py:1518)         or _global_backward_pre_hooks or _global_backward_hooks
   [1519](file:///C:/Users/wilso/OneDrive/Documentos/GitHub/Colhedora/Dados_season_2024/.venv/Lib/site-packages/torch/nn/modules/module.py:1519)         or _global_forward_hooks or _global_forward_pre_hooks):
-> [1520](file:///C:/Users/wilso/OneDrive/Documentos/GitHub/Colhedora/Dados_season_2024/.venv/Lib/site-packages/torch/nn/modules/module.py:1520)     return forward_call(*args, **kwargs)
   [1522](file:///C:/Users/wilso/OneDrive/Documentos/GitHub/Colhedora/Dados_season_2024/.venv/Lib/site-packages/torch/nn/modules/module.py:1522) try:
...
---> [74](file:///C:/Users/wilso/OneDrive/Documentos/GitHub/Colhedora/Dados_season_2024/.venv/Lib/site-packages/tsai/models/MINIROCKET_Pytorch.py:74) C = F.conv1d(x, self.kernels, padding=padding, dilation=dilation, groups=self.c_in)
     [75](file:///C:/Users/wilso/OneDrive/Documentos/GitHub/Colhedora/Dados_season_2024/.venv/Lib/site-packages/tsai/models/MINIROCKET_Pytorch.py:75) if self.c_in > 1: # multivariate
     [76](file:///C:/Users/wilso/OneDrive/Documentos/GitHub/Colhedora/Dados_season_2024/.venv/Lib/site-packages/tsai/models/MINIROCKET_Pytorch.py:76)     C = C.reshape(x.shape[0], self.c_in, self.num_kernels, -1)

RuntimeError: dilation should be greater than zero

I noted the dilations seems to be a bit off, what can I do?

@Yurnerosk
Copy link
Author

RuntimeError: Given groups=9, weight of size [756, 1, 9], expected input[168, 1, 9] to have 9 channels, but got 1 channels instead.

I'm getting crazy of how Rockt is not being able to recognize the channels, even when I did my array3d [sample_size x n_features x 1].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant