Skip to content

Commit

Permalink
Implement dynamic scoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MsRandom committed Nov 27, 2024
1 parent 97573b7 commit 237da0a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions validator/weight_setting/winner_selection.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from operator import itemgetter
from statistics import median

from base.checkpoint import Key, Submissions, Benchmarks
from base.contest import Metrics

RANK_SCORE_IMPROVEMENT_THRESHOLD = 1.05
WINNER_PERCENTAGE = 0.80


Expand All @@ -22,19 +22,30 @@ def get_contestant_ranks(scores: dict[Key, float]) -> dict[Key, int]:
if not scores:
return {}

scores = iter(sorted(scores.items(), key=itemgetter(1), reverse=True))
i = 0
rank = 0

scores = list(sorted(scores.items(), key=itemgetter(1), reverse=True))
score_values = list(map(itemgetter(1), scores))

deviation = median(score_values[i] - score_values[i + 1] for i in range(len(score_values) - 1))

scores = iter(scores)

hotkey, last_score = next(scores)

rank = 0
ranks = {hotkey: rank}

for hotkey, score in scores:
if last_score > score * RANK_SCORE_IMPROVEMENT_THRESHOLD:
last_score = score
difference = last_score - score
i += 1

if difference > deviation:
deviation = (deviation * i + difference) / i
rank += 1

ranks[hotkey] = rank
last_score = score

return ranks

Expand Down

0 comments on commit 237da0a

Please sign in to comment.