-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakeorthol1test.m
85 lines (66 loc) · 1.85 KB
/
makeorthol1test.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function handles = makeorthol1test(dctrows, n, b, lambda, delta)
fcount = 0;
bothfgcount = 0;
gcount = 0;
function resetcounts()
fcount = 0;
bothfgcount = 0;
gcount = 0;
end
function s = getcounts()
s = struct('fcount', fcount, 'gcount', gcount, ...
'bothfgcount', bothfgcount);
end
function s = fgcount()
s = fcount + gcount + bothfgcount;
end
function y = Ax(x)
y0 = fdct(x);
y = y0(dctrows);
end
function y = At(z)
v = zeros(n,1);
v(dctrows) = z;
y = fdct(v);
end
function fval = localfuneval(y)
fval = norm(Ax(y) - b)^2 / 2 + lambda * sum(sqrt(y.^2 + delta));
fcount = fcount + 1;
end
function [fval,grad]=localfg(y)
Ayb = Ax(y) - b;
sqrty2 = sqrt(y.^2 + delta);
fval = norm(Ayb)^2 / 2 + lambda * sum(sqrty2);
grad = At(Ayb) + lambda * (y ./ sqrty2);
bothfgcount = bothfgcount + 1;
end
function grad = localg(y)
[~,grad] = localfg(y);
gcount = gcount + 1;
end
L = 1 + lambda/sqrt(delta);
%mu = lambda * delta / norm(b,'inf');
%y1max = norm(b)^2 / (2 * lambda) + n * sqrt(delta);
%mu = lambda * delta / (y1max + delta)^3;
bfull = zeros(n,1);
bfull(dctrows) = b;
ystart = fdct(bfull);
btest = fdct(ystart);
assert(norm(btest(dctrows) - b) <= 1e-15 * norm(b))
y1obj = lambda * sum(sqrt(ystart.^2 + delta));
mxentry = sqrt(y1obj^2 / lambda^2 - delta);
mu = lambda * delta / (mxentry^2 + delta)^1.5;
function y = goodstart()
y = ystart;
end
handles = struct('fg', @localfg, ...
'f', @localfuneval, ...
'g', @localg, ...
'L', L, ...
'ell', mu, ...
'n', n, ...
'goodstart', @goodstart, ...
'resetcounts', @resetcounts, ...
'fgcount', @fgcount, ...
'getcounts', @getcounts);
end