-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaplacian.m
49 lines (39 loc) · 1.03 KB
/
laplacian.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
function L = laplacian(DATA, TYPE, PARAM)
% Calculate the graph laplacian of the adjacency graph of data set DATA.
%
% L = laplacian(DATA, TYPE, PARAM)
%
% DATA - NxK matrix. Data points are rows.
% TYPE - string 'nn' or string 'epsballs'
% PARAM - integer if TYPE='nn', real number if TYPE='epsballs'
%
% Returns: L, sparse symmetric NxN matrix
%
% Example:
%
% L = laplacian(X,'nn',6)
% L contains the Laplacian of the graph obtained from connecting
% each point of the data set to its 6 nearest neigbours.
%
%
% Author:
%
% Mikhail Belkin
%
disp(' ');
disp('Laplacian Egenmaps Embedding.');
% calculate the adjacency matrix for DATA
A = adjacency(DATA, TYPE, PARAM);
W = A;
% disassemble the sparse matrix
[A_i, A_j, A_v] = find(A);
for i = 1: size(A_i)
% replece distances by 1
% gaussain kernel can be used instead of 1:
% W(A_i(i), A_j(i)) = exp(-A_v^2/t);
W(A_i(i), A_j(i)) = 1;
end;
disp('Computing Laplacian eigenvectors.');
D = sum(W(:,:),2);
L = spdiags(D,0,speye(size(W,1)))-W;