The likelihood_cmhn submodule#
This submodule contains functions to work with the transition rate matrix Q in a restricted state-space as well as functions to compute the marginal log-likelihood score and its gradient making use of state-space restriction.
- exception mhn.training.likelihood_cmhn.CUDAError#
Error raised if something went wrong during execution of the CUDA code.
- mhn.training.likelihood_cmhn.compute_restricted_inverse(double[:, :] theta, int[:] state, double[:] b, bool transp=False) np.ndarray#
Multiplies [I-Q]^(-1) with the vector b, where Q is the restricted transition rate matrix constructed from the given state.
This is a Python wrapper for the internal Cython function.
- Parameters:
theta (np.ndarray) – Matrix containing the theta entries used to construct Q.
state (np.ndarray) – State representing the current tumor sample. Must be a binary 1D NumPy array with dtype=np.int32, where each entry indicates whether an event is present (1) or not (0).
b (np.ndarray) – Array to be multiplied with [I-Q]^(-1).
transp (bool, optional) – If True, multiplies b with the transposed [I-Q]^(-1). Defaults to False.
- Returns:
The result of the multiplication as a NumPy array.
- Return type:
np.ndarray
- mhn.training.likelihood_cmhn.count_ones64(long long x)#
Counts the number of bits set to 1 in a 64-bit integer. Wrapper so that count_ones can be called from a Python script
- mhn.training.likelihood_cmhn.cpu_gradient_and_score(double[:, :] theta, StateContainer mutation_data)#
Computes the total gradient and score for a given cMHN and mutation data.
- Parameters:
theta (np.ndarray) – Matrix containing the theta entries of the current cMHN.
mutation_data (StateContainer) – Mutation data used to train the cMHN.
- Returns:
The computed gradient and score.
- Return type:
tuple
- mhn.training.likelihood_cmhn.cpu_score(double[:, :] theta, StateContainer mutation_data)#
Computes the total log-likelihood score for a given cMHN and mutation data.
- Parameters:
theta (np.ndarray) – Matrix containing the theta entries of the current cMHN.
mutation_data (StateContainer) – StateContainer holding the mutation data used to train the cMHN.
- Returns:
The normalized log-likelihood score.
- Return type:
float
- mhn.training.likelihood_cmhn.cuda_available() Literal[CUDA_AVAILABLE, CUDA_NOT_AVAILABLE, CUDA_NOT_FUNCTIONAL]#
Call this function if you want to know if the mhn package is able to use CUDA functions on your device.
- mhn.training.likelihood_cmhn.cuda_gradient_and_score(double[:, :] theta, StateContainer mutation_data)#
This function is a wrapper for the CUDA implementation of state-space restriction.
This function can only be used if the mhn package was compiled with CUDA.
- Parameters:
theta (np.ndarray) – Matrix containing the theta entries of the current cMHN.
mutation_data (StateContainer) – Mutation data used to train the cMHN.
- Returns:
The computed gradient and score.
- Return type:
tuple
- Raises:
RuntimeError – If the mhn package was not compiled with CUDA.
- mhn.training.likelihood_cmhn.cython_gradient_and_score(double[:, :] theta, StateContainer mutation_data)#
Deprecated: Use cpu_gradient_and_score() instead.
Computes the total gradient and score for a given cMHN and mutation data.
- Parameters:
theta (np.ndarray) – Matrix containing the theta entries of the current cMHN.
mutation_data (StateContainer) – Mutation data used to train the cMHN.
- Returns:
The computed gradient and score.
- Return type:
tuple
- mhn.training.likelihood_cmhn.gradient_and_score(double[:, :] theta, StateContainer mutation_data)#
Computes the gradient using both the CPU and CUDA implementation (only if CUDA is installed).
The function computes gradients for data points with few mutations using the CPU implementation, and for data points with many mutations using CUDA. If CUDA is not installed on your device, the function will only use the CPU implementation.
- Parameters:
theta (np.ndarray) – Matrix containing the theta entries of the current cMHN.
mutation_data (StateContainer) – Mutation data used to train the cMHN.
- Returns:
The computed gradient and score.
- Return type:
tuple
- mhn.training.likelihood_cmhn.CUDA_AVAILABLE#
constant returned by
cuda_available()if CUDA functions are available
- mhn.training.likelihood_cmhn.CUDA_NOT_AVAILABLE#
constant returned by
cuda_available()if CUDA functions are not available
- mhn.training.likelihood_cmhn.CUDA_NOT_FUNCTIONAL#
constant returned by
cuda_available()if CUDA functions don’t work as expected, in this case check your CUDA drivers