-
Notifications
You must be signed in to change notification settings - Fork 1
/
SDM_nov.m
55 lines (38 loc) · 1.3 KB
/
SDM_nov.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
% Function to give self similarity matrix
% Input : Kw-> floor(Kernel Width/2)
% : dist_measure->Distance measure for SDM computation
% : As per the matlab version and the distances allowed
% : feature-> Feature matrix
% Output : Similarity matrix sim_mat
% : Novelty score
% Example Usage:
% [sim_mat,nov_score]=SDM_nov(50,'Euclidean',feature);
function [sim_mat,nov_score]= SDM_nov(Kw,dist_measure,feature)
%%% make a kernel of 2*Kw+1
zv=zeros(Kw,1);
zh=zeros(1,2*Kw+1);
pos_mat=ones(Kw,Kw);
neg_mat=-1*ones(Kw,Kw);
kernel=horzcat(neg_mat,zv,pos_mat);
kernel=vertcat(kernel,zh);
kernel1=horzcat(pos_mat,zv,neg_mat);
kernel=vertcat(kernel,kernel1);
win = fspecial('gaussian',size(kernel),4);
win = win ./ max(win(:));
kernel=kernel.*win;
% Make a similarity matrix
sim_mat=pdist2(feature,feature,dist_measure);
%matlab 2009 doesnt have pdist2 so comment the line32 of pdist2 and
%uncomment the 2lines below
% sim_mat=pdist(feature,dist_measure);
% sim_mat=squareform(sim_mat);
nov_score=zeros(length(sim_mat),1);
% kernel multiplication along diagonal to obtain the novelty score
for i=Kw+1:length(sim_mat)-Kw-1
for k1=-Kw:Kw
for k2=-Kw:Kw
temp_chk(k1+Kw+1,k2+Kw+1)= sim_mat(i+k1,i+k2);
end
end
nov_score(i)=sum(sum(temp_chk.*kernel));
end