Skip to content

Commit

Permalink
Add option to simulate without prior knowledge (#1575)
Browse files Browse the repository at this point in the history
Thanks! We'll look at implementing other prior sampling methods and the interface of the review class when/if we refactor that class.
  • Loading branch information
J535D165 committed Nov 23, 2023
1 parent 3b60e75 commit 7e75f7c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions asreview/review/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ def sample_prior_knowledge(
return init


def naive_prior_knowledge(labels):
"""Select top records until the first 0 and 1 are found.
Arguments
---------
labels: np.ndarray
Array of labels, with 1 -> included, 0 -> excluded.
Returns
-------
np.ndarray:
An array with prior indices from top dataset.
"""

# retrieve the index of included and excluded papers
first_included_idx = np.where(labels == 1)[0].min()
first_excluded_idx = np.where(labels == 0)[0].min()

return np.arange(max(first_included_idx, first_excluded_idx) + 1)


class ReviewSimulate(BaseReview):
"""ASReview Simulation mode class.
Expand Down Expand Up @@ -154,6 +176,9 @@ def __init__(
start_idx = sample_prior_knowledge(
labels, n_prior_included, n_prior_excluded, random_state=init_seed
)
else:
start_idx = naive_prior_knowledge(labels)

super(ReviewSimulate, self).__init__(
as_data, *args, start_idx=start_idx, **kwargs
)
Expand Down

0 comments on commit 7e75f7c

Please sign in to comment.