From 7020faef125a87f0dba56b876caa2983781f8354 Mon Sep 17 00:00:00 2001 From: marscher Date: Tue, 12 Feb 2019 18:26:37 +0100 Subject: [PATCH 1/4] [coordinates/VAMP] fix variance cutoff --- pyemma/coordinates/tests/test_vamp.py | 11 +++++++++++ pyemma/coordinates/transform/vamp.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pyemma/coordinates/tests/test_vamp.py b/pyemma/coordinates/tests/test_vamp.py index 37396e61a..057a9d8ee 100644 --- a/pyemma/coordinates/tests/test_vamp.py +++ b/pyemma/coordinates/tests/test_vamp.py @@ -237,6 +237,17 @@ def test_singular_functions_against_MSM(self): np.testing.assert_allclose(np.diag(p), np.diag(r), atol=1E-6) np.testing.assert_allclose(np.abs(p), np.abs(r), atol=1E-6) + cumsum_Tsym = np.cumsum(S[1:] ** 2) + cumsum_Tsym /= cumsum_Tsym[-1] + np.testing.assert_allclose(self.vamp.cumvar, cumsum_Tsym) + + def test_cumvar_variance_cutoff(self): + for d in (0.2, 0.5, 0.8, 0.9, 1.0): + self.vamp.dim = d + special_cumvar = np.asarray([0] + self.vamp.cumvar.tolist()) + self.assertLessEqual(d, special_cumvar[self.vamp.dimension()],) + self.assertLessEqual(special_cumvar[self.vamp.dimension() - 1], d) + def test_CK_expectation_against_MSM(self): obs = np.eye(3) # observe every state cktest = self.vamp.cktest(observables=obs, statistics=None, mlags=4) diff --git a/pyemma/coordinates/transform/vamp.py b/pyemma/coordinates/transform/vamp.py index 6a8adbc88..f16fe3777 100644 --- a/pyemma/coordinates/transform/vamp.py +++ b/pyemma/coordinates/transform/vamp.py @@ -131,7 +131,7 @@ def _dimension(rank0, rankt, dim, singular_values): if dim is None or (isinstance(dim, float) and dim == 1.0): return min(rank0, rankt) if isinstance(dim, float): - return np.count_nonzero(VAMPModel._cumvar(singular_values) >= dim) + return np.searchsorted(VAMPModel._cumvar(singular_values), dim) + 1 else: return np.min([rank0, rankt, dim]) From 0bbd4c87441a903ecd51d2548ef98e77277fd45d Mon Sep 17 00:00:00 2001 From: marscher Date: Tue, 12 Feb 2019 18:29:15 +0100 Subject: [PATCH 2/4] amend changelog --- doc/source/CHANGELOG.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/CHANGELOG.rst b/doc/source/CHANGELOG.rst index 4e2aa0d2d..3c84adadc 100644 --- a/doc/source/CHANGELOG.rst +++ b/doc/source/CHANGELOG.rst @@ -4,7 +4,7 @@ Changelog 2.5.5 (??-??-????) ------------------ -This version only supports Python 3. +For now all future versions will only support Python 3. :pr:`1395` **New features**: @@ -23,6 +23,7 @@ This version only supports Python 3. - coordinates: VAMP: changed default projection vector from right to left, since only the left singular functions induce a kinetic map wrt. the conventional forward propagator, while the right singular functions induce a kinetic map wrt. the backward propagator. :pr:`1394` +- coordinates: VAMP: fixed variance cutoff to really include as many dimensions to meet subspace variance criterion. :pr:`1397` **Contributors**: From fa2e6ef5aeab323dee76f3dfe8ca521b8f66f173 Mon Sep 17 00:00:00 2001 From: marscher Date: Tue, 12 Feb 2019 18:29:52 +0100 Subject: [PATCH 3/4] cleanup --- devtools/conda-recipe/meta.yaml | 10 ++-------- pyemma/__init__.py | 2 +- pyemma/_base/estimator.py | 3 +-- pyemma/coordinates/clustering/tests/test_assign.py | 2 +- pyemma/coordinates/tests/test_random_access_stride.py | 2 +- pyemma/coordinates/tests/test_traj_info_cache.py | 2 +- pyemma/msm/tests/test_estimator.py | 2 +- pyemma/util/tests/test_config.py | 2 +- pyemma/util/tests/test_log.py | 2 +- 9 files changed, 10 insertions(+), 17 deletions(-) diff --git a/devtools/conda-recipe/meta.yaml b/devtools/conda-recipe/meta.yaml index 0905a2053..9230a4526 100644 --- a/devtools/conda-recipe/meta.yaml +++ b/devtools/conda-recipe/meta.yaml @@ -15,9 +15,7 @@ build: - CIRCLE_TEST_REPORTS - OMP_NUM_THREADS - PYEMMA_NJOBS - script: python setup.py install --single-version-externally-managed --record record.txt - # workaround for bpo-24935, the compiler jinja2 template sets CC, but LDSHARED is not being set accordingly by distutils.sysconfig. - script: LDSHARED="$CC -shared" python setup.py install --single-version-externally-managed --record record.txt # [linux] + script: pip install . --ignore-dependencies requirements: build: @@ -34,8 +32,7 @@ requirements: - python - scipy - setuptools - # use build flags (eg. CFLAGS etc) from conda-forge - #- toolchain + - pip - pybind11 run: @@ -45,7 +42,6 @@ requirements: - intel-openmp # [osx] - matplotlib - mdtraj >=1.8 - - mock # TODO: remove when py3k only. - msmtools >=1.2 - {{ pin_compatible('numpy') }} - pathos @@ -54,9 +50,7 @@ requirements: - pyyaml - scipy - setuptools - - six >=1.10 - tqdm - - progress_reporter >=2 test: source_files: diff --git a/pyemma/__init__.py b/pyemma/__init__.py index b84792247..bfaeeeb72 100644 --- a/pyemma/__init__.py +++ b/pyemma/__init__.py @@ -44,7 +44,7 @@ def _version_check(current, testing=False): Can be disabled by setting config.check_version = False. - >>> from mock import patch + >>> from unittest.mock import patch >>> import warnings, pyemma >>> with warnings.catch_warnings(record=True) as cw, patch('pyemma.version', '0.1'): ... warnings.simplefilter('always', UserWarning) diff --git a/pyemma/_base/estimator.py b/pyemma/_base/estimator.py index 729651147..d1f4732dc 100644 --- a/pyemma/_base/estimator.py +++ b/pyemma/_base/estimator.py @@ -311,8 +311,7 @@ def estimate_param_scan(estimator, X, param_sets, evaluate=None, evaluate_args=N if logger_available: logger = estimators[0].logger if progress_reporter is None: - from mock import MagicMock - # TODO: replace with nullcontext from util once merged + from unittest.mock import MagicMock ctx = progress_reporter = MagicMock() callback = None else: diff --git a/pyemma/coordinates/clustering/tests/test_assign.py b/pyemma/coordinates/clustering/tests/test_assign.py index 57ee707eb..0c85d5099 100644 --- a/pyemma/coordinates/clustering/tests/test_assign.py +++ b/pyemma/coordinates/clustering/tests/test_assign.py @@ -20,7 +20,7 @@ import unittest from contextlib import contextmanager -from mock import patch +from unittest.mock import patch from pyemma.util.files import TemporaryDirectory from logging import getLogger diff --git a/pyemma/coordinates/tests/test_random_access_stride.py b/pyemma/coordinates/tests/test_random_access_stride.py index 6ccda0ef4..6f89adcd7 100644 --- a/pyemma/coordinates/tests/test_random_access_stride.py +++ b/pyemma/coordinates/tests/test_random_access_stride.py @@ -469,7 +469,7 @@ def test_RA_high_stride(self): for ext in savable_formats_mdtra_18: traj = create_traj(length=n, dir=self.tmpdir, format=ext)[0] - from mock import patch + from unittest.mock import patch # temporarily overwrite the memory cutoff with a smaller value, to trigger the switch to RA stride. with patch('pyemma.coordinates.util.patches.iterload.MEMORY_CUTOFF', n_bytes - 1): r = coor.source(traj, top=get_top()) diff --git a/pyemma/coordinates/tests/test_traj_info_cache.py b/pyemma/coordinates/tests/test_traj_info_cache.py index d3149e4bf..c578e7c3b 100644 --- a/pyemma/coordinates/tests/test_traj_info_cache.py +++ b/pyemma/coordinates/tests/test_traj_info_cache.py @@ -27,7 +27,7 @@ import tempfile import unittest -import mock +from unittest import mock from pyemma.coordinates import api from pyemma.coordinates.data.feature_reader import FeatureReader diff --git a/pyemma/msm/tests/test_estimator.py b/pyemma/msm/tests/test_estimator.py index 563f4ee4c..b1a81e577 100644 --- a/pyemma/msm/tests/test_estimator.py +++ b/pyemma/msm/tests/test_estimator.py @@ -16,7 +16,7 @@ # along with this program. If not, see . import os import unittest -import mock +from unittest import mock from pyemma import msm from functools import wraps diff --git a/pyemma/util/tests/test_config.py b/pyemma/util/tests/test_config.py index fb7967014..98d20ad30 100644 --- a/pyemma/util/tests/test_config.py +++ b/pyemma/util/tests/test_config.py @@ -171,7 +171,7 @@ def test_mute_logging(self): def test_mute_progress(self): """ switch mute on shall turn off progress bars""" from pyemma._base.progress import ProgressReporterMixin - import mock + from unittest import mock rp = ProgressReporterMixin() self.config_inst.mute = True diff --git a/pyemma/util/tests/test_log.py b/pyemma/util/tests/test_log.py index 756362ec2..f1b0b86af 100644 --- a/pyemma/util/tests/test_log.py +++ b/pyemma/util/tests/test_log.py @@ -27,7 +27,7 @@ from pyemma.util import log from pyemma.util import config -import mock +from unittest import mock class TestNonWriteableLogFile(unittest.TestCase): From 508d9257711ea49416f129c45f0e6175650489aa Mon Sep 17 00:00:00 2001 From: marscher Date: Tue, 12 Feb 2019 18:46:29 +0100 Subject: [PATCH 4/4] fix install cmd --- devtools/conda-recipe/meta.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devtools/conda-recipe/meta.yaml b/devtools/conda-recipe/meta.yaml index 9230a4526..4b26f9d41 100644 --- a/devtools/conda-recipe/meta.yaml +++ b/devtools/conda-recipe/meta.yaml @@ -15,7 +15,7 @@ build: - CIRCLE_TEST_REPORTS - OMP_NUM_THREADS - PYEMMA_NJOBS - script: pip install . --ignore-dependencies + script: "{{ PYTHON }} -m pip install . --no-deps --ignore-installed --no-cache-dir -vvv" requirements: build: