-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompute_diffusion_kernel.m
More file actions
39 lines (32 loc) · 928 Bytes
/
compute_diffusion_kernel.m
File metadata and controls
39 lines (32 loc) · 928 Bytes
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
function K = compute_diffusion_kernel(A,normalization)
% compute_normalized_kernel - compute a diffusion kernel from a weight/adjacency matrix
%
% K = compute_diffusion_kernel(A);
%
% A is a (n,n) adjacency matrix or a weight matrix
% A(i,j) is the weigth between points, e.g.
% A(i,j) = exp( -|xi-xj|^2/sigma^2 )
% if normalization==1, perform full normalization (ie. K will be symmetric)
% otherwise, just do row equalisation (ie. the row will sum to one, the
% matrix is stochastic)
%
% Copyright (c) 2005 Gabriel Peyr
if nargin<2
normalization = 1;
end
N = size(A,1);
if normalization==1
D = sparse([1:N], [1:N], 1./sum(A), N, N, N);
A = D * A * D;
D = sum(A);
for j=1:N
for k=1:j
A(j,k) = (1/sqrt(D(j))) * (1/sqrt(D(k))) * A(j,k);
A(k,j) = A(j,k);
end
end
else
D = sparse(diag(1./sum(A)));
A = D * A;
end
K = sparse(A);