Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-089

Chernoff Bound for Bernoulli

Problem

Chernoff upper bound for the tail of a binomial(n, p) variable:

P(X >= (1 + delta) * n * p) <= (e^delta / (1 + delta)^(1 + delta))^(n * p).

Return 0.0 when delta <= 0 or the inputs are invalid, and 1.0 when n * p is 0.

Hint

The exponent simplifies to delta - (1 + delta) * ln(1 + delta).

Test cases

case 1
in: [10,0.5,1]
expected: 0.14493472568611
case 2
in: [100,0.5,0.1]
expected: 0.7850091625435301
case 3
in: [10,0.5,0]
expected: 0
case 4
in: [0,0.5,1]
expected: 1
Starter codePython
import math


def chernoff_bound_bernoulli(n, p, delta):
    # Your code here
    pass

4 test cases · run your code against them in the editor