PNN 分类
此示例使用 NEWPNN 和 SIM 函数。
此处有三个二元输入向量 X 和它们相关联的类 Tc。我们想创建 y 概率神经网络,对这些向量正确分类。
X = [1 2; 2 2; 1 1]'; Tc = [1 2 3]; plot(X(1,:),X(2,:),'.','markersize',30) for i = 1:3, text(X(1,i)+0.1,X(2,i),sprintf('class %g',Tc(i))), end axis([0 3 0 3]) title('Three vectors and their classes.') xlabel('X(1,:)') ylabel('X(2,:)')
首先,我们将目标类索引 Tc 转换为向量 T。然后,我们用 NEWPNN 设计 y 概率神经网络。我们使用 y SPREAD 值 1,因为这是输入向量之间的 y 典型距离。
T = ind2vec(Tc); spread = 1; net = newpnn(X,T,spread);
现在我们基于设计输入向量测试网络。我们通过对网络进行仿真并将其向量输出转换为索引来实现此目的。
Y = net(X); Yc = vec2ind(Y); plot(X(1,:),X(2,:),'.','markersize',30) axis([0 3 0 3]) for i = 1:3,text(X(1,i)+0.1,X(2,i),sprintf('class %g',Yc(i))),end title('Testing the network.') xlabel('X(1,:)') ylabel('X(2,:)')
让我们用我们的网络对 y 新向量进行分类。
x = [2; 1.5]; y = net(x); ac = vec2ind(y); hold on plot(x(1),x(2),'.','markersize',30,'color',[1 0 0]) text(x(1)+0.1,x(2),sprintf('class %g',ac)) hold off title('Classifying y new vector.') xlabel('X(1,:) and x(1)') ylabel('X(2,:) and x(2)')
该图显示概率神经网络如何将输入空间分为三个类。
x1 = 0:.05:3; x2 = x1; [X1,X2] = meshgrid(x1,x2); xx = [X1(:) X2(:)]'; yy = net(xx); yy = full(yy); m = mesh(X1,X2,reshape(yy(1,:),length(x1),length(x2))); m.FaceColor = [0 0.5 1]; m.LineStyle = 'none'; hold on m = mesh(X1,X2,reshape(yy(2,:),length(x1),length(x2))); m.FaceColor = [0 1.0 0.5]; m.LineStyle = 'none'; m = mesh(X1,X2,reshape(yy(3,:),length(x1),length(x2))); m.FaceColor = [0.5 0 1]; m.LineStyle = 'none'; plot3(X(1,:),X(2,:),[1 1 1]+0.1,'.','markersize',30) plot3(x(1),x(2),1.1,'.','markersize',30,'color',[1 0 0]) hold off view(2) title('The three classes.') xlabel('X(1,:) and x(1)') ylabel('X(2,:) and x(2)')