Add basic code
This commit is contained in:
@@ -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);
|
||||
@@ -1,82 +0,0 @@
|
||||
% 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
|
||||
@@ -1,11 +0,0 @@
|
||||
function Psi = get_Psi(N, M, epi)
|
||||
Psi = zeros(N,M*N);
|
||||
for n = 0 : N-1
|
||||
Cn = floor(rand()*M);
|
||||
for q = 0 : N-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);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user