From 2c1d15318912a6d8c124d5cc5c43007da15eeee5 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Tue, 21 Mar 2023 22:17:43 +0000 Subject: [PATCH] Fix the dE method for AMBER (#300) * fix #299 * Fix the dE method in u_nk2series to use the difference between two lambda columns instead of using the next lambda column or the previous column for the last window * change tests (GROMACS results changed) * Update CHANGES --- CHANGES | 10 ++++++++++ src/alchemlyb/preprocessing/subsampling.py | 10 ++++++++-- src/alchemlyb/tests/test_preprocessing.py | 8 ++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 7e55c754..fd23a12b 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,16 @@ The rules for this file: * release numbers follow "Semantic Versioning" https://semver.org ------------------------------------------------------------------------------ +*/*/* xiki-tempula, + + * unreleased + +Fixes + - Fix the dE method in u_nk2series to use the difference between two + lambda columns instead of using the next lambda column or the previous + column for the last window (issue #299, PR #300). + + 12/12/2022 xiki-tempula, orbeckst * 2.0.0 diff --git a/src/alchemlyb/preprocessing/subsampling.py b/src/alchemlyb/preprocessing/subsampling.py index a659ca09..ffe39704 100644 --- a/src/alchemlyb/preprocessing/subsampling.py +++ b/src/alchemlyb/preprocessing/subsampling.py @@ -153,6 +153,10 @@ def u_nk2series(df, method="dE"): .. versionadded:: 1.0.0 + .. versionchanged:: 2.0.1 + The `dE` method computes the difference between the current lambda + and the next lambda (previous lambda for the last window), instead + of using the next lambda or the previous lambda for the last window. """ @@ -196,11 +200,13 @@ def u_nk2series(df, method="dE"): # For the case of more than 1 lambda index = df.columns.values.tolist().index(key) # for the state that is not the last state, take the state+1 + current_lambda = df.iloc[:, index] if index + 1 < len(df.columns): - series = df.iloc[:, index + 1] + new_lambda = df.iloc[:, index + 1] # for the state that is the last state, take the state-1 else: - series = df.iloc[:, index - 1] + new_lambda = df.iloc[:, index - 1] + series = new_lambda - current_lambda else: raise ValueError("Decorrelation method {} not found.".format(method)) return series diff --git a/src/alchemlyb/tests/test_preprocessing.py b/src/alchemlyb/tests/test_preprocessing.py index ea8231ab..766bc3df 100644 --- a/src/alchemlyb/tests/test_preprocessing.py +++ b/src/alchemlyb/tests/test_preprocessing.py @@ -422,7 +422,7 @@ def test_decorrelate_u_nk_burnin(u_nk): remove_burnin=True, ) ) - == 2849 + == 2848 ) @@ -493,9 +493,9 @@ class TestU_nk2series: @pytest.mark.parametrize( "methodargs,reference", # reference = sum [ - ({}, 9207.80229000283), + ({}, 7988.667045), ({"method": "all"}, 85982.34668751864), - ({"method": "dE"}, 9207.80229000283), + ({"method": "dE"}, 7988.667045), ], ) def test_u_nk2series(self, u_nk, methodargs, reference): @@ -507,7 +507,7 @@ def test_u_nk2series(self, u_nk, methodargs, reference): "methodargs,reference", # reference = sum [ ({"method": "dhdl_all"}, 85982.34668751864), - ({"method": "dhdl"}, 9207.80229000283), + ({"method": "dhdl"}, 7988.667045), ], ) def test_u_nk2series_deprecated(self, u_nk, methodargs, reference):