-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo2DEGStatisticalAnalysis.m
191 lines (165 loc) · 7.09 KB
/
demo2DEGStatisticalAnalysis.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
clear;close all;
addPath;
font_size = 18;
%% Simulate 4 EGs
T = 101;sig = 0.1;
% Create EG1
mainBranch = create2DCurve([0;0],[0.5;1],T,sig);
node1=[0;0];node2=mainBranch(:,25);node3=[-0.1;0.35];node4=mainBranch(:,50);
node5=[0.35;0.55];node6=mainBranch(:,75);node7=[-0.05;0.85];node8=[0.5;1];
nodeXY = [node1 node2 node3 node4 node5 node6 node7 node8];
n = size(nodeXY,2); Abeta = zeros(2,T,n,n);A = zeros(n,n);
i=1;j=2; c = resampleCurve(mainBranch(:,1:25),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=2;j=3; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=2;j=4; c = resampleCurve(mainBranch(:,25:50),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=4;j=5; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=4;j=6; c = resampleCurve(mainBranch(:,50:75),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=6;j=7; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=6;j=8; c = resampleCurve(mainBranch(:,75:end),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=4;j=7; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=2;j=5; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
[G,H,~] = adj2GH(A);
EG1 = struct('Abeta',Abeta,'beta',adj2beta(Abeta,A),'nodeXY',nodeXY,'A',A,'G',G,'H',H);
% Create EG2
i=1;j=2; c = resampleCurve(mainBranch(:,1:25),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=2;j=3; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=2;j=4; c = resampleCurve(mainBranch(:,25:50),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=4;j=5; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=4;j=6; c = resampleCurve(mainBranch(:,50:75),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=6;j=7; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=6;j=8; c = resampleCurve(mainBranch(:,75:end),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=4;j=7; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=2;j=5; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
[G,H,~] = adj2GH(A);
EG2 = struct('Abeta',Abeta,'beta',adj2beta(Abeta,A),'nodeXY',nodeXY,'A',A,'G',G,'H',H);
EG2 = permutateElasticGraphs(EG2,randperm(8));
% Create EG3
i=1;j=2; c = resampleCurve(mainBranch(:,1:25),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=2;j=3; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=2;j=4; c = resampleCurve(mainBranch(:,25:50),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=4;j=5; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=4;j=6; c = resampleCurve(mainBranch(:,50:75),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=6;j=7; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=6;j=8; c = resampleCurve(mainBranch(:,75:end),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=4;j=7; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=2;j=5; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
[G,H,~] = adj2GH(A);
EG3 = struct('Abeta',Abeta,'beta',adj2beta(Abeta,A),'nodeXY',nodeXY,'A',A,'G',G,'H',H);
EG3 = permutateElasticGraphs(EG3,randperm(8));
% Create EG4
i=1;j=2; c = resampleCurve(mainBranch(:,1:25),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=2;j=3; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=2;j=4; c = resampleCurve(mainBranch(:,25:50),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=4;j=5; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=4;j=6; c = resampleCurve(mainBranch(:,50:75),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=6;j=7; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=6;j=8; c = resampleCurve(mainBranch(:,75:end),T);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=4;j=7; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
i=2;j=5; c = create2DCurve(nodeXY(:,i),nodeXY(:,j),T,sig);
Abeta(:,:,i,j) = c; Abeta(:,:,j,i) =fliplr(c);A(i,j)=1;A(j,i)=1;
[G,H,~] = adj2GH(A);
EG4 = struct('Abeta',Abeta,'beta',adj2beta(Abeta,A),'nodeXY',nodeXY,'A',A,'G',G,'H',H);
EG4 = permutateElasticGraphs(EG4,randperm(8));
%% Samples
EG(1) = EG1; EG(2) = EG2;EG(3) = EG3; EG(4) = EG4;
figure
subplot(1,4,1)
plotElasticGraph(EG(1).Abeta,EG(1).A,true,font_size)
axis equal off
subplot(1,4,2)
plotElasticGraph(EG(2).Abeta,EG(2).A,true,font_size)
axis equal off
subplot(1,4,3)
plotElasticGraph(EG(3).Abeta,EG(3).A,true,font_size)
axis equal off
subplot(1,4,4)
plotElasticGraph(EG(4).Abeta,EG(4).A,true,font_size)
axis equal off
sgtitle('Sample EGs')
%% Multiple Matching
EGp = matchMultipleEGs(EG);
for i = 1:length(EGp)
EGpv(i) = interpEGAbeta(EGp(i));
end
figure
subplot(1,4,1)
plotElasticGraph(EGpv(1).Abeta,EGpv(1).A,true,font_size)
axis equal off
subplot(1,4,2)
plotElasticGraph(EGpv(2).Abeta,EGpv(2).A,true,font_size)
axis equal off
subplot(1,4,3)
plotElasticGraph(EGpv(3).Abeta,EGpv(3).A,true,font_size)
axis equal off
subplot(1,4,4)
plotElasticGraph(EGpv(4).Abeta,EGpv(4).A,true,font_size)
axis equal off
sgtitle('Matched Sample EGs')
muEGp = avgEG(EGp);
muEG = avgEG(EG);
figure
subplot(1,2,1)
plotElasticGraph(muEG.Abeta,muEG.A,false)
title('Unmatched Mean')
axis equal off
subplot(1,2,2)
plotElasticGraph(muEGp.Abeta,muEGp.A,false)
axis equal off
title('Matched Mean')
%% PCA
[eigenvectors,scores,latent,explained,mu] = pcaEG(EGp);
figure
subplot(121)
plot(latent,'o-')
title('Singular Value')
subplot(122)
plot(cumsum(explained),'o-')
title('Cumulative Explaination')
sgtitle('PCA')
a = linspace(-2,2,5);
n = length(a);
for i = 1:n
modesEG(i) = getPCAmodes(muEGp,mu,eigenvectors(:,1),latent(1),a(i),2,101,8);
end
figure
for i = 1:(length(a))
subplot(1,5,i)
plotElasticGraph(modesEG(i).Abeta,modesEG(i).A,false)
axis equal off
end
sgtitle('Variations Along 1st PC Direction')