• 大小: 4.58MB
    文件类型: .rar
    金币: 2
    下载: 0 次
    发布日期: 2024-01-31
  • 语言: Matlab
  • 标签: SVM  

资源简介

印章识别效果非常好的代码,主要使用了支持向量机

资源截图

代码片段和文件信息

function [nsv alpha b0] = svc(XYkerC)
%SVC Support Vector Classification
%
%  Usage: [nsv alpha bias] = svc(XYkerC)
%
%  Parameters: X      - Training inputs
%              Y      - Training targets
%              ker    - kernel function
%              C      - upper bound (non-separable case)
%              nsv    - number of support vectors
%              alpha  - Lagrange Multipliers
%              b0     - bias term
%
%  Author: Steve Gunn (srg@ecs.soton.ac.uk)

  if (nargin <2 | nargin>4) % check correct number of arguments
    help svc
  else

    fprintf(‘Support Vector Classification\n‘)
    fprintf(‘_____________________________\n‘)
    n = size(X1);
    if (nargin<4) C=Inf; end
    if (nargin<3) ker=‘linear‘; end

    % tolerance for Support Vector Detection
    epsilon = svtol(C);
    
    % Construct the Kernel matrix
    fprintf(‘Constructing ...\n‘);
    H = zeros(nn);  
    for i=1:n
       for j=1:n
          H(ij) = Y(i)*Y(j)*svkernel(kerX(i:)X(j:));
       end
    end
    c = -ones(n1);  

    % Add small amount of zero order regularisation to 
    % avoid problems when Hessian is badly conditioned. 
    H = H+1e-10*eye(size(H));
    
    % Set up the parameters for the Optimisation problem

    vlb = zeros(n1);      % Set the bounds: alphas >= 0
    vub = C*ones(n1);     %                 alphas <= C
    x0 = zeros(n1);       % The starting point is [0 0 0   0]
    neqcstr = nobias(ker); % Set the number of equality constraints (1 or 0)  
    if neqcstr
       aeq = Y‘; beq = 0;     % Set the constraint Ax = b
    else       
       aeq = zeros(1n);beq=0;
    end

    % Solve the Optimisation Problem
    
    fprintf(‘Optimising ...\n‘);
    st = cputime;
    
    %[alpha lambda how] = qp(H c A b vlb vub x0 neqcstr);
    [alpha lambda how] = quadprog(H c [][]aeqbeqvlb vub x0);
    fprintf(‘Execution time: %4.1f seconds\n‘cputime - st);
    fprintf(‘Status : %s\n‘how);
    w2 = alpha‘*H*alpha;
    fprintf(‘|w0|^2    : %f\n‘w2);
    fprintf(‘Margin    : %f\n‘2/sqrt(w2));
    fprintf(‘Sum alpha : %f\n‘sum(alpha));
    
        
    % Compute the number of Support Vectors
    svi = find( alpha > epsilon);
    nsv = length(svi);
    fprintf(‘Support Vectors : %d (%3.1f%%)\n‘nsv100*nsv/n);

    % Implicit bias b0
    b0 = 0;

    % Explicit bias b0 
    if nobias(ker) ~= 0
      % find b0 from average of support vectors on margin
      % SVs on margin have alphas: 0 < alpha < C
      svii = find( alpha > epsilon & alpha < (C - epsilon));
      if length(svii) > 0
        b0 =  (1/length(svii))*sum(Y(svii) - H(sviisvi)*alpha(svi).*Y(svii));
      else 
        fprintf(‘No support vectors on margin - cannot compute bias.\n‘);
      end
    end
    
  end
 
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1497  2011-03-26 11:25  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\COPYRIGHT

     文件      71213  2011-11-05 09:35  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\FAQ.html

     文件      27670  2003-07-12 12:07  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\heart_scale

     文件      62406  2011-11-05 14:22  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\java\libsvm\svm.java

     文件      61755  2011-05-28 22:19  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\java\libsvm\svm.m4

     文件        734  2010-09-12 20:11  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\java\libsvm\svm_model.java

     文件        115  2003-10-11 20:30  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\java\libsvm\svm_node.java

     文件       1288  2006-03-03 23:44  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\java\libsvm\svm_parameter.java

     文件         87  2009-02-18 11:20  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\java\libsvm\svm_print_interface.java

     文件        136  2003-10-11 20:30  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\java\libsvm\svm_problem.java

     文件      50037  2011-11-05 14:23  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\java\libsvm.jar

     文件        624  2009-02-18 08:41  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\java\Makefile

     文件       4267  2009-03-18 04:20  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\java\svm_predict.java

     文件       8944  2011-05-28 22:19  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\java\svm_scale.java

     文件      11483  2010-12-13 17:43  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\java\svm_toy.java

     文件       8268  2011-05-28 22:19  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\java\svm_train.java

     文件         81  2003-07-12 12:07  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\java\test_applet.html

     文件        559  2011-06-26 03:55  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\Makefile

     文件       1087  2010-09-12 20:11  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\Makefile.win

     文件       4014  2011-08-27 13:03  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\matlab\libsvmread.c

     文件       8192  2012-07-22 08:45  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\matlab\libsvmread.mexw32

     文件       2148  2011-08-27 13:03  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\matlab\libsvmwrite.c

     文件       7680  2012-07-22 08:45  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\matlab\libsvmwrite.mexw32

     文件        799  2011-09-05 00:35  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\matlab\make.m

     文件       1499  2011-05-10 07:35  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\matlab\Makefile

     文件       9618  2011-10-30 19:40  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\matlab\README

     文件       9263  2011-08-27 13:03  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\matlab\svmpredict.c

     文件      20480  2012-07-22 08:46  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\matlab\svmpredict.mexw32

     文件      11371  2011-08-27 13:03  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\matlab\svmtrain.c

     文件      49152  2012-07-22 08:46  印章识别\dfs_service_libsvm-3.11\libsvm-3.11\matlab\svmtrain.mexw32

............此处省略389个文件信息

评论

共有 条评论