Skip to content
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
4 changes: 2 additions & 2 deletions src/skmatter/_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ def fit(self, X, y=None, warm_start=False):
n_to_select_from = X.shape[self._axis]
self.n_samples_in_, self.n_features_in_ = X.shape

self.n_samples_in_, self.n_features_in_ = X.shape

error_msg = (
"n_to_select must be either None, an "
f"integer in [1, n_{self.selection_type}s] "
Expand Down Expand Up @@ -428,6 +426,8 @@ def _continue_greedy_search(self, X, y, n_to_select):
def _get_best_new_selection(self, scorer, X, y):
scores = scorer(X, y)

# Get the score argmax, but only for idxs not already selected
scores[self.selected_idx_[: self.n_selected_]] = -np.inf
max_score_idx = np.argmax(scores)
if self.score_threshold is not None:
if self.first_score_ is None:
Expand Down
1 change: 0 additions & 1 deletion tests/test_feature_pcov_cur.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def test_non_it(self):
self.idx = [2, 8, 3, 6, 7, 9, 1, 0, 5]
selector = PCovCUR(n_to_select=9, recompute_every=0)
selector.fit(self.X, self.y)

self.assertTrue(np.allclose(selector.selected_idx_, self.idx))


Expand Down
16 changes: 16 additions & 0 deletions tests/test_feature_simple_cur.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ def test_non_it(self):

self.assertTrue(np.allclose(selector.selected_idx_, ref_idx))

def test_unique_selected_idx_zero_score(self):
"""
Tests that the selected idxs are unique, which may not be the
case when the score is numerically zero
"""
np.random.seed(0)
n_samples = 10
n_features = 15
X = np.random.rand(n_samples, n_features)
X[:, 1] = X[:, 0]
X[:, 2] = X[:, 0]
selector_problem = CUR(n_to_select=len(X.T)).fit(X)
assert len(selector_problem.selected_idx_) == len(
set(selector_problem.selected_idx_)
)


if __name__ == "__main__":
unittest.main(verbosity=2)
16 changes: 16 additions & 0 deletions tests/test_feature_simple_fps.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ def test_get_distances(self):
selector = FPS(n_to_select=7)
_ = selector.get_select_distance()

def test_unique_selected_idx_zero_score(self):
"""
Tests that the selected idxs are unique, which may not be the
case when the score is numerically zero
"""
np.random.seed(0)
n_samples = 10
n_features = 15
X = np.random.rand(n_samples, n_features)
X[:, 1] = X[:, 0]
X[:, 2] = X[:, 0]
selector_problem = FPS(n_to_select=len(X.T)).fit(X)
assert len(selector_problem.selected_idx_) == len(
set(selector_problem.selected_idx_)
)


if __name__ == "__main__":
unittest.main(verbosity=2)
17 changes: 17 additions & 0 deletions tests/test_sample_simple_cur.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ def test_non_it(self):

self.assertTrue(np.allclose(selector.selected_idx_, ref_idx))

def test_unique_selected_idx_zero_score(self):
"""
Tests that the selected idxs are unique, which may not be the
case when the score is numerically zero.
"""
np.random.seed(0)
n_samples = 10
n_features = 15
X = np.random.rand(n_samples, n_features)
X[1] = X[0]
X[2] = X[0]
X[3] = X[0]
selector_problem = CUR(n_to_select=len(X)).fit(X)
assert len(selector_problem.selected_idx_) == len(
set(selector_problem.selected_idx_)
)


if __name__ == "__main__":
unittest.main(verbosity=2)
17 changes: 17 additions & 0 deletions tests/test_sample_simple_fps.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ def test_threshold(self):
self.assertEqual(len(selector.selected_idx_), 5)
self.assertEqual(selector.selected_idx_.tolist(), self.idx[:5])

def test_unique_selected_idx_zero_score(self):
"""
Tests that the selected idxs are unique, which may not be the
case when the score is numerically zero.
"""
np.random.seed(0)
n_samples = 10
n_features = 15
X = np.random.rand(n_samples, n_features)
X[1] = X[0]
X[2] = X[0]
X[3] = X[0]
selector_problem = FPS(n_to_select=len(X)).fit(X)
assert len(selector_problem.selected_idx_) == len(
set(selector_problem.selected_idx_)
)


if __name__ == "__main__":
unittest.main(verbosity=2)
16 changes: 16 additions & 0 deletions tests/test_voronoi_fps.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ def test_score(self):
)
)

def test_unique_selected_idx_zero_score(self):
"""
Tests that the selected idxs are unique, which may not be the
case when the score is numerically zero
"""
np.random.seed(0)
n_samples = 10
n_features = 15
X = np.random.rand(n_samples, n_features)
X[1] = X[0]
X[2] = X[0]
selector_problem = VoronoiFPS(n_to_select=n_samples, initialize=3).fit(X)
assert len(selector_problem.selected_idx_) == len(
set(selector_problem.selected_idx_)
)


if __name__ == "__main__":
unittest.main(verbosity=2)
Loading