计算团队获胜的概率



我正在计算A队赢得壁球比赛的概率。两个团队都有3名成员:

A队:拥有能力(r)40、50和70-B队拥有能力(r)75、25和30。

赢得至少两场比赛的球队赢得比赛。如果A队按照上面给出的顺序比赛,B队随机选择一个顺序:

(a) 估计TeamA赢得的概率

(b) 如果一支球队赢了两场比赛,比赛就结束了,那么预期的比赛次数是多少。

我用这个等式计算出A队赢得一轮比赛的概率:(A队获胜的概率)=rA/(rA+rB)

到目前为止,我只是试图计算A队获胜的机会。

import random
def game(a,b,c,d,e,f):
    overallprob = 0
    for item in [a, b, c]:
        probA = item / (item + d)
        overallprob = overallprob + probA
    for item in [a, b, c]:
        probA = item / (item + e)
        overallprob = overallprob + probA
    for item in [a, b, c]:
        probA = item / (item + f)
        overallprob = overallprob + probA
    print "Chances of team A winning =",round((overallprob / 9*100),2),"%"
game(40.0,50.0,60.0,75.0,25.0,30.0)

打印:

Chances of team A winning = 56.04 %

我不确定这是否正确,我想知道是否可以在第(b)部分获得任何帮助,因为我不确定从哪里开始

from itertools import permutations, product
def main():
    teamA = [40, 50, 70]
    teamB = [75, 25, 30]
    # Compute two averages by processing every possible match:
    #   pa   Probability that Team A wins a match.
    #   ng   Expected N of games in a match.
    tot_pa, tot_ng, n = (0, 0, 0)
    for As, Bs in product(permutations(teamA), permutations(teamB)):
        pa, ng = prob_a_wins(As, Bs)
        tot_pa += pa
        tot_ng += ng
        n      += 1
    print tot_pa / n  # 0.61233
    print tot_ng / n  # 2.50580
def prob_a_wins(As, Bs):
    # Probabilities that Team A wins game 1, 2, 3, and the match.
    g1, g2, g3 = [ a / float(a + b) for a, b in zip(As, Bs) ]
    pa = (
        g1       * g2            +  # win g1 and g2
        g1       * (1 - g2) * g3 +  # win g1 and g3
        (1 - g1) * g2       * g3    # win g2 and g3
    )
    # Probabability of a two-game match, and expected N of games.
    two = (
        g1       * g2 +        # win  g1 and g2
        (1 - g1) * (1 - g2)    # lose g1 and g2
    )
    ng  = two * 2  +  (1 - two) * 3
    return (pa, ng)
main()

您计算的是来自a队的随机玩家击败球队随机玩家的几率。

一旦你考虑到球队之间可能的配对,A队击败B队的随机顺序的几率将变为61.23%

from itertools import permutations
def match_win_prob(ra, rb):
    """
    Given the skills of players a and b,
    return the probability of player a beating player b
    """
    return ra / float(ra + rb)
def team_win_prob(x, y, z):
    """
    Given the probability of a win in each match,
    return the probability of being first to two games
    (same as best-of-three)
    """
    return x*y + x*(1.-y)*z + (1.-x)*y*z
def game_win_prob(As, Bs):
    pairs = [[match_win_prob(a, b) for b in Bs] for a in As]
    ways, prob = 0, 0.
    for i,j,k in permutations(pairs):
        ways += 1
        prob += team_win_prob(i[0], j[1], k[2])
    return prob / ways
def main():
    p = game_win_prob([40, 50, 70], [75, 25, 30])
    print('Chances of team A winning = {:.2f} %'.format(p * 100.))
if __name__=="__main__":
    main()

最新更新