Skip to content
Merged
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
47 changes: 29 additions & 18 deletions libreco/algorithms/swing.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,26 @@
self.show_start_time()
user_interacts = build_sparse(train_data.sparse_interaction)
item_interacts = build_sparse(train_data.sparse_interaction, transpose=True)
self.rs_model = recfarm.Swing(
self.top_k,
self.alpha,
self.max_cache_num,
self.n_users,
self.n_items,
user_interacts,
item_interacts,
self.user_consumed,
self.default_pred,
)
with time_block("swing computing", verbose=1):
self.rs_model.compute_swing(self.num_threads, self.incremental)
if self.incremental:
assert self.rs_model is not None
with time_block("update swing", verbose=1):
self.rs_model.update_swing(

Check warning on line 85 in libreco/algorithms/swing.py

View check run for this annotation

Codecov / codecov/patch

libreco/algorithms/swing.py#L82-L85

Added lines #L82 - L85 were not covered by tests
self.num_threads, user_interacts, item_interacts
)
else:
self.rs_model = recfarm.Swing(

Check warning on line 89 in libreco/algorithms/swing.py

View check run for this annotation

Codecov / codecov/patch

libreco/algorithms/swing.py#L89

Added line #L89 was not covered by tests
self.top_k,
self.alpha,
self.max_cache_num,
self.n_users,
self.n_items,
user_interacts,
item_interacts,
self.user_consumed,
self.default_pred,
)
with time_block("swing computing", verbose=1):
self.rs_model.compute_swing(self.num_threads)

Check warning on line 101 in libreco/algorithms/swing.py

View check run for this annotation

Codecov / codecov/patch

libreco/algorithms/swing.py#L100-L101

Added lines #L100 - L101 were not covered by tests

num = self.rs_model.num_swing_elements()
density_ratio = 100 * num / (self.n_items * self.n_items)
Expand Down Expand Up @@ -137,17 +144,21 @@
result_recs[u] = popular_recommendations(
self.data_info, inner_id, n_rec
)

if user_ids:
computed_recs, no_rec_indices = self.rs_model.recommend(
computed_recs, additional_rec_counts = self.rs_model.recommend(

Check warning on line 149 in libreco/algorithms/swing.py

View check run for this annotation

Codecov / codecov/patch

libreco/algorithms/swing.py#L149

Added line #L149 was not covered by tests
user_ids,
n_rec,
filter_consumed,
random_rec,
)
for i in no_rec_indices:
computed_recs[i] = popular_recommendations(
self.data_info, inner_id=True, n_rec=n_rec
)
for rec, arc in zip(computed_recs, additional_rec_counts):
if arc > 0:
additional_recs = popular_recommendations(

Check warning on line 157 in libreco/algorithms/swing.py

View check run for this annotation

Codecov / codecov/patch

libreco/algorithms/swing.py#L155-L157

Added lines #L155 - L157 were not covered by tests
self.data_info, inner_id=True, n_rec=arc
)
rec.extend(additional_recs)

Check warning on line 160 in libreco/algorithms/swing.py

View check run for this annotation

Codecov / codecov/patch

libreco/algorithms/swing.py#L160

Added line #L160 was not covered by tests

user_recs = construct_rec(self.data_info, user_ids, computed_recs, inner_id)
result_recs.update(user_recs)
return result_recs
Expand Down
Loading