Skip to content

Commit

Permalink
Update nd.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bencrts authored Sep 25, 2024
1 parent 1e58f02 commit a36e4e7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions estimator/nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,34 @@ def CenteredBinomial(eta, n=None):
bounds=(-eta, eta),
tag="CenteredBinomial",
)

@staticmethod
def TUniform(b, n=None):
"""
TUniform distribution ∈ ``[-2^b,2^b]``, endpoints inclusive.
This distribution samples the two endpoints with a probability of
1/2^(b+2) and the intermediate points with a probability of
1/2^(b+1).
e.g. TUniform(0) samples -1,1 each with a probability 1/4 and 0
with a probability 1/2.
EXAMPLE::
>>> from estimator.nd import NoiseDistribution as ND
>>> ND.TUniform(0)
>>> ND.Uniform(10)
"""
if b < 0:
raise ValueError("TUniform parameter b needs to be larger than zero")
mean = 0
stddev = sqrt(2**(2*b + 1) / 6)
density = 2**(b+1) / (2**(b+1) + 1)

return NoiseDistribution(
n=n, stddev=stddev, mean=mean, bounds=(-2**b, 2**b), density=density, tag="TUniform"
)

@staticmethod
def Uniform(a, b, n=None):
Expand Down

0 comments on commit a36e4e7

Please sign in to comment.