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

out_dim or n_features #3

Closed
ZhixuanLiu opened this issue Jul 2, 2021 · 2 comments
Closed

out_dim or n_features #3

ZhixuanLiu opened this issue Jul 2, 2021 · 2 comments
Assignees

Comments

@ZhixuanLiu
Copy link

self.recon_model = ReconstructionModel(window_size, gru_hid_dim, recon_hid_dim, out_dim, recon_n_layers, dropout)

self.recon_model = ReconstructionModel(window_size, gru_hid_dim, recon_hid_dim, out_dim, recon_n_layers, dropout)
should the "out_dim" be changed to "n_features" to match the shape of input x while the loss is calculated by MSELoss(recons, x) ??

@axeloh
Copy link
Collaborator

axeloh commented Jul 2, 2021

We do it like this because we do not always want to forecast and reconstruct all input features.
For example, for SMAP and MSL datasets, the input consists of one-hot encoded data plus one (continuous) telemetry value. So here we do not want to forecast and reconstruct the one-hot encoded features, only the telemetry value.

def get_target_dims(dataset):
"""
:param dataset: Name of dataset
:return: index of data dimension that should be modeled (forecasted and reconstructed),
returns None if all input dimensions should be modeled
"""
if dataset == "SMAP":
return [0]
elif dataset == "MSL":
return [0]
elif dataset == "SMD":
return None
else:
raise ValueError("unknown dataset " + str(dataset))

That is why we for MSL and SMAP use [0] as target dim (dim of the telemetry value).

In train.py the out_dim is set based on this:

n_features = x_train.shape[1]
target_dims = get_target_dims(dataset)
if target_dims is None:
out_dim = n_features
print(f"Will forecast and reconstruct all {n_features} input features")
elif type(target_dims) == int:
print(f"Will forecast and reconstruct input feature: {target_dims}")
out_dim = 1
else:
print(f"Will forecast and reconstruct input features: {target_dims}")
out_dim = len(target_dims)
train_dataset = SlidingWindowDataset(x_train, window_size, target_dims)
test_dataset = SlidingWindowDataset(x_test, window_size, target_dims)
train_loader, val_loader, test_loader = create_data_loaders(

To get correct loss during training (forecastings and recons are compared against the correct input features) we must also check for this:

preds, recons = self.model(x)
if self.target_dims is not None:
x = x[:, :, self.target_dims]
y = y[:, :, self.target_dims].squeeze(-1)

@ZhixuanLiu
Copy link
Author

Thanks for the explanation. I did miss that part in train.py. It helps a lot.

@axeloh axeloh pinned this issue Sep 18, 2021
@axeloh axeloh self-assigned this Sep 18, 2021
JinYang88 pushed a commit to JinYang88/mtad-gat-pytorch that referenced this issue Dec 17, 2023
JinYang88 pushed a commit to JinYang88/mtad-gat-pytorch that referenced this issue Dec 17, 2023
# This is the 1st commit message:

feat: possibility to specify target dim

# The commit message ML4ITS#2 will be skipped:

# feat: possibility to specify target dim

# The commit message ML4ITS#3 will be skipped:

# feat: possibility to specify target dim

# The commit message ML4ITS#4 will be skipped:

# feat: possibility to specify target dim

# The commit message ML4ITS#5 will be skipped:

# feat: possibility to specify target dim

# The commit message ML4ITS#6 will be skipped:

# feat: possibility to specify target dim

# The commit message ML4ITS#7 will be skipped:

# feat: possibility to specify target dim

# The commit message ML4ITS#8 will be skipped:

# feat: possibility to specify target dim

# The commit message ML4ITS#9 will be skipped:

# feat: possibility to specify target dim

# The commit message ML4ITS#10 will be skipped:

# fix

# The commit message ML4ITS#11 will be skipped:

# fix

# The commit message ML4ITS#12 will be skipped:

# feat: writing results to txt file

# The commit message ML4ITS#13 will be skipped:

# feat: writing results to txt file

# The commit message ML4ITS#14 will be skipped:

# ..

# The commit message ML4ITS#15 will be skipped:

# ..

# The commit message ML4ITS#16 will be skipped:

# ..

# The commit message ML4ITS#17 will be skipped:

# trying new anomaly score

# The commit message ML4ITS#18 will be skipped:

# trying new anomaly score

# The commit message ML4ITS#19 will be skipped:

# trying new anomaly score

# The commit message ML4ITS#20 will be skipped:

# trying new anomaly score

# The commit message ML4ITS#21 will be skipped:

# fix

# The commit message ML4ITS#22 will be skipped:

# results from all experiments, plotting, ++

# The commit message ML4ITS#23 will be skipped:

# added plotter class and jupyter notebook file to visualize results
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

2 participants