返回题库

抽球问题

Orb Draws

专题
Probability / 概率
难度
L3

题目详情

一个包含 2 个红色和 1 个蓝色球体的瓮就在你面前。在每一步中,无论选择什么颜色,你都会随机均匀地取出一个球体并将其替换为蓝色球体。求出预计需要的抽奖次数,直到瓮中只含有蓝色球体。

An urn containing 2 red and 1 blue orb is in front of you. At each step, you will take out an orb uniformly at random and replace it with a blue orb, regardless of the color selected. Find the expected amount of draws needed until the urn contains only blue orbs.

解析

这个问题有三个状态,只能依次到达。第一个状态是起始状态,或 2R1B(2 红,1 蓝)。从这里开始,如果我们绘制一个蓝色球体,我们就会返回到这种状态。如果我们画一个红色球体,它就会被蓝色替换,然后我们进入第二个状态,1R2B。

此状态表现出类似的行为。如果我们画一个蓝色球体,我们就会回到这种状态。然而,如果我们绘制最后一个红色球体,我们就会以状态 0R3B 退出游戏。

这个问题简化为从状态 1 前进到状态 2 的抽牌次数(我们称为 XX)和从状态 2 前进到退出的抽牌次数(我们称为 YY)的总和。

我们想要求解从状态 1 前进到退出的抽牌总数(我们将称为 ZZ)。我们知道Z=X+YZ = X + Y。我们被要求求解 E(Z)\mathbb{E}(Z),或 E(X)+E(Y)\mathbb{E}(X) + \mathbb{E}(Y) 之和。 XXYY 均遵循不同参数的几何分布。 XGeom(2/3)X \sim Geom(2/3)XGeom(1/3)X \sim Geom(1/3)。这个结论是根据以下事实得出的:对于每个随机变量 X 和 Y,我们正在计算抽奖次数,直到我们观察到第一次成功(在这种情况下,通过抽出红色弹珠来标记成功)。

从这里,我们可以通过取参数 ppE[Geom(p)]=1p\mathbb{E}[Geom(p)] = \frac{1}{p} 的倒数来计算每个几何随机变量的期望。 E(Z)=E(X)+E(Y)E(Z)=E(Geom(23)+E(Geom(13)E(Z)=32+3E(Z)=92\mathbb{E}(Z) = \mathbb{E}(X) + \mathbb{E}(Y) \newline \mathbb{E}(Z) = \mathbb{E}(Geom(\frac{2}{3}) + \mathbb{E}(Geom(\frac{1}{3}) \newline \mathbb{E}(Z) = \frac{3}{2} + 3 \newline \mathbb{E}(Z) = \frac{9}{2}

import random

def simulate_trial():
    urn = [0, 0, 1] # 0 = red, 1 = blue
    count = 0
    while urn != [1, 1, 1]:
        sample = random.choice(urn)
        if sample == 0:
            urn.remove(0)
            urn.append(1)
        count += 1
    
    return count

res = []

for i in range(1_000_000):
    res.append(simulate_trial())

print(sum(res) / 1000000)

Original Explanation

This question has three states which can only be reached successively. The first state is the starting state, or 2R1B (2 red, 1 blue). From here, if we draw a blue orb, we return to this state. If we draw a red orb, it gets replaced with a blue and we advance to the second state, 1R2B.

This state exhibits similar behavior. If we draw a blue orb, we return to this state. However, if we draw the last red orb, we exit the game with state 0R3B.

This problem reduces to the sum of the number of draws to advance from state 1 to state 2 (we'll call XX), and the number of draws to advance from state 2 to exit (we'll call YY).

We want to solve for the total number of draws to advance from state 1 to exit (we'll call ZZ). We know Z=X+YZ = X + Y. We're asked to solve for the E(Z)\mathbb{E}(Z), or the sum E(X)+E(Y)\mathbb{E}(X) + \mathbb{E}(Y). XX and YY each follow the geometric distribution with different parameters. XGeom(2/3)X \sim Geom(2/3) and XGeom(1/3)X \sim Geom(1/3). This conclusion was drawn from the fact that for each random variable X and Y, we are calculating the number of draws until we observe our first success (in this case, a success is marked by drawing a red marble).

From here, we can calculate the expectation of each geometric random variable by taking the inverse of its parameter pp, E[Geom(p)]=1p\mathbb{E}[Geom(p)] = \frac{1}{p}. E(Z)=E(X)+E(Y)E(Z)=E(Geom(23)+E(Geom(13)E(Z)=32+3E(Z)=92\mathbb{E}(Z) = \mathbb{E}(X) + \mathbb{E}(Y) \newline \mathbb{E}(Z) = \mathbb{E}(Geom(\frac{2}{3}) + \mathbb{E}(Geom(\frac{1}{3}) \newline \mathbb{E}(Z) = \frac{3}{2} + 3 \newline \mathbb{E}(Z) = \frac{9}{2}

import random

def simulate_trial():
    urn = [0, 0, 1] # 0 = red, 1 = blue
    count = 0
    while urn != [1, 1, 1]:
        sample = random.choice(urn)
        if sample == 0:
            urn.remove(0)
            urn.append(1)
        count += 1
    
    return count

res = []

for i in range(1_000_000):
    res.append(simulate_trial())

print(sum(res) / 1000000)