diff options
author | Daniel Langesten <daniel.langest@gmail.com> | 2015-03-04 13:53:18 +0100 |
---|---|---|
committer | Daniel Langesten <daniel.langest@gmail.com> | 2015-03-04 13:53:18 +0100 |
commit | 9619f46a96cb0dc35fb0ad495245c8eda5c59115 (patch) | |
tree | 5083ff26e70f07861c4ad6871f5af9711333d45b | |
parent | 88c81cca68b23f02a8a7074093c07d7782373fbf (diff) |
added differential privacy to the algorithm
-rw-r--r-- | cleaner.go | 6 | ||||
-rw-r--r-- | diffpriv.go | 9 |
2 files changed, 10 insertions, 5 deletions
@@ -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)) } |