This commit is contained in:
wJsJwr 2018-06-16 21:37:40 +08:00
parent f0934a0fe8
commit 57368db7a9
20 changed files with 299 additions and 117 deletions

4
.gitignore vendored
View File

@ -1,7 +1,7 @@
.DS_Store
graph
wos-data-new
wos-data-casual
wos-data*
user*
*.svg
__pycache__
.vscode/

View File

@ -4,17 +4,12 @@ from island.match import Match
from island.matches import Matches
import numpy as np
matches = Matches('wos-data-new')
matches = Matches('wos-data-compete')
max_round = 15
total_players = 0
dnc_players = 0
survivals = {}
with open('survivals.json', 'r') as f:
survivals = json.load(f)
for j in range(len(matches.data)):
players = set()
for r in matches.data[j].query('player', 'join').raw_data:

View File

@ -2,18 +2,24 @@
import json
from pathlib import Path
from island.match import Match
from island.matches import Matches
result = 0
count = 0
for file in Path('wos-data-new').iterdir():
p = Path(file)
if p.suffix == '.json':
name = p.stem
if int(name[1:]) >= 254:
m = Match.read_from_json(str(file))
result += len(m.query('player', 'join').select('pid').raw_data)
# ms = Matches.from_profile('CCCN')
ms = Matches.from_profile_expr(lambda r: 'LAB' in r and 'SURVIVE' in r and 'COMM' in r)
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)
count += 1
print(result)
print("avg:", result / count)
# 146 users
# casual: 324
# new(254-354, 全国复杂网络大会): 205
# new-2(375-421, 无交流): 320
# new-3(426-440, 有交流): 203
# new-4(443-472, 经典模式,无交流): 230
# new-5(474-,经典模式,有交流): 159
# total: 1117

50
calc_reward.py Normal file
View File

@ -0,0 +1,50 @@
import json
import csv
from pathlib import Path
from island.match import Match
from island.matches import Matches
result = {}
userdata = {}
with open('user.data', 'r') as c:
for row in csv.reader(c):
userdata[int(row[0])] = {
'uid': row[0],
'name': row[1],
'email': row[2]
}
ms = Matches.from_profile_expr(lambda r: 'LAB' in r and 'CLASSIC' in r)
for m in ms.data:
for r in m.query('user', 'fitness').raw_data:
if r['user'] in result:
result[r['user']]['rewards'] += float(r['fitness']) - 0.0001
result[r['user']]['participate'] += 1
else:
result[r['user']] = {
'rewards': float(r['fitness']) - 0.0001,
'participate': 1
}
ms = Matches.from_profile_expr(lambda r: 'LAB' in r and 'SURVIVE' in r)
for m in ms.data:
for r in m.query('player', 'join').raw_data:
if r['uid'] in result:
result[r['uid']]['rewards'] += 5
result[r['uid']]['participate'] += 1
else:
result[r['uid']] = {
'rewards': 5.0,
'participate': 1
}
for r in m.query('user', 'fitness').raw_data:
result[r['user']]['rewards'] += float(r['fitness']) * 5
total = 0.0
with open('user.reward.csv', 'w') as out:
writer = csv.writer(out)
writer.writerow(['uid', 'name', 'email', 'reward', 'participates'])
for k,v in result.items():
writer.writerow([k, userdata[k]['name'], userdata[k]
['email'], round(v['rewards'], 2), v['participate']])
total += v['rewards']
print("total: %f" % (total))

View File

@ -4,7 +4,7 @@ from island.match import Match
result = {}
for file in Path('wos-data-new').iterdir():
for file in Path('wos-data-compete').iterdir():
p = Path(file)
if p.suffix == '.json':
name = p.stem

View File

@ -8,7 +8,7 @@ from island.matches import Matches
def error(f,x,y):
return sp.sum((f(x)-y)**2)
matches = Matches('wos-data-new')
matches = Matches('wos-data-new-2')
max_round = 17
coopr = []

View File

@ -4,7 +4,7 @@ from island.match import Match
from island.matches import Matches
import numpy as np
matches = Matches('wos-data-new')
matches = Matches('wos-data-new-3')
max_round = 15
coopr = []
@ -37,6 +37,8 @@ for i in range(max_round):
yerr_min.append(coopr[-1] - min(co))
yerr_max.append(max(co) - coopr[-1])
print("%f, %f, %f"%(yerr_min[-1], yerr_max[-1], coopr[-1]))
else:
coopr.append(0)
plt.figure()

View File

@ -6,21 +6,21 @@ from numpy import mean, std
import numpy as np
matches = Matches('wos-data-new')
matches = Matches('wos-data-new-2')
max_round = 15
fig = plt.figure(figsize=(6.4, 3.6))
ax = fig.gca()
index = np.arange(11)
index = np.arange(13)
ax.set_xlabel('k')
ax.set_ylabel('p(k)')
c = ['#00b894','#00cec9','#0984e3','#6c5ce7','#e84393','#d63031','#e17055','#fdcb6e','#2d3436','#6ab04c','#30336b','#ED4C67']
for i in range(len(matches.data)):
k = np.zeros(11)
k = np.zeros(13)
m = matches.data[i]
n = {}
for r in m.query('neighbor', 'create').raw_data:
@ -34,10 +34,12 @@ for i in range(len(matches.data)):
else:
n[r['b']] = [r['a']]
for j in n.keys():
print(n[j], len(n[j]))
k[len(n[j])] += 1
pk = k / np.sum(k)
print(i)
ax.scatter(index, pk, color=c[i])
# ax.scatter(index, pk, color=c[i])
ax.scatter(index, pk)
# ax.set_title('Scores by group and gender')
fig.tight_layout()

View File

@ -351,9 +351,9 @@ def draw_picture(fin,fout):
if __name__ == '__main__':
# for file in Path('wos-data-new').iterdir():
# p = Path(file)
# if p.suffix == '.json':
# name = p.stem
# draw_picture(str(p), str(p.parent.parent / 'graph' / ("%s.eps"%name)))
draw_picture("wos-data-new/G285.json", "graph/G285.eps")
for file in Path('wos-data-compete').iterdir():
p = Path(file)
if p.suffix == '.json':
name = p.stem
draw_picture(str(p), str(p.parent.parent / 'graph' / ("%s.eps"%name)))
# draw_picture("wos-data-new/G285.json", "graph/G285.eps")

View File

@ -4,7 +4,7 @@ from island.match import Match
from island.matches import Matches
import numpy as np
matches = Matches('wos-data-new')
matches = Matches('wos-data-new-2')
max_round = 14
coopr = []
@ -16,7 +16,7 @@ y = np.zeros((5, max_round))
sy = np.zeros(max_round)
survivals = {}
with open('survivals.json', 'r') as f:
with open('survivals-2.json', 'r') as f:
survivals = json.load(f)

View File

@ -1,13 +1,37 @@
from pathlib import Path
from .match import Match
import json
import csv
class Matches:
def __init__(self, logdir):
def __init__(self, source, from_list=False):
self.data = []
self.names = []
for file in Path(logdir).iterdir():
if Path(file).suffix == '.json':
self.data.append(Match.read_from_json(str(file)))
self.names.append(Path(file).stem)
if from_list:
for l in source:
self.data.append(Match.read_from_json(l))
self.names.append(Path(l).stem)
else:
for f in Path(source).iterdir():
if Path(f).suffix == '.json':
self.data.append(Match.read_from_json(str(f)))
self.names.append(Path(f).stem)
@staticmethod
def from_profile(pname, ppos='profile.csv'):
source = []
with open(ppos, 'r', encoding='utf-8') as f:
for row in csv.reader(f):
if pname in row:
source.append(row[0])
return Matches(source, True)
@staticmethod
def from_profile_expr(expr, ppos='profile.csv'):
source = []
with open(ppos, 'r', encoding='utf-8') as f:
for row in csv.reader(f):
if expr(row):
source.append(row[0])
return Matches(source, True)

View File

@ -6,14 +6,14 @@ import numpy as np
from scipy.stats import pearsonr
matches = Matches('wos-data-new')
matches = Matches('wos-data-new-2')
k = np.arange(2, 11)
succ = np.zeros(9)
total = np.zeros(9)
survivals = {}
with open('survivals.json', 'r') as f:
with open('survivals-2.json', 'r') as f:
survivals = json.load(f)
neighbors = {}

View File

@ -6,11 +6,11 @@ from numpy import mean, std
import numpy as np
matches = Matches('wos-data-new')
matches = Matches('wos-data-new-2')
max_round = 15
survivals = {}
with open('survivals.json', 'r') as f:
with open('survivals-2.json', 'r') as f:
survivals = json.load(f)
neighbors = {}
@ -123,5 +123,5 @@ ax.set_xticks(index + bar_width / 2)
ax.set_xticklabels(index+1)
ax.legend()
fig.tight_layout()
# plt.show()
plt.savefig('graph/neigh_per_round.eps')
plt.show()
# plt.savefig('graph/neigh_per_round.eps')

75
profile.csv Normal file
View File

@ -0,0 +1,75 @@
wos-data-compete/G254.json,CCCN,,,COMM,SURVIVE,
wos-data-compete/G272.json,CCCN,,,COMM,SURVIVE,
wos-data-compete/G285.json,CCCN,,,COMM,SURVIVE,
wos-data-compete/G295.json,CCCN,,,COMM,SURVIVE,
wos-data-compete/G299.json,CCCN,,,COMM,SURVIVE,
wos-data-compete/G302.json,CCCN,,,COMM,SURVIVE,
wos-data-compete/G307.json,CCCN,,,COMM,SURVIVE,
wos-data-compete/G318.json,CCCN,,,COMM,SURVIVE,
wos-data-compete/G337.json,CCCN,,,COMM,SURVIVE,
wos-data-compete/G341.json,CCCN,,,COMM,SURVIVE,
wos-data-compete/G349.json,CCCN,,,COMM,SURVIVE,
wos-data-compete/G354.json,CCCN,,,COMM,SURVIVE,
wos-data-compete/G375.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G379.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G380.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G385.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G386.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G389.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G390.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G391.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G392.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G393.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G394.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G395.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G396.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G397.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G398.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G399.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G400.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G402.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G403.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G404.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G405.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G406.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G407.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G408.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G409.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G413.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G420.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G421.json,,LAB,NOCOMM,,SURVIVE,
wos-data-compete/G426.json,,LAB,,COMM,SURVIVE,
wos-data-compete/G427.json,,LAB,,COMM,SURVIVE,
wos-data-compete/G428.json,,LAB,,COMM,SURVIVE,
wos-data-compete/G429.json,,LAB,,COMM,SURVIVE,
wos-data-compete/G430.json,,LAB,,COMM,SURVIVE,
wos-data-compete/G431.json,,LAB,,COMM,SURVIVE,
wos-data-compete/G434.json,,LAB,,COMM,SURVIVE,
wos-data-compete/G435.json,,LAB,,COMM,SURVIVE,
wos-data-compete/G436.json,,LAB,,COMM,SURVIVE,
wos-data-compete/G437.json,,LAB,,COMM,SURVIVE,
wos-data-compete/G439.json,,LAB,,COMM,SURVIVE,
wos-data-compete/G440.json,,LAB,,COMM,SURVIVE,
wos-data-compete/G443.json,,LAB,NOCOMM,,,CLASSIC
wos-data-compete/G447.json,,LAB,NOCOMM,,,CLASSIC
wos-data-compete/G448.json,,LAB,NOCOMM,,,CLASSIC
wos-data-compete/G449.json,,LAB,NOCOMM,,,CLASSIC
wos-data-compete/G450.json,,LAB,NOCOMM,,,CLASSIC
wos-data-compete/G451.json,,LAB,NOCOMM,,,CLASSIC
wos-data-compete/G452.json,,LAB,NOCOMM,,,CLASSIC
wos-data-compete/G467.json,,LAB,NOCOMM,,,CLASSIC
wos-data-compete/G468.json,,LAB,NOCOMM,,,CLASSIC
wos-data-compete/G469.json,,LAB,NOCOMM,,,CLASSIC
wos-data-compete/G470.json,,LAB,NOCOMM,,,CLASSIC
wos-data-compete/G471.json,,LAB,NOCOMM,,,CLASSIC
wos-data-compete/G472.json,,LAB,NOCOMM,,,CLASSIC
wos-data-compete/G474.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G475.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G476.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G477.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G478.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G479.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G480.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G481.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G482.json,,LAB,,COMM,,CLASSIC
wos-data-compete/G483.json,,LAB,,COMM,,CLASSIC
1 wos-data-compete/G254.json CCCN COMM SURVIVE
2 wos-data-compete/G272.json CCCN COMM SURVIVE
3 wos-data-compete/G285.json CCCN COMM SURVIVE
4 wos-data-compete/G295.json CCCN COMM SURVIVE
5 wos-data-compete/G299.json CCCN COMM SURVIVE
6 wos-data-compete/G302.json CCCN COMM SURVIVE
7 wos-data-compete/G307.json CCCN COMM SURVIVE
8 wos-data-compete/G318.json CCCN COMM SURVIVE
9 wos-data-compete/G337.json CCCN COMM SURVIVE
10 wos-data-compete/G341.json CCCN COMM SURVIVE
11 wos-data-compete/G349.json CCCN COMM SURVIVE
12 wos-data-compete/G354.json CCCN COMM SURVIVE
13 wos-data-compete/G375.json LAB NOCOMM SURVIVE
14 wos-data-compete/G379.json LAB NOCOMM SURVIVE
15 wos-data-compete/G380.json LAB NOCOMM SURVIVE
16 wos-data-compete/G385.json LAB NOCOMM SURVIVE
17 wos-data-compete/G386.json LAB NOCOMM SURVIVE
18 wos-data-compete/G389.json LAB NOCOMM SURVIVE
19 wos-data-compete/G390.json LAB NOCOMM SURVIVE
20 wos-data-compete/G391.json LAB NOCOMM SURVIVE
21 wos-data-compete/G392.json LAB NOCOMM SURVIVE
22 wos-data-compete/G393.json LAB NOCOMM SURVIVE
23 wos-data-compete/G394.json LAB NOCOMM SURVIVE
24 wos-data-compete/G395.json LAB NOCOMM SURVIVE
25 wos-data-compete/G396.json LAB NOCOMM SURVIVE
26 wos-data-compete/G397.json LAB NOCOMM SURVIVE
27 wos-data-compete/G398.json LAB NOCOMM SURVIVE
28 wos-data-compete/G399.json LAB NOCOMM SURVIVE
29 wos-data-compete/G400.json LAB NOCOMM SURVIVE
30 wos-data-compete/G402.json LAB NOCOMM SURVIVE
31 wos-data-compete/G403.json LAB NOCOMM SURVIVE
32 wos-data-compete/G404.json LAB NOCOMM SURVIVE
33 wos-data-compete/G405.json LAB NOCOMM SURVIVE
34 wos-data-compete/G406.json LAB NOCOMM SURVIVE
35 wos-data-compete/G407.json LAB NOCOMM SURVIVE
36 wos-data-compete/G408.json LAB NOCOMM SURVIVE
37 wos-data-compete/G409.json LAB NOCOMM SURVIVE
38 wos-data-compete/G413.json LAB NOCOMM SURVIVE
39 wos-data-compete/G420.json LAB NOCOMM SURVIVE
40 wos-data-compete/G421.json LAB NOCOMM SURVIVE
41 wos-data-compete/G426.json LAB COMM SURVIVE
42 wos-data-compete/G427.json LAB COMM SURVIVE
43 wos-data-compete/G428.json LAB COMM SURVIVE
44 wos-data-compete/G429.json LAB COMM SURVIVE
45 wos-data-compete/G430.json LAB COMM SURVIVE
46 wos-data-compete/G431.json LAB COMM SURVIVE
47 wos-data-compete/G434.json LAB COMM SURVIVE
48 wos-data-compete/G435.json LAB COMM SURVIVE
49 wos-data-compete/G436.json LAB COMM SURVIVE
50 wos-data-compete/G437.json LAB COMM SURVIVE
51 wos-data-compete/G439.json LAB COMM SURVIVE
52 wos-data-compete/G440.json LAB COMM SURVIVE
53 wos-data-compete/G443.json LAB NOCOMM CLASSIC
54 wos-data-compete/G447.json LAB NOCOMM CLASSIC
55 wos-data-compete/G448.json LAB NOCOMM CLASSIC
56 wos-data-compete/G449.json LAB NOCOMM CLASSIC
57 wos-data-compete/G450.json LAB NOCOMM CLASSIC
58 wos-data-compete/G451.json LAB NOCOMM CLASSIC
59 wos-data-compete/G452.json LAB NOCOMM CLASSIC
60 wos-data-compete/G467.json LAB NOCOMM CLASSIC
61 wos-data-compete/G468.json LAB NOCOMM CLASSIC
62 wos-data-compete/G469.json LAB NOCOMM CLASSIC
63 wos-data-compete/G470.json LAB NOCOMM CLASSIC
64 wos-data-compete/G471.json LAB NOCOMM CLASSIC
65 wos-data-compete/G472.json LAB NOCOMM CLASSIC
66 wos-data-compete/G474.json LAB COMM CLASSIC
67 wos-data-compete/G475.json LAB COMM CLASSIC
68 wos-data-compete/G476.json LAB COMM CLASSIC
69 wos-data-compete/G477.json LAB COMM CLASSIC
70 wos-data-compete/G478.json LAB COMM CLASSIC
71 wos-data-compete/G479.json LAB COMM CLASSIC
72 wos-data-compete/G480.json LAB COMM CLASSIC
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

View File

@ -6,13 +6,18 @@ from numpy import mean, std
import numpy as np
matches = Matches('wos-data-new')
matches = Matches('wos-data-new-2')
max_round = 14
c_req_succ = np.zeros(max_round-2)
c_req = np.zeros(max_round-2)
d_req_succ = np.zeros(max_round-2)
d_req = np.zeros(max_round-2)
# c_req_succ = np.zeros(max_round-2)
# c_req = np.zeros(max_round-2)
# d_req_succ = np.zeros(max_round-2)
# d_req = np.zeros(max_round-2)
c_req_succ = np.zeros(max_round)
c_req = np.zeros(max_round)
d_req_succ = np.zeros(max_round)
d_req = np.zeros(max_round)
def is_cooperator(rows, pid):
m = 0
@ -39,36 +44,39 @@ for i in range(max_round):
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 is_cooperator(rows, row['a']):
c_req_succ[j] += len(rs)
c_req[j] += len(r)
c_req_succ[i] += len(rs)
c_req[i] += len(r)
else:
d_req_succ[j] += len(rs)
d_req[j] += len(r)
d_req_succ[i] += len(rs)
d_req[i] += len(r)
calced.add(row['a'])
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 is_cooperator(rows, row['b']):
c_req_succ[j] += len(rs)
c_req[j] += len(r)
c_req_succ[i] += len(rs)
c_req[i] += len(r)
else:
d_req_succ[j] += len(rs)
d_req[j] += len(r)
d_req_succ[i] += len(rs)
d_req[i] += len(r)
calced.add(row['b'])
for i in range(len(c_req)):
if c_req[i] == 0:
c_req[i] = 0.1
if d_req[i] == 0:
d_req[i] = 0.1
c_req_succ_fr = c_req_succ / c_req
d_req_succ_fr = d_req_succ / d_req
# print(c_req_succ)
# print(c_req)
# print(c_req_succ_fr)
# print(d_req_succ)
# print(d_req)
# print(d_req_succ_fr)
print(c_req_succ)
print(c_req)
print(c_req_succ_fr)
print(d_req_succ)
print(d_req)
print(d_req_succ_fr)
req_succ_fr_mean = [mean(c_req_succ_fr), mean(d_req_succ_fr)]
req_succ_fr_sem = [std(c_req_succ_fr), std(d_req_succ_fr)]
@ -115,5 +123,5 @@ ax.set_ylabel('Request Approval Rate')
# ax.set_xticklabels(index+2)
# ax.legend()
fig.tight_layout()
# plt.show()
plt.savefig('graph/request_success.eps')
plt.show()
# plt.savefig('graph/request_success.eps')

View File

@ -12,11 +12,11 @@ def error(f,x,y):
if __name__ == '__main__':
matches = Matches('wos-data-new')
matches = Matches('wos-data-new-2')
max_round = 15
survivals = {}
with open('survivals.json', 'r') as f:
with open('survivals-2.json', 'r') as f:
survivals = json.load(f)
neighbors = {}
@ -41,7 +41,7 @@ if __name__ == '__main__':
n[r['b']] = [r['a']]
neighbors[matches.names[i]] = n
for i in range(max_round):
for i in range(max_round-1):
re = []
for j in range(len(matches.data)):
rewire = 0
@ -95,47 +95,47 @@ if __name__ == '__main__':
red = '#d63031'
# p1折线图
# 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)
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)
# plt.tight_layout()
# # plt.show()
plt.tight_layout()
plt.show()
# plt.savefig('graph/tau_p_rewire_plot.eps')
# # 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))
# fx = sp.linspace(0,max(tau2),1000)
fx = sp.linspace(0,1440,2)
# 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))
# # 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.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')
# plt.savefig('graph/tau_p_rewire_sca.eps')

File diff suppressed because one or more lines are too long

14
t.py Normal file

File diff suppressed because one or more lines are too long

View File

@ -12,11 +12,11 @@ def error(f,x,y):
if __name__ == '__main__':
matches = Matches('wos-data-new')
matches = Matches('wos-data-new-3')
max_round = 15
survivals = {}
with open('survivals.json', 'r') as f:
with open('survivals-3.json', 'r') as f:
survivals = json.load(f)
neighbors = {}
@ -42,7 +42,7 @@ if __name__ == '__main__':
n[r['b']] = [r['a']]
neighbors[matches.names[i]] = n
for i in range(max_round):
for i in range(max_round-1):
co = []
for j in range(len(matches.data)):
coop = 0
@ -59,6 +59,8 @@ if __name__ == '__main__':
bx.append(co)
if co:
coopr.append(np.average(co))
else:
coopr.append(0)
for i in range(max_round-1):
@ -114,17 +116,23 @@ if __name__ == '__main__':
# ax2.tick_params(axis='y', labelcolor=red)
# plt.tight_layout()
# # plt.show()
# plt.savefig('graph/tau_p_co_plot.eps')
# 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])
coopr_r.append(coopr[i])
@ -153,7 +161,5 @@ if __name__ == '__main__':
plt.show()
# plt.savefig('graph/tau_p_co_sca.eps')
# 皮尔逊相关系数
print("pearson: %f, p-value: %f" % pearsonr(tau2, coopr2))

View File

@ -5,14 +5,14 @@ from island.matches import Matches
import numpy as np
from scipy.stats import pearsonr
matches = Matches('wos-data-new')
matches = Matches('wos-data-new-2')
k = np.arange(0, 1441, 144)
succ = np.zeros(11)
total = np.zeros(11)
survivals = {}
with open('survivals.json', 'r') as f:
with open('survivals-2.json', 'r') as f:
survivals = json.load(f)
neighbors = {}