Godiffpriv is a golang module for help to work differential privacy in golang projects. The module has support to queries with numeric and symbolic values. Besides, we apply the probability Laplace distribution to generate a random numbers.
- Numeric data should be float64 array
- Symbolic data should be string array
go get github.com/eriksonJAguiar/godiffpriv
import "github.com/eriksonJAguiar/godiffpriv"
- For symbolic data:
package main
import (
"encoding/json"
"fmt"
"github.com/eriksonJAguiar/godiffpriv"
)
func main() {
data := []string{"Male", "Female", "Male", "Female"}
val := godiffpriv.PrivateDataFactory(data)
epsilon:= 1
res, _ := val.ApplyPrivacy(epsilon)
var response map[string]float64
err := json.Unmarshal(res, &response)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(response)
}
}
- For numeric data:
package main
import (
"encoding/json"
"fmt"
"github.com/eriksonJAguiar/godiffpriv"
)
func main() {
data := []float64{1.5, 2.3, 7.2, 9.1}
val := godiffpriv.PrivateDataFactory(data)
epsilon:= 1
res, _ := val.ApplyPrivacy(epsilon)
var response map[string]float64
err := json.Unmarshal(res, &response)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(response)
}
}