From be30a4035470a14af9634057d58b47ccdf15ff0d Mon Sep 17 00:00:00 2001 From: wassname Date: Sat, 15 Feb 2020 07:22:14 +0800 Subject: [PATCH] misc --- src/data/smart_meter.py | 16 +++++++++------- src/plot.py | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/data/smart_meter.py b/src/data/smart_meter.py index 37def80..2cd744f 100644 --- a/src/data/smart_meter.py +++ b/src/data/smart_meter.py @@ -23,15 +23,19 @@ def collate_fns(max_num_context, max_num_extra_target, sample, sort=True): x = torch.from_numpy(x).float() y = torch.from_numpy(y).float() - x[:,:max_num_context, -1] = 0 # Feature to let the model know this is past data + x[:, :max_num_context, -1] = 0 # Feature to let the model know this is past data n=x[:, max_num_context:, -1].shape[1] x[:, max_num_context:, -1] = torch.arange(1, n+1)/1.0/n # Feature to let the model know this is past data x_context = x[:, :max_num_context] y_context = y[:, :max_num_context] + x_target_extra = x[:, max_num_context:] + y_target_extra = y[:, max_num_context:] + + # x = x_target_extra # torch.cat([x_context, x_target_extra], 1) + # y = y_target_extra # torch.cat([y_context, y_target_extra], 1) + if sample: - x_target_extra = x[:, max_num_context:] - y_target_extra = y[:, max_num_context:] # This is slightly differen't than normal, we are ensuring that our target point are in the future, to mimic deployment x_context, y_context = npsample_batch( @@ -42,14 +46,12 @@ def collate_fns(max_num_context, max_num_extra_target, sample, sort=True): x_target_extra, y_target_extra, size=num_extra_target, sort=sort ) - x = torch.cat([x_context, x_target_extra], 1) - y = torch.cat([y_context, y_target_extra], 1) assert (x_context[:, :, -1]==0).all() assert (x[:, -1, -1] > 0).all() - assert (x[:, 0, -1] == 0).all() + # assert (x[:, 0, -1] == 0).all() - return x_context, y_context, x, y + return x_context, y_context, x_target_extra, y_target_extra return collate_fn diff --git a/src/plot.py b/src/plot.py index f4a0129..c7d2b4b 100644 --- a/src/plot.py +++ b/src/plot.py @@ -80,6 +80,7 @@ def plot_from_loader( x_rows, y_rows = loader.dataset.get_rows(i) max_num_context = context_x.shape[1] y_context_rows = y_rows[:max_num_context] + y_target_rows = y_rows[max_num_context:] dt = y_context_rows.index[0] model.eval() @@ -90,7 +91,7 @@ def plot_from_loader( plt.figure() plt.title(title + f" loss={loss_test: 2.2g} {dt}") plot_rows( - y_rows, + y_target_rows, y_context_rows, y_pred.detach().cpu().numpy(), y_std.detach().cpu().numpy(),