Skip to content

Commit

Permalink
Reimplement preference converter
Browse files Browse the repository at this point in the history
  • Loading branch information
daffidwilde committed Apr 9, 2024
1 parent 8a5903b commit ea23205
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/matching/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
from scipy.stats import rankdata


def preference_to_rank(preference, others):
"""Convert a preference dictionary to a rank array."""
def preference_to_rank(preferences, others):
"""Convert a preference list dictionary to a rank array."""

rank = np.array(
[[others.index(o) for o in prefs] for prefs in preference.values()]
)
sorted_preferences = sorted(preferences.items(), key=lambda x: x[0])
sorted_others = sorted(others)
ranks = [
[prefs.index(o) if o in prefs else len(others) for o in sorted_others]
for _, prefs in sorted_preferences
]

return rank
return np.array(ranks)


def utility_to_rank(utility):
Expand Down

0 comments on commit ea23205

Please sign in to comment.