Skip to content

Add Class Core Set - #353

Merged
mherde merged 44 commits into
scikit-activeml:developmentfrom
Cheng-JY:Cheng/feat/coreset
Jan 10, 2024
Merged

mherde merged 44 commits into
scikit-activeml:developmentfrom
Cheng-JY:Cheng/feat/coreset

Conversation

@Cheng-JY

@Cheng-JY Cheng-JY commented Nov 14, 2023 •

Copy link
Copy Markdown
Contributor

Description

Add Class Core Set with the corresponding query strategy, k_greedy_center.

Features

  1. Add Class Core Set with init method
  2. Add query method
  3. Add a static k-greedy-center method
  4. Add a private method for calculation the distance between samples and cluster centres
  5. Add a corresponding tests

Comment thread skactiveml/pool/_core_set.py Outdated
from ..utils import MISSING_LABEL, simple_batch

class CoreSet(SingleAnnotatorPoolQueryStrategy):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation is missing.

Comment thread skactiveml/pool/_test_core_set.ipynb Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Performing a query must be deterministic for a given random seed, e.g.:
qs = CoreSet(random_state=42)
query_indices_1 = qs.query(X, y)
query_indices_2 = qs.query(X, y)
np.testing.assertArrayEqual(query_indices_1, query_indices_2)
  • The name convention of functions/methods in Python is lowercase with _ as separators, e.g., kCenterGreedy -> k_center_greedy.
  • Use the min_distances as utilities, which can be returned if return_utilities=True.
  • Change np.random.choice(np.arange(X.shape[0])) to self.random_state_.choice(np.arange(X.shape[0]))

Comment thread skactiveml/pool/_core_set.py Outdated
If candidates is of shape (n_candidates, n_features), the indexing
refers to samples in candidates.
"""
# read the labeled aka selected samples from the y vector

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check whether the parameters are valid? For example:

X = check_array(X, allow_nd=True)
y = check_array(y, ensure_2d=False, force_all_finite="allow-nan", dtype=None)
check_consistent_length(X, y)    

Cf. base.by to see which checks are possible.

Comment thread skactiveml/pool/_core_set.py Outdated
X: array-like of shape (n_samples, n_features)
Training data set, usually complete, i.e. including the labeled and
unlabeled samples
selected_samples: np.ndarray of shape (n_selected_samples, )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust documentation according to the new parameters.

Comment thread skactiveml/pool/_core_set.py Outdated

return query_indices, utilities

def update_distances(X, cluster_centers, mapping):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an additional parameter, which contains already computed distances for the previous cluster centers.

Comment thread skactiveml/pool/_core_set.py Outdated

return query_indices, utilities

def update_distances(X, cluster_centers, mapping):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def update_distances(X, cluster_centers, mapping):
def _update_distances(X, cluster_centers, mapping):

@mherde
mherde changed the base branch from master to development December 6, 2023 10:09
@Cheng-JY Cheng-JY mentioned this pull request Dec 13, 2023
Comment thread skactiveml/pool/_core_set.py Outdated
candidates=None,
batch_size=1,
return_utilities=False,
**kwargs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**kwargs

Comment thread skactiveml/pool/_core_set.py Resolved
Comment thread skactiveml/pool/_core_set.py Resolved
Comment thread skactiveml/pool/_core_set.py Resolved
Comment thread skactiveml/pool/_core_set.py Resolved
Comment thread skactiveml/pool/_core_set.py Resolved
Comment thread skactiveml/pool/tests/test_core_set.py Resolved
Comment thread skactiveml/pool/tests/test_core_set.py Resolved
Comment thread skactiveml/pool/tests/test_core_set.py Resolved
Comment thread skactiveml/pool/tests/test_core_set.py Resolved
@mherde
mherde merged commit b39cdc8 into scikit-activeml:development Jan 10, 2024
@mherde
mherde deleted the Cheng/feat/coreset branch January 10, 2024 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants