new version

This commit is contained in:
wJsJwr 2018-07-15 12:22:05 +08:00
parent 57368db7a9
commit 0bc7632c58
15 changed files with 233 additions and 142 deletions

3
.gitignore vendored
View File

@ -1,7 +1,8 @@
.DS_Store .DS_Store
graph graph
wos-data* wos-data*
!wos-data-complete
user* user*
*.svg *.svg
__pycache__ __pycache__
.vscode/ .vscode

Binary file not shown.

View File

@ -3,7 +3,8 @@ from matplotlib import pyplot as plt
from island.match import Match from island.match import Match
from island.matches import Matches from island.matches import Matches
matches = Matches('wos-data-new') mode = 'SURVIVE'
matches = Matches.from_profile_expr(lambda r: mode in r)
labels = ['Stay Connected', 'Break Tie'] labels = ['Stay Connected', 'Break Tie']
percents = [0.0, 0.0] percents = [0.0, 0.0]
@ -16,7 +17,7 @@ for m in matches.data:
for row in m.query('action', 'done').where(lambda x: x['act_a'] == op or x['act_b'] == op).raw_data: for row in m.query('action', 'done').where(lambda x: x['act_a'] == op or x['act_b'] == op).raw_data:
if row['rno'] == game_end_at: if row['rno'] == game_end_at:
print(row) # print(row)
continue continue
if row['act_a'] == op: if row['act_a'] == op:
a = row['a'] a = row['a']
@ -46,4 +47,4 @@ plt.pie(percents, labels=labels, autopct="%1.2f%%", pctdistance=1.1, labeldistan
plt.legend() plt.legend()
plt.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle. plt.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
# plt.show() # plt.show()
plt.savefig("graph/break_tie_%s.eps"%op) plt.savefig("graph/break_tie_%s_%s.eps"%(op, mode))

View File

@ -1,6 +1,15 @@
from scipy.stats import chi2_contingency as chi2 from scipy.stats import chi2_contingency as chi2
import numpy as np import numpy as np
obs = np.array([[219,113],[661,25]]) obs = np.array([[2887.0, 459.0], [61.0, 383.0]])
chi,p,dof,expected = chi2(obs) chi,p,dof,expected = chi2(obs)
print("%f, %f, %f" % (chi, p, dof)) print("%f, %e, %f" % (chi, p, dof))
'''
survive:
chi = 1189.53, p = 1.149752e-260
survive:
chi = 611.59, p = 5.031232e-135
'''

View File

@ -4,7 +4,7 @@ from island.match import Match
from island.matches import Matches from island.matches import Matches
import numpy as np import numpy as np
matches = Matches('wos-data-compete') matches = Matches.from_profile_expr(lambda r: True)
max_round = 15 max_round = 15
total_players = 0 total_players = 0

View File

@ -8,18 +8,19 @@ result = 0
count = 0 count = 0
# ms = Matches.from_profile('CCCN') # ms = Matches.from_profile('CCCN')
ms = Matches.from_profile_expr(lambda r: 'LAB' in r and 'SURVIVE' in r and 'COMM' in r) ms = Matches.from_profile_expr(lambda r: True)
for m in ms.data: for m in ms.data:
result += len(m.query('player', 'join').where(lambda x: 'bot' not in x or x['bot'] == False).select('pid').raw_data) result += len(m.query('player', 'join').where(lambda x: 'bot' not in x or x['bot'] == False).select('pid').raw_data)
count += 1 count += 1
print(result) print(result)
print("avg:", result / count) print("participants: %d, matches: %d, avg: %f" % (result, count, result / count))
# 146 users # 146 users
# casual: 324 # casual: 324
# new(254-354, 全国复杂网络大会): 205 # new(254-354, 全国复杂网络大会): 205
# new-2(375-421, 无交流): 320 # new-2(375-421, 无交流): 320
# new-3(426-440, 有交流): 203 # new-3(426-440, 有交流): 203
# new-4(443-472, 经典模式,无交流): 230 # new-4(443-472, 经典模式,无交流): 230
# new-5(474-,经典模式,有交流): 159 # new-5(474-,经典模式,有交流): 286
# total: 1117 # total: 1244, 81, 15.35
# lab: 1039, 69, 15.05

View File

@ -4,11 +4,11 @@ from island.match import Match
result = {} result = {}
for file in Path('wos-data-compete').iterdir(): for f in Path('wos-data-compete').iterdir():
p = Path(file) p = Path(f)
if p.suffix == '.json': if p.suffix == '.json':
name = p.stem name = p.stem
m = Match.read_from_json(str(file)) m = Match.read_from_json(str(f))
info = m.query('game', 'created').select('info').first()['info'] info = m.query('game', 'created').select('info').first()['info']
conf = json.loads(info['config']) conf = json.loads(info['config'])
game_end_at = int(info['game_end_at']) game_end_at = int(info['game_end_at'])

View File

@ -4,7 +4,8 @@ from island.match import Match
from island.matches import Matches from island.matches import Matches
import numpy as np import numpy as np
matches = Matches('wos-data-new-3')
matches = Matches.from_profile_expr(lambda r: 'CLASSIC' in r)
max_round = 15 max_round = 15
coopr = [] coopr = []
@ -14,7 +15,7 @@ x = np.arange(1, max_round+1)
bx = [] bx = []
survivals = {} survivals = {}
with open('winner.json','r') as f: with open('survivals.json','r') as f:
survivals = json.load(f) survivals = json.load(f)
for i in range(max_round): for i in range(max_round):
@ -46,4 +47,4 @@ plt.figure()
# plt.boxplot(bx, showmeans=True, meanline=True) # plt.boxplot(bx, showmeans=True, meanline=True)
plt.plot(x, coopr) plt.plot(x, coopr)
plt.show() plt.show()
# plt.savefig('graph/co_per_round.png') # plt.savefig('graph/co_per_round.png')

View File

@ -3,11 +3,12 @@ from matplotlib import pyplot as plt
from island.match import Match from island.match import Match
from island.matches import Matches from island.matches import Matches
matches = Matches('wos-data-new') mode = 'SURVIVE'
matches = Matches.from_profile_expr(lambda r: mode in r)
percents = [0.0, 0.0] percents = [0.0, 0.0]
op = 'C' op = 'D'
def get_reason(m, i, target): def get_reason(m, i, target):
r = m.query('action', 'request').where(lambda x: x['rno'] == i+1 and x['from'] == target).raw_data r = m.query('action', 'request').where(lambda x: x['rno'] == i+1 and x['from'] == target).raw_data
@ -52,11 +53,11 @@ percents[0] /= _all
percents[1] /= _all percents[1] /= _all
labels = ['Insufficient Temporal Resource', 'Sufficient Temporal Resource'] labels = ['Insufficient Time Resource', 'Sufficient Time Resource']
plt.figure() plt.figure()
plt.pie(percents, labels=labels, autopct="%1.2f%%", pctdistance=1.1, labeldistance=2,startangle=90, colors=['#00b894', '#fdcb6e']) plt.pie(percents, labels=labels, autopct="%1.2f%%", pctdistance=1.1, labeldistance=2,startangle=90, colors=['#00b894', '#fdcb6e'])
plt.legend() plt.legend()
plt.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle. plt.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
# plt.show() # plt.show()
plt.savefig("graph/fail_reason_%s.eps"%op) plt.savefig("graph/fail_reason_%s_%s.eps"%(op, mode))

View File

@ -1,6 +1,14 @@
from scipy.stats import chi2_contingency as chi2 from scipy.stats import chi2_contingency as chi2
import numpy as np import numpy as np
obs = np.array([[159,90],[53,24]]) obs = np.array([[203.0, 49.0], [279.0, 78.0]])
chi,p,dof,expected = chi2(obs) chi,p,dof,expected = chi2(obs)
print("%f, %f, %f" % (chi, p, dof)) print("%f, %e, %f" % (chi, p, dof))
'''
classic
chi = 0.381964, p = 0.536554
survive
chi = 23.490576, p = 1.255272e-06
'''

View File

@ -5,15 +5,15 @@ from island.matches import Matches
import numpy as np import numpy as np
from scipy.stats import pearsonr from scipy.stats import pearsonr
mode = 'CLASSIC'
matches = Matches.from_profile_expr(lambda r: mode in r)
matches = Matches('wos-data-new-2') k = np.arange(5, 11)
succ = np.zeros(10)
k = np.arange(2, 11) total = np.zeros(10)
succ = np.zeros(9)
total = np.zeros(9)
survivals = {} survivals = {}
with open('survivals-2.json', 'r') as f: with open('survivals.json', 'r') as f:
survivals = json.load(f) survivals = json.load(f)
neighbors = {} neighbors = {}
@ -73,10 +73,23 @@ for m_i in range(len(matches.data)):
else: else:
if r['a'] not in previous_round_partner: if r['a'] not in previous_round_partner:
new_partner_succ += 1 new_partner_succ += 1
succ[len(neighborhood)-2] += new_partner_succ try:
total[len(neighborhood)-2] += new_partner_request succ[len(neighborhood) - 2] += new_partner_succ
total[len(neighborhood) - 2] += new_partner_request
except:
print("N!: %d" % len(neighborhood))
print(succ,total)
# for classic
succ = succ[4:]
total = total[4:]
# for survival
# succ = succ[:-1]
# total = total[:-1]
red = '#d63031' red = '#d63031'
fig = plt.figure(figsize=(6.4, 4)) fig = plt.figure(figsize=(6.4, 4))
ax = fig.gca() ax = fig.gca()
@ -105,9 +118,9 @@ ax2.tick_params(axis='y', labelcolor=red)
ax2.set_ylim(0,1) ax2.set_ylim(0,1)
fig.tight_layout() fig.tight_layout()
# plt.show() # plt.show()
# plt.savefig('graph/k_and_new_partner.eps') plt.savefig("graph/k_and_new_partner_%s.eps" % mode)
print("[succ vs k]pearson: %f, p-value: %f" % pearsonr(succ, k)) print("[succ vs k]pearson: %f, p-value: %f" % pearsonr(succ, k))
print("[total vs k]pearson: %f, p-value: %f" % pearsonr(total, k)) print("[total vs k]pearson: %f, p-value: %f" % pearsonr(total, k))
print("[rate vs k]pearson: %f, p-value: %f" % pearsonr(succ/total, k)) print("[rate vs k]pearson: %f, p-value: %f" % pearsonr(succ/total, k))
print(np.average(succ/total)) print(np.average(succ/total))

View File

@ -73,3 +73,9 @@ wos-data-compete/G480.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G481.json,,LAB,,COMM,,CLASSIC wos-data-compete/G481.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G482.json,,LAB,,COMM,,CLASSIC wos-data-compete/G482.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G483.json,,LAB,,COMM,,CLASSIC wos-data-compete/G483.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G484.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G485.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G487.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G488.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G490.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G491.json,,LAB,,COMM,,CLASSIC
1 wos-data-compete/G254.json CCCN COMM SURVIVE
73 wos-data-compete/G481.json LAB COMM CLASSIC
74 wos-data-compete/G482.json LAB COMM CLASSIC
75 wos-data-compete/G483.json LAB COMM CLASSIC
76 wos-data-compete/G484.json LAB COMM CLASSIC
77 wos-data-compete/G485.json LAB COMM CLASSIC
78 wos-data-compete/G487.json LAB COMM CLASSIC
79 wos-data-compete/G488.json LAB COMM CLASSIC
80 wos-data-compete/G490.json LAB COMM CLASSIC
81 wos-data-compete/G491.json LAB COMM CLASSIC

View File

@ -10,13 +10,66 @@ from matplotlib import markers
def error(f,x,y): def error(f,x,y):
return sp.sum((f(x)-y)**2) return sp.sum((f(x)-y)**2)
if __name__ == '__main__': def p1(x, rewires, tau, postfix, show):
fig = plt.figure(figsize=(6.4, 3.6))
ax = fig.gca()
ax.plot(x, rewires, color=green, linewidth=3)
ax.set_ylim(0, 0.5)
ax2 = ax.twinx()
ax2.plot(x, tau, color=red, linewidth=3)
ax2.set_ylim(0, 1440)
ax.set_xlim(1, 14)
ax.set_xlabel("Rounds")
ax.set_ylabel("Rewiring Rate", color=green)
ax.tick_params(axis='y', labelcolor=green)
ax2.set_ylabel("$\\tau_{p}$", family='sans-serif', color=red)
ax2.tick_params(axis='y', labelcolor=red)
matches = Matches('wos-data-new-2') plt.tight_layout()
if show:
plt.show()
else:
plt.savefig("graph/tau_p_rewire_plot_%s.eps" % postfix)
def p2(tau, rewires, postfix, show):
# # p2散点图
fig = plt.figure(figsize=(6.4, 3.6))
ax = fig.gca()
# ax.set_ylim(0.5, 1)
fp1,residuals,rank,sv,rcond = sp.polyfit(tau, rewires, 1, full=True)
print("残差:",residuals)
print('Model parameter:',fp1)
f1 = sp.poly1d(fp1)
print("error= %f" % error(f1, tau, rewires))
print("Other parameters: rank=%s, sv=%s, rcond=%s" % (str(rank), str(sv), str(rcond)))
# fx = sp.linspace(0,max(tau2),1000)
fx = sp.linspace(0,1440,2)
plt.plot(fx,f1(fx),linewidth=2,color=red, ls='--', zorder=0)
plt.scatter(tau, rewires, color=green, linewidths=2, zorder=100)
# plt.scatter(tau_r, coopr_r, color='white', edgecolors=green, linewidths=2, zorder=101)
ax.set_xlabel('$\\tau_{p}$', family='sans-serif')
ax.set_ylabel('Rewiring Rate')
ax.set_xlim(0, 1440)
ax.set_xticks(sp.linspace(0, 1440, 13))
ax.set_ylim(0, 0.6)
plt.tight_layout()
if show:
plt.show()
else:
plt.savefig("graph/tau_p_rewire_sca_%s.eps" % postfix)
# 皮尔逊相关系数
print("pearson: %f, p-value: %f" % pearsonr(tau, rewires))
if __name__ == '__main__':
mode = 'CLASSIC'
matches = Matches.from_profile_expr(lambda r: mode in r)
max_round = 15 max_round = 15
survivals = {} survivals = {}
with open('survivals-2.json', 'r') as f: with open('survivals.json', 'r') as f:
survivals = json.load(f) survivals = json.load(f)
neighbors = {} neighbors = {}
@ -95,49 +148,21 @@ if __name__ == '__main__':
red = '#d63031' red = '#d63031'
# p1折线图 # p1折线图
fig = plt.figure(figsize=(6.4, 3.6)) # p1(x, rewires, tau, mode, False)
ax = fig.gca() p2(tau, rewires, mode, False)
ax.plot(x, rewires, color=green, linewidth=3)
ax.set_ylim(0, 0.5) '''
ax2 = ax.twinx() classic
ax2.plot(x, tau, color=red, linewidth=3) 残差 [ 0.05873797]
ax2.set_ylim(0,1440) Model parameter: [ 9.81549075e-04 -9.87729952e-01]
ax.set_xlim(1,14) error= 0.058738
ax.set_xlabel("Rounds") Other parameters: rank=2, sv=[ 1.41291267 0.06064473], rcond=3.10862446895e-15
ax.set_ylabel("Rewiring Rate", color=green) pearson: 0.823000, p-value: 0.000300
ax.tick_params(axis='y', labelcolor=green)
ax2.set_ylabel("$\\tau_{p}$", family='sans-serif', color=red)
ax2.tick_params(axis='y', labelcolor=red)
plt.tight_layout() survive
plt.show() 残差 [ 0.05788203]
# plt.savefig('graph/tau_p_rewire_plot.eps') Model parameter: [ 0.00033232 -0.06283898]
error= 0.057882
# # p2散点图 Other parameters: rank=2, sv=[ 1.3284034 0.48512309], rcond=3.10862446895e-15
# fig = plt.figure(figsize=(6.4, 3.6)) pearson: 0.893237, p-value: 0.000017
# ax = fig.gca() '''
# # ax.set_ylim(0.5, 1)
# fp1,residuals,rank,sv,rcond = sp.polyfit(tau, rewires, 1, full=True)
# print("残差:",residuals)
# print('Model parameter:',fp1)
# f1 = sp.poly1d(fp1)
# print("error= %f" % error(f1, tau, rewires))
# # fx = sp.linspace(0,max(tau2),1000)
# fx = sp.linspace(0,1440,2)
# plt.plot(fx,f1(fx),linewidth=2,color=red, ls='--', zorder=0)
# plt.scatter(tau, rewires, color=green, linewidths=2, zorder=100)
# # plt.scatter(tau_r, coopr_r, color='white', edgecolors=green, linewidths=2, zorder=101)
# ax.set_xlabel('$\\tau_{p}$', family='sans-serif')
# ax.set_ylabel('Rewiring Rate')
# ax.set_xlim(0, 1440)
# ax.set_xticks(sp.linspace(0, 1440, 13))
# ax.set_ylim(0, 0.6)
# plt.tight_layout()
# plt.show()
# plt.savefig('graph/tau_p_rewire_sca.eps')
# # 皮尔逊相关系数
print("pearson: %f, p-value: %f" % pearsonr(tau, rewires))

File diff suppressed because one or more lines are too long

View File

@ -7,16 +7,83 @@ import scipy as sp
from scipy.stats import pearsonr from scipy.stats import pearsonr
from matplotlib import markers from matplotlib import markers
'''
计算tau_p和合作频率之间的关系
'''
def error(f,x,y): def error(f,x,y):
return sp.sum((f(x)-y)**2) return sp.sum((f(x)-y)**2)
def p1(x, coopr, tau, postfix, show=True):
fig = plt.figure(figsize=(6.4, 3.6))
ax = fig.gca()
ax.plot(x, coopr, color=blue, linewidth=3)
ax.set_ylim(0.5, 1)
ax2 = ax.twinx()
ax2.plot(x, tau, color=red, linewidth=3)
ax2.set_ylim(0, 1440)
ax.set_xlim(1, 14)
ax.set_xlabel("Rounds")
ax.set_ylabel("Frequency of Cooperation", color=blue)
ax.tick_params(axis='y', labelcolor=blue)
ax2.set_ylabel("$\\tau_{p}$", family='sans-serif', color=red)
ax2.tick_params(axis='y', labelcolor=red)
plt.tight_layout()
if show:
plt.show()
else:
plt.savefig("graph/tau_p_co_plot_%s.eps" % postfix)
def p2(tau, coopr, limited, postfix, show=True):
tau2 = []
coopr2 = []
tau_r = []
coopr_r = []
for i in range(len(tau)):
if tau[i] <= limited:
tau2.append(tau[i])
coopr2.append(coopr[i])
else:
tau_r.append(tau[i])
coopr_r.append(coopr[i])
# p2散点图
fig = plt.figure(figsize=(6.4, 3.6))
ax = fig.gca()
# ax.set_ylim(0.5, 1)
fp1,residuals,rank,sv,rcond = sp.polyfit(tau2, coopr2, 1, full=True)
print("残差:",residuals)
print('Model parameter:',fp1)
print("Other parameters: rank=%s, sv=%s, rcond=%s"%(str(rank), str(sv), str(rcond)))
f1 = sp.poly1d(fp1)
print("error= %f" % error(f1, tau2, coopr2))
fx = sp.linspace(0, limited, 2)
plt.plot(fx,f1(fx),linewidth=2,color=red, ls='--', zorder=0)
plt.scatter(tau2, coopr2, color=blue, linewidths=2, zorder=100)
plt.scatter(tau_r, coopr_r, color='white', edgecolors=blue, linewidths=2, zorder=101)
ax.set_xlabel('$\\tau_{p}$', family='sans-serif')
ax.set_ylabel('Frequency of Cooperation')
ax.set_xlim(0, 1440)
ax.set_xticks(sp.linspace(0, 1440, 13))
ax.set_ylim(0.5, 1)
plt.tight_layout()
if show:
plt.show()
else:
plt.savefig("graph/tau_p_co_sca_%s.eps" % postfix)
# 皮尔逊相关系数
print("pearson: %f, p-value: %f" % pearsonr(tau2, coopr2))
if __name__ == '__main__': if __name__ == '__main__':
matches = Matches('wos-data-new-3') matches = Matches.from_profile_expr(lambda r: 'SURVIVE' in r)
max_round = 15 max_round = 15
survivals = {} survivals = {}
with open('survivals-3.json', 'r') as f: with open('survivals.json', 'r') as f:
survivals = json.load(f) survivals = json.load(f)
neighbors = {} neighbors = {}
@ -101,65 +168,23 @@ if __name__ == '__main__':
red = '#d63031' red = '#d63031'
# p1折线图 # p1折线图
# fig = plt.figure(figsize=(6.4, 3.6)) # p1(x, coopr, tau, 'survive', False)
# ax = fig.gca()
# ax.plot(x, coopr, color=blue, linewidth=3)
# ax.set_ylim(0.5, 1)
# ax2 = ax.twinx()
# ax2.plot(x, tau, color=red, linewidth=3)
# ax2.set_ylim(0,1440)
# ax.set_xlim(1,14)
# ax.set_xlabel("Rounds")
# ax.set_ylabel("Frequency of Cooperation", color=blue)
# ax.tick_params(axis='y', labelcolor=blue)
# ax2.set_ylabel("$\\tau_{p}$", family='sans-serif', color=red)
# ax2.tick_params(axis='y', labelcolor=red)
# plt.tight_layout() p2(tau[:12], coopr[:12], 720, 'survive', False)
# plt.show()
# # plt.savefig('graph/tau_p_co_plot.eps')
tau2 = []
coopr2 = []
tau_r = []
coopr_r = []
tau3 = []
coopr3 = []
for i in range(len(tau)):
if tau[i] <= 720:
tau2.append(tau[i])
coopr2.append(coopr[i])
if tau[i] - 316 > 0.00001:
tau3.append(tau[i])
coopr3.append(coopr[i])
else: '''
tau_r.append(tau[i]) classic
coopr_r.append(coopr[i]) 残差 [ 0.00317365]
Model parameter: [ -1.24291981e-04 9.70766132e-01]
Other parameters: rank=2, sv=[ 1.41276801 0.06392615], rcond=2.6645352591e-15
error= 0.003174
pearson: -0.607866, p-value: 0.036010
# p2散点图 survive
fig = plt.figure(figsize=(6.4, 3.6)) 残差 [ 0.00548837]
ax = fig.gca() Model parameter: [ -2.71223484e-04 1.00851422e+00]
# ax.set_ylim(0.5, 1) Other parameters: rank=2, sv=[ 1.36321571 0.37635479], rcond=1.99840144433e-15
fp1,residuals,rank,sv,rcond = sp.polyfit(tau2, coopr2, 1, full=True) error= 0.005488
print("残差:",residuals) pearson: -0.829102, p-value: 0.005723
print('Model parameter:',fp1) '''
f1 = sp.poly1d(fp1)
print("error= %f" % error(f1, tau2, coopr2))
# fx = sp.linspace(0,max(tau2),1000)
fx = sp.linspace(0,720,2)
plt.plot(fx,f1(fx),linewidth=2,color=red, ls='--', zorder=0)
plt.scatter(tau2, coopr2, color=blue, linewidths=2, zorder=100)
plt.scatter(tau_r, coopr_r, color='white', edgecolors=blue, linewidths=2, zorder=101)
ax.set_xlabel('$\\tau_{p}$', family='sans-serif')
ax.set_ylabel('Frequency of Cooperation')
ax.set_xlim(0, 1440)
ax.set_xticks(sp.linspace(0, 1440, 13))
ax.set_ylim(0.5, 1)
plt.tight_layout()
plt.show()
# plt.savefig('graph/tau_p_co_sca.eps')
# 皮尔逊相关系数
print("pearson: %f, p-value: %f" % pearsonr(tau2, coopr2))