diff options
author | Daniel Langesten <daniel.langest@gmail.com> | 2015-03-11 10:19:00 +0100 |
---|---|---|
committer | Daniel Langesten <daniel.langest@gmail.com> | 2015-03-11 10:19:00 +0100 |
commit | 269c380c745529788a2bd15b159d0aa232b2dc9e (patch) | |
tree | a68dee372e4c10179b65cc6a5597116e30bb113b | |
parent | 8ef903a1e0c01654124eeb38bbf7901e87e815bc (diff) |
avoiding division by zero and negative numbers and som comments describing the function
-rw-r--r-- | diffpriv.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/diffpriv.go b/diffpriv.go index 03f341f..382ef37 100644 --- a/diffpriv.go +++ b/diffpriv.go @@ -10,7 +10,14 @@ var ( rnd = rand.New(rand.NewSource(time.Now().UnixNano())) ) +//Returns 0 if epsilon is less than or equal to 0. +//Otherwise it picks a number from the laplace distribution +//with the mean 0 and standard deviation sensitivity/epsilon. +//This follows the definition of differential privacy noise addition. func diffpriv(value int, sensitivity, epsilon float64) int { + if epsilon <= 0 { + return 0 + } noise := laplaceDist(0, sensitivity/epsilon) return round(float64(value) + noise) } |