for paper v1.4

This commit is contained in:
wJsJwr 2018-08-19 23:26:08 +08:00
parent 7b673d11e7
commit c1abe1cab6
11 changed files with 258 additions and 138 deletions

View File

@ -3,7 +3,7 @@ from matplotlib import pyplot as plt
from island.match import Match
from island.matches import Matches
mode = 'CLASSIC'
mode = 'SURVIVE'
matches = Matches.from_profile_expr(lambda r: mode in r)
labels = ['Stay Connected', 'Break Tie']

View File

@ -4,18 +4,23 @@ from matplotlib import pyplot as plt
'''
survive
'''
break_tie = [13.717872086072923, 86.26126126126125]
stay_connected = [86.28212791392707, 13.738738738738737]
'''
classic
break_tie = [8.331150117893634, 42.07858048162231]
stay_connected = [91.66884988210636, 57.9214195183777]
'''
# break_tie = [8.331150117893634, 42.07858048162231]
# stay_connected = [91.66884988210636, 57.9214195183777]
mode = 'SURVIVE'
"""
NEW VERSION
"""
bt_s = [13.717872086072923, 86.26126126126125]
bt_c = [8.331150117893634, 42.07858048162231]
fig = plt.figure(figsize=(3, 3))
fig = plt.figure(figsize=(4, 4))
ax = fig.gca()
index = np.arange(2)
@ -24,21 +29,22 @@ bar_width = 0.35
opacity = 1
error_config = {'ecolor': '0.3'}
rects1 = ax.bar(index, break_tie, bar_width,
alpha=opacity, color='#fdcb6e',
label='Break Tie')
rects1 = ax.bar(index, bt_s, bar_width,
alpha=opacity, color='#d63031',
label='Dissipative')
rects2 = ax.bar(index + bar_width, stay_connected, bar_width,
rects2 = ax.bar(index + bar_width, bt_c, bar_width,
alpha=opacity, color='#00b894',
label='Stay Connected')
label='Classic')
ax.set_ylabel('Frequency of Behavior')
ax.set_title('Behavior after Moves')
ax.set_ylabel('Frequency of Breaking Ties')
# ax.set_title('Behavior after Moves')
ax.set_xticks(index + bar_width / 2)
ax.set_xticklabels(('C', 'D'))
ax.set_xlabel('Previous Move')
ax.set_ylim(0,100)
fig.legend(loc='lower center')
ax.legend(loc='upper left')
fig.tight_layout()
# plt.show()
plt.savefig("graph/break_tie_bar_%s.eps" % (mode))
plt.savefig("graph/break_tie_bar.eps")

View File

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

View File

@ -2,62 +2,127 @@ import json
from matplotlib import pyplot as plt
from island.match import Match
from island.matches import Matches
import numpy as np
from scipy.stats import pearsonr
mode = 'SURVIVE'
matches = Matches.from_profile_expr(lambda r: mode in r)
class Solution:
def __init__(self, mode):
self.mode = mode
self.matches = Matches.from_profile_expr(lambda r: mode in r)
self.survivals = {}
with open('survivals.json', 'r') as f:
self.survivals = json.load(f)
self.neighbors = {}
self.read_neighbor()
self.suff = 0
self.insuff = 0
self.detail_suff = [0]*2
self.detail_insuff = [0]*2
percents = [0.0, 0.0]
def read_neighbor(self):
for i, m in enumerate(self.matches.data):
n = {}
for r in m.query('neighbor', 'create').raw_data:
if r['a'] in n:
n[r['a']].append(r['b'])
else:
n[r['a']] = [r['b']]
op = 'D'
if r['b'] in n:
n[r['b']].append(r['a'])
else:
n[r['b']] = [r['a']]
self.neighbors[self.matches.names[i]] = n
def get_reason(m, i, target):
r = m.query('action', 'request').where(lambda x: x['rno'] == i+1 and x['from'] == target).raw_data
rs = m.query('action', 'approve').where(lambda x: x['rno'] == i+1 and x['to'] == target).raw_data
rsn = [n['from'] for n in rs]
for j in r:
if j['to'] not in rsn:
tr = 1440
for k in m.query('action', 'request').where(lambda x: x['rno'] == i+1 and x['from'] == j['to']).raw_data:
tr -= k['tr']
for k in m.query('action', 'cancel').where(lambda x: x['rno'] == i+1 and x['from'] == j['to']).raw_data:
tr += m.query('action', 'request').where(lambda x: x['rno'] == i+1 and x['from'] == j['to'] and x['to'] == k['to'] and x['log_id'] < k['log_id']).orderby('log_id').raw_data[-1]['tr']
for k in m.query('action', 'deny').where(lambda x: x['rno'] == i+1 and x['to'] == j['to']).raw_data:
tr += m.query('action', 'request').where(lambda x: x['rno'] == i+1 and x['from'] == j['to'] and x['to'] == k['from'] and x['log_id'] < k['log_id']).orderby('log_id').raw_data[-1]['tr']
for k in m.query('action', 'approve').where(lambda x: x['rno'] == i+1 and x['from'] == j['to']).raw_data:
tr -= k['tr']
# print(tr)
if tr >= j['tr']:
percents[1] += 1
else:
percents[0] += 1
def get_reason(self, m, i, target, ttr):
tr = 1440
for k in m.query('action', 'request').where(lambda x: x['rno'] == i and x['from'] == target).raw_data:
tr -= k['tr']
for k in m.query('action', 'cancel').where(lambda x: x['rno'] == i and x['from'] == target).raw_data:
tr += m.query('action', 'request').where(lambda x: x['rno'] == i and x['from'] == target and x['to'] == k['to'] and x['log_id'] < k['log_id']).orderby('log_id').raw_data[-1]['tr']
for k in m.query('action', 'deny').where(lambda x: x['rno'] == i and x['to'] == target).raw_data:
tr += m.query('action', 'request').where(lambda x: x['rno'] == i and x['from'] == target and x['to'] == k['from'] and x['log_id'] < k['log_id']).orderby('log_id').raw_data[-1]['tr']
for k in m.query('action', 'approve').where(lambda x: x['rno'] == i and x['from'] == target).raw_data:
tr -= k['tr']
return tr >= ttr
for m in matches.data:
info = m.query('game', 'created').select('info').first()['info']
conf = json.loads(info['config'])
game_end_at = int(info['game_end_at'])
def new_partner_reason(self):
re_after = [0] * 2 # [c,d]
su_after = [0] * 2
for m in self.matches.data:
info = m.query('game', 'created').select('info').first()['info']
game_end_at = int(info['game_end_at'])
for i in range(1, game_end_at):
calced = set()
for row in m.query('action', 'done').where(lambda x: (x['act_a'] == op or x['act_b'] == op) and x['rno'] == i).raw_data:
if row['act_a'] == op and row['a'] not in calced:
get_reason(m, i, row['a'])
calced.add(row['a'])
if row['act_b'] == op and row['b'] not in calced:
get_reason(m, i, row['b'])
calced.add(row['b'])
for p in m.query('player', 'join').raw_data:
pid = p['pid']
for i in range(2, game_end_at):
previous_round_partner = []
c, t = 0, 0
for r in m.query('action', 'done').where(lambda x: x['rno'] == i - 1 and (x['a'] == pid or x['b'] == pid)).raw_data:
if r['a'] == pid:
previous_round_partner.append(r['b'])
if r['act_a'] == 'C':
c += 1
else:
previous_round_partner.append(r['a'])
if r['act_b'] == 'C':
c += 1
t += 1
is_coop = 0 if c * 2 >= t else 1
print(percents)
_all = sum(percents) / 100
percents[0] /= _all
percents[1] /= _all
new_partner_requester = {}
for r in m.query('action', 'request').where(lambda x: x['rno'] == i and (x['from'] == pid or x['to'] == pid)).raw_data:
if r['from'] == pid:
if r['to'] not in previous_round_partner:
# new_partner_request += 1
new_partner_requester[r['to']] = r['tr']
else:
if r['from'] not in previous_round_partner:
# new_partner_request += 1
new_partner_requester[r['from']] = r['tr']
if not new_partner_requester:
continue
re_after[is_coop] += len(new_partner_requester)
new_partner_succ = 0
new_partner = []
for r in m.query('action', 'done').where(lambda x: x['rno'] == i and (x['a'] == pid or x['b'] == pid)).raw_data:
if r['a'] == pid:
if r['b'] not in previous_round_partner:
new_partner_succ += 1
new_partner.append(r['b'])
else:
if r['a'] not in previous_round_partner:
new_partner_succ += 1
new_partner.append(r['a'])
su_after[is_coop] += new_partner_succ
for npr, ntr in new_partner_requester.items():
if npr not in new_partner:
if self.get_reason(m, i, npr, ntr):
self.suff += 1
self.detail_suff[is_coop] += 1
else:
self.insuff += 1
self.detail_insuff[is_coop] += 1
for i, _ in enumerate(su_after):
print(su_after[i], re_after[i], su_after[i] / re_after[i])
su_after[i] /= re_after[i]
return su_after
labels = ['Insufficient Time Resource', 'Sufficient Time Resource']
plt.figure()
plt.pie(percents, labels=labels, autopct="%1.2f%%", pctdistance=1.1, labeldistance=2,startangle=90, colors=['#00b894', '#fdcb6e'])
plt.legend()
plt.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
# plt.show()
plt.savefig("graph/fail_reason_%s_%s.eps"%(op, mode))
if __name__ == '__main__':
print('CLASSIC')
sc = Solution('CLASSIC')
npc_after = sc.new_partner_reason()
print("reason: ", sc.suff, sc.insuff, sc.insuff / (sc.suff + sc.insuff))
print("reason(c): ", sc.detail_suff[0], sc.detail_insuff[0], sc.detail_insuff[0] / (sc.detail_suff[0] + sc.detail_insuff[0]))
print("reason(d): ", sc.detail_suff[1], sc.detail_insuff[1], sc.detail_insuff[1] / (sc.detail_suff[1] + sc.detail_insuff[1]))
print('SURVIVE')
ss = Solution('SURVIVE')
nps_after = ss.new_partner_reason()
print("reason: ", ss.suff, ss.insuff, ss.insuff / (ss.suff + ss.insuff))
print("reason(c): ", ss.detail_suff[0], ss.detail_insuff[0], ss.detail_insuff[0] / (ss.detail_suff[0] + ss.detail_insuff[0]))
print("reason(d): ", ss.detail_suff[1], ss.detail_insuff[1], ss.detail_insuff[1] / (ss.detail_suff[1] + ss.detail_insuff[1]))

View File

@ -1,7 +1,7 @@
from scipy.stats import chi2_contingency as chi2
import numpy as np
obs = np.array([[203.0, 49.0], [279.0, 78.0]])
obs = np.array([[290.0, 1023.0], [30.0, 321.0]])
chi,p,dof,expected = chi2(obs)
print("%f, %e, %f" % (chi, p, dof))

View File

@ -1,5 +1,6 @@
import json
from matplotlib import pyplot as plt
from matplotlib import patches as pch
from island.match import Match
from island.matches import Matches
import numpy as np
@ -12,6 +13,9 @@ class Solution:
self.matches = Matches.from_profile_expr(lambda r: mode in r)
def food_loss(self):
survivals = {}
with open('survivals.json', 'r') as f:
survivals = json.load(f)
fl = [[],[]]
payoff = {
'C': {
@ -30,46 +34,57 @@ class Solution:
for p in m.query('player', 'join').raw_data:
pid = p['pid']
for i in range(2, game_end_at):
if pid not in survivals[m.name][str(i)]: break
c, t = 0, 0
for r in m.query('action', 'done').where(lambda x: x['rno'] == i - 1 and (x['a'] == pid or x['b'] == pid)).raw_data:
if r['act_a' if r['a'] == pid else 'act_b'] == 'C':
c += 1
t += 1
is_coop = 0 if c * 2 >= t else 1
f = -3.0
f = -3.0 if self.mode == 'SURVIVE' else 0
for r in m.query('action', 'done').where(lambda x: x['rno'] == i and (x['a'] == pid or x['b'] == pid)).raw_data:
if r['a'] == pid:
f += payoff[r['act_a']][r['act_b']] * r['tr'] / 1440.0
else:
f += payoff[r['act_b']][r['act_a']] * r['tr'] / 1440.0
fl[is_coop].append(f)
fl[is_coop].append(-f)
print(len(fl[0]), len(fl[1]))
print(sum(fl[0]) / len(fl[0]), sum(fl[1]) / len(fl[1]))
return fl
if __name__ == '__main__':
mode = 'SURVIVE'
s = Solution(mode)
f = s.food_loss()
sc = Solution('CLASSIC')
fc = sc.food_loss()
ss = Solution('SURVIVE')
fs = ss.food_loss()
blue = '#0984e3'
red = '#d63031'
green = '#00b894'
c = [blue, red]
labels = ['C', 'D']
fig = plt.figure(figsize=(3, 3))
labels = ['Dissipative', 'Classic']
fig = plt.figure(figsize=(8, 6))
ax = fig.gca()
error_config = {'ecolor': '0.3', 'capsize': 4}
bplot = ax.boxplot(f,
vert=True, # vertical box alignment
patch_artist=True, # fill with color
notch=True, # notch shape
labels=labels) # will be used to label x-ticks
index = np.arange(2)
widths = 0.3
for patch, color in zip(bplot['boxes'], c):
patch.set_facecolor(color)
ax.set_ylabel('Frequency')
vp1 = ax.violinplot(fs, positions=index-widths/2, widths=widths, showmeans=True, showmedians=True)
vp2 = ax.violinplot(fc, positions=index+widths/2, widths=widths, showmeans=True, showmedians=True)
hdl1 = pch.Patch(facecolor=vp1['bodies'][0].get_facecolor()[0])
hdl2 = pch.Patch(facecolor=vp2['bodies'][0].get_facecolor()[0])
vp1['cmeans'].set_edgecolor(green)
vp1['cmeans'].set_linestyle(':')
vp2['cmeans'].set_edgecolor(green)
vp2['cmeans'].set_linestyle(':')
ax.set_ylabel('Food Loss')
ax.yaxis.grid(True, linestyle='--')
# ax.set_title('Scores by group and gender')
ax.legend()
ax.set_xticks(index)
ax.set_xticklabels(['C', 'D'])
ax.set_ylim(-6, 4)
ax.set_xlabel("Previous Move")
ax.legend([hdl1, hdl2], labels)
fig.tight_layout()
plt.show()
# plt.savefig("graph/new_partner_bar_%s.eps" % mode)
# plt.show()
plt.savefig("graph/FoodLoss.svg")

View File

@ -10,6 +10,7 @@ class Match:
"""
:param json_string: string represents data in json format
"""
self.name = ''
if dtype == 'json':
self.raw_data = json.loads(raw)
self.dtype = 'json'

View File

@ -11,11 +11,13 @@ class Matches:
if from_list:
for l in source:
self.data.append(Match.read_from_json(l))
self.data[-1].name = Path(l).stem
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.data[-1].name = Path(f).stem
self.names.append(Path(f).stem)
@staticmethod

View File

@ -75,14 +75,16 @@ class Solution:
new_partner_succ += 1
su_after[is_coop] += new_partner_succ
for i, _ in enumerate(su_after):
print(su_after[i], re_after[i], su_after[i] / re_after[i])
su_after[i] /= re_after[i]
return su_after
if __name__ == '__main__':
mode = 'CLASSIC'
s = Solution(mode)
su_after = s.new_partner_after()
sc = Solution('CLASSIC')
npc_after = sc.new_partner_after()
ss = Solution('SURVIVE')
nps_after = ss.new_partner_after()
index = np.arange(2)
blue = '#0984e3'
@ -90,20 +92,23 @@ if __name__ == '__main__':
fig = plt.figure(figsize=(3, 3))
ax = fig.gca()
bar_width = 0.5
bar_width = 0.35
opacity = 1
error_config = {'ecolor': '0.3', 'capsize': 4}
rects1 = ax.bar(index, su_after, bar_width,
color=red, label='New Patner')
rects1 = ax.bar(index, nps_after, bar_width,
color=red, label='Dissipative')
rects2 = ax.bar(index + bar_width, npc_after, bar_width,
alpha=opacity, color='#00b894',
label='Classic')
ax.set_ylabel('Frequency')
# ax.set_title('Scores by group and gender')
ax.set_xticks(index)
ax.set_ylabel('Rate')
# ax.set_title('Rate of Successfully Making New Partner')
ax.set_xlabel('Previous Move')
ax.set_xticks(index + bar_width / 2)
ax.set_xticklabels(['C', 'D'])
ax.set_ylim(0,1)
ax.set_xlim(-0.5,1.5)
ax.legend()
fig.tight_layout()
# plt.show()
plt.savefig("graph/new_partner_bar_%s.eps" % mode)
# plt.savefig("graph/new_partner_bar.eps")

View File

@ -18,7 +18,7 @@ def p1(x, rewires, tau, postfix, show):
ax2 = ax.twinx()
ax2.plot(x, tau, color=red, linewidth=3)
ax2.set_ylim(0, 1440)
ax.set_xlim(1, 14)
ax.set_xlim(2, 15)
ax.set_xlabel("Rounds")
ax.set_ylabel("Rewiring Rate", color=green)
ax.tick_params(axis='y', labelcolor=green)
@ -31,11 +31,31 @@ def p1(x, rewires, tau, postfix, show):
else:
plt.savefig("graph/tau_p_rewire_plot_%s.eps" % postfix)
def p2c(tau, rewires, show):
# # p2散点图
fig = plt.figure(figsize=(4, 3))
ax = fig.gca()
plt.scatter(tau, rewires, color=green, linewidths=2, zorder=100)
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, 7))
ax.set_ylim(0, 0.6)
plt.tight_layout()
if show:
plt.show()
else:
plt.savefig("graph/tau_p_rewire_sca_c.eps")
# 皮尔逊相关系数
print("pearson: %f, p-value: %f" % pearsonr(tau, rewires))
def p2(tau, rewires, postfix, show):
# # p2散点图
fig = plt.figure(figsize=(6.4, 3.6))
fig = plt.figure(figsize=(4, 3))
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)
@ -51,7 +71,7 @@ def p2(tau, rewires, postfix, show):
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_xticks(sp.linspace(0, 1440, 7))
ax.set_ylim(0, 0.6)
plt.tight_layout()
if show:
@ -64,7 +84,7 @@ def p2(tau, rewires, postfix, show):
if __name__ == '__main__':
mode = 'CLASSIC'
mode = 'SURVIVE'
matches = Matches.from_profile_expr(lambda r: mode in r)
max_round = 15
@ -74,7 +94,7 @@ if __name__ == '__main__':
neighbors = {}
rewires = []
x = np.arange(1, max_round)
x = np.arange(2, max_round+1)
mwRe = {} # Match-wise frequency of rewiring
mwTau = {} # Match-wise Tau
tau = []
@ -94,7 +114,7 @@ if __name__ == '__main__':
n[r['b']] = [r['a']]
neighbors[matches.names[i]] = n
for i in range(max_round-1):
for i in range(1, max_round):
re = []
for j in range(len(matches.data)):
rewire = 0
@ -110,7 +130,7 @@ if __name__ == '__main__':
rewires.append(np.average(re))
for i in range(max_round-1):
for i in range(1, max_round):
tp = []
for j in range(len(matches.data)):
if i == 0:
@ -148,8 +168,10 @@ if __name__ == '__main__':
red = '#d63031'
# p1折线图
# p1(x, rewires, tau, mode, False)
p2(tau, rewires, mode, False)
# p1(x, rewires, tau, mode, True)
# p2c(tau, rewires, False)
p2(tau[:12], rewires[:12], mode, False)
'''
classic
@ -157,12 +179,12 @@ classic
Model parameter: [ 9.81549075e-04 -9.87729952e-01]
error= 0.058738
Other parameters: rank=2, sv=[ 1.41291267 0.06064473], rcond=3.10862446895e-15
pearson: 0.823000, p-value: 0.000300
pearson: -0.507660, p-value: 0.063859
survive
残差 [ 0.05788203]
Model parameter: [ 0.00033232 -0.06283898]
error= 0.057882
Other parameters: rank=2, sv=[ 1.3284034 0.48512309], rcond=3.10862446895e-15
pearson: 0.893237, p-value: 0.000017
残差 [ 0.00293523]
Model parameter: [ 0.00016483 -0.02259405]
error= 0.002935
Other parameters: rank=2, sv=[ 1.33437859 0.46843758], rcond=2.6645352591e-15
pearson: 0.947167, p-value: 0.000003
'''

View File

@ -15,20 +15,21 @@ def error(f,x,y):
return sp.sum((f(x)-y)**2)
def p1(x, coopr, tau, postfix, show=True):
fig = plt.figure(figsize=(6.4, 3.6))
fig = plt.figure(figsize=(5, 4))
ax = fig.gca()
ax.plot(x, coopr, color=blue, linewidth=3)
ax.set_ylim(0.5, 1)
ax.plot(x, coopr, color=blue, linewidth=2, label="$f_c$")
ax.set_ylim(0, 1)
ax2 = ax.twinx()
ax2.plot(x, tau, color=red, linewidth=3)
ax2.plot(x, tau, color=red, linewidth=2, label=r"$\tau_p$")
ax2.set_ylim(0, 1440)
ax.set_xlim(1, 14)
ax.set_xlim(1, 15)
ax.set_xlabel("Rounds")
ax.set_ylabel("Frequency of Cooperation", color=blue)
ax.set_ylabel(r"$f_c$", color=blue)
ax.tick_params(axis='y', labelcolor=blue)
ax2.set_ylabel("$\\tau_{p}$", family='sans-serif', color=red)
ax2.set_ylabel(r"$\tau_{p}$", family='sans-serif', color=red)
ax2.tick_params(axis='y', labelcolor=red)
fig.legend()
plt.tight_layout()
if show:
plt.show()
@ -49,7 +50,7 @@ def p2(tau, coopr, limited, postfix, show=True):
coopr_r.append(coopr[i])
# p2散点图
fig = plt.figure(figsize=(6.4, 3.6))
fig = plt.figure(figsize=(4, 3))
ax = fig.gca()
# ax.set_ylim(0.5, 1)
fp1,residuals,rank,sv,rcond = sp.polyfit(tau2, coopr2, 1, full=True)
@ -63,10 +64,10 @@ def p2(tau, coopr, limited, postfix, show=True):
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_xlabel(r'$\tau_{p}$', family='sans-serif')
ax.set_ylabel(r'$f_{c}$', family='sans-serif')
ax.set_xlim(0, 1440)
ax.set_xticks(sp.linspace(0, 1440, 13))
ax.set_xticks(sp.linspace(0, 1440, 7))
ax.set_ylim(0.5, 1)
plt.tight_layout()
if show:
@ -88,7 +89,7 @@ if __name__ == '__main__':
neighbors = {}
coopr = []
x = np.arange(1, max_round)
x = np.arange(1, max_round+1)
mwCo = {} # Match-wise frequency of cooperation
mwTau = {} # Match-wise Tau
bx = []
@ -109,7 +110,7 @@ if __name__ == '__main__':
n[r['b']] = [r['a']]
neighbors[matches.names[i]] = n
for i in range(max_round-1):
for i in range(max_round):
co = []
for j in range(len(matches.data)):
coop = 0
@ -130,7 +131,7 @@ if __name__ == '__main__':
coopr.append(0)
for i in range(max_round-1):
for i in range(max_round):
tp = []
for j in range(len(matches.data)):
if i == 0:
@ -168,18 +169,13 @@ if __name__ == '__main__':
red = '#d63031'
# p1折线图
# p1(x, coopr, tau, 'survive', False)
# p1(x, coopr, tau, 'classic', False)
p2(tau[:12], coopr[:12], 720, 'survive', False)
p2(tau[:12], coopr[:12], 720, 'survive', True)
# p2(tau, coopr, 1440, 'classic', False)
'''
classic
残差 [ 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
survive
残差 [ 0.00548837]
@ -187,4 +183,12 @@ if __name__ == '__main__':
Other parameters: rank=2, sv=[ 1.36321571 0.37635479], rcond=1.99840144433e-15
error= 0.005488
pearson: -0.829102, p-value: 0.005723
classic
残差 [ 0.00489393]
Model parameter: [ -1.38823596e-04 9.82787424e-01]
Other parameters: rank=2, sv=[ 1.41298532 0.05892772], rcond=3.33066907388e-15
error= 0.004894
pearson: -0.582154, p-value: 0.022790
'''