From 4314b3d9ca89b203c7e69e0094eb3cb0948b8103 Mon Sep 17 00:00:00 2001 From: Bernard Ong Date: Mon, 3 Dec 2018 16:52:24 -0500 Subject: [PATCH] Update main.py For lines 32 and 34, Edited to address deprecation warning to replace tensor.data[0] with tensor.item() For line 45, edited to add a very small epsilon value to ensure divisor is not 0 or NaN. This eliminates true_divide issue. --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 05bfa0a..dec99c0 100755 --- a/main.py +++ b/main.py @@ -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 @@ -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 + 0.000000000000001); correlation = (correlation[index]).mean(); return rse, rae, correlation;