The Likelihood submodule#
This submodule implements Likelihood.R from the original implementation in Cython.
It contains functions to compute the log-likelihood score and its gradient without state-space restriction as well as functions for matrix-vector multiplications with the transition rate matrix and [I-Q]^(-1). There are also functions to compute the probability distribution represented by an cMHN.
- mhn.full_state_space.Likelihood.cuda_compute_inverse(double[:, :] theta, double[:] b, bool transp=False)#
Computes the solution for [I-Q] x = b on the GPU.
This function can only be used if the mhn package was compiled with CUDA.
- Parameters:
theta (np.ndarray[np.double_t]) – The theta matrix representing the cMHN.
b (np.ndarray[np.double_t]) – A vector that is multiplied with [I-Q]^(-1).
transp (bool, optional) – If set to True, computes the solution for [I-Q]^T x = b. Defaults to False.
- Returns:
The solution for [I-Q] x = b.
- Return type:
np.ndarray[np.double_t]
- Raises:
RuntimeError – If the mhn package was not compiled with CUDA.
- mhn.full_state_space.Likelihood.cuda_fisher(double[:, :] theta)#
Computes the Fisher information matrix of a cMHN on the GPU.
This function can only be used if the mhn package was compiled with CUDA.
- Parameters:
theta (np.ndarray[np.double_t]) – The theta matrix representing the cMHN.
- Returns:
The Fisher information matrix.
- Return type:
np.ndarray[np.double_t]
- Raises:
RuntimeError – If the mhn package was not compiled with CUDA.
- mhn.full_state_space.Likelihood.cuda_gradient_and_score(double[:, :] theta, double[:] pD)#
Computes the log-likelihood score and its gradient for a given theta and a given empirical distribution.
This function can only be used if the mhn package was compiled with CUDA.
- Parameters:
theta (np.ndarray[np.double_t]) – The theta matrix representing the cMHN.
pD (np.ndarray[np.double_t]) – The probability distribution according to the training data.
- Returns:
The gradient and the log-likelihood score.
- Return type:
tuple
- Raises:
RuntimeError – If the mhn package was not compiled with CUDA.
- mhn.full_state_space.Likelihood.generate_pTh(double[:, :] theta, p0=None) ndarray#
Returns the probability distribution given by theta.
- Parameters:
theta (np.ndarray[np.double_t]) – The matrix representing the cMHN parameters.
p0 (optional) – The initial probability distribution. If None, it assumes no initial active events. Defaults to None.
- Returns:
The probability distribution computed from the given theta.
- Return type:
np.ndarray[np.double_t]
- mhn.full_state_space.Likelihood.grad(double[:, :] theta, ndarray pD, ndarray pth_space=None) np.ndarray#
Implements the gradient calculation of equation 7.
- Parameters:
theta (np.ndarray[np.double_t]) – The matrix representing the cMHN parameters.
pD (np.ndarray[np.double_t]) – The probability distribution in the data.
pth_space (optional, np.ndarray[np.double_t]) – Optional parameter for performance optimization. If provided, it allows communication with the score function, reducing computation time. Defaults to None.
- Returns:
The gradient calculated according to equation 7.
- Return type:
np.ndarray[np.double_t]
- mhn.full_state_space.Likelihood.jacobi(double[:, :] theta, ndarray b, bool transp=False) ndarray#
Returns the solution for [I - Q] x = b.
- Parameters:
theta (np.ndarray[np.double_t]) – Thetas used to construct the transition rate matrix Q.
b (np.ndarray[np.double_t]) – The vector on the right-hand side of the equation.
transp (bool, optional) – If True, returns the solution for ([I - Q]^-1)^T x = b. Defaults to False.
- Returns:
The solution vector x for the equation [I - Q] x = b.
- Return type:
np.ndarray[np.double_t]
- mhn.full_state_space.Likelihood.q_vec(double[:, :] theta, double[:] x, bool diag=False, bool transp=False) ndarray#
Multiplies the vector x with the transition rate matrix Q.
- Parameters:
theta (np.ndarray[np.double_t]) – Thetas used to construct the transition rate matrix Q.
x (np.ndarray[np.double_t]) – Vector that is multiplied with Q.
diag (bool, optional) – If False, the diagonal of Q is set to zero. Defaults to False.
transp (bool, optional) – If True, x is multiplied with Q^T (transposed Q). Defaults to False.
- Returns:
The product of Q and x.
- Return type:
np.ndarray[np.double_t]
- mhn.full_state_space.Likelihood.score(double[:, :] theta, ndarray pD, ndarray pth_space=None) float#
Calculates the score for the current theta.
- Parameters:
theta (np.ndarray[np.double_t]) – The matrix representing the cMHN parameters.
pD (np.ndarray[np.double_t]) – The probability distribution in the data.
pth_space (optional, np.ndarray[np.double_t]) – Optional parameter for performance optimization. If provided, it allows communication with the gradient function, reducing computation time. Defaults to None.
- Returns:
The score value for the given theta.
- Return type:
float