Ejemplo n.º 1
0
def test_cktest():
    traj = ellipsoids().observations(n_steps=10000)
    estimator = VAMP(1, dim=1).fit(traj)
    validator = estimator.chapman_kolmogorov_validator(4)
    cktest = validator.fit(traj).fetch_model()
    np.testing.assert_almost_equal(cktest.predictions,
                                   cktest.estimates,
                                   decimal=1)
Ejemplo n.º 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)
Ejemplo n.º 3
0
r"""
Ellipsoids dataset
==================

The :meth:`deeptime.data.ellipsoids` dataset.
"""

import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import multivariate_normal

from deeptime.data import ellipsoids

data_source = ellipsoids(seed=17)
x = np.linspace(-10, 10, 1000)
y = np.linspace(-10, 10, 1000)
X, Y = np.meshgrid(x, y)
pos = np.empty(X.shape + (2, ))
pos[:, :, 0] = X
pos[:, :, 1] = Y
rv1 = multivariate_normal(data_source.state_0_mean,
                          data_source.covariance_matrix)
rv2 = multivariate_normal(data_source.state_1_mean,
                          data_source.covariance_matrix)

fig = plt.figure()
ax = fig.gca()

ax.contourf(X, Y, (rv1.pdf(pos) + rv2.pdf(pos)).reshape(len(x), len(y)))
ax.autoscale(False)
ax.set_aspect('equal')
def plot_dominant_component(ax, dxy, title):
    x, y = np.meshgrid(
        np.linspace(np.min(feature_trajectory[:, 0]),
                    np.max(feature_trajectory[:, 0]), 4),
        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)