Main Content

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

線形ニューロンの学習

ターゲット出力を使用して特定の入力に応答するように線形ニューロンの学習を行います。

X は、2 つの 1 要素入力パターン (列ベクトル) を定義します。T は、関連する 1 要素ターゲット (列ベクトル) を定義します。y バイアスをもつ単一入力の線形ニューロンを使用してこの問題を解くことができます。

X = [1.0 -1.2];
T = [0.5 1.0];

ERRSURF は、可能な重みとバイアスの値の y 範囲を使用して y ニューロンの誤差を計算します。PLOTES は、この誤差曲面と、その下の y 等高線図を併せてプロットします。最適な重みとバイアスの値は、誤差曲面の最低点が得られる値です。

w_range = -1:0.2:1;  b_range = -1:0.2:1;
ES = errsurf(X,T,w_range,b_range,'purelin');
plotes(w_range,b_range,ES);

Figure contains 2 axes objects. Axes object 1 with title Error Surface, xlabel Weight W, ylabel Bias B contains 2 objects of type surface. Axes object 2 with title Error Contour, xlabel Weight W, ylabel Bias B contains 2 objects of type surface, contour.

MAXLINLR は、y 線形ネットワークの学習のための最速かつ安定した学習率を求めます。この例では、学習率はこの最大値の 40% のみになります。NEWLIN は y 線形ニューロンを作成します。NEWLIN は、次の引数を取ります。1) R 個の入力要素の最小値と最大値の R 行 2 列の行列、2) 出力ベクトルの要素数、3) 入力遅延ベクトル、4) 学習率。

maxlr = 0.40*maxlinlr(X,'bias');
net = newlin([-2 2],1,[0],maxlr);

性能目標を設定して既定の学習パラメーターをオーバーライドします。

net.trainParam.goal = .001;

学習のパスを示すために、y 時間で 1 エポックのみ学習させ、エポックごとに PLOTEP を呼び出します。プロットは学習の y 履歴を示します。各点はエポックを表し、青い線は学習規則 (既定では Widrow・Hoff) によって行われる各変更を示します。

% [net,tr] = train(net,X,T);
net.trainParam.epochs = 1;
net.trainParam.show = NaN;
h=plotep(net.IW{1},net.b{1},mse(T-net(X)));     
[net,tr] = train(net,X,T);                                                    
r = tr;
epoch = 1;
while true
   epoch = epoch+1;
   [net,tr] = train(net,X,T);
   if length(tr.epoch) > 1
      h = plotep(net.IW{1,1},net.b{1},tr.perf(2),h);
      r.epoch=[r.epoch epoch]; 
      r.perf=[r.perf tr.perf(2)];
      r.vperf=[r.vperf NaN];
      r.tperf=[r.tperf NaN];
   else
      break
   end
end

Figure Neural Network Training (27-Jul-2023 15:31:00) contains an object of type uigridlayout.

Figure contains 2 axes objects. Axes object 1 with title Error Surface, xlabel Weight W, ylabel Bias B contains 20 objects of type surface, line. One or more of the lines displays its values using only markers Axes object 2 with title Error Contour, xlabel Weight W, ylabel Bias B contains 11 objects of type surface, contour, line. One or more of the lines displays its values using only markers

tr=r;

学習関数は、学習済みネットワークおよび学習性能 (tr) の y 履歴を出力します。ここでは誤差が学習エポックに対してプロットされています。誤差は、誤差の目標 (黒い線) を下回るまで減少しました。その時点で学習は停止しました。

plotperform(tr);

Figure Performance (plotperform) contains an axes object. The axes object with title Best Training Performance is 0.625 at epoch 0, xlabel 1 Epochs, ylabel Mean Squared Error (mse) contains 6 objects of type line. One or more of the lines displays its values using only markers These objects represent Train, Best, Goal.

次に、SIM を使用して、元の入力の 1 つである -1.2 でアソシエーターをテストし、ターゲットである 1.0 を返すかどうかを確認します。結果はターゲットの 1 に非常に近くなっています。これは、性能目標を下げることでさらに近づけることが可能です。

x = -1.2;
y = net(x)
y = 0.9817