def predict_cumulative_hazard(self, X, times=None, ancillary_X=None): """ Return the cumulative hazard rate of subjects in X at time points. Parameters ---------- X: numpy array or DataFrame a (n,d) covariate numpy array or DataFrame. If a DataFrame, columns can be in any order. If a numpy array, columns must be in the same order as the training data. times: iterable, optional an iterable of increasing times to predict the cumulative hazard at. Default is the set of all durations (observed and unobserved). Uses a linear interpolation if points in time are not in the index. ancillary_X: numpy array or DataFrame, optional a (n,d) covariate numpy array or DataFrame. If a DataFrame, columns can be in any order. If a numpy array, columns must be in the same order as the training data. Returns ------- cumulative_hazard_ : DataFrame the cumulative hazard of individuals over the timeline """ import numpy as np times = coalesce(times, self.timeline, np.unique(self.durations)) exp_mu_, sigma_ = self._prep_inputs_for_prediction_and_return_scores( X, ancillary_X) mu_ = np.log(exp_mu_) Z = np.subtract.outer(np.log(times), mu_) / sigma_ return pd.DataFrame(-logsf(Z), columns=_get_index(X), index=times)
def predict_cumulative_hazard(self, X, times=None, ancillary_X=None): """ Return the cumulative hazard rate of subjects in X at time points. Parameters ---------- X: numpy array or DataFrame a (n,d) covariate numpy array or DataFrame. If a DataFrame, columns can be in any order. If a numpy array, columns must be in the same order as the training data. times: iterable, optional an iterable of increasing times to predict the cumulative hazard at. Default is the set of all durations (observed and unobserved). Uses a linear interpolation if points in time are not in the index. ancillary_X: numpy array or DataFrame, optional a (n,d) covariate numpy array or DataFrame. If a DataFrame, columns can be in any order. If a numpy array, columns must be in the same order as the training data. Returns ------- cumulative_hazard_ : DataFrame the cumulative hazard of individuals over the timeline """ import numpy as np times = coalesce(times, self.timeline, np.unique(self.durations)) exp_mu_, sigma_ = self._prep_inputs_for_prediction_and_return_scores(X, ancillary_X) mu_ = np.log(exp_mu_) Z = np.subtract.outer(np.log(times), mu_) / sigma_ return pd.DataFrame(-logsf(Z), columns=_get_index(X), index=times)
def _cumulative_hazard(self, params, T, Xs): mu_params = params["mu_"] mu_ = np.dot(Xs["mu_"], mu_params) sigma_params = params["sigma_"] sigma_ = np.exp(np.dot(Xs["sigma_"], sigma_params)) Z = (np.log(T) - mu_) / sigma_ return -logsf(Z)
def _cumulative_hazard(self, params, T, *Xs): mu_params = params[self._LOOKUP_SLICE["mu_"]] mu_ = np.dot(Xs[0], mu_params) sigma_params = params[self._LOOKUP_SLICE["sigma_"]] sigma_ = np.exp(np.dot(Xs[1], sigma_params)) Z = (np.log(T) - mu_) / sigma_ return -logsf(Z)
def _log_hazard(self, params, T, Xs): mu_params = params["mu_"] mu_ = np.dot(Xs["mu_"], mu_params) sigma_params = params["sigma_"] log_sigma_ = np.dot(Xs["sigma_"], sigma_params) sigma_ = np.exp(log_sigma_) Z = (np.log(T) - mu_) / sigma_ return norm.logpdf(Z) - log_sigma_ - np.log(T) - logsf(Z)
def _log_hazard(self, params, T, *Xs): mu_params = params[self._LOOKUP_SLICE["mu_"]] mu_ = np.dot(Xs[0], mu_params) sigma_params = params[self._LOOKUP_SLICE["sigma_"]] log_sigma_ = np.dot(Xs[1], sigma_params) sigma_ = np.exp(log_sigma_) Z = (np.log(T) - mu_) / sigma_ return logpdf(Z) - log_sigma_ - np.log(T) - logsf(Z)
def _log_hazard(self, params, T, *Xs): mu_params = params[self._LOOKUP_SLICE["mu_"]] mu_ = np.dot(Xs[0], mu_params) sigma_params = params[self._LOOKUP_SLICE["sigma_"]] log_sigma_ = np.dot(Xs[1], sigma_params) sigma_ = np.exp(log_sigma_) Z = (np.log(T) - mu_) / sigma_ return norm.logpdf(Z) - log_sigma_ - np.log(T) - logsf(Z)
def _log_hazard(self, params, times): mu_, sigma_ = params Z = (np.log(times) - mu_) / sigma_ return norm.logpdf(Z, loc=0, scale=1) - np.log(sigma_) - np.log(times) - logsf(Z)
def _cumulative_hazard(self, params, times): mu_, sigma_ = params Z = (np.log(times) - mu_) / sigma_ return -logsf(Z)