-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathf_JS_discr.m
More file actions
32 lines (26 loc) · 778 Bytes
/
Copy pathf_JS_discr.m
File metadata and controls
32 lines (26 loc) · 778 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
function JS = f_JS_discr(aij,bij,nbins)
[d1 d2] = size(aij);
[b1 b2] = size(bij);
if (d1 == d2) && (b1 == b2)
% aij, bij are adyacency matrices
% get laplacian and eigenvalues
vaij = f_get_spectrum_lap(aij);
vbij = f_get_spectrum_lap(bij);
else % aij bij are vectors of eigenvalues
vaij = aij;
vbij = bij;
end
ul = max([max(vaij),max(vbij)]);
if nargin < 3
nbins = mean(length(vaij),length(vbij));
nbins = sqrt(nbins);
end
bins = linspace(0,ul,nbins);
pr_aij = hist(vaij,bins);
pr_aij = pr_aij./length(vaij);
pr_bij = hist(vbij,bins);
pr_bij = pr_bij./length(vbij);
pr = (pr_aij + pr_bij)./2;
KLaij = f_kullback_leibler(pr_aij,pr);
KLbij = f_kullback_leibler(pr_bij,pr);
JS = ((KLaij/2) + (KLbij/2))^(1/2);