• PUDN用户
    了解作者
  • matlab
    开发工具
  • 2KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 10 积分
    下载积分
  • 6313
    下载次数
  • 2006-10-13 03:05
    上传日期
支持向量机(SVM)实现的分类算法源码[matlab]
SVM(matlab).rar
  • SVM.txt
    3.8KB
  • www.pudn.com.txt
    218B
内容介绍
function [iter, optCond, time, w, gamma] = lsvm(A,D,nu,tol,maxIter,alpha, ... perturb,normalize); % LSVM Langrangian Support Vector Machine algorithm % LSVM solves a support vector machine problem using an iterative % algorithm inspired by an augmented Lagrangian formulation. % % iters = lsvm(A,D) % % where A is the data matrix, D is a diagonal matrix of 1s and -1s % indicating which class the points are in, and 'iters' is the number % of iterations the algorithm used. % % All the following additional arguments are optional: % % [iters, optCond, time, w, gamma] = ... % lsvm(A,D,nu,tol,maxIter,alpha,perturb,normalize) % % optCond is the value of the optimality condition at termination. % time is the amount of time the algorithm took to terminate. % w is the vector of coefficients for the separating hyperplane. % gamma is the threshold scalar for the separating hyperplane. % % On the right hand side, A and D are required. If the rest are not % specified, the following defaults will be used: % nu = 1/size(A,1), tol = 1e-5, maxIter = 100, alpha = 1.9/nu, % perturb = 0, normalize = 0 % % perturb indicates that all the data should be perturbed by a random % amount between 0 and the value given. perturb is recommended only % for highly degenerate cases such as the exclusive or. % % normalize should be set to 1 if the data should be normalized before % training. % % The value -1 can be used for any of the entries (except A and D) to % specify that default values should be used. % % Copyright (C) 2000 Olvi L. Mangasarian and David R. Musicant. % Version 1.0 Beta 1 % This software is free for academic and research use only. % For commercial use, contact musicant@cs.wisc.edu. % If D is a vector, convert it to a diagonal matrix. [k,n] = size(D); if k==1 | n==1 D=diag(D); end; % Check all components of D and verify that they are +-1 checkall = diag(D)==1 | diag(D)==-1; if any(checkall==0) error('Error in D: classes must be all 1 or -1.'); end; m = size(A,1); if ~exist('nu') | nu==-1 nu = 1/m; end; if ~exist('tol') | tol==-1 tol = 1e-5; end; if ~exist('maxIter') | maxIter==-1 maxIter = 100; end; if ~exist('alpha') | alpha==-1 alpha = 1.9/nu; end; if ~exist('normalize') | normalize==-1 normalize = 0; end; if ~exist('perturb') | perturb==-1 perturb = 0; end; % Do a sanity check on alpha if alpha > 2/nu, disp(sprintf('Alpha is larger than 2/nu. Algorithm may not converge.')); end; % Perturb if appropriate rand('seed',22); if perturb, A = A + rand(size(A))*perturb; end; % Normalize if appropriate if normalize, avg = mean(A); dev = std(A); if (isempty(find(dev==0))) A = (A - avg(ones(m,1),:))./dev(ones(m,1),:); else warning('Could not normalize matrix: at least one column is constant.'); end; end; % Create matrix H [m,n] = size(A); e = ones(m,1); H = D*[A -e]; iter = 0; time = cputime; % "K" is an intermediate matrix used often in SMW calclulations K = H*inv((speye(n+1)/nu+H'*H)); % Choose initial value for x x = nu*(1-K*(H'*e)); % y is the old value for x, used to check for termination y = x + 1; while iter < maxIter & norm(y-x)>tol % Intermediate calculation which is used twice z = (1+pl(((x/nu+H*(H'*x))-alpha*x)-1)); y = x; % Calculate new value of x x=nu*(z-K*(H'*z)); iter = iter + 1; end; % Determine outputs time = cputime - time; optCond = norm(x-y); w = A'*D*x; gamma = -e'*D*x; disp(sprintf('Running time (CPU secs) = %g',time)); disp(sprintf('Number of iterations = %d',iter)); disp(sprintf('Training accuracy = %g',sum(D*(A*w-gamma)>0)/m)); return; function pl = pl(x); %PLUS function : max{x,0} pl = (x+abs(x))/2; return;
评论
  • PUDN用户 2010-01-01 21:53:39
    不怎么样
相关推荐
  • 4.SVM分类算法.rar
    svm算法 matlab基础教程,适合新手学习入门........
  • SVM算法实现分类
    支持向量机SVM算法可以有效的实现分类,该程序包含完整的代码以及训练和测试数据集。
  • svm实现多类分类算法的文章
    收集了关于svm实现多类分类问题的文章,中文英文都有。有做这方面研究的可以下下来看看
  • SVM分类算法.zip
    内含SVM示例程序,以基于乳腺组织电阻抗特性的乳腺癌诊断为示例,具体程序注释
  • 很好的SVM分类算法
    这是一个很好的SVM分类算法,可以对要进行分类的特征进行识别。
  • Python实现SVM分类算法
    Python实现SVM分类算法
  • SVM分类算法代码及实验报告
    压缩包中包括SVM分类算法实现代码、测试数据以及实验报告
  • SVM程序算法
    支持向量机分类算法实现,利用线性核函数构建最优分类面,对训练样本进行训练,然后对测试样本进行测试分类,得出分类准确率
  • java实现基于SMO算法SVM分类
    用java实现基于SMO算法SVM分类器的完整eclipse工程代码,带测试数据文件
  • C++实现SVM分类算法
    SVM有如下特征:(1)SVM学习问题可以表示为凸优化问题,因此可以利用已知的有效算法发现目标函数...本代码通过C++实现SVM分类算法,并通过SSE实现最优解的快速计算,学习SVM的同学可以参考一下,如有不足,请指正。