Beispiel #1
0
 def setUpClass(cls):
     N_steps = 10000
     N_traj = 20
     lag = 1
     T = np.linalg.matrix_power(np.array([[0.7, 0.2, 0.1], [0.1, 0.8, 0.1], [0.1, 0.1, 0.8]]), lag)
     dtrajs = [generate(T, N_steps) for _ in range(N_traj)]
     p0 = np.zeros(3)
     p1 = np.zeros(3)
     trajs = []
     for dtraj in dtrajs:
         traj = np.zeros((N_steps, T.shape[0]))
         traj[np.arange(len(dtraj)), dtraj] = 1.0
         trajs.append(traj)
         p0 += traj[:-lag, :].sum(axis=0)
         p1 += traj[lag:, :].sum(axis=0)
     estimator = VAMP(scaling=None, var_cutoff=1.0)
     cov = VAMP.covariance_estimator(lagtime=lag).fit(trajs).fetch_model()
     vamp = estimator.fit(cov).fetch_model()
     msm = estimate_markov_model(dtrajs, lag=lag, reversible=False)
     cls.trajs = trajs
     cls.dtrajs = dtrajs
     cls.trajs_timeshifted = list(timeshifted_split(cls.trajs, lagtime=lag, chunksize=5000))
     cls.lag = lag
     cls.msm = msm
     cls.vamp = vamp
     cls.estimator = estimator
     cls.p0 = p0 / p0.sum()
     cls.p1 = p1 / p1.sum()
     cls.atol = np.finfo(np.float32).eps * 1000.0
Beispiel #2
0
def test_vamp_consistency():
    trajectory = ellipsoids(seed=13).observations(10000, n_dim=50)
    cov_estimator = VAMP.covariance_estimator(lagtime=1)
    cov_estimator.compute_ctt = False
    cov_estimator.reversible = True
    cov_estimator.fit(trajectory)
    koopman1 = VAMP(dim=2).fit(cov_estimator).fetch_model()
    koopman2 = TICA(dim=2, scaling=None,
                    lagtime=1).fit(trajectory).fetch_model()
    np.testing.assert_array_almost_equal(koopman1.singular_values,
                                         koopman2.singular_values,
                                         decimal=1)
    np.testing.assert_array_almost_equal(
        np.abs(koopman1.singular_vectors_left),
        np.abs(koopman2.singular_vectors_left),
        decimal=2)
    np.testing.assert_array_almost_equal(
        np.abs(koopman1.singular_vectors_right),
        np.abs(koopman2.singular_vectors_right),
        decimal=2)
    np.testing.assert_array_almost_equal(koopman1.timescales(),
                                         koopman2.timescales(),
                                         decimal=2)
Beispiel #3
0
def vamp_score_data(data, data_lagged, transformation=None, r=2, epsilon=1e-6, dim=None):
    r""" Computes VAMP score based on data and corresponding time-lagged data.
    Can be equipped with a transformation, defaults to 'identity' transformation.

    Parameters
    ----------
    data : (T, n) ndarray
        Instantaneous data.
    data_lagged : (T, n) ndarray
        Time-lagged data.
    transformation : Callable
        Transformation on data that will be scored.
    r : int or str, optional, default=2
        The type of VAMP score evaluated, see :meth:`deeptime.decomposition.vamp_score`.
    epsilon : float, optional, default=1e-6
        Regularization parameter for the score, see :meth:`deeptime.decomposition.vamp_score`.
    dim : int, optional, default=None
        Number of components that should be scored. Defaults to all components. See
        :meth:`deeptime.decomposition.vamp_score`.

    Returns
    -------
    score : float
        The VAMP score.

    See Also
    --------
    vamp_score
    """
    if transformation is None:
        def transformation(x):
            return x
    from deeptime.decomposition import VAMP
    cov_estimator = VAMP.covariance_estimator(1)
    cov = cov_estimator.partial_fit((transformation(data), transformation(data_lagged))).fetch_model()
    return VAMP().fit(cov).fetch_model().score(r=r, dim=dim, epsilon=epsilon)