-
Notifications
You must be signed in to change notification settings - Fork 4
/
DIA.m
49 lines (40 loc) · 1.36 KB
/
DIA.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
function [ choi_ml_vec, solution, costs ] = DIA( A,n )
%DIA: diluted RrhoR algorithm
% here we follow Anis and Lvovsky NJP 2012
% also Fedorov et al NJP 2014
d = sqrt(sqrt(size(A)));
d = d(2);
% unbiased initialisation
choi_init = sparse(eye(d*d)/d);
choi_init = reshape(choi_init,[],1);
solution = {choi_init};
costs=0;
old_cost = 1e10;
for k=1:1e4
rho = reshape(solution{k},[],d*d) ;
rho = 0.5*rho + 0.5*rho'; %enforce hermitian
R = reshape(gradient(A,n,solution{k}),[],d*d);
e = 1;
Rp = (e*R)+(1-e)*eye(d*d); % dilute
lambda = sqrtm(partial_trace(Rp*rho*Rp));
LI = kron(inv(lambda),eye(d));
while cost(A,n,reshape(LI*Rp*rho*Rp*LI,[],1)) > cost(A,n,reshape(rho,[],1))
e = e * 0.5;
if e < 1e-100
break
end
Rp = (e*R)+(1-e)*eye(d*d);
lambda = sqrtm(partial_trace(Rp*rho*Rp));
LI = kron(inv(lambda),eye(d));
end
rho_new = LI*Rp*rho*Rp*LI;
solution{k+1} = reshape(rho_new,[],1);
new_cost = cost(A,n,solution{k+1});
p = real(A*solution{k+1});
if (old_cost - new_cost) < 1e-10
break
end
old_cost = new_cost;
end
choi_ml_vec = solution{end};
end