diff --git a/neighbor_per_round.py b/neighbor_per_round.py index be9b5bb..8a0bf28 100644 --- a/neighbor_per_round.py +++ b/neighbor_per_round.py @@ -21,7 +21,7 @@ cstd = [] dstd = [] -def is_defector(rows, pid): +def is_cooperator(rows, pid): m = 0 mall = 0 for r in rows: @@ -67,7 +67,7 @@ for i in range(max_round): if k in survivals[matches.names[j]][str(i+1)]: nn += 1 - if is_defector(rows, row['a']): + if is_cooperator(rows, row['a']): cneigh.append(nn) else: dneigh.append(nn) @@ -78,7 +78,7 @@ for i in range(max_round): for k in neighbors[matches.names[j]][row['b']]: if k in survivals[matches.names[j]][str(i+1)]: nn += 1 - if is_defector(rows, row['b']): + if is_cooperator(rows, row['b']): cneigh.append(nn) else: dneigh.append(nn) diff --git a/request_success.py b/request_success.py index 18d1b61..b75fa19 100644 --- a/request_success.py +++ b/request_success.py @@ -14,6 +14,21 @@ c_req = np.zeros(max_round-2) d_req_succ = np.zeros(max_round-2) d_req = np.zeros(max_round-2) +def is_cooperator(rows, pid): + m = 0 + mall = 0 + for r in rows: + if pid == r['a'] and r['act_a'] == 'C': + m += 1 + mall += 1 + elif pid == r['a'] and r['act_a'] == 'D': + mall += 1 + elif pid == r['b'] and r['act_b'] == 'C': + m += 1 + mall += 1 + elif pid == r['b'] and r['act_b'] == 'D': + mall += 1 + return m*2 >= mall for i in range(max_round): for j in range(len(matches.data)): @@ -23,7 +38,7 @@ for i in range(max_round): if row['a'] not in calced: r = matches.data[j].query('action', 'request').where(lambda x: x['rno'] == i+2 and x['from'] == row['a']).raw_data rs = matches.data[j].query('action', 'approve').where(lambda x: x['rno'] == i+2 and x['to'] == row['a']).raw_data - if row['act_a'] == 'C': + if is_cooperator(rows, row['a']): c_req_succ[j] += len(rs) c_req[j] += len(r) else: @@ -34,7 +49,7 @@ for i in range(max_round): if row['b'] not in calced: r = matches.data[j].query('action', 'request').where(lambda x: x['rno'] == i+2 and x['from'] == row['b']).raw_data rs = matches.data[j].query('action', 'approve').where(lambda x: x['rno'] == i+2 and x['to'] == row['b']).raw_data - if row['act_b'] == 'C': + if is_cooperator(rows, row['b']): c_req_succ[j] += len(rs) c_req[j] += len(r) else: @@ -74,9 +89,9 @@ flier_marker = dict(markerfacecolor='w', marker='o', markersize=4, markeredgewid mean_marker = dict(markerfacecolor='w', marker='s', markeredgecolor='#0984e3', markersize=5, markeredgewidth=1) ax.boxplot(req_succ, showmeans=True, notch=True, meanprops=mean_marker, flierprops=flier_marker, - whis=[0.15,99.85], + whis=[0.35,99.65], widths=0.4, - labels=['Cooperation', 'Defection']) + labels=['From Cooperator', 'From Defector']) m1 = np.median(c_req_succ_fr) m2 = np.median(d_req_succ_fr) @@ -92,8 +107,8 @@ print('IQR=(%f, %f)' % (i1, i2)) # ax.set_xlabel('Group') -ax.set_ylabel('Rate') -ax.set_title('Request Approving Rate after Specific Actions', fontsize='small', weight='semibold') +ax.set_ylabel('Request Approval Rate') +# ax.set_title(' from ', fontsize='small', weight='semibold') # ax.set_xticks(index) # ax.set_ylim(0, 1) # ax.set_xlim(-0.75, 1.75) diff --git a/request_success_per_round.py b/request_success_per_round.py index 4c84de1..874cb22 100644 --- a/request_success_per_round.py +++ b/request_success_per_round.py @@ -7,7 +7,7 @@ import numpy as np matches = Matches('wos-data-new') -max_round = 13 +max_round = 14 c_req_suc_mean = [] d_req_suc_mean = [] @@ -19,6 +19,22 @@ d_req_fail_mean = [] c_req_fail_std = [] d_req_fail_std = [] +def is_cooperator(rows, pid): + m = 0 + mall = 0 + for r in rows: + if pid == r['a'] and r['act_a'] == 'C': + m += 1 + mall += 1 + elif pid == r['a'] and r['act_a'] == 'D': + mall += 1 + elif pid == r['b'] and r['act_b'] == 'C': + m += 1 + mall += 1 + elif pid == r['b'] and r['act_b'] == 'D': + mall += 1 + return m*2 >= mall + for i in range(max_round): cReSu = [] cReFa = [] @@ -31,7 +47,7 @@ for i in range(max_round): if row['a'] not in calced: r = matches.data[j].query('action', 'request').where(lambda x: x['rno'] == i+2 and x['from'] == row['a']).raw_data rs = matches.data[j].query('action', 'approve').where(lambda x: x['rno'] == i+2 and x['to'] == row['a']).raw_data - if row['act_a'] == 'C': + if is_cooperator(rows, row['a']): cReSu.append(len(rs)) cReFa.append(len(r) - len(rs)) else: @@ -42,7 +58,7 @@ for i in range(max_round): if row['b'] not in calced: r = matches.data[j].query('action', 'request').where(lambda x: x['rno'] == i+2 and x['from'] == row['b']).raw_data rs = matches.data[j].query('action', 'approve').where(lambda x: x['rno'] == i+2 and x['to'] == row['b']).raw_data - if row['act_b'] == 'C': + if is_cooperator(rows, row['a']): cReSu.append(len(rs)) cReFa.append(len(r) - len(rs)) else: @@ -95,23 +111,23 @@ error_config = {'ecolor': '0.3', 'capsize': 4} rects1 = ax.bar(index, c_req_suc_mean, bar_width, alpha=opacity, color='#00b894', # yerr=c_req_suc_std, error_kw=error_config, - label='Approve after Cooperation') + label='Request from Cooperator Approved') rects2 = ax.bar(index, c_req_fail_mean, bar_width, alpha=opacity, color='#0984e3', # yerr=c_req_fail_std, error_kw=error_config, bottom=c_req_suc_mean, - label='Deny after Cooperation') + label='Request from Cooperator Rejected') rects3 = ax.bar(index + bar_width, d_req_suc_mean, bar_width, alpha=opacity, color='#fdcb6e', # yerr=d_req_suc_mean, error_kw=error_config, - label='Approve after Defection') + label='Request from Defector Approved') rects4 = ax.bar(index + bar_width, d_req_fail_mean, bar_width, alpha=opacity, color='#d63031', # yerr=d_req_fail_mean, error_kw=error_config, bottom=d_req_suc_mean, - label='Deny after Defection') + label='Request from Defector Rejected') ax.set_xlabel('Round') ax.set_ylabel('Number of Requests')