-
Notifications
You must be signed in to change notification settings - Fork 1
/
VSPSolver.m
65 lines (53 loc) · 1.64 KB
/
VSPSolver.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function [x,v] = VSPSolver(y,A,K,beta,alpha)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
n = size(A,2);
m = size(y,1);
rho = K/n;
a = 1e-10;
b = 1e-10;
c = 1e-10;
d = 1e-10;
iter = 0;
iter_mx = 80;
alpha_new = ones(n,1);
D = diag(alpha_new);
sigma2 = 1;
var_new = inv(A'*A/sigma2+D);
mu_new = 1/sigma2*var_new*A'*y;
% gamma_new = 1/sigma2;
while iter<iter_mx %&& norm(mu_new-mu_old)>1e-6
iter = iter + 1;
omega = diag(var_new) + mu_new .* conj(mu_new);
alpha_new = (1+2*a) ./ (omega+2*b);
idx1 = find(alpha_new>1e10);
alpha_new(idx1) = 1e10;
if mod(iter,30)==0
v_old = 1./alpha_new;
max_in = mean(maxk(v_old,K));
factor_in = 1/ max_in ;
v_old = factor_in * v_old;
v_old = min(v_old,1);
%v_old(find(v_old>1e-2)) = 1;
% [ v_new, ~, ~ ] = SPD_MC(v_old, K/n, L/K );
[v_new,~] = SPD_MRF1D(v_old.', beta, alpha, 100);
v_new = v_new.';
% v_new = v_new / rho;
% max_out = mean(maxk(v_new,K));
% factor_out = 1 / rho / max_out;
v_new = v_new / factor_in;
alpha_new = 1./v_new;
end
D = diag(alpha_new);
%=============================================
% estimate the variance of noise
num=(y-A*mu_new)'*(y-A*mu_new)+trace(var_new*A'*A)+2*d;
den=m+2*c;
sigma2=num/den;
%==============================================
var_new=inv(A'*A/sigma2+D);
mu_new=1/sigma2*var_new*A'*y;
end
x = mu_new;
v = diag(var_new);
end