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

📄 gcsbaypw.m

📁 细胞生长结构可视化工具箱-MATLAB Toolbox1999.zip
💻 M
字号:
% Apply Bayes theory to a GCS applied to a 2 case problem - eg, fnab
% Version which uses a test and training set 
% Version computing probs from cmap1 and cmap2 directly




ppos = zeros(size(z1));
pneg = zeros(size(z1));

NoPos = sum(z2);
NoNeg = sum(z1);

% claculate prior probs
priorpos = NoPos/(NoPos+NoNeg);
priorneg = NoNeg/(NoPos+NoNeg);

% Form basic plot based on node values
for i=1:size(wvis,1)	% for each node
	if (z1(i)>0 | z2(i)>0)	% catch nodes which have no associated ips
		ppos(i) = z2(i)/(z1(i)+z2(i));
		pneg(i) = z1(i)/(z1(i)+z2(i));

	else
		ppos(i)=0;
		pneg(i)=0;
	end
end

% Plot results
figure(2);
clf;
whitebg('white');
subplot(2,2,1);
hold on;
cla;
title('Posterior prob at each node');
view(45,30);

% Determine extent of visualisation area
minx = min(wvis(:,1));
miny = min(wvis(:,2));
maxx = max(wvis(:,1));
maxy = max(wvis(:,2));

% Plot basic network
Axis([minx,maxx,miny,maxy]);
for i = 1:size(wvis,1)
	for j = i+1:size(wvis,1)
		if (C(i,j) == 1)
			plot([wvis(i,1),wvis(j,1)],[wvis(i,2),wvis(j,2)],'k');
			plot([wvis(i,1),wvis(j,1)],[wvis(i,2),wvis(j,2)],'k');
		end
	end
end
% Now add posterior prob data
offset=0.02;	% offste used to prevent bars overwritting each other
for i = 1:size(wvis,1)
	plot3([wvis(i,1),wvis(i,1)],[wvis(i,2),wvis(i,2)],[0,pneg(i)],'r');
	plot3([wvis(i,1),wvis(i,1)],[wvis(i,2)+offset,wvis(i,2)+offset],[0,ppos(i)],'b');
end





intbound = 0.1; % factor for determining interpolation boundary
minxint = minx - intbound*(maxx-minx);
maxxint = maxx + intbound*(maxx-minx);
minyint = miny - intbound*(maxy-miny);
maxyint = maxy + intbound*(maxy-miny);

ppos = cmap2./(cmap1+cmap2);
pneg = cmap1./(cmap1+cmap2);


Noc = size(colormap,1);
xi=minx:(maxx-minx)/NoPts:maxx;
yi=maxy:-(maxy-miny)/NoPts:miny;

%figure(4);
subplot(2,2,3);
colormap(c);
cla;
image(xi,yi,pneg*Noc);
colorbar;
plotv2;
contour(xi,[miny:(maxy-miny)/NoPts:maxy],sign(ppos-pneg),1); %,'m*');
title('Posterior probability ''O'' class');
%figure(5);
subplot(2,2,4);
colormap(c);
cla;
image(xi,yi,ppos*Noc);
colorbar;
plotv2;
contour(xi,[miny:(maxy-miny)/NoPts:maxy],sign(ppos-pneg),1); %,'m*');
title('Posterior probability ''+'' class');

%figure(6);
subplot(2,2,2);
colormap(c);
cla;
mesh(xi,yi,(pneg) );
hold on;
mesh(xi,yi,(ppos) );
axis([minx,maxx,miny,maxy,0,1]);
view(45,30);
title('Mesh of posteriors for both classes');

colormenu;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     Calculate the performance as a classifier
tp=0;	%No True positives 
tn=0; 	%true negatives
fp=0;	% false positives
fn=0;	% false negatives

Act=[];
neg=[];
pos=[];
pippos=[];
pipneg=[];
class=[];

for i=1:size(test,1)
	Ip = test(rem(i-1,size(test,1))+1,1:n);	
	class(i) =  test(rem(i-1,size(test,1))+1,n+1);
	for k = 1:size(wvis,1)
		Act(k) = exp(-((norm((Ip-w(k,:)),metric)^2)./(sigma(k)).^2));
	end
	neg(i) = Act*z1;
	pos(i) = Act*z2;	
	pipneg(i) = neg(i)/(neg(i)+pos(i));
	pippos(i) = pos(i)/(neg(i)+pos(i));

	if (pippos(i)>pipneg(i))
		if (class(i) == 1)
			tp = tp+1;	% z2 is positive count
		else
			fp = fp+1;
		end
	else
		if (class(i) == 0)
			tn = tn+1;
		else
			fn = fn+1;
		end
	end
end




acc = (tp+tn)/(tp+tn+fp+fn);
sens = tp/(tp+fn);
spec = tn/(tn+fp);


disp('Performance of Bayes Classifier');
disp(['True Positives  ',int2str(tp)]);
disp(['True Negatives  ',int2str(tn)]);
disp(['False Positives ',int2str(fp)]);
disp(['False Negatives ',int2str(fn)]);
disp(['Accuracy        ',num2str(acc)]);
disp(['Sensitivity     ',num2str(sens)]);
disp(['Specificity     ',num2str(spec)]);

⌨️ 快捷键说明

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