-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTotal_variation_minimization.m
42 lines (31 loc) · 1.19 KB
/
Total_variation_minimization.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
% Total variation denoising with random data
%% Generate problem data
rand('seed', 0);
randn('seed', 0);
n = 100;
x0 = ones(n,1);
for j = 1:3
idx = randsample(n,1);
k = randsample(1:10,1);
x0(ceil(idx/2):idx) = k*x0(ceil(idx/2):idx);
end
b = x0 + randn(n,1);
lambda = 5;
e = ones(n,1);
D = spdiags([e -e], 0:1, n,n);
%% Solve problem
[x history] = total_variation(b, lambda, 1.0, 1.0);
%% Reporting
K = length(history.objval);
h = figure;
plot(1:K, history.objval, 'k', 'MarkerSize', 10, 'LineWidth', 2);
ylabel('f(x^k) + g(z^k)'); xlabel('iter (k)');
g = figure;
subplot(2,1,1);
semilogy(1:K, max(1e-8, history.r_norm), 'k', ...
1:K, history.eps_pri, 'k--', 'LineWidth', 2);
ylabel('||r||_2');
subplot(2,1,2);
semilogy(1:K, max(1e-8, history.s_norm), 'k', ...
1:K, history.eps_dual, 'k--', 'LineWidth', 2);
ylabel('||s||_2'); xlabel('iter (k)');