Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def evaluate(data, X, Y, model, evaluateL2, evaluateL1, batch_size):
test = torch.cat((test, Y));

scale = data.scale.expand(output.size(0), data.m)
total_loss += evaluateL2(output * scale, Y * scale).data[0]
total_loss_l1 += evaluateL1(output * scale, Y * scale).data[0]
total_loss += evaluateL2(output * scale, Y * scale).item()
total_loss_l1 += evaluateL1(output * scale, Y * scale).item()
n_samples += (output.size(0) * data.m);
rse = math.sqrt(total_loss / n_samples)/data.rse
rae = (total_loss_l1/n_samples)/data.rae
Expand All @@ -42,7 +42,7 @@ def evaluate(data, X, Y, model, evaluateL2, evaluateL1, batch_size):
mean_p = predict.mean(axis = 0)
mean_g = Ytest.mean(axis = 0)
index = (sigma_g!=0);
correlation = ((predict - mean_p) * (Ytest - mean_g)).mean(axis = 0)/(sigma_p * sigma_g);
correlation = ((predict - mean_p) * (Ytest - mean_g)).mean(axis = 0)/(sigma_p * sigma_g + 1e-15);
correlation = (correlation[index]).mean();
return rse, rae, correlation;

Expand All @@ -57,7 +57,7 @@ def train(data, X, Y, model, criterion, optim, batch_size):
loss = criterion(output * scale, Y * scale);
loss.backward();
grad_norm = optim.step();
total_loss += loss.data[0];
total_loss += loss.item();
n_samples += (output.size(0) * data.m);
return total_loss / n_samples

Expand Down
2 changes: 1 addition & 1 deletion models/LSTNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, args, data):
self.hidS = args.hidSkip;
self.Ck = args.CNN_kernel;
self.skip = args.skip;
self.pt = (self.P - self.Ck)/self.skip
self.pt = (self.P - self.Ck)//self.skip
self.hw = args.highway_window
self.conv1 = nn.Conv2d(1, self.hidC, kernel_size = (self.Ck, self.m));
self.GRU1 = nn.GRU(self.hidC, self.hidR);
Expand Down