Update wide vs narrow code

This commit is contained in:
Ksyer
2024-07-22 21:17:57 +08:00
parent 13f660826d
commit 9cbe8e31ea
14 changed files with 1642 additions and 0 deletions
+95
View File
@@ -0,0 +1,95 @@
function [recovery_results, sigma_w2, thresholds] = All_Recovery2(A, x, P_fa, noise_sigma, trail_times, LASSO_lambda, tau)
sz = size(A);
M = sz(1);
N = sz(2);
recovery_results = zeros(2, trail_times, N);
sigma_w2 = zeros(2, trail_times, 1);
thresholds = zeros(2, trail_times, 1);
for hypo = 2: -1: 1
% hypo-假设
hypo = 3 - hypo;
h = waitbar(0, '正在仿真' + string(hypo-1) + '假设情况');
for T = 1:trail_times
waitbar(T / trail_times, h);
noise = get_noise(noise_sigma, M, 1);
% y = Ax + n
if hypo == 1
y_noise = noise;
else
y_noise = A * x + noise;
end
[x_LASSO, x_hat_d] = cVAMPro(y_noise, A, LASSO_lambda, tau, 100);
% x_LASSO = FISTA(y_noise, A, LASSO_lambda, 1e-5);
sz = size(A);
n = sz(2);
gamma = sz(1) / sz(2);
lambda = LASSO_lambda;
% 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_noise - A*x_LASSO)/Q_hat; % x_d_CROD == x_hat_d
sigma_n = noise_sigma;
% CROD求门限和检验统计量
RSS = sum(abs(y_noise - A * x_LASSO).^2)/length(y_noise);
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;
if sigma_CROD > 1
sigma_CROD = sigma_CROD;
end
sigma_w2(hypo, T) = sigma_CROD^2;
thresholds(hypo, T) = -sigma_CROD^2 * log(P_fa);
% figure; subplot(221); plot(real(x)); subplot(222); plot(real(x_LASSO)); subplot(223); plot(real(x_hat_d)); subplot(224); plot(real(x_d_CROD));
% % data4 folder
% if hypo == 2
% x_hat = x_d_CROD;
% % x_hat = x_hat_d;
% else
% x_hat = x_d_CROD;
% end
% data5 folder
if hypo == 2
x_hat = x_hat_d;
else
x_hat = x_d_CROD;
end
recovery_results(hypo, T, :) = x_hat;
end
close(h);
end
end