by jbandela1 · 3y ago · 0 comments
1. Flip the coin twice
2. If you get the same result both times, goto 1
3. Now that you have different results for your pair of flips, use the first element of the pair of flips as your result.
https://en.wikipedia.org/wiki/Fair_coin#Fair_results_from_a_...
https://www.techiedelight.com/generate-fair-results-biased-c...
The coin is biased to come up TAILS 80% of the time, but using Von Neumann's method in the program I got HEADS 50.035%, TAILS 49.965%.
Probability of two heads: p*p
Probability of two tails: (1-p)*(1-p)
Probability of head followed by tails: p*(1-p)
Probability of tails followed by heads: (1-p)*p
It's not difficult to notice that if you remove the first two, the last two form a 50/50 distribution
I recall conversations on Usenet decades ago about the Monty Hall problem[1] in which people gave elementary proofs that probabilities don't change by opening a door. Even from mathematicians and statisticians. People were very insistent that the analytical solution was simple and obvious and that switching doors didn't change anything.
The only thing that changed some people's minds was a program that simulated the Monty Hall problem. This was needed to get people to reconsider their proof when the claim was highly counterintuitive.
I suppose this is an interesting corollary with discoveries made by deep theoretical mathematics. While something may seem possible because "the math checks out" it could be only theoretically possible as it relies on some unnatural value to "be" possible in the first place.
Testing is where hopeful theories are smashed by reality until all that remains is the verifiable truth. Truly, why wouldn't we test?
Doors: Goat Goat Car
You pick a door. Monty shows you a Goat. You switch or stay.
Monty will never show you the Car before offering a switch. He always shows you a Goat. It doesn't matter which Goat he shows you - it's just "not the Car".
If your first choice is a Goat, switching will win you the Car. If your first choice is a Car, switching will win you a Goat. You have a 2/3 chance of picking a Goat, so, effectively, you want to pick a Goat so that you switch to the Car.
As a young teenager, I encountered the Monty Hall problem for the first time, and I didn't believe that the "analytical" answer was correct. I decided to simulate it by programming. In the 20 minutes it took me to write a simulation, I went from complete incomprehension to a full understanding of why I got the results I got. Programming a simulation of the problem forces you to write out the algorithmic significance of "Monty reveals one of the goats".
I coded it up in F# https://github.com/jackfoxy/LetsMakeADeal to convince one of the founders of a start-up I worked for. He just grunted and walked away. Pretty sure he still doesn't want to hear about Bayes' Theorem.
I think seeing the results of a simulation also elucidates the set up of the math problem vs reading a proof.
A colleague told him about the Two Trains Problem (https://mathworld.wolfram.com/TwoTrainsPuzzle.html), and Von Neumann replied with the correct answer. When his colleague said, "Ah! You figured out he trick!", Von Neumann replied, "What trick? I just summed up the distances in my head!"
Theory is useful but so is experiment.
p(th) = p(t) p(h)
p(ht) = p(h) p(t)
Hence p(th) = p(ht) regardless of coin imbalance as long as both events actually will happen. QED.
Look I found the mathematician
Is this a wrong way to get a right answer?
Very nice way to illustrate why throwing out the duplicate sequences gets back to a 50/50 distribution.
Maybe it's just a meat space thing, but even if the math gives us the answer it still only feels "final" or "true" to me when we've actually tested something out.
So the probability is the same. Whereas p doesn't equal (1-p) unless p=0.5
Why not?
The fact that you can show something with a mathematical equation doesn’t make other demonstrations any less cool.
Because according to the study the person can choose the bias by choosing which side start up.
So if the person wants tails based on what you've said, they should always
1. Do the first throw starting tails up.
2. If the first one is tails, then they now want to start second one heads up.
3. If the first one is heads, they will want to try and get heads again to dismiss the results. So they will do heads up.
So assuming for example that they have an ability to control bias 75% vs 25%.
Then there would be 75% chance of getting first as tails. After that 75% chance of getting heads.
So they will have 56.25% chance of getting it right the first 2 rounds.
The worst case for them would be if they get heads first (25% chance), and then are unable to get heads again. Which would be another 25% chance so 6.25% odds to lose with the first round.
So 56.25% chance of winning the first round of 2, or 6.25% losing and 37.5% of having to try again.
And I think the odds would converge at somewhere around 90% to 10%. I didn't do full calculations here, but overall it seems this strategy would increase the bias even more.
Alice writes on a piece of paper whether to use the result from the first or the second coin, Bob flips the coins however he likes, then once there are two different sides of the coins up, Alice turns over the paper and reveals to Bob which coin contains the result.
Though I guess that unnecessarily complicates the procedure – maybe Alice can just write "heads" or "tails" on a note and then Bob flips without having seen the note. It essentially replaces the second coin with Alice's mind which hopefully doesn't suffer from the same known bias.
° Shake the cup vigorously and dump coins on the table
° If coins match, go back to step one
° If coins are opposed take the result of the southernmost coin
I was still lucky with the numbers as for example with 80% vs 20% it would've been 4x4=16 and so 1 to 16 comes to 100 / 17.
Under the same IID assumption you can take N flips that returned M heads and map them to the N choose M possible ways that could have happened. The result will (under IID assumption, even in the presence of bias) be a uniform number on the range [0..N choose M). The ctz(N choose M) trailing bits can be used directly (as they will be uniform) but the rest would have to be converted to binary via something like an arithmetic coder or rejection sampling.
The result is muuch more efficient.
Less directly, VN debiasers can also be stacked. Each debiaser outputs three streams: the normal one, one that says if the normal one output anything, and one that says if it got HH or TT. Then run VN debiasers on those. Though it takes a fairly large tree to extract most of the entropy.
To get a fair result from a biased dN: Roll it N times. If you don't get all N distinct results, restart. If you do, then the first of those is your final result.
In both cases it has to do with shaping the combination of multiple rolls using some knowledge of outcome-symmetries and overlaps.
____
[0] In this particular case, that's something like: Roll the die twice to get rolls A and B; map those a number X in the range range [1,36] using x=(((A-1)*6)+B); if X<=33 then return (x%11)+1 which will be equally likely in the range [1,11]; if X>33 then start over.
If a coin is more likely to land on the side it starts on, then the bias can change between flips. To fix this, we just need to make sure the coin starts the same side up before every flip.
I find it easier to understand if you say “instead of using the level/value as the source of randomness, use the transition from one level/state to the other as the bit of entropy.” (edge-based instead of level-based) I.E. instead of head is 0 and tails is 1, head to tail is 0 and tails to head is 1, and the other transitions are disregarded.
You're right that the first coin is more likely to end up heads. But so is the second coin, and if both occur, that would invalidate the pair of tosses. Now, imagine you guessed tails despite the coin starting on heads. If the first toss lands tails, the second coin is still more likely to land heads, which keeps the pair valid.
In other words, whatever you gain by guessing the side that's up on the first coin, you lose on account of the second coin having that same higher probability of invalidating the pair.
----
Using extreme numbers, in case that makes it more clear: imagine a coin that has a 99 % probability of ending up with the same side we start with, and – for simplicity of exposition – we always start with heads facing up before the toss.
If you guess heads, and the first coin lands heads, then there is a 1 % chance that you win, namely that when the second coin lands tails.
If you guess tails, and the first coin lands tails, then there is a 99 % chance that you win, namely that when the second coin lands heads.
The two outcomes of the first coin (99 % and 1 % respectively) perfectly balance out the two valid outcomes of the second coin.
1. keep flipping until you get HT (and so you choose 'heads') 2. keep flipping until you get TH (and so you choose 'tails')
Since HT and TH are equally likely, results 1 and 2 are equally likely, i.e. there's a 50% chance of choosing heads, 50% change of choosing tails.
https://www.newton.ac.uk/files/seminar/20100623134014301-152...
[edit]
If you always start with the same side of the coin face-up, then the tosses will be independent of each other, but if you e.g. always flip it once or always keep it the same before the next toss, then they are not.
It would be important to start the flip on the same side, but that’s doesn’t make the second flip dependent on the first
(You might say "of course it is!", but if that's your approach to the problem, you should be aware that biased coins don't exist...)
Otherwise it never halts.
1. starting from heads
2. flip heads
3. flip heads
4. starting from heads
5. flip heads
6. flip tails
take 5 = heads?
heads should still be more likely to occur than tails under this scenario, although, Zeno-like, with decreasing likelihood approaching zero over time?
on edit: of course Von Neumann's process has more restrictions, leading closer to fairness.
Well, yes. The wiki description basically states that you get to throw away results of coin tosses in some particular cases.
In that sense, it's not really any different from just making up the results of the coin tosses entirely. There's 10000 different ways to make your data garbage.