-
Notifications
You must be signed in to change notification settings - Fork 3
/
metricUpgrade.m
123 lines (96 loc) · 2.56 KB
/
metricUpgrade.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
function [V_upg,K] = metricUpgrade( V )
% [V_upg,K] = metricUpgrade( V )
% Compute matrix K such that V*K is closest to the primal feasible domain.
%
% Note: For convenience V is treated as a column block-vector with
% (3 x k) blocks, so we store the nullspace basis V as a blkmat object.
%
% See also blkmat
% Assert the input is a block matrix
s = size(V);
k = s(2);
if ~isa(V,'blkmat')
n = s(1)/3;
V = blkmat(n,1,3,k,V);
end
% Compute the quadratic form matrices
n = numel(V);
A = zeros(k^2); b = zeros(k^2,1);
for i=1:n
W = V(i)'*V(i);
A = A + kron(W,W);
b = b + vec(W);
end
c = n*3;
f_vec = @(S) vec(S)'*A*vec(S) - 2*b'*vec(S) + c;
% Project quadratic form to its symmetric vectorization
% using vec(S) = P'*vecs(S)
P = build_vec2vecsProj( k );
A = P*A*P';
b = P*b;
f_vecs = @(S) vecs(S)'*A*vecs(S) - 2*b'*vecs(S) + c;
% DEBUG: Check validity of equivalent representations
% K = randn(k,k);
% sum_Frob(V,K)
% f_vec(K*K')
% f_vecs(K*K')
% keyboard
% Solve minimum for the proximity cost
s_optim = A\b;
% Undo the symmetric vectorization
S_optim = avecs(s_optim);
% Get original linear metric upgrade K so that S=K*K'
% This is done with SVD decomposition
[U,D,~] = svd(S_optim);
if k == 3
K = U*sqrt(D);
else
% If the rank is higher than 3, take the largest singular values
K0 = U(:,1:3)*sqrt(D(1:3,1:3));
% And refine the non-convex problem
% This non-linear refinement is done with Manopt
K = refine_fixedRank(A,b,K0);
end
% Get new linear combination
V_upg = V*K;
end
% TEMPORAL: For debug purposes
function f = sum_Frob( V,K )
% This function encodes the feasibility metric as defined in the paper
n = numel(V);
I_3 = eye(3);
f = 0;
for i=1:n
f = f + norm( K'*V(i)'*V(i)*K - I_3, 'fro' )^2;
end
end
function [K] = refine_fixedRank(A,b,K0)
% Function with non-convex optimization of fixed-rank matrix
% for the case k>3. It uses Manopt toolbox.
k = size(K0,1);
K = symfixedrankYYfactory(k,3);
problem.M = K;
problem.cost = @cost;
problem.grad = @grad;
% checkgradient(problem);
% Solve.
% X0 = []; % Random for now (uninitialized)
opts = struct();
% opts.verbosity = 0;
[K, Scost, info, options] = trustregions(problem,K0,opts);
function f = cost(Y)
s = vecs(Y*Y');
f = 0.5*s'*A*s - b'*s;
end
function g = grad(Y)
% Objective part
s = vecs(Y*Y');
der_g_s = (A*s-b)';
% Formulation part
dervec_S_Y = ( eye(k^2) + build_vecProj(k,k) ) * kron(Y,eye(k));
% Compose (chain rule)
dervec_g_Y = der_g_s * build_vec2vecsProj(k) * dervec_S_Y;
% Reshape to Y matrix
g = reshape(dervec_g_Y, size(Y));
end
end