Sampling from exponential Bernoulli

461 Views Asked by At

Bernoulli is a probability distribution. I need to sample from an exponential bernoulli and returns a binary value (i.e. either 0 or 1). I found this algorithm exponential bernoulli sampling and i want to implement it but i do not understand the step 3 of the algorithm where : r1 = r1 & (2^h - 1 ). Could someone give help ?

1

There are 1 best solutions below

3
On

You can use a library which implements sampling from a Bernoulli distribution, e.g., np.random.binomial (as the binomial distribution with n = 1 is the Bernoulli distribution).

import numpy as np
np.random.binomial(n=1, p=.2, size=20)
# output: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0])