<jupyter_start><jupyter_text>Reduction of the Simulations into Matrix Game Social Dilemmas  Preparation  Clone the github repository<jupyter_code>!rm -rf socialsims
!git clone https://leloykun:<EMAIL>/leloykun/socialsims.git
cd socialsims<jupyter_output>/content/socialsims<jupyter_text>The following is needed to ensure that the repo is updated<jupyter_code>!git reset --hard HEAD
!git pull origin<jupyter_output>Already up-to-date.<jupyter_text>Install the necessary libraries<jupyter_code>!pip install -r requirements.txt
import numpy as np
from google.colab import files
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(context='paper')<jupyter_output><empty_output><jupyter_text>Run the Simulations `!python main.py -s [simulation name] [parameter_1, parameter_2, etc]`<jupyter_code>!python main.py -s wolfpack_reduction_2 100 20 20 2 3 50<jupyter_output>wolfpack_reduction_2 started with params: ['90', '20', '20', '2', '3', '50']
-91 -193
-1129 -1231
-156 -462
-82 -490
30 -72
-455 -251
-759 -657
-304 -100
-443 -341
9 -195
-691 -793
-538 -436
-1289 -473
-352 -352
-1275 -867
-300 -402
-50 -50
-530 -734
-568 -262
-411 -513
-596 -392
-215 -419
-944 -638
-708 -912
49 -53
-1243 -1039
-907 -907
-8 -110
-777 -471
-536 -638
-685 -685
92 -520
-129 -231
-954 -852
-998 -794
-533 -533
-266 -368
-158 -464
-378 -174
-371 -65
-820 -1024
-614 -410
-52 50
-668 -464
-295 -703
-250 -250
6 -96
-216 -12
-24 78
-7 -313
-96 -96
-482 -176
194 194
35 -169
-373 -271
-540 -387
79 181
89 -115
-236 -32
-5 -107
-357 -663
-214 -112
252 354
459 51
-466 -160
-597 -291
-380 -278
-12 -114
-143 61
-22 -124
-449 -143
-846 -744
-41 -245
-187 17
-151 53
151 49
-194 112
-394 -292
-301 -403
-426 -528
-45 -45
-108 -6
-418 -622
-500 -602
-52 -52
83 -19
-304 -508
-370 -166
-559 -151
-81 -183
[-690, -690]
[-296, -296]
[-254, 52]
[-477, -477]
[-84, -84]
[-26, -26]
[-975, -1281]
[-5[...]<jupyter_text>Download the results to your pc<jupyter_code>files.download("data/raw/wolfpack_reduction_2/results.npy")<jupyter_output><empty_output><jupyter_text>Data Analysis  Declare helper functions<jupyter_code>def extract_payoffs(x):
  # R, P, S, T
  return [np.mean(x[2]), np.mean(x[0]), x[1][1], x[1][0]]
def greed_fear_coords(x):
  R, P, S, T = extract_payoffs(x)
  return T - R, P - S 
type_name = ["prisoner's dilemma", "chicken", "stag hunt", "almost a social dilemma", "not a social dilemma"]
def msgd_type(x):
  R, P, S, T = extract_payoffs(x)
  if R > P and R > S and 2*R > T+S:
    greed = T - R
    fear = P - S
    if greed >= 0 and fear >= 0:
      return 0
    elif greed >= 0 and fear < 0:
      return 1
    elif greed < 0 and fear >= 0:
      return 2
    else:
      return 3
  else:
    return 4<jupyter_output><empty_output><jupyter_text>Load the results Note: We don't need to rerun the simulations<jupyter_code>res = np.load("data/raw/wolfpack_reduction_2/results.npy")<jupyter_output><empty_output><jupyter_text>Transform into fear-greed coordinates<jupyter_code>X = [[], [], [], [], []]
Y = [[], [], [], [], []]
for x in res:
  greed, fear = greed_fear_coords(x)
  typ = msgd_type(x)
  X[typ].append(fear)
  Y[typ].append(greed)<jupyter_output><empty_output><jupyter_text>Normalize the points<jupyter_code>allx = np.concatenate((X[0], X[1], X[2], X[3], X[4]))
ally = np.concatenate((Y[0], Y[1], Y[2], Y[3], Y[4]))

xgap = max(abs(np.min(allx)), abs(np.max(allx)))
ygap = max(abs(np.min(ally)), abs(np.max(ally)))

for typ in range(5):
  X[typ] = np.array(X[typ]) / xgap
  Y[typ] = np.array(Y[typ]) / ygap<jupyter_output><empty_output><jupyter_text>Plot the points<jupyter_code>plt.figure(figsize=(3.5,3.5))

plt.xlim(-1, 1)
plt.ylim(-1, 1)

plt.xticks(np.linspace(-1, 1, 5), fontsize=10)
plt.yticks(np.linspace(-1, 1, 5), fontsize=10)

plt.fill([0, 1, 1, 0],   [0, 0, 1, 1], 'red', alpha=0.1)
plt.fill([0, -1, -1, 0], [0, 0, 1, 1], 'blue', alpha=0.1)
plt.fill([0, 1, 1, 0],   [0, 0, -1, -1], 'green', alpha=0.1)
plt.fill([0, -1, -1, 0], [0, 0, -1, -1], 'grey', alpha=0.1)

plt.xlabel('Fear', fontsize=12)
plt.ylabel('Greed', fontsize=12)

plt.scatter(X[0], Y[0], marker='s', color='red', label='Prisoner\'s Dilemma')
plt.scatter(X[1], Y[1], marker='*', color='blue', label='Chicken')
plt.scatter(X[2], Y[2], marker='o', color='green', label='Stag Hunt')
plt.scatter(X[3], Y[3], marker='+', color='grey', label='Non Social Dilemma (R > P)')
plt.scatter(X[4], Y[4], marker='x', color='grey', label='Non Social Dilemma (R < P)')

lgd = plt.legend(loc='center left', fontsize=12, bbox_to_anchor=(1, 0.5))
plt.savefig('wolfpack_results.png', dpi=1024,  bbox_extra_artists=(lgd,), bbox_inches='tight')
plt.show()
files.download('wolfpack_results.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19008970525416488, 'fraction_numerical': 0.14395557454079452, 'mean_word_length': 3.934668071654373, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 47, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '22377', 'license': 'MIT', 'n_tokens_mistral': 2475, 'n_tokens_neox': 2029, 'n_words': 541, 'path': 'data/Wolfpack_Reduction.ipynb', 'repo_name': 'LE-LOY/socialsims', 'size': '4694'}