This commit is contained in:
wJsJwr 2018-09-30 15:51:09 +08:00
parent 3180c88173
commit 8c6591bf27
6 changed files with 94 additions and 36 deletions

View File

@ -61,6 +61,10 @@ class Eid:
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):
"""
获取该玩家当轮存活邻居
@ -86,7 +90,7 @@ class Eid:
"""
victim = []
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':
victim.append(d['b'])
ans += d['tr']
@ -124,10 +128,11 @@ class Eid:
ans = {}
sigma = 0.0
for p in self.survivals[m.name][str(r)]:
u, v = self.getVictims2(m, r+1, p)
e = max(0, min(1440, self.getNeighborTR(m, r, p, self.getNeighborhood(m, r, p), v))) - u
ans[p] = e
sigma += e
u, v = self.getVictims(m, r, p)
if u > 0:
e = max(0, min(1440, self.getTR2(m, r, p, self.getNeighborhood(m, r, p), v))) - u
ans[p] = e
sigma += e
return (sigma, ans)
def calc(self):
@ -144,6 +149,10 @@ class Eid:
avgC[r-1] += sigma
cnt[r-1] += len(ans)
detail[m.name] = d
print(cnt)
for i in range(15):
if cnt[i] == 0:
cnt[i] = 1
avgC /= cnt
cnt = np.zeros(15)
for m in self.seasonSurvive.data:
@ -155,6 +164,10 @@ class Eid:
avgS[r-1] += sigma
cnt[r-1] += len(ans)
detail[m.name] = d
print(cnt)
for i in range(15):
if cnt[i] == 0:
cnt[i] = 1
avgS /= cnt
with open('outputs/EID_CLASSIC.csv', 'w') as f:
csv.writer(f).writerow(avgC)
@ -165,4 +178,4 @@ class Eid:
if __name__ == '__main__':
e = Eid()
e.calc()
e.calc()

View File

@ -3,6 +3,7 @@ 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'
@ -15,7 +16,7 @@ def p1(x, coopr, e, postfix, show=True):
ax.set_ylim(0, 1)
ax.set_yticks(sp.linspace(0, 1, 5))
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_yticks(sp.linspace(0, 1440, 5))
ax2.tick_params(labelsize=18)
@ -33,29 +34,28 @@ def p1(x, coopr, e, postfix, show=True):
else:
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散点图
fig = plt.figure(figsize=(4, 3))
ax = fig.gca()
fp1,residuals,rank,sv,rcond = sp.polyfit(e, coopr, 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, e, coopr))
fx = sp.linspace(np.min(e), np.max(e), 2)
plt.plot(fx,f1(fx),linewidth=2,color=red, ls='--', zorder=0)
if showline:
fp1,residuals,rank,sv,rcond = sp.polyfit(e, coopr, 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, e, coopr))
fx = sp.linspace(np.min(e), np.max(e), 2)
plt.plot(fx,f1(fx),linewidth=2,color=red, ls='--', zorder=0)
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_ylabel(r'$f_{c}$', family='sans-serif', size=20)
# 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.set_ylim(0.5, 1)
ax.set_yticks(sp.linspace(0.5, 1, 5))
ax.set_ylim(0.6, 1)
ax.set_yticks(sp.linspace(0.6, 1, 5))
plt.tight_layout()
if show:
plt.show()
@ -65,21 +65,28 @@ def p2(e, coopr, postfix, show=True):
# 皮尔逊相关系数
print("pearson: %f, p-value: %f" % pearsonr(e, coopr))
if __name__ == '__main__':
mode = 'CLASSIC'
mode = 'SURVIVE'
def p2c(e,c,m,s):
p2(e,c,m,s,False)
show = False
show = True
coopr = np.loadtxt("outputs/CR_%s.csv"%mode, delimiter=',')
def plot(mode, show, isp1):
coopr = np.loadtxt("outputs/CR_%s.csv" % mode, delimiter=',')
x = np.arange(1, 16)
e = np.loadtxt("outputs/EID_%s.csv"%mode, delimiter=',')
e = np.loadtxt("outputs/EID_%s.csv" % mode, delimiter=',')
p1(x,coopr, e, mode, show)
# p2(e, coopr, mode, show)
if isp1:
p1(x, coopr, e, 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
@ -96,4 +103,4 @@ Model parameter: [ 3.14661037e-05 7.35284315e-01]
Other parameters: rank=2, sv=[ 1.41231835 0.07319068], rcond=3.33066907388e-15
error= 0.009927
pearson: 0.309326, p-value: 0.261915
"""
"""

38
fc_plot.py Normal file
View 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)

View File

@ -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 180.0 0.0 -41.8604651163 -965.647058824 -124.186046512 -1052.30769231 -69.7674418605 -1074.92957746 -44.6511627907 -944.262295082 -164.651162791 -884.571428571 -69.7674418605 -1140.0 -92.0930232558 -1143.52941176 -97.6744186047 -1188.57142857 -101.860465116 -1249.41176471 -209.032258065 -1047.27272727 -213.71024735 -1097.14285714 -104.939271255 -1200.0 -165.755395683 -1260.0 -649.411764706 -1440.0

View File

@ -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

1 -58.293956044 0.0 -788.740365112 -944.835294118 -833.236533958 -790.169230769 -1329.43820225 -551.851851852 -1278.73417722 -1107.69230769 -1369.30909091 -1280.0 -1370.60240964 -960.0 -1343.59832636 -1440.0 -1427.42358079 -1440.0 -1392.89719626 -1440.0 0.0 0.0 -1390.34482759 0.0 -411.428571429 -1152.0 -1440.0

File diff suppressed because one or more lines are too long