Skip to content
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

Check for negative weights #60

Merged
merged 3 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package/xentropy/dihedrals.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from .internal.pre_post_processing import preprocess_dihedral_data, process_data_shapes, \
process_weights_argument, process_method_argument, reshape_arrays_eventually, postprocess_dihedral_pdf, \
rad_to_deg, deg_to_rad
rad_to_deg, deg_to_rad, sanity_check_input_data
from .internal.constants import id_gas_SI, PI
import warnings

Expand All @@ -34,6 +34,7 @@ def __init__(self, data, weights=None, resolution="auto", verbose=False, method=
rules_of_thumb=rules_of_thumb_dihedral())
# process input arrays
weights, weight_switch = process_weights_argument(weights, verbose=verbose)
sanity_check_input_data(data, weights, weight_switch)
self.__has_weights = weight_switch
data, weights = process_data_shapes(data, weights, weight_switch)
self.__data = data
Expand Down
4 changes: 3 additions & 1 deletion package/xentropy/internal/pre_post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def process_weights_argument(weights, verbose=False):
if verbose:
print("Weights have been given.")
weights = np.array(weights)
if True in (weights < 0):
err_msg = "You gave negative values in you weights array.\n"
raise ValueError(err_msg)

return weights, weight_switch

Expand Down Expand Up @@ -115,7 +118,6 @@ def sanity_check_input_data(data, weights=None, weight_switch=True):

def process_data_shapes(data, weights=None, weight_switch=True):
data = np.array(data)
sanity_check_input_data(data, weights, weight_switch)

if len(data.shape) == 0:
err_msg = "Shape of data is suspicious\n" \
Expand Down
4 changes: 3 additions & 1 deletion package/xentropy/kde.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def __init__(self, data, weights=None, resolution="auto", verbose=False):
# input
# TODO preprocess and sanitycheck data here, too (code in dihedrals.py should be applicable)
weights, weight_switch = process_weights_argument(weights, verbose=verbose)
self.__has_weights = weight_switch
sanity_check_input_data(data, weights, weight_switch)
self.__has_weights = weight_switch
check_dims(data) # kde can only take single data sets currently
self.__data = data
self.__weights = weights
Expand Down Expand Up @@ -62,10 +62,12 @@ def calculate(self, resolution=None, verbose=None):
if verbose:
print("Initializing C++ kernel for kde...")
if self.has_weights:
# print(self.weights) # DEBUG
kernel = _kde_kernel(self.data, self.resolution, self.weights)
else:
kernel = _kde_kernel(self.data, self.resolution)
kernel.calculate()
# print(kernel.get_pdf()) # DEBUG
self.__is_finished = True
if verbose:
print("KDE finished.")
Expand Down