Add example

This commit is contained in:
Ksyer
2024-05-09 16:54:58 +08:00
parent b91a609ca5
commit 17386d80c1
24 changed files with 3344 additions and 1 deletions
@@ -0,0 +1,27 @@
function [z] = FISTA(y, A, lambda, delta)
x_pre = A'*y;
t = 1;
z = x_pre;
z_pre = z;
t_pre = t;
N = size(A, 2);
diff = 1;
E = eig(A'*A);
L = E(end);
temp1 = A'*y/L;
temp2 = eye(N) - A'*A/L;
k = 0;
while((diff > delta) && (k < 1000))
temp = temp1 + temp2 * z_pre;
x = sft_thd(temp, lambda/L);
t = 0.5*(1 + sqrt(1+4*t_pre*t_pre));
z = x + (x - x_pre) * (t_pre-1) / t;
diff = mean(abs(z_pre - z));
x_pre = x;
z_pre = z;
t_pre = t;
k = k + 1;
end
end
@@ -0,0 +1,66 @@
clear;
close all;
clc;
load test_Pfa_Pd_SNR_PF_CROD_CAMP_SDL_ROD_gamma.mat;
Fontsize = 18;
plot_width = 800;
plot_height = 600;
Linewidth = 2;
Markersize = 8;
%% plot
figure(1);
plot(gamma_total, P_fa_CROD, '-o', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
hold on;
grid on;
plot(gamma_total, P_fa_CAMP, '-d', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(gamma_total, P_fa_SDL, '-s', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(gamma_total, P_fa_ROD, '-+', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
legend('CROD', 'CAMP', 'SDL-test', 'ROD');
xlabel('compression rate');
ylabel('P_{fa}');
set(gca, 'FontSize', Fontsize);
%set(gca, 'FontSize', Fontsize, 'fontname', 'Times New Roman');
set(gcf, 'position', [200, 300, plot_width, plot_height]);
figure(2);
plot(gamma_total, P_d_CROD, '-o', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
hold on;
grid on;
plot(gamma_total, P_d_CAMP, '-d', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(gamma_total, P_d_SDL, '-s', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(gamma_total, P_d_ROD, '-+', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
legend('CROD', 'CAMP', 'SDL-test', 'ROD');
xlabel('compression rate');
ylabel('P_{d}');
set(gca, 'FontSize', Fontsize);
%set(gca, 'FontSize', Fontsize, 'fontname', 'Times New Roman');
set(gcf, 'position', [200, 300, plot_width, plot_height]);
@@ -0,0 +1,251 @@
clc;
clear;
close all;
%% parameter setting
n = 256;
SNR = 13;
rep_time = 1e4;
P_fa = 1e-2;
p0 = 0.1;
gamma_total = (4: 12)/16;
len_gamma = length(gamma_total);
lambda = 0.1;
sigma_0 = 0.1;
sigma_n = sigma_0;
%% experiment
P_fa_CROD_cnt = zeros(len_gamma, rep_time);
P_fa_CAMP_cnt = zeros(len_gamma, rep_time);
P_fa_SDL_cnt = zeros(len_gamma, rep_time);
P_fa_ROD_cnt = zeros(len_gamma, rep_time);
P_fa_LASSO_cnt = zeros(len_gamma, rep_time);
P_d_CROD_cnt = zeros(len_gamma, rep_time);
P_d_CAMP_cnt = zeros(len_gamma, rep_time);
P_d_SDL_cnt = zeros(len_gamma, rep_time);
P_d_ROD_cnt = zeros(len_gamma, rep_time);
P_d_LASSO_cnt = zeros(len_gamma, rep_time);
h_thd = -log(P_fa);
parfor rep = 1: rep_time
for cnt_gamma = 1: len_gamma
gamma = gamma_total(cnt_gamma);
m = round(gamma*n);
A_idx = randperm(n);
A_idx = A_idx(1: m);
A_idx = sort(A_idx);
A = dftmtx(n);
A = A(A_idx, :);
A = A / sqrt(n);
w = random('Normal', 0, sigma_0/sqrt(2), m, 1) + 1j * random('Normal', 0, sigma_0/sqrt(2), m, 1);
x_idx = rand(n, 1);
if p0 == 0
thd = -1;
x_l0 = sum(x_idx > thd);
else
thd = sort(x_idx);
thd = thd(round(n*p0));
x_l1 = sum(x_idx <= thd);
x_l0 = sum(x_idx > thd);
end
x = zeros(n, 1);
x_temp = sigma_0 * exp(1j*random('Uniform', 0, 2*pi, n, 1));
x(x_idx <= thd) = x_temp(x_idx <= thd);
x = x * sqrt(n/m);
x1 = x * sqrt(10^(SNR/10));
y = A * x1 + w;
% x_LASSO = LASSO_cvx(y, A, lambda);
x_LASSO = FISTA(y, A, lambda, 1e-5);
% CROD
rho_active = sum(abs(x_LASSO) > 1e-3)/n;
Q_hat = (gamma - rho_active)/(1 - rho_active);
Rho = sum((abs(x_LASSO) > 1e-3).* (2 - lambda./(Q_hat*abs(x_LASSO) + lambda))) / 2 / n;
diff = 1;
while(diff > 1e-4)
Rho_pre = Rho;
Rho = sum((abs(x_LASSO) > 1e-3).* (2 - lambda./((gamma-Rho)/(1-Rho)*abs(x_LASSO) + lambda))) / 2 / n;
diff = abs(Rho - Rho_pre);
end
Q_hat = (gamma-Rho)/(1-Rho);
x_d_CROD = x_LASSO + A'*(y - A*x_LASSO)/Q_hat;
RSS = sum(abs(y - A * x_LASSO).^2)/m;
chi = Rho*(1 - Rho)/(gamma - Rho);
if chi ~= 0
chi_temp = sqrt((chi+1)*(chi+1)-4*gamma*chi);
z = -(1 - chi + chi_temp) / (2*chi);
z_prime = -(1 - 2*gamma*chi + chi + chi_temp) / (2*chi*chi*chi_temp);
G_prime = (z + 1/chi);
G_wprime = (z_prime + 1/chi/chi);
chi_hat = gamma/2*G_wprime*RSS/(G_prime - chi*G_wprime)...
+ (G_prime*G_prime/2 - gamma/2*G_wprime)*sigma_n*sigma_n/(G_prime - chi*G_wprime);
else
G_prime = gamma;
G_wprime = gamma*(1-gamma);
chi_hat = gamma/2*G_wprime*RSS/(G_prime - chi*G_wprime)...
+ (G_prime*G_prime/2 - gamma/2*G_wprime)*sigma_n*sigma_n/(G_prime - chi*G_wprime);
end
sigma_CROD = sqrt(2*chi_hat) / Q_hat;
stat_CROD = abs(x_d_CROD / sigma_CROD).^2;
P_fa_CROD_cnt(cnt_gamma, rep) = sum(stat_CROD(x_idx > thd) > h_thd) / x_l0;
P_d_CROD_cnt(cnt_gamma, rep) = sum(stat_CROD(x_idx <= thd) > h_thd) / x_l1;
% CAMP
Q_hat1 = gamma - rho_active;
Rho = sum((abs(x_LASSO) > 1e-3).* (2 - lambda./(Q_hat1*abs(x_LASSO) + lambda))) / 2 / n;
diff = 1;
while(diff > 1e-4)
Rho_pre = Rho;
Rho = sum((abs(x_LASSO) > 1e-3).* (2 - lambda./((gamma-Rho)*abs(x_LASSO) + lambda))) / 2 / n;
diff = abs(Rho - Rho_pre);
end
Q_hat1 = (gamma-Rho);
x_d_CAMP = x_LASSO + A'*(y - A*x_LASSO)/Q_hat1;
sigma_CAMP = 1/sqrt(log(2))*median(abs(x_d_CAMP));
stat_CAMP = abs(x_d_CAMP / sigma_CAMP).^2;
P_fa_CAMP_cnt(cnt_gamma, rep) = sum(stat_CAMP(x_idx > thd) > h_thd) / x_l0;
P_d_CAMP_cnt(cnt_gamma, rep) = sum(stat_CAMP(x_idx <= thd) > h_thd) / x_l1;
% SDL
Q_hat2 = (gamma - rho_active);
x_d_SDL = x_LASSO + A'*(y - A*x_LASSO)/Q_hat2;
sigma_SDL = sqrt(gamma)/sqrt(log(2))/(gamma - rho_active)*median(abs(y - A*x_LASSO));
stat_SDL = abs(x_d_SDL / sigma_SDL).^2;
P_fa_SDL_cnt(cnt_gamma, rep) = sum(stat_SDL(x_idx > thd) > h_thd) / x_l0;
P_d_SDL_cnt(cnt_gamma, rep) = sum(stat_SDL(x_idx <= thd) > h_thd) / x_l1;
% ROD
Q_hat3 = (gamma - rho_active)/(1 - rho_active);
x_d_ROD = x_LASSO + A'*(y - A*x_LASSO)/Q_hat3;
chi = rho_active*(1 - rho_active)/(gamma - rho_active);
if chi ~= 0
chi_temp = sqrt((chi+1)*(chi+1)-4*gamma*chi);
z = -(1 - chi + chi_temp) / (2*chi);
z_prime = -(1 - 2*gamma*chi + chi + chi_temp) / (2*chi*chi*chi_temp);
G_prime = (z + 1/chi);
G_wprime = (z_prime + 1/chi/chi);
chi_hat2 = gamma/2*G_wprime*RSS/(G_prime - chi*G_wprime)...
+ (G_prime*G_prime/2 - gamma/2*G_wprime)*sigma_n*sigma_n/(G_prime - chi*G_wprime);
else
G_prime = gamma;
G_wprime = gamma*(1-gamma);
chi_hat2 = gamma/2*G_wprime*RSS/(G_prime - chi*G_wprime)...
+ (G_prime*G_prime/2 - gamma/2*G_wprime)*sigma_n*sigma_n/(G_prime - chi*G_wprime);
end
sigma_ROD = sqrt(2*chi_hat2) / Q_hat3;
stat_ROD = abs(x_d_ROD / sigma_ROD).^2;
P_fa_ROD_cnt(cnt_gamma, rep) = sum(stat_ROD(x_idx > thd) > h_thd) / x_l0;
P_d_ROD_cnt(cnt_gamma, rep) = sum(stat_ROD(x_idx <= thd) > h_thd) / x_l1;
% LASSO
% stat_LASSO = abs(x_LASSO).^2;
% if p0 ~= 0
% stat_H1_LASSO_cnt(rep, :) = stat_LASSO(x_idx <= thd);
% end
% stat_H0_LASSO_cnt(rep, :) = stat_LASSO(x_idx > thd);
end
fprintf('%d\n', rep);
end
P_fa_CROD = mean(P_fa_CROD_cnt, 2);
P_fa_CAMP = mean(P_fa_CAMP_cnt, 2);
P_fa_SDL = mean(P_fa_SDL_cnt, 2);
P_fa_ROD = mean(P_fa_ROD_cnt, 2);
P_d_CROD = mean(P_d_CROD_cnt, 2);
P_d_CAMP = mean(P_d_CAMP_cnt, 2);
P_d_SDL = mean(P_d_SDL_cnt, 2);
P_d_ROD = mean(P_d_ROD_cnt, 2);
%% plot
figure(1);
plot(gamma_total, P_fa_CROD, 'linewidth', 2);
hold on;
grid on;
plot(gamma_total, P_fa_CAMP, 'linewidth', 2);
plot(gamma_total, P_fa_SDL, 'linewidth', 2);
plot(gamma_total, P_fa_ROD, 'linewidth', 2);
legend('CROD', 'CAMP', 'SDL-test', 'ROD');
xlabel('compression rate');
ylabel('P_{fa}');
figure(2);
plot(gamma_total, P_d_CROD, 'linewidth', 2);
hold on;
grid on;
plot(gamma_total, P_d_CAMP, 'linewidth', 2);
plot(gamma_total, P_d_SDL, 'linewidth', 2);
plot(gamma_total, P_d_ROD, 'linewidth', 2);
legend('CROD', 'CAMP', 'SDL-test', 'ROD');
xlabel('compression rate');
ylabel('P_{d}');
save test_Pfa_Pd_SNR_PF_CROD_CAMP_SDL_ROD_gamma.mat ...
gamma_total...
P_fa_CROD...
P_fa_CAMP...
P_fa_SDL...
P_fa_ROD...
P_d_CROD...
P_d_CAMP...
P_d_SDL...
P_d_ROD;