Skip to content

fix: add epsilon to prevent ZeroDivisionError in BPR-based models#686

Merged
qtuantruong merged 1 commit intoPreferredAI:masterfrom
WeishuZ:fix/bpr-zero-division
Apr 3, 2026
Merged

fix: add epsilon to prevent ZeroDivisionError in BPR-based models#686
qtuantruong merged 1 commit intoPreferredAI:masterfrom
WeishuZ:fix/bpr-zero-division

Conversation

@WeishuZ
Copy link
Copy Markdown
Contributor

@WeishuZ WeishuZ commented Apr 3, 2026

Related to #675

Problem

The ZeroDivisionError fix (+ 1e-8 in the denominator) was applied to recom_bpr.pyx but not to three other models that use the same progress-reporting pattern. When all samples are skipped (e.g., very small datasets), the denominator (n_samples - skipped) becomes 0.

Fix

Added + 1e-8 to the denominator in:

  • cornac/models/companion/recom_companion.pyx
  • cornac/models/comparer/recom_comparer_sub.pyx
  • cornac/models/lrppm/recom_lrppm.pyx

Consistent with the existing fix in recom_bpr.pyx (line 199).

The BPR zero-division fix (+ 1e-8) was previously applied to
recom_bpr.pyx but not to other models that use the same pattern:
- cornac/models/companion/recom_companion.pyx
- cornac/models/comparer/recom_comparer_sub.pyx
- cornac/models/lrppm/recom_lrppm.pyx

When all samples are skipped (e.g., on very small datasets),
the denominator (n_samples - skipped) becomes 0, causing a
ZeroDivisionError during training progress display.

Related to PreferredAI#675
@qtuantruong
Copy link
Copy Markdown
Member

LGTM, thanks!

@qtuantruong qtuantruong merged commit 8d24377 into PreferredAI:master Apr 3, 2026
19 checks passed
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