Main Content

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

GRNN 関数近似

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

当てはめる関数 y の 8 つのデータ点を以下に示します。関数への入力が X の場合、ターゲットの出力 T が得られるはずです。

X = [1 2 3 4 5 6 7 8];
T = [0 1 2 3 2 1 2 1];

plot(X,T,'.','markersize',30)
axis([0 9 -1 4])
title('Function to approximate.')
xlabel('X')
ylabel('T')

Figure contains an axes object. The axes object with title Function to approximate., xlabel X, ylabel T contains a line object which displays its values using only markers.

NEWGRNN を使用し、y一般回帰ネットワークを作成します。個々のデータ点にかなり密接に当てはまる関数 y を取得するため、入力値間の距離 1 よりわずかに小さい y SPREAD を使用します。広がりが小さいほどデータによく当てはまりますが、滑らかさが低下します。

spread = 0.7;
net = newgrnn(X,T,spread);
A = net(X);

hold on
outputline = plot(X,A,'.','markersize',30,'color',[1 0 0]);
title('Create and test y network.')
xlabel('X')
ylabel('T and A')

Figure contains an axes object. The axes object with title Create and test y network., xlabel X, ylabel T and A contains 2 objects of type line. One or more of the lines displays its values using only markers

ネットワークを使用し、y の新しい入力値で関数を近似できます。

x = 3.5;
y = net(x);
plot(x,y,'.','markersize',30,'color',[1 0 0]);
title('New input value.')
xlabel('X and x')
ylabel('T and y')

Figure contains an axes object. The axes object with title New input value., xlabel X and x, ylabel T and y contains 3 objects of type line. One or more of the lines displays its values using only markers

ここで、ネットワークの応答が多くの値についてシミュレートされ、それが表す関数を確認できます。

X2 = 0:.1:9;
Y2 = net(X2);
plot(X2,Y2,'linewidth',4,'color',[1 0 0])
title('Function to approximate.')
xlabel('X and X2')
ylabel('T and Y2')

Figure contains an axes object. The axes object with title Function to approximate., xlabel X and X2, ylabel T and Y2 contains 4 objects of type line. One or more of the lines displays its values using only markers