4
$\begingroup$

Recently, I thought of the following question: Suppose there are 5 candies in a bag - you choose two candies, and then put these two candies back in the bag (assume each candy has an equal probability of being selected). On average, how many times do you need to choose candies before you are guaranteed to have seen every candy at least once?

In a way, this problem kind of reminds me of the "Coupon Collector Problem" (https://en.wikipedia.org/wiki/Coupon_collector%27s_problem), but I am not sure how to solve this problem using the Coupon Collector framework. I thought of framing this problem as a Markov Chain:

  • State 2 : You have observed 2 unique candies
  • State 3: You have observed 3 unique candies
  • State 4: You have observed 4 unique candies
  • State 5: You have observed 5 unique candies (Absorbing State)

It took me a long time, but I think I was able to create a Transition Matrix for this problem :

 A = matrix(
   c(0.1, 0.6, 0.3, 0, 0,0.3, 0.6, 0.1, 0,0, 0.6, 0.4, 0,0,0, 1), # the data elements
   nrow=4,              # number of rows
   ncol=4,              # number of columns
  byrow = TRUE) 



     [,1] [,2] [,3] [,4]
[1,]  0.1  0.6  0.3  0.0
[2,]  0.0  0.3  0.6  0.1
[3,]  0.0  0.0  0.6  0.4
[4,]  0.0  0.0  0.0  1.0

From here, I suppose I could use the Theory of Markov Chains and find out the expected number of transitions until you reach the Absorbing State - but it was quite difficult to correctly calculate the transition probabilities. I imagine that once the number of states (i.e. "candies") increase, it will become very difficult to calculate all these transition probabilities.

I was hoping for an easier way which would directly allow you to calculate the expected number of draws needed to observe "M" candies (at least once) with "N" draws and each draw of size "K" (e.g. M = 5, K = 2, N = ?) - provided you are given the probability of selecting any given candy (e.g. suppose the candies did not have equal probabilities of being selected).

Can someone please suggest another way of solving this problem?

Thanks!

  • "Food" for Thought: Suppose there were "M" candies" and you draw "K" candies "N" number of times. Suppose this time, you don't know the true value of "M" and you only have information on "K" and "N" - is there a way to estimate "M" based on the data you collect from "K" and "N"?
$\endgroup$
10
  • 2
    $\begingroup$ Your wording is imprecise. No matter how many times you draw 2 candies, you are never guaranteed to see all 5. I think the question you meant to ask is on average how many times will you draw before you see each of the 5 candies at least once. $\endgroup$
    – Moosh
    Jun 15, 2022 at 18:09
  • 3
    $\begingroup$ The only difference from the coupon collector's problem is the multiple draw. If you think about breaking your draws into single ones the difference is that you draw one extra candy if single draws end on an odd number. Making the rough guess that you end on an odd number half the time, the expected number of candies to draw is about $\frac 12$ more when you draw two. This will be very close and be more accurate as the number of candies gets large. If you draw $K$ at a time you add $\frac 12(K-1)$ to the single draw expectation under this approach. $\endgroup$ Jun 15, 2022 at 19:15
  • $\begingroup$ @RossMillikan Being totally ignorant of Markov Chains, this is an embarrassing speculation. See my answer. I suspect that the problem composer intentionally selected the small number $(2)$ as the number of candies to be drawn, so that (per the syntax of my answer), the computations of $E(r)$ would never have more than three terms. Therefore, I suspect that the problem composer wants the problem solver to compute an exact answer. $\endgroup$ Jun 15, 2022 at 21:48
  • $\begingroup$ @RossMillikan On the other hand, it may be that I misunderstood your comment and that your comment is providing a method of computing an exact answer. $\endgroup$ Jun 15, 2022 at 21:50
  • $\begingroup$ No, it does not give an exact answer. There is a slight incorrectness as well. The way you have the problem you are guaranteed that you never draw two of the same candy in one draw. The usual coupon collector can draw the same candy twice in a row. This will decrease the number of draws you need relative to the coupon collector. $\endgroup$ Jun 16, 2022 at 0:19

3 Answers 3

4
$\begingroup$

The transition probabilities come from the Hypergeometric distribution. You have population size $M$, you draw $K$ of these without replacement. When you've seen $i$ candies (that is you're in state $i$), the number of successes (unseen candies) in population is $M-i$ and the probability of observing $k$ new candies is

$$\frac{{M-i\choose k}{i\choose K-k}}{M \choose K}$$

For $M=5$ you get (I include the states 0 and 1)

$$ \displaystyle \frac{1}{\binom{5}{K}} \left(\begin{array}{rrrrrr} \binom{0}{K} & 5 \, \binom{0}{K - 1} & 10 \, \binom{0}{K - 2} & 10 \, \binom{0}{K - 3} & 5 \, \binom{0}{K - 4} & \binom{0}{K - 5} \\ 0 & \binom{1}{K} & 4 \, \binom{1}{K - 1} & 6 \, \binom{1}{K - 2} & 4 \, \binom{1}{K - 3} & \binom{1}{K - 4} \\ 0 & 0 & \binom{2}{K} & 3 \, \binom{2}{K - 1} & 3 \, \binom{2}{K - 2} & \binom{2}{K - 3} \\ 0 & 0 & 0 & \binom{3}{K} & 2 \, \binom{3}{K - 1} & \binom{3}{K - 2} \\ 0 & 0 & 0 & 0 & \binom{4}{K} & \binom{4}{K - 1} \\ 0 & 0 & 0 & 0 & 0 & \binom{5}{K} \end{array}\right) $$

which agrees with your result if you plug in $K=2$:

$$ \displaystyle \left(\begin{array}{rrrrrr} 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & \frac{2}{5} & \frac{3}{5} & 0 & 0 \\ 0 & 0 & \frac{1}{10} & \frac{3}{5} & \frac{3}{10} & 0 \\ 0 & 0 & 0 & \frac{3}{10} & \frac{3}{5} & \frac{1}{10} \\ 0 & 0 & 0 & 0 & \frac{3}{5} & \frac{2}{5} \\ 0 & 0 & 0 & 0 & 0 & 1 \end{array}\right) $$

Here's a Sage-code I used (I keep $K$ as variable, but the formula for the expected value of number of transitions before being absorbed becomes cumbersome, so there I plug in a value for $K$):

#M candies, draw K each time
def getTransitionMatrix(M):
    R.<K> = PolynomialRing(QQ, 1)
    a = [[0]*(M+1) for _ in range(M+1)]
    for i in range(M+1):
        for k in range(M-i+1):
            a[i][i+k] = binomial(M-i, k)*binomial(i, K-k)
    #show(1/binomial(M, K), matrix(a))
    return 1/binomial(M, K) * matrix(a)


def calcE(M, KVal):
    P = getTransitionMatrix(M).subs(K=KVal)
    Q = P[0:M, 0:M] #last one is the absorbing state
    fundMat = (matrix.identity(M)-Q)^(-1)
    #show(fundMat)
    return sum(fundMat[0])

    
print (calcE(5, 2))

#P = getTransitionMatrix(5)
#show(P.subs(K=2))
$\endgroup$
1
  • $\begingroup$ I really like your answer! Very clever use of the hypergeometric distribution! $\endgroup$
    – stats_noob
    Jun 16, 2022 at 15:09
3
$\begingroup$

This response assumes that the problem to be solved is the expected number of draws before each of the $(5)$ candies is seen at least once.

Alternative approach, that would be forced on me, if I had to attack the problem. This is because I am totally ignorant of Markov chains.

I will capitalize on the fact that $5$ is such a small number, and that the number of candies viewed each time is only one more than $(1)$. Therefore, it is not that onerous to re-invent the wheel and employ the same ideas that (I would speculate) provide the foundation of Markov Chains.

However, I must admit that I am probably destroying the educational value that the problem composer intended, by this answer. On the other hand, you may still be able to use the following analysis as a guide to walking down the actual path intended by the problem composer.


For $~r \in \{1,2,3\}$, let $E(r)$ denote the expected number of additional draws needed, under the assumption that there are still $r$ candies unseen.

Let $T$ denote the expected total number of draws.

After $1$ draw, you are guaranteed that exactly $3$ of the $5$ candies are still unseen. Therefore, the desired overall computation is:

$$T = 1 + E(3). $$

I will work backwards, first computing $E(1)$, then computing $E(2)$, and then computing $E(3)$.


Assume that $(4)$ of the candies have been seen, and that $(1)$ candy has been unseen.

On the next draw, the probability that the unseen candy will be seen is $~\displaystyle \frac{2}{5}$.

Therefore,

$$E(1) = \left\{1 \times \frac{2}{5}\right\} + \left\{\left[1 + E(1)\right] \times \frac{3}{5}\right\} = 1 + \left[E(1) \times \frac{3}{5}\right] \implies $$

$$\frac{2}{5} \times E(1) = 1 \implies E(1) = \frac{5}{2}.$$


If $(2)$ candies are unseen, then, the probabilities are:

  • Next draw sees both unseen candies : $~\displaystyle \frac{\binom{2}{2}}{\binom{5}{2}} = \frac{1}{10}.$

  • Next draw sees neither unseen candies : $~\displaystyle \frac{\binom{3}{2}}{\binom{5}{2}} = \frac{3}{10}.$

  • Next draw sees exactly $(1)$ of the unseen candies : $~\displaystyle 1 - \left[\frac{1}{10} + \frac{3}{10}\right] = \frac{3}{5}.$

Therefore,

$$E(2) = \left\{1 \times \frac{1}{10}\right\} + \left\{\left[1 + E(1)\right] \times \frac{3}{5}\right\} + \left\{\left[1 + E(2)\right] \times \frac{3}{10}\right\}$$

$$= 1 + \left\{\frac{5}{2} \times \frac{3}{5}\right\} + \left\{E(2) \times \frac{3}{10}\right\}\implies $$

$$\frac{7}{10} \times E(2) = 1 + \frac{3}{2} = \frac{5}{2} \implies $$

$$E(2) = \frac{10}{7} \times \frac{5}{2} = \frac{25}{7}.$$


The computation for $E(3)$ will parallel the computation for $E(2).$

If $(3)$ candies are unseen, then, the probabilities are:

  • Next draw sees two of the unseen candies : $~\displaystyle \frac{\binom{3}{2}}{\binom{5}{2}} = \frac{3}{10}.$

  • Next draw sees none of the unseen candies : $~\displaystyle \frac{\binom{2}{2}}{\binom{5}{2}} = \frac{1}{10}.$

  • Next draw sees exactly $(1)$ of the unseen candies : $~\displaystyle 1 - \left[\frac{1}{10} + \frac{3}{10}\right] = \frac{3}{5}.$

Therefore,

$$E(3) = \left\{\left[1 + E(1)\right] \times \frac{3}{10}\right\} + \left\{\left[1 + E(2)\right] \times \frac{3}{5}\right\} + \left\{\left[1 + E(3)\right] \times \frac{1}{10}\right\}$$

$$= 1 + \left\{\frac{5}{2} \times \frac{3}{10}\right\} + \left\{\frac{25}{7} \times \frac{3}{5}\right\} + \left\{E(3) \times \frac{1}{10}\right\}\implies $$

$$\frac{9}{10} \times E(3) = 1 + \frac{3}{4} + \frac{15}{7} = \frac{109}{28} \implies $$

$$E(3) = \frac{10}{9} \times \frac{109}{28} = \frac{545}{126}.$$

Therefore,

$$T = 1 + E(3) = 1 + \frac{545}{126} = \frac{671}{126}.$$

$\endgroup$
1
  • $\begingroup$ great answer! ! $\endgroup$
    – stats_noob
    Mar 20, 2023 at 0:43
1
$\begingroup$

The general case of $M$ candies drawn in equiprobable groups of $K$ is solved at Expected number of times a set of 10 integers (selected from 1-100) is selected before all 100 are seen. The expected number of required draws is

$$ \sum_{j=1}^M(-1)^{j-1}\binom Mj\frac1{1-\frac{\binom{M-j}K}{\binom MK}}\;. $$

For $M=5$, $K=2$, this is

\begin{eqnarray} &&\sum_{j=1}^5(-1)^{j-1}\binom 5j\frac1{1-\frac{\binom{5-j}2}{\binom 52}} \\&=& 5\cdot\frac1{1-\frac{\binom42}{\binom52}}-10\cdot\frac1{1-\frac{\binom32}{\binom52}}+10\cdot\frac1{1-\frac{\binom22}{\binom52}}-5\cdot\frac1{1-\frac{\binom12}{\binom52}}+1\cdot\frac1{1-\frac{\binom02}{\binom52}} \\ &=& 10\left(\frac5{10-6}-\frac{10}{10-3}+\frac{10}{10-1}-\frac5{10-0}+\frac1{10-0}\right) \\ &=& \frac{671}{126}\;, \end{eqnarray}

in agreement with the existing two answers.

As far as I can tell, the case of unequal probabilities isn’t well-defined in your question. You write that “you are given the probability of selecting any given candy”, but that doesn’t define a unique distribution over the tuples of candies being selected: There are $\binom MK$ different probabilities $p_t$ for the tuples $t$ and only $M$ probabilities for selecting any given candy, and I don’t see a canonical resolution of this ambiguity that you might have intended to imply.

If you’re instead given the probabilities $p_t$ of selecting the tuples, then by inclusion–exclusion the expected number of draws required is

$$ \sum_{\emptyset\ne S\subset C}(-1)^{|S|-1}\frac1{\sum_{t\cap S\ne\emptyset}p_t}\;, $$

where the outer sum runs over all subsets $S$ of the set $C$ of candies and the sum in the denominator runs over all tuples $t$ that intersect $S$. In the equiprobable case, $p_t=\binom MK^{-1}$, there are $\binom Mj$ subsets of size $j$, and for each subset of size $j$ there are $\binom MK-\binom{M-j}K$ tuples that intersect it, so we recover the result above.

As regards your additional “food for thought” question, I take it that you mean the following scenario: There is an unknown number $M$ of candies in a bag. You make $N$ draws of $K$ candies each, where $N$ is predetermined and doesn’t depend on the results of the draws. I assume that you can distinguish the candies, so “the data you collect” is the identity of the candies drawn in each draw.

In order to estimate $M$ from these results, you need to assume a prior for $M$. If you don’t know anything about $M$, a reasonable choice might be an improper uniform prior over $\mathbb N$ (improper because it can’t be normalized, so it’s not a probability distribution).

Another point to note is that given the number $D$ of different candies observed, the details of which of these candies you observed in which draw contain no additional information about $M$; that is, $D$ is a sufficient statistic for $M$.

The case $K=1$ of individual draws is treated in the Magic 8 Ball Problem. The results are quite interesting. The improper uniform prior leads to a normalizable posterior probability distribution for $M$ only if $D\le N-2$, that is, if at least two draws give you a candy that you’d seen before; and the expected value of $M$ under this posterior distribution is finite only if $D\le N-3$. To generalize this to $K\gt1$, let’s look at what changes in that analysis. (I’m referring to the above post but using your variables to keep the notation in this post consistent.) For $K=1$, the probability that $N$ draws yield $D$ distinct candies was

$$ \frac{D!}{M^N}\binom MD\left\{N\atop D\right\}\;, $$

where $\left\{N\atop D\right\}$ is a Stirling number of the second kind that counts the partitions of a set of $N$ elements into $D$ non-empty subsets, so $D!\left\{N\atop D\right\}$ counts the ways to distribute $N$ elements into $D$ distinguishable non-empty bins. For $K\gt1$, the corresponding probability contains a corresponding count of the ways to distribute $K$-tuples of balls into distinguishable non-empty bins (with each $K$-tuple going into $K$ different bins). But this count cancelled out in the analysis because it didn’t depend on $M$, and the same happens for $K\gt1$, so we don’t have to worry about actually counting these configurations; all we need is the $M$ dependence of the probability. For that, we still get the factor $\binom MD$ for the number of ways to choose the $D$ distinct candies out of the $M$ in the bag, and instead of the probability $M^{-N}$ of drawing a particular sequence of candies, we now get the probability $\binom MK^{-N}$ of drawing a particular sequence of $K$-tuples of candies. Thus, the posterior distribution of $M$ given $D$ (assuming the uniform prior) is

$$ P(M=m\mid D=d)=\frac{\binom mK^{-N}\binom md}{\sum_{m=d}^\infty\binom mK^{-N}\binom md}\;. $$

We get an analogous phenomenon as for $K=1$: the series for the normalization constant in the denominator only converges if $D\le NK-2$ (that is, if we see at least two fewer candies than we maximally could have in $N$ $K$-tuples), and the expected value

$$ E(M\mid D=d)=\frac{\sum_{m=d}^\infty m\binom mK^{-N}\binom md}{\sum_{m=d}^\infty\binom mK^{-N}\binom md} $$

is only finite if $D\le NK-3$. As in the $K=1$ case, you might want to use the mode rather than the expected value to estimate $M$.

Note that (as one might have expected) for small $K$ the result isn’t all that different than if you’d drawn $NK$ candies one by one. For instance, in your example $K=2$, we’ve merely replaced $m^2$ by $m(m-1)$. (The factor $\frac12$ cancels.) Still, for small numbers of candies, it makes a slight difference. For example, if you draw $6$ candies individually and only see $2$ different ones, the expected value of $M$ is

\begin{eqnarray} E(M\mid D=2) &=& \frac{\sum_{m=2}^\infty m\cdot m^{-6}\binom m2}{\sum_{m=2}^\infty m^{-6}\binom m2} \\ &=& \frac{90\zeta(3)-\pi^4}{\pi^4-90\zeta(5)} \\ &\approx& 2.64\;, \end{eqnarray}

with a probability of

\begin{eqnarray} P(M=2\mid D=2) &=& \frac{2^{-6}}{\sum_{m=2}^\infty m^{-6}\binom m2} \\ &=& \frac{45}{16\left(\pi^4-90\zeta(5)\right)} \\ &\approx& 69\% \end{eqnarray}

concentrated at $M=2$, whereas if you only see $2$ different candies in drawing $3$ pairs, it’s

\begin{eqnarray} E(M\mid D=2) &=& \frac{\sum_{m=2}^\infty m\binom m2^{-3}\binom m2}{\sum_{m=2}^\infty\binom m2^{-3}\binom m2} \\ &=& \frac{\sum_{m=2}^\infty m\binom m2^{-2}}{\sum_{m=2}^\infty\binom m2^{-2}} \\ &=& \frac12\cdot\frac{\pi^2-6}{\pi^2-9} \\ &\approx& 2.22\;, \end{eqnarray}

with a probability of

\begin{eqnarray} P(M=2\mid D=2) &=& \frac1{\sum_{m=2}^\infty\binom m2^{-3}\binom m2} \\ &=& \frac3{4\left(\pi^2-9\right)} \\ &\approx& 86\% \end{eqnarray}

concentrated at $M=2$, so you’re considerably more confident that there are actually just those two candies in the bag.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .