From a6acf0e7967acfe3adaed9c7ee90f603ca97eb4b Mon Sep 17 00:00:00 2001 From: Ben <16917183+bencrts@users.noreply.github.com> Date: Wed, 25 Sep 2024 18:22:56 +0100 Subject: [PATCH] Update nd.py --- estimator/nd.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/estimator/nd.py b/estimator/nd.py index c693e17..89f9d5a 100644 --- a/estimator/nd.py +++ b/estimator/nd.py @@ -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): """