Add basic code

This commit is contained in:
Ksyer
2024-07-16 15:54:44 +08:00
parent 088f1a82fd
commit e98983b374
5 changed files with 65 additions and 43 deletions
-42
View File
@@ -1,42 +0,0 @@
%% 参数设置
N = 16;
M = 4;
A = get_Psi(N, M, 0);
%% 检查每一行 / 列的二范数
col_norms = zeros(N, 1);
for i = 1: N
col_norms(i) = norm(A(i, :), 2);
end
row_norms = zeros(N * M, 1);
for i = 1: N * M
row_norms(i) = norm(A(:, i), 2);
end
figure(1);
subplot(211);
plot(1: N, col_norms);
xlabel("Col");
ylabel("L2 norm of col");
title("L2 norm of cols");
subplot(212);
plot(1: N * M, row_norms);
xlabel("Row");
ylabel("L2 norm of row");
title("L2 norm of rows");
%%
AH = conj(A).';
figure(2);
result = abs(A * AH);
subplot(211);
plot(diag(result));
subplot(212);
heatmap(result);
a = sum(result(:)) - sum(diag(result));
fprintf("%f", a);
+31
View File
@@ -0,0 +1,31 @@
function [x_hat, threshold] = debiased_LASSO(A, y_noise, P_fa, noise_sigma_2)
sz = size(A);
N = sz(2);
LASSO_lambda = 2;
gamma = sz(1) / sz(2);
cvx_begin quiet
variable x_LASSO(N) complex
minimize(LASSO_lambda * norm(x_LASSO, 1) + norm(y_noise - A * x_LASSO, 2))
cvx_end
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 - LASSO_lambda./(Q_hat*abs(x_LASSO) + LASSO_lambda))) / 2 / N;
diff = 1;
while(diff > 1e-4)
Rho_pre = Rho;
Rho = sum((abs(x_LASSO) > 1e-3).* (2 - LASSO_lambda./((gamma-Rho)/(1-Rho)*abs(x_LASSO) + 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_hat = x_d_CROD;
RSS = 1/sz(2) * norm(y_noise - A*x_LASSO, 2) ^ 2;
sigma_w_2 = (gamma * (1 - gamma)) / ((gamma - Rho)^2) * RSS + noise_sigma_2;
threshold = -sigma_w_2 * log(P_fa);
end
+5 -1
View File
@@ -1,11 +1,15 @@
function Psi = get_Psi(N, M, epi) function Psi = get_Psi(N, M, epi)
Psi = zeros(N,M*N); Psi = zeros(N,M*N);
for n = 0 : N-1 for n = 0 : N-1
col = zeros(1, M*N);
Cn = floor(rand()*M); Cn = floor(rand()*M);
for q = 0 : N-1 for q = 0 : N-1
for p = 0:M-1 for p = 0:M-1
Psi(n+1,q*M+p+1) = exp(1i*2*pi*p/M*Cn+1i*2*pi*q/N*n*(1+Cn*epi)) / sqrt(N); f1 = p/M*Cn;
f2 = q/N*n*(1+Cn*epi);
col(q*M+p+1) = exp(1j*2*pi*(f1 + f2));
end end
end end
Psi(n+1, :) = col;
end end
end end
+29
View File
@@ -0,0 +1,29 @@
function Psi = get_Psi_KR_product(N, M, epi)
d_n = floor(rand(N, 1)*M) / M;
zeta_n = 1 + d_n .* epi; % epi = B / f_c
R = zeros(N, M);
D = zeros(N, N);
for n = 0: N-1
for m = 0: M-1
R(n+1, m+1) = exp(-1j * 2 * pi * m * d_n(n+1));
end
end
for n = 0: N-1
for l = 0: N-1
D(n+1, l+1) = exp(-1j * 2 * pi * l * n * zeta_n(n+1) / N);
end
end
Psi = KR_product(R', D')';
end
function kr = KR_product(F, G)
nR_F = size(F, 1);
nR_G = size(G, 1);
mul = ones(nR_G, 1);
FF = kron(F, mul);
GG = repmat(G, nR_F, 1);
kr = FF .* GG;
end