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

📄 myperceptron.m

📁 最新的模式识别分类工具箱,希望对朋友们有用!
💻 M
字号:
function w_percept = MyPerceptron(train_features, train_targets, alg_param)% Trains using the Perceptron algorithm% Inputs:% 	featvect    - feature vectors: column = feature vector, row = feature%	labels	    - Labels of feature vectors: 0 and 1 (do not use 2, 3 etc.%	alg_param   - Either: Number of iterations, weights vector or [weights, number of iterations]%% Outputs%	weights	     - the weight vector% x * weights > 0 -> class 1% x * weights < 0 -> class 0[c, r]		   = size(train_features);%Weighted Perceptron or not?switch length(alg_param),case r + 1,    %Ada boost form    p           = alg_param(1:end-1);    max_iter    = alg_param(end);case {r,0},    %No parameter given    p           = ones(1,r);    max_iter    = 5000;otherwise    %Number of iterations given    max_iter    = alg_param;    p           = ones(1,r);endtrain_features = [train_features ; ones(1,r)];train_one      = find(train_targets == 1);train_zero     = find(train_targets == 0);%Preprocessingprocessed_features = train_features;processed_features(:,train_zero) = -processed_features(:,train_zero);%Initial weightsw_percept	= rand(c+1,1);correct_classified = 0;n						 = length(train_targets);iter					 = 0;while (  (longest_run(w_percept, processed_features) < 0.9*n) ...       & (iter < max_iter))   iter = iter + 1;   indice = 1 + floor(rand(1)*n);   if (w_percept' *  processed_features(:,indice) <= 0)      w_percept = w_percept + p(indice)* processed_features(:,indice);   endenddisp(w_percept);if (iter == max_iter)&(length(alg_param)~= r + 1),   disp(['Maximum iteration (' num2str(max_iter) ') reached']);end%Find decision region

⌨️ 快捷键说明

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