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

📄 relaxation_bm.m

📁 模式识别matlab工具箱,包括SVM,ICA,PCA,NN等等模式识别算法,很有参考价值
💻 M
字号:
function [D, a] = Relaxation_BM(train_features, train_targets, params, region)

% Classify using the batch relaxation with margin algorithm
% Inputs:
% 	features	- Train features
%	targets	    - Train targets
%	param		- [Max iter, Margin, Convergence rate]
%	region	    - Decision region vector: [-x x -y y number_of_points]
%
% Outputs
%	D			- Decision sufrace
%   a          - Classifier weights

[c, n]				    = size(train_features);
[Max_iter, b, eta]	 = process_params(params);

y               = [train_features ; ones(1,n)];
train_zero      = find(train_targets == 0);

%Preprocessing
processed_features = y;
processed_features(:,train_zero) = -processed_features(:,train_zero);

%Initial weights
a               = sum(processed_features')';
iter  	        = 0;
Yk				= [1];

while (~isempty(Yk) & (iter < Max_iter))
   iter = iter + 1;
   
   %If a'y_j <= b then append y_j to Yk
   Yk = [];
   for k = 1:n,
   	if (a'*processed_features(:,k) <= b),
         Yk = [Yk k];
      end
   end
   
   if isempty(Yk),
      break
   end
   
   % a <- a + eta*sum((b-w'*Yk)/||Yk||*Yk)
   grad			= (b-a'*y(:,Yk))./sum(y(:,Yk).^2);
   update		= sum(((ones(c+1,1)*grad).*y(:,Yk))')';
   a            = a + eta * update;
end

if (iter == Max_iter),
   disp(['Maximum iteration (' num2str(Max_iter) ') reached']);
end

%Find decision region
N		= region(5);
x		= ones(N,1) * linspace (region(1),region(2),N);
y		= linspace (region(3),region(4),N)' * ones(1,N);

D       = (a(1).*x + a(2).*y + a(c+1)> 0);
a       = a';

⌨️ 快捷键说明

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