# SVM算法.zip

• LOST0522
了解作者
• matlab
开发工具
• 14KB
文件大小
• zip
文件格式
• 0
收藏次数
• 10 积分
下载积分
• 27
下载次数
• 2019-07-03 10:34
上传日期
SVM算法的线性分类，图像分类单幅遥感图像特征提取分类
SVM算法.zip
• SVM算法
• SVMtest.m
2.4KB
• feixianxingSVM.m
572B
• svmPredict.m
1.7KB
• BreastTissue_data.mat
6.6KB
• xianxingSVM.m
364B
• concrete_data.mat
2.2KB
• svmTrain1.m
4.9KB

function [model] = svmTrain(X, Y, C, kernelFunction,sigma,tol, max_passes) if ~exist('tol', 'var') || isempty(tol) tol = 1e-3; end if ~exist('max_passes', 'var') || isempty(max_passes) max_passes = 5; end if ~exist('sigma', 'var') || isempty(sigma) sigma = 1; end % Data parameters m = size(X, 1); n = size(X, 2); % Variables alphas = zeros(m, 1); %拉格朗日算子 b = 0; %超平面截距 E = zeros(m, 1); %评价函数 passes = 0; eta = 0; L = 0; H = 0; if strcmp(func2str(kernelFunction), 'linearKernel') % Vectorized computation for the Linear Kernel % This is equivalent to computing the kernel on every pair of examples K = X*X'; % m*m 样本之间的内积 K是对称矩阵 elseif strfind(func2str(kernelFunction), 'gaussianKernel') % Vectorized RBF Kernel % This is equivalent to computing the kernel on every pair of examples X2 = sum(X.^2, 2); %求向量平方和 K = bsxfun(@plus, X2, bsxfun(@plus, X2', - 2 * (X * X'))); % K=kernelFunction(1,0).^K; K = exp(-K/(2*sigma*sigma)); else % Pre-compute the Kernel Matrix % The following can be slow due to the lack of vectorization K = zeros(m); for i = 1:m for j = i:m K(i,j) = kernelFunction(X(i,:)', X(j,:)'); K(j,i) = K(i,j); %the matrix is symmetric对称 end end end % Train fprintf('\nTraining ...'); dots = 12; while passes < max_passes, num_changed_alphas = 0; for i = 1:m, % Calculate Ei = f(x(i)) - y(i) using (2). % E(i) = b + sum (X(i, :) * (repmat(alphas.*Y,1,n).*X)') - Y(i); E(i) = b + sum (alphas.*Y.*K(:,i)) - Y(i); if ((Y(i)*E(i) < -tol && alphas(i) < C) || (Y(i)*E(i) > tol && alphas(i) > 0)), % In practice, there are many heuristics one can use to select % the i and j. In this simplified code, we select them randomly. j = ceil(m * rand()); while j == i, % Make sure i \neq j j = ceil(m * rand()); end % Calculate Ej = f(x(j)) - y(j) using (2). E(j) = b + sum (alphas.*Y.*K(:,j)) - Y(j); % Save old alphas alpha_i_old = alphas(i); alpha_j_old = alphas(j); % Compute L and H by (10) or (11). if (Y(i) == Y(j)), L = max(0, alphas(j) + alphas(i) - C); H = min(C, alphas(j) + alphas(i)); else L = max(0, alphas(j) - alphas(i)); H = min(C, C + alphas(j) - alphas(i)); end if (L == H), % continue to next i. continue; end % Compute eta by (14). eta = 2 * K(i,j) - K(i,i) - K(j,j); if (eta >= 0), % continue to next i. continue; end % Compute and clip new value for alpha j using (12) and (15). alphas(j) = alphas(j) - (Y(j) * (E(i) - E(j))) / eta; % Clip alphas(j) = min (H, alphas(j)); alphas(j) = max (L, alphas(j)); % Check if change in alpha is significant if (abs(alphas(j) - alpha_j_old) < tol), % continue to next i. % replace anyway alphas(j) = alpha_j_old; continue; end % Determine value for alpha i using (16). alphas(i) = alphas(i) + Y(i)*Y(j)*(alpha_j_old - alphas(j)); % Compute b1 and b2 using (17) and (18) respectively. b1 = b - E(i) ... - Y(i) * (alphas(i) - alpha_i_old) * K(i,j)' ... - Y(j) * (alphas(j) - alpha_j_old) * K(i,j)'; b2 = b - E(j) ... - Y(i) * (alphas(i) - alpha_i_old) * K(i,j)' ... - Y(j) * (alphas(j) - alpha_j_old) * K(j,j)'; % Compute b by (19). if (0 < alphas(i) && alphas(i) < C), b = b1; elseif (0 < alphas(j) && alphas(j) < C), b = b2; else b = (b1+b2)/2; end num_changed_alphas = num_changed_alphas + 1; end end if (num_changed_alphas == 0), passes = passes + 1; else passes = 0; end fprintf('.'); dots = dots + 1; if dots > 78 dots = 0; fprintf('\n'); end % if exist('OCTAVE_VERSION') % fflush(stdout); % end end fprintf(' Done! \n\n'); % Save the model idx = alphas > 0; model.idx=idx; model.X= X(idx,:); model.y= Y(idx); model.kernelFunction = kernelFunction; model.sigma=sigma; model.b= b; model.alphas= alphas(idx); model.w = ((alphas.*Y)'*X)'; end

相关推荐
• ENVI遥感图像处理方法
全书共分17章，涵盖了ENVI软件概述、ENVI遥感图像处理基础、数据显示操作、遥感图像预处理、图像增强、图像分类、矢量处理、地图制图与三维可视化、正射校正、面向对象图像特征提取、地形分析、遥感动态监测、辐射...
• 遥感图像分类方法研究
由于不同场合遥感图像的应用对遥感图像处理提出了不同的要求,所以图像处理中重要的环节——图像分类也就显得尤为重要,经过多年的努力,形成了许多经典的分类方法和算法。
• 遥感图像地物信息分类
遥感地物信息分类，采用K均值和ISODATA两种算法。
• 遥感图像在ENVI中的分类
用ENVI软件对遥感图像进行地物识别和分类
• 神经网络方法分类遥感图像vc
用神经网络方法分类遥感图像用神经网络方法分类遥感图像用神经网络方法分类遥感图像用神经网络方法分类遥感图像
• 遥感图像分类EuroSAT.zip
遥感图像分类，共10类图像大小64*64。
• 遥感图像分类
遥感图像处理，
• 遥感图像分类
2017年3月14日esri中国遥感教程《白话遥感图像分类技术》
• 基于神经网路的遥感图像分类
基于神经网路的遥感图像分类，使用神经网络对几幅不同频段的遥感图像分类，主要是区分图像中不同的地形区域。
• 基于FMC遥感图像分类
用于图像分类，可以运行希望对大家有用，谢谢了！！！