-
Notifications
You must be signed in to change notification settings - Fork 1
/
getDistance.py
84 lines (63 loc) · 1.77 KB
/
getDistance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import ConvertFile as cf
from scipy.spatial import distance
import Main as main
import numpy as np
import PrivateProtection as pp
import GenMatrix as gm
import RandomizedResponse as rr
# original matrix distance
def studentMatrix():
matrix = cf.getStudent()
(n,d) = matrix.shape
dist = []
for i in range(0,n):
row = []
for j in range(0, n):
if (i == j):
row.append(0)
else:
#row.append("{} compared with {}".format(i,j))
userA = matrix[i]
userB = matrix[j]
euc = distance.euclidean(userA, userB)**2
#tmp = (euc - (2*k*p)*(1-p))/((1-2*p)**2)
row.append(euc)
dist.append(row)
return np.array(dist)
#dist = distance.squareform(distance.pdist(matrix, metric='euclidean'))
dist
return dist
# PP, the recovered distance on student
def ppStudent():
matrix = main.studentPP()
return matrix
# original vs PP distance
def differencePPStudent():
x = studentMatrix()
#print (x[0])
y = ppStudent()
#print y[0]
return y - x
## RR on studend
def rrStudent():
matrix = main.studentRR()
return matrix
## original vs RR DISTANCE
def differenceRRStudent():
x = studentMatrix()
y = rrStudent()
return y - x
def ppGM(generateMatrix):
Z, P, sigma = pp.PrivateProtection(generateMatrix)
distance = pp.recoveredDistance(Z, sigma)
return distance
def rrGM(generateMatrix):
p = .37
X = rr.RandomizedResponse(p, generateMatrix)
distance = rr.RecoverDistanceRR(p, X)
return distance
# original matrix distance
def heartMatrix():
matrix = cf.getHeart()
dist = distance.squareform(distance.pdist(matrix, metric='euclidean'))
return dist