Best probability of guessing the coin from one toss

I have two coins $$\phi, \psi$$ whose probability of showing head is $$p(h_1), p(h_2)$$ and probability of showing tail is $$p(t_1),p(t_2)$$. My friend (if any), who has a prior of choosing coin 1 and coin 2 as $$p_\phi, p_\psi$$, will toss a random coin once and tell me the result. What is the best probability that I guess the tossed coin correctly?

One trivial tactic is to always guess the coin with bigger prior, but can we do better?

I am formalizing the problem as follow

• If I observe a tail, then we guess $$\phi, \psi$$ with probability $$e_1$$ and $$1-e_1$$, respectively. If it is head, then we guess $$\phi, \psi$$ with probability $$e$$ and $$1-e$$, respectively
• Probability of success when guessing $$\phi$$ is $$p_s(\phi):=p(\phi)(ep(h_1)+e_1p(t_1))$$. With similar reasoning, $$p_s(\psi):=p(\psi)((1-e)p(h_2)+(1-e_1)p(t_2))$$

By summing them, we have the answer. But when factoring and moving terms around, the probability of success has the form of $$e(const)+e_1(const)$$, which is not an optimization problem anymore. I suspect something is wrong with the way I formalize this

• Assume it comes up heads. Use conditional probability to determine which of the two coins is the one most likely to have been the coin that was tossed. Commented Dec 20, 2023 at 21:49

As you say, the probability of a successful guess is the sum: $$p_s = p(\phi)(ep(h_1)+e_1p(t_1)) + p(\psi)((1-e)p(h_2)+(1-e_1)p(t_2)$$ and we want to choose $$e$$ and $$e_1$$ to maximize this probability. This is just a linear function of $$e$$ and $$e_1$$, so the following derivatives are constant: $$\frac{dp_s}{de} = p(\phi)p(h_1) - p(\psi)p(h_2)$$ and $$\frac{dp_s}{de_1} = p(\phi)p(t_1) - p(\psi)p(t_2)$$
If $$p(\phi)p(h_1) > p(\psi)p(h_2)$$, then $$p_s$$ is an increasing function in $$e$$, so we maximimize $$p_s$$ by taking the maximum possible value of $$e$$, namely $$e=1$$ -- always guess $$\phi$$. Conversely, if $$p(\phi)p(h_1) < p(\psi)p(h_2)$$, then $$p_s$$ is a decreasing function in $$e$$, so our optimal solution is $$e=0$$ -- always guess $$\psi$$. (If $$p(\phi)p(h_1) = p(\psi)p(h_2)$$, then the choice of $$e$$ is irrelevant.)
Similarly, if $$p(\phi)p(t_1) > p(\psi)p(t_2)$$, choose $$e_1=1$$ -- always guess $$\phi$$. If the inequality is reversed, choose $$e_1=0$$ -- always guess $$\psi$$.
Note two special cases. (1) If $$p(\phi)=p(\psi)$$, then you always guess the coin with a bigger "head" probability when you observe a head, and you always guess the coin with a bigger "tail" probability when you observe a tail. (2) If $$p(h_1)=p(h_2)$$ and $$p(t_1)=p(t_2)$$ (so the coins are indistinguishable), then you effectively ignore the result and always choose the coin that your friend was more likely to pick. Other cases fall somewhere in the middle.
Note that this strategy corresponds to calculating the maximum likelihood estimator of the coin. The likelihoods of coins $$\phi$$ and $$\psi$$ given heads are: \begin{align} L(\phi|H) &= p(\phi)p(h_1) \\ L(\psi|H) &= p(\psi)p(h_2) \\ \end{align} so if we see heads, we choose the coin whose likelihood is bigger. Similarly, the likelihoods gives tails are: \begin{align} L(\phi|T) &= p(\phi)p(t_1) \\ L(\psi|T) &= p(\psi)p(t_2) \\ \end{align} and if we see tails, we again choose the coin whose likelihood is bigger.