source: prextra/change_R.m @ 118

Last change on this file since 118 was 5, checked in by bduin, 14 years ago
File size: 1.4 KB
Line 
1function R = change_R(R,c,beta,gammac)
2% R = change_R(R,c,beta,gammac)
3%
4% Auxiliary function for the incremental SVDD, see there.
5
6% Copyright: D.M.J. Tax, D.M.J.Tax@prtools.org
7% Faculty EWI, Delft University of Technology
8% P.O. Box 5031, 2600 GA Delft, The Netherlands
9
10% Note that n is one larger than set S, because of the
11% added parameter b at the beginning!
12n = size(R,1);
13
14% In some unfortunate cases the gamma_c can be very very small (like 0),
15% and in these cases we don't want to blow up the whole thing. Therefore
16% we define a small eps and define that as the smallest gamma_c
17% possible.
18smalleps = 1e-12;
19
20if c>0                          % we add object c to R
21        if abs(gammac)>smalleps
22                R = [R zeros(n,1); zeros(1,n+1)] + ...
23                        ([beta;1]/gammac)*[beta' 1];
24                % Improve the numerical stability (overflow) for large beta and
25                % gammac, by first dividing by gammac and then multiplying again
26                % by beta.
27                % Fix suggested by Mauro Del Rio
28        else
29                warning('dd_tools:change_R:DivideByZero','We are about to divide by 0.');
30                R = [R zeros(n,1); zeros(1,n+1)] + ...
31                        ([beta;1]/(sign(gammac)*smalleps))*[beta' 1];
32        end
33else                       % we remove object c from R
34        c = -c; % ok, get rid of the sign
35        Irm = [1:c,c+2:n];
36        if R(c+1,c+1)>smalleps  % whatever...
37                R = R(Irm,Irm) - R(Irm,c+1)*R(c+1,Irm)/R(c+1,c+1);
38        else
39                R = R(Irm,Irm) - R(Irm,c+1)*R(c+1,Irm)/smalleps;
40        end
41end
Note: See TracBrowser for help on using the repository browser.