pyemma.msm.BayesianHMSM

class pyemma.msm.BayesianHMSM(*args, **kwargs)

Estimator for a Bayesian Hidden Markov state model

__init__(nstates=2, lag=1, stride='effective', p0_prior='mixed', transition_matrix_prior='mixed', nsamples=100, init_hmsm=None, reversible=True, stationary=False, connectivity='largest', mincount_connectivity='1/n', separate=None, observe_nonempty=True, dt_traj='1 step', conf=0.95, store_hidden=False, show_progress=True)

Estimator for a Bayesian HMSM

Parameters
  • nstates (int, optional, default=2) – number of hidden states

  • lag (int, optional, default=1) – lagtime to estimate the HMSM at

  • stride (str or int, default=1) –

    stride between two lagged trajectories extracted from the input trajectories. Given trajectory s[t], stride and lag will result in trajectories

    s[0], s[tau], s[2 tau], … s[stride], s[stride + tau], s[stride + 2 tau], …

    Setting stride = 1 will result in using all data (useful for maximum likelihood estimator), while a Bayesian estimator requires a longer stride in order to have statistically uncorrelated trajectories. Setting stride = None ‘effective’ uses the largest neglected timescale as an estimate for the correlation time and sets the stride accordingly.

  • p0_prior (None, str, float or ndarray(n)) –

    Prior for the initial distribution of the HMM. Will only be active if stationary=False (stationary=True means that p0 is identical to the stationary distribution of the transition matrix). Currently implements different versions of the Dirichlet prior that is conjugate to the Dirichlet distribution of p0. p0 is sampled from:

    where \(n_i\) are the number of times a hidden trajectory was in state \(i\) at time step 0 and \(a_i\) is the prior count. Following options are available:

    • ’mixed’ (default), \(a_i = p_{0,init}\), where \(p_{0,init}\) is the initial distribution of initial_model.

    • ndarray(n) or float, the given array will be used as A.

    • ’uniform’, \(a_i = 1\)

    • None, \(a_i = 0\). This option ensures coincidence between sample mean an MLE. Will sooner or later lead to sampling problems, because as soon as zero trajectories are drawn from a given state, the sampler cannot recover and that state will never serve as a starting state subsequently. Only recommended in the large data regime and when the probability to sample zero trajectories from any state is negligible.

  • transition_matrix_prior (str or ndarray(n, n)) –

    Prior for the HMM transition matrix. Currently implements Dirichlet priors if reversible=False and reversible transition matrix priors as described in 3 if reversible=True. For the nonreversible case the posterior of transition matrix \(P\) is:

    where \(c_{ij}\) are the number of transitions found for hidden trajectories and \(b_{ij}\) are prior counts.

    • ’mixed’ (default), \(b_{ij} = p_{ij,init}\), where \(p_{ij,init}\) is the transition matrix of initial_model. That means one prior count will be used per row.

    • ndarray(n, n) or broadcastable, the given array will be used as B.

    • ’uniform’, \(b_{ij} = 1\)

    • None, \(b_ij = 0\). This option ensures coincidence between sample mean an MLE. Will sooner or later lead to sampling problems, because as soon as a transition \(ij\) will not occur in a sample, the sampler cannot recover and that transition will never be sampled again. This option is not recommended unless you have a small HMM and a lot of data.

  • init_hmsm (HMSM, default=None) – Single-point estimate of HMSM object around which errors will be evaluated. If None is give an initial estimate will be automatically generated using the given parameters.

  • store_hidden (bool, optional, default=False) – store hidden trajectories in sampled HMMs

  • show_progress (bool, default=True) – Show progressbars for calculation?

References

1

F. Noe, H. Wu, J.-H. Prinz and N. Plattner: Projected and hidden Markov models for calculating kinetics and metastable states of complex molecules. J. Chem. Phys. 139, 184114 (2013)

2

J. D. Chodera Et Al: Bayesian hidden Markov model analysis of single-molecule force spectroscopy: Characterizing kinetics under measurement uncertainty. arXiv:1108.1430 (2011)

3

Trendelkamp-Schroer, B., H. Wu, F. Paul and F. Noe: Estimation and uncertainty of reversible Markov models. J. Chem. Phys. 143, 174101 (2015).

Methods

_Loggable__create_logger()

_ProgressReporterMixin__check_stage_registered(stage)

_SerializableMixIn__interpolate(state, klass)

__delattr__(name, /)

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__(other)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__getstate__()

__gt__(value, /)

Return self>value.

__init__([nstates, lag, stride, p0_prior, …])

Estimator for a Bayesian HMSM

__init_subclass__(*args, **kwargs)

This method is called when a class is subclassed.

__le__(value, /)

Return self<=value.

__lt__(value, /)

Return self<value.

__my_getstate__()

__my_setstate__(state)

__ne__(value, /)

Return self!=value.

__new__(cls, *args, **kwargs)

Create and return a new object.

__reduce__()

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__()

Return repr(self).

__setattr__(name, value, /)

Implement setattr(self, name, value).

__setstate__(state)

__sizeof__()

Size of object in memory, in bytes.

__str__()

Return str(self).

__subclasshook__

Abstract classes can override this to customize issubclass().

_assert_in_active(A)

Checks if set A is within the active set

_assert_metastable()

Tests if pcca object is available, or else raises a ValueError.

_check_estimated()

_check_samples_available()

_cleanup_logger(logger_id, logger_name)

_committor_backward(P, A, B[, mu])

_committor_forward(P, A, B)

_compute_eigendecomposition(neig)

Conducts the eigenvalue decomposition and stores k eigenvalues, left and right eigenvectors

_compute_eigenvalues(neig)

Conducts the eigenvalue decomposition and stores k eigenvalues, left and right eigenvectors

_ensure_eigendecomposition([neig])

Ensures that eigendecomposition has been performed with at least neig eigenpairs

_ensure_eigenvalues([neig])

Ensures that at least neig eigenvalues have been computed

_estimate(dtrajs)

_get_classes_to_inspect()

gets classes self derives from which 1.

_get_interpolation_map(cls)

_get_model_param_names()

Get parameter names for the model

_get_param_names()

Get parameter names for the estimator

_get_private_field(cls, name[, default])

_get_serialize_fields(cls)

_get_state_of_serializeable_fields(klass, state)

:return a dictionary {k:v} for k in self.serialize_fields and v=getattr(self, k)

_get_version(cls[, require])

_get_version_for_class_from_state(state, klass)

retrieves the version of the current klass from the state mapping from old locations to new ones.

_logger_is_active(level)

@param level: int log level (debug=10, info=20, warn=30, error=40, critical=50)

_mfpt(P, A, B[, mu])

_progress_context([stage])

param stage

_progress_force_finish([stage, description])

forcefully finish the progress for given stage

_progress_register(amount_of_work[, …])

Registers a progress which can be reported/displayed via a progress bar.

_progress_set_description(stage, description)

set description of an already existing progress

_progress_update(numerator_increment[, …])

Updates the progress.

_set_state_from_serializeable_fields_and_state(…)

set only fields from state, which are present in klass.__serialize_fields

cktest([mlags, conf, err_est, n_jobs, …])

Conducts a Chapman-Kolmogorow test.

committor_backward(A, B)

Backward committor from set A to set B

committor_forward(A, B)

Forward committor (also known as p_fold or splitting probability) from set A to set B

correlation(a[, b, maxtime, k, ncv])

Time-correlation for equilibrium experiment.

eigenvalues([k])

Compute the transition matrix eigenvalues

eigenvectors_left([k])

Compute the left transition matrix eigenvectors

eigenvectors_right([k])

Compute the right transition matrix eigenvectors

estimate(X, **params)

Estimates the model given the data X

expectation(a)

Equilibrium expectation value of a given observable.

fingerprint_correlation(a[, b, k, ncv])

Dynamical fingerprint for equilibrium time-correlation experiment.

fingerprint_relaxation(p0, a[, k, ncv])

Dynamical fingerprint for perturbation/relaxation experiment.

fit(X[, y])

Estimates parameters - for compatibility with sklearn.

get_model_params([deep])

Get parameters for this model.

get_params([deep])

Get parameters for this estimator.

load(file_name[, model_name])

Loads a previously saved PyEMMA object from disk.

mfpt(A, B)

Mean first passage times from set A to set B, in units of the input trajectory time step

pcca(m)

Runs PCCA++ 1 to compute a metastable decomposition of MSM states

propagate(p0, k)

Propagates the initial distribution p0 k times

relaxation(p0, a[, maxtime, k, ncv])

Simulates a perturbation-relaxation experiment.

sample_by_observation_probabilities(nsample)

Generates samples according to the current observation probability distribution

sample_conf(f, *args, **kwargs)

Sample confidence interval of numerical method f over all samples

sample_f(f, *args, **kwargs)

Evaluated method f for all samples

sample_mean(f, *args, **kwargs)

Sample mean of numerical method f over all samples

sample_std(f, *args, **kwargs)

Sample standard deviation of numerical method f over all samples

save(file_name[, model_name, overwrite, …])

saves the current state of this object to given file and name.

set_model_params([samples, conf, P, pobs, …])

param samples

sampled MSMs

set_params(**params)

Set the parameters of this estimator.

simulate(N[, start, stop, dt])

Generates a realization of the Hidden Markov Model

submodel([states, obs, …])

Returns a HMM with restricted state space

submodel_disconnect([mincount_connectivity])

Disconnects sets of hidden states that are barely connected

submodel_largest([strong, mincount_connectivity])

Returns the largest connected sub-HMM (convenience function)

submodel_populous([strong, …])

Returns the most populous connected sub-HMM (convenience function)

timescales([k])

The relaxation timescales corresponding to the eigenvalues

trajectory_weights()

Uses the HMSM to assign a probability weight to each trajectory frame.

transition_matrix_obs([k])

Computes the transition matrix between observed states

update_model_params(**params)

Update given model parameter if they are set to specific values

Attributes

P

The transition matrix on the active set.

_BayesianHMSM__serialize_fields

_BayesianHMSM__serialize_version

_Estimator__serialize_fields

_HMSM__serialize_version

_Loggable__ids

_Loggable__refs

_MSM__serialize_fields

_MSM__serialize_version

_MaximumLikelihoodHMSM__serialize_fields

_MaximumLikelihoodHMSM__serialize_version

_SampledHMSM__serialize_version

_SerializableMixIn__serialize_fields

_SerializableMixIn__serialize_modifications_map

_SerializableMixIn__serialize_version

__dict__

__doc__

__hash__

__module__

__weakref__

list of weak references to the object (if defined)

_estimated

_loglevel_CRITICAL

_loglevel_DEBUG

_loglevel_ERROR

_loglevel_INFO

_loglevel_WARN

_pg_threshold

_prog_rep_callbacks

_prog_rep_descriptions

_prog_rep_progressbars

_progress_num_registered

_progress_registered_stages

_save_data_producer

active_set

The active set of hidden states on which all hidden state computations are done

discrete_trajectories_full

A list of integer arrays with the original trajectories.

discrete_trajectories_lagged

Transformed original trajectories that are used as an input into the HMM estimation

discrete_trajectories_obs

A list of integer arrays with the discrete trajectories mapped to the observation mode used.

dt_model

Description of the physical time corresponding to the lag.

dt_traj

dtrajs_full

A list of integer arrays with the original trajectories.

dtrajs_lagged

Transformed original trajectories that are used as an input into the HMM estimation

dtrajs_obs

A list of integer arrays with the discrete trajectories mapped to the observation mode used.

eigenvectors_left_obs

eigenvectors_right_obs

init_hmsm

is_reversible

Returns whether the MSM is reversible

is_sparse

Returns whether the MSM is sparse

lagtime

The lag time in steps

lifetimes

Lifetimes of states of the hidden transition matrix

logger

The logger for this class instance

metastable_assignments

Computes the assignment to metastable sets for observable states

metastable_distributions

Returns the output probability distributions. Identical to

metastable_memberships

Computes the memberships of observable states to metastable sets by

metastable_sets

Computes the metastable sets of observable states within each

model

The model estimated by this Estimator

msm_init

n_metastable

Number of states chosen for PCCA++ computation.

name

The name of this instance

neig

number of eigenvalues to compute.

nstates

Number of active states on which all computations and estimations are done

nstates_obs

Number of states in discrete trajectories

observable_set

The active set of states on which all computations and estimations will be done

observable_state_indexes

Ensures that the observable states are indexed and returns the indices

observation_probabilities

returns the output probability matrix

pi

The stationary distribution on the MSM states

reversible

Returns whether the MSM is reversible

samples

show_progress

whether to show the progress of heavy calculations on this object.

sparse

Returns whether the MSM is sparse

stationary_distribution

The stationary distribution on the MSM states

stationary_distribution_obs

timestep_model

Physical time corresponding to one transition matrix step, e.g.

transition_matrix

The transition matrix on the active set.