A probability game
Assume that two positive numbers are given,
A player draws randomly one of the numbers and has to guess if the
number is smaller or larger than the other unrevealed number, i.e.,
let
A random guess (coin-flip) would due to the sampling
Assume we can sample
Applying
which under the given assumptions is strictly larger than
Example in python
import sys
import numpy as np
import scipy.linalg as linalg
from scipy.stats import norm, bernoulli, uniform
if sys.version_info.major < 3 or sys.version_info.minor<6:
raise Exception("Must be using Python >= 3.6")
def rexp(n: int): return np.exp(-uniform.rvs(size=n))
class game:
"""Simulation of simple probability game"""
def __init__(self,
n: int,
gen=lambda n: -np.log(uniform.rvs(size=n)),
rho=.5):
R = np.matrix([[1, rho], [rho, 1]]);
L = linalg.cholesky(R)
xy = np.matrix(np.resize(norm.rvs(size=2*n), (n,2)))*L
self.u = bernoulli.rvs(0.5, size=n)
self.w = np.array(xy[range(len(xy)), self.u])
self.z = np.array(xy[range(len(xy)), 1-self.u])
self.x = np.array(xy[:,[0]])
self.y = np.array(xy[:,[1]])
self.g = gen(n)
self.guess = self.w>self.g
self.true = self.w>self.z
n = int(1e5)
sim = game(n)
print(np.mean(sim.true==sim.guess))
0.60851
Example in R
sim <- function(n, delta=0, ...) {
xy <- exp(mets::rmvn(n, ...)) + delta
u <- rbinom(n, 1, 0.5)
w <- xy[cbind(seq(n), u+1)]
z <- xy[cbind(seq(n), 2-u)]
wmax <- w>z
cbind(w=w, z=z, wmax=wmax, x=xy[,1], y=xy[,2])
}
n <- 1e5
val <- sim(n=n, rho=0.5)
z0 <- rexp(n, 1)
guess <- val[, "w"]>z0
mean(guess==val[, "wmax"])
[1] 0.6037
val <- sim(n=1e5, rho=0.5, mu=c(-3,3))
z0 <- rexp(n, 1)
guess <- val[, "w"]>z0
mean(guess==val[, "wmax"])
[1] 0.96077
val <- sim(n=1e5, rho=0.5, mu=c(10,10))
z0 <- rexp(n, 1)
guess <- val[, "w"]>z0
mean(guess==val[, "wmax"])
[1] 0.49956