## blind monty hall

Posted in R, Statistics with tags , , , , , , , , on January 10, 2022 by xi'an

As I was waiting for my boat on a French Guiana beach last week, I thought back about a recent riddle from The Riddler where an item does a random walk over a sequence of N integers. Behind doors. The player opens a door at the same rate as the item, door that closes immediately after. What is the fastest strategy to catch the item? With a small value of N, it seemed that repeating the same door twice and moving from 1 to N and backward was eventually uncovering the item.

Here is the cRude code I later wrote to check whether or not this was working:

  p=1+t%%N #starting item position
h=v=s=m=1 #h=door, v=attempt number, s=direction, m=repeat number
while(h-p){
p=ifelse(p==1,2, #no choice
ifelse(p==N,N-1, #no choice
ifelse(p==h-1,p-1, #avoid door
ifelse(p==h+1,p+1, #avoid door
p+sample(c(-1,1),1))))) #random
m=m+1
if(m>2){
h=h+s;m=1
if(h>N){
h=N-1;s=-1}
if(!h){
s=1;h=2}
}
v=v+1


and the outcome for N=100 was a maximum equal to 198. The optimal strategy leads to 196 as repeating the extreme doors is not useful.

## triple ruin

Posted in Books, Kids, pictures, R, Statistics, Wines with tags , , , , , , , , , , on December 28, 2021 by xi'an

An almost straightforward riddle from The Riddler involving a triple gambler’s ruin: Dawn competes against three players Alessandra, Berenike, and Chinue, with probabilities of winning one round ¾, ½, and ¼, respectively, until the cumulated score reaches ±15, ±30, and ±45, for the first, second, and third games. What is Dawn’s optimal sequence of adversaries?

First, a brute force R simulation shows that the optimal ordering is to play the three adversaries first weakest, third strongest and middle fair:

ord=function(p){
z=2*(runif(1)<p[1])-1
while(abs(z)<15)z=z+2*(runif(1)<p[1])-1
y=2*(runif(1)<p[2])-1
while(abs(z+y)<30)y=y+2*(runif(1)<p[2])-1
x=2*(runif(1)<p[3])-1
while(abs(z+y+x)<45)x=x+2*(runif(1)<p[3])-1
return(x+y+z>0)}
mcord=function(p,T=1e2){
for(t in 1:T)F=F+ord(p)
return(F/T)}
comp=function(T=1e2){
return(c(mcord(c(.5,.55,.45),t),
#mcord(c(.5,.45,.55),t),#1-above
mcord(c(.55,.5,.45),t),
#mcord(c(.45,.5,.55),t),#1-above
mcord(c(.55,.45,.5),t)
#mcord(c(.45,.55,.5),t)))#1-above
))}


where I used probabilities closer to ½ to avoid estimated probabilities equal to one.

> comp(1e3)
[1] 0.051 0.038 0.183


(and I eliminated the three other probabilities by sheer symmetry). Second, checking in Feller’s bible (Vol. 1, XIV.3) for the gambler’s ruin probability, a simple comparison of the six orderings confirms this simulation.

## dice and sticks

Posted in Books, Kids, R with tags , , , , , , on November 19, 2021 by xi'an

A quick weekend riddle from the Riddler about the probability of getting a sequence of increasing numbers from dice with an increasing number of faces, eg 4-, 6-, and 8-face dice. Which happens to be 1/4. By sheer calculation (à la Gauss) or simple enumération (à la R):

> for(i in 1:4)for(j in (i+1):6)F=F+(8-j)
> F/4/6/8
[1] 0.25


The less-express riddle is an optimisation problem related with stick breaking: given a stick of length one, propose a fraction a and win (1-a) if a Uniform x is less than one. Since the gain is a(1-a) the maximal average gain is associated with a=½. Now, if the remaining stick (1-a) can be divided when x>a, what is the sequence of fractions one should use when the gain is the length of the remaining stick? With two attempts only, the optimal gain is still ¼. And a simulation experiment with three attempts again returns ¼.

## A discrete Bernoulli factory

Posted in Books, Kids, Statistics with tags , , , , , , on October 18, 2021 by xi'an

A rather confusing (and now closed) question on X validated contained an interesting challenge of simulating an arbitrary discrete distribution using a single (standard) dice. It indeed made me think of the (more challenging) Bernoulli factory problem of simulating B(f(p)) using a B(p) simulator (with p unknown). I still do not see what the optimal solution is but the core challenge is to avoid simulating U(0,1) variate by exploiting the discrete nature of the target. Which may be an issue if the probabilities of the target are irrational and one is considering the cdf inversion approach. An alternative is to use an accept-reject approach, which also works for discrete distributions, by first deriving an instrumental distribution on the discrete support of the target from dice rolls, second finding the maximum of the ratio instrument to target, and third devising a discrete approach to selecting a generation with a probability taking a finite number of values. Which may prove quite costly. Finally, the least debatable approach is to turn the dice into a Uniform generator by using each draw as a digit in the base 5 representation of this Uniform variate, up to the precision desired for the resolution, and then apply the most efficient algorithm for the target distribution.

## top of the top

Posted in Statistics with tags , , , on August 19, 2021 by xi'an

An easy-peasy riddle from The Riddler about the probability that a random variable is the largest among ten iid variates, conditional on the event that this random variable is larger than the upper decile. This writes down easily as

$10\int_{q_{90}}^\infty F^9(x) f(x)\,\text d x$

if F and f are the cdf and pmf, respectively, which is equal to 1-.9¹⁰, approximately 1-e⁻¹, no matter what F is….