PNN 분류
이 예제에서는 NEWPNN 함수와 SIM 함수를 사용합니다.
다음은 요소를 2개 가진 3개의 입력 벡터 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 거리인 1을 SPREAD 값으로 사용합니다.
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)')
다음 도식은 확률 신경망이 입력 공간을 3개의 클래스로 나누는 것을 보여줍니다.
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)')