1. 程式人生 > >【讀書1】【2017】MATLAB與深度學習——單層神經網路的侷限性(1)

【讀書1】【2017】MATLAB與深度學習——單層神經網路的侷限性(1)

單層神經網路的侷限性(Limitations of Single-Layer Neural Networks)

本節將給出單層神經網路演化到多層神經網路的重要原因。

This section presents the critical reasonthat the single-layer neural network had to evolve into a multi-layer neuralnetwork.

我們將通過一個特定的案例來說明這一點。

We will try to show this through aparticular case.

仍然考慮上一節討論的相同的神經網路。

Consider the same neural network that wasdiscussed in the previous section.

它由三個輸入節點和一個輸出節點組成,並且輸出節點的啟用函式是一個sigmoid函式(圖2-21)。

It consists of three input nodes and anoutput node, and the activation function of the output node is a sigmoidfunction (Figure 2-21).

在這裡插入圖片描述

圖2-21 與上一節相同的神經網路Our same neural network

假設我們有四組訓練資料點,如下所示。

Assume that we have four training datapoints, as shown here.

在這裡插入圖片描述

它與“示例:增量規則”部分的不同之處在於第二組和第四組的正確輸出被交換,而輸入保持不變。

It is different from that of the “Example:Delta Rule” section in that the second and fourth correct outputs are switchedwhile the inputs remain the same.

嗯,差異幾乎不明顯。

Well, the difference is barely noticeable.

這種差異並不應該會引起任何麻煩,對吧?

It shouldn’t cause any trouble, right?

現在我們將使用SGD對增量規則進行訓練。

We will now train it with the delta ruleusing the SGD.

當我們考慮相同的神經網路時,我們可以使用“示例:增量規則”一節中的函式DeltaSGD來訓練它。

As we are considering the same neuralnetwork, we can train it using the function DeltaSGD from the “Example: DeltaRule” section.

我們只是將該函式的命名修改為DeltaXOR。

We have to just change its name toDeltaXOR.

下面的程式清單顯示了TestDeltaXOR.m檔案的程式碼,用於測試DeltaXOR函式。

The following program listing shows theTestDeltaXOR.m file, which tests the DeltaXOR function.

該程式與“示例:增量規則”一節中的TestDeltaSGD.m檔案相同,只是它對期望的輸出D具有不同的值,並且它呼叫DeltaXOR函式而不是DeltaSGD。

This program is identical to theTestDeltaSGD.m file from the “Example: Delta Rule” section, except that it hasdifferent values for D, and it calls the DeltaXOR function instead of DeltaSGD.

clear all X = [ 0 0 1; 0 1 1; 1 0 1; 1 1 1; ]; D = [ 0 1 1 0];

W = 2*rand(1, 3) - 1;

for epoch = 1:40000 % train

W = DeltaXOR(W,X, D);

end

N = 4; %inference for k = 1:N

x = X(k, ?’;

v = W*x;

y = Sigmoid(v) end

當我們執行以上程式碼時,電腦螢幕將顯示以下值,這些值由訓練後的神經網路對應於訓練資料的輸出組成。

When we run the code, the screen will showthe following values, which consist of the output from the trained neuralnetwork corresponding to the training data.

——本文譯自Phil Kim所著的《Matlab Deep Learning》

更多精彩文章請關注微訊號:在這裡插入圖片描述