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,82 @@
% Input: y,A,lambda,tau,Kit
% Output: x_hat_wl,x_hat_d
% Main structure of cVAMP
function [x_hat_wl, x_hat_d] = cVAMPro(y, A, lambda, tau, Kit)
% Initialization
[M, N] = size(A);
gamma = M / N;
k = 0;
p = ctranspose(A) * y;
h_1 = p;
Q_1 = gamma;
tau_d = 1;
% Iteration
while ((k < Kit) && (tau_d > tau))
% Factorized Part
x_1 = ST(h_1, lambda, Q_1);
chi_1 = F1(x_1, lambda, Q_1);
% Message Passing
h_2 = x_1 / chi_1 - h_1;
Q_2 = 1 / chi_1 - Q_1;
% Gaussian Part
t1 = (p + h_2) / Q_2;
t2 = ctranspose(A) * (A * (p + h_2)) / ((Q_2 + 1) * Q_2);
x_2 = t1 - t2;
chi_2 = gamma / (Q_2 + 1) + (1 - gamma) / Q_2;
% Message Passing
h_1_next = x_2 ./ chi_2 - h_2;
Q_1_next = 1 / chi_2 - Q_2;
tau_d = norm(h_1_next - h_1, Inf) / norm(h_1_next, Inf);
k = k + 1;
% output
x_hat_wl = x_1;
x_hat_d = h_1_next / Q_1_next;
% next
h_1 = h_1_next;
Q_1 = Q_1_next;
end
end
% SoftThreshold function
function x = ST(h_1, lambda, Q_1)
[N, M] = size(h_1);
x = zeros(N, M);
for i = 1:N
sign = h_1(i) ./ abs(h_1(i));
diff = abs(h_1(i)) - lambda(i);
x(i) = sign .* (diff ./ Q_1) .* SF(diff);
end
end
% Heaviside's step function
function v = SF(a)
if a > 0
v = 1;
elseif a == 0
v = 0; % at zero points
else
v = 0;
end
end
% Calculation of chi_1
function chi_1 = F1(x_1, lambda, Q_1)
[N, M] = size(x_1);
count = 0;
for i = 1:N
temp = Q_1 * abs(x_1(i)) + lambda(i);
count = count + (2 - lambda(i) / temp) * SF(abs(x_1(i)));
% count = count + (2-lambda(i)/temp) * (abs(x_1(i)) > 1e-4);
end
chi_1 = count / (2 * N * Q_1);
end
@@ -0,0 +1,122 @@
clear;
close all;
clc;
load test_Pd_Pfa_vamp_cal_stat.mat;
Fontsize = 18;
plot_width = 800;
plot_height = 600;
Linewidth = 2;
Markersize = 8;
%% plot
figure(1);
loglog(P_fa, P_fa_CROD(1,:), '-o', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
hold on;
grid on;
loglog(P_fa, P_fa_CROD(2,:), '-+', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
loglog(P_fa, P_fa_CROD(3,:), '-d', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
loglog(P_fa, P_fa_CROD(4,:), '-s', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
loglog(P_fa, P_fa_CROD(5,:), '-^', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
legend('SNR = 0', 'SNR = 2', 'SNR = 4', 'SNR = 6', 'SNR = 8');
xlabel('P_{fa} Set');
ylabel('Actual P_{fa}');
ylim([8e-5,1]);
set(gca, 'FontSize', Fontsize);
title('cVAMPro P_{fa}')
set(gcf, 'position', [200, 300, plot_width, plot_height]);
set(gca,'fontsize',20,'fontname','Times');
figure(3);
semilogx(P_fa_CROD(1,:), P_d_CROD(1,:), '-o', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
hold on;
grid on;
semilogx(P_fa_CROD(2,:), P_d_CROD(2,:), '-+', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
semilogx(P_fa_CROD(3,:), P_d_CROD(3,:), '-d', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
semilogx(P_fa_(3,:), P_d_CROD(4,:), '-s', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
semilogx(P_fa_CROD(3,:), P_d_CROD(5,:), '-^', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
legend('SNR = 0', 'SNR = 2', 'SNR = 4', 'SNR = 6', 'SNR = 8');
xlabel('P_{fa}');
ylabel('P_{d}');
xlim([8e-5,1]);
set(gca, 'FontSize', Fontsize);
title('cVAMPro ROC')
set(gcf, 'position', [200, 300, plot_width, plot_height]);
set(gca,'fontsize',20,'fontname','Times');
figure(5);
semilogy(SNR, P_fa_CROD(:,1), '-o', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
hold on;
grid on;
semilogy(SNR, P_fa_CROD(:,3), '-+', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
semilogy(SNR, P_fa_CROD(:,5), '-d', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
semilogy(SNR, P_fa_CROD(:,7), '-s', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
semilogy(SNR, P_fa_CROD(:,9), '-^', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
legend('Pfa = 1e-4', 'Pfa = 1e-3', 'Pfa = 1e-2', 'Pfa = 1e-1', 'Pfa = 1');
xlabel('SNR');
ylabel('P_{fa}');
set(gca, 'FontSize', Fontsize);
title('cVAMPro')
set(gcf, 'position', [200, 300, plot_width, plot_height]);
set(gca,'fontsize',20,'fontname','Times');
figure(6);
plot(SNR, P_d_CROD(:,1), '-o', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
hold on;
grid on;
plot(SNR, P_d_CROD(:,3), '-+', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(SNR, P_d_CROD(:,5), '-d', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(SNR, P_d_CROD(:,7), '-s', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(SNR, P_d_CROD(:,9), '-^', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
legend('Pfa = 1e-4', 'Pfa = 1e-3', 'Pfa = 1e-2', 'Pfa = 1e-1', 'Pfa = 1');
xlabel('SNR');
ylabel('P_{d}');
set(gca, 'FontSize', Fontsize);
title('cVAMPro')
set(gcf, 'position', [200, 300, plot_width, plot_height]);
set(gca,'fontsize',20,'fontname','Times');
@@ -0,0 +1,11 @@
function [ stat ] = stat_window(signal, win_size)
n = length(signal);
stat = zeros(n, 1);
for i = 1: n
for j = 1: win_size
if i + j - 1 <= n
stat(i, 1) = stat(i, 1) + signal(i + j - 1, 1);
end
end
end
end
@@ -0,0 +1,280 @@
clc;
clear;
close all;
%% parameter setting
% SNR = 5: 1: 6;
% SNR = 0: 2: 10;
% SNR = 0: 5: 25;
SNR = [0,5,8,10,12,15,20,25];
len_SNR = length(SNR);
SNR_t2 = 25;
rep_time = 2000;
% P_fa = 1e-1;
P_fa = [1e-4, 5e-4, 1e-3, 5e-3, 1e-2, 5e-2, 1e-1, 5e-1, 1];
len_P_fa = length(P_fa);
target_scattering = [0.8,1,0.9];
win_size = length(target_scattering);
alpha_prop = 0.8;
% alpha_prop = [0.6, 0.4, 0.2];
lambda = 0.1;
% Sparsity
sigma_0 = 0.1;
% noise sigma
sigma_n = sigma_0;
%% vamp set
delta_VAMP = 1e-6;
iter_max = 500;
lambda_val = 0.1;
gamma = 0.5;
%% 参数设置
B=5e5; %信号带宽10MHz
Tp=100e-6; %脉宽100us
fs=2*B; %采样频率
Ts= 1 / fs; %采样周期
K = B / Tp; %线性调频率
fc = 1e8; %载波频率
Tr = 1e-3;
t = 0:1/fs:Tr-1/fs;
t2 = 0:1/fs/2:Tr-1/fs/2;
c = 3e8; % 光速
distance_max = (Tr-Tp) * c / 2;
n = Tr * fs;
m = round(n * gamma);
%% experiment
P_fa_CROD_cnt = zeros(len_SNR, len_P_fa, rep_time);
P_d_CROD_cnt = zeros(len_SNR, len_P_fa, rep_time);
% h_thd = -log(P_fa);
h_thd = chi2inv(1 - P_fa, 6) / 2;
%%
parfor rep = 1: rep_time
% for rep = 1: rep_time
for cnt_SNR = 1: len_SNR
% 设置目标位置
% target_index = randi([2,n - length(target_scattering)]);
target_index = 300;
target2_index = round(n * 0.4);
% 根据 SNR 设置散射点强度
alpha = alpha_prop * sqrt(10^(SNR(cnt_SNR)/10) * sigma_n^2);
alpha2 = alpha_prop * sqrt(10^(SNR_t2/10) * sigma_n^2);
% 设置 x
x = zeros(n ,1);
x(target_index:target_index+2,1) = target_scattering * alpha;
x(target2_index:target2_index+2,1) = target_scattering * alpha2;
% plot(x)
%% 生成矩阵 A
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);
% % 匹配滤波放大倍数
% multiple = A(:,1)' * A(:,1);
%% 生成 y
noise = random('Normal', 0, sigma_n/sqrt(2), m, 1) + 1j * random('Normal', 0, sigma_n/sqrt(2), m, 1);
y = A * x + noise;
%% cVAMPro 求解
lambda = zeros(n,1) + lambda_val;
[x_LASSO, x_hat_d_ro] = cVAMPro(y, A, lambda, delta_VAMP, iter_max);
%%
% 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;
% plot(abs(x_d_CROD))
%%
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;
% window
stat_extend = stat_window(stat_CROD, win_size);
figure(100)
plot(stat_CROD);hold on;
plot(stat_extend);hold off;
n_index = ones(size(stat_extend));
t_index = zeros(size(stat_extend));
% distance_node = [target_index, target_index + 1, target_index + 2];
distance_node = target_index;
distance_area = target_index-2: 1: target_index+2;
distance_area2 = target2_index-2: 1: target2_index+2;
n_index(distance_area) = 0;
n_index(distance_area2) = 0;
t_index(distance_node) = 1;
for cnt_h_th = 1: len_P_fa
figure(12);
plot(stat_extend)
hold on;
kdline = zeros(size(stat_extend)) + h_thd(cnt_h_th);
plot(kdline)
hold off;
P_fa_CROD_cnt(cnt_SNR, cnt_h_th, rep) = sum(stat_extend(n_index>0) > h_thd(cnt_h_th)) / sum(n_index);
P_d_CROD_cnt(cnt_SNR, cnt_h_th, rep) = sum(stat_extend(t_index>0) > h_thd(cnt_h_th)) / sum(t_index);
end
end
fprintf('%d\n', rep);
end
P_fa_CROD = mean(P_fa_CROD_cnt, 3);
P_d_CROD = mean(P_d_CROD_cnt, 3);
display(['设定虚警率',num2str(P_fa(1))])
display(['实验虚警率',num2str(P_fa_CROD(1,1))])
display(['实验检测率',num2str(P_d_CROD(1,1))])
%% plot
figure(1);
loglog(P_fa,P_fa_CROD(1,:), 'linewidth', 2);
hold on;
grid on;
loglog(P_fa,P_fa_CROD(2,:), 'linewidth', 2);
loglog(P_fa,P_fa_CROD(3,:), 'linewidth', 2);
loglog(P_fa,P_fa_CROD(4,:), 'linewidth', 2);
loglog(P_fa,P_fa_CROD(5,:), 'linewidth', 2);
loglog(P_fa,P_fa_CROD(6,:), 'linewidth', 2);
legend('SNR = 0','SNR = 2','SNR = 4','SNR = 6','SNR = 8','SNR = 10');
xlabel('P_fa');
ylabel('P_fa_CROD');
% figure(2);
% loglog(P_fa_CROD_thry(1,:), P_d_CROD_thry(1,:), 'linewidth', 2);
% hold on;
% grid on;
% loglog(P_fa_CROD_thry(2,:), P_d_CROD_thry(2,:), 'linewidth', 2);
% loglog(P_fa_CROD_thry(3,:), P_d_CROD_thry(3,:), 'linewidth', 2);
% legend('SNR = 0', 'SNR = 10', 'SNR = 20');
% xlabel('P_{fa}');
% ylabel('P_{d}');
%
% % figure(4);
% % loglog(P_fa_CROD_thry(1,:), P_d_CROD_thry2(1,:), 'linewidth', 2);
% % hold on;
% % grid on;
% % loglog(P_fa_CROD_thry(2,:), P_d_CROD_thry2(2,:), 'linewidth', 2);
% % loglog(P_fa_CROD_thry(3,:), P_d_CROD_thry2(3,:), 'linewidth', 2);
% % legend('SNR = 0', 'SNR = 10', 'SNR = 20');
% % xlabel('P_{fa}');
% % ylabel('P_{d}');
%
%
% figure(3);
% loglog(P_fa_CROD(1,:), P_d_CROD(1,:), 'linewidth', 2);
% hold on;
% grid on;
% loglog(P_fa_CROD(2,:), P_d_CROD(2,:), 'linewidth', 2);
% loglog(P_fa_CROD(3,:), P_d_CROD(3,:), 'linewidth', 2);
% loglog(P_fa_CROD_thry(1,:), P_d_CROD_thry(1,:), 'linewidth', 2);
% loglog(P_fa_CROD_thry(2,:), P_d_CROD_thry(2,:), 'linewidth', 2);
% loglog(P_fa_CROD_thry(3,:), P_d_CROD_thry(3,:), 'linewidth', 2);
% legend('rSNR = 0', 'rSNR = 10', 'rSNR = 20', ...
% 'tSNR = 0', 'tSNR = 10', 'tSNR = 20');
% xlabel('P_{fa}');
% ylabel('P_{d}');
save test_Pd_Pfa_vamp_cal_stat.mat ...
SNR...
P_fa...
P_fa_CROD...
P_d_CROD...
lambda...
m...
n...
h_thd...
sigma_n...
target_scattering;
@@ -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_SNR.mat;
Fontsize = 18;
plot_width = 800;
plot_height = 600;
Linewidth = 2;
Markersize = 8;
%% plot
figure(1);
plot(SNR, P_fa_CROD, '-o', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
hold on;
grid on;
plot(SNR, P_fa_CAMP, '-d', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(SNR, P_fa_SDL, '-s', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(SNR, P_fa_ROD, '-+', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
legend('CROD', 'CAMP', 'SDL-test', 'ROD');
xlabel('SNR');
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(SNR, P_d_CROD, '-o', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
hold on;
grid on;
plot(SNR, P_d_CAMP, '-d', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(SNR, P_d_SDL, '-s', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(SNR, P_d_ROD, '-+', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
legend('CROD', 'CAMP', 'SDL-test', 'ROD');
xlabel('SNR');
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,247 @@
clc;
clear;
close all;
%% parameter setting
m = 128;
n = 256;
SNR = 0: 1: 15;
len_SNR = length(SNR);
rep_time = 1e4;
P_fa = 1e-2;
p0 = 0.1;
lambda = 0.1;
sigma_0 = 0.1;
sigma_n = sigma_0;
%% experiment
gamma = m/n;
P_fa_CROD_cnt = zeros(len_SNR, rep_time);
P_fa_CAMP_cnt = zeros(len_SNR, rep_time);
P_fa_SDL_cnt = zeros(len_SNR, rep_time);
P_fa_ROD_cnt = zeros(len_SNR, rep_time);
P_fa_LASSO_cnt = zeros(len_SNR, rep_time);
P_d_CROD_cnt = zeros(len_SNR, rep_time);
P_d_CAMP_cnt = zeros(len_SNR, rep_time);
P_d_SDL_cnt = zeros(len_SNR, rep_time);
P_d_ROD_cnt = zeros(len_SNR, rep_time);
P_d_LASSO_cnt = zeros(len_SNR, rep_time);
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);
h_thd = -log(P_fa);
parfor rep = 1: rep_time
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);
% w = w / sqrt(10^(SNR(cnt_SNR)/10));
for cnt_SNR = 1: len_SNR
x1 = x * sqrt(10^(SNR(cnt_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_SNR, rep) = sum(stat_CROD(x_idx > thd) > h_thd) / x_l0;
P_d_CROD_cnt(cnt_SNR, 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_SNR, rep) = sum(stat_CAMP(x_idx > thd) > h_thd) / x_l0;
P_d_CAMP_cnt(cnt_SNR, 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_SNR, rep) = sum(stat_SDL(x_idx > thd) > h_thd) / x_l0;
P_d_SDL_cnt(cnt_SNR, 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_SNR, rep) = sum(stat_ROD(x_idx > thd) > h_thd) / x_l0;
P_d_ROD_cnt(cnt_SNR, 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(SNR, P_fa_CROD, 'linewidth', 2);
hold on;
grid on;
plot(SNR, P_fa_CAMP, 'linewidth', 2);
plot(SNR, P_fa_SDL, 'linewidth', 2);
plot(SNR, P_fa_ROD, 'linewidth', 2);
legend('CROD', 'CAMP', 'SDL-test', 'ROD');
xlabel('SNR');
ylabel('P_{fa}');
figure(2);
plot(SNR, P_d_CROD, 'linewidth', 2);
hold on;
grid on;
plot(SNR, P_d_CAMP, 'linewidth', 2);
plot(SNR, P_d_SDL, 'linewidth', 2);
plot(SNR, P_d_ROD, 'linewidth', 2);
legend('CROD', 'CAMP', 'SDL-test', 'ROD');
xlabel('SNR');
ylabel('P_{d}');
save test_Pfa_Pd_SNR_PF_CROD_CAMP_SDL_ROD_SNR.mat ...
SNR...
P_fa_CROD...
P_fa_CAMP...
P_fa_SDL...
P_fa_ROD...
P_d_CROD...
P_d_CAMP...
P_d_SDL...
P_d_ROD;
@@ -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_p0.mat;
Fontsize = 18;
plot_width = 800;
plot_height = 600;
Linewidth = 2;
Markersize = 8;
%% plot
figure(1);
plot(p0_total, P_fa_CROD, '-o', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
hold on;
grid on;
plot(p0_total, P_fa_CAMP, '-d', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(p0_total, P_fa_SDL, '-s', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(p0_total, P_fa_ROD, '-+', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
legend('CROD', 'CAMP', 'SDL-test', 'ROD');
xlabel('signal density');
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(p0_total, P_d_CROD, '-o', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
hold on;
grid on;
plot(p0_total, P_d_CAMP, '-d', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(p0_total, P_d_SDL, '-s', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
plot(p0_total, P_d_ROD, '-+', ...
'Linewidth', Linewidth, ...
'MarkerSize', Markersize);
legend('CROD', 'CAMP', 'SDL-test', 'ROD');
xlabel('signal density');
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,249 @@
clc;
clear;
close all;
%% parameter setting
m = 128;
n = 256;
SNR = 13;
rep_time = 1e4;
P_fa = 1e-2;
p0_total = 0.02: 0.02: 0.2;
len_p0 = length(p0_total);
lambda = 0.1;
sigma_0 = 0.1;
sigma_n = sigma_0;
%% experiment
gamma = m/n;
P_fa_CROD_cnt = zeros(len_p0, rep_time);
P_fa_CAMP_cnt = zeros(len_p0, rep_time);
P_fa_SDL_cnt = zeros(len_p0, rep_time);
P_fa_ROD_cnt = zeros(len_p0, rep_time);
P_fa_LASSO_cnt = zeros(len_p0, rep_time);
P_d_CROD_cnt = zeros(len_p0, rep_time);
P_d_CAMP_cnt = zeros(len_p0, rep_time);
P_d_SDL_cnt = zeros(len_p0, rep_time);
P_d_ROD_cnt = zeros(len_p0, rep_time);
P_d_LASSO_cnt = zeros(len_p0, rep_time);
h_thd = -log(P_fa);
parfor rep = 1: rep_time
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);
% w = w / sqrt(10^(SNR(cnt_SNR)/10));
for cnt_p0 = 1: len_p0
p0 = p0_total(cnt_p0);
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_p0, rep) = sum(stat_CROD(x_idx > thd) > h_thd) / x_l0;
P_d_CROD_cnt(cnt_p0, 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_p0, rep) = sum(stat_CAMP(x_idx > thd) > h_thd) / x_l0;
P_d_CAMP_cnt(cnt_p0, 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_p0, rep) = sum(stat_SDL(x_idx > thd) > h_thd) / x_l0;
P_d_SDL_cnt(cnt_p0, 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_p0, rep) = sum(stat_ROD(x_idx > thd) > h_thd) / x_l0;
P_d_ROD_cnt(cnt_p0, 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(p0_total, P_fa_CROD, 'linewidth', 2);
hold on;
grid on;
plot(p0_total, P_fa_CAMP, 'linewidth', 2);
plot(p0_total, P_fa_SDL, 'linewidth', 2);
plot(p0_total, P_fa_ROD, 'linewidth', 2);
legend('CROD', 'CAMP', 'SDL-test', 'ROD');
xlabel('signal density');
ylabel('P_{fa}');
figure(2);
plot(p0_total, P_d_CROD, 'linewidth', 2);
hold on;
grid on;
plot(p0_total, P_d_CAMP, 'linewidth', 2);
plot(p0_total, P_d_SDL, 'linewidth', 2);
plot(p0_total, P_d_ROD, 'linewidth', 2);
legend('CROD', 'CAMP', 'SDL-test', 'ROD');
xlabel('signal density');
ylabel('P_{d}');
save test_Pfa_Pd_SNR_PF_CROD_CAMP_SDL_ROD_p0.mat ...
p0_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;
@@ -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;