sync
This commit is contained in:
parent
3180c88173
commit
8c6591bf27
19
eid_calc.py
19
eid_calc.py
@ -61,6 +61,10 @@ class Eid:
|
|||||||
|
|
||||||
return reduce(lambda x,y: x + max(0,min(y,1440)), trs.values(), 0)
|
return reduce(lambda x,y: x + max(0,min(y,1440)), trs.values(), 0)
|
||||||
|
|
||||||
|
def getTR2(self, m, r, p, s, d):
|
||||||
|
truenb = [i for i in s if i not in d]
|
||||||
|
return reduce(lambda a, b: a + b['tr'], m.query('action', 'done').where(lambda x: x['rno'] == r and ((x['a'] in truenb and x['b'] == p)or(x['b']in truenb and x['a'] == p))).raw_data, 0)
|
||||||
|
|
||||||
def getNeighborhood(self, m, r, p):
|
def getNeighborhood(self, m, r, p):
|
||||||
"""
|
"""
|
||||||
获取该玩家当轮存活邻居
|
获取该玩家当轮存活邻居
|
||||||
@ -86,7 +90,7 @@ class Eid:
|
|||||||
"""
|
"""
|
||||||
victim = []
|
victim = []
|
||||||
ans = 0
|
ans = 0
|
||||||
for d in m.query('action', 'done').where(lambda x: x['rno'] == r and (x['a'] == p or x['b'] == p)).raw_data:
|
for d in m.query('action', 'done').where(lambda x: x['rno'] == r-1 and (x['a'] == p or x['b'] == p)).raw_data:
|
||||||
if d['a'] == p and d['act_a'] == 'D':
|
if d['a'] == p and d['act_a'] == 'D':
|
||||||
victim.append(d['b'])
|
victim.append(d['b'])
|
||||||
ans += d['tr']
|
ans += d['tr']
|
||||||
@ -124,8 +128,9 @@ class Eid:
|
|||||||
ans = {}
|
ans = {}
|
||||||
sigma = 0.0
|
sigma = 0.0
|
||||||
for p in self.survivals[m.name][str(r)]:
|
for p in self.survivals[m.name][str(r)]:
|
||||||
u, v = self.getVictims2(m, r+1, p)
|
u, v = self.getVictims(m, r, p)
|
||||||
e = max(0, min(1440, self.getNeighborTR(m, r, p, self.getNeighborhood(m, r, p), v))) - u
|
if u > 0:
|
||||||
|
e = max(0, min(1440, self.getTR2(m, r, p, self.getNeighborhood(m, r, p), v))) - u
|
||||||
ans[p] = e
|
ans[p] = e
|
||||||
sigma += e
|
sigma += e
|
||||||
return (sigma, ans)
|
return (sigma, ans)
|
||||||
@ -144,6 +149,10 @@ class Eid:
|
|||||||
avgC[r-1] += sigma
|
avgC[r-1] += sigma
|
||||||
cnt[r-1] += len(ans)
|
cnt[r-1] += len(ans)
|
||||||
detail[m.name] = d
|
detail[m.name] = d
|
||||||
|
print(cnt)
|
||||||
|
for i in range(15):
|
||||||
|
if cnt[i] == 0:
|
||||||
|
cnt[i] = 1
|
||||||
avgC /= cnt
|
avgC /= cnt
|
||||||
cnt = np.zeros(15)
|
cnt = np.zeros(15)
|
||||||
for m in self.seasonSurvive.data:
|
for m in self.seasonSurvive.data:
|
||||||
@ -155,6 +164,10 @@ class Eid:
|
|||||||
avgS[r-1] += sigma
|
avgS[r-1] += sigma
|
||||||
cnt[r-1] += len(ans)
|
cnt[r-1] += len(ans)
|
||||||
detail[m.name] = d
|
detail[m.name] = d
|
||||||
|
print(cnt)
|
||||||
|
for i in range(15):
|
||||||
|
if cnt[i] == 0:
|
||||||
|
cnt[i] = 1
|
||||||
avgS /= cnt
|
avgS /= cnt
|
||||||
with open('outputs/EID_CLASSIC.csv', 'w') as f:
|
with open('outputs/EID_CLASSIC.csv', 'w') as f:
|
||||||
csv.writer(f).writerow(avgC)
|
csv.writer(f).writerow(avgC)
|
||||||
|
|||||||
37
eid_plot.py
37
eid_plot.py
@ -3,6 +3,7 @@ from matplotlib import pyplot as plt
|
|||||||
import scipy as sp
|
import scipy as sp
|
||||||
from scipy.stats import pearsonr
|
from scipy.stats import pearsonr
|
||||||
from matplotlib import markers
|
from matplotlib import markers
|
||||||
|
from sys import argv
|
||||||
blue = '#0984e3'
|
blue = '#0984e3'
|
||||||
red = '#d63031'
|
red = '#d63031'
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ def p1(x, coopr, e, postfix, show=True):
|
|||||||
ax.set_ylim(0, 1)
|
ax.set_ylim(0, 1)
|
||||||
ax.set_yticks(sp.linspace(0, 1, 5))
|
ax.set_yticks(sp.linspace(0, 1, 5))
|
||||||
ax2 = ax.twinx()
|
ax2 = ax.twinx()
|
||||||
ax2.plot(x, e, color=red, linewidth=2, label=r"$E_{i,D}$")
|
ax2.plot(x[1:], e[1:], color=red, linewidth=2, label=r"$E_{i,D}$")
|
||||||
# ax2.set_ylim(0, 1440)
|
# ax2.set_ylim(0, 1440)
|
||||||
# ax2.set_yticks(sp.linspace(0, 1440, 5))
|
# ax2.set_yticks(sp.linspace(0, 1440, 5))
|
||||||
ax2.tick_params(labelsize=18)
|
ax2.tick_params(labelsize=18)
|
||||||
@ -33,10 +34,11 @@ def p1(x, coopr, e, postfix, show=True):
|
|||||||
else:
|
else:
|
||||||
plt.savefig("graph/eid_co_plot_%s.eps" % postfix)
|
plt.savefig("graph/eid_co_plot_%s.eps" % postfix)
|
||||||
|
|
||||||
def p2(e, coopr, postfix, show=True):
|
def p2(e, coopr, postfix, show=True, showline=True):
|
||||||
# p2散点图
|
# p2散点图
|
||||||
fig = plt.figure(figsize=(4, 3))
|
fig = plt.figure(figsize=(4, 3))
|
||||||
ax = fig.gca()
|
ax = fig.gca()
|
||||||
|
if showline:
|
||||||
fp1,residuals,rank,sv,rcond = sp.polyfit(e, coopr, 1, full=True)
|
fp1,residuals,rank,sv,rcond = sp.polyfit(e, coopr, 1, full=True)
|
||||||
print("残差:",residuals)
|
print("残差:",residuals)
|
||||||
print('Model parameter:',fp1)
|
print('Model parameter:',fp1)
|
||||||
@ -44,18 +46,16 @@ def p2(e, coopr, postfix, show=True):
|
|||||||
f1 = sp.poly1d(fp1)
|
f1 = sp.poly1d(fp1)
|
||||||
print("error= %f" % error(f1, e, coopr))
|
print("error= %f" % error(f1, e, coopr))
|
||||||
fx = sp.linspace(np.min(e), np.max(e), 2)
|
fx = sp.linspace(np.min(e), np.max(e), 2)
|
||||||
|
|
||||||
plt.plot(fx,f1(fx),linewidth=2,color=red, ls='--', zorder=0)
|
plt.plot(fx,f1(fx),linewidth=2,color=red, ls='--', zorder=0)
|
||||||
|
|
||||||
|
|
||||||
plt.scatter(e, coopr, color='white', edgecolors=blue, linewidths=2, zorder=101)
|
plt.scatter(e, coopr, color='white', edgecolors=blue, linewidths=2, zorder=101)
|
||||||
ax.set_xlabel(r'$E_{i,D}$', family='sans-serif', size=20)
|
ax.set_xlabel(r'$E_{i,D}$', family='sans-serif', size=20)
|
||||||
ax.set_ylabel(r'$f_{c}$', family='sans-serif', size=20)
|
ax.set_ylabel(r'$f_{c}$', family='sans-serif', size=20)
|
||||||
# ax.set_xlim(0, 1440)
|
# ax.set_xlim(0, 1440)
|
||||||
# ax.set_xticks(sp.linspace(0, 1440, 5))
|
# ax.set_xticks(sp.linspace(int(min(e)*0.9), int(max(e)*1.1), 4))
|
||||||
ax.tick_params(labelsize=14)
|
ax.tick_params(labelsize=14)
|
||||||
ax.set_ylim(0.5, 1)
|
ax.set_ylim(0.6, 1)
|
||||||
ax.set_yticks(sp.linspace(0.5, 1, 5))
|
ax.set_yticks(sp.linspace(0.6, 1, 5))
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
if show:
|
if show:
|
||||||
plt.show()
|
plt.show()
|
||||||
@ -65,21 +65,28 @@ def p2(e, coopr, postfix, show=True):
|
|||||||
# 皮尔逊相关系数
|
# 皮尔逊相关系数
|
||||||
print("pearson: %f, p-value: %f" % pearsonr(e, coopr))
|
print("pearson: %f, p-value: %f" % pearsonr(e, coopr))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def p2c(e,c,m,s):
|
||||||
mode = 'CLASSIC'
|
p2(e,c,m,s,False)
|
||||||
mode = 'SURVIVE'
|
|
||||||
|
|
||||||
show = False
|
|
||||||
show = True
|
|
||||||
|
|
||||||
|
def plot(mode, show, isp1):
|
||||||
coopr = np.loadtxt("outputs/CR_%s.csv" % mode, delimiter=',')
|
coopr = np.loadtxt("outputs/CR_%s.csv" % mode, delimiter=',')
|
||||||
x = np.arange(1, 16)
|
x = np.arange(1, 16)
|
||||||
e = np.loadtxt("outputs/EID_%s.csv" % mode, delimiter=',')
|
e = np.loadtxt("outputs/EID_%s.csv" % mode, delimiter=',')
|
||||||
|
|
||||||
|
if isp1:
|
||||||
p1(x, coopr, e, mode, show)
|
p1(x, coopr, e, mode, show)
|
||||||
# p2(e, coopr, mode, show)
|
else:
|
||||||
|
if mode == 'SURVIVE':
|
||||||
|
p2(e[1:12], coopr[1:12], mode, show)
|
||||||
|
else:
|
||||||
|
p2c(e[1:], coopr[1:], mode, show)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# eid_plot c/s 1/2 t/f
|
||||||
|
mode = 'CLASSIC' if argv[1] == 'c' else 'SURVIVE'
|
||||||
|
isp1 = argv[2] == '1'
|
||||||
|
show = argv[3] == 't'
|
||||||
|
plot(mode, show, isp1)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
SURVIVE
|
SURVIVE
|
||||||
|
|||||||
38
fc_plot.py
Normal file
38
fc_plot.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import numpy as np
|
||||||
|
from matplotlib import pyplot as plt
|
||||||
|
import scipy as sp
|
||||||
|
from scipy.stats import pearsonr
|
||||||
|
from matplotlib import markers
|
||||||
|
from sys import argv
|
||||||
|
blue = '#0984e3'
|
||||||
|
red = '#d63031'
|
||||||
|
|
||||||
|
def p1(x, coopr, postfix, show=True):
|
||||||
|
fig = plt.figure(figsize=(4.5, 3))
|
||||||
|
ax = fig.gca()
|
||||||
|
ax.plot(x, coopr, 'o-', color=blue, linewidth=2, label="$f_c$")
|
||||||
|
ax.set_ylim(0, 1)
|
||||||
|
ax.set_yticks(sp.linspace(0, 1, 5))
|
||||||
|
ax.tick_params(labelsize=18)
|
||||||
|
ax.set_xlim(0, 16)
|
||||||
|
ax.set_xlabel("Rounds", size=22)
|
||||||
|
ax.set_ylabel(r"$f_c$", family='sans-serif', size=22)
|
||||||
|
ax.yaxis.grid(True, linestyle='--')
|
||||||
|
|
||||||
|
plt.tight_layout()
|
||||||
|
if show:
|
||||||
|
plt.show()
|
||||||
|
else:
|
||||||
|
plt.savefig("graph/fc_plot_%s.eps" % postfix)
|
||||||
|
|
||||||
|
|
||||||
|
def plot(mode, show):
|
||||||
|
coopr = np.loadtxt("outputs/CR_%s.csv" % mode, delimiter=',')
|
||||||
|
x = np.arange(1, 16)
|
||||||
|
p1(x, coopr, mode, show)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# fc_plot c/s t/f
|
||||||
|
mode = 'CLASSIC' if argv[1] == 'c' else 'SURVIVE'
|
||||||
|
show = argv[2] == 't'
|
||||||
|
plot(mode, show)
|
||||||
@ -1 +1 @@
|
|||||||
180.0,-41.8604651163,-124.186046512,-69.7674418605,-44.6511627907,-164.651162791,-69.7674418605,-92.0930232558,-97.6744186047,-101.860465116,-209.032258065,-213.71024735,-104.939271255,-165.755395683,-649.411764706
|
0.0,-965.647058824,-1052.30769231,-1074.92957746,-944.262295082,-884.571428571,-1140.0,-1143.52941176,-1188.57142857,-1249.41176471,-1047.27272727,-1097.14285714,-1200.0,-1260.0,-1440.0
|
||||||
|
|||||||
|
@ -1 +1 @@
|
|||||||
-58.293956044,-788.740365112,-833.236533958,-1329.43820225,-1278.73417722,-1369.30909091,-1370.60240964,-1343.59832636,-1427.42358079,-1392.89719626,-1440.0,-1440.0,-1390.34482759,-1440.0,-1152.0
|
0.0,-944.835294118,-790.169230769,-551.851851852,-1107.69230769,-1280.0,-960.0,-1440.0,-1440.0,-1440.0,0.0,0.0,0.0,-411.428571429,-1440.0
|
||||||
|
|||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user