%% test out finding an approximate matrix completion

%% comment out next two lines to repeat the same 'random' problem
rng('shuffle')
%rng('default');     % for same problem
saverng=rng;
rng(saverng);


nbElts = 100;
a=pdist(randn(nbElts, 10));

% distance matrix to predict
A=squareform(a);

p = .2;
nbZeros = ceil(length(a)*p);
w = 1000*ones(1, length(a));
w(randi(length(a), 1, nbZeros)) = 1;
% weight matrix
W = squareform(w);

[optval,L,P,iter] = dualcomp(A, W, eps);
fprintf('The PSD completion matrix is P with min eig %g \n',min(eig(P)))

