Added time as input feature
This commit is contained in:
@@ -218,7 +218,7 @@ class AutoRegressiveQuantileTrainer(AutoRegressiveTrainer):
|
||||
|
||||
if other_features is not None:
|
||||
prev_features = torch.cat(
|
||||
new_features, other_features, dim=1
|
||||
(new_features.to(self.device), other_features.to(self.device)), dim=1
|
||||
) # (batch_size, 96 + new_features)
|
||||
else:
|
||||
prev_features = new_features
|
||||
@@ -252,36 +252,39 @@ class AutoRegressiveQuantileTrainer(AutoRegressiveTrainer):
|
||||
def plot_quantile_percentages(
|
||||
self, task, data_loader, train: bool = True, iteration: int = None
|
||||
):
|
||||
quantiles = self.quantiles.cpu().numpy()
|
||||
total = 0
|
||||
quantile_counter = {q: 0 for q in self.quantiles.cpu().numpy()}
|
||||
quantile_counter = {q: 0 for q in quantiles}
|
||||
|
||||
self.model.eval()
|
||||
with torch.no_grad():
|
||||
for inputs, targets, _ in data_loader:
|
||||
inputs = inputs.to("cuda")
|
||||
output = self.model(inputs)
|
||||
inputs = inputs.to(self.device)
|
||||
output = self.model(inputs).cpu().numpy()
|
||||
targets = targets.squeeze(-1).cpu().numpy()
|
||||
|
||||
# output shape: (batch_size, num_quantiles)
|
||||
# target shape: (batch_size, 1)
|
||||
for i, q in enumerate(self.quantiles.cpu().numpy()):
|
||||
for i, q in enumerate(quantiles):
|
||||
quantile_counter[q] += np.sum(
|
||||
targets.squeeze(-1).cpu().numpy() < output[:, i].cpu().numpy()
|
||||
targets < output[:, i]
|
||||
)
|
||||
|
||||
total += len(targets)
|
||||
|
||||
# to numpy array of length len(quantiles)
|
||||
percentages = np.array(
|
||||
[quantile_counter[q] / total for q in self.quantiles.cpu().numpy()]
|
||||
[quantile_counter[q] / total for q in quantiles]
|
||||
)
|
||||
|
||||
bar_width = 0.35
|
||||
index = np.arange(len(self.quantiles.cpu().numpy()))
|
||||
index = np.arange(len(quantiles))
|
||||
|
||||
# Plotting the bars
|
||||
fig, ax = plt.subplots(figsize=(15, 10))
|
||||
|
||||
bar1 = ax.bar(
|
||||
index, self.quantiles.cpu().numpy(), bar_width, label="Ideal", color="brown"
|
||||
index, quantiles, bar_width, label="Ideal", color="brown"
|
||||
)
|
||||
bar2 = ax.bar(
|
||||
index + bar_width, percentages, bar_width, label="NN model", color="blue"
|
||||
@@ -305,7 +308,7 @@ class AutoRegressiveQuantileTrainer(AutoRegressiveTrainer):
|
||||
ax.set_ylabel("Fraction of data under quantile forecast")
|
||||
ax.set_title(f"Quantile Performance Comparison ({series_name})")
|
||||
ax.set_xticks(index + bar_width / 2)
|
||||
ax.set_xticklabels(self.quantiles.cpu().numpy())
|
||||
ax.set_xticklabels(quantiles)
|
||||
ax.legend()
|
||||
|
||||
task.get_logger().report_matplotlib_figure(
|
||||
|
||||
@@ -41,7 +41,7 @@ class Trainer:
|
||||
self.patience = patience
|
||||
self.delta = delta
|
||||
|
||||
def add_metrics_to_track(self, loss: torch.nn.Module | list[torch.nn.Module]):
|
||||
def add_metrics_to_track(self, loss):
|
||||
if isinstance(loss, list):
|
||||
self.metrics_to_track.extend(loss)
|
||||
else:
|
||||
@@ -59,7 +59,8 @@ class Trainer:
|
||||
if self.debug:
|
||||
task.add_tags("Debug")
|
||||
|
||||
change_description = input("Enter a change description: ")
|
||||
# change_description = input("Enter a change description: ")
|
||||
change_description = ""
|
||||
if change_description:
|
||||
task.set_comment(change_description)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user