From 9619f46a96cb0dc35fb0ad495245c8eda5c59115 Mon Sep 17 00:00:00 2001 From: Daniel Langesten Date: Wed, 4 Mar 2015 13:53:18 +0100 Subject: added differential privacy to the algorithm --- cleaner.go | 6 ++++++ diffpriv.go | 9 ++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cleaner.go b/cleaner.go index c32abaf..6e8832f 100644 --- a/cleaner.go +++ b/cleaner.go @@ -15,6 +15,7 @@ const ( DATABASE_NAME = "netflow" MAXIMUM_ENTRIES = 100 TIMESPAN = "day" + EPSILON = 1 ) func cleanData() (err error) { @@ -38,6 +39,11 @@ func cleanData() (err error) { return } + //Add noise for differential privacy + for i := range cDat { + cDat[i].occurances = diffpriv(cDat[i].occurances, 1, EPSILON) + } + //Begin transaction tx, err := db.Begin() if err != nil { diff --git a/diffpriv.go b/diffpriv.go index 06aa426..8491156 100644 --- a/diffpriv.go +++ b/diffpriv.go @@ -11,9 +11,8 @@ var ( rnd = rand.New(rand.NewSource(time.Now().UnixNano())) ) -func diffpriv(value, sensitivity, epsilon float64) float64 { +func diffpriv(value int, sensitivity, epsilon float64) int { noise := laplaceDist(0, sensitivity/epsilon) - fmt.Println("noise: ", noise) return round(float64(value) + noise) } @@ -36,9 +35,9 @@ func sgn(x float64) float64 { return 0 } -func round(n float64) float64 { +func round(n float64) int { if n < 0 { - return math.Ceil(n - 0.5) + return int(math.Ceil(n - 0.5)) } - return math.Floor(n + 0.5) + return int(math.Floor(n + 0.5)) } -- cgit v1.1