Module for functions to predict the risk of lymphatic progression.
The code in this module is utilized by the views.RiskPredictionView
of the
riskpredictor
app to compute the risk of lymphatic progression for a given diagnosis.
Function | aggregate |
Aggregate the results of the risk computation into a dictionary. |
Function | compute |
Compute the probability of the selected diagnosis for any possible hidden state and for both sides of the neck, if the model is a bilateral one. |
Function | compute |
Compute the marginalised risks of involvement of each LNL. |
Function | compute |
Compute the posterior risks for any possible hidden state and for each of the samples used to compute the prior risks. |
Function | create |
Create a vector for marginalizing over hidden states that match the given pattern. |
Function | create |
Create a patient dataframe from a specific diagnosis. |
Function | default |
Return default risks (everything unknown). |
Function | risks |
Compute the marginalized risk of microscopic involvement in any of the modelled LNLs for a given diagnosis. |
Variable | logger |
Undocumented |
Aggregate the results of the risk computation into a dictionary.
This is a helper function that is used to convert the numpy arrays that are
returned by the risk computation into a dictionary that can be used as context
for the views.RiskPredictionView
view.
The returned dictionary has the following structure: For each side (ipsi or contra) and each LNL, the dictionary contains a list of three values: The first value is the error of the prediction, the second value is the risk of involvement (but minus half the error), and the third value is the probability of being healthy (again minus half the error).
Parameters | |
inferenceInferenceResult | Undocumented |
marginalizedDict[ | Undocumented |
Returns | |
Dict[ | Undocumented |
Compute the probability of the selected diagnosis for any possible hidden state and for both sides of the neck, if the model is a bilateral one.
In probabilistic terms, this is the probability P(D=d|X) of the diagnosis D=d given any of the possible hidden states X. Consequently, this is a 1D array of length 2^V, where V is the number of LNLs in the model.
Parameters | |
inferenceInferenceResult | Undocumented |
tstr | Undocumented |
diagnosis:Dict[ | Undocumented |
specificity:float | Undocumented |
sensitivity:float | Undocumented |
midlineOptional[ | Undocumented |
Returns | |
Dict[ | Undocumented |
Compute the marginalised risks of involvement of each LNL.
In probabilistic terms, this is the probability P(X=x|D=d), which is computed by marginalizing over all hidden states that do match the given diagnosis (for wich the posterior risk over all possible hidden states was already computed).
Parameters | |
inferenceInferenceResult | Undocumented |
posteriornp.ndarray | Undocumented |
Returns | |
Dict[ | Undocumented |
Compute the posterior risks for any possible hidden state and for each of the samples used to compute the prior risks.
In probabilistic terms, this is the probability P(X|D=d) of any of the possible hidden state X given the diagnosis D=d. This is computed for each of the N samples. Consequently, this is a 3D array of shape (N, 2^V, 2^V) in the bilateral case, or (N, 2^V) in the unilateral case.
Parameters | |
inferenceInferenceResult | Undocumented |
diagnoseDict[ | Undocumented |
risknp.ndarray | Undocumented |
Returns | |
np.ndarray | Undocumented |
Create a vector for marginalizing over hidden states that match the given pattern.
If one wants to know the probability of e.g. LNL II involvement, one needs to marginalize over all hidden states where LNL II is involved. This function creates a vector that is 1 for all hidden states that match the given pattern and 0 for all others.
Parameters | |
lymphUnion[ | Undocumented |
pattern:Dict[ | Undocumented |
Returns | |
np.ndarray | Undocumented |
Create a patient dataframe from a specific diagnosis.
This is necessary, so that the lymph-model can be used to compute the probability of the given diagnosis for any possible hidden state.
Parameters | |
diagnosis:Dict[ | Undocumented |
tstr | Undocumented |
isbool | Undocumented |
midlineOptional[ | Undocumented |
Returns | |
pd.DataFrame | Undocumented |
Return default risks (everything unknown).
Parameters | |
inferenceInferenceResult | Undocumented |
**kwargs | Undocumented |
Returns | |
Dict[ | Undocumented |
Compute the marginalized risk of microscopic involvement in any of the modelled LNLs for a given diagnosis.
Parameters | |
inferenceInferenceResult | Undocumented |
tstr | Undocumented |
diagnosis:Dict[ | Undocumented |
specificity:float | Undocumented |
sensitivity:float | Undocumented |
midlineOptional[ | Undocumented |
**_kwargs | Undocumented |
Returns | |
Dict[ | Undocumented |