Skip to content

Instantly share code, notes, and snippets.

@robodhruv
Created May 28, 2018 21:50
Show Gist options
  • Save robodhruv/2e1da8c677061832f2667876bd25b94f to your computer and use it in GitHub Desktop.
Save robodhruv/2e1da8c677061832f2667876bd25b94f to your computer and use it in GitHub Desktop.
Compute the restricted isometry constant (RIC) of a matrix at a specified sparsity level. Note that this is a certified NP-hard problem and only computationally tractable for small values of s (upto 4 or 5).
function out = compute_RIC(A, s)
% This function computes the Restricted Isometry Constant of given matrix A
% at sparsity level s.
% Written by Alankar Kotwal (alankarkotwal13@gmail.com), Dhruv Shah (dhruv.ilesh@gmail.com)
A = normc(A);
nT = size(A, 2);
combs = combnk(1:nT, s);
out = 0;
disp(size(combs, 1))
% for i = 1:size(combs, 1)
% Use the below if you have access to the Parallel Computing Toolbox, else use above
parfor i = 1:size(combs, 1)
if mod(i, 10000) == 0
disp(i)
end
subsA = A(:, combs(i, :));
dots = subsA' * subsA;
dotsSub = dots - eye(size(dots));
maxEig = max(abs(eig(dotsSub)));
out = max(out, maxEig);
end
end
@chinmay0301
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment