-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmy_R.m
33 lines (27 loc) · 1023 Bytes
/
my_R.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
%==========================================================================
%
% Calculating function value and gradient of
% the trained kernel radius function
%
%==========================================================================
% January 13, 2009
% Implemented by Daewon Lee
% WWW: http://sites.google.com/site/daewonlee/
%==========================================================================
function [f,g,H]=my_R(x,model)
d=size(x,2);
n=model.nsv;
[f] = kdist2(x', model); % x: 1 x dim
q=1/(2*model.options.arg^2);
if nargout>1
K=kernel(model.sv.X,x',model.options.ker,model.options.arg); % NSV x 1
g=4*q*model.Alpha'*(repmat(K,1,d).*(repmat(x,n,1)-model.sv.X')); % assuming a Gaussian kernel
end
if nargout>2
const=model.Alpha.*K; % nsv x 1
H=[];
for i=1:d
H=[H -8*q^2*sum(repmat(const',d,1).*(repmat(x(i),d,n)-repmat(model.sv.X(i,:),d,1)).*(repmat(x',1,n)-model.sv.X),2)];
end
H=H+eye(d)*4*q*(model.Alpha'*K);
end