Skip to content

Commit

Permalink
feat(nd): add TUniform distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
bencrts committed Sep 25, 2024
1 parent 1e58f02 commit ae46d75
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions estimator/nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,36 @@ 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)
D(σ=0.58)
>>> ND.Uniform(4)
D(σ=9.24)
"""
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 ae46d75

Please sign in to comment.