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

Complete pairwise ranking #396

Merged
merged 3 commits into from
Feb 12, 2025
Merged

Complete pairwise ranking #396

merged 3 commits into from
Feb 12, 2025

Conversation

sivanravidos
Copy link
Collaborator

add an option to create a ranking based on complete pairwise ranking of a list of items.
For a list of items and a given pairwise comparator:

  • Runs the comparator of all pairs of items i,j
  • Rank the item list based on pairwise results using a ranking algorithm.

Currently only one such algorithm is implemented - the Bradely-Terry model, via the choix package implementation.
Note this adds the choix package to the requirements, its license is MIT.
see: https://en.wikipedia.org/wiki/Bradley%E2%80%93Terry_model
and: https://choix.lum.li/en/latest/index.html
The implementation is simple and follows this notebook: https://github.com/lucasmaystre/choix/blob/master/notebooks/intro-pairwise.ipynb

This approach uses N^2 comparisons, so it fit best to small input.

The test on synthetic data gets very high spearman correlation, even with some noise (N-200, noise.= 0.5, spearman = 0.98)

data = []
for i, j in [
(i, j)
for i in range(len(self.items))
Copy link
Collaborator

Choose a reason for hiding this comment

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

on a separate PR, can this be vectorized?
looks like it might be slow

How long does it take for N=200?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

0.4 seconds for 200 items, but this comparator takes no time..

YoelShoshan
YoelShoshan previously approved these changes Feb 10, 2025
Copy link
Collaborator

@YoelShoshan YoelShoshan left a comment

Choose a reason for hiding this comment

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

looks great!

@sivanravidos sivanravidos marked this pull request as ready for review February 10, 2025 11:37
@sivanravidos
Copy link
Collaborator Author

@YoelShoshan I switched to choix dense method, with expects a matrix of comparison, and now expect to get the comparisons from outside. Let me know what do you think.

class PairwiseRanking:
"""
Rank a set of items [a,b,c,...n] based on pairwise comparisons.
The pairwise comparisons should be given as a matrix, and may be complete (n^2) or parital.
Copy link
Collaborator

Choose a reason for hiding this comment

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

looks great!

We need to figure out what people should do if their model return True to both item(i)<item(j) and item(j)<item(i)
also for when their model returned False for both

We can start simple and just ask them to consider model(target, i, j) to mean "i won against j" and they should do:
matrix[i,j]+= 1

and we can start simply with that.

(We can always rectroactively detect the cases mentioned above and modify them with preprocessing in this class)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I think the most straight forward is setting matrix[i,j] = 1 if i<j, and leave it zero if not.
This way we can also have matrix[i,j] =1 and matrix[j,i] = 1 if the model predicts both, or they can both be zero if it doesn't predict any over them.
The ranking algorithm will product the most probably overall ranking considering these inconsistencies.

Copy link
Collaborator

@YoelShoshan YoelShoshan left a comment

Choose a reason for hiding this comment

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

Looks great!

@sivanravidos sivanravidos merged commit 710fa74 into master Feb 12, 2025
6 checks passed
@sivanravidos sivanravidos deleted the pair2list_ranking branch February 12, 2025 11:52
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