sparsesurv.gradients module
Summary
Functions:
Calculates the negative gradient of the AFT model wrt eta. |
|
Calculates the negative gradient of the AFT model wrt beta. |
|
Calculates the negative gradient of the EH model wrt eta. |
|
Calculates the negative gradient of the EH model wrt beta. |
Reference
- aft_gradient(linear_predictor, time, event, bandwidth=None)[source]
Calculates the negative gradient of the AFT model wrt eta.
- Parameters:
linear_predictor (npt.NDArray[np.float64]) – Linear predictor of the training data of dimension n.
time (npt.NDArray[np.float64]) – Time of the training data of dimension n. Assumed to be sorted.
event (npt.NDArray[np.int64]) – Event indicator of the training data of dimension n.
bandwidth (Optional[float], optional) – Bandwidth to kernel-smooth the profile likelihood. Will be estimated if not specified. Defaults to None.
- Returns:
Negative gradient of the AFT model wrt eta. Of dimensionality n.
- Return type:
npt.NDArray[np.float64]
- aft_gradient_beta(beta, X, time, event, bandwidth=None)[source]
Calculates the negative gradient of the AFT model wrt beta.
Note
Utility function to be used with off-the-shelf optimisers (e.g., scipy). Since the main gradient function calculates the gradient wrt eta (see aft_gradient), we recover the gradient wrt beta through a matrix multiplication.
- Parameters:
beta (npt.NDArray[np.float64]) – Coefficient vector of length p.
X (npt.NDArray[np.float64]) – Design matrix of the training data. N rows and p columns.
time (npt.NDArray[np.float64]) – Time of the training data of length n. Assumed to be sorted.
event (npt.NDArray[np.int64]) – Event indicator of the training data of length n.
bandwidth (Optional[float], optional) – Bandwidth to kernel-smooth the profile likelihood. Will be estimated empirically if not specified. Defaults to None.
- Returns:
Negative gradient of the AFT model wrt beta of length p.
- Return type:
npt.NDArray[np.float64]
- eh_gradient(linear_predictor, time, event, bandwidth=None)[source]
Calculates the negative gradient of the EH model wrt eta.
- Parameters:
linear_predictor (npt.NDArray[np.float64]) – Linear predictor of the training data. N rows and 2 columns.
time (npt.NDArray[np.float64]) – Time of the training data of length n. Assumed to be sorted.
event (npt.NDArray[np.int64]) – Event indicator of the training data of length n.
bandwidth (Optional[float], optional) – Bandwidth to kernel-smooth the profile likelihood. Will be estimated if not specified. Defaults to None.
- Returns:
Negative gradient of the EH model wrt eta of length 2n.
- Return type:
np.array
- eh_gradient_beta(beta, X, time, event, bandwidth=None)[source]
Calculates the negative gradient of the EH model wrt beta.
Note
Utility function to be used with off-the-shelf optimisers (e.g., scipy). Since the main gradient function calculates the gradient wrt eta (see eh_gradient), we recover the gradient wrt beta through a matrix multiplication.
- Parameters:
beta (npt.NDArray[np.float64]) – Coefficient vector. Length 2p to account for the two coefficients that were stacked into one vector (see pcsurv.eh.EH for details).
X (npt.NDArray[np.float64]) – Design matrix of the training data. N rows and 2p columns.
time (npt.NDArray[np.float64]) – Time of the training data of length n. Assumed to be sorted.
event (npt.NDArray[np.int64]) – Event indicator of the training data of length n.
bandwidth (Optional[float], optional) – Bandwidth to kernel-smooth the profile likelihood. Will be estimated if not specified. Defaults to None. Defaults to None.
- Returns:
Negative gradient of the AFT model wrt beta of length 2p.
- Return type:
npt.NDArray[np.float64]