現在、私はNeural Networks and Deep Learningを読んでおり、問題が残っています。問題は、彼がL2正則化の代わりにL1正則化を使用するために与えたコードを更新することです。ミニバッチ更新でL1正規化を実行する
L2正則化を使用するコードの元の部分である:
self.weights
をL2正則用語を使用して更新されることが分かる
def update_mini_batch(self, mini_batch, eta, lmbda, n):
"""Update the network's weights and biases by applying gradient
descent using backpropagation to a single mini batch. The
``mini_batch`` is a list of tuples ``(x, y)``, ``eta`` is the
learning rate, ``lmbda`` is the regularization parameter, and
``n`` is the total size of the training data set.
"""
nabla_b = [np.zeros(b.shape) for b in self.biases]
nabla_w = [np.zeros(w.shape) for w in self.weights]
for x, y in mini_batch:
delta_nabla_b, delta_nabla_w = self.backprop(x, y)
nabla_b = [nb+dnb for nb, dnb in zip(nabla_b, delta_nabla_b)]
nabla_w = [nw+dnw for nw, dnw in zip(nabla_w, delta_nabla_w)]
self.weights = [(1-eta*(lmbda/n))*w-(eta/len(mini_batch))*nw
for w, nw in zip(self.weights, nabla_w)]
self.biases = [b-(eta/len(mini_batch))*nb
for b, nb in zip(self.biases, nabla_b)]
。 L1正則化のために、私はちょうどそれは、私たちはミニを使用して
用語を推定することができる本に記載されている
を反映するために、その同じ行を更新する必要があることと考えています - バッチ平均。これは私にとっては紛らわしい声明でしたが、各ミニバッチで各レイヤーの平均値をnabla_w
とすることが考えられました。
def update_mini_batch(self, mini_batch, eta, lmbda, n):
"""Update the network's weights and biases by applying gradient
descent using backpropagation to a single mini batch. The
``mini_batch`` is a list of tuples ``(x, y)``, ``eta`` is the
learning rate, ``lmbda`` is the regularization parameter, and
``n`` is the total size of the training data set.
"""
nabla_b = [np.zeros(b.shape) for b in self.biases]
nabla_w = [np.zeros(w.shape) for w in self.weights]
for x, y in mini_batch:
delta_nabla_b, delta_nabla_w = self.backprop(x, y)
nabla_b = [nb+dnb for nb, dnb in zip(nabla_b, delta_nabla_b)]
nabla_w = [nw+dnw for nw, dnw in zip(nabla_w, delta_nabla_w)]
avg_nw = [np.array([[np.average(layer)] * len(layer[0])] * len(layer))
for layer in nabla_w]
self.weights = [(1-eta*(lmbda/n))*w-(eta)*nw
for w, nw in zip(self.weights, avg_nw)]
self.biases = [b-(eta/len(mini_batch))*nb
for b, nb in zip(self.biases, nabla_b)]
が、私は約10%の精度で、かなりノイズだけです取得結果:これは、コードを次のように編集を行うために私を導きました。私は文を間違って解釈しているのですか、またはコードが間違っていますか?どんなヒントもありがとう。
これは非常に非常に役に立ちました。私は、L1とL2の正則化の概念的な記述が目の開きであることを発見しました。ありがとうございました! –