Skip to content

Commit 48864dd

Browse files
authored
Add checking that binary matrix is not suitable for hypershpere overlap (#280)
* Add checking that binary matrix is not suitable for hypershpere overlap * Update testing
1 parent 6e0da09 commit 48864dd

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

selector/measures/diversity.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,11 @@ def hypersphere_overlap_of_subset(x: np.ndarray, x_subset: np.array) -> float:
403403
Agrafiotis, D. K.. (1997) Stochastic Algorithms for Maximizing Molecular Diversity.
404404
Journal of Chemical Information and Computer Sciences 37, 841-851.
405405
"""
406+
# check if x is binary matrix or not
407+
if np.array_equal(x, x.astype(bool)):
408+
raise ValueError(
409+
"Input matrix cannot be binary because the diversity measurement is designed for continuous orthogonal features."
410+
)
406411

407412
# Find the maximum and minimum over each feature across all molecules.
408413
max_x = np.max(x, axis=0)

selector/measures/tests/test_diversity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def test_hypersphere_normalization_error():
256256

257257
def test_hypersphere_radius_warning():
258258
"""Test the hypersphere overlap method gives warning when radius is too large."""
259-
corner_pts = np.array([[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]])
259+
corner_pts = np.array([[0.0, 0.0], [0.0, 2.0], [2.0, 0.0], [2.0, 2.0]])
260260
assert_warns(Warning, hypersphere_overlap_of_subset, corner_pts, corner_pts)
261261

262262

0 commit comments

Comments
 (0)