Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

PNN 分類

この例では、関数 NEWPNN および SIM を使用します。

3 つの 2 要素入力ベクトル 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,:)')

Figure contains an axes object. The axes object with title Three vectors and their classes., xlabel X(1,:), ylabel X(2,:) contains 4 objects of type line, text. One or more of the lines displays its values using only markers

最初に、ターゲット クラス インデックス Tc をベクトル T に変換します。その後、NEWPNN を使用して y の確率的ニューラル ネットワークを設計します。y の入力ベクトル間の一般的な距離である 1 を y 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,:)')

Figure contains an axes object. The axes object with title Testing the network., xlabel X(1,:), ylabel X(2,:) contains 4 objects of type line, text. One or more of the lines displays its values using only markers

ネットワークを使用して 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)')

Figure contains an axes object. The axes object with title Classifying y new vector., xlabel X(1,:) and x(1), ylabel X(2,:) and x(2) contains 6 objects of type line, text. One or more of the lines displays its values using only markers

この図は、確率的ニューラル ネットワークがどのように入力空間を 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)')

Figure contains an axes object. The axes object with title The three classes., xlabel X(1,:) and x(1), ylabel X(2,:) and x(2) contains 5 objects of type surface, line. One or more of the lines displays its values using only markers