Archive for balanced random walk

more [grass]hope

Posted in Books, Kids, pictures, Statistics with tags , , , , on May 16, 2023 by xi'an

Following my earlier post on the terrible performances of ChatGPT for a grasshopping riddle, Bob Carpenter sent me his interaction with GPT4, using the same entry. Here is the outcome he obtained. The answer is correct, but the reasoning is wrong.

GPT4: This is a classic problem of infinite series and expected values in probability theory.

Given the nature of the grasshopper’s random walk, at each jump, it has an equal probability (1/2) of hopping to the left or to the right. Thus, we expect that, on average, it won’t be moving away from the origin (0) because the positive and negative jumps should cancel out.

However, you are asking for the expected absolute distance from the origin, which can’t be negative by definition. The key to solving this problem is to recognize that the expected value of the absolute value of a random variable is not the same as the absolute value of its expected value.

Since the absolute value function is not linear, we cannot pull the expected value inside of it. Instead, we need to directly compute the expected value of the absolute distance from the origin, which is a sum of an infinite series.

The nth jump’s absolute distance is 1/(2^n), and it has a probability of 1/2 to go either left or right. Therefore, the expected absolute distance from the origin after the nth jump is (1/2) * 1/(2^n).

Adding up these expected distances for all jumps gives us the total expected absolute distance from the origin:

E = (1/2) * (1/2 + 1/4 + 1/8 + 1/16 + …)

The sum inside the parentheses is a geometric series with a = 1/2 and r = 1/2. The sum of an infinite geometric series is a / (1 – r), so the sum of this series is (1/2) / (1 – 1/2) = 1.

Therefore, E = (1/2) * 1 = 1/2

So on average, the grasshopper is expected to be 1/2 unit away from the origin after infinitely many jumps. The expected distance it travels to return to the origin is thus 1/2 unit.

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.