diff --git a/Macroscopic Analysis of VAMP in a MMS/cVAMP.m b/Macroscopic Analysis of VAMP in a MMS/cVAMP.m new file mode 100644 index 0000000..43ba1d4 --- /dev/null +++ b/Macroscopic Analysis of VAMP in a MMS/cVAMP.m @@ -0,0 +1,77 @@ +% Input:y,A,lambda,tau,Kit +% Output:x_hat_wl,x_hat_d + +function [x_hat_wl, x_hat_d] = cVAMP(y, A, lambda, tau, Kit) + % Initialization + gamma = 768 ./ 1024; + k = 0; + p = ctranspose(A) * y; + h_1 = p; + Q_1 = gamma; + tau_d = 1; + + % while + while (k < Kit) && (tau_d > tau) + % Factorized Part + x_1 = ST(h_1, lambda, Q_1); % \hat{x}_1^{(k)} + chi_1 = F1(x_1, lambda, Q_1); % \chi_1^{(k)} + % Message Passing + h_2 = x_1 ./ chi_1 - h_1; % h_2^{(k)} + Q_2 = 1 ./ chi_1 - Q_1; % \hat{Q}_2^{(k)} + % Gaussian Part + t1 = (p + h_2) ./ Q_2; + t2 = ctranspose(A) * (A * (p + h_2)) / ((Q_2 + 1) * Q_2); + x_2 = t1 + t2; % \hat{x}_2^{(k)} + 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) ./ norm(h_1_next); + 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(h_1(i)) .* (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 + v = heaviside(a); +end + +% SoftThreshold function +function v = 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))); + end + + v = count ./ (2 .* N .* Q_1); +end diff --git a/Macroscopic Analysis of VAMP in a MMS/demo1.m b/Macroscopic Analysis of VAMP in a MMS/demo1.m new file mode 100644 index 0000000..a61d6c3 --- /dev/null +++ b/Macroscopic Analysis of VAMP in a MMS/demo1.m @@ -0,0 +1,46 @@ +% Input:y,A,lambda,tau,Kit +% Output:x_hat_wl,x_hat_d +clear; +clc; +% rng(1); % 随机种子 + +%% test_稀疏向量 +% 设定稀疏度 +k = 100; % 设定稀疏度 + +% 构造感知矩阵D +m = 768; % 感知矩阵行数 +n = 1024; % 感知矩阵列数 (n>>m) + +% D = randn(m,n); % 生成满足高斯分布的感知矩阵 64*256 + +F = dftmtx(n); +row_indices = randperm(n, m); +D = F(row_indices, :); + +% 构造稀疏信号X——共n个元素,其中k个元素不为0 +X = zeros(n, 1); +index = randperm(n, k); +val = randn(1, k); +X(index) = val; + +% 得到观测矩阵(压缩后) +A = D * X; + +%% +% % 通过cVMAP算法完成恢复X,得到恢复后信号 +lambda = ones(n, 1) ./ 10; +[x_hat_wl, x_hat_d] = cVAMP(A, D, lambda, 1e-4, 200); + +%% +% 显示结果 +figure; +subplot(3, 1, 1) +stem(X); +title('origin signal') +subplot(3, 1, 2) +stem(x_hat_wl); +title('restored signal') +subplot(3, 1, 3) +stem(X - x_hat_wl); +title('differ')