-
Notifications
You must be signed in to change notification settings - Fork 0
/
runPGDB.m
56 lines (40 loc) · 1.48 KB
/
runPGDB.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
%This function uses the PGDB for full tomography.
%
%inputs
%data: Nx1 vector of integers corresponding to numbers of detector clicks
%A: Nxd matrix of the measurement kets
%counts : multiplication factor that turns probabilities into estimated clicks
%output
%rhoPGDB: maximum likelihood density matrix
%timePGDB: time taken by the algorithm
%costFunction: cost function value as a function of iteration number
function [rhoPGDB, timePGDB, costFunction] = runPGDB(data,A,counts)
%
% Example of usage of 'pgqs' routine
% --------------------------------------
% Maximum Likelihood tomography of W state
% disp('PGDB')
t1 = tic;
sA = size(A);
d = sA(2);
n = d; % order of the density matrix
normalisedData = data/counts;
% other options for grrhor
tol = 0.1e-4; % tolerance used in convergence criteria
rho0 = (1/n)*eye(n); % initial guess for the density matrix
maxit = 2000; % maximum number of iterations
% this is the function to be minimized
% (For this example, the function is the least squares function)
fun = @(rho) leastsquares(rho,A,normalisedData ,counts); % function handle
% calling grrhor
[rho,flag,iter,fe,costFunction] = pgqs(fun,rho0,tol,maxit,1);
if (flag>=0)
% fprintf('Succesfully solved with PGDB. Flag: %d, Iter: %d, nfeval: %d \n', flag, iter, fe);
% % printing the recovered density matrix
% rho;
else
% fprintf('PGDB did not converge to the maximum likelihood state. \n');
end
timePGDB = toc(t1);
costFunction = abs(costFunction);
rhoPGDB = rho;