The ModelConstruction submodule#

This submodule implements ModelConstruction.R from the original implementation in Cython.

It contains functions to generate random MHNs, build their transition rate matrix Q, the diagonal of Q, and to generate and independence model for a given distribution

mhn.full_state_space.ModelConstruction.build_q(ndarray theta: np.ndarray) np.ndarray#

Build the transition rate matrix Q for a given MHN.

Parameters:

theta (np.ndarray) – A 2D array representing the MHN.

Returns:

A 2D array representing the transition rate matrix Q constructed from the subdiagonals of Theta.

Return type:

np.ndarray

mhn.full_state_space.ModelConstruction.learn_indep(ndarray pD: np.ndarray) np.ndarray#

Learns an independence model from the data distribution, which assumes that no events interact. This model is used to initialize the parameters of the actual model before optimization.

Parameters:

pD (np.ndarray) – Probability distribution of the events in the data.

Returns:

The learned independence model.

Return type:

np.ndarray

mhn.full_state_space.ModelConstruction.q_diag(double[:, :] theta) ndarray#

Get the diagonal of the transition rate matrix Q for a given MHN.

Parameters:

theta (np.ndarray) – A 2D array representing the MHN.

Returns:

A 1D array representing the diagonal of the transition rate matrix Q.

Return type:

np.ndarray

mhn.full_state_space.ModelConstruction.q_subdiag(double[:, :] theta, int i) ndarray#

Creates a single subdiagonal of Q from the ith row in Theta.

Parameters:
  • theta (np.ndarray) – A 2D array representing the Theta matrix.

  • i (int) – The index of the row in Theta from which the subdiagonal of Q is created.

Returns:

A 1D array representing the subdiagonal of Q corresponding to the ith row of Theta.

Return type:

np.ndarray

mhn.full_state_space.ModelConstruction.random_theta(n: int, double sparsity: float = 0, rounded: bool = True) np.ndarray#

Creates a random cMHN Theta matrix (logarithmic format).

Parameters:
  • n (int) – Number of events considered by the MHN. The corresponding Q matrix will have size 2^n.

  • sparsity (float, optional) – Sparsity of Theta as a percentage (default is 0).

  • rounded (bool, optional) – If True, the random Theta is rounded to two decimal places (default is True).

Returns:

Randomly generated MHN.

Return type:

np.ndarray