forked from cvjena/knfst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_multiClassNovelty_knfst.m
59 lines (51 loc) · 2.03 KB
/
test_multiClassNovelty_knfst.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
55
56
57
58
59
% Test method for multi-class novelty detection with KNFST according to the work:
%
% Paul Bodesheim and Alexander Freytag and Erik Rodner and Michael Kemmler and Joachim Denzler:
% "Kernel Null Space Methods for Novelty Detection".
% Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2013.
%
% Please cite that paper if you are using this code!
%
%
% function scores = test_multiClassNovelty_knfst(model, Ks)
%
% compute novelty scores using the multi-class KNFST model obtained from learn_multiClassNovelty_knfst
%
% INPUT:
% model -- model obtained from learn_multiClassNovelty_knfst
% Ks -- (n x m) kernel matrix containing similarities between n training samples and m test samples
%
% OUTPUT:
% scores -- novelty scores for the m test samples (distances in the null space)
%
% (LGPL) copyright by Paul Bodesheim and Alexander Freytag and Erik Rodner and Michael Kemmler and Joachim Denzler
%
function scores = test_multiClassNovelty_knfst(model, Ks)
% projected test samples:
projectionVectors = transpose(Ks)*model.proj;
% squared euclidean distances to target points:
squared_distances = squared_euclidean_distances(projectionVectors,model.target_points);
% novelty scores as minimum distance to one of the target points
scores = sqrt( min(squared_distances, [], 2) );
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function distmat = squared_euclidean_distances(x,y)
% function distmat=squared_euclidean_distances(x,y)
%
% computes squared euclidean distances between data points in the rows of x and y
%
% INPUT:
% x -- (n x d) matrix containing n samples of dimension d in its rows
% y -- (m x d) matrix containing m samples of dimension d in its rows
%
% OUTPUT:
% distmat -- (n x m) matrix of pairwise squared euclidean distances
%
distmat = zeros( size(x,1), size(y,1) );
for i=1:size(x,1)
for j=1:size(y,1)
buff=(x(i,:)-y(j,:));
distmat(i,j)=buff*buff';
end
end
end