[5] | 1 | function K = inckernel(par,I,J); |
---|
| 2 | %INCKERNEL Kernel definition for incsvdd |
---|
| 3 | % |
---|
| 4 | % K = INCKERNEL(PAR,I,J); |
---|
| 5 | % |
---|
| 6 | % Computation of the kernel function for the incremental SVDD. It is |
---|
| 7 | % assumed that there is a global variable X_incremental, containing the |
---|
| 8 | % objects. This is to avoid unnecessary overhead for very large |
---|
| 9 | % datasets. Therefore we will also not use the 'standard' ways to comute |
---|
| 10 | % the kernel (i.e. proxm). |
---|
| 11 | % |
---|
| 12 | % The kernel is defined by PAR. We assume that PAR is a structure |
---|
| 13 | % containing: |
---|
| 14 | % PAR.type the kernel type |
---|
| 15 | % 'kernel' | 'k': X_incremental(I,J) |
---|
| 16 | % 'polynomial' | 'p': sign(xI*xJ'+1).*(xI*xJ'+1).^s |
---|
| 17 | % 'exponential' | 'e': exp(-(||xI-xJ||)/s) |
---|
| 18 | % 'radial_basis' | 'r': exp(-(||xI-xJ||.^2)/(s*s)) |
---|
| 19 | % 'sigmoid' | 's': sigm((sign(xI*xJ').*(xI*xJ'))/s) |
---|
| 20 | % 'distance' | 'd': ||xI-xJ||.^s |
---|
| 21 | % And the special case: |
---|
| 22 | % 'inline' | 'i': use s as an inline function |
---|
| 23 | % PAR.s the free parameter, |
---|
| 24 | % when more than 1 free parameter is required, then par.s |
---|
| 25 | % can be a vector of length 2 or more. |
---|
| 26 | % The index vectors I and J indicate between which objects in |
---|
| 27 | % X_incremental the kernel should be computed. |
---|
| 28 | % |
---|
| 29 | % See also: incsvdd, proxm |
---|
| 30 | |
---|
| 31 | % Copyright: D. Tax, R.P.W. Duin, davidt@ph.tn.tudelft.nl |
---|
| 32 | % Faculty of Applied Physics, Delft University of Technology |
---|
| 33 | % P.O. Box 5046, 2600 GA Delft, The Netherlands |
---|
| 34 | |
---|
| 35 | if nargin<2 |
---|
| 36 | I = []; |
---|
| 37 | J = []; |
---|
| 38 | end |
---|
| 39 | |
---|
| 40 | global X_incremental; |
---|
| 41 | if isempty(X_incremental) |
---|
| 42 | error('No data matrix X_incremental defined'); |
---|
| 43 | end |
---|
| 44 | if isa(X_incremental,'dataset'); |
---|
| 45 | error('Please make X_incremental a normal matlab array'); |
---|
| 46 | end |
---|
| 47 | |
---|
| 48 | A = X_incremental(I,:); |
---|
| 49 | B = X_incremental(J,:); |
---|
| 50 | |
---|
| 51 | switch par.type |
---|
| 52 | case {'kernel' 'k'} |
---|
| 53 | if isempty(I) & isempty(J) |
---|
| 54 | K = X_incremental; |
---|
| 55 | else |
---|
| 56 | K = X_incremental(I,J); |
---|
| 57 | end |
---|
| 58 | case {'polynomial' 'p'} |
---|
| 59 | K = A*B'; |
---|
| 60 | [n,d] = size(A); |
---|
| 61 | [m,d] = size(B); |
---|
| 62 | if par.s ~= round(par.s) |
---|
| 63 | K = K + ones(n,m); |
---|
| 64 | K = sign(K).*abs(K).^par.s; |
---|
| 65 | elseif par.s ~= 1 |
---|
| 66 | K = K + ones(n,m); |
---|
| 67 | K = K.^par.s; |
---|
| 68 | end |
---|
| 69 | case {'sigmoid' 's'} |
---|
| 70 | K = A*B'; |
---|
| 71 | if length(par.s)>1 |
---|
| 72 | K = sigm(K/par.s(1) + par.s(2)); %DXD: I need this sometimes |
---|
| 73 | else |
---|
| 74 | K = sigm(K/par.s); |
---|
| 75 | end |
---|
| 76 | case {'exponential' 'e'} |
---|
| 77 | K = sqeucldistm(A,B); |
---|
| 78 | J = find(K<0); |
---|
| 79 | K(J) = zeros(size(J)); |
---|
| 80 | K = exp(-sqrt(K)/par.s); |
---|
| 81 | case {'radial_basis' 'r'} |
---|
| 82 | K = sqeucldistm(A,B); |
---|
| 83 | J = find(K<0); |
---|
| 84 | K(J) = zeros(size(J)); |
---|
| 85 | K = exp(-K/(par.s*par.s)); |
---|
| 86 | case {'inv_radial_basis' 'i'} |
---|
| 87 | K = sqeucldistm(A,B); |
---|
| 88 | J = find(K<0); |
---|
| 89 | K(J) = zeros(size(J)); |
---|
| 90 | K = exp(sqrt(K)/par.s); |
---|
| 91 | case {'distance' 'd'} |
---|
| 92 | K = sqeucldistm(A,B); |
---|
| 93 | J = find(K<0); |
---|
| 94 | K(J) = zeros(size(J)); |
---|
| 95 | if par.s ~= 2 |
---|
| 96 | K = K.^(par.s/2); |
---|
| 97 | end |
---|
| 98 | case {'inline' 'i'} |
---|
| 99 | error('Sorry, this does not work yet.'); |
---|
| 100 | case {'combp1s2'} |
---|
| 101 | K = sqeucldistm(A,B); |
---|
| 102 | J = find(K<0); |
---|
| 103 | K(J) = zeros(size(J)); |
---|
| 104 | K = exp(-K/(2*2)); |
---|
| 105 | K = par.s*A*B' + (1-par.s)*K; |
---|
| 106 | otherwise |
---|
| 107 | error(sprintf('Unknown proximity type: %s',par.type)) |
---|
| 108 | end |
---|
| 109 | |
---|
| 110 | return |
---|