\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{\datapoint}{\vz}
\newcommand{\distof}[1]{\probdist^{(#1)}}
\newcommand{\feature}{x}
\newcommand{\featurespace}{\mathcal{X}}
\newcommand{\genericevent}{\mathcal{A}}
\newcommand{\outcome}{\omega}
\newcommand{\prob}[1]{\mathbb{P}\left(#1\right)}
\newcommand{\probdist}{\mathbb{P}}
\newcommand{\probspace}{(\samplespace,\, \sigmaalgebra,\, \probdist)}
\newcommand{\probspacerep}[1]{\probspace^{(#1)}}
\newcommand{\samplesize}{m}
\newcommand{\samplespace}{\Omega}
\newcommand{\sigmaalgebra}{\Sigma}
\newcommand{\vz}[0]{{\bf z}}

\begin{document}

\section{random experiment}

\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}
A random experiment is a physical or computational data-generating process that produces an outcome $\outcome$ 
	               from a known set of possibilities, the sample space of the experiment. Probability theory represents the 
	               process by a probability space $\probspace$, where the $\sigma$-algebra $\sigmaalgebra$ collects the measurable
		       events and the probability measure $\prob{\cdot}$ assigns each event a probability. This representation is a
		      probabilistic model of the process, not a property of it. A measurement of the outcome is represented by a random variable (RV), 
		      a measurable function $\feature : \samplespace \to \featurespace$, and the measured value
	               $\feature(\outcome)$ is a realization. Repeating the experiment $\samplesize$ times is itself a random 
	               experiment on the product sample space, and the measurements of the runs are modeled as
	               independent and identically distributed (i.i.d.) RVs. In machine learning (ML), the construction of a training set, the draw of a subset of it by stochastic gradient descent (SGD), and the
	noise added for differential privacy (DP) are random experiments.

\subsection{Definition}
The weather station Krems an der Donau (Austria) records the air
   temperature at $06{:}00$ and at $15{:}00$ (UTC) of every day
   (Fig.~\ref{fig_randomexperiment_january_dict}). On any
   given day neither temperature is known in advance, but the range they can take is. A process of that 
   kind is a random experiment: it produces an outcome $\outcome$ from a set $\samplespace$ of 
   possibilities, the sample space of the experiment (Bertsekas and Tsitsiklis, 2008, Sect.~1.2; Billingsley, 1986).
   The outcome is uncertain, and the experiment can be repeated under identical conditions. Here one 
   day is one run: the outcome $\outcome$ is the weather of that day, and the two recorded temperatures are measurements of it.
  \begin{figure}[H]
   \centering
   \begin{tikzpicture}
			\begin{axis}[
			width=0.86\linewidth, height=0.42\linewidth,
			axis lines=left,
			xlabel={day of January 2023}, ylabel={temperature ($^{\circ}$C)},
			xmin=0, xmax=32, ymin=-8, ymax=18,
			tick label style={font=\scriptsize},
			label style={font=\small},
			legend style={font=\scriptsize, draw=none, fill=none,
			at={(0.5,-0.32)}, anchor=north, legend columns=2},
			]
			\addplot[ycomb, black, mark=*, mark size=1.3pt]
			table[col sep=comma, x=day, y=t15]{randomexperiment_january.csv};
			\addlegendentry{temperature at $15{:}00$ (UTC)}
			\addplot[ycomb, black, densely dotted, mark=o, mark size=1.5pt]
			table[col sep=comma, x=day, y=t06]{randomexperiment_january.csv};
			\addlegendentry{temperature at $06{:}00$ (UTC)}
			\end{axis}
		\end{tikzpicture}
		\caption{The air temperature at $15{:}00$ (solid stems, filled
		circles) and at $06{:}00$ (UTC) (dotted stems, open circles) of every day of
		January 2023 at the weather station Krems an der Donau
		(Austria). Each day is one run of the same random experiment:
		the outcome is the weather of that day, and the two
		temperatures are measurements of it. The month as a whole can
		instead be read as a single random experiment, whose
		outcome is the ordered list of the $31$ daily
		outcomes. Data
		generated by
		\texttt{pythondemos/randomexperiment.py}
		\label{fig_randomexperiment_january_dict}}
  \end{figure}
Probability theory represents a random experiment by a probability space $\probspace$ (Bertsekas and Tsitsiklis, 2008, Sect.~1.2; Billingsley, 1986, Sect.~2).
 The sample space $\samplespace$ collects the possible outcomes $\outcome \in \samplespace$. 
 The $\sigma$-algebra $\sigmaalgebra$ collects the events, those subsets $\genericevent \subseteq \samplespace$ 
 to which a probability is assigned. The probability measure $\prob{\cdot}$ assigns to each event 
 $\genericevent \in \sigmaalgebra$ a number $\prob{\genericevent} \in [0,1]$ such that $\prob{\samplespace} = 1$ 
 and the probability of a countable union of pairwise disjoint events is the sum of their probabilities. 
 The triple $\probspace$ is a probabilistic model of the process, not a property of it. There are principled methods for choosing
 a useful probabilistic model $\probspace$ based on the observed data.
\par
 Rolling a die is a random experiment small enough to write the triple
 out. Its sample space is $\samplespace = \{1, \ldots, 6\}$. Its
 $\sigma$-algebra $\sigmaalgebra$ is the collection of all subsets of
 $\samplespace$: that the roll is even is the event $\genericevent = \{2,4,6\}$.
 The uniform probability measure, $\prob{\genericevent} = |\genericevent| / 6$, is the
 model of a fair die, under which $\prob{\{2,4,6\}} = 1/2$. Whether a given
 die is fair is a question about the process rather than about the model,
 answered by the relative frequencies of its outcomes in many rolls.
\par
 The observed data are measurements of the outcome of the experiment. In particular, each measurement is a 
 measurable function $\feature : \samplespace \to \featurespace$ of the outcome. Such a measurable 
 function is a random variable (RV), and the value $\feature(\outcome)$ it takes for the actual outcome $\outcome$ is a realization 
 of it (Billingsley, 1986; Gray, 2009). The temperature at 13:00 is an RV on the weather of a day, 
 and the number read on one day is a realization.
\par
 The probability measure on $\samplespace$ induces the probability distribution of the RV, $\distof{\feature}(\mathcal{B}) = \prob{\feature \in
 \mathcal{B}}$ for every measurable set $\mathcal{B} \subseteq \featurespace$ (Billingsley, 1986, Sect.~20).
 Fig.~\ref{fig_randomexperiment_model_dict} shows the process beside its mathematical representation: the experiment, 
 its outcome and the measured value above, the probability space and the RV that represent them below. 
	\begin{figure}[H]
		\centering
		\begin{tikzpicture}[>=Stealth, font=\scriptsize,
			box/.style={draw, rounded corners, align=center, inner sep=4pt,
			minimum height=0.8cm}]
			% top row: the process
			\node[box] (exp) {random\\experiment};
			\node[right=1.5cm of exp] (om) {outcome $\outcome \in \samplespace$};
			\node[right=1.3cm of om] (val) {realization $\feature(\outcome) \in \featurespace$};
			\draw[->, thick] (exp) -- node[above] {produces} (om);
			\draw[->, thick] (om) -- node[above] {measurement} (val);
			% bottom row: the representation
			\node[box, below=1.3cm of exp] (ps) {probability space\\$\probspace$};
			% pinned to the row of (ps): "below=... of val" put the two
			% lower boxes at different heights and slanted the arrow
			\node[box] (rv) at (val |- ps) {RV $\feature : \samplespace \to \featurespace$\\probability distribution $\distof{\feature}$};
			\draw[->, thick] (ps) -- node[above] {measurable function on $\samplespace$} (rv);
			% the modeling step
			\draw[->, dashed] (exp) -- node[right] {represented by} (ps);
			\draw[->, dashed] (val) -- node[left] {represented by} (rv);
			\node[anchor=south west] at ([yshift=0.25cm]exp.north west) {process};
			\node[anchor=north west] at ([yshift=-0.25cm]ps.south west) {probabilistic model};
		\end{tikzpicture}
		\caption{A random experiment and its mathematical representation.
		The upper row is the process, the lower row the model, as the
		labels at the left mark. Boxed items are objects, the
		experiment, the probability space and the RV; unboxed items
		are the values they produce. Solid arrows stay within one row;
		the dashed arrows cross from the process to its model. The
		process produces an outcome $\outcome$; a measurement of
		that outcome is a measurable function
		$\feature$ on $\samplespace$, an RV, and the value
		$\feature(\outcome)$ it takes is a realization. The
		probability distribution $\distof{\feature}$ of $\feature$ is
		induced by $\prob{\cdot}$
		\label{fig_randomexperiment_model_dict}}
	\end{figure}
 Repeating a random experiment $\probspace$ a fixed number $\samplesize$ of times, under identical conditions,
 defines a new random experiment $\probspacerep{\samplesize}$ whose outcomes are sequences
 $(\outcome^{(1)}, \ldots, \outcome^{(\samplesize)})$ of outcomes of the original one (Fig.~\ref{fig_randomexperiment_dict}). 
 Its sample space is the product $\samplespace^{(\samplesize)} = \samplespace \times \cdots \times \samplespace$,
 and its probability measure is the product $\distof{\samplesize} = \probdist \times \cdots \times \probdist$.
 The measurements $\feature^{(1)}, \ldots, \feature^{(\samplesize)}$ of the runs are then independent and identically distributed (i.i.d.) RVs (Billingsley, 1986, Sect.~20).
 In machine learning (ML) these measurements are the data points $\datapoint^{(1)}, \ldots, \datapoint^{(\samplesize)}$ of a training set.
 While the outcome of a single experiment is uncertain, the long-run behavior of repeated experiments becomes
 predictable: the law of large numbers and the central limit theorem (CLT) make this precise (Bertsekas and Tsitsiklis, 2008, Sects.~5.2 and~5.4).
	\begin{figure}[H]
		\begin{center}
			\begin{tikzpicture}[>=Stealth, node distance=1.5cm and 2cm, every node/.style={font=\small}]
			\node (experiment) [draw, rectangle, rounded corners, minimum width=2.6cm, align=center] {random\\experiment};
			\node (omega) [right=of experiment] {$\outcome \in \samplespace$};
			\coordinate (rightpad) at ($(omega.east) + (0.2,0)$);
			\draw[->] (experiment) -- (omega);
			\node (sequence) [below=of experiment, yshift=-0.5cm] {$(\outcome^{(1)}, \,\outcome^{(2)}, \,\dots, \,\outcome^{(\samplesize)})$};
			\node (sequence1) [below=of sequence, yshift=-0.5cm] {$(\datapoint^{(1)}, \,\datapoint^{(2)}, \,\dots, \,\datapoint^{(\samplesize)})$};
			\draw[->, thick] (experiment.south) -- node[midway, right, xshift=3pt] {repeat $\samplesize$ times} (sequence.north);
			\draw[->, thick] (sequence.south) -- node[midway, right, xshift=3pt] {RVs} (sequence1.north);
			\path (experiment.south) -- (sequence.north) coordinate[pos=0.6] (repeatpoint);
			\node[draw=black, rounded corners, dotted, fit={(experiment) (repeatpoint) (rightpad)}, inner sep=8pt, label=above:{new random experiment with $\samplespace^{(\samplesize)} = \samplespace \times \ldots \times \samplespace$}] {};
			\end{tikzpicture}
		\end{center}
		\caption{Repeating a random experiment $\probspace$ a fixed number $\samplesize$ of times yields another random experiment $\probspacerep{\samplesize}$
		whose outcomes are sequences $(\outcome^{(1)}, \,\outcome^{(2)}, \,\dots, \,\outcome^{(\samplesize)}) \in \samplespace\times\ldots\times \samplespace$.
		One random experiment arising in many ML applications is the gathering of a training set $\datapoint^{(1)},\,\ldots,\,\datapoint^{(\samplesize)}$, whose
		data points are RVs on the repeated runs. Boxes and arrows follow Fig.~\ref{fig_randomexperiment_model_dict} \label{fig_randomexperiment_dict}}
	\end{figure}
 The notion of a repeated experiment is an idealization that might result in a poor probabilistic model for a 
 physical or computational data-generating process. Successive rolls of a die can typically be considered a repeated 
 experiment. In contrast, the daily weather observations shown in Fig.~\ref{fig_randomexperiment_january_dict} 
 are not well represented as the result of a repeated experiment: a
 warm day tends to follow a warm day, so the daily readings are
 related rather than independent. The autocorrelation of such
 a record measures that relation
 (Brockwell and Davis, 1991, Sect.~1.5; Hyndman and Athanasopoulos, 2021).
\par
	Random experiments arise in ML in three places:
	\begin{itemize}
	 \item Data collection: the data points $\datapoint^{(1)}, \ldots, \datapoint^{(\samplesize)}$ of a training set are 
	         modeled as RVs, i.e., as functions of the outcome $\outcome \in \samplespace$ of a random experiment, 
	         and the independent and identically distributed assumption (i.i.d.\ assumption) models their collection as the repetition of one experiment. Empirical risk minimization (ERM) minimizes the average 
	         loss over those $\samplesize$ data points; because they are i.i.d. RVs with probability distribution 
	         $\distof{\datapoint}$, that average estimates the risk of a hypothesis, an expectation under 
	         $\distof{\datapoint}$, which is what makes the risk a meaningful target for ERM.
		\item Stochastic algorithms: stochastic gradient descent (SGD) runs a random experiment at each iteration, the draw of 
		     a subset of the training set; the bootstrap draws resamples of the training set.
		\item Privacy protection methods run a random experiment to perturb the outputs of an ML method, which is what
			differential privacy (DP) requires.
	\end{itemize}

\subsection{Cross References}
outcome, sample space, event, RV, realization, probability, probability space, probability measure, probability distribution, probabilistic model, i.i.d., law of large numbers, CLT, autocorrelation

\subsection{References}
\begin{enumerate}
  \item Bertsekas and Tsitsiklis (2008). Introduction to Probability. 2nd ed., Athena Scientific, Belmont, MA, USA.
  \item Billingsley (1986). Probability and Measure. 2nd ed., Wiley, New York, NY, USA.
  \item Brockwell and Davis (1991). Time Series: Theory and Methods. 2nd ed., Springer-Verlag, New York, NY, USA.
  \item Gray (2009). Probability, Random Processes, and Ergodic Properties. 2nd ed., Springer Science+Business Media, New York, NY, USA.
  \item Hyndman and Athanasopoulos (2021). Forecasting: Principles and Practice. 3rd ed., OTexts, Melbourne, Australia.
\end{enumerate}

\end{document}
