|
|
望月漂雪
编个程序模拟一下,首先是确定4强的队伍,假设他们的临场发挥都服从正态分布,A组最强,均值为0.5,B和C组为0.49,D组为0.48,所有队伍的方差为0.1。
程序记录小场胜率和夺冠率。
# 双败赛制模拟
import random
import numpy as np
import matplotlib.pyplot as plt
class Team():
def __init__(self,u,sigma) -> None:
self.u = u
self.sigma = sigma
# 小场胜场数
self.small_win = 0
# 总场数
self.total_count = 0
# 冠军数
self.win = 0
def __str__(self):
return 'u: %.2f, sigma: %.2f, win: %d' % (self.u,self.sigma,self.win)
def get_score(self):
self.score = np.random.normal(self.u,self.sigma)
return self.score
def get_win(team1,team2):
team1.total_count += 1
team2.total_count += 1
if team1.get_score() > team2.get_score():
team1.small_win += 1
return team1,team2
else:
team2.small_win += 1
return team2,team1常规赛制是随机抽取两个队伍比赛,两个胜者通过最后的决赛比出冠军.
# 初始化
A = Team(0.5,0.1)
B = Team(0.49,0.1)
C = Team(0.49,0.1)
D = Team(0.48,0.1)
# 普通赛制
N = 100000
# 初始化比赛次数
count = 0
teams = [A,B,C,D]
while count < N:
# 随机选择比赛顺序
order = np.random.permutation(4)
team1 = teams[order[0]]
team2 = teams[order[1]]
# 获取胜者
team_win1,_ = get_win(team1,team2)
team3 = teams[order[2]]
team4 = teams[order[3]]
# 获取胜者
team_win2,_ = get_win(team3,team4)
# 赢的两组再打一场
team_win,_ = get_win(team_win1,team_win2)
# 赢的队冠军数+1
team_win.win += 1
count += 1
# 输出胜率
print(&#34;常规赛制&#34;)
print(&#39;A组胜率:%.2f%%&#39; % (A.win/N*100))
print(&#39;B组胜率:%.2f%%&#39; % (B.win/N*100))
print(&#39;C组胜率:%.2f%%&#39; % (C.win/N*100))
print(&#39;D组胜率:%.2f%%&#39; % (D.win/N*100))
print(&#39;A组小场胜率:%.2f%%&#39; % (A.small_win/A.total_count*100))
print(&#39;B组小场胜率:%.2f%%&#39; % (B.small_win/B.total_count*100))
print(&#39;C组小场胜率:%.2f%%&#39; % (C.small_win/C.total_count*100))
print(&#39;D组小场胜率:%.2f%%&#39; % (D.small_win/D.total_count*100))
print(&#39;-&#39;*20)在10万次模拟下,得到的结果为
常规赛制
A组胜率:28.58%
B组胜率:24.79%
C组胜率:25.13%
D组胜率:21.50%
A组小场胜率:53.45%
B组小场胜率:49.79%
C组小场胜率:50.16%
D组小场胜率:46.43%<hr/>然后是双败赛制
# 双败赛制
N = 100000
# 初始化比赛次数
count = 0
# 初始化比赛结果
A = Team(0.5,0.1)
B = Team(0.49,0.1)
C = Team(0.49,0.1)
D = Team(0.48,0.1)
teams = [A,B,C,D]
while count < N:
# 随机选择比赛顺序
order = np.random.permutation(4)
team1 = teams[order[0]]
team2 = teams[order[1]]
# 获取上半区胜者
team_win1,team_lose1 = get_win(team1,team2)
team3 = teams[order[2]]
team4 = teams[order[3]]
# 获取下半区胜者
team_win2,team_lose2 = get_win(team3,team4)
# 赢的两组打一场, team_lose获得复活甲
team_win,team_lose = get_win(team_win1,team_win2)
# 输的两组再打一场
team_lose2,_ = get_win(team_lose1,team_lose2)
# 决出败者组冠军
team_lose,_ = get_win(team_lose,team_lose2)
# 败者组冠军与胜者组冠军决战
team_win,_ = get_win(team_win,team_lose)
# 胜者冠军+1
team_win.win += 1
count += 1
# 输出胜率
print(&#34;双败赛制&#34;)
print(&#39;A组胜率:%.2f%%&#39; % (A.win/N*100))
print(&#39;B组胜率:%.2f%%&#39; % (B.win/N*100))
print(&#39;C组胜率:%.2f%%&#39; % (C.win/N*100))
print(&#39;D组胜率:%.2f%%&#39; % (D.win/N*100))
print(&#39;A组小场胜率:%.2f%%&#39; % (A.small_win/A.total_count*100))
print(&#39;B组小场胜率:%.2f%%&#39; % (B.small_win/B.total_count*100))
print(&#39;C组小场胜率:%.2f%%&#39; % (C.small_win/C.total_count*100))
print(&#39;D组小场胜率:%.2f%%&#39; % (D.small_win/D.total_count*100))
print(&#39;-&#39;*20)同样是进行10万次模拟,
双败赛制
A组胜率:29.83%
B组胜率:24.75%
C组胜率:25.01%
D组胜率:20.41%
A组小场胜率:53.72%
B组小场胜率:49.89%
C组小场胜率:50.00%
D组小场胜率:46.25%结果就是影响不大,对实力强的队伍略微有利,但如果我们把方差调大到1
常规赛制
A组胜率:25.49%
B组胜率:24.85%
C组胜率:25.13%
D组胜率:24.52%
A组小场胜率:50.45%
B组小场胜率:49.92%
C组小场胜率:50.07%
D组小场胜率:49.56%
--------------------
双败赛制
A组胜率:29.83%
B组胜率:24.88%
C组胜率:24.71%
D组胜率:20.59%
A组小场胜率:53.76%
B组小场胜率:49.99%
C组小场胜率:49.82%
D组小场胜率:46.30%
--------------------可以看到,在队伍发挥都不稳定的情况下,常规赛制各个队伍直接夺冠的概率都差不多,主要就是看运气,但在双败赛制下,不稳定的因素会被抹除,可以看到最终的结果和方差为0.1时的结果一致。
结论就是,双败赛制对实力强的队伍略微有利,但基本影响不大,主要的作用是缩小方差,减少不稳定因素。 |
|