Details on EBS Code
This is a brief introduction to my implementation of the EBS algorithm. More details are available on
GitHub
.
Implementation
The Python example below samples a random variable from the uniform distribution U(0, 1).
The usage is simple:
- Import the class
- Initialise the EBS class
- Feed samples into EBS until the stopping condition is met
- Return the estimate
This version of EBS uses an absolute accuracy target, which is better suited than a relative accuracy target to random variables with an expectation value close to zero.
Unlike a sampling bound based on Hoeffding's inequality, EBS uses empirical information from the samples to provide tighter bounds in certain cases.
Python · Example usage
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()))
# Example output (values vary between runs):
# Estimated mean: 0.50
# Number of samples taken: 14978