74 lines
1.4 KiB
Plaintext
74 lines
1.4 KiB
Plaintext
|
{
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 2,
|
||
|
"metadata": {
|
||
|
"language_info": {
|
||
|
"name": "python",
|
||
|
"codemirror_mode": {
|
||
|
"name": "ipython",
|
||
|
"version": 3
|
||
|
}
|
||
|
},
|
||
|
"orig_nbformat": 2,
|
||
|
"file_extension": ".py",
|
||
|
"mimetype": "text/x-python",
|
||
|
"name": "python",
|
||
|
"npconvert_exporter": "python",
|
||
|
"pygments_lexer": "ipython3",
|
||
|
"version": 3
|
||
|
},
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# Statistical Tools"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import numpy as np"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"* Helper function to calculate the wheel of fortune"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def wheel_of_fortune(rank_i,n):\n",
|
||
|
" return rank_i / (0.5 * n * (n + 1))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 3,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def wheel_of_fortune_selection(items: list, item_scores:list):\n",
|
||
|
" ordering = np.argsort(item_scores)\n",
|
||
|
" ordering = ordering + 1\n",
|
||
|
"\n",
|
||
|
" wheel_weights = wheel_of_fortune(ordering, len(ordering))\n",
|
||
|
"\n",
|
||
|
" return np.random.choice(items, p=wheel_weights)\n"
|
||
|
]
|
||
|
}
|
||
|
]
|
||
|
}
|