ContinuousTimeMSM([lag_time, n_timescales, ...]) | Reversible first order master equation model |
Consider an n-state time-homogeneous Markov process, \(X(t)\) At time \(t\), the \(n\)-vector \(P(t) = Pr[ X(t) = i ]\) is probability that the system is in each of the \(n\) states. These probabilities evolve forward in time, governed by an \(n \times n\) transition rate matrix \(K\)
The solution is
Where \(\exp(tK)\) is the matrix exponential. Written differently, the state-to-state lag-\(\tau\) transition probabilities are
For this model, we observe the evolution of one or more chains, \(X(t)\) at a regular interval, \(\tau\). Let \(C_{ij}\) be the number of times the chain was observed at state \(i\) at time \(t\) and at state \(j\) at time \(t+\tau\) (the number of observed transition counts). Suppose that \(K\) depends on a length-\(b\) parameter vector, \(\theta\). The log-likelihood is
This code parameterizes \(K(\theta)\) such that \(K\) is constrained to satisfy detailed balance with respect to a stationary distribution, \(\pi\). For an \(n\)-state model, \(\theta\) is of length \(n(n-1)/2 + n\). The first \(n(n-1)/2\) elements of \(\theta\) are the parameterize the symmetric rate matrix, \(S\), and the remaining \(n\) entries parameterize the stationary distribution. For \(n=4\), the function \(K(\theta)\) is
where the diagonal elements \(k_{ii}\) are set such that the row sums of \(K\) are all zero, \(k_{ii} = -\sum_{j != i} K_{ij}\). This form for \(K\) satisfies detailed balance by construction
Note that \(K\) is built from \(\exp(\theta)\). This parameterization makes optimization easier, since it keeps the off-diagonal entries positive and the diagonal entries negative. The optimization with respect to \(\theta\) without constraints.
Using the dense parameterization, it is not possible for elements of \(K\) to be exactly zero, because the symmetric rate matrix is parameterized in log-space. Thus, ContinuousTimeMSM also includes an ability to find a sparse rate matrix, through an alternative parameterization. In the sparse parameterization, certain entries in \(\theta\) are fixed at \(-\infty\), such that \(s_u = 0\). The indices of the “active” elements in \(\theta\) are stored in an array of indices, inds, and a compressed representation of theta is used, with only the “active” elements explicitly.
ContinuousTimeMSM uses L-BFGS-B to find a maximum likelihood estimate (MLE) rate matrix, \(\hat{\theta}\) and \(K(\hat{\theta})\). By default, the algorithm works first be estimating a fully dense rate matrix. Then, small off-diagonal elements of K are taken as candidates for truncation to zero. A new optimization using the sparse parameterization is performed with these elements constrained. If the log-likelihood of the sparse model is superior to the log likelihood of the dense model, it is retained.
build_ratemat(theta, n, inds, out[, which]) | Build the reversible rate matrix K or symmetric rate matrix, S, |
dK_dtheta_A(theta, n, u, A[, out]) | Compute the sum of the Hadamard (element-wise) product of the derivative of (the rate matrix, K, with respect to the free parameters,`theta`, dK_ij / dtheta_u) and another matrix, A. |
loglikelihood(theta, counts, n[, t]) | Log likelihood and gradient of the log likelihood of a continuous-time Markov model. |
hessian(theta, counts[, t]) | Estimate of the hessian of the log-likelihood with respect to theta. |
sigma_K(covar_theta, theta, n) | Estimate the asymptotic standard deviation (uncertainty in the rate |
sigma_pi(covar_theta, theta, n) | Estimate the asymptotic standard deviation (uncertainty) in the stationary distribution, pi. |
sigma_eigenvalues(covar_theta, theta, n) | Estimate the asymptotic standard deviation (uncertainty) in the |
sigma_timescales | sigma_timescales(covar_theta, theta, n): |
eig_K(A, n[, pi, which]) | Diagonalize the rate matrix, K, from either the matrix K or the symmetric rate matrix, S. |
[1] | Kalbfleisch, J. D., and Jerald F. Lawless. “The analysis of panel data under a Markov assumption.” J. Am. Stat. Assoc. 80.392 (1985): 863-871. |