% Description of this demo:
%  In this demo we see the performance of MFOCUSS when the
%  regularization parameter chooses different possible values.
%
% ====== The whole experiment takes about 1 minute. ======
%
% Author: Zhilin Zhang (z4zhang@ucsd.edu)
% Date  : 05/12/2011
%

clear; clc; close all;


% problem dimension
N = 50;   % row number of the dictionary matrix
M = 200;  % column number of the dictionary matrix
K = 20;   % number of nonzero rows in the solution matrix
L = 4;    % number of measurement vectors

% candidate values for the regularization parameter (lambda)
LAMBDA = logspace(-4,-2, 5);

% We repeat the experiment for 10 trials to see the statistical result
for it = 1:10
    fprintf('\n\nRunning %d:\n',it);

    % dictionary matrix with columns draw uniformly from the surface of a unit hypersphere
    Phi = randn(N,M);
    Phi = Phi./(ones(N,1)*sqrt(sum(Phi.^2)));

    % Generate K sources (i.i.d. sources)
    nonzeroW = randn(K,L);
    nonzeroW = nonzeroW./( sqrt(sum(nonzeroW.^2,2)) * ones(1,L) );   % normalize 

    % select active sources at random locations
    ind = randperm(M);
    indice = ind(1:K);
    Wgen = zeros(M,L);
    Wgen(indice,:) = nonzeroW;

    % noiseless signal
    signal = Phi * Wgen;

    % noise
    stdvariance = 0.05;
    noise = randn(N,L) * stdvariance;

    % noisy signal
    Y = signal + noise;


    for n = 1 : length(LAMBDA)
        lambda = LAMBDA(n);
        
        [X_focuss, gamma_ind_focuss, gamma_est_focuss, count_focuss] = MFOCUSS(Phi, Y, lambda);

        % MSE
        MSE_MFOCUSS(it,n) = (norm(Wgen - X_focuss,'fro')/norm(Wgen,'fro'))^2;

    end

    fprintf('Regular Path of MFOCUSS \n');
    mean(MSE_MFOCUSS,1)


end


figure(1);
semilogx(LAMBDA,mean(MSE_MFOCUSS),'k','linewidth',3);
title('\bf\fontsize{14}Performance Measured by Mean Square Error');
xlabel('\bf\fontsize{12}lambda');
ylabel('\bf\fontsize{12}MSE'); axis tight;

