def noise(sigma, sum_of_sq, p_exit):
'''
Sample noise from a gussian distribution
the distribution is over +/- sigma, scaled by the noise weight, which is
calculated from the exit probability p_exit, and the overall sum_of_sq
bandwidth
returns a floating-point value between +sigma and -sigma, scaled by
noise_weight
'''
sigma_i = p_exit * sigma / sqrt(sum_of_sq)
# the noise needs to be cryptographically secure, because knowing the RNG
# state could allow an adversary to remove the noise
random_sample = SystemRandom().gauss(0, sigma_i)
return random_sample
评论列表
文章目录