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

📄 pnn_vc.m

📁 最新的模式识别分类工具箱,希望对朋友们有用!
💻 M
字号:
% Learns classifier and classifies test set% using a Probabilistic Neural Network% Usage%      [trainError, testError, estTrainLabels, estTestLabels] = ...%           PNN_VC(trainFeatures, trainLabels,Nmu ,testFeatures, testLabels)% where%% Inputs:% 	trainFeatures  - the training set vectors, one vector per column%	trainLabels    - the labels of the above%	sigma          - Gaussian width%       testFeatures   - test set, one column per vector%       testLabels     - labels  for test set%% Outputs%	trainError     - the error rate on the training set (one entry per%	                   class + total error)%	testError      - the error rate on the test set (one entry per class%	                  + total error)%       estTrainLabels - the labels produced by the algorithm for the%                          training samples%       estTestLabels - the labels produced by the algorithm for the%                          test samplesfunction [trainError, testError, estTrainLabels, estTestLabels] = ...    PNN_VC(trainFeatures, trainLabels,sigma ,testFeatures, testLabels)hm = findobj('Tag', 'Messages'); fprintf('Probabilistic Neural Network: Training\n');if (isempty(hm)==0)  s = sprintf('Probabilistic Neural Network: Training');  set(hm,'String',s);  refresh;end[Dim, Nsam]       = size(trainFeatures);normFeatures    = trainFeatures;normFeatures(Dim+1,:) = ones(1,Nsam);[Nclasses, classes]  = find_classes([trainLabels(:);testLabels(:)]); % Number of classes in labels%  Build the classifier%  Normalizes the training featuresnormFeatures  = normFeatures ./ (sqrt(sum(normFeatures'.^2))'*ones(1,Nsam));%%for cl=1:Nclasses  evalstr =sprintf('ind%d = find(trainLabels == classes(cl));', cl);  eval (evalstr);  evalstr =sprintf('ClassFeatures%d = normFeatures(:,ind%d);',cl,cl);  eval (evalstr);    evalstr =sprintf('Onen%d =ones(size(ind%d));', cl,cl);  eval (evalstr);  evalstr =sprintf('Num(%d) = length(ind%d);',cl, cl);  eval(evalstr);enddisp(Num);fprintf('Probabilistic Neural Network: Computing Training Set Error Rate\n');if (isempty(hm)==0)  s = sprintf('Probabilistic Neural Network: Computing Training Set Error Rates');  set(hm,'String',s);  pause(.1);endclassVote=[];for sam=1:Nsam,  thisSam =[trainFeatures(:,sam);1];  %thisSam =trainFeatures(:,sam);  for cl = 1:Nclasses,    evalstr = ...	sprintf('innerprod = (thisSam * Onen%d).* ClassFeatures%d;',cl,cl);    eval(evalstr);    sumval    = (sum(innerprod) - 1)/(sigma * sigma);    classVote(cl) = sum(exp(sumval))/Num(cl);  end  [foo,bestClass] = max(classVote);  estTrainLabels(sam)= classes(bestClass);endfprintf('Probabilistic Neural Network: Computing Test Set Error Rate\n');if (isempty(hm)==0)  s = sprintf('Probabilistic Neural Network: Computing Test Set Error Rates');  set(hm,'String',s);  pause(.1);end[Dim, Nsamt]       = size(testFeatures);classVote=[];for sam=1:Nsamt,  thisSam =[testFeatures(:,sam);1];  %thisSam =testFeatures(:,sam);  for cl = 1:Nclasses,    evalstr = ...	sprintf('innerprod = (thisSam * Onen%d).* ClassFeatures%d;',cl,cl);    eval(evalstr);    sumval        = (sum(innerprod) - 1)/(sigma * sigma);    classVote(cl) = sum(exp(sumval))/Num(cl);  end  [foo,bestClass] = max(classVote);  estTestLabels(sam)= classes(bestClass);end    trainError = computeError( classes, trainLabels, estTrainLabels);testError = computeError ( classes, testLabels, estTestLabels);

⌨️ 快捷键说明

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