PyGT.mfpt

Calculate matricies of mean first passage times with graph transformation

Note

Install the pathos package to parallelize MFPT computations, with e.g.

```
pip install pathos
```
PyGT.mfpt.full_MFPT_matrix(B, tau, pool_size=1, screen=False, **kwargs)[source]

Compute full matrix of inter-microstate MFPTs with GT.

Parameters:
  • B (sparse or dense matrix (N,N)) – branching probability matrix.
  • tau (array-like (N,)) – vector of waiting times from each node.
  • pool_size (int,optional) – Number of cores over which to parallelize computation. only attempted if pool_size>1 and pathos package is installed. Default=1.
  • screen (bool, optional) – Show progress bar. Default=False
Returns:

mfpt – matrix of inter-microstate MFPTs between all pairs of nodes

Return type:

np.ndarray[float64] (N,N)

PyGT.mfpt.community_MFPT_matrix(communities, B, tau, pi, MS_approx=False, diagzero=True, pool_size=1, screen=False, **kwargs)[source]

Compute matrix of effective inter-macrostate MFPTs with GT, defined as

\[\begin{equation} \label{eq:PT} [ \mathcal{T}_\mathrm{C} ]_{IJ} = \frac{1}{\Pi_I \Pi_J} \sum_{i \in I} \sum_{j \in J} \pi_i \mathcal{T}_{ij} \pi_j - \frac{1}{\Pi_I \Pi_I} \sum_{i \in I} \sum_{i^\prime \in I} \pi_{i^\prime} \mathcal{T}_{i^\prime i} \pi_i, \end{equation}\]

This matrix has diagonal elements equal to zero and can be shown to satisfy the Kemeny constant constraint, and thus is suitable for producing a coarse grained rate matrix. If diagzero is set to False, an alternative matrix is computed where the second term of the above equation is ignored so that the diagonal elements of the matrix will no longer be zero. This alternative matrix also satisfies the Kemeny constant constraint. [Kannan20a]

Parameters:
  • communities (dict) – mapping from community ID (0-indexed) to a boolean array of shape (N, ) which selects out the states in that community. Communities must be disjoint. Communities must be disjoint.
  • B (sparse or dense matrix (N,N)) – branching probability matrix.
  • tau (array-like (N,), float) – vector of waiting times from each node.
  • pi (array-like (N,), float) – stationary probability distribution of microstates
  • MS_approx (bool, optional) – If True, assume all communities are sufficiently metastable to use only one microstate pair per community pair, a much more efficient but approximate computation. [Kannan20a]
  • diagzero (bool) – Choose the inter-community MFPTs such that the diagonal elements are zero. Defaults to True.
  • pool_size (int,optional) – Number of cores over which to parallelize computation. Default=1 Only active if MS_approx = False
  • screen (bool, optional) – Print progress. Default = False
Returns:

  • Pi (array-like (N_comm,)) – Macroscopic stationary distribution. Indexed in ascending order
  • tau_AB (dense matrix (N_comm,N_comm)) – matrix of effective inter-macrostate MFPTs

PyGT.mfpt.compute_MFPT(i, j, B, tau, block=1, **kwargs)[source]

Compute the inter-microstate \(i\leftrightarrow j\) MFPT using GT. Called by full_MFPT_matrix(). Unlike compute_rates() function, which assumes there is at least 2 microstates in the absorbing macrostate, this function does not require knowledge of equilibrium occupation probabilities since \(\mathcal{T}_{ij}=\tau_j^\prime/B_{ij}^\prime\) when there are only two nodes remaining after GT

Parameters:
  • i (int) – node-ID (0-indexed) of first microstate.
  • j (int) – node-ID (0-indexed) of second microstate.
  • B (sparse or dense matrix (N,N)) – branching probability matrix.
  • tau (array-like (N,)) – vector of waiting times from each node.
  • block (int, optional) – block size for matrix generalization GT procedure. Reverts to slower but guaranteed stable one-by-one GT (block=1) when numpy matrix inversion routine raises errors. Default=10
Returns:

  • MFPTij (float) – mean first passage time \(i \leftarrow j\)
  • MFPTji (float) – mean first passage time \(j \leftarrow i\)