示例#1
0
def test_recover_timescale():
    trajs = double_well_discrete().simulate_trajectories(n_trajectories=100,
                                                         n_steps=50000)
    ts = double_well_discrete().analytic_msm.timescales(1)[0]
    counts = TransitionCountEstimator(1, 'sliding').fit(trajs).fetch_model()
    msm = MaximumLikelihoodMSM().fit(counts.submodel_largest()).fetch_model()
    ts_rec = msm.timescales(1)[0]
    np.testing.assert_(np.abs(ts - ts_rec) <= 200.)
示例#2
0
def compute_effective_stride(dtrajs, lagtime, n_states) -> int:
    r"""
    Computes the effective stride which is an estimate of the striding required to produce uncorrelated samples.
    By default this is the lagtime (lag sampling). A nonreversible MSM is estimated, if its number of states is larger
    than the number of states provided to this method, stride is set to the minimum of lagtime and two times the
    correlation time of the next neglected timescale.

    Parameters
    ----------
    dtrajs : array_like or list of array_like
        Discretized trajectory or list of discretized trajectories
    lagtime : int
        Lagtime
    n_states : int
        Number of resolved states

    Returns
    -------
    stride : int
        Estimated effective stride to produce approximately uncorrelated samples
    """
    from deeptime.util.types import ensure_dtraj_list
    dtrajs = ensure_dtraj_list(dtrajs)
    # by default use lag as stride (=lag sampling), because we currently have no better theory for deciding
    # how many uncorrelated counts we can make
    stride = lagtime
    # get a quick fit from the spectral radius of the non-reversible
    from deeptime.markov import TransitionCountEstimator
    count_model = TransitionCountEstimator(
        lagtime=lagtime, count_mode="sliding").fit(dtrajs).fetch_model()
    count_model = count_model.submodel_largest()
    from deeptime.markov.msm import MaximumLikelihoodMSM
    msm_non_rev = MaximumLikelihoodMSM(
        reversible=False, sparse=False).fit(count_model).fetch_model()
    # if we have more than n_states timescales in our MSM, we use the next (neglected) timescale as an
    # fit of the de-correlation time
    if msm_non_rev.n_states > n_states:
        # because we use non-reversible msm, we want to silence the ImaginaryEigenvalueWarning
        import warnings
        with warnings.catch_warnings():
            from deeptime.util.exceptions import ImaginaryEigenValueWarning
            warnings.filterwarnings('ignore',
                                    category=ImaginaryEigenValueWarning)
            correlation_time = max(1, msm_non_rev.timescales()[n_states - 1])
        # use the smaller of these two pessimistic estimates
        stride = int(min(lagtime, 2 * correlation_time))

    return stride