Example #1
0
 def test_kinetic_map(self):
     tica = TICA(scaling='km', dim=None,
                 lagtime=self.lagtime).fit(self.data).fetch_model()
     O = tica.transform(self.data)
     vars = np.var(O, axis=0)
     refs = tica.singular_values**2
     assert np.max(np.abs(vars - refs)) < 0.01
Example #2
0
def test_dim_parameter():
    np.testing.assert_equal(TICA(dim=3).dim, 3)
    np.testing.assert_equal(TICA(var_cutoff=.5).var_cutoff, 0.5)
    with np.testing.assert_raises(ValueError):
        TICA(dim=-1)  # negative int
    with np.testing.assert_raises(ValueError):
        TICA(var_cutoff=5.5)  # float > 1
    with np.testing.assert_raises(ValueError):
        TICA(var_cutoff=-0.1)  # negative float
Example #3
0
def test_fit_from_cov():
    data = np.random.normal(size=(500, 3))
    # fitting with C0t and symmetric covariances, should pass
    TICA().fit(Covariance(1, compute_c0t=True, reversible=True).fit(data))

    with np.testing.assert_raises(ValueError):
        TICA().fit(Covariance(1, compute_c0t=True, reversible=False).fit(data))

    with np.testing.assert_raises(ValueError):
        TICA().fit(Covariance(1, compute_c0t=False, reversible=True).fit(data))
Example #4
0
    def test_dimension(self):
        assert self.model_unscaled.output_dimension == 1
        # Test other variants
        model = TICA(var_cutoff=1.0,
                     lagtime=self.lagtime).fit(self.data).fetch_model()
        assert model.output_dimension == 2
        model = TICA(var_cutoff=.9,
                     lagtime=self.lagtime).fit(self.data).fetch_model()
        assert model.output_dimension == 1

        invalid_dims = [0, 0.0, 1.1, -1]
        for invalid_dim in invalid_dims:
            with self.assertRaises(ValueError):
                TICA(dim=invalid_dim)
Example #5
0
def test_constant_features():
    z = np.zeros((100, 10))
    o = np.ones((100, 10))
    z_lagged = (z[:-10], z[10:])
    o_lagged = (o[:-10], o[10:])
    tica_obj = TICA()
    cov_estimator = TICA.covariance_estimator(lagtime=1)
    cov_estimator.partial_fit(z_lagged)
    with np.testing.assert_raises(ZeroRankError):
        model = tica_obj.fit(cov_estimator.fetch_model())
        _ = model.timescales(lagtime=1)
        tica_obj.transform(z)
    cov_estimator.partial_fit(o_lagged)
    try:
        model = tica_obj.fit(cov_estimator).fetch_model()
        _ = model.timescales(lagtime=1)
        tica_obj.transform(z)
    except ZeroRankError:
        pytest.fail('ZeroRankError was raised unexpectedly.')
Example #6
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)
Example #7
0
    def setUpClass(cls):
        test_data = generate_hmm_test_data()
        cls.lagtime = test_data['lagtime']
        cls.cov_ref_00 = test_data['cov_ref_00']
        cls.cov_ref_00_nr = test_data['cov_ref_00_nr']
        cls.cov_ref_0t = test_data['cov_ref_0t']
        cls.cov_ref_0t_nr = test_data['cov_ref_0t_nr']
        cls.data = test_data['data']

        # perform unscaled TICA
        cls.model_unscaled = TICA(dim=1, lagtime=cls.lagtime,
                                  scaling=None).fit_from_timeseries(
                                      cls.data).fetch_model()
        cls.transformed_data_unscaled = cls.model_unscaled.transform(cls.data)
Example #8
0
def test_fit_reset():
    lag = 100
    np.random.seed(0)
    data = np.random.randn(23000, 3)

    estimator = TICA(dim=1, lagtime=lag)
    model1 = estimator.fit_from_timeseries(data).fetch_model()
    # ------- run again with new chunksize -------
    covars = TICA.covariance_estimator(lagtime=lag).fit(data)
    estimator.fit_from_covariances(covars)
    model2 = estimator.fetch_model()

    assert model1 != model2
    np.testing.assert_array_almost_equal(model1.mean_0, model2.mean_0)
    np.testing.assert_array_almost_equal(model1.cov_00, model2.cov_00)
    np.testing.assert_array_almost_equal(model1.cov_0t, model2.cov_0t)
Example #9
0
def test_scaling_parameter(scaling_param):
    scaling, valid_scaling = scaling_param
    if valid_scaling:
        # set via ctor
        estimator = TICA(scaling=scaling)
        np.testing.assert_equal(estimator.scaling, scaling)

        # set via property
        estimator = TICA()
        estimator.scaling = scaling
        np.testing.assert_equal(estimator.scaling, scaling)
    else:
        with np.testing.assert_raises(ValueError):
            TICA(scaling=scaling)
        with np.testing.assert_raises(ValueError):
            TICA().scaling = scaling
Example #10
0
 def test_commute_map(self):
     # todo: this is just a sanity check for now, something more meaningful should be tested
     TICA(scaling='commute_map', dim=None,
          lagtime=self.lagtime).fit(self.data).fetch_model()