Archive for Bernoulli factory

mostly Monte Carlo [13/11]

Posted in Books, Statistics, University life with tags , , , , , , , , , , , , , , , , on November 9, 2026 by xi'an

The next episode of the mostly Monte Carlo seminar is this very Friday! At Paris Santé Campus as usual.

14h30 Simon Costes (Université Paris Cité)

The Wasserstein cost of Importance Sampling

Abstract: Importance sampling (IS) consists in biasing samples from a distribution f towards another distribution g. Concretely, given samples Xi from f, the IS measure is
\[
\hat g^n=\frac1{Z_n}\sum_{i=1}^n \frac{g⁡(X_i)}{f⁡(X_i)}​\delta_{X_i},
\]
with \(Z_n=\sum_i g⁡(X_i)/f⁡(X_i)\). The random measure \(\hat g^n\) approximates g, and is used in many contexts ranging from Monte Carlo integration to Bayesian inference. We show that, in high dimension (d⩾3), the Wasserstein cost \(\cal W_p^p​(g^n,g)\) has order \(n^{−p/d}\) in expectation, i.e.
\[
β_{p,d}^\text{low}\int gf^{−p/d} \le \lim \inf_{n\to\infty}n^{p/d}\mathbb E[\cal W_p^p​(g^n,g)] \le \lim \inf_{n\to\infty}n^{p/d}\mathbb E[\cal W \le \beta{_p,d} \int gf^{−p/d}
\]
where \(β_{p,d}^\text{low},β_{p,d}\) are constants depending only on p and d, which are equal for \(p=2\) and conjectured to be equal for any \(p\ge 1\). Our results are valid for all \(p\ge 1\) and \(d\ge 3\).

In the case where \(β_{p,d}^\text{low}=β_{p,d}\), we show that the asymptotically optimal sampling distribution \(f^\star\) for importance sampling is not equal to g but to a tempered version of g, namely \(f^\star\propto g^{d/(p+d)}\), which is reminiscent of Zador’s theorem in the domain of measure quantization.

15h30 Tyler Farghly (INRIA/ENS)

Metropolis-Adjusted Diffusion Model

Abstract: Sampling from score-based diffusion models incurs bias due to both time discretisation and the approximation of the score function. A common strategy for reducing this bias is to apply corrector steps based on the unadjusted Langevin algorithm (ULA) at each noise level within a predictor-corrector framework. However, ULA is itself a biased sampler, as it discretises a continuous diffusion process. In this work, we consider adjusted Langevin correctors that employ Metropolis–Hastings (MH) or Barker’s accept-reject steps to correct for this bias. Since the target density ratio typically required by MH-based algorithms is unavailable, we propose methods that instead utilise the score function to compute the correct acceptance probability. We introduce the first exact method for adjusting Langevin corrections in diffusion models, based on a two-coin Bernoulli factory algorithm. We also propose an efficient approximation based on Simpson’s rule that achieves accuracy of order 5/2 in the step size at near-zero marginal cost. We demonstrate that these procedures improve sample quality on both synthetic and image datasets, yielding consistent gains in Fréchet Inception Distance (FID) on the latter.

Bernoulli factory on a budget

Posted in Books, Kids with tags , , on May 23, 2023 by xi'an

A form of Bernoulli factory with limited energy from The Riddler: being given the choice of 0<p<1, what is the minimal number n of throws such that the outcomes of n iid B(p) draws can be partitioned into six groups of equal probability? Running a brute force R code [in the train to Cambridge] and checking random partitions for different values of p and n, I found a near fit for n=6 and p around 0.42. With partition weights

0.1658159 0.1669405 0.1657981 0.1662112 0.1682599 0.1669745

while missing the n=5 case for p≈0.3034.

powering a probability [a Bernoulli factory tale]

Posted in Books, R, Statistics with tags , , on April 21, 2023 by xi'an

Starting from an X validated question on finding an unbiased estimator of an integral raised to a non-integer power, I came across a somewhat interesting Bernoulli factory solution! Thanks to Peter Occil’s encyclopedic record of cases, pointing out to Mendo’s (2019) solution for functions of ρ that can be expressed as power series. Like ργ since

(1-[1-\rho])^\gamma=1+\gamma(1-\rho)+\frac{\gamma(\gamma-1)(1-\rho)^2}{2}+\cdots

which rather magically turns into the reported algorithm

Set k=1
Repeat the following process, until it returns a value x:
 1. Generate a Bernoulli B(ϱ) variate z; if z=1, return x=1
 2. Else, with probability γ/k, return x=0
 3. Else, set k=k+1 and return to 1.

since

\rho^\gamma=\rho+(1-\rho)(1-\gamma)\big\{\rho+\frac{(1-\rho)(2-\gamma)}{2}\big[\rho+\cdots

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.

Buffon machines

Posted in Books, pictures, Statistics, University life with tags , , , , , , , , on December 22, 2020 by xi'an

By chance I came across a 2010 paper entitled On Buffon Machines and Numbers by Philippe Flajolet, Maryse Pelletier and Michèle Soria. Which relates to Bernoulli factories, a related riddle, and the recent paper by Luis Mendo I reviewed here. What the authors call a Buffon machine is a device that produces a perfect simulation of a discrete random variable out of a uniform bit generator. Just like (George Louis Leclerc, comte de) Buffon’s needle produces a Bernoulli outcome with success probability π/4. out of a real Uniform over (0,1). Turned into a sequence of Uniform random bits.

“Machines that always halt can only produce Bernoulli distributions whose parameter is a dyadic rational.”

When I first read this sentence it seemed to clash with the earlier riddle, until I realised the later started from a B(p) coin to produce a fair coin, while this paper starts with a fair coin.

The paper hence aims at a version of the Bernoulli factory problem (see Definition 2), although the term is only mentioned at the very end, with the added requirement of simplicity and conciseness translated as a finite expected number of draws and possibly an exponential tail.

It first recalls the (Forsythe–)von Neumann method of generating exponential (and other) variates out of a Uniform generator (see Section IV.2 in Devroye’s generation bible). Expanded into a general algorithm for generating discrete random variables whose pmf’s are related to permutation cardinals,

\mathbb P(N=n)\propto P_n\lambda^n/n!

if the Bernoulli generator has probability λ. These include the Poisson and the logarithmic distributions and as a side product Bernoulli distributions with some logarithmic, exponential and trigonometric transforms of λ.

As a side remark, a Bernoulli generator with probability 1/π is derived from Ramanujan identity

\frac{1}{\pi} = \sum_{n=0}^\infty {2n \choose n}^3 \frac{6n+1}{2^{8n+2}}

as “a discrete analogue of Buffon’s original. In a neat connection with Mendo’s paper, the authors of this 2010 paper note that Euler’s constant does not appear to be achievable by a Buffon machine.