-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkdist2.m
49 lines (43 loc) · 1.6 KB
/
kdist2.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
function d=kdist2(X,model)
%==========================================================================
% KDIST2 Computes squared distance between vectors in kernel space.
%
% Synopsis:
% d = kdist2(X,model)
%
% Description:
% It computes distance between vectors mapped into the feature
% space induced by the kernel function (model.options.ker,
% model.options.arg). The distance is computed between images
% of vectors X [dim x num_data] mapped into feature space
% and a point in the feature space given by model:
%
% d(i) = kernel(X(:,i),X(:,i))
% - 2*kernel(X(:,i),models.sv.X)*model.Alpha + b,
%
% where b [1x1] is assumed to be equal to
% model.b = model.Alpha'*kernel(model.sv.X)*model.Alpha.
%
% Input:
% X [dim x num_data] Input vectors.
% model [struct] Deternines a point of the feature space:
% .Alpha [nsv x 1] Multipliers.
% .sv.X [dim x nsv] Vectors.
% .b [1x1] Bias.
% .options.ker [string] Kernel identifier (see 'help kernel').
% .options.arg [1 x nargs] Kernel argument(s).
%
% Output:
% d [num_data x 1] Squared distance between vectors in the feature space.
%
%==========================================================================
% January 13, 2009
% Implemented by Daewon Lee
% WWW: http://sites.google.com/site/daewonlee/
%==========================================================================
[dim,num_data]=size(X);
x2 = diagker( X, model.options.ker, model.options.arg);
Ksvx = kernel( X, model.sv.X, model.options.ker, model.options.arg);
d = x2 - 2*Ksvx*model.Alpha(:) + model.b*ones(num_data,1) ;
return;
% EOF