From 269c380c745529788a2bd15b159d0aa232b2dc9e Mon Sep 17 00:00:00 2001 From: Daniel Langesten Date: Wed, 11 Mar 2015 10:19:00 +0100 Subject: avoiding division by zero and negative numbers and som comments describing the function --- diffpriv.go | 7 +++++++ 1 file changed, 7 insertions(+) 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) } -- cgit v1.1