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 a6acf0e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions estimator/nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,35 @@ def CenteredBinomial(eta, n=None):
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(f"TUniform parameter 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=(a, b), density=density, tag="TUniform"
)

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

0 comments on commit a6acf0e

Please sign in to comment.