\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb}
\usepackage{algorithm,algpseudocode}
\usepackage{bm}
\usepackage{hyperref}
\usepackage{float}
\usepackage{subcaption}
\usepackage{enumitem}
\usepackage{xcolor}
\definecolor{darkgreen}{rgb}{0.0, 0.5, 0.0}
\definecolor{aaltoBlue}{RGB}{0, 51, 102}
\definecolor{pinegreen}{cmyk}{0.92,0,0.59,0.25}
\definecolor{royalblue}{cmyk}{1,0.50,0,0}
\definecolor{lavander}{cmyk}{0,0.48,0,0}
\definecolor{violet}{cmyk}{0.79,0.88,0,0}
\definecolor{lightblue}{RGB}{173, 216, 230}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc,arrows.meta,positioning,fit,shapes.geometric,shapes.misc,intersections,patterns,decorations.pathreplacing,backgrounds,matrix}
\usepgfplotslibrary{fillbetween,groupplots}
\setcounter{secnumdepth}{-\maxdimen}
% Long unbreakable tokens (the ISO/IEC author names in citations, term names
% in the title) otherwise overflow the margin by a few points; a modest
% emergency stretch lets TeX loosen the paragraph instead.
\emergencystretch=2em
\usepackage{mleftright}
% Project macros used by this entry (auto-extracted).
\newcommand{\dataset}{\mathcal{D}}
\newcommand{\feature}{x}
\newcommand{\hypothesis}{h}
\newcommand{\learnthypothesis}{\widehat{\hypothesis}}
\newcommand{\lossfunc}[2]{L\left(#1,#2 \right)}
\newcommand{\mI}{\mathbf{I}}
\newcommand{\normgeneric}[2]{\mleft\lVert #1 \mright\rVert_{#2}}
\newcommand{\pair}[2]{\left( #1,#2 \right)}
\newcommand{\regparam}{\alpha}
\newcommand{\regularizer}[1]{\mathcal{R}\big\{ #1 \big\}}
\newcommand{\sampleidx}{r}
\newcommand{\samplesize}{m}
\newcommand{\truelabel}{y}
\newcommand{\uncertset}{\mathcal{U}}
\newcommand{\vw}[0]{{\bf w}}
\newcommand{\weight}{w}
\newcommand{\weights}{\vw}

\begin{document}

\section{data augmentation}

\subsection*{Author and editors}
Alexander Jung\textsuperscript{*}, Department of Computer Science, Aalto University, Espoo, Finland (ORCID \mbox{\href{https://orcid.org/0000-0001-7538-0990}{0000-0001-7538-0990}}) \\
Editors: Konstantina Olioumtsevits (ORCID \mbox{\href{https://orcid.org/0000-0003-2697-8659}{0000-0003-2697-8659}}), Ekkehard Schnoor (ORCID \mbox{\href{https://orcid.org/0000-0001-8252-1499}{0000-0001-8252-1499}}), Aalto University, Espoo, Finland \\
\textsuperscript{*}Corresponding author: \href{mailto:alex.jung@aalto.fi}{alex.jung@aalto.fi}



\subsection{Abstract}
Data augmentation enlarges a training set with synthetic
		data points obtained from transformations or perturbations of
		existing ones. Typical examples are rotating or cropping an image
		and adding small perturbations to the features and
		labels of a measured data point. If the label does
		not change under a transformation, training on transformed copies
		makes the learned hypothesis vary little under it. Sensing
		devices measure with limited precision, so perturbed copies reflect
		the uncertainty interval around each recorded value. Data
		augmentation is a form of regularization, beside
		model pruning and adding a penalty term to the
		training error. For linear regression, perturbing the features
		with zero-mean noise whose covariance matrix is a multiple of
		the identity is, in expectation over the noise, equivalent to
		adding the ridge regression penalty term.

\subsection{Definition}
Three measured days at Krems an der Donau
	(Austria) are all a forecaster has to learn from. Each day is a
	data point, characterized by the air temperature at $06{:}00$
	(UTC) as its feature $\feature$, and the temperature at
	$15{:}00$ (UTC) of the same day as its
	label $\truelabel$ (Fig.~\ref{fig_dataaug_picture_dict}). The figure also shows a
		learned hypothesis map $\learnthypothesis$, obtained by
		empirical risk minimization (ERM) using the polynomials of degree two as hypothesis space.
\par
		The learned hypothesis achieves zero training error but
		delivers poor predictions outside the training set, which
		is overfitting. On a held-out set of $106$ data points
		obtained from other days of 2024, whose feature lies inside
		the measured range, its average squared error loss is $335.3$ squared
		degrees. One reason for the failure of $\learnthypothesis$ is that
		the training set is too small. For almost every training set of
		sample size $\samplesize = 3$ there is one polynomial of degree
		two passing through its data points.
\par
		Data augmentation enlarges a dataset with synthetic
		data points, obtained by perturbations of the
		features and labels of the measured ones. Sensing
		devices have imperfections such as thermal noise, so a reading
		$\feature$ is one representative of an uncertainty interval
		$\uncertset^{(\feature)}$. Any other value from that interval could
		have been observed instead.
\par
		Considering the weather data from
		Fig.~\ref{fig_dataaug_picture_dict}, a temperature reading
		$\feature$ carries
		$\uncertset^{(\feature)} = [\feature - 1, \feature + 1]$. Each
		measured day $\pair{\feature}{\truelabel}$ is replaced by $400$
		copies $\pair{\feature + \varepsilon}{\truelabel + \varepsilon'}$,
		whose perturbations $\varepsilon$ and $\varepsilon'$ are
		realizations of random variables (RVs) distributed uniformly on
		$[-1, 1]$. The augmented training set $\widetilde{\dataset}$ holds
		$1200$ data points, none of which required a new temperature
		measurement. The width of the uncertainty interval used for
		the perturbation of the features and labels is a
		hyperparameter. One basic way to determine it is to try a few
		choices and compare the validation error of the resulting learned
		hypotheses.
\par
		Fig.~\ref{fig_dataaug_picture_dict} also shows the polynomial of
		degree two $\learnthypothesis'$ that ERM learns using
		$\widetilde{\dataset}$ as training set. The hypothesis
		$\learnthypothesis'$ no longer passes through the three measured
		days, but it delivers better predictions outside the training set. Its
		training error on them is $4.0$ squared degrees, but its average
		squared error loss on the held-out data points falls to $25.7$.
		The coefficient of $\feature^{2}$ drops from
		$\widehat{\weight}_{2} = 1.87$ for $\learnthypothesis$ to
		$\widehat{\weight}_{2}' = 0.11$ for $\learnthypothesis'$.
		\begin{figure}[H]
		\centering
		\begin{tikzpicture}
			\begin{axis}[
				width=0.72\linewidth, height=0.46\linewidth,
				xlabel={feature $\feature$: the $06{:}00$ reading in $^{\circ}$C},
				ylabel={label $\truelabel$: the $15{:}00$ reading in $^{\circ}$C},
				axis lines=left,
				xmin=2.5, xmax=12.5, ymin=-16, ymax=20,
				legend style={draw=none, fill=none, font=\scriptsize,
					at={(0.5,-0.36)}, anchor=north, legend columns=1},
				tick label style={font=\small},
				label style={font=\small},
				]
				\addplot[thick, black]
					table[col sep=comma, x=x, y=interpolant]
					{dataaug_curves.csv};
				\addlegendentry{$\learnthypothesis$ learned from three
					measured days}
				\addplot[thick, black, dashed]
					table[col sep=comma, x=x, y=augmented]
					{dataaug_curves.csv};
				\addlegendentry{$\learnthypothesis'$ learned from the
					augmented training set $\widetilde{\dataset}$}
				\addplot[only marks, mark=square, mark size=1.3pt, black!55]
					table[col sep=comma, x=x, y=y]
					{dataaug_copies_plot.csv};
				\addlegendentry{perturbed copies in $\widetilde{\dataset}$}
				\addplot[only marks, mark=*, mark size=2.4pt, black]
					table[col sep=comma, x=x, y=y]
					{dataaug_points.csv};
				\addlegendentry{original dataset $\dataset$}
			\end{axis}
		\end{tikzpicture}
		\caption{Three data points (filled circles) that represent
			daily weather conditions at Krems an der Donau. The solid curve
			is the degree-two polynomial $\learnthypothesis$ with a
			training error of zero on them. It dips far below every
			temperature that was measured. The open squares are copies drawn
			from the uncertainty interval of each measured day, five
			of the copies of every day. The
			dashed curve is the hypothesis $\learnthypothesis'$
			learned from them. Data generated by
			\texttt{pythondemos/dataaug.py}
			\label{fig_dataaug_picture_dict}}
		\end{figure}
		Enlarging $\dataset$ with perturbed copies is one basic form of
		regularization, beside model pruning, which shrinks the
		hypothesis space, and adding a penalty term to the
		training error. These different forms of regularization are
		sometimes equivalent in their effect on the learned
		hypothesis (Fig.~\ref{fig_dataaug_routes_dict}). For
		linear regression, adding
		zero-mean perturbations with covariance matrix $\sigma^{2} \mI$ to
		each feature vector yields the ridge regression solution,
		asymptotically in the number of copies. Its penalty term is
		$\sigma^{2} \normgeneric{\weights}{2}^{2}$ for the weight
		vector $\weights$ (Bishop, 1995;
		Goodfellow et al., 2016, Sect.~7.5).
		\begin{figure}[H]
		\centering
		\begin{tikzpicture}
			\begin{axis}[
				width=0.72\linewidth, height=0.44\linewidth,
				xlabel={feature $\feature$: the $06{:}00$ reading in $^{\circ}$C},
				ylabel={label $\truelabel$: the $15{:}00$ reading in $^{\circ}$C},
				axis lines=left,
				xmin=2.5, xmax=12.5, ymin=-16, ymax=20,
				legend style={draw=none, fill=none, font=\scriptsize,
					at={(0.5,-0.36)}, anchor=north, legend columns=2,
					/tikz/every even column/.append style={column sep=0.6em}},
				tick label style={font=\small},
				label style={font=\small},
				]
				\addplot[thick, black]
					table[col sep=comma, x=x, y=interpolant]
					{dataaug_curves.csv};
				\addlegendentry{$\learnthypothesis$, plain ERM}
				\addplot[thick, black, dashed]
					table[col sep=comma, x=x, y=featonly]
					{dataaug_routes.csv};
				\addlegendentry{$\learnthypothesis'$ after regularization}
				\addplot[only marks, mark=square, mark size=1.3pt, black!55]
					table[col sep=comma, x=x, y=y]
					{dataaug_featcopies.csv};
				\addlegendentry{copies in $\widetilde{\dataset}$ with $\feature$ perturbed alone}
				\addplot[only marks, mark=*, mark size=2.4pt, black]
					table[col sep=comma, x=x, y=y]
					{dataaug_points.csv};
				\addlegendentry{original dataset $\dataset$}
				\draw[<->, thick] (axis cs:3,17) -- (axis cs:5,17);
				\node[font=\footnotesize, above] at (axis cs:4,17.2)
					{width of $\uncertset^{(\feature)}$};
			\end{axis}
		\end{tikzpicture}
		\\[0.3em]
		$\underbrace{\frac{1}{\samplesize}
			\sum_{\sampleidx=1}^{\samplesize}
			\lossfunc{\pair{\feature^{(\sampleidx)}}
			{\truelabel^{(\sampleidx)}}}{\hypothesis}}_{\text{training error}}
		\;+\; \underbrace{\regparam
			\regularizer{\hypothesis}}_{\text{penalty term}}$
		\caption{The three forms of regularization on the
			data points of Fig.~\ref{fig_dataaug_picture_dict}. Only
			the feature is perturbed here, the case the equivalence
			with ridge regression covers, so each open square sits
			beside its measured day at the same label. The double
			arrow marks the width of the uncertainty interval they
			are drawn from. Enlarging the training set with them replaces
			the solid curve $\learnthypothesis$ by the dashed one, which
			stays within $0.05\,^{\circ}$C of the $\learnthypothesis'$ of
			Fig.~\ref{fig_dataaug_picture_dict}. Adding the
			penalty term $\regparam \regularizer{\hypothesis}$ to the
			training error, shown below the plot, is the second form.
			Shrinking the hypothesis space to
			$\{\hypothesis : |\weight_{2}| \leq 0.10\}$ is the third; the
			hypothesis it yields lands within $0.11\,^{\circ}$C of the
			dashed curve and is not drawn separately. Data
			generated by \texttt{pythondemos/dataaug.py} Markers and lines: copies in $\widetilde{\dataset}$ with $\feature$ perturbed alone (open squares) and original dataset $\dataset$ (filled circles).
			\label{fig_dataaug_routes_dict}}
		\end{figure}
		Instead of adding noise to the features and labels,
		perturbations can also come from a transformation $\mathcal{T}$ of
		the feature space. A transformation known to leave the
		label alone is a symmetry of the learning task. A rotated or cropped image of a
		cat still shows a cat, while its feature vector, obtained by
		stacking the pixel color intensities, changes. The
		transformation must preserve the label, and a rotation does
		so only up to a point. Fig.~\ref{fig_dataaug_mnist_dict} reduces
		images of the handwritten digits 6 and 9 to their first two
		principal directions (see principal component analysis (PCA)) as features
		$\feature_{1}, \feature_{2}$. A small rotation $\mathcal{T}$ keeps
		an image of a 6 among the other 6s. However, rotating an image by
		$180$ degrees carries it into the 9s, where the label has
		changed.
		\begin{figure}[H]
		\centering
		\begin{tikzpicture}
			\begin{axis}[
				name=mnistaxis, clip=false,
				width=0.66\linewidth, height=0.44\linewidth,
				xlabel={$\feature_{1}$}, ylabel={$\feature_{2}$},
				axis lines=left,
				legend style={draw=none, fill=none, font=\scriptsize,
					at={(0.5,-0.32)}, anchor=north, legend columns=3,
					/tikz/every even column/.append style={column sep=0.5em}},
				tick label style={font=\footnotesize},
				label style={font=\small},
				]
				\addplot[only marks, mark=o, mark size=1.1pt, black!55]
					table[col sep=comma, x=x1, y=x2]
					{dataaug_mnist_six.csv};
				\addlegendentry{image of a 6}
				\addplot[only marks, mark=triangle, mark size=1.4pt, black]
					table[col sep=comma, x=x1, y=x2]
					{dataaug_mnist_nine.csv};
				\addlegendentry{image of a 9}
				\addplot[thick, black, mark=square*, mark size=1.5pt]
					table[col sep=comma, x=x1, y=x2]
					{dataaug_mnist_path.csv};
				\addlegendentry{the 6, rotated}
				% Each inlay sits above its own point of the path, and a
				% thin ruler joins the two. Both ends are \coordinate, and
				% the rulers are drawn after \end{axis}: a node declared
				% inside a pgfplots axis does not resolve outside it, so a
				% ruler anchored on the image node came out truncated.
				\coordinate (topC) at (axis cs:-2.8402,4.6);
				\coordinate (topB) at (axis cs:1.0786,4.6);
				\coordinate (topA) at (axis cs:2.7934,4.6);
				\coordinate (markC) at (axis cs:-2.8402,0.7122);
				\coordinate (markB) at (axis cs:1.0786,0.5829);
				\coordinate (markA) at (axis cs:2.7934,-0.1223);
				\node[anchor=south, inner sep=1pt] (inlayC) at (topC)
					{\includegraphics[width=0.95cm]
						{dataaug_six_180.png}};
				\node[anchor=south, inner sep=1pt] (inlayB) at (topB)
					{\includegraphics[width=0.95cm]
						{dataaug_six_030.png}};
				\node[anchor=south, inner sep=1pt] (inlayA) at (topA)
					{\includegraphics[width=0.95cm]
						{dataaug_six_000.png}};
				\node[font=\scriptsize, above=1pt] at (inlayC.north)
					{$180^{\circ}$};
				\node[font=\scriptsize, above=1pt] at (inlayB.north)
					{$30^{\circ}$};
				\node[font=\scriptsize, above=1pt] at (inlayA.north)
					{$0^{\circ}$};
			\end{axis}
			% a white halo lifts each ruler off the markers it crosses; at
			% 0.1pt (very thin) the line was invisible against them
			\draw[line width=1.8pt, white] (topC) -- (markC);
			\draw[line width=0.45pt, black!70, shorten >=2.5pt]
				(topC) -- (markC);
			\draw[line width=1.8pt, white] (topB) -- (markB);
			\draw[line width=0.45pt, black!70, shorten >=2.5pt]
				(topB) -- (markB);
			\draw[line width=1.8pt, white] (topA) -- (markA);
			\draw[line width=0.45pt, black!70, shorten >=2.5pt]
				(topA) -- (markA);
		\end{tikzpicture}
		\caption{Images of the handwritten digits 6 (circles) and 9
			(triangles), each represented by two features
			$\feature_{1}, \feature_{2}$ obtained from PCA. The
			solid line with
			square marks is the path that one image of a 6 traces as it is
			rotated from $0$ to $180$ degrees. The three inlays above the
			plot are that image upright, turned by $30$ degrees, and turned
			by $180$ degrees, each placed above its own point of the path. Its first steps keep the
			image among the 6s, so a rotation by a small angle preserves the
			label. Its last steps place the image among the 9s. Data
			generated by \texttt{pythondemos/dataaug.py}
			\label{fig_dataaug_mnist_dict}}
		\end{figure}

\subsection{Cross References}
regularization, model pruning, penalty term, ridge regression, overfitting, ERM, training set, dataset, hypothesis space, hypothesis, data point, feature, label, feature vector, feature space, uncertainty, hyperparameter, validation error, polynomial regression, learning task

\subsection{References}
\begin{enumerate}
  \item Bishop (1995). Training with Noise is Equivalent to Tikhonov Regularization. Neural Computation, 7(1), pp.~108--116.
  \item Goodfellow et al. (2016). Deep Learning. MIT Press, Cambridge, MA, USA.
\end{enumerate}

\end{document}
