Code covered by the BSD License  

Highlights from
Geometric Gaussian-Kernel Bolstered Error Estimation for Linear Classification

image thumbnail

Geometric Gaussian-Kernel Bolstered Error Estimation for Linear Classification

by

 

This is fast implementation of bolstered error estimation algorithm for linear SVM classification.

bolster.m
function [err_bol, err_resub,sigmas] = bolster(P,T,sw,sb,flag)
% Geometrical bolstered and semibolstered error estimation for linear
% classification and spherical bolstering
% Input:
% P - m-by-n vector, where m is a number of objects, n is a number of features
% T - 1-by-n column vector of class labels
% sw - hyperplane coefficients
% sb - hyperplane intercept
% flag - if flag is 'semi', semibolstered error estimation is calculated
% Output:
% err_bol - bolstered error estimator
% err_resub - resubstitution error estimation
% Author: Arsen Arakelyan, arakelyanaa@zoho.com
% Reference: Braga-Neto, U., Dougherty, E., 2004. Bolstered error estimation.
%            Pattern Recognition 37, 12671281.

% Check arguments
if nargin < 5
    flag = 'full';
elseif nargin < 4
    error('At least 4 coefficients are exptected');
end

sigmas = [];
dims = size(P,2);
c = unique(T); % number of classes
lc = length(c);
if dims > 1 % just for fun
    k = 0;
else
    k = 0;
end
FD = chi2inv(0.5,dims-k)^0.5;
err_resub = zeros(size(c));
err_bol = zeros(size(c));

for i = 1:lc
    data =  P(T==c(i),:);
    ldata = size(data,1);
    d2 = sum(data'.^2,1)';
    dist1 = repmat(d2',ldata,1) + repmat(d2,1,ldata) - 2*(data*data');
    dist1 = sort(dist1,1,'ascend');
    dmin1 = mean(sqrt(dist1(2,:)));
    sigma = dmin1/FD;
    sigmas = [sigmas,sigma];
    W = sw*data'+sb;
    Wa = W./norm(sw); % Normalized distance from hyperplane
    Tpr = -1*Wa>0; % predicted class
    Tact = T(T==c(i)); % actual class
    misclass = logical(abs(Tact-Tpr'));
    err_resub(i) = sum(misclass)/length(Tact); % resubstitution error
    if c(i)==1 % shift positive values
        Wa = -1*Wa;
        x = Wa-sigma;
    else
        x = Wa-sigma;
    end
    cap_height = (sigma-Wa).*(x<0);
%   Calculation of volume of n-dimensional sphere and cap
    [V_cap,V_full] = spherecapbetainc(dims,sigma,cap_height);
    V(i,:) = V_cap/V_full;
    if strcmp(flag,'semi') % semibolstered error estimation
        if any(misclass)
            V(i,misclass) = 1;
        end
    end
end
err_resub = mean(err_resub); %total resubstitution error estimator
err_bol = mean(reshape(V,1,numel(V))); % total bolstered error estimator


Contact us