Newer
Older
Lecture_repo / Lectures_my / MC_2016 / Lecture4 / mchrzasz.tex
@mchrzasz mchrzasz on 3 Apr 2016 30 KB update the lectures
\documentclass[11 pt,xcolor={dvipsnames,svgnames,x11names,table}]{beamer}

\usepackage[english]{babel} 
\usepackage{polski}         
\usepackage[skins,theorems]{tcolorbox}
\tcbset{highlight math style={enhanced,
  colframe=red,colback=white,arc=0pt,boxrule=1pt}}

\usetheme[
	bullet=circle,		% Other option: square
	bigpagenumber,		% circled page number on lower right
	topline=true,			% colored bar at the top of the frame 
	shadow=false,			% Shading for beamer blocks
	watermark=BG_lower,	% png file for the watermark
	]{Flip}

%\logo{\kern+1.em\includegraphics[height=1cm]{SHiP-3_LightCharcoal}}
                            

\usepackage[lf]{berenis}
\usepackage[LY1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{emerald}
\usefonttheme{professionalfonts}
\usepackage[no-math]{fontspec}	
\usepackage{listings}
\defaultfontfeatures{Mapping=tex-text}	% This seems to be important for mapping glyphs properly

\setmainfont{Gillius ADF}			% Beamer ignores "main font" in favor of sans font
\setsansfont{Gillius ADF}			% This is the font that beamer will use by default
% \setmainfont{Gill Sans Light}		% Prettier, but harder to read

\setbeamerfont{title}{family=\fontspec{Gillius ADF}}

\input t1augie.fd

%\newcommand{\handwriting}{\fontspec{augie}} % From Emerald City, free font
%\newcommand{\handwriting}{\usefont{T1}{fau}{m}{n}} % From Emerald City, free font
% \newcommand{\handwriting}{}	% If you prefer no special handwriting font or don't have augie

%% Gill Sans doesn't look very nice when boldfaced
%% This is a hack to use Helvetica instead
%% Usage: \textbf{\forbold some stuff}
%\newcommand{\forbold}{\fontspec{Arial}}

\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{amsmath, amssymb}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{colortbl}
\usepackage{mathrsfs} 			% For Weinberg-esque letters
\usepackage{cancel}				% For "SUSY-breaking" symbol
\usepackage{slashed}            % for slashed characters in math mode
\usepackage{bbm}                % for \mathbbm{1} (unit matrix)
\usepackage{amsthm}				% For theorem environment
\usepackage{multirow}			% For multi row cells in table
\usepackage{arydshln} 			% For dashed lines in arrays and tables
\usepackage{siunitx}
\usepackage{xhfill}
\usepackage{grffile}
\usepackage{textpos}
\usepackage{subfigure}
\usepackage{tikz}
\usepackage{hyperref}
%\usepackage{hepparticles}    
\usepackage[italic]{hepparticles}     

\usepackage{hepnicenames} 

% Drawing a line
\tikzstyle{lw} = [line width=20pt]
\newcommand{\topline}{%
  \tikz[remember picture,overlay] {%
    \draw[crimsonred] ([yshift=-23.5pt]current page.north west)
             -- ([yshift=-23.5pt,xshift=\paperwidth]current page.north west);}}



% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\usepackage{tikzfeynman}		% For Feynman diagrams
\usetikzlibrary{arrows,shapes}
\usetikzlibrary{trees}
\usetikzlibrary{matrix,arrows} 				% For commutative diagram
% http://www.felixl.de/commu.pdf
\usetikzlibrary{positioning}				% For "above of=" commands
\usetikzlibrary{calc,through}				% For coordinates
\usetikzlibrary{decorations.pathreplacing}  % For curly braces
% http://www.math.ucla.edu/~getreuer/tikz.html
\usepackage{pgffor}							% For repeating patterns

\usetikzlibrary{decorations.pathmorphing}	% For Feynman Diagrams
\usetikzlibrary{decorations.markings}
\tikzset{
	% >=stealth', %%  Uncomment for more conventional arrows
	vector/.style={decorate, decoration={snake}, draw},
	provector/.style={decorate, decoration={snake,amplitude=2.5pt}, draw},
	antivector/.style={decorate, decoration={snake,amplitude=-2.5pt}, draw},
	fermion/.style={draw=gray, postaction={decorate},
		decoration={markings,mark=at position .55 with {\arrow[draw=gray]{>}}}},
	fermionbar/.style={draw=gray, postaction={decorate},
		decoration={markings,mark=at position .55 with {\arrow[draw=gray]{<}}}},
	fermionnoarrow/.style={draw=gray},
	gluon/.style={decorate, draw=black,
		decoration={coil,amplitude=4pt, segment length=5pt}},
	scalar/.style={dashed,draw=black, postaction={decorate},
		decoration={markings,mark=at position .55 with {\arrow[draw=black]{>}}}},
	scalarbar/.style={dashed,draw=black, postaction={decorate},
		decoration={markings,mark=at position .55 with {\arrow[draw=black]{<}}}},
	scalarnoarrow/.style={dashed,draw=black},
	electron/.style={draw=black, postaction={decorate},
		decoration={markings,mark=at position .55 with {\arrow[draw=black]{>}}}},
	bigvector/.style={decorate, decoration={snake,amplitude=4pt}, draw},
}

% TIKZ - for block diagrams, 
% from http://www.texample.net/tikz/examples/control-system-principles/
% \usetikzlibrary{shapes,arrows}
\tikzstyle{block} = [draw, rectangle, 
minimum height=3em, minimum width=6em]

\def\ARROW{{\color{JungleGreen}{$\Rrightarrow$}}\xspace}  



\usetikzlibrary{backgrounds}
\usetikzlibrary{mindmap,trees}	% For mind map
\newcommand{\degree}{\ensuremath{^\circ}}
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand\Ts{\rule{0pt}{2.6ex}}       % Top strut
\newcommand\Bs{\rule[-1.2ex]{0pt}{0pt}} % Bottom strut

\graphicspath{{images/}}	% Put all images in this directory. Avoids clutter.

% SOME COMMANDS THAT I FIND HANDY
% \renewcommand{\tilde}{\widetilde} % dinky tildes look silly, dosn't work with fontspec
%\newcommand{\comment}[1]{\textcolor{comment}{\footnotesize{#1}\normalsize}} % comment mild
%\newcommand{\Comment}[1]{\textcolor{Comment}{\footnotesize{#1}\normalsize}} % comment bold
%\newcommand{\COMMENT}[1]{\textcolor{COMMENT}{\footnotesize{#1}\normalsize}} % comment crazy bold
\newcommand{\Alert}[1]{\textcolor{Alert}{#1}} % louder alert
\newcommand{\ALERT}[1]{\textcolor{ALERT}{#1}} % loudest alert
%% "\alert" is already a beamer pre-defined
\newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}%

\def\Put(#1,#2)#3{\leavevmode\makebox(0,0){\put(#1,#2){#3}}}

\usepackage{gmp}
\usepackage[final]{feynmp-auto}

\usepackage[backend=bibtex,style=numeric-comp,firstinits=true]{biblatex}
\bibliography{bib}
\setbeamertemplate{bibliography item}[text]

\makeatletter\let\frametextheight\beamer@frametextheight\makeatother

% suppress frame numbering for backup slides
% you always need the appendix for this!
\newcommand{\backupbegin}{
	\newcounter{framenumberappendix}
	\setcounter{framenumberappendix}{\value{framenumber}}
}
\newcommand{\backupend}{
	\addtocounter{framenumberappendix}{-\value{framenumber}}
	\addtocounter{framenumber}{\value{framenumberappendix}} 
}


\definecolor{links}{HTML}{2A1B81}
%\hypersetup{colorlinks,linkcolor=,urlcolor=links}

% For shapo's formulas:
\def\lsi{\raise0.3ex\hbox{$<$\kern-0.75em\raise-1.1ex\hbox{$\sim$}}}
\def\gsi{\raise0.3ex\hbox{$>$\kern-0.75em\raise-1.1ex\hbox{$\sim$}}}
\newcommand{\lsim}{\mathop{\lsi}}
\newcommand{\gsim}{\mathop{\gsi}}
\newcommand{\wt}{\widetilde}
%\newcommand{\ol}{\overline}
\newcommand{\Tr}{\rm{Tr}}
\newcommand{\tr}{\rm{tr}}
\newcommand{\eqn}[1]{&\hspace{-0.7em}#1\hspace{-0.7em}&}
\newcommand{\vev}[1]{\rm{$\langle #1 \rangle$}}
\newcommand{\abs}[1]{\rm{$\left| #1 \right|$}}
\newcommand{\eV}{\rm{eV}}
\newcommand{\keV}{\rm{keV}}
\newcommand{\GeV}{\rm{GeV}}
\newcommand{\im}{\rm{Im}}
\newcommand{\disp}{\displaystyle}
\def\be{\begin{equation}}
\def\ee{\end{equation}}
\def\ba{\begin{eqnarray}}
\def\ea{\end{eqnarray}}
\def\d{\partial}
\def\l{\left(}
\def\r{\right)}
\def\la{\langle}
\def\ra{\rangle}
\def\e{{\rm e}}
\def\Br{{\rm Br}}
\def\fixme{{\color{red} FIXME!}}
\def\mc{{\color{Magenta}{MC}}}
\def\pdf{{\rm p.d.f.}}

\author{ {\fontspec{Trebuchet MS}Marcin Chrz\k{a}szcz} (Universit\"{a}t Z\"{u}rich)}
\institute{UZH}
\title[Random number generators]{Random number generators}
\date{\fixme}


\begin{document}
\tikzstyle{every picture}+=[remember picture]

{
\setbeamertemplate{sidebar right}{\llap{\includegraphics[width=\paperwidth,height=\paperheight]{bubble2}}}
\begin{frame}[c]%{\phantom{title page}} 
\begin{center}
\begin{center}
	\begin{columns}
		\begin{column}{0.9\textwidth}
			\flushright\fontspec{Trebuchet MS}\bfseries \Huge {Random number generators}
		\end{column}
		\begin{column}{0.2\textwidth}
		  %\includegraphics[width=\textwidth]{SHiP-2}
		\end{column}
	\end{columns}
\end{center}
	\quad
	\vspace{3em}
\begin{columns}
\begin{column}{0.44\textwidth}
\flushright \vspace{-1.8em} {\fontspec{Trebuchet MS} \Large Marcin Chrząszcz\\\vspace{-0.1em}\small \href{mailto:mchrzasz@cern.ch}{mchrzasz@cern.ch}}

\end{column}
\begin{column}{0.53\textwidth}
\includegraphics[height=1.3cm]{uzh-transp}
\end{column}
\end{columns}

\vspace{1em}
%		\footnotesize\textcolor{gray}{With N. Serra, B. Storaci\\Thanks to the theory support from M. Shaposhnikov, D. Gorbunov}\normalsize\\
\vspace{0.5em}
	\textcolor{normal text.fg!50!Comment}{Monte Carlo methods, \\ 17 March, 2016}
\end{center}
\end{frame}
}


\begin{frame}\frametitle{Random and pseudorandom numbers}
  \begin{exampleblock}{John von Neumann:}                                                                                                                                                                                                                                                                                                
''Any one who considers arithmetical methods of producing random digits is, of course, in a state of sin. For, as has been pointed out several times, there is no such thing as a random number — there are only methods to produce random numbers, and a strict arithmetic procedure of course is not such a method.''
        \end{exampleblock} 

$\color{PineGreen}\Rrightarrow$ Random number: a given value that is taken by a random variable $ \twoheadrightarrow$ by definition cannot be predicted.\\
%$\color{PineGreen}\Rrightarrow$ Sequence of random numbers $\twoheadrightarrow$ 
$\color{PineGreen}\Rrightarrow$ Sources of truly random numbers:
\begin{itemize}
\item Mechanical
\item Physical
\end{itemize}
$\color{PineGreen}\Rrightarrow$ Disadvantages of physical generators:
\begin{itemize}
\item To slow for typical applications, especially the mechanical ones!
\item Not stable; small changes in boundary conditions might lead to completely different results!
\end{itemize}


\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Random numbers - history remark}
$\color{PineGreen}\Rrightarrow$ In the past there were books with random numbers:
\begin{center}
\includegraphics[width=0.55\textwidth]{images/million-random-digits-open.jpg}
  \end{center}
$\color{PineGreen}\Rrightarrow$ It's obvious that they didn't become very popular ;)\\
$\color{PineGreen}\Rrightarrow$ This methods are comming back!\\
$\color{PineGreen}\twoheadrightarrow$ Storage device are getting more cheap and bigger (CD, DVD).\\
$\color{PineGreen}\twoheadrightarrow$ 1995: G. Marsaglia, $650\rm MB$ of random numbers, ''White and Black Noise''.


\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Pseudorandom numbers}
\begin{footnotesize}
\begin{alertblock}{}
Commercially available physical generators of random numbers are usually based on electronic noise. This kind of generators do not pass simple statistical tests! Before you use them check they statistical properties.
\end{alertblock}
\ARROW Pseudorandom numbers- numbers generated accordingly to strict mathematical formula.\\
\ARROW Strictly speaking they are non random numbers, how ever they have all the statistical properties of random numbers.\\
\ARROW How ever modern generators are so good that no one can distinguish the pseudo random numbers generated by then from true random numbers.\\
\ARROW Mathematical methods of producing pseudorandom numbers:
\begin{itemize}
\item Good statistical properties of generated numbers.
\item Easy to use and fast!
\item Reproducible!
\end{itemize}
\ARROW Because of those properties the truelly random numbers are not used in practice any more!


\end{footnotesize}
\end{frame}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Middle square generator; von Neumann}
$\color{PineGreen}\Rrightarrow$  The first mathematical generator (middle square) was proposed by von Neumann (1964).\\{~}\\
$\color{PineGreen}\looparrowright$ Formula: $
\tcbhighmath[fuzzy halo=0.5mm with PineGreen!50!white,arc=0.1pt,
  boxrule=0pt,frame hidden]{ X_n= \lfloor X_{n-1}^2\cdot 10 ^{-m} \rfloor - \lfloor X_{n-1}^2\cdot 10^{-3m} \rfloor \cdot 10^{2m}}
$

$\color{PineGreen}\looparrowright$ where $X_0$ is a constant (seed), $\lfloor\cdot\rfloor$ is the cut-off of a number to integer.\\
$\color{PineGreen}\Rrightarrow$  Example:\\
{~}{~}Let's put $m=2$ and $X_0=2045$:\\
\begin{columns}
\column{0.1\textwidth}
{~}
\column{0.4\textwidth}
$\color{PineGreen}\looparrowright$ $X_0^2=\underbrace{04}_{\rm rej}1820\underbrace{25}_{\rm rej}$
\column{0.3\textwidth}
 $\Rightarrow X_1=1820$
\end{columns}
\begin{columns}
\column{0.1\textwidth}
{~}
\column{0.4\textwidth}
$\color{PineGreen}\looparrowright$ $X_1^2=\underbrace{03}_{\rm rej}3124\underbrace{00}_{\rm rej}$
\column{0.3\textwidth}
 $\Rightarrow X_1=3124$
\end{columns}
$\color{PineGreen}\looparrowright$ Simple generator but unfortunately quite bad generator. Firstly the sequences are very short and strongly dependent on the $X_0$ number.



\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Middle square generator; von Neumann}
$\color{PineGreen}\Rrightarrow$  This was a first generator written and it's a good example how to not write generators.\\
$\color{PineGreen}\Rrightarrow$ It's highly non stable!
\includegraphics[width=0.8\textwidth]{images/shit.png}

\ARROW E 4.1 Write the von Neumann Middle square generator.

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{General schematic }
\begin{small}
\ARROW Typical \mc~generator layout:
\begin{itemize}
\item We choose initial constants: $X_0$, $X_1$, ... $X_{k-1}$. 
\item The $k$ number if calculated based on the previous ones:
\end{itemize}
\begin{align*}
X_k=f(X_0, ..., X_{k-1}),
\end{align*}
\ARROW Typically one generates $0/1$ which are then converted towards double precision numbers with $\mathcal{U}(0,1)$. \\
\ARROW Generator period ($P, l$ integer numbers): $P$ is the period:
\begin{align*}
\exists _{l, P}: X_i=X_{i+j\cdot P}~~ 	\forall_{j \in \mathbb{I^+}}~ \forall_{i>l}
\end{align*}
\ARROW In post of the cases the period can be calculated analytically, although this is sometimes not trivial.\\
\ARROW There is a recommendation about the period of a generator. For $N$ numbers we usually require:
\begin{align*}
N\ll P
\end{align*}
\ARROW In practice: $N<P^{2/3}$ is oki ;)\\
\ARROW For example a generator ''Mersenne Twister'' (Matsumoto,  Nishimura, 1998): $P \thicksim  10^{6000}$.


\end{small}
\end{frame}






%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Linear generators}

$\color{PineGreen}\Rrightarrow$ General equation:
\begin{equation}
\tcbhighmath[fuzzy halo=0.5mm with PineGreen!50!white,arc=0.1pt,
  boxrule=0pt,frame hidden]{X_n=(a_1X_{n-1} + a_2X_{n-2}+...+a_kX_{n-k}+c)~{\rm mod}~m    ,} \nonumber
\end{equation}
$\color{PineGreen}\looparrowright$ where $a_i,c,m$ are parameters of a generator(integer numbers).\\
$\color{PineGreen}\looparrowright$  Generator initialization $\color{PineGreen} \rightleftarrows$ setting those parameters.\\
$\color{PineGreen}\Rrightarrow$ Very old generators. (often used in Pascal, or first C versions):
\begin{columns}
\column{0.1\textwidth}
{~}
\column{0.8\textwidth}
$k=1:~X_n=(aX_{n-1} +c )~{\rm mod} m,$
$c=
\begin{cases}
=0, {\rm multiplicative~ geneator}\\
\neq 0, {\rm mix~ geneator}
\end{cases}
$
\column{0.1\textwidth}
{~}


\end{columns}
$\color{PineGreen}\Rrightarrow$ The period can be achieved by tuning the seed parameters (multiplicative) :\\
$P_{{\rm max}}=
\begin{cases}
2^{L-2};~{\rm for~} m=2^L\\
m-1;~{\rm for~} m= {\rm prime~number}
\end{cases}
$
\end{frame}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Linear generators}
\begin{footnotesize}
\ARROW Some simple linear generators and their periods:
\begin{center}
\begin{tabular}{|c|c|c|c|}
$a$ & $c$ & $m$ & Name/author\\\hline
$2^16+3$ & $0$ & $2^{31}$ & \texttt{RANDU}\\
$2^2\cdot 23^7+1$ & $0$ & $2^{35}$ & Zielinski (1966)\\
$69069$ & $1$ & $2^{32}$ & Marsaglia (1972)\\
$16807$ & $0$ & $2^{31}-1$ & Park, Miller (1980)\\
$40692$ & $0$ & $2^{31}-249$ & L’ Ecuyer (1988)\\
$68909602460261$ & $0$ & $2^{48}$ & Fishman (1990)\\
\end{tabular}
\end{center}
\ARROW $m$ - prime number $\rightarrow$ better statistical properties.
\ARROW There are some quid lines how to choose the parameters to make the period larger.
\begin{alertblock}{}
The periods of $2^{32} \sim 4 \cdot 10^9$ are not good enough for modern applications! Remember that in practice $N \ll P^{2/3}$!
\end{alertblock}
\ARROW Simple linear generators do not pass newer statistical tests!

\end{footnotesize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Linear generators}
\begin{footnotesize}
\ARROW Marsaglia (1995) generators:
\begin{enumerate}
\item $X_n =(1176 X_{n-1} + 1476 X_{n-2} + 1776 X_{n-3})~{\rm mod}~ m,~m=2^{32}-5$
\item $X_n =2^{13} (X_{n−1} + X_{n−2} + X_{n−3} )~{\rm mod}~ m,~m=2^{32}-5$
\item $X_n = (1995 X_{n−1} + 1998 X_{n−2} + 2001 X_{n−3 }) mod m,~m=2^{35} − 849$
\item  $X_n = 2^{19}(X_{n−1} + X_{n−2} + X_{n−3} ) mod m, ~m=2^{32} − 1629$
\end{enumerate}
\ARROW $P=m^3-1$
\ARROW They got surprisingly good statistical properties!
\ARROW The main disadvantage is that multidimensional distributions look very suspicious:\\
\begin{align*}
U_i=X_i/m,~i=1,2... \Rightarrow U_i(0,1) \\
(U_1,U_2,..., U_k), (U_2, U_3,...,U_{k+1}),...
(U_1,U_2,..., U_k), (U_{k+1}, U_{k+2},...,U_{2k}),...
\end{align*}
are being located on a resurfaces in a hiper-cube $[0,1]]^k$.\\
\ARROW Using Fourier analysis one can find the distances between the hiper-surfaces. \\
\ARROW Generalization for multiple dimensions:
\begin{equation}
\tcbhighmath[fuzzy halo=0.5mm with PineGreen!50!white,arc=0.1pt,
  boxrule=0pt,frame hidden]{X_n=\textbf{A}\overrightarrow{X}_{n-1}~{\rm mod}~m    ,} \nonumber
\end{equation}
\ARROW E4.2 Code all 4  Marsaglia generators. 
\end{footnotesize}

\end{frame}










%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Shift register generator}
\begin{small}
$\color{PineGreen}\Rrightarrow$ General equation:
\begin{equation}
\tcbhighmath[fuzzy halo=0.5mm with PineGreen!50!white,arc=0.1pt,
  boxrule=0pt,frame hidden]{b_n=(a_1X_{n-1} + a_2X_{n-2}+...+a_kX_{n-k}+c)~{\rm mod}~2    ,} \nonumber
\end{equation}
where $a_i \subset(\lbrace0,1\rbrace )$\\
$\color{PineGreen}\Rrightarrow$ Super fast and easy to implement due to: $(a+b) ~{\rm mod}~2 = a~{\rm xor}~b$
\begin{center}
\begin{tabular}{||c|c|c||}
\hline \hline a & b & a xor b\\ \hline
0 & 0 & 0\\
1 & 0 & 1\\
0 & 1 & 1\\
1 & 1 & 0\\ \hline \hline
\end{tabular}
\end{center}
$\color{PineGreen}\Rrightarrow$ Maximal period is $2^k-1$.\\
$\color{PineGreen}\Rrightarrow$ Example (Tausworths generator):\\
$a_p=a_q=1$, other $a_i=0$ and $p>q$. Then: $b_n=b_{n-p}~{\rm xor}~b_{n-q}$

$\color{PineGreen}\Rrightarrow$ How to get numbers from bits (for example):\\
$U_i = \sum_{j=1}^L 2^{-j} b_{is+j},~s<L$.

\end{small}
\end{frame}


\iffalse
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Shift register generator}
\begin{footnotesize}
\ARROW The Tausworth was improved by Tezuki in 1995:\\
$A$, $B$ - L bit integer number with bits: $b1,...,b_n$.\\
\begin{enumerate}
\item $B= ((A$
\end{enumerate}
\end{footnotesize}

\end{frame}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Fibonacci generator}
\begin{footnotesize}


$\color{PineGreen}\Rrightarrow$ In 1202 Fibonacci with Leonardo in Piza:
\begin{equation}
f_n=f_{n-2}+f_{n-1},~n\geqslant 2 \nonumber
\end{equation}
$\color{PineGreen}\Rrightarrow$ Based on this first generator was created (Taussky and Todd, 1956):
\begin{equation}
X_n=(X_{n-2}+X_{n-1})~{\rm mod}~m,~n\geqslant 2 \nonumber
\end{equation}
This generator isn't so good in terms of statistics tests.\\
$\color{PineGreen}\Rrightarrow$ Generalization:
\begin{equation}
X_n=(X_{n-r} \odot X_{n-s})~{\rm mod}~m,~n \geqslant r ,~s \geqslant 1 \nonumber
\end{equation}\begin{center}

\begin{tabular}{||c|c|c||}
\hline \hline $\bigodot$ & $P_{max}$ & Stat. properties \\ \hline
$+,-$ & $(2^r-1)2^{L-1}$ & good \\
$x$ & $(2^r-1)2^{L-13}$ & very good \\
$xor$ & $(2^r-1)$ & poor \\ \hline \hline 
\end{tabular}


\end{center}

\end{footnotesize}
\end{frame}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{MZT}
\begin{footnotesize}


\ARROW Popular generator MZT, better known as RANMAR (Marsaglia, Zaman, Tsang, 1990):
\begin{itemize}
\item Very universal! Will give the same results on all computers that have integer numbers with $\geqslant 16$ bit and floating with $\leqslant 24$ bits.
\end{itemize}
\ARROW It's effectivelly a combination of two generators:

\begin{itemize}
\item The Fibonacci:
\end{itemize}
\begin{align*}
F(97,33,\bullet) \rightarrowtail V_n \in [0,1)
\end{align*}
where
\begin{equation*}
x \bullet y =
\begin{cases}
x-y, & x \geqslant y\\
x-y+1, & x < y
\end{cases}
\end{equation*}
\begin{itemize}
\item The initialization is done by setting $V_i$ ,$i=1,..., 97$ numbers.
\item They are initialized by bits: $V_1=0.b_1 b_2...b_{24}$, $V_2=0.b_{25}...b_{48}$,...
\item The series ${b_n}$ is generated via two generators:
\begin{equation*}
 \left\{\begin{array}{lr}
        y_n=(y_{n-3} \cdot y_{n-2} \cdot y_{n-1}){{\rm mod}} 179 \\
 		z_n=(53 z_{n-1}+1) {{\rm mod}} 169
        \end{array}\right\}   \Rightarrow b_n   \left\{\begin{array}{lr}
        0,~~(y_n \cdot z_n)  {{\rm mod}} 64 <32\\
        1,~~(y_n \cdot z_n)  {{\rm mod}} 64 \geqslant 32
        \end{array}\right\}
\end{equation*}
\item Initialization: provide 4 numbers 4: $y_1, y_2, y_3 \in{1,...178}$, $z_1 \in {0,..., 168}$
\item Period $P=2^{120}$
\end{itemize}

\end{footnotesize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{MZT}
\begin{footnotesize}


\ARROW The second generator $c_n \in (0,1)$:
\begin{align*}
c_n=c_{n-1}\circ (7654321/16777216),~~~n \geqslant 2,~ c_1=362436/16777216,
\end{align*}
where:
\begin{align*}
c\circ d =\left\{\begin{array}{lr} 
	c-d,~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c \geqslant d\\
	c-  d + (16777213/16777216), c < d
\end{array}\right\}, c,d \in [0,1)
\end{align*}
\ARROW Period: $P= 2^{144}$
\ARROW The full MZT generator is calculated:
\begin{align*}
U_n= V_n \bullet c_n
\end{align*}
\begin{itemize}
\item Period $P=2^{144} \sim 10^{43}$
\end{itemize}
\ARROW It fulfils all know statistical test!
\ARROW E4.3 Code the Fibonacci generator
\ARROW A4.1 Code the RANMAR generator.
\end{footnotesize}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Multiply with carry, generator}
\begin{small}
$\color{PineGreen}\Rrightarrow$ We start from:
\begin{equation}
X_n=(a_1X_{n-1} + a_2X_{n-2}+...+a_kX_{n-k}+c)~{\rm mod}~m, \nonumber
\end{equation}
where $a_1,..,a_k \in \mathbb{N}$ are constant parameters.\\
$\color{PineGreen}\Rrightarrow$  The c parameters is calculated foe each step:
\begin{equation}
c=\lfloor (a_1X_{n-1} + a_2X_{n-2}+...+a_kX_{n-k}+c)/m\rfloor, \nonumber 
\end{equation}
$\color{PineGreen}\Rrightarrow$ Initialization: $a_1,..,a_k,c$.\\
$\color{PineGreen}\Rrightarrow$ Advantages:
\begin{itemize}
\item Fast and easy to implement.
\item Large period.
\item Good statistical properties.
\item First proposed by Marsaglia.
\end{itemize}

\end{small}
\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Multiply with carry, generator, example}
\begin{footnotesize}
\ARROW MWC1:
\begin{align*}
\begin{array}{lr} 
	X_n = (18000 X_{n-1}+ c_x) {{\rm mod}} 2^{16}\\
	Y_n = (30903 Y_{n-1}+ c_y) {{\rm mod}} 2^{16}\\
\end{array} \rbrace~~~{{ \rm 16-bit~digits}}
\end{align*}
\begin{align*}
\Rightarrow Z_n=b_1^{X_n}...b_{16}^{X_n}b_1^{Y_n}...b_{16}^{Y_n}~~~{{ \rm 32-bit~digits}}
\end{align*}
\ARROW Period: $2^{60}\sim 10^{18}$\\
\ARROW MWC2:
\begin{align*}
X_n= 	(12013 X_{ n-8} + 1066 X_{ n-7} + 1215 X_{n-6} + 1492 X_{ n-5} + 1776_{X n-4}\\ + 1812 X_{ n-3} + 1860 X_{ n-2} + 1941 X_{n-1} + c_X)~{{\rm mod}}~ 2^{16}
\end{align*}
\begin{align*}
Y_n= 	(9272 Y_{ n-8} + 7777 Y_{ n-7} + 6666 Y_{n-6} + 5555 Y_{ n-5} + 4444  Y_{n-4}\\ + 3333 Y_{ n-3} + 2222 Y_{ n-2} + 1111 Y_{n-1} + c_Y)~{{\rm mod}}~ 2^{16}
\end{align*}
\begin{align*}
\Rightarrow Z_n=b_1^{X_n}...b_{16}^{X_n}b_1^{Y_n}...b_{16}^{Y_n}~~~{{ \rm 32-bit~digits}}
\end{align*}
\ARROW Period: $2^{250}\sim 10^{75}$\\
\ARROW E4.4 Code the MWC1 and MWC2.
\end{footnotesize}
\end{frame}




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Subtract with borrow, generator}
\begin{small}
$\color{PineGreen}\Rrightarrow$  Created again by Marsaglia (1991):
\begin{equation}
X_n=(X_{n-r} \circleddash X_{n-s})~{\rm mod}~m,~r,s  \nonumber \in \mathbb{N},
\end{equation}
where :
\begin{equation}
x \circleddash y = \begin{cases}
x-y-c +m,~c=1,~{\rm{ when~x-y-c<0}}\\
x-y-c,~c=0,~{\rm{ when~x-y-c\geq0}} \nonumber 
\end{cases}
\end{equation}


$\color{PineGreen}\Rrightarrow$ Initialization: $X_1,...,X_{n-r}$ and $c=0$.\\
$\color{PineGreen}\Rrightarrow$ Fast and easy :)\\
$\color{PineGreen}\Rrightarrow$ Fails some of the basic statistics tests.
\end{small}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Non linear generators}
\begin{small}
$\color{PineGreen}\Rrightarrow$ The natural solutions to problems of linear generators are the non-linear generators (second part of 1980s).\\
$\color{PineGreen}\Rrightarrow$ Eichenauera i Lehna (1986):
\begin{equation}
X_n= (a X_{n−1}^{-1} + b)~{\rm mod}~m, \nonumber 
\end{equation}
$\color{PineGreen}\Rrightarrow$ Eichenauera-Hermanna (1993)
\begin{equation}
X_n= [a(n+n_0)+b]^{-1}~{\rm mod}~m, \nonumber 
\end{equation}
$\color{PineGreen}\Rrightarrow$ L. Blum, M. Blum, Shub (1986):
\begin{equation}
X_n= X_{n-1}^2~{\rm mod}~m, \nonumber 
\end{equation}
$\color{PineGreen}\rightarrowtail$ Very popular in cryptography.\\
$\color{PineGreen}\Rrightarrow$ Pros and cons:
\begin{itemize}
\item {\color{PineGreen}{They all pass all statistical tests.}}
\item {\color{red}{Much slower then linear generators.}}
\end{itemize}
\end{small}
\end{frame}











%%%%%%%%%%%%%%%%%%%%%%%%%%%5
%% Stat tests$

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{\texttt{RANLUX} generator}
\begin{small}
$\color{PineGreen}\Rrightarrow$ All described generators are based on some mathematical algorithms and recursion. The typical scheme is of constructing a MC generator:
\begin{itemize}
\item Think of a formula that takes some initial values.
\item Generate large number of random numbers and put them through statistical tests.
\item If the test are positive we accept the the generator.
\end{itemize}
$\color{PineGreen}\Rrightarrow$ Now let's think: why the hell numbers obtained that way are showing some random number properties?\pause ~There is no science behind it, it's pure luck!\\
$\color{PineGreen}\Rrightarrow$ M.Luscher (1993) \href{http://arxiv.org/pdf/hep-lat/9309020v1.pdf}{hep-lat/9309020}\\
$\color{PineGreen}\Rrightarrow$ Generator RANLUX based on Kolomogorow entropy and Lyapunov exponent. { \color{PineGreen} Effectively we are building inside the generator the chaos theory}.\\
$\color{PineGreen}\Rrightarrow$  RANLUX and Mersenne Twister (TRandom1, TRandom3) are the 2 most powerful generators in the world that passed every known statistical test.

\end{small}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Chaos theory in a nut shell}
\begin{small}
\begin{columns}
\column{0.1in}
{~}
\column{3in}
$\color{PineGreen}\Rrightarrow$ We know that the solution of classical systems is described by trajectory in phase spaces. Now the problem with this picture starts to be when arround one point in this phase space we are getting more and more trajectories that are drifting a part later on.\\
$\color{PineGreen}\Rrightarrow$ The Lyapunov exponent tells us how a two solutions drift apart with time:
\begin{equation}
\vert \delta X(t) \vert \approx  e^{\lambda t} \vert \delta X_0 \vert \nonumber
\end{equation}
$\color{PineGreen}\Rrightarrow$ Kolomogorow entropy:
\begin{equation}
h_K = \int_P \lambda d \mu  \nonumber
\end{equation}
\column{2in}

\includegraphics[width=0.9\textwidth]{images/Focal_stability.png}\\
\includegraphics[width=0.9\textwidth]{images/LogisticMap_BifurcationDiagram.png}

\end{columns}
\end{small}
\end{frame}
\iffalse
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{HEP simulation}
\begin{small}
$\color{PineGreen}\Rrightarrow$ There is some ambiguity what particle physicist call MC. Normally those are mathematical theorises but when we say MC we usually mean MC simulation of a physics process.
$\color{PineGreen}\Rrightarrow$ There are plenty of things that need to be simulated:
\only<1>{
\includegraphics[width=0.95\textwidth]{images/gen1.png}
}
\only<2>{
\includegraphics[width=0.95\textwidth]{images/gen2.png}
}
\only<3>{
\includegraphics[width=0.95\textwidth]{images/gen3.png}
}
\only<4>{
\includegraphics[width=0.95\textwidth]{images/gen4.png}
}
\only<5>{
\includegraphics[width=0.95\textwidth]{images/gen5.png}
}
\only<6>{
\includegraphics[width=0.95\textwidth]{images/gen6.png}
}
\end{small}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}\frametitle{Detector simulation}

\begin{small}
$\color{PineGreen}\Rrightarrow$ Things do not get simpler on the detector side simulation.\\
$\color{PineGreen}\Rrightarrow$ Lots of effects need to be taken into account:
\begin{columns}
\column{0.2in}
{~}
\column{2in}
$\color{PineGreen}\rightarrowtail$ Bremsstrahlung\\
$\color{PineGreen}\rightarrowtail$ Interactions with different detector materials\\
$\color{PineGreen}\rightarrowtail$ Particle identification\\
$\color{PineGreen}\rightarrowtail$ Showers\\
\column{3in}
\includegraphics[width=0.95\textwidth]{{images/lhcb2_h-640x408}.jpg}
\end{columns}
$\color{PineGreen}\Rrightarrow$ Example of generators:\\
$\color{PineGreen}\rightarrowtail$ FLUKA\\
$\color{PineGreen}\rightarrowtail$ Geant

\end{small}
\end{frame}
\fi

\begin{frame}\frametitle{Wrap up}
\begin{small}
$\color{PineGreen}\Rrightarrow$ Things to remember:
\begin{itemize}
\item Computer cannot produce random numbers, only pseudorandom numbers.
\item We use pseudorandon numbers as random numbers if they are statistically acting the same as random numbers.
\item Linear generators are not commonly used nowadays.
\item State of the art generators are the ones based on Kolomogorows theorem.
\end{itemize}
\end{small}
\end{frame}



\backupbegin   

\begin{frame}\frametitle{Backup}


\end{frame}

\backupend			

\end{document}