-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable MBAR to do bootstrap error estimation #322
Changes from 9 commits
1a853ab
8277280
ee1d4fb
fb4b659
89f855f
9cf90c7
18ded44
0ca40c4
d959393
74df776
b887659
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,15 @@ Changes | |
Enhancements | ||
- Add a parser to read serialised pandas dataframe (parquet) (issue #316, PR#317). | ||
- workflow.ABFE allow parquet as input (issue #316, PR#317). | ||
- Allow MBAR estimator to use bootstrap to compute error (issue #320, PR#322). | ||
|
||
Fixes | ||
- Fix the case where visualisation.plot_convergence would fail when the final | ||
error is NaN (issue #318, PR#319). | ||
error is NaN (issue #318, PR#319). | ||
|
||
DeprecationWarning | ||
- The default MBAR error estimator in workflow.ABFE.estimate will change from | ||
analytic to bootstrap=50 (issue #320, PR#322). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. say when it will change (target release, current + 2 = 2.3 I think) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or 2.2, if you want to be aggressive, but state the target release. |
||
|
||
|
||
06/04/2023 xiki-tempula | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,10 @@ class MBAR(BaseEstimator, _EstimatorMixOut): | |
available via :func:`scipy.optimize.minimize` or | ||
:func:`scipy.optimize.root`. | ||
|
||
n_bootstraps : int, optional | ||
Whether to use bootstrap to estimate uncertainty. `0` means use analytic error | ||
estimation. 50~200 is a reasonable range to do bootstrap. | ||
|
||
verbose : bool, optional | ||
Set to ``True`` if verbose debug output from :mod:`pymbar` is desired. | ||
|
||
|
@@ -59,6 +63,8 @@ class MBAR(BaseEstimator, _EstimatorMixOut): | |
`delta_f_`, `d_delta_f_`, `states_` are view of the original object. | ||
.. versionchanged:: 2.0.0 | ||
default value for `method` was changed from "hybr" to "robust" | ||
.. versionchanged:: 2.1.0 | ||
`n_bootstraps` option added. | ||
""" | ||
|
||
def __init__( | ||
|
@@ -67,13 +73,15 @@ def __init__( | |
relative_tolerance=1.0e-7, | ||
initial_f_k=None, | ||
method="robust", | ||
n_bootstraps=0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add a reminder comment n_bootstraps=0, # release 2.2: change to 50 (see PR #322) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So my feeling is that for the MBAR estimator, we retain the current behaviour unless people manually turn it on as bootstrap does come with a computational cost. It is only for the estimate method in workflow.ABFE where I know that the input is decorrelated and I'm prepared to pay the computational cost, I will set the default to 50. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's ok, we just can't make the default behave differently without a minimal warning period. |
||
verbose=False, | ||
): | ||
self.maximum_iterations = maximum_iterations | ||
self.relative_tolerance = relative_tolerance | ||
self.initial_f_k = initial_f_k | ||
self.method = method | ||
self.verbose = verbose | ||
self.n_bootstraps = n_bootstraps | ||
|
||
# handle for pymbar.MBAR object | ||
self._mbar = None | ||
|
@@ -108,8 +116,15 @@ def fit(self, u_nk): | |
verbose=self.verbose, | ||
initial_f_k=self.initial_f_k, | ||
solver_protocol=self.method, | ||
n_bootstraps=self.n_bootstraps, | ||
) | ||
if self.n_bootstraps == 0: | ||
uncertainty_method = None | ||
else: | ||
uncertainty_method = "bootstrap" | ||
out = self._mbar.compute_free_energy_differences( | ||
return_theta=True, uncertainty_method=uncertainty_method | ||
) | ||
out = self._mbar.compute_free_energy_differences(return_theta=True) | ||
self._delta_f_ = pd.DataFrame( | ||
out["Delta_f"], columns=self._states_, index=self._states_ | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -403,6 +403,9 @@ def estimate(self, estimators=("MBAR", "BAR", "TI"), **kwargs): | |
'MBAR']. Note that the estimators are in their original form where | ||
no unit conversion has been attempted. | ||
|
||
.. versionchanged:: 2.1.0 | ||
DeprecationWarning for using analytic error for MBAR estimator. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indent |
||
|
||
""" | ||
# Make estimators into a tuple | ||
if isinstance(estimators, str): | ||
|
@@ -436,6 +439,10 @@ def estimate(self, estimators=("MBAR", "BAR", "TI"), **kwargs): | |
for estimator in estimators: | ||
if estimator == "MBAR": | ||
logger.info("Run MBAR estimator.") | ||
warnings.warn( | ||
"From 2.2.0, n_bootstraps=50 will be the default for estimating MBAR error.", | ||
DeprecationWarning, | ||
) | ||
self.estimator[estimator] = MBAR(**kwargs).fit(u_nk) | ||
elif estimator == "BAR": | ||
logger.info("Run BAR estimator.") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a deprecation for using analytical error estimate as the default in ABFE, will change to using 50 bootstraps in 2.3 (see other comments)