Ejemplo n.º 1
0
def test_dim_and_var_cutoff(full_rank_time_series, dim, var_cutoff, partial_fit):
    # basically dim should be ignored here since var_cutoff takes precedence if it is None
    est = VAMP(lagtime=1, dim=dim, var_cutoff=var_cutoff)
    if partial_fit:
        for chunk in timeshifted_split(full_rank_time_series, lagtime=1, chunksize=15):
            est.partial_fit(chunk)
        est2 = VAMP(lagtime=1, dim=dim, var_cutoff=var_cutoff).fit(full_rank_time_series)
        np.testing.assert_array_almost_equal(est.fetch_model().operator,
                                             est2.fetch_model().operator, decimal=4)  # can fail on M$ with higher acc.
    else:
        est.fit(full_rank_time_series)
    projection = est.transform(full_rank_time_series)
    np.testing.assert_equal(projection.shape[0], full_rank_time_series.shape[0])
    if var_cutoff is not None:
        if var_cutoff == 1.:
            # data is internally mean-free
            np.testing.assert_equal(projection.shape[1], full_rank_time_series.shape[1] - 1)
        else:
            np.testing.assert_array_less(projection.shape[1], full_rank_time_series.shape[1])
    else:
        if dim is None:
            # data is internally mean-free
            np.testing.assert_equal(projection.shape[1], full_rank_time_series.shape[1] - 1)
        else:
            np.testing.assert_equal(projection.shape[1], dim)
Ejemplo n.º 2
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
        np.linspace(np.min(feature_trajectory[:, 1]),
                    np.max(feature_trajectory[:, 1]), 4))
    ax.scatter(*feature_trajectory.T, marker='.')
    ax.quiver(x, y, dxy[0], dxy[1])
    ax.set_title(title)
    ax.set_aspect('equal')
    ax.set_xlabel('x')
    ax.set_ylabel('y')


data = ellipsoids(seed=17)
discrete_trajectory = data.discrete_trajectory(n_steps=1000)
feature_trajectory = data.map_discrete_to_observations(discrete_trajectory)

vamp = VAMP(dim=1, lagtime=1)
vamp = vamp.fit(feature_trajectory).fetch_model()
vamp_projection = vamp.transform(feature_trajectory)
dxy_vamp = vamp.singular_vectors_left[:, 0]  # dominant vamp component

tica = TICA(dim=1, lagtime=1)
tica = tica.fit(feature_trajectory).fetch_model()
tica_projection = tica.transform(feature_trajectory)
dxy_tica = tica.singular_vectors_left[:, 0]  # dominant tica component

pca = PCA(n_components=1)
pca.fit(feature_trajectory)
pca_projection = pca.transform(feature_trajectory)
dxy_pca = pca.components_[0]  # dominant pca component

f = plt.figure(constrained_layout=False, figsize=(14, 14))
gs = f.add_gridspec(nrows=2, ncols=3)