From b362f16dcd487aae4c47f5d30fbc4b3f78f748b3 Mon Sep 17 00:00:00 2001 From: Vincent Jeanselme Date: Thu, 31 Dec 2020 18:48:16 +0000 Subject: [PATCH 1/2] Evaluation Compute the loss on a given set of points --- dsm/dsm_api.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dsm/dsm_api.py b/dsm/dsm_api.py index 6988728..028f6b2 100644 --- a/dsm/dsm_api.py +++ b/dsm/dsm_api.py @@ -31,7 +31,7 @@ from dsm.dsm_torch import DeepRecurrentSurvivalMachinesTorch from dsm.losses import predict_cdf import dsm.losses as losses -from dsm.utilities import train_dsm, _get_padded_features, _get_padded_targets +from dsm.utilities import train_dsm, _get_padded_features, _get_padded_targets, _reshape_tensor_with_nans import torch import numpy as np @@ -118,6 +118,18 @@ def fit(self, x, t, e, vsize=0.15, self.fitted = True return self + + def eval(self, x, t, e): + """ + Evaluates models with conditional loss + """ + processed_data = self._prepocess_training_data(x, t, e, 0, 0) + _, _, _, x_val, t_val, e_val = processed_data + x_val, t_val, e_val = x_val,\ + _reshape_tensor_with_nans(t_val),\ + _reshape_tensor_with_nans(e_val) + return losses.conditional_loss(self.torch_model, x_val, t_val, e_val, + elbo=False).detach().numpy() def _prepocess_test_data(self, x): return torch.from_numpy(x) From 4b9b090761adde2e8aef95a05eea8ff6b537a706 Mon Sep 17 00:00:00 2001 From: Vincent Jeanselme Date: Sat, 2 Jan 2021 15:36:57 +0000 Subject: [PATCH 2/2] Update function name and import --- dsm/dsm_api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dsm/dsm_api.py b/dsm/dsm_api.py index 028f6b2..3e69dca 100644 --- a/dsm/dsm_api.py +++ b/dsm/dsm_api.py @@ -31,7 +31,8 @@ from dsm.dsm_torch import DeepRecurrentSurvivalMachinesTorch from dsm.losses import predict_cdf import dsm.losses as losses -from dsm.utilities import train_dsm, _get_padded_features, _get_padded_targets, _reshape_tensor_with_nans +from dsm.utilities import train_dsm, _get_padded_features, _get_padded_targets,\ + _reshape_tensor_with_nans import torch import numpy as np @@ -119,7 +120,7 @@ def fit(self, x, t, e, vsize=0.15, return self - def eval(self, x, t, e): + def _eval_conditional_loss(self, x, t, e): """ Evaluates models with conditional loss """