[regression] translations I

This commit is contained in:
Jan Grewe 2018-10-10 18:05:42 +02:00
parent fde6fb6177
commit 51a8183f33

View File

@ -1,196 +1,171 @@
\chapter{\tr{Optimization and gradient descent}{Optimierung und Gradientenabstieg}}
\selectlanguage{ngerman}
% \selectlanguage{ngerman}
To understand the behaviour of a given system sciences often probe the
system with input signals and then try to explain the responses
through a model. Typically the model has a few parameter that specify
how input and output signals are related. The question arises which
combination of paramters are best suited to describe the relation of
in- and output. The process of finding the best paramter set is called
optimization or also \enterm{curve fitting}. One rather generic
approach to the problem is the so called gradient descent method which
will be introduced in this chapter.
Ein sehr h\"aufiges Problem ist, dass die Abh\"angigkeit von
Messwerten von einer Eingangsgr\"o{\ss}e durch ein Modell erkl\"art
werden soll. Das Modell enth\"alt \"ublicherweise einen oder mehrere
Parameter, die den Zusammenhang modifizieren. Wie soll die beste
Parameterisierung des Modells gefunden werden, so dass das Modell die
Daten am besten beschreibt? Dieser Prozess der Parameteranpassung ist
ein Optimierungsproblem, der als Kurvenfit bekannt ist
(\enterm{curve fitting}).
\begin{figure}[t]
\includegraphics[width=1\textwidth]{lin_regress}\hfill
\titlecaption{Beispieldatensatz f\"ur den Geradenfit.}{F\"ur eine
Reihe von Eingangswerten $x$, z.B. Stimulusintensit\"aten, wurden
die Antworten $y$ eines Systems gemessen (links). Der postulierte
lineare Zusammenhang hat als freie Parameter die Steigung (mitte)
und den $y$-Achsenabschnitt (rechts).}\label{linregressiondatafig}
\titlecaption{Example data suggesting a linear relation.}{A set of
input signals $x$, e.g. stimulus intensities, were used to probe a
system. The system's output $y$ to the inputs are noted
(left). Assuming a linear relation between $x$ and $y$ leaves us
with 2 parameters, the slope (center) and the intercept with the
y-axis (right panel).}\label{linregressiondatafig}
\end{figure}
Die Punktewolke in \figref{linregressiondatafig} legt
zum Beispiel nahe, einen (verrauschten) linearen Zusammenhang zwischen
der Eingangsgr\"o{\ss}e $x$ (\enterm{input}) und der Systemantwort
$y$ (\enterm{output}) zu postulieren.
Wir nehmen also an, dass die Geradengleichung
\[y = f(x; m, b) = m\cdot x + b \]
ein gutes Modell f\"ur das zugrundeliegende System sein k\"onnte
(Abbildung \ref{linregressiondatafig}). Die Geradengleichung hat die
beiden Parameter Steigung $m$ und $y$-Achsenabschnitt $b$ und es wird
die Kombination von $m$ und $b$ gesucht, die die Systemantwort am
besten vorhersagt.
In folgenden Kapitel werden wir anhand dieses Beispiels zeigen, welche
Methoden hinter einem Kurvenfit stecken, wie also numerisch die
optimale Kombination aus Steigung und $y$-Achsen\-abschnitt gefunden
werden kann.
\section{Mittlere quadratischen Abweichung}
Zuerst m\"u{\ss}en wir pr\"azisieren, was wir unter optimalen
Parametern verstehen. Es sollen die Werte der Parameter der
Geradengleichung sein, so dass die entsprechende Gerade am besten die
Daten beschreibt. Was meinen wir damit? Jeder $y$-Wert der $N$
Datenpaare wird einen Abstand $y_i - y^{est}_i$ zu den durch das
Modell vorhergesagten Werten $y^{est}_i$ (\enterm{estimate}) an den
entsprechenden $x$-Werten haben. In unserem Beispiel mit der
Geradengleichung ist die Modellvorhersage $y^{est}_i=f(x_i;m,b)$
gegeben durch die Geradengleichung
(\figref{leastsquareerrorfig}). F\"ur den besten Fit sollten dieser
Abst\"ande m\"oglichst klein sein.
Wir k\"onnten z.B. fordern, die Summe $\sum_{i=1}^N y_i - y^{est}_i$
m\"oglichst klein zu machen. Das funktioniert aber nicht, da diese
Summe auch dann klein wird, wenn die H\"alfte der $y$-Daten weit
oberhalb der Geraden und die andere H\"alfte weit darunter liegt, da
sich diese positiven und negativen Werte gegenseitig zu Zahlen nahe
Null aufsummieren. Besser w\"are es auf jeden Fall, die Summe des
Betrags der Abst\"ande $\sum_{i=1}^N |y_i - y^{est}_i|$ zu betrachten. Ein
kleiner Wert der Summe kann dann nur erreicht werden, wenn die
Abst\"ande der Datenpunkte von der Kurve tats\"achlich klein sind,
unabh\"angig ob sie \"uber oder unter der Gerade liegen. Statt der
Summe k\"onnen wir genauso gut fordern, dass der \emph{mittlere} Abstand
The data plotted in \figref{linregressiondatafig} suggests a linear
relation between input and output of the invesitagted system. We thus
assume that the linear equation
\[y = f(x; m, b) = m\cdot x + b \] is an appropriate model to describe the system.
The linear equation has two free paramteter $m$ and $b$ which denote
the slope and the y-intercept, respectively. In this chapter we will
use this example to illustrate the methods behind several curve
fitting approaches. We will apply this method to find the combination
of slope and intercept that best describes the system.
\section{The error function --- mean square error}
Before the optimization can be done we need to specify what is
considered an optimal fit. In our example we search the parameter
combination that describe the relation of $x$ and $y$ best. What is
meant by this? Each input $x_i$ leads to an output $y_i$ and for each
$x_i$ there is a \emph{prediction} or \emph{estimation}
$y^{est}_i$. For each of $x_i$ estimation and measurement will have a
certain distance $y_i - y_i^{est}$. In our example the estimation is
given by the linear equation $y_i^{est} = f(x;m,b)$. The best fit of
the model with the parameters $m$ and $b$ leads to the minimal
distances between observation $y_i$ and estimation $y_i^{est}$
(\figref{leastsquareerrorfig}).
We could require that the sum $\sum_{i=1}^N y_i - y^{est}_i$ is
minimized. This approach, however, will not work since a minimal sum
can also be achieved if half of the measurements is above and the
other half below the predicted line. Positive and negative errors
would cancel out and then sum up to values close to zero. A better
approach is to consider the absolute value of the distance
$\sum_{i=1}^N |y_i - y^{est}_i|$. The total error can only be small if
all deviations are indeed small no matter if they are above or below
the prediced line. Instead of the sum we could also ask for the
\emph{average}
\begin{equation}
\label{meanabserror}
f_{dist}(\{(x_i, y_i)\}|\{y^{est}_i\}) = \frac{1}{N} \sum_{i=1}^N |y_i - y^{est}_i|
\end{equation}
der Menge der $N$ Datenpaare $(x_i, y_i)$ gegeben die Modellvorhersagen
$y_i^{est}$ klein sein soll.
Am h\"aufigsten wird jedoch bei einem Kurvenfit der \determ[mittlerer
quadratische Abstand]{mittlere quadratische Abstand} (\enterm{mean
squared distance} oder \enterm{mean squared error})
should be small. Commonly, the \enterm{mean squared distance} oder
\enterm{mean squared error}
\begin{equation}
\label{meansquarederror}
f_{mse}(\{(x_i, y_i)\}|\{y^{est}_i\}) = \frac{1}{N} \sum_{i=1}^N (y_i - y^{est}_i)^2
\end{equation}
verwendet (\figref{leastsquareerrorfig}). Wie beim Betrag sind die
quadratischen Abst\"ande immer positiv, unabh\"angig ob die Datenwerte
\"uber oder unter der Kurve liegen. Durch das Quadrat werden
zus\"atzlich gro{\ss}e Abst\"ande st\"arker gewichtet.
is used (\figref{leastsquareerrorfig}). Similar to the absolute
distance, the square of the error($(y_i - y_i^{est})^2$) is always
positive error values do not cancel out. The square further punishes
large deviations.
\begin{exercise}{meanSquareError.m}{}\label{mseexercise}%
Schreibe eine Funktion \code{meanSquareError()}, die die mittlere
quadratische Abweichung zwischen einem Vektor mit den beobachteten
Werten $y$ und einem Vektor mit den entsprechenden Vorhersagen
$y^{est}$ berechnet.
\pagebreak[4]
Implement a function \code{meanSquareError()}, that calculates the
\emph{mean square distance} bewteen a vector of observations ($y$)
and respective predictions ($y^{est}$). \pagebreak[4]
\end{exercise}
\section{Zielfunktion}
\section{\tr{Objective function}{Zielfunktion}}
$f_{cost}(\{(x_i, y_i)\}|\{y^{est}_i\})$ ist eine sogenannte
\determ{Zielfunktion}, oder \determ{Kostenfunktion} (\enterm{objective
function}, \enterm{cost function}), da wir die Modellvorhersage so
anpassen wollen, dass der mittlere quadratische Abstand, also die
Zielfunktion, minimiert wird. In
Kapitel~\ref{maximumlikelihoodchapter} werden wir sehen, dass die
Minimierung des mittleren quadratischen Abstands \"aquivalent zur
Maximierung der Wahrscheinlichkeit ist, dass die Daten aus der
Modellfunktion stammen, unter der Vorraussetzung, dass die Daten
um die Modellfunktion normalverteilt streuen.
$f_{cost}(\{(x_i, y_i)\}|\{y^{est}_i\})$ is a so called
\enterm{objective function} or \enterm{cost function}. We aim to adapt
the model parameters to minimize the error (mean square error) and
thus the \emph{objective function}. In Chapter~\ref{maximumlikelihood}
we will show that the minimization of the mean square error is
equivalent to maximizing the likelihood that the observations
originate from the model (assuming a normal distribution of the data
around the model prediction).
\begin{figure}[t]
\includegraphics[width=1\textwidth]{linear_least_squares}
\titlecaption{Ermittlung des mittleren quadratischen Abstands.}
{Der Abstand (\enterm{error}, orange) zwischen der Vorhersage (rote
Gerade) und den Messdaten (blaue Punkte) wird f\"ur jeden
gemessenen Datenpunkt ermittelt (links). Anschlie{\ss}end werden
die Differenzen zwischen Messwerten und Vorhersage quadriert
(\enterm{squared error}) und der Mittelwert berechnet (rechts).}
\titlecaption{Estimating the \emph{mean square error}.} {The
deviation (\enterm{error}, orange) between the prediction (red
line) and the observations (blue dots) is calculated for each data
point (left). Then the deviations are squared and the aveage is
calculated (right).}
\label{leastsquareerrorfig}
\end{figure}
Die Kostenfunktion mu{\ss} nicht immer der mittlere quadratische
Abstand sein. Je nach Problemstellung kann die Kostenfunktion eine
beliebige Funktion sein, die die Parameter eines Modells auf einen
Wert abbildet, der in irgendeiner Weise die Qualit\"at des Modells
quantifiziert. Ziel ist es dann, diejenigen Parameterwerte zu finden,
bei der die Kostenfunktion minimiert wird.
%%% Einfaches verbales Beispiel?
Wenn wir nun in unsere Gleichung \eqref{meansquarederror} f\"ur die
Modellvorhersage $y^{est}$ die Geradengleichung einsetzen, erhalten wir
f\"ur die Zielfunktion
The error or also \enterm{cost function} is not necessarily the mean
square distance but can be any function that maps the predictions to a
scalar value describing the quality of the fit. In the optimization
process we aim for the paramter combination that minimized the costs
(error).
%%% Einfaches verbales Beispiel? Eventuell aus der Populationsoekologie?
Replacing $y^{est}$ with the linear equation (the model) in
(\eqnref{meansquarederror}) we yield:
\begin{eqnarray}
f_{cost}(\{(x_i, y_i)\}|m,b) & = & \frac{1}{N} \sum_{i=1}^N (y_i - f(x_i;m,b))^2 \label{msefunc} \\
& = & \frac{1}{N} \sum_{i=1}^N (y_i - m x_i - b)^2 \label{mseline}
\end{eqnarray}
den mittleren quadratischen Abstand der Datenpaare $(x_i, y_i)$
gegeben die Parameterwerte $m$ und $b$ der Geradengleichung. Ziel des
Kurvenfits ist es, die Werte f\"ur $m$ und $b$ so zu optimieren, dass
der Fehler \eqnref{mseline} minimal wird (\determ{Methode der
kleinsten Quadrate}, \enterm{least square error}).
That is, the meas square error given the pairs $(x_i, y_i)$ and the
parameters $m$ and $b$ of the linear equation. The optimization
process will not try to optimize $m$ and $b$ to lead to the smallest
error, the method of the \enterm{least square error}.
\begin{exercise}{lsqError.m}{}
Implementiere die Zielfunktion f\"ur die Optimierung mit der
linearen Geradengleichung als Funktion \code{lsqError()}.
Implement the objective function \code{lsqError()} that applies the
linear equation as a model.
\begin{itemize}
\item Die Funktion \"ubernimmt drei Argumente: Das erste Argument
ist ein 2-elementiger Vektor, der die Parameter \varcode{m} und
\varcode{b} enth\"alt. Das zweite ist ein Vektor mit den $x$-Werten,
an denen gemessen wurde, und das dritte ein Vektor mit den
zugeh\"origen $y$-Werten.
\item Die Funktion gibt als Ergebniss den Fehler als mittleren
quadratischen Abstand \eqnref{mseline} zur\"uck.
\item Die Funktion soll die Funktion \code{meanSquareError()} der
vorherigen \"Ubung benutzen.
\item The function takes three arguments. The first is a 2-element
vector that contains the values of parameters \varcode{m} and
\varcode{b}. The second is a vector of x-values the third contains
the measurements for each value of $x$, the respecive $y$-values.
\item The function returns the mean square error \eqnref{mseline}.
\item The function should call the function \code{meanSquareError()}
defined in the previouos exercise to calculate the error.
\end{itemize}
\end{exercise}
\section{Fehlerfl\"ache}
Die beiden Parameter $m$ und $b$ der Geradengleichung spannen eine
F\"ache auf. F\"ur jede Kombination aus $m$ und $b$ k\"onnen wir den
Wert der Zielfunktion, hier der mittlere quadratische Abstand
\eqnref{meansquarederror}, berechnen. Wir betrachten also die
Kostenfunktion $f_{cost}(\{(x_i, y_i)\}|m,b)$ nun als Funktion
$f_{cost}(m,b)$, die die beiden Variablen $m$ und $b$ auf einen
Fehlerwert abbildet.
\section{Error surface}
The two parameters of the model define a surface. For each combination
of $m$ and $b$ we can use \eqnref{mseline} to calculate the associated
error. We thus consider the objective function $f_{cost}(\{(x_i,
y_i)\}|m,b)$ as a function $f_{cost}(m,b)$, that maps the variables
$m$ and $b$ to an error value.
Es gibt also f\"ur jeden Punkt in der sogenannten
\determ{Fehlerfl\"ache} einen Fehlerwert. In diesem Beispiel eines
2-dimensionalen Problems (zwei freie Parameter) kann die
Fehlerfl\"ache graphisch durch einen 3-d \enterm{surface-plot}
dargestellt werden. Dabei werden auf der $x$- und der $y$-Achse die
beiden Parameter und auf der $z$-Achse der Fehlerwert aufgetragen
Thus, for each spot of the surface we get an error that we can
illustrate graphically using a 3-d surface-plot, i.e. the error
surface. $m$ and $b$ are plotted on the $x-$ and $y-$ axis while the
third dimension is used to indicate the error value
(\figref{errorsurfacefig}).
\begin{figure}[t]
\includegraphics[width=0.75\columnwidth]{error_surface.pdf}
\titlecaption{Fehlerfl\"ache.}{Die beiden freien Parameter
unseres Modells $m$ und $b$ spannen die Grundfl\"ache des Plots
auf. F\"ur jede Kombination von Steigung $m$ und
$y$-Achsenabschnitt $b$ wird die errechnete Vorhersage des Modells
mit den Messwerten verglichen und der Fehlerwert geplottet. Die
sich ergebende Fehlerfl\"ache hat ein Minimum (roter Punkt) bei
den Werten von $m$ und $b$, f\"ur die die Gerade die Daten am
besten beschreibt.}\label{errorsurfacefig}
\titlecaption{Error surface.}{The two model parameters $m$ and $b$
define the base area of the surface plot. For each parameter
combination of slope and intercept the error is calculated. The
resulting surface has a minimum which indicates the parameter
combination that best fits the data.}\label{errorsurfacefig}
\end{figure}
\begin{exercise}{errorSurface.m}{}\label{errorsurfaceexercise}%
Lade den Datensatz \textit{lin\_regression.mat} in den Workspace (20
Datenpaare in den Vektoren \varcode{x} und \varcode{y}). Schreibe ein Skript
\file{errorSurface.m}, dass den Fehler, berechnet als mittleren
quadratischen Abstand zwischen den Daten und einer Geraden mit
Steigung $m$ und $y$-Achsenabschnitt $b$, in Abh\"angigkeit von $m$
und $b$ als surface plot darstellt (siehe Hilfe f\"ur die
\code{surf()} Funktion).
Load the dataset \textit{lin\_regression.mat} into the workspace (20
data pairs contained in the vectors \varcode{x} and
\varcode{y}). Implement a script \file{errorSurface.m}, that
calculates the mean square error between data and a linear model und
illustrates the error surface using the \code{surf()} function
(consult the help to find out how to use \code{surf}.).
\end{exercise}
An der Fehlerfl\"ache kann direkt erkannt werden, bei welcher