msmbuilder.hmm.GaussianHMM

class msmbuilder.hmm.GaussianHMM

Reversible Gaussian Hidden Markov Model L1-Fusion Regularization

This model estimates Hidden Markov model for a vector dataset which is contained to be reversible (satisfy detailed balance) with Gaussian emission distributions. This model is similar to a MarkovStateModel without a “hard” assignments of conformations to clusters. Optionally, it can apply L1-regularization to the positions of the Gaussians. See [1] for details.

Parameters:
n_states : int

The number of components (states) in the model

n_init : int

Number of time the EM algorithm will be run with different random seeds. The final results will be the best output of n_init consecutive runs in terms of log likelihood.

n_iter : int

The maximum number of iterations of expectation-maximization to run during each fitting round.

n_lqa_iter : int

The number of iterations of the local quadratic approximation fixed point equations to solve when computing the new means with a nonzero L1 fusion penalty.

thresh : float

Convergence threshold for the log-likelihood during expectation maximization. When the increase in the log-likelihood is less than thresh between subsequent rounds of E-M, fitting will finish.

fusion_prior : float

The strength of the L1 fusion prior.

reversible_type : str

Method by which the reversibility of the transition matrix is enforced. ‘mle’ uses a maximum likelihood method that is solved by numerical optimization (BFGS), and ‘transpose’ uses a more restrictive (but less computationally complex) direct symmetrization of the expected number of counts.

vars_prior : float, optional

A prior used on the variance. This can be useful in the undersampled regime where states may be collapsing onto a single point, but is generally not needed.

vars_weight : float, optional

Weight of the vars prior

random_state : int, optional

Random state, used during sampling.

timing : bool, default=False

Print detailed timing information about the fitting process.

n_hotstart : {int, ‘all’}

Number of sequences to use when hotstarting the EM. Default=’all’

init_algo : str

Use this algorithm to hotstart the means and covariances. Must be one of “kmeans” or “GMM”

References

[1]McGibbon, Robert T. et al., “Understanding Protein Dynamics with L1-Regularized Reversible Hidden Markov Models” Proc. 31st Intl. Conf. on Machine Learning (ICML). 2014.
Attributes:
means_ :
vars_ :
transmat_ :
populations_ :
fit_logprob_ :

Methods

draw_centroids Find conformations most representative of model means.
draw_samples Sample conformations from each state.
fit Estimate model parameters.
fit_predict Find most likely hidden-state sequence corresponding to each data timeseries.
predict Find most likely hidden-state sequence corresponding to each data timeseries.
score Log-likelihood of sequences under the model
summarize Get a string summarizing the model.
draw_centroids()

Find conformations most representative of model means.

Parameters:
sequences : list

List of 2-dimensional array observation sequences, each of which has shape (n_samples_i, n_features), where n_samples_i is the length of the i_th observation.

Returns:
centroid_pairs_by_state : np.ndarray, dtype=int, shape = (n_states, 1, 2)

centroid_pairs_by_state[state, 0] = (trj, frame) gives the trajectory and frame index associated with the mean of state

mean_approx : np.ndarray, dtype=float, shape = (n_states, 1, n_features)

mean_approx[state, 0] gives the features at the representative point for state

See also

utils.map_drawn_samples
Extract conformations from MD trajectories by index.
GaussianHMM.draw_samples
Draw samples from GHMM
draw_samples()

Sample conformations from each state.

Parameters:
sequences : list

List of 2-dimensional array observation sequences, each of which has shape (n_samples_i, n_features), where n_samples_i is the length of the i_th observation.

n_samples : int

How many samples to return from each state

scheme : str, optional, default=’even’

Must be one of [‘even’, “maxent”].

match_vars : bool, default=False

Flag for matching variances in maxent discrete approximation

Returns:
selected_pairs_by_state : np.array, dtype=int, shape=(n_states, n_samples, 2)

selected_pairs_by_state[state] gives an array of randomly selected (trj, frame) pairs from the specified state.

sample_features : np.ndarray, dtype=float, shape = (n_states, n_samples, n_features)

sample_features[state, sample] gives the features for the given sample of state

See also

utils.map_drawn_samples
Extract conformations from MD trajectories by index.
GaussianHMM.draw_centroids
Draw centers from GHMM

Notes

With scheme=’even’, this function assigns frames to states crisply then samples from the uniform distribution on the frames belonging to each state. With scheme=’maxent’, this scheme uses a maximum entropy method to determine a discrete distribution on samples whose mean (and possibly variance) matches the GHMM means.

fit()

Estimate model parameters.

Parameters:
sequences : list

List of 2-dimensional array observation sequences, each of which has shape (n_samples_i, n_features), where n_samples_i is the length of the i_th observation.

fit_predict()

Find most likely hidden-state sequence corresponding to each data timeseries.

Uses the Viterbi algorithm.

Parameters:
sequences : list

List of 2-dimensional array observation sequences, each of which has shape (n_samples_i, n_features), where n_samples_i is the length of the i_th observation.

Returns:
viterbi_logprob : float

Log probability of the maximum likelihood path through the HMM.

hidden_sequences : list of np.ndarrays[dtype=int, shape=n_samples_i]

Index of the most likely states for each observation.

predict()

Find most likely hidden-state sequence corresponding to each data timeseries.

Uses the Viterbi algorithm.

Parameters:
sequences : list

List of 2-dimensional array observation sequences, each of which has shape (n_samples_i, n_features), where n_samples_i is the length of the i_th observation.

Returns:
viterbi_logprob : float

Log probability of the maximum likelihood path through the HMM.

hidden_sequences : list of np.ndarrays[dtype=int, shape=n_samples_i]

Index of the most likely states for each observation.

score()

Log-likelihood of sequences under the model

Parameters:
sequences : list

List of 2-dimensional array observation sequences, each of which has shape (n_samples_i, n_features), where n_samples_i is the length of the i_th observation.

summarize()

Get a string summarizing the model.

timescales_

The implied relaxation timescales of the hidden Markov transition matrix

By diagonalizing the transition matrix, its propagation of an arbitrary initial probability vector can be written as a sum of the eigenvectors of the transition weighted by per-eigenvector term that decays exponentially with time. Each of these eigenvectors describes a “dynamical mode” of the transition matrix and has a characteristic timescale, which gives the timescale on which that mode decays towards equilibrium. These timescales are given by \(-1/log(u_i)\) where \(u_i\) are the eigenvalues of the transition matrix. In a reversible HMM with N states, the number of timescales is at most N-1. (The -1 comes from the fact that the stationary distribution of the chain is associated with an eigenvalue of 1, and an infinite characteristic timescale). The number of timescales can be less than N-1 for every eigenvalue of the transition matrix that is negative (which is allowable by detailed balance).

Returns:
timescales : array, shape=[n_timescales]

The characteristic timescales of the transition matrix. If the model has not been fit or does not have a transition matrix, the return value will be None.