Details on EBS Code
This is serves as a brief introduction to my implementation of the EBS algorithm, more details can be found on GitHub
.
Below Python code for an examplatory use of EBS is show. We sample our random variables according to a uniform distribution U(0,1) The usage is simple:
- Load the class
- Initialise the EBS class
- Feed samples into EBS till the while loop terminates ↔ EBS finished sampling
- Return the estimate
with an ≈ zero expectation value better.
The main advantage of EBS in comaprison to the commonly used Höffdings inequality comes from the fact that EBS utilises empirical data from the samples and is thus able to provide more thight bounds in certain cases.
import numpy as np
from algorithms import EBS
a = 0
b = 1
delta = 0.1
epsilon = 0.01
ebs = EBS(epsilon=epsilon, delta=delta,range_of_rndvar=b-a)
while ebs.cond_check():
ebs.add_sample(np.random.uniform(a,b))
print("Estimated mean:", ebs.get_estimate())
print("Number of samples taken:", round(ebs.get_num_samples()))
>>> Estimate: 0.50
>>> Number of samples taken: 14978
