23 lines
460 B
Python
23 lines
460 B
Python
#!/usr/bin/env python3
|
|
# coding: utf-8
|
|
|
|
# # Statistical Tools
|
|
|
|
import numpy as np
|
|
|
|
|
|
# * Helper function to calculate the wheel of fortune
|
|
|
|
def wheel_of_fortune(rank_i,n):
|
|
return rank_i / (0.5 * n * (n + 1))
|
|
|
|
|
|
def wheel_of_fortune_selection(items: list, item_scores:list):
|
|
ordering = np.argsort(item_scores)
|
|
ordering = ordering + 1
|
|
|
|
wheel_weights = wheel_of_fortune(ordering, len(ordering))
|
|
|
|
return np.random.choice(items, p=wheel_weights)
|
|
|