Geri yayılım algoritması


19

Çok katmanlı algılayıcıda (MLP) kullanılan geri yayılım algoritması üzerinde hafif bir karışıklık var .

Hata, maliyet fonksiyonu tarafından ayarlanır. Geri çoğaltmada, gizli katmanların ağırlığını ayarlamaya çalışıyoruz. Anlayabildiğim çıkış hatası, yani e = d - y[Abonelikler olmadan].

Sorular:

  1. Gizli katman hatası nasıl alınır? Kişi nasıl hesaplar?
  2. Geri çoğaltırsam, uyarlanabilir bir filtrenin maliyet fonksiyonu olarak mı kullanmalıyım yoksa ağırlığı güncellemek için bir işaretçi (C / C ++ 'da) programlama duygusu kullanmalı mıyım?

NN oldukça eski bir teknoloji, bu yüzden korkarım cevap alamayacaksınız çünkü burada kimse onları kullanmıyor ...

@mbq: Sözlerinizden şüphe etmiyorum, ama NN'nin "eski teknoloji" olduğu sonucuna nasıl ulaşıyorsunuz?
steffen

1
@steffen Gözlem yoluyla; Demek istediğim, NN topluluğundan önemli hiç kimsenin çıkmayacağı ve "Hey millet, hayat işimizi bırakıp daha iyi bir şeyle oynayalım!" eğitim. Ve insanlar kendileri için NN düşürüyorlar.

5
Bunu söylediğinizde bunun bir gerçeği vardı, @mbq, ama artık değil.
jerad

1
@jerad Oldukça kolay - Diğer yöntemlerle henüz adil bir karşılaştırma görmedim (Kaggle, doğruluklar için güven aralıklarının olmaması nedeniyle - özellikle tüm yüksek puanlı takımların sonuçları çok yakın olduğunda - adil bir karşılaştırma değildir. Merck yarışmasında olduğu gibi), parametre optimizasyonunun sağlamlığının herhangi bir analizi - ki bu çok daha kötüdür.

Yanıtlar:


27

İlgilenen herkes için burada bulunan bir yazıya cevap vereceğimi düşündüm. Bu, burada açıklanan gösterimi kullanacaktır .

Giriş

Geri yayılımın arkasındaki fikir, ağımızı eğitmek için kullandığımız bir dizi "eğitim örneği" ne sahip olmaktır. Bunların her birinin bilinen bir cevabı var, bu yüzden onları sinir ağına bağlayabilir ve ne kadar yanlış olduğunu bulabiliriz.

Örneğin, el yazısı tanıma özelliğiyle, gerçekte olduklarının yanında çok sayıda el yazısı karakteriniz olur. Daha sonra sinir ağı, her sembolün nasıl tanınacağını "öğrenmek" için backpropagation yoluyla eğitilebilir, bu nedenle daha sonra el yazısı bilinmeyen bir karakterle sunulduğunda, neyin doğru olduğunu belirleyebilir.

Özellikle, sinir ağına bazı eğitim örnekleri giriyoruz, ne kadar iyi olduğunu görüyoruz, daha sonra daha iyi bir sonuç elde etmek için her bir düğümün ağırlıklarını ve önyargılarını ne kadar değiştirebileceğimizi bulmak için "geriye doğru" damlatıyoruz ve ardından buna göre ayarlıyoruz. Bunu yapmaya devam ettikçe, ağ "öğrenir".

Eğitim sürecine dahil edilebilecek başka adımlar da var (örneğin, bırakma), ancak bu sorunun konusu olduğu için çoğunlukla backpropagation'a odaklanacağım.

Kısmi türevler

Kısmi bir türev fx ,bazıxdeğişkenlerine görebir türevidir.fx

Örneğin, f(x,y)=x2+y2 , fx=2x, çünküy2ile ilgili olarak sabit bir basitçex. Benzer şekilde,fy=2y, çünküx2sadecegöre bir sabittiry.

adlandırılan bir fonksiyonun gradyanı, f'dekif her değişken için kısmi türevi içeren bir fonksiyondur. özellikle:

f(v1,v2,...,vn)=fv1e1++fvnen
,

burada ei değişken yönünü gösteren bir birim vektördür v1.

Şimdi, bilgisayarlı sonra bazı fonksiyon için f , biz pozisyonda ise ( v 1 , v 2 , . . . , V , n ) , biz "aşağı slayt" f yönünde giderek - f ( v 1 , v 2 , . . . , v , n ) .ff(v1,v2,...,vn)ff(v1,v2,...,vn)

örneğimizle birim vektörler e 1 = ( 1 , 0 ) ve e 2 = ( 0 , 1 ) şeklindedir , çünkü v 1 = x ve v 2 = y , ve bu vektörler x ve y eksenlerini gösterir. Böylece, f ( x , yf(x,y)=x2+y2e1=(1,0)e2=(0,1)v1=xv2=yxy .f(x,y)=2x(1,0)+2y(0,1)

Şimdi, fonksiyonumuzu "aşağı kaydırmak" için , bir noktada olduğumuzu varsayalım ( - 2 , 4 ) . Sonra - f ( - 2 , - 4 ) = - ( 2 - 2 ( 1 , 0 ) + 2 4 ( 0 , 1 ) ) = - ( ( - 4 , 0 ) yönünde hareket etmeliyiz ) +f(2,4) .f(2,4)=(22(1,0)+24(0,1))=((4,0)+(0,8))=(4,8)

Bu vektörün büyüklüğü bize tepenin ne kadar dik olduğunu verecektir (daha yüksek değerler tepenin daha dik olduğu anlamına gelir). Bu durumda, .42+(8)28.944

Gradient Descent

Hadamard Ürünleri

İki matrisinin Hadamard Ürünü, matris ilavesi gibidir, ancak matrisleri element-wise eklemek yerine element-wise olarak çoğaltırız.A,BRn×m

Formally, while matrix addition is A+B=C, where CRn×m such that

Cji=Aji+Bji
,

The Hadamard Product AB=C, where CRn×m such that

Cji=AjiBji

Computing the gradients

(most of this section is from Neilsen's book).

We have a set of training samples, (S,E), where Sr is a single input training sample, and Er is the expected output value of that training sample. We also have our neural network, composed of biases W, and weights B. r is used to prevent confusion from the i, j, and k used in the definition of a feedforward network.

C(W,B,Sr,Er)

Normalde kullanılan ikinci dereceden maliyettir.

C(W,B,Sr,Er)=0.5j(ajLEjr)2

where aL is the output to our neural network, given input sample Sr

Then we want to find Cwji and Cbji for each node in our feedforward neural network.

We can call this the gradient of C at each neuron because we consider Sr and Er as constants, since we can't change them when we are trying to learn. And this makes sense - we want to move in a direction relative to W and B that minimizes cost, and moving in the negative direction of the gradient with respect to W and B will do this.

To do this, we define δji=Czji as the error of neuron j in layer i.

We start with computing aL by plugging Sr into our neural network.

Then we compute the error of our output layer, δL, via

δjL=CajLσ(zjL)
.

Which can also be written as

δL=aCσ(zL)
.

Next, we find the error δi in terms of the error in the next layer δi+1, via

δi=((Wi+1)Tδi+1)σ(zi)

Now that we have the error of each node in our neural network, computing the gradient with respect to our weights and biases is easy:

Cwjki=δjiaki1=δi(ai1)T

Cbji=δji

Note that the equation for the error of the output layer is the only equation that's dependent on the cost function, so, regardless of the cost function, the last three equations are the same.

As an example, with quadratic cost, we get

δL=(aLEr)σ(zL)

for the error of the output layer. and then this equation can be plugged into the second equation to get the error of the L1th layer:

δL1=((WL)TδL)σ(zL1)
=((WL)T((aLEr)σ(zL)))σ(zL1)

which we can repeat this process to find the error of any layer with respect to C, which then allows us to compute the gradient of any node's weights and bias with respect to C.

I could write up an explanation and proof of these equations if desired, though one can also find proofs of them here. I'd encourage anyone that is reading this to prove these themselves though, beginning with the definition δji=Czji and applying the chain rule liberally.

For some more examples, I made a list of some cost functions alongside their gradients here.

Gradient Descent

Now that we have these gradients, we need to use them learn. In the previous section, we found how to move to "slide down" the curve with respect to some point. In this case, because it's a gradient of some node with respect to weights and a bias of that node, our "coordinate" is the current weights and bias of that node. Since we've already found the gradients with respect to those coordinates, those values are already how much we need to change.

We don't want to slide down the slope at a very fast speed, otherwise we risk sliding past the minimum. To prevent this, we want some "step size" η.

Then, find the how much we should modify each weight and bias by, because we have already computed the gradient with respect to the current we have

Δwjki=ηCwjki

Δbji=ηCbji

Thus, our new weights and biases are

wjki=wjki+Δwjki
bji=bji+Δbji

Using this process on a neural network with only an input layer and an output layer is called the Delta Rule.

Stochastic Gradient Descent

Now that we know how to perform backpropagation for a single sample, we need some way of using this process to "learn" our entire training set.

One option is simply performing backpropagation for each sample in our training data, one at a time. This is pretty inefficient though.

A better approach is Stochastic Gradient Descent. Instead of performing backpropagation for each sample, we pick a small random sample (called a batch) of our training set, then perform backpropagation for each sample in that batch. The hope is that by doing this, we capture the "intent" of the data set, without having to compute the gradient of every sample.

For example, if we had 1000 samples, we could pick a batch of size 50, then run backpropagation for each sample in this batch. The hope is that we were given a large enough training set that it represents the distribution of the actual data we are trying to learn well enough that picking a small random sample is sufficient to capture this information.

However, doing backpropagation for each training example in our mini-batch isn't ideal, because we can end up "wiggling around" where training samples modify weights and biases in such a way that they cancel each other out and prevent them from getting to the minimum we are trying to get to.

To prevent this, we want to go to the "average minimum," because the hope is that, on average, the samples' gradients are pointing down the slope. So, after choosing our batch randomly, we create a mini-batch which is a small random sample of our batch. Then, given a mini-batch with n training samples, and only update the weights and biases after averaging the gradients of each sample in the mini-batch.

Formally, we do

Δwjki=1nrΔwjkri

and

Δbji=1nrΔbjri

where Δwjkri is the computed change in weight for sample r, and Δbjri is the computed change in bias for sample r.

Then, like before, we can update the weights and biases via:

wjki=wjki+Δwjki
bji=bji+Δbji

This gives us some flexibility in how we want to perform gradient descent. If we have a function we are trying to learn with lots of local minima, this "wiggling around" behavior is actually desirable, because it means that we're much less likely to get "stuck" in one local minima, and more likely to "jump out" of one local minima and hopefully fall in another that is closer to the global minima. Thus we want small mini-batches.

On the other hand, if we know that there are very few local minima, and generally gradient descent goes towards the global minima, we want larger mini-batches, because this "wiggling around" behavior will prevent us from going down the slope as fast as we would like. See here.

One option is to pick the largest mini-batch possible, considering the entire batch as one mini-batch. This is called Batch Gradient Descent, since we are simply averaging the gradients of the batch. This is almost never used in practice, however, because it is very inefficient.


Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.