2017-08-02 58 views
0

我一直在努力獲得反向傳播的一些熟練,並且已經運行了標準的數學公式來做到這一點。我實施了一個似乎可以正常工作的解決方案(並通過了有關飛行顏色的相關測試)。反向傳播公式似乎無法實現

但是...實際的解決方案(在MATLAB中實現,並使用向量化)在兩個重要方面與公式不一致。

的計算公式如下:

enter image description here

三角二層=(θ-二層轉)×Δ-三層點X gprime( - 現在並不重要)

工作代碼如下所示:

% d3 is delta3, d2 is delta2, Theta2 is minus the bias column 
% dimensions: d3--[5000x10], d2--[5000x25], Theta2--[10x25] 

d3 = (a3 - y2); 
d2 = (d3 * Theta2) .* gPrime(z2); 

我無法調和一下我用數學公式來實現,基於兩點:

  1. 工作代碼反轉表達式第一部分中的術語;
  2. 工作代碼不轉置theta- layer2,但公式確實。

這怎麼可能?單個矩陣的尺寸似乎不允許任何其他工作組合。

喬希

+0

它可能只取決於設置,兩個實現如何定義矩陣。注意你不能做'Theta2'。 * d2'具有給定的尺寸。 – David

+0

哦,我注意到了。這就是促使我首先發布這個問題的原因。 –

回答

2

這不是一個錯誤的問題,我不是爲什麼那些downvotes;反向傳播算法的實現並不直觀。我在數學上並不是很優秀,我從來沒有使用過MATLAB(通常是c),所以我首先回避了這個問題,但它應該得到它。

首先,我們必須做一些簡化。

,我們將僅使用一個in_Data設定成:vector in_Data[N](在下文中N = 2的情況下)(如果我們成功白衣只在基質中的拍不難延伸它)。

我們將用這個結構:2 I,2小時,2 O(我們成功了白衣這個,我們將與所有成功的)這個網絡(我已經被盜:this blog

enter image description here

讓我們開始:我們知道,更新權重:

enter image description here

注:M=num_pattern,但是我們之前已經聲明in_data作爲向量,所以你可以用刪除上面公式中的和和下面公式中的矩陣。因此,這是你的新公式:

enter image description here

我們將學習2個連接:W1和W5。讓我們寫的導數:

enter image description here

enter image description here

enter image description here

讓我們的代碼是:(我真的不知道MATLAB所以我會寫一個僞代碼)

vector d[num_connections+num_output_neurons] // num derivatives = num connections whitout count bias there are 8 connections. ; +2 derivative of O) 
vector z[num_neurons]  // z is the output of each neuron. 
vector w[num_connections] // Yes a Vector! we have previous removed matrix and the sum. 

// O layer 
d[10] = (a[O1] - y[O1]); // Start from last to calculate the error. 
d[9] = (a[O2] - y[O2]); 

// H -> O layer 
for i=5; i<=8; i++ (Hidden to Out layer connections){ 
    d[i] = (d)*g_prime(z[i]) 
} 

// I -> H layer 

for i=1; i<=8 i++ (Input to Hidden layer connections){ 

    for j=1; i<=num_connection_from_neuron i++ (Take for example d[1] it depends on how many connections have H1 versus Outputs){ 
    d[i] = d1 + (d[j+4]*w[j+4]) 

    } 
    d[i] = d[i]*g_prime(z[i]); 
} 

如果您需要在Matrix中擴展它,請將其寫入註釋中,以擴展代碼。

所以你已經找到了所有的衍生物。也許這不是你正在尋找的東西。我甚至不確定我寫的所有內容是否正確(我希望是這樣),我會盡量在這幾天編寫反向傳播代碼,這樣我就可以糾正錯誤。我希望這會有所幫助;有總比沒有好。

最好的問候,馬可。