-
Notifications
You must be signed in to change notification settings - Fork 14
/
calcPLbyThm.m
61 lines (47 loc) · 1.51 KB
/
calcPLbyThm.m
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
%=========================================
% This function calculate the incremental privacy leakag, i.e. L(a), by Theorem 4 and Corollary 2 (in our TKDE paper).
% note1: this function only calc L(a), while BPL or FPL = L(a)+ eps_t.
% note2: some precision problem could happen when a is large (e.g. a>30,
% because exp(a)),but calcBPLbyPreComp.m and calcBPLbyFunc.m is robust to precision problem
% 04-Dec-2017 author: Yang Cao
%-----------------inputs-----------------
% TM: transition matrix
% a: previouts BPL or the next FPL
%-----------------outputs-----------------
% maxPL: maximum incremental privacy leakage L(a)
% q,d: two scalars that satisfy Theorem 4 in our TKDE paper
%=========================================
function [maxPL, q, d]=calcPLbyThm(TM, a)
% transition matrix M, previous BPL a
% s=tic;
n=size(TM,1);
pairs=VChooseK(int16(1:n), 2);
pairs=[pairs; fliplr(pairs)]';
QM=TM(pairs(1,:), :);
DM=TM(pairs(2,:), :);
% [QM, DM]=sortRatioM1M2_DES(QM,DM);
QDplusInd = QM>DM;
QM=QM.*QDplusInd;
DM=DM.*QDplusInd;
update = true;
while update
sizeRemain = sum(sum(QDplusInd));
valArr = (sum(QM, 2).*(exp(a)-1)+1)./(sum(DM,2).*(exp(a)-1)+1);
QDplusIndNew = QM./DM>valArr;
if sizeRemain == sum(sum(QDplusIndNew))
update = false;
else
idx=find(QDplusIndNew~=QDplusInd);
QM(idx)=0;
DM(idx)=0;
QDplusInd = QDplusIndNew;
end
end
[maxVal, I]=max(valArr);
maxPL= log(maxVal);
qArr=sum(QM, 2);
q=qArr(I);
dArr=sum(DM, 2);
d=dArr(I);
% runtime=toc(s);
end