Gaussian_sampling.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:Lattice-Based-Signatures 作者: krishnacharya 项目源码 文件源码
def Bernoulli_exp(x):
    '''
    Description:
    Algorithm 8 in BLISS paper

    Sample according to exp(-x/f) for x E [0,2^l)
    or x is an integer in binary form of lenght l
    f is a real.

    i/p:
    x: int
    f: float
    '''
    bin_rep = map(int, list(bin(x)[2:])) # list with 0's and 1's reprsenting x. msb is first as usual
    d = len(bin_rep) # length of the current integer in binary, d < l

    # starting from l-1, as then smallest probabilities are checked first and algorithm terminates faster 
    for i in range(0, d):
        if(bin_rep[i]):
            A = Bernoulli_rv(c[d-i-1])
            if not A:
                return 0
    return 1

# uses the same fixed real f
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号