Skip to content

Commit

Permalink
Allow tolerance of 1e-02 for feature weights sum is 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiquesydow committed May 8, 2021
1 parent 92d381a commit 39a64d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion kissim/comparison/fingerprint_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def _calculate_weighted_sum(values, weights):
if np.isnan(values).any():
raise ValueError(f"Input values cannot contain NaN values: {values}")

if not np.isclose(np.sum(weights), 1.0):
# NOTE: Sync with rtol in kissim.comparison.utils.format_weights
if not np.isclose(np.sum(weights), 1.0, rtol=1e-02):
raise ValueError(f"Sum of input weights must be 1 but is {np.sum(weights)}.")

return np.sum(values * weights)
Expand Down
3 changes: 2 additions & 1 deletion kissim/comparison/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def format_weights(feature_weights=None):
if len(feature_weights) != 15:
raise ValueError(f"List must have length 15, but has length {len(feature_weights)}.")
# Sum of weights must be 1.0
if not np.isclose(sum(feature_weights), 1.0, rtol=1e-04):
# NOTE: Sync with rtol in FingerprintDistance._calculate_weighted_sum
if not np.isclose(sum(feature_weights), 1.0, rtol=1e-02):
raise ValueError(f"Sum of all weights must be one, but is {sum(feature_weights)}.")

else:
Expand Down

0 comments on commit 39a64d4

Please sign in to comment.