⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shssvmtrain.m

📁 Matlab codes for Hidden Sapce Support vector machines
💻 M
字号:
function [alpha, bias, svi, nsv ] = shssvmtrain(samplesX,samplesY,kernel,kernelparam,C,threshold)
% 稀疏隐空间支持向量机训练
if (nargin ~= 6) % check correct number of arguments
    help shssvm
  else

    fprintf('Sparse hidden space svm training ....\n')
    fprintf('______________________________\n')
    n = size(samplesX,1);

    % tolerance for Support Vector Detection
    tol = 1e-4;

    % Construct the Kernel matrix
    fprintf('Constructing ...\n');
    K = zeros(n,n);  
    st = cputime;
    for i=1:n
          K(:,i) = bsvkernel(samplesX,samplesX(i*ones(n,1),:),kernel,kernelparam);
    end
    
    % Set up the parameters for the Optimisation problem
    R = K'*K;
    Q = K'*ones(n,1);
    S = K'*samplesY;
    if threshold
        H = [R -R Q; -R R -Q; Q' -Q' n];
        c = [-S+ones(n,1)/C; S+ones(n,1)/C; -ones(1,n)*samplesY];
    else
        H = [R -R; -R R];
        c = [-S+ones(n,1)/C; S+ones(n,1)/C];
        bias =0;
    end
     A = [];
     b = [];
  
    % Solve the Optimisation Problem
    
    fprintf('Optimising ...\n');
    [w,y,z,s,t,flag] = quadsolve(H,c,A,b,10);
    fprintf('Execution time : %4.1f seconds\n',cputime - st);
     % Compute the number of Support Vectors
     w1 = w(1:n);
     w2 = w(n+1:2*n);
     if threshold
         bias = w(2*n+1);
     end
     alpha = w1-w2;
     svi = find( abs(alpha) >tol );
     nsv = length( svi );
     fprintf('Support Vectors : %d (%3.1f%%)\n',nsv,100*nsv/n);

end

    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -