Main Content

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

学習率が大きすぎる場合

簡単な問題に対して誤差が最小の解を求めるように線形ニューロンの学習を行います。MAXLINLR によって提案されるものよりも大きい学習率でニューロンの学習を行います。

X は、2 つの 1 要素入力パターン (列ベクトル) を定義します。T は、関連する 1 要素ターゲット (列ベクトル) を定義します。

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

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

w_range = -2:0.4:2;
b_range = -2:0.4:2;
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 は、線形ネットワークの学習のための最速かつ安定した学習率を求めます。NEWLIN は、線形ニューロンを作成します。学習率が大きすぎると何が起こるかを確認するには、学習率を推奨値の 225% に増やします。NEWLIN は、次の引数を取ります。1) R 個の入力要素の最小値と最大値の R 行 2 列の行列、2) 出力ベクトルの要素数、3) 入力遅延ベクトル、4) 学習率。

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

最大エポック数を設定して既定の学習パラメーターをオーバーライドします。これにより、学習は確実に停止します。

net.trainParam.epochs = 20;

学習のパスを示すために、一度に 1 エポックのみ学習を行い、各エポックで PLOTEP を呼び出します (ここではコードは示されません)。プロットは学習の履歴を示します。各点はエポックを表し、青い線は学習規則 (既定では 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 epoch < 20
   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:32: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 42 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 22 objects of type surface, contour, line. One or more of the lines displays its values using only markers

tr=r;

学習関数は、学習済みネットワークおよび学習性能 (tr) の履歴を出力します。ここでは、誤差が学習エポックに関してプロットされています。

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.

SIM を使用して、元の入力の 1 つである -1.2 でアソシエーターをテストし、ターゲットである 1.0 を返すかどうかを確認できるようになりました。結果は 0.5 にあまり近くありません。これは、大きすぎる学習率でネットワークに学習させたためです。

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