Backpropagation hinzugefügt.

This commit is contained in:
paul-loedige 2022-02-16 23:24:54 +01:00
parent 5a2303eb23
commit 0041e5e5de
10 changed files with 80 additions and 4 deletions

View File

@ -52,7 +52,7 @@
\part{Neural Networks}
\label{part:Neural Networks}
\input{chapters/Neural_Networks/Basics.tex}
\input{chapters/Neural_Networks/Neural_Networks_and_Backpropagation.tex}
\input{chapters/Neural_Networks/Backpropagation.tex}
\input{chapters/Neural_Networks/CNNs_and_LSTMs.tex}
\part{Classical Unsupervised Learning}

View File

@ -120,6 +120,7 @@ rightsub = \grq%
\DeclareMathOperator*{\loss}{loss}
\DeclareMathOperator*{\loglik}{loglik}
\DeclareMathOperator*{\softmax}{softmax}
%special symbols
\usepackage{fontawesome}
\usepackage{amssymb}

View File

@ -0,0 +1,78 @@
\chapter{Backpropagation}%
\label{cha:Backpropagation}
Um die einzelnen Gewichte rückwirkend durch die verschiedenen Schichten eines Neural Networks einzulernen wird das Verfahren der Backpropagation benutzt.
Bei diesem Verfahren wird der \nameref{sec:Gradient Descent} verwendet.
Die eigentliche Backpropagation findet erst dann statt,
wenn die Anpassungen,
die sich aus dem \nameref{sec:Gradient Descent} ergeben rückwirkend auf die verschiedenen Schichten des Neural Networks angewandt werden sollen.
Die Loss Function errechnet sich hier durch
\begin{equation} \label{eq:backpropagration_loss_function}
\mathcal L(\bm\theta,\mathcal D) = \sum_{i=1}^N l(\bm x_i,\bm\theta) + \nomeq{regularization_factor}\text{ penalty}(\bm\theta)
\end{equation}
\begin{wrapfigure}{r}{.5\textwidth}
\vspace*{-5mm}
\centering
\includegraphics[width=.8\linewidth]{back_propagation.png}
\caption{Zusammenhang zwischen Errechnung der Loss Function und Errechnung der partiellen Ableitungen}
\label{fig:backpropagation}
\vspace*{-15mm}
\end{wrapfigure}
Um die Gewichtsvektoren auf Basis dieser Loss Function anzupassen muss die partielle Ableitung für die jeweilige Gewichtsmatrix und den Biasvektor gezogen werden.
Hierfür ist die Kettenregel nützlich,
die die Regeln für die partielle Ableitung vorgibt
\begin{equation} \label{eq:chain_rule}
\frac{d}{dt}f(x(t)) = \frac{df}{dx}\frac{dx}{dt}
\end{equation}
In \cref{fig:backpropagation} ist dieser Ablauf am Beispiel eines zweistufigen Neuronalen Netzes gezeigt.
Hier berechnet sich der Loss durch
\begin{align} \label{eq:forward_pass}
z &= wx + b\\
y &= \sigma(z)\\
\mathcal L &= \frac{1}{2}(y-t)^2
\end{align}
Für dieses Neural Network ist die Backpropagation dann
\begin{alignat}{5} \label{eq:backward_pass}
\frac{\partial \mathcal L}{\partial y} &= y - t &&
&&=\overline{y}\\
\frac{\partial \mathcal L}{\partial z} &= \frac{\partial\mathcal L}{\partial y}\frac{\partial y}{\partial z} &&= \frac{\partial\mathcal L}{\partial y}\sigma'(z)
&&=\overline{z} &&= \overline{y}\sigma'(z)\\
\frac{\partial \mathcal L}{\partial w} &= \frac{\partial\mathcal L}{\partial z}\frac{\partial z}{\partial w} &&= \frac{\partial\mathcal L}{\partial z} x
&&=\overline{w} &&= \overline{z}x \\
\frac{\partial \mathcal L}{\partial b} &= \frac{\partial\mathcal L}{\partial z}\frac{\partial z}{\partial b}
&&= \frac{\partial\mathcal L}{\partial z} \cdot 1 &&=\overline{b} &&=\overline{z}
\end{alignat}
Wenn sich der Graph des Neural Networks sich allerdings verzweigt (mehrere Neuronen auf einer Schicht) muss die multivariable Kettenregel (multivariable chain rule) verwendet werden
\begin{equation} \label{eq:multivariable_chain_rule}
\frac{d}{dt}f(x(t),y(t)) = \frac{\partial f}{\partial x}\frac{dx}{dt} + \frac{\partial f}{\partial y}\frac{dy}{dt}
\end{equation}
Die Anwendung dieser Regel wird in den folgenden zwei Beispielen deutlich
\paragraph{Example: univariate logistic least squares regression}%
\label{par:Example: univariate logistic least squares regression}
\mbox{}\\
\includegraphics[scale=.65]{univariate_logisitc_least_squares_regression.png}
\paragraph{Example: Multi-layer Perceptron (multiple outputs)}%
\label{par:Example: Multi-layer Perceptron}
\mbox{}\\
\includegraphics[scale=.65]{multi-layer_perceptron.png}\\
Mithilfe der Matrix-Rechentricks aus \cref{sec:Matrix-Calculus} ist es möglich die Backpropagation für das Multi-layer Perceptron in Matrix-Form aufzuschreiben:\\
({\color{red}Herleitung Vorlesung 08 Folien 52 und 53})\\
\includegraphics[scale=.65]{multi-layer_perceptron_matrix_form.png}
\section{Computational costs}%
\label{sec:Computational costs}
Die Computational Costs für eine Backpropagation ergibt sich als Summe aus dem Forward Pass und dem Backward Pass.
Die Kosten für den Forward Pass sind in etwa linear in der Anzahl der Gewichte,
da für jedes Gewicht in etwa eine Addition und Multiplikation nötig ist.
\begin{equation} \label{eq:computational_cost_forward_pass}
\bm z = \bm W\bm x + \bm b
\end{equation}
Die Kosten für den Backward Pass sind ebenfalls in etwa linear,
mit jeweils zwei Additionen und Multiplikationen pro Gewicht.
\begin{equation} \label{eq:computational_cost_backward_pass}
\overline{\bm W} = \overline{\bm h}\bm z^T,\quad\overline{\bm h} = \bm W^T\overline{\bm y}
\end{equation}
In Summe ergeben sich also \say{nur} etwa 3 Additionen und Multiplikationen pro Gewicht.
Da der Algorithmus allerdings während des Trainings eines Neural Networks sehr sehr oft durchlaufen wird,
ist der Rechenaufwand dennoch sehr hoch, weshalb sich Neural Networks erst in den letzten 5"~10 Jahren durchsetzen konnten.

View File

@ -1,3 +0,0 @@
\chapter{Neural Networks and Backpropagation}%
\label{cha:Neural Networks and Backpropagation}

BIN
images/back_propagation.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
images/g542.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 949 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 667 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 748 KiB