-
Notifications
You must be signed in to change notification settings - Fork 1
/
EXAMPLE.hodgelaplacian.m
196 lines (163 loc) · 5.63 KB
/
EXAMPLE.hodgelaplacian.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
192
193
194
195
196
% Example showing how to compute the Hodge Laplacian explained in
%
% Anand, D.V., Dakurah, S., Chung, M.K. 2022
% Hodge-Laplacian of brain networks and its application to modeling cycles.
% arXiv:2110.14599
%
% Dakurah, S., Anand, D.V., Chen, Z., Chung, M.K. 2022 Modeling cycles in
% brain networks with the Hodge Laplacian, MICCAI LNCS 13431:326-335.
%
%https://github.com/laplcebeltrami/hodge/blob/main/dakurah.2022.MICCAI.pdf
%% https://arxiv.org/pdf/2110.14599v1.pdf
%% Version 1 of arXiv has detailed explanation of Figure 2 example in Page 8.
%
%
% The code downloaded from https://github.com/laplcebeltrami/hodge
%
% (C) 2022 Moo K. Chung
% University of Wisconsin-Madison
%
% Contact mkchung@wisc.edu for the maintainance of codes and support.
%
% Update history
% 2022 Septermber 28, crediated Moo Chung
%% Figure 2 example in the paper
%boundary operator (# of nodes x # of edges)
%This is the indidence matrix in graph theory
B1= [-1 -1 0 0 0 0
1 0 -1 -1 0 0
0 1 1 0 -1 0
0 0 0 1 0 -1
0 0 0 0 1 1];
%boundary operator (# of edges x # of triangles)
B2 = [1
-1
1
0
0
0]
%1st Hodge Laplacian. This include the filled-in triangle.
%In Anand's paper, we simply ignored the filled-in triangle so
%L1 = B1'*B1
% If you want to have B2, you MUST define a rule for forming a connectiity
% of 3 nodes.
L1 = B1'*B1 + B2*B2'
%L1=[3 0 0 -1 0 0
% 0 3 0 0 -1 0
% 0 0 3 1 -1 0
% -1 0 1 2 0 -1
% 0 -1 -1 0 2 1
% 0 0 0 -1 1 2]
[V1, D1]= eig(L1)
%There is only one cycle so we have 1 zero eigenvalue.
%The first column of V1 corresponds to the cycle.
%V1 =
%
% 0.1741 0.3717 -0.2409 -0.5774 -0.6015 -0.2799
% -0.1741 0.3717 0.2409 0.5774 -0.6015 0.2799
% -0.3482 -0.0000 0.4817 -0.5774 0.0000 0.5598
% 0.5222 0.6015 -0.1489 -0.0000 0.3717 0.4529
% -0.5222 0.6015 0.1489 0.0000 0.3717 -0.4529
% 0.5222 0.0000 0.7795 0.0000 -0.0000 -0.3460
%eigenvalues
%D1 =
% -0.0000 0 0 0 0 0
% 0 1.3820 0 0 0 0
% 0 0 2.3820 0 0 0
% 0 0 0 3.0000 0 0
% 0 0 0 0 3.6180 0
% 0 0 0 0 0 4.6180
%Filled-in triangle is simply ignored. So there is a cycle. Then
%Hodge Laplacian is simply L1 = B0'B0 + B1*B1', where B0 is 0.
L1simple = B1'*B1
%L1simple=
% 2 1 -1 -1 0 0
% 1 2 1 0 -1 0
% -1 1 2 1 -1 0
% -1 0 1 2 0 -1
% 0 -1 -1 0 2 1
% 0 0 0 -1 1 2
%-----------------
%Using Anand's codes on the same example
% Adjacency matrix
% In practice, we obtain this by thresholding correleation matrix.
% The rule for where to treshold should be emprically determined.
% In Anand's paper, we thresholded at zero.
ConnMat = [ 0 1 1 0 0
1 0 1 1 0
1 1 0 0 1
0 1 0 0 1
0 0 1 1 0]
%Visual check: MATLAB format of graph constructed as structued array
graphmat = graph(ConnMat)
figure; plot(ans)
% Generate k-skeleton from a given adjacency matrix
kSkeleton = Hodge_1Skeleton(ConnMat)
%kSkeleton =
% 1×2 cell array consisting of nodes set and edge set
% {5×1 double} {6×2 double}
%kSkeleton{1} :Node set
%ans =
% 1
% 2
% 3
% 4
% 5
%kSkeleton{2} :Edge set
%ans =
% 1 2
% 1 3
% 2 3
% 2 4
% 3 5
% 4 5
% Create boundary matrix from the k-Skeleton
IncidenceMat= Hodge_incidence(kSkeleton);
%IncidenceMat =
% 1×2 cell array
% {0×0 double} {5×6 double}
%IncidenceMat{2}
%ans =
% -1 -1 0 0 0 0
% 1 0 -1 -1 0 0
% 0 1 1 0 -1 0
% 0 0 0 1 0 -1
% 0 0 0 0 1 1
% Ignoring the sign, it exactly matches to boundary matrix B1
% computed by hand above
% Create Hodge Laplacian matrix from the boundary matrix
Laplacemat=Hodge_laplacian(IncidenceMat);
%
%Laplacemat =
% 2 1 -1 -1 0 0
% 1 2 1 0 -1 0
% -1 1 2 1 -1 0
% -1 0 1 2 0 -1
% 0 -1 -1 0 2 1
% 0 0 0 -1 1 2
% Eigenvectors corresponding to the kernel of Hodge Laplacian matrix
[EigVector,~] = Hodge_ker(Laplacemat);
%Since we ignored filled-in triangle, there should be 2 cycles.
%EigVector =
% 0.5692 -0.1992
% -0.5692 0.1992
% 0.5921 0.3225
% -0.0229 -0.5217
% 0.0229 0.5217
% -0.0229 -0.5217
%The above function is same as
[V1, D1]= eig(Laplacemat)
%V1 =
% 0.5692 -0.1992 -0.3717 -0.2409 -0.6015 -0.2799
% -0.5692 0.1992 -0.3717 0.2409 -0.6015 0.2799
% 0.5921 0.3225 -0.0000 0.4817 0 0.5598
% -0.0229 -0.5217 -0.6015 -0.1489 0.3717 0.4529
% 0.0229 0.5217 -0.6015 0.1489 0.3717 -0.4529
% -0.0229 -0.5217 -0.0000 0.7795 -0.0000 -0.3460
%D1 =
% -0.0000 0 0 0 0 0
% 0 -0.0000 0 0 0 0
% 0 0 1.3820 0 0 0
% 0 0 0 2.3820 0 0
% 0 0 0 0 3.6180 0
% 0 0 0 0 0 4.6180