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

📄 sgceval.m

📁 一个关于数据聚类和模式识别的程序,在生物化学,化学中因该都可以用到.希望对大家有用,谢谢支持
💻 M
字号:
function [computedClass, recogRate, hitIndex]=sgcEval(DS, classParam, plotOpt)
% sgcTrain: Evaluation for single Gaussian classifier
%	Usage: [computedClass, recogRate, hitIndex]=sgcEval(DS, classParam, plotOpt)
%		If DS does not have "output" field, then this command won't return "recogRate" and "hitIndex".

% Roger Jang, 20041123, 20080924

if nargin<1, selfdemo; return; end
if nargin<2, classParam=[]; end
if nargin<3, plotOpt=0; end

classNum=length(classParam);
[dim, dataNum]=size(DS.input);
logProb=zeros(classNum, dataNum);
for i=1:classNum
	dataMinusMu = DS.input-classParam(i).mu*ones(1, dataNum);
	logProb(i,:) = -0.5*sum(dataMinusMu.*(classParam(i).invSigma*dataMinusMu), 1)+classParam(i).gconst;
	logProb(i,:) = logProb(i,:)+log(classParam(i).weight);		% Take weight into consideration
end
[junk, computedClassIndex]=max(logProb);
className=[classParam.name];
computedClass=className(computedClassIndex);
if isfield(DS, 'output')
	className=[classParam.name];
	hitIndex=find(computedClass==DS.output);
	recogRate = length(hitIndex)/dataNum;
end

if plotOpt & dim==2
	dcprDataPlot(DS);
	axis image; box on
	missIndex=1:dataNum;
	missIndex(hitIndex)=[];
	% display these points
	for i=1:length(missIndex),
		line(DS.input(1,missIndex(i)), DS.input(2,missIndex(i)), 'marker', 'x', 'color', 'k');
	end
	titleString = sprintf('%d error points denoted by "x".', length(missIndex));
	title(titleString);
end

% ====== Self demo
function selfdemo
[DS, TS]=prData('iris');
DS.input=DS.input(3:4, :);
TS.input=TS.input(3:4, :);
[classParam, recogRate1]=sgcTrain(DS);
[computedClass, recogRate2, hitIndex]=sgcEval(TS, classParam, 1);
fprintf('Inside recog rate = %g%%\n', recogRate1*100);
fprintf('Outside recog rate = %g%%\n', recogRate2*100);

⌨️ 快捷键说明

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