Skip to content

Commit

Permalink
Renamed histogram_correction to weight_correction
Browse files Browse the repository at this point in the history
  • Loading branch information
wehs7661 committed Sep 6, 2023
1 parent a3023ff commit 435180d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
22 changes: 11 additions & 11 deletions ensemble_md/cli/run_EEXE.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,35 +154,35 @@ def main():
# since they are updated by `get_swapping_pattern`. (Even if the function does not explicitly
# returns `states_` and `weights_`, `states_` and `weights_` can still be different after
# the use of the function.) Therefore, here we create copies for `states_` and `weights_`
# before the use of `get_swapping_pattern`, so we can use them in `histogram_correction`,
# before the use of `get_swapping_pattern`, so we can use them in `weight_correction`,
# `combine_weights` and `update_MDP`.
states = copy.deepcopy(states_)
weights = copy.deepcopy(weights_)
swap_pattern, swap_list = EEXE.get_swapping_pattern(dhdl_files, states_, weights_) # swap_list will only be used for modify_coords # noqa: E501

# 3-3. Perform histogram correction/weight combination
# 3-3. Perform weight correction/weight combination
if wl_delta != [None for i in range(EEXE.n_sim)]: # weight-updating
print(f'\nCurrent Wang-Landau incrementors: {wl_delta}\n')

# (1) First we prepare the weights to be combined.
# Note that although averaged weights are sometimes used for histogram correction/weight combination,
# Note that although averaged weights are sometimes used for weight correction/weight combination,
# the final weights are always used for calculating the acceptance ratio.
if EEXE.N_cutoff != -1 or EEXE.w_combine is not None:
# Only when histogram correction/weight combination is needed.
# Only when weight correction/weight combination is needed.
weights_avg, weights_err = EEXE.get_averaged_weights(log_files)
weights_input = EEXE.prepare_weights(weights_avg, weights) # weights_input is for weight combination # noqa: E501

# (2) Now we perform histogram correction/weight combination.
# (2) Now we perform weight correction/weight combination.
# The product of this step should always be named as "weights" to be used in update_MDP
if EEXE.N_cutoff != -1 and EEXE.w_combine is not None:
# perform both
if weights_input is None:
# Then only histogram correction will be performed
# Then only weight correction will be performed
print('Note: Weight combination is deactivated because the weights are too noisy.')
weights = EEXE.histogram_correction(weights, counts)
weights = EEXE.weight_correction(weights, counts)
_ = EEXE.combine_weights(weights, print_weights=False)[1] # just to print the combiend weights
else:
weights_preprocessed = EEXE.histogram_correction(weights_input, counts)
weights_preprocessed = EEXE.weight_correction(weights_input, counts)
if EEXE.verbose is True:
print('Performing weight combination ...')
else:
Expand All @@ -191,7 +191,7 @@ def main():
EEXE.g_vecs.append(g_vec)
elif EEXE.N_cutoff == -1 and EEXE.w_combine is not None:
# only perform weight combination
print('Note: No histogram correction will be performed.')
print('Note: No weight correction will be performed.')
if weights_input is None:
print('Note: Weight combination is deactivated because the weights are too noisy.')
_ = EEXE.combine_weights(weights, print_weights=False)[1] # just to print the combined weights
Expand All @@ -203,12 +203,12 @@ def main():
weights, g_vec = EEXE.combine_weights(weights_input) # inverse-variance weighting seems worse
EEXE.g_vecs.append(g_vec)
elif EEXE.N_cutoff != -1 and EEXE.w_combine is None:
# only perform histogram correction
# only perform weight correction
print('Note: No weight combination will be performed.')
weights = EEXE.histogram_correction(weights_input, counts)
_ = EEXE.combine_weights(weights, print_weights=False)[1] # just to print the combined weights
else:
print('Note: No histogram correction will be performed.')
print('Note: No weight correction will be performed.')
print('Note: No weight combination will be performed.')
_ = EEXE.combine_weights(weights, print_weights=False)[1] # just to print the combiend weights

Expand Down
10 changes: 5 additions & 5 deletions ensemble_md/ensemble_EXE.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def set_params(self, analysis):
raise ParameterError("The parameter 's' should be non-negative.")

if self.N_cutoff < 0 and self.N_cutoff != -1:
raise ParameterError("The parameter 'N_cutoff' should be non-negative unless no histogram correction is needed, i.e. N_cutoff = -1.") # noqa: E501
raise ParameterError("The parameter 'N_cutoff' should be non-negative unless no weight correction is needed, i.e. N_cutoff = -1.") # noqa: E501

params_str = ['gro', 'top', 'mdp', 'gmx_executable']
# First check if self.gro and self.top are lists and check their lengths
Expand Down Expand Up @@ -317,7 +317,7 @@ def set_params(self, analysis):

if self.fixed_weights is True:
if self.N_cutoff != -1 or self.w_combine is not None:
self.warnings.append('Warning: The histogram correction/weight combination method is specified but will not be used since the weights are fixed.') # noqa: E501
self.warnings.append('Warning: The weight correction/weight combination method is specified but will not be used since the weights are fixed.') # noqa: E501
# In the case that the warning is ignored, enforce the defaults.
self.N_cutoff = -1
self.w_combine = None
Expand Down Expand Up @@ -1096,7 +1096,7 @@ def accept_or_reject(self, prob_acc):
print(" Swap rejected! ")
return swap_bool

def histogram_correction(self, weights, counts):
def weight_correction(self, weights, counts):
"""
Corrects the lambda weights based on the histogram counts. Namely,
:math:`g_k' = g_k + ln(N_{k-1}/N_k)`, where :math:`g_k` and :math:`g_k'`
Expand All @@ -1119,9 +1119,9 @@ def histogram_correction(self, weights, counts):
An updated list of lists of corected weights.
"""
if self.verbose is True:
print("\nPerforming histogram correction for the lambda weights ...")
print("\nPerforming weight correction for the lambda weights ...")
else:
print("\nPerforming histogram correction for the lambda weights ...", end="")
print("\nPerforming weight correction for the lambda weights ...", end="")

for i in range(len(weights)): # loop over the replicas
if self.verbose is True:
Expand Down

0 comments on commit 435180d

Please sign in to comment.