2017-08-02 65 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中扩展它,请将其写入注释中,以扩展代码。

所以你已经找到了所有的衍生物。也许这不是你正在寻找的东西。我甚至不确定我写的所有内容是否正确(我希望是这样),我会尽量在这几天编写反向传播代码,这样我就可以纠正错误。我希望这会有所帮助;有总比没有好。

最好的问候,马可。