Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix random_state #654

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions implicit/evaluation.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ cdef _choose(rng, int n, float frac):
return arr


cdef _take_tails(arr, int n, return_complement=False, shuffled=False):
cdef _take_tails(arr, int n, rng, return_complement=False, shuffled=False):
"""
Given an array of (optionally shuffled) integers in the range 0->n, take the indices
of the last 'n' occurrences of each integer (tail) -- subject to shuffling.
Expand Down Expand Up @@ -127,7 +127,7 @@ cdef _take_tails(arr, int n, return_complement=False, shuffled=False):
ranges = np.linspace(start, end, num=n + 1, dtype=int)[1:]

if shuffled:
shuffled_idx = (sorted_arr + np.random.random(arr.shape)).argsort()
shuffled_idx = (sorted_arr + rng.random(arr.shape)).argsort()
tails = shuffled_idx[np.ravel(ranges, order="f")]
else:
tails = np.ravel(ranges, order="f")
Expand Down Expand Up @@ -206,7 +206,7 @@ cpdef leave_k_out_split(
candidate_data = data[full_candidate_mask]

test_idx, train_idx = _take_tails(
candidate_users, K, shuffled=True, return_complement=True
candidate_users, K, random_state, shuffled=True, return_complement=True
)

# get all remaining remaining candidate user-item pairs, and prepare to append to
Expand Down