-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfung.m
61 lines (47 loc) · 1.49 KB
/
fung.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
function [memory, g, gA, gB, gC, hA, hB, hC] = fung(memory, A, B, C, OA, OB, OC)
% Part of cost function for DIGRESS --- see paper.
%
% OA, OB, OC are 3D matrices with slices being skew symmetric matrices.
%
% Nicolas Boumal, Oct. 2017.
assert(all(size(A) == size(B)));
assert(all(size(A) == size(C)));
assert(ndims(A) <= 3);
if ~isfield(memory, 'BpC')
memory.BpC = B+C;
end
BpC = memory.BpC;
if ~isfield(memory, 'At')
memory.At = multitransp(A);
end
At = memory.At;
if ~isfield(memory, 'R')
memory.R = multiskew(multiprod(At, BpC));
end
R = memory.R;
if ~isfield(memory, 'g')
memory.g = .5*squeeze(sum(sum(R.^2)));
end
g = memory.g;
if ~isfield(memory, 'gA') || ~isfield(memory, 'gB')
memory.gA = -multiprod(BpC, R);
memory.gB = multiprod(A, R);
end
gA = memory.gA;
gB = memory.gB;
gC = memory.gB;
if nargin == 7
assert(all(size(A) == size(OA)));
assert(all(size(B) == size(OB)));
assert(all(size(C) == size(OC)));
HA = multiprod(A, OA);
HB = multiprod(B, OB);
HC = multiprod(C, OC);
HBpHC = HB + HC;
HAt = multitransp(HA);
HR = multiskew( multiprod(HAt, BpC) + multiprod( At, HBpHC) );
hA = -(multiprod(HBpHC, R) + multiprod(BpC, HR));
hB = multiprod(HA, R) + multiprod(A, HR);
hC = hB;
end
end