Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluation #26

Closed
wants to merge 2 commits into from
Closed
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
15 changes: 14 additions & 1 deletion dsm/dsm_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
from dsm.utilities import train_dsm, _get_padded_features, _get_padded_targets,\
_reshape_tensor_with_nans

import torch
import numpy as np
Expand Down Expand Up @@ -118,6 +119,18 @@ def fit(self, x, t, e, vsize=0.15,
self.fitted = True

return self

def _eval_conditional_loss(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)
Expand Down