\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{\featuredim}{d}
\newcommand{\featurespace}{\mathcal{X}}
\newcommand{\reals}{\mathbb{R}}
\newcommand{\sampleidx}{r}
\newcommand{\samplesize}{m}
\newcommand{\samplespace}{\Omega}

\begin{document}

\section{random variable (RV)}

\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 variable (RV) is a measurable function
		that maps each outcome of a random experiment to an
		element of a measurable space. Important types of RVs
		include binary RVs, discrete random variables (discrete RVs), real-valued RVs,
		random vectors, and random matrices. The analysis of
		machine learning (ML) methods often relies on probabilistic models that represent
		data sources as RVs. The most widely used probabilistic model assumes
		that data points are independent and identically distributed (i.i.d.) RVs with a common probability distribution,
		which is unknown in general.

\subsection{Definition}
The weather on a given day in the Austrian city Krems an der Donau is the
			outcome of a random experiment
			(Hyndman and Athanasopoulos, 2021). Each possible outcome
			$\omega$ is characterized by a maximum daytime temperature, the
			temperature at 13:00, and recording this temperature assigns a real
			number $x(\omega)$ to the outcome. This assignment is an
			RV $x$. The temperatures recorded on
			consecutive days are realizations of this RV
			(see Fig.~\ref{fig_rv_stem}).
		\begin{figure}[H]
			\begin{center}
			\begin{tikzpicture}
				\begin{axis}[
					width=9cm, height=5cm,
					axis lines=left,
					xlabel={day}, ylabel={temperature at 13:00 ($^{\circ}$C)},
					ymin=0, xtick={1,10,20,30},
				]
					\addplot[ycomb, black, mark=*, mark size=1.2pt]
						table[col sep=comma, x=day, y=temp]{rv_stem.csv};
				\end{axis}
			\end{tikzpicture}
			\end{center}
			\caption{Each day's maximum daytime temperature, read at 13:00, is a
				realization of the real-valued RV $x$; the stem plot shows one
				realization per day over 30 consecutive days. Data generated by
				\texttt{pythondemos/rv.py}\label{fig_rv_stem}}
		\end{figure}
 		More generally, an RV maps the outcomes of a random experiment
		to elements of a measurable space
			(Billingsley, 1986; Gray, 2009).
 		Mathematically, an RV is a measurable function $x: \samplespace \rightarrow \featurespace$
		whose domain is the sample space $\samplespace$ of a probability space and
		whose co-domain is a measurable space $\featurespace$.
		Measurability refers to the $\sigma$-algebras of the two spaces:
		the preimage $x^{-1}(B)$ of every measurable set $B \subseteq \featurespace$
		must belong to the $\sigma$-algebra of the probability space, so that
		the probability of $x$ taking a value in $B$ is defined.
			The value $x(\omega) \in \featurespace$ that $x$ assigns to an
			outcome $\omega \in \samplespace$ is the image of $\omega$ under
			$x$ (see Fig.~\ref{fig_rv_map}).
		\begin{figure}[H]
			\begin{center}
			\begin{tikzpicture}[font=\small]
				\draw[thick] (0,0) ellipse (1.35cm and 1.15cm);
				\node[font=\scriptsize, anchor=south] at (0,1.2)
					{sample space $\samplespace$};
				\foreach \x/\y in {-0.4/0.6, 0.35/0.45, -0.55/-0.15,
								   0.3/-0.35, -0.15/-0.75}
					\fill (\x,\y) circle (1.6pt);
				\node[font=\scriptsize, anchor=south] at (-0.4,0.68) {$\omega$};
				\draw[thick] (5.0,0) ellipse (1.1cm and 1.0cm);
				\node[font=\scriptsize, anchor=south] at (5.0,1.05)
					{measurable space $\featurespace$};
				\foreach \x/\y in {4.75/0.45, 5.35/-0.1, 4.85/-0.55}
					\fill (\x,\y) circle (1.6pt);
				\node[font=\scriptsize, anchor=west] at (4.85,0.52)
					{$x(\omega)$};
				\draw[->, thick] (-0.4,0.6) -- (4.75,0.45);
				\draw[->, gray] (0.35,0.45) -- (4.75,0.45);
				\draw[->, gray] (-0.55,-0.15) -- (4.85,-0.55);
				\draw[->, gray] (0.3,-0.35) -- (5.35,-0.1);
				\draw[->, gray] (-0.15,-0.75) -- (4.85,-0.55);
				\draw[->, thick] (1.55,1.5) -- (3.45,1.5)
					node[midway, above, font=\scriptsize] {$x$};
			\end{tikzpicture}
			\end{center}
			\caption{An RV $x$ sends each outcome $\omega$ of a
				random experiment to its image $x(\omega)$ in a
				measurable space $\featurespace$. The black arrow follows
				one outcome; the gray arrows show the remaining
				outcomes, two of which share the same image. An RV can
				therefore map a large sample space into a small
				measurable space \label{fig_rv_map}}
		\end{figure}
 		Different types of RVs include
 		\begin{itemize} 
 			\item {binary RVs}, which map each outcome to an element of a binary 
			set (e.g., $\{-1,1\}$ or $\{\text{cat}, \text{no cat}\}$); 
			\item {discrete random variables (discrete RVs)}, which take on values in a countable set (which can
			be finite or countably infinite; e.g., the number of heads in ten coin flips, with values in $\{0,1,\ldots,10\}$);
 			\item {real-valued RVs}, which take on values in the real numbers $\reals$ (e.g., the maximum daytime temperature in Krems);
 			\item {random vectors}, which map outcomes to the Euclidean space $\reals^{\featuredim}$ (e.g., the red-green-blue (RGB) values of a pixel, which form a vector in $\reals^{3}$);
			\item {random matrices}, which map outcomes to a space of matrices $\reals^{\samplesize \times \featuredim}$ (e.g., the data matrix of a dataset).
 		\end{itemize}
 		The sample space and the RVs on it are a modeling choice, not fixed
 		by the data. The daily Krems temperatures admit two standard constructions
 		(Fig.~\ref{fig_rv_spaces}).
 		In the first, each day $\sampleidx$ has its own probability space with
 		sample space $\samplespace^{(\sampleidx)}$, and the
 		temperature of that day is an RV
 		$x^{(\sampleidx)} : \samplespace^{(\sampleidx)} \rightarrow \reals$; the
 		recorded value is one realization
 		$x^{(\sampleidx)}(\omega^{(\sampleidx)})$. In the second, one probability space
 		with sample space $\samplespace$
 		represents all days at once: a single outcome $\omega \in \samplespace$
 		fixes the temperatures of all days, and each day is an RV
 		$x^{(\sampleidx)} : \samplespace \rightarrow \reals$ on this common space.
 		The independent and identically distributed (i.i.d.) assumption is a statement about the second construction: the
 		$x^{(\sampleidx)}$ share one probability distribution and are independent, a
 		property defined for random variables (RVs) on one common probability space
 		(Billingsley, 1986, Sect.~20). The
 		common-space construction is the one used for learning from data, because a
 		single probability distribution then governs an entire dataset.
		\begin{figure}[H]
			\begin{center}
			\begin{tikzpicture}[font=\scriptsize,
				dot/.style={circle, fill, inner sep=1pt}]
				% ---- left: a separate probability space per day
				\foreach \i/\y in {1/1.2, 2/0.35, 3/-0.5} {
					\draw (0,\y) ellipse (0.5cm and 0.33cm);
					\node[dot] (dL\i) at (0,\y) {};
					\node[anchor=east] at (-0.55,\y) {$\samplespace^{(\i)}$};
					\node[anchor=west] (tL\i) at (1.85,\y) {$t_{\i}$};
					\draw[->] (dL\i) -- (tL\i.west)
						node[midway, above] {$x^{(\i)}$};
				}
				\node at (0,-1.15) {$\vdots$};
				\node[font=\scriptsize] at (1.0,-1.65) {(a)};
				% ---- right: one common probability space
				\begin{scope}[xshift=5.3cm]
					\draw (0,0.35) ellipse (0.7cm and 1.15cm);
					\node[anchor=south] at (0,1.5) {$\samplespace$};
					\node[dot] (o) at (0,0.35) {};
					\node[anchor=east] at (-0.08,0.35) {$\omega$};
					\foreach \i/\y in {1/1.2, 2/0.35, 3/-0.5} {
						\node[anchor=west] (tR\i) at (1.95,\y) {$t_{\i}$};
						\draw[->] (o) -- (tR\i.west)
							node[pos=0.6, above] {$x^{(\i)}$};
					}
					\node[anchor=west] at (1.95,-1.15) {$\vdots$};
					\node[font=\scriptsize] at (1.0,-1.65) {(b)};
				\end{scope}
			\end{tikzpicture}
			\end{center}
			\caption{Two constructions for the daily Krems an der Donau temperatures
				$t_{\sampleidx}$. (a) Each day $\sampleidx$ has its own
				probability space with sample space $\samplespace^{(\sampleidx)}$
				and RV
				$x^{(\sampleidx)}$, with a separate outcome per day. (b)
				One probability space with sample space $\samplespace$ represents
				all days at once, so a
				single outcome $\omega$ fixes every day's temperature
				$t_{\sampleidx} = x^{(\sampleidx)}(\omega)$; only this construction
				supports modeling the days as i.i.d. RVs\label{fig_rv_spaces}}
		\end{figure}
		In machine learning (ML), RVs represent data sources, so that the behavior of
		learning methods can be analyzed.
 		For example, the generation of a training set or
 		validation set is represented by i.i.d. RVs sharing one underlying
 		probability distribution in the common-space construction. This probability distribution is
 		either postulated or estimated from
 		actual datasets, for example via maximum likelihood. Ideally, an
 		ML method should work well on datasets that arise as
 		realizations of high probability. This is the generalization goal
 		that empirical risk minimization (ERM) pursues, minimizing the average loss on the training set
 		as a proxy for the expected loss of the learned hypothesis
 		on a new data point drawn from the common probability distribution.

\subsection{Cross References}
function, random experiment, sample space, probability space, vector, Euclidean space, probability, measurable, realization, probabilistic model, random vector, random matrix, sub-Gaussian RV

\subsection{References}
\begin{enumerate}
  \item Billingsley (1986). Probability and Measure. 2nd ed., Wiley, 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}
