Skip to content

Commit

Permalink
averages
Browse files Browse the repository at this point in the history
  • Loading branch information
ggsavin committed Feb 17, 2024
1 parent 542063e commit ae1a860
Showing 1 changed file with 88 additions and 37 deletions.
125 changes: 88 additions & 37 deletions notebooks/oracle.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 56,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -45,7 +45,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand All @@ -54,7 +54,7 @@
"<All keys matched successfully>"
]
},
"execution_count": 5,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -77,7 +77,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -176,7 +176,7 @@
},
{
"cell_type": "code",
"execution_count": 176,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -222,49 +222,53 @@
" v_wins = df[df['game_result'] == 0]\n",
" v_losses = df[df['game_result'] == 1]\n",
"\n",
" print(f'Likelihood that oracle lived to see end of a winning game : {len(v_wins[v_wins[\"day_oracle_killed\"] == -1])/len(v_wins):.2f}')\n",
" # print(f'Likelihood of Oracle being executed : {1 - oracle_executions[\"day_oracle_killed\"].value_counts()[-1] / len(df)}')\n",
"\n",
" print(f'Oracle being executed in a winning game : {len(v_wins[(v_wins[\"day_oracle_killed\"] != -1) & (v_wins[\"way_oracle_killed\"] == 0)])/len(v_wins):.2f}')\n",
" print(f'Oracle being executed in a losing game : {len(v_losses[(v_losses[\"day_oracle_killed\"] != -1) & (v_losses[\"way_oracle_killed\"] == 0)])/len(v_losses):.2f}')\n",
"\n",
" print(f'Likelihood of Oracle being executed : {len(oracle_executions)/len(df):.2f} ')\n",
" print(f'\\t Oracle executed in day 0 : {len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 0])/len(oracle_executions):.3f}')\n",
" print(f'\\t Oracle executed in day 1 : {len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 1])/len(oracle_executions):.3f}')\n",
" print(f'\\t Oracle executed in day 2 : {len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 2])/len(oracle_executions):.3f}')\n",
" print(f'\\t Oracle executed in day 3 : {len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 3])/len(oracle_executions):.3f}')\n",
" print(f'\\t Oracle executed in day 4 : {len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 4])/len(oracle_executions):.3f}')\n",
"\n",
" return {\n",
" '1': len(oracle_executions)/len(df),\n",
" '2': [\n",
" len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 0])/len(oracle_executions),\n",
" len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 1])/len(oracle_executions),\n",
" len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 2])/len(oracle_executions),\n",
" len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 3])/len(oracle_executions),\n",
" len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 4])/len(oracle_executions)\n",
" ]\n",
" }"
" # print(f'Likelihood that oracle lived to see end of a winning game : {len(v_wins[v_wins[\"day_oracle_killed\"] == -1])/len(v_wins):.2f}')\n",
" # # print(f'Likelihood of Oracle being executed : {1 - oracle_executions[\"day_oracle_killed\"].value_counts()[-1] / len(df)}')\n",
"\n",
" # print(f'Oracle being executed in a winning game : {len(v_wins[(v_wins[\"day_oracle_killed\"] != -1) & (v_wins[\"way_oracle_killed\"] == 0)])/len(v_wins):.2f}')\n",
" # print(f'Oracle being executed in a losing game : {len(v_losses[(v_losses[\"day_oracle_killed\"] != -1) & (v_losses[\"way_oracle_killed\"] == 0)])/len(v_losses):.2f}')\n",
"\n",
" # print(f'Likelihood of Oracle being executed : {len(oracle_executions)/len(df):.2f} ')\n",
" # print(f'\\t Oracle executed in day 0 : {len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 0])/len(oracle_executions):.3f}')\n",
" # print(f'\\t Oracle executed in day 1 : {len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 1])/len(oracle_executions):.3f}')\n",
" # print(f'\\t Oracle executed in day 2 : {len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 2])/len(oracle_executions):.3f}')\n",
" # print(f'\\t Oracle executed in day 3 : {len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 3])/len(oracle_executions):.3f}')\n",
" # print(f'\\t Oracle executed in day 4 : {len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 4])/len(oracle_executions):.3f}')\n",
"\n",
" return [len(v_wins[v_wins[\"day_oracle_killed\"] == -1])/len(v_wins),\n",
" len(v_wins[(v_wins[\"day_oracle_killed\"] != -1) & (v_wins[\"way_oracle_killed\"] == 0)])/len(v_wins),\n",
" len(v_losses[(v_losses[\"day_oracle_killed\"] != -1) & (v_losses[\"way_oracle_killed\"] == 0)])/len(v_losses),\n",
" len(oracle_executions)/len(df)]\n",
" # return {\n",
" # '1': len(oracle_executions)/len(df),\n",
" # '2': [\n",
" # len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 0])/len(oracle_executions),\n",
" # len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 1])/len(oracle_executions),\n",
" # len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 2])/len(oracle_executions),\n",
" # len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 3])/len(oracle_executions),\n",
" # len(oracle_executions[oracle_executions[\"day_oracle_killed\"] == 4])/len(oracle_executions)\n",
" # ]\n",
" # }"
]
},
{
"cell_type": "code",
"execution_count": 177,
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Without Oracle wins : 0.59 \n",
"Without Oracle wins : 0.61 \n",
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"0it [00:00, ?it/s]\n"
"100%|██████████| 10/10 [36:38<00:00, 219.86s/it]\n"
]
}
],
Expand All @@ -280,7 +284,7 @@
"p = [0.0,0.5,1.0]\n",
"oracle_res = []\n",
"o_results = {}\n",
"for i in tqdm(range(0)):\n",
"for i in tqdm(range(10)):\n",
" for how_v in vill_vote:\n",
" for percent in p:\n",
" wins, replays, o_ids = play_recurrent_game_with_oracle(env, \n",
Expand All @@ -293,15 +297,15 @@
" vtc_other_villagers=how_v,\n",
" p=percent)\n",
" \n",
" print(\"+++++++++++++\")\n",
" print(f'Oracle wins with {how_v} for villagers and a chance of voting for werewolves at {percent}: {wins/float(num_times):.2f}')\n",
" print(\"-------------\")\n",
" # print(\"+++++++++++++\")\n",
" # print(f'Oracle wins with {how_v} for villagers and a chance of voting for werewolves at {percent}: {wins/float(num_times):.2f}')\n",
" # print(\"-------------\")\n",
" oracle_res.append(f'{wins/float(num_times):.2f}')\n",
" run_res = print_oracle_info(replays, o_ids)\n",
" if f'{how_v}_{percent}' not in o_results.keys():\n",
" o_results[f'{how_v}_{percent}'] = [run_res]\n",
" o_results[f'{how_v}_{percent}'] = [[wins/float(num_times), *run_res]]\n",
" else:\n",
" o_results[f'{how_v}_{percent}'].append(run_res)\n",
" o_results[f'{how_v}_{percent}'].append([wins/float(num_times), *run_res])\n",
" # print(\"+++++++++++++\")\n",
" # print()\n",
" # print(\"\\n\")\n",
Expand All @@ -313,6 +317,53 @@
"# print(f'With other random villager wins : {wins/float(num_times):.2f}')\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'1_0.0': array([0.4565 , 0.51248379, 0.22238384, 0.45998759, 0.3514 ]),\n",
" '1_0.5': array([0.4498 , 0.48570549, 0.23497028, 0.46977154, 0.3644 ]),\n",
" '1_1.0': array([0.4356 , 0.47607341, 0.24376224, 0.48497113, 0.3799 ]),\n",
" '0_0.0': array([0.569 , 0.62276081, 0.13006722, 0.38740495, 0.241 ]),\n",
" '0_0.5': array([0.5584 , 0.63083329, 0.13991254, 0.39401212, 0.2522 ]),\n",
" '0_1.0': array([0.5407 , 0.62655096, 0.1402842 , 0.39408828, 0.2569 ])}"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"o_results['1_0.0']\n",
"\n",
"{k:np.mean(v,axis=0) for (k,v) in o_results.items()}"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.4565 , 0.51248379, 0.22238384, 0.45998759, 0.3514 ])"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.mean(o_results['1_0.0'],axis=0)"
]
},
{
"cell_type": "code",
"execution_count": 138,
Expand Down

0 comments on commit ae1a860

Please sign in to comment.