Skip to content

Commit

Permalink
Fix the dE method for AMBER (#300)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
xiki-tempula authored Mar 21, 2023
1 parent 045f85d commit 2c1d153
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
10 changes: 10 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/alchemlyb/preprocessing/subsampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/alchemlyb/tests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def test_decorrelate_u_nk_burnin(u_nk):
remove_burnin=True,
)
)
== 2849
== 2848
)


Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 2c1d153

Please sign in to comment.