-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvb_create_affinity_matrix.m
33 lines (25 loc) · 1.1 KB
/
vb_create_affinity_matrix.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
function A = vb_create_affinity_matrix(neighborhood)
% USE:
% A = vb_create_affinity_matrix(neighborhood)
% Outputs a normalised angle affinity matrix
% Create a mean centered neighborhood
neighborhood_mean = mean(neighborhood,2);
neighborhood_mc = bsxfun(@minus, neighborhood, neighborhood_mean);
neighborhood_mc(neighborhood_mc==0)=eps;
% Normalise the mean centered neighborhood
neighborhood_w = sqrt(sum(neighborhood_mc.^2 , 2));
neighborhood = bsxfun(@rdivide, neighborhood_mc , neighborhood_w);
% Dot product
AFFINITY = neighborhood*neighborhood';
% avoid "correlation" values of above 1 - numerical error that
% leads to complex numbers in AFFINITY
AFFINITY(AFFINITY>.9999999)=1;
% "Linearlise" the AFFINITY (create the normalised angle)
% ensure positive correlations are between 0 to 1
% what i am doing here is to change cosines to angles but to ensure that
% this remains a similarity rather than dissimilarity I am treating the
% values as the sine rather than cosine. I.e. identical signals will be 90
% rather than 0. 90/90 == 1.
A = (asind(AFFINITY) / 90);
% remove negative correlations
A(A<=0) = eps;