-
Notifications
You must be signed in to change notification settings - Fork 1
/
v2Gv.m
40 lines (30 loc) · 832 Bytes
/
v2Gv.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
function [Gv] = v2Gv(v,g0,g1,g2,h1,W1,W2,indices,regularization)
[subsetSize,backup] = size(v);
if (backup > subsetSize)
subsetSize = backup;
end
v = decompress(v,indices);
[rows1,cols1] = size(W1);
[rows2,cols2] = size(W2);
W1_1 = zeros(rows1,cols1);
W2_1 = zeros(rows2,cols2);
% matricize
for i = 1:rows1
W1_1(i,:) = v((i-1)*cols1 + 1:i*cols1);
end
count = rows1*cols1;
for i = 1:rows2
W2_1(i,:) = v(count + (i-1)*cols2 + 1:count + i*cols2);
end
[W1_2,W2_2] = v2Gv_average(g0,g1,g2,h1,W1_1,W2_1,W1,W2);
% vectorize
for i = 1:rows1
Gv((i-1)*cols1 + 1:i*cols1) = W1_2(i,:);
end
count = rows1*cols1;
for i = 1:rows2
Gv(count + (i-1)*cols2 + 1:count + i*cols2) = W2_2(i,:);
end
Gv = Gv.';
Gv = Gv + regularization*v;
Gv = compress(Gv,indices,subsetSize);