Skip to content

Instantly share code, notes, and snippets.

@higham
Created February 3, 2018 14:28
Show Gist options
  • Save higham/9d9ba7557b1b262c35f6147df8b64eb7 to your computer and use it in GitHub Desktop.
Save higham/9d9ba7557b1b262c35f6147df8b64eb7 to your computer and use it in GitHub Desktop.
MATLAB expriment for correlation matrix compleition
%NCM_COMPARE
% M-file to carry out experiment in "Explicit Solutions to Correlation
% Matrix Completion Problems, with an Application to Risk Management and
% Insurance" by Dan I. Georgescu, Nicholas J. Higham and Gareth W. Peters.
C = [%
1 0.25 0.6 0.55 0.65 0 0.4 0.6 0.2 0.3
0.25 1 0 0 0 0 NaN NaN NaN NaN
0.6 0 1 0.75 0.75 0 NaN NaN NaN NaN
0.55 0 0.75 1 0.5 0 NaN NaN NaN NaN
0.65 0 0.75 0.5 1 0 NaN NaN NaN NaN
0 0 0 0 0 1 NaN NaN NaN NaN
0.4 NaN NaN NaN NaN NaN 1 0.25 0.25 0.5
0.6 NaN NaN NaN NaN NaN 0.25 1 0.25 0
0.2 NaN NaN NaN NaN NaN 0.25 0.25 1 0
0.3 NaN NaN NaN NaN NaN 0.5 0 0 1];
format short
pattern = ~isnan(C);
A = C; A(isnan(A)) = 0
eigA = eig(A)
% Max det completion.
A11 = C(1,1);
B = C(1,2:6); CC = C(1,7:end);
A22 = C(2:6,2:6);
E = C(2:6,7:end);
A33 = C(7:end,7:end);
E_maxdet = B'*(A11\CC)
normF_Emaxdet = norm(E_maxdet,'fro')
dist_maxdet = norm(E_maxdet)
Y = A;
Y(2:6,7:end) = E_maxdet;
Y(7:end,2:6) = E_maxdet';
format short e
eig_maxdet = eig(Y)'
det_maxdet = det(Y)
% Use code from https://github.com/higham/anderson-accel-ncm
% Adjust next line as necessary.
addpath d:\tex\anderson\matlab -end
[X,iter] = nearcorr_aa(A,pattern);
format short
E_ncm = X(2:6,7:end)
normF_Encm = norm(E_ncm,'fro')
format short e
eig_ncm = eig(X)'
dist_ncm = norm(A-X,'fro')
det_ncm = det(X)
% Use code from https://github.com/higham/shrinking
% Adjust next line as necessary.
addpath d:\tex\shrinking\matlab -end
M0 = A;
M1 = Y;
alpha = shrink_bisect(M0,M1,1e-14)
Z = alpha*M1 + (1-alpha)*M0
format short
E_shrink = Z(2:6,7:end)
normF_Eshrink = norm(E_shrink,'fro')
dist_shrink = norm(A-Z,'fro')
det_shrink = det(Z)
format short e
eig_shrink = eig(Z)'
Z = inv(Y);
norm_inv_unspec = norm(Z(2:6,7:end))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment