\subsection{Cross-sections and zero-sections of fibre bundles}


\documentclass[12pt]{article}
\usepackage{amsmath, hyperref, multicol, fullpage}

\usepackage[usenames,dvipsnames]{xcolor} % allows you to use color names, call this BEFORE you call TikZ

\usepackage{tikz, tikz-3dplot, pgfplots}
\usepackage{tkz-graph}
\usetikzlibrary[positioning,patterns] % tikz libraries for relative positioning and silly patterns

% let pgfplots know what version you're using
\pgfplotsset{compat=1.8}

% Tyson's macros for Young tableau squares and big dominoes
\tikzstyle{bsq}=[rectangle, draw, thick, minimum width=1cm, minimum height=1cm]
\tikzstyle{bver}=[rectangle, draw, thick, minimum width=1cm, minimum height=2cm]
\tikzstyle{bhor}=[rectangle, draw, thick, minimum width=2cm, minimum height=1cm]

% formatting the section titles
\usepackage{titlesec}
\titleformat{\section}{\large\bfseries}{\thesection}{1em}{}

% macro for TikZ logo
\newcommand{\TikZ}{Ti$k$Z }

\title{\TikZ/PGF and other \LaTeX  \, Tricks}
\author{Erica Shannon}
\date{}

\begin{document}

\setlength\parindent{0pt}

\maketitle

\tableofcontents

\vfill

\TikZ stands for \TikZ ist \emph{kein} Zeichenprogramm; PGF stands for Portable Graphics Format.

\vfill

\section{Resources}

\footnotesize

\begin{itemize}
\item Comprehensive \TikZ Manual: \\ \url{http://ftp.math.purdue.edu/mirrors/ctan.org/graphics/pgf/base/doc/generic/pgf/pgfmanual.pdf}
\item \ttfamily pgfplots \rmfamily Manual: \\ \url{http://www.bakoma-tex.com/doc/latex/pgfplots/pgfplots.pdf}
\item A nice tutorial for basic drawing using \TikZ: \\ \url{http://www.math.uni-leipzig.de/~hellmund/LaTeX/pgf-tut.pdf}
\item List of colors available from the \ttfamily dvipsnames \rmfamily package: \\ \url{http://en.wikibooks.org/wiki/LaTeX/Colors}
\end{itemize}

\normalsize

\newpage
\section{Polygons}

Here are some triangles with labels.

\bigskip

\begin{center}
\begin{tikzpicture}[scale=3]

	\draw[fill=YellowGreen] (0,0) -- (1.732050808,0) -- (0,1) -- cycle;
	\draw (0,.1) -- (.1,.1) -- (.1,0);

	\node at (.15,.75) {$\pi / 3$};
	\node at (1.25,.13) {$\pi/6$};

	\node at (.9,.65) {1};
	\node at (-.15,.5) {$\displaystyle \frac{1}{2}$};
	\node at (.8, -.2) {$\displaystyle \frac{\sqrt{3}}{2}$};

\begin{scope}[xshift=80] % shifts everything enclosed in this to the right

	\draw[fill=YellowGreen] (0,0) -- (1,0) -- (0,1) -- cycle;
	\draw (0,.1) -- (.1,.1) -- (.1,0);

	\node at (.15,.65) {$\pi / 4$};
	\node at (.68,.1) {$\pi/4$};

	\node at (.6,.6) {1};
	\node at (-.15,.5) {$\displaystyle \frac{\sqrt{2}}{2}$};
	\node at (.5, -.2) {$\displaystyle \frac{\sqrt{2}}{2}$};
\end{scope}

\end{tikzpicture}
\end{center}

\bigskip

Here are some regular polygons, drawn using the \ttfamily foreach \rmfamily command for~loops.

\bigskip

\begin{center}
\begin{tikzpicture}

	\newdimen\R
	\R=1.8cm % this means each polygon will be inscribed in a circle of radius 1.8 cm.

	% all coordinates given below are polar coordinates in the form (angle : radius)

	\draw[fill=Dandelion] (0:\R) \foreach \x in {120,240} { -- (\x:\R) } -- cycle (90:\R) node[above] {$n=3$} ;

	\draw[fill=Dandelion,xshift=2.5\R] (0:\R) \foreach \x in {90,180,...,359} {--(\x:\R)}--cycle (90:\R) node[above] {$n=4$} ;

	\draw[fill=Dandelion,xshift=5.0\R] (0:\R) \foreach \x in {72,144,...,359} {--(\x:\R)}--cycle (90:\R) node[above] {$n=5$} ;

	\draw[fill=Dandelion,yshift=-3\R] (0:\R) \foreach \x in {60,120,...,359} {-- (\x:\R)}--cycle (90:\R) node[above] {$n=6$} ;

	\draw[fill=Dandelion, yshift=-3\R,xshift=2.5\R] (0:\R) \foreach \x in {51.4286,102.8571,...,359} {-- (\x:\R)}--cycle (90:\R) node[above] {$n=7$} ;

	\draw[fill=Dandelion,yshift=-3\R,xshift=5.0\R] (0:\R) \foreach \x in {45,90,...,359} {-- (\x:\R)} -- cycle (90:\R) node[above] {$n=8$} ;

\end{tikzpicture}
\end{center}

\bigskip

The TikZ manual has examples of how to draw pretty much any type of shape or diagram you might come up with. In particular, there's a list of cool available node shapes starting on p.435. (Forbidden sign, clouds, magnifying glass, starburst, etc.)

\newpage
\section{Subgroup Lattices}

There is supposed to be a \TikZ library (\ttfamily graphs\rmfamily) for typesetting graphs. However, I found it extremely difficult to get this library to work correctly (or at all!). As a result, the examples here are made using the standard \TikZ nodes and lines.

\begin{center}
\begin{tikzpicture}[every node/.style={fill=white}] % white fill keeps lines from running into labels

	\draw (0,6) -- (3,5) -- (0,2);
	\draw (0,6) -- (1,4) -- (0,2);
	\draw (0,6) -- (-1,4) -- (0,2);
	\draw (0,6) -- (-3,4) -- (0,2);

	\node at (0,6) {$S_3$};
	\node at (3,5) {$\langle (123) \rangle$};
	\node at (1,4) {$\langle(13)\rangle$};
	\node at (-1,4) {$\langle(23)\rangle$};
	\node at (-3,4) {$\langle(13)\rangle$};
	\node at (0,2) {$\{e\}$};

\end{tikzpicture}
\end{center}

Here's a more complicated one:

\begin{center}
\begin{tikzpicture}[every node/.style={fill=white}]

	\draw (0,8) -- (0,2);
	\draw (0,8) -- (3,6) -- (0,4);
	\draw (0,8) -- (-3,6) -- (0,4);
	\draw (3,6) -- (2,4) -- (0,2);
	\draw (-3,6) -- (-2,4) -- (0,2);
	\draw (3,6) -- (4,4) -- (0,2);
	\draw (-3,6) -- (-4,4) -- (0,2);

	\node at (0,8) {$D_8 = \langle r,s\rangle$};
	\node at (0,6) {$\langle r \rangle$};
	\node at (0,4) {$\langle r^2 \rangle$};
	\node at (0,2) {$\{e\}$};

	\node at (-3,6) {$\langle s, r^2 \rangle$};
	\node at (3,6) {$\langle sr, r^2 \rangle$};

	\node at (-4,4) {$\langle s r^2 \rangle$};
	\node at (-2,4) {$\langle s \rangle$};
	\node at (2,4) {$\langle s r^3 \rangle$};
	\node at (4,4) {$\langle sr \rangle$};

\end{tikzpicture}
\end{center}

\newpage
\section{Coxeter graphs and Dynkin diagrams}

Finite Coxeter groups can be classified by their Coxeter graphs.

\begin{multicols}{2}

\begin{tikzpicture}

	\draw (0,0) -- (2.7,0);
	\draw (3.3, 0) -- (5,0);

	\draw[fill=red] (0,0) circle (.1);
	\draw[fill=red] (1,0) circle (.1);
	\draw[fill=red] (2,0) circle (.1);
	\draw[fill=red] (4,0) circle (.1);
	\draw[fill=red] (5,0) circle (.1);

	\node at (3,0) {$\cdots$};
	\node at (-1,0) {$A_n$};

\end{tikzpicture}

\begin{tikzpicture}

	\draw (0,0) -- (2.7,0);
	\draw (3.3, 0) -- (5,0);

	\draw[fill=blue] (0,0) circle(.1);
	\draw[fill=blue] (1,0) circle(.1);
	\draw[fill=blue] (2,0) circle(.1);
	\draw[fill=blue] (4,0) circle(.1);
	\draw[fill=blue] (5,0) circle(.1);

	\node at (3,0) {$\cdots$};
	\node at (4.5,.3) {4};
	\node at (-1,0) {$B_n$};

\end{tikzpicture}

\begin{tikzpicture}

	\draw (0,0) -- (2.7,0);
	\draw (3.3, 0) -- (5,0);

	\draw[fill=ProcessBlue] (0,0) circle(.1);
	\draw[fill=ProcessBlue] (1,0) circle(.1);
	\draw[fill=ProcessBlue] (2,0) circle(.1);
	\draw[fill=ProcessBlue] (4,0) circle(.1);
	\draw[fill=ProcessBlue] (5,0) circle(.1);

	\node at (3,0) {$\cdots$};
	\node at (4.5,.3) {4};
	\node at (-1,0) {$C_n$};

\end{tikzpicture}

\begin{tikzpicture}

	\draw (0,0) -- (2.7,0);
	\draw (3.3, 0) -- (4,0);
	\draw (4,0) -- (5,-.5);
	\draw (4,0) -- (5,.5);

	\draw[fill=Magenta] (0,0) circle(.1);
	\draw[fill=Magenta] (1,0) circle(.1);
	\draw[fill=Magenta] (2,0) circle(.1);
	\draw[fill=Magenta] (4,0) circle(.1);
	\draw[fill=Magenta] (5,-.5) circle(.1);
	\draw[fill=Magenta] (5,.5) circle(.1);

	\node at (3,0) {$\cdots$};
	\node at (-1,0) {$D_n$};

\end{tikzpicture}

\begin{tikzpicture}

	\draw (0,0) -- (4,0);
	\draw (2,0) -- (2,1);

	\draw[fill=Green] (0,0) circle(.1);
	\draw[fill=Green] (1,0) circle(.1);
	\draw[fill=Green] (2,0) circle(.1);
	\draw[fill=Green] (2,1) circle(.1);
	\draw[fill=Green] (3,0) circle(.1);
	\draw[fill=Green] (4,0) circle(.1);

	\node at (-1,0) {$E_6$};

\end{tikzpicture}

\begin{tikzpicture}

	\draw (0,0) -- (5,0);
	\draw (2,0) -- (2,1);

	\draw[fill=Green] (0,0) circle(.1);
	\draw[fill=Green] (1,0) circle(.1);
	\draw[fill=Green] (2,0) circle(.1);
	\draw[fill=Green] (2,1) circle(.1);
	\draw[fill=Green] (3,0) circle(.1);
	\draw[fill=Green] (4,0) circle(.1);
	\draw[fill=Green] (5,0) circle(.1);

	\node at (-1,0) {$E_7$};

\end{tikzpicture}

\begin{tikzpicture}

	\draw (0,0) -- (6,0);
	\draw (2,0) -- (2,1);

	\draw[fill=Green] (0,0) circle(.1);
	\draw[fill=Green] (1,0) circle(.1);
	\draw[fill=Green] (2,0) circle(.1);
	\draw[fill=Green] (2,1) circle(.1);
	\draw[fill=Green] (3,0) circle(.1);
	\draw[fill=Green] (4,0) circle(.1);
	\draw[fill=Green] (5,0) circle(.1);
	\draw[fill=Green] (6,0) circle(.1);

	\node at (-1,0) {$E_8$};

\end{tikzpicture}

\begin{tikzpicture}

	\draw (0,0) -- (3,0);

	\draw[fill=yellow] (0,0) circle(.1);
	\draw[fill=yellow] (1,0) circle(.1);
	\draw[fill=yellow] (2,0) circle(.1);
	\draw[fill=yellow] (3,0) circle(.1);

	\node at (1.5, .3) {4};
	\node at (-1,0) {$F_4$};

\end{tikzpicture}

\begin{tikzpicture}

	\draw (0,0) -- (2,0);

	\draw[fill=orange] (0,0) circle(.1);
	\draw[fill=orange] (1,0) circle(.1);
	\draw[fill=orange] (2,0) circle(.1);

	\node at (.5, .3) {5};
	\node at (-1,0) {$H_3$};

\end{tikzpicture}

\begin{tikzpicture}

	\draw (0,0) -- (3,0);

	\draw[fill=orange] (0,0) circle(.1);
	\draw[fill=orange] (1,0) circle(.1);
	\draw[fill=orange] (2,0) circle(.1);
	\draw[fill=orange] (3,0) circle(.1);

	\node at (.5, .3) {5};
	\node at (-1,0) {$H_4$};

\end{tikzpicture}

\begin{tikzpicture}

	\draw (0,0) -- (1,0);

	\draw[fill=Violet] (0,0) circle(.1);
	\draw[fill=Violet] (1,0) circle(.1);

	\node at (.5, .3) {$m$};
	\node at (-1,0) {$I_2(m)$};

\end{tikzpicture}

\end{multicols}

\bigskip

If $\Phi$ is an irreducible root system of rank $\ell$, its Dynkin diagram is one of the following ($\ell$ vertices in each case):

\begin{multicols}{2}

\begin{tikzpicture}
	\fill[color=white] (0,0) circle(.1);
\end{tikzpicture}

\begin{tikzpicture}

	\draw (0,0) -- (1,0);
         \draw (2,0) -- (2.7,0);
         \draw (1,0) -- (2,0);
	\draw (3.3, 0) -- (4,0);
	\draw (4,0) -- (5,0);

	\draw[fill=white] (0,0) circle(.1);
	\draw[fill=white] (1,0) circle(.1);
	\draw[fill=white] (2,0) circle(.1);
	\draw[fill=white] (4,0) circle(.1);
	\draw[fill=white] (5,0) circle(.1);

	\node at (3,0) {$\cdots$};
	\node at (-1,0) {$A_{\ell}$};

\end{tikzpicture}

\vfill

\begin{tikzpicture}

	\draw (0,0) -- (2.7,0);
	\draw (3.3, 0) -- (4,0);
	\draw (4,0.1) -- (5,0.1);
	\draw (4,-0.1) -- (5,-0.1);
	\draw (4.4,0.2) -- (4.6,0);
	\draw (4.4,-0.2) -- (4.6,0);

	\draw[fill=white] (0,0) circle(.1);
	\draw[fill=white] (1,0) circle(.1);
	\draw[fill=white] (2,0) circle(.1);
	\draw[fill=white] (4,0) circle(.1);
	\draw[fill=white] (5,0) circle(.1);

	\node at (3,0) {$\cdots$};
	\node at (-1,0) {$B_{\ell}$};

\end{tikzpicture}

\vfill

\begin{tikzpicture}

	\draw (0,0) -- (2.7,0);
	\draw (3.3, 0) -- (4,0);
	\draw (4,0.1) -- (5,0.1);
	\draw (4,-0.1) -- (5,-0.1);
	\draw (4.4,0) -- (4.6,0.2);
	\draw (4.4,0) -- (4.6,-0.2);

	\draw[fill=white] (0,0) circle(.1);
	\draw[fill=white] (1,0) circle(.1);
	\draw[fill=white] (2,0) circle(.1);
	\draw[fill=white] (4,0) circle(.1);
	\draw[fill=white] (5,0) circle(.1);

	\node at (3,0) {$\cdots$};
	\node at (-1,0) {$C_{\ell}$};

\end{tikzpicture}

\vfill

\begin{tikzpicture}

	\draw (0,0) -- (2.7,0);
	\draw (3.3, 0) -- (4,0);
	\draw (4,0) -- (5,-.5);
	\draw (4,0) -- (5,.5);

	\draw[fill=white] (0,0) circle(.1);
	\draw[fill=white] (1,0) circle(.1);
	\draw[fill=white] (2,0) circle(.1);
	\draw[fill=white] (4,0) circle(.1);
	\draw[fill=white] (5,-.5) circle(.1);
	\draw[fill=white] (5,.5) circle(.1);

	\node at (3,0) {$\cdots$};
	\node at (-1,0) {$D_{\ell}$};

\end{tikzpicture}

\columnbreak

\begin{tikzpicture}

	\draw (0,0) -- (4,0);
	\draw (2,0) -- (2,1);

	\draw[fill=white] (0,0) circle(.1);
	\draw[fill=white] (1,0) circle(.1);
	\draw[fill=white] (2,0) circle(.1);
	\draw[fill=white] (2,1) circle(.1);
	\draw[fill=white] (3,0) circle(.1);
	\draw[fill=white] (4,0) circle(.1);

	\node at (-1,0) {$E_6$};

\end{tikzpicture}

\vfill

\begin{tikzpicture}

	\draw (0,0) -- (5,0);
	\draw (2,0) -- (2,1);

	\draw[fill=white] (0,0) circle(.1);
	\draw[fill=white] (1,0) circle(.1);
	\draw[fill=white] (2,0) circle(.1);
	\draw[fill=white] (2,1) circle(.1);
	\draw[fill=white] (3,0) circle(.1);
	\draw[fill=white] (4,0) circle(.1);
	\draw[fill=white] (5,0) circle(.1);

	\node at (-1,0) {$E_7$};

\end{tikzpicture}

\vfill

\begin{tikzpicture}

	\draw (0,0) -- (6,0);
	\draw (2,0) -- (2,1);

	\draw[fill=white] (0,0) circle(.1);
	\draw[fill=white] (1,0) circle(.1);
	\draw[fill=white] (2,0) circle(.1);
	\draw[fill=white] (2,1) circle(.1);
	\draw[fill=white] (3,0) circle(.1);
	\draw[fill=white] (4,0) circle(.1);
	\draw[fill=white] (5,0) circle(.1);
	\draw[fill=white] (6,0) circle(.1);

	\node at (-1,0) {$E_8$};

\end{tikzpicture}

\vspace{.2in}

\begin{tikzpicture}

	\draw (0,0) -- (1,0);
	\draw (1,.1) -- (2,.1);
	\draw (1,-.1) -- (2,-.1);
	\draw(2,0) -- (3,0);
	\draw (1.4,0.2) -- (1.6,0);
	\draw (1.4,-0.2) -- (1.6,0);

	\draw[fill=white] (0,0) circle(.1);
	\draw[fill=white] (1,0) circle(.1);
	\draw[fill=white] (2,0) circle(.1);
	\draw[fill=white] (3,0) circle(.1);

	\node at (-1,0) {$F_4$};

\end{tikzpicture}

\vspace{.2in}

\begin{tikzpicture}

	\draw (0,0) -- (1,0);
	\draw (0,.1) -- (1,.1);
	\draw (0,-.1) -- (1,-.1);
	\draw (.4,0) -- (.6,0.2);
	\draw (.4,0) -- (.6,-0.2);

	\draw[fill=white] (0,0) circle(.1);
	\draw[fill=white] (1,0) circle(.1);

	\node at (-1,0) {$G_2$};

\end{tikzpicture}

\end{multicols}

\newpage

\section{Tableau(x)}

Here's a standard Young tableau.

\begin{center}
\begin{tikzpicture}[node distance=0 cm,outer sep = 0pt]
	      \node[bsq] (11) at (   1,  1) {1};
	      \node[bsq] (12) [right = of 11] {4};
	      \node[bsq] (13) [right = of 12] {5};
	      \node[bsq] (14) [right = of 13] {10};
	      \node[bsq] (15) [right = of 14] {11};
	      \node[bsq] (21) [below = of 11] {2};
	      \node[bsq] (22) [right = of 21] {6};
	      \node[bsq] (23) [right = of 22] {8};
	      \node[bsq] (31) [below = of 21] {3};
	      \node[bsq] (32) [right = of 31] {9};
	      \node[bsq] (33) [right = of 32] {12};
	      \node[bsq] (41) [below = of 31] {7};
\end{tikzpicture}
\end{center}

Here's a domino tableau.

\begin{center}
\begin{tikzpicture}[node distance=0 cm,outer sep = 0pt]
        \node[bver] (1) at ( 1.5,   3) {1};
        \node[bver] (2) [below = of 1] {2};
        \node[bhor] (3) at (   3, 3.5) {3};
        \node[bver] (4) at ( 2.5,   2) {4};
        \node[bhor] (5) [right = of 3] {5};
        \node[bhor] (6) at (   4, 2.5) {6};
\end{tikzpicture}
\end{center}

Both of these images use macros from Tyson Gern -- you'll need to copy these from the header section.

\newpage
\section{Graphs of Functions}

Here's a simple graph of the function $f(x) = x - \frac{x^2}{2} +1$.

\begin{center}
\begin{tikzpicture}
\begin{axis}[
	xmin=-2, xmax=2,
	ymin=-3, ymax=3,
	xtick={-2,...,2}, ytick={-3,...,3},
	major tick length={5},
	line width=1pt,
	axis lines=center
	]
	\addplot [Blue,smooth] {x - 0.5*x^2+1};
\end{axis}
\end{tikzpicture}
\end{center}

Here's a graph of a piecewise linear function, with background grid.

\begin{center}
\begin{tikzpicture}
\begin{axis}[
	xmin=-2.5, xmax=3.5,
	ymin=-3.5, ymax=2.5,
	xtick={-4,...,4}, ytick={-4,...,4},
	major tick length={0},
	grid=major,
	line width=1pt, % you can take this out, but I find 1pt lines photocopy better than lighter ones
	axis lines=center
	]
	\addplot [domain=-2.5:-1] {-3-x};
	\addplot [domain=-1:1] {2*x};
	\addplot [domain=1:3.5] {-2*x+4};
\end{axis}
\end{tikzpicture}
\end{center}

\newpage

Here's a graph of $f(x) = \sin(x) - \cos(x)$, with a shaded region.

\begin{center}
\begin{tikzpicture}
	\begin{axis}[
	y=1.5cm, x=2cm, % this sets the size of one unit along each axis.
	xlabel={$x$}, ylabel={$y$},
	xmin=0, xmax=5.3,
	ymin=-1.5, ymax=1.5,
	xtick={0,0.7853981634,1.570796327,2.35619449,3.141592654,3.926990817,4.71238898}, % tike is dumb with multiples of pi
	ytick={-2,-1,...,2},
	xticklabels={0,$\frac{\pi}{4}$,$\frac{\pi}{2}$,$\frac{3\pi}{4}$,$\pi$,$\frac{5\pi}{4}$,$\frac{3\pi}{2}$}, % so we label them manually
	line width=1pt,
	axis lines=center,
	major tick length={8},
	]
	\addplot [smooth, domain=0:5] {sin(deg(x))-cos(deg(x))};
	\addplot [fill=LimeGreen, domain=0:3.926990817] {sin(deg(x))-cos(deg(x))} \closedcycle;
	\node at (axis cs:4.3,1.2) {$f(x) = \sin(x) - \cos(x)$};
\end{axis}
\end{tikzpicture}
\end{center}

Here's another graph, this time with an annoyingly starred region. See p.393 of the \TikZ manual for a list of patterns.

\begin{center}
\begin{tikzpicture}[scale=1]
\begin{axis}[
	y=.5cm, x=2cm,
	xlabel={$x$}, ylabel={$y$},
	xmin=0, xmax=5,
	ymin=0, ymax=11,
	xtick={0,1,2,...,4}, ytick={0,2,...,10},
	line width=1pt,
	axis lines=center
	]
	\addplot [smooth, domain=0:10] {-4*sin(deg(x))+6};
	\addplot [pattern=fivepointed stars, pattern color=Periwinkle, domain=1:4] {-4*sin(deg(x))+6} \closedcycle;
	\node at (axis cs:2,6) {$f(x) =6-4\sin(x)$};
\end{axis}
\end{tikzpicture}
\end{center}

Here's a function and its tangent line. This graph has a legend.

\begin{center}
\begin{tikzpicture}
\begin{axis}[
	legend pos=south east,
	y=2cm, x=3cm,
	xlabel={$x$}, ylabel={$y$},
	xmin=0, xmax=3,
	ymin=-1.2, ymax=1.5,
	xtick={0,1,2}, ytick={0,0.6931471806,1},
	xticklabels={0,1,2}, yticklabels={0, $\ln(2)$,1},
	line width=1pt,
	axis lines=center,
	]
	\addplot [smooth, domain=0.2:2.4,line width=2pt] {ln(x)};
	\addlegendentry{$f(x) = ln(x)$}
	\addplot [smooth, dashed, line width=2pt,Green, domain=0.1:2.4] {x-1};
	\addlegendentry{$y = x - 1$}
\end{axis}
\end{tikzpicture}
\end{center}

\newpage
Here are some various blank axes for a student to draw a graph on.

\begin{center}
\begin{tikzpicture}
\begin{axis}[
	x=1cm, y=1cm,
	xlabel={$x$}, ylabel={$y$},
	xmin=-6, xmax=6,
	ymin=-4, ymax=4,
	xtick={-6,...,6}, ytick={-4,...,4},
	grid=major,
	line width=2pt,
	axis lines=center
	]
\end{axis}
\end{tikzpicture}
\end{center}

\bigskip

\begin{center}
\begin{tikzpicture}
\begin{axis}[
	x=1cm, y=1cm,
	xlabel={$x$}, ylabel={$y$},
	xmin=-6, xmax=6,
	ymin=-4, ymax=4,
	xtick={-5,...,5}, ytick={-3,...,3},
	major tick length={5},
	line width=1pt,
	axis lines=center
	]
\end{axis}
\end{tikzpicture}
\end{center}

\newpage

Here are some 3d graphs.

\begin{center}
\begin{tikzpicture}
\begin{axis}[axis lines=center,line width=1pt]
\addplot3[surf,domain=0:8,samples=20] {sin(deg(x))*sin(deg(y))};
\end{axis}
\end{tikzpicture}
\end{center}

\bigskip

\begin{center}
\begin{tikzpicture}
\begin{axis}[view={60}{30},axis lines=center]
\addplot3[surf,fill=white,opacity=0.6,samples=40,
domain=-3:3,y domain=-3:3,
]
{x^2 + y^2};
\end{axis}
\end{tikzpicture}
\end{center}

\newpage
Here is a 3d plot of a parameterized curve:

\begin{center}
\begin{tikzpicture}
\begin{axis}[view={60}{30},axis lines=center,xmin=-1.5,xmax=1.5,ymin=-1.5,ymax=1.5,zmax=3]
\addplot3+[domain=0:5*pi,samples=60,samples y=0,smooth,mark=none,line width=3pt]
({sin(deg(x))},
{cos(deg(x))},
{2*x/(5*pi)});
\end{axis}
\end{tikzpicture}
\end{center}

\bigskip

And a parameterized torus:

\begin{center}
\begin{tikzpicture}
\begin{axis}[view={80}{60},axis lines=none]
\addplot3[surf,fill=white,opacity=0.6,z buffer=sort,domain=0:2*pi,y domain=0:2*pi]
({(4+cos(deg(x))) * cos(deg(y))}, {(4+cos(deg(x))) * sin(deg(y))}, {sin(deg(x))});
\end{axis}
\end{tikzpicture}
\end{center}

\newpage

\section{Vector Diagrams / Root Systems}

Here are some 2d root systems.

\begin{center}
\begin{tikzpicture}[scale=1.6]

	% draw axes

	\draw[thick,<->] (-2,0) -- (2,0) node[anchor=north east]{$x$};
	\draw[thick,<->] (0,-2) -- (0,2) node[anchor=north west]{$y$};

	% simple roots

	\draw[line width=3,color=blue,->] (0,0) -- (1,-1) node[anchor=north west]{$\alpha_1 = \varepsilon_1 - \varepsilon_2$};
	\draw[line width=3,color=blue,->] (0,0) -- (0,1) node[anchor=south]{$\alpha_2 = \varepsilon_2$};

	% other positive roots

	\draw[->] (0,0) -- (1,1) node[anchor=south west]{$\tilde{\alpha} = \varepsilon_1+\varepsilon_2$};
	\draw[->] (0,0) -- (1,0) ;

	% negative roots

	\draw[color=Gray,->] (0,0) -- (-1,1) ;
	\draw[color=Gray,->] (0,0) -- (-1,0) ;
	\draw[color=Gray,->] (0,0) -- (0,-1) ;
	\draw[color=Gray,->] (0,0) -- (-1,-1) ;

	% dotted square

	\draw[dashed, color=Gray] (1,1) -- (1,-1) -- (-1,-1) -- (-1,1) -- cycle;

	\node[rectangle,draw] at (-3,0) {Type $B_2$};

\end{tikzpicture}

\begin{tikzpicture}

	\draw[thick,<->] (-3,0) -- (3,0) node[anchor=north east]{$x$};
	\draw[thick,<->] (0,-3) -- (0,3) node[anchor=north west]{$y$};

	\draw[line width=3,color=ProcessBlue,->] (0,0) -- (1,-1) node[anchor=north west]{$\alpha_1 = \varepsilon_1 - \varepsilon_2$};
	\draw[line width=3,color=ProcessBlue,->] (0,0) -- (0,2) node[anchor=south]{$\alpha_2 = 2\varepsilon_2$};

	\draw[->] (0,0) -- (1,1) ;
	\draw[color=gray,->] (0,0) -- (-1,1) ;
	\draw[color=gray,->] (0,0) -- (-1,-1) ;

	\draw[color=gray,->] (0,0) -- (-2,0) ;
	\draw[color=gray,->] (0,0) -- (0,-2) ;
	\draw[color=black,->] (0,0) -- (2,0) node[anchor=south]{$\tilde{\alpha} = 2\varepsilon_1$};

	\draw[dashed, color=Gray] (2,0) -- (0,2);
	\draw[dashed, color=Gray] (-2,0) -- (0,2);
	\draw[dashed, color=Gray] (-2,0) -- (0,-2);
	\draw[dashed, color=Gray] (2,0) -- (0,-2);

	\node[rectangle,draw] at (-4.5,0) {Type $C_2$};

\end{tikzpicture}

\begin{tikzpicture}[scale=2]

	\draw[thick,<->] (-1.5,0) -- (1.5,0) node[anchor=north east]{$x$};
	\draw[thick,<->] (0,-1.5) -- (0,1.5) node[anchor=north west]{$y$};

	\draw[line width=3,color=Violet,->] (0,0) -- (.5,-.8660254038) node[anchor=north west]{$\alpha_1 = \left(\frac{1}{2}, -\frac{\sqrt{3}}{2}\right) = \left( \sin\left( \frac{\pi}{6} \right), -\cos\left(\frac{\pi}{6}\right) \right)$ };
	\draw[line width=3,color=Violet,->] (0,0) -- (0,.8660254038) node[anchor=south west]{$\alpha_2 = \left( 0,\frac{\sqrt{3}}{2}\right) = \left( 0, \cos\left( \frac{\pi}{6} \right) \right)$};

\draw[->] (0,0) -- (1,0);
\draw[->] (0,0) -- (.5,.8660254038);
\draw[->] (0,0) -- (.5, -.8660254038);

\draw[->] (0,0) -- (.75,.4330127019);
\draw[->] (0,0) -- (.75,-.4330127019);

\draw[color=gray, ->] (0,0) -- (0,-.8660254038);
\draw[color=gray, ->] (0,0) -- (-.5,.8660254038);
\draw[color=gray, ->] (0,0) -- (-.5, -.8660254038);
\draw[color=gray,->] (0,0) -- (-.75,.4330127019);
\draw[color=gray,->] (0,0) -- (-.75,-.4330127019);
\draw[color=gray, ->] (0,0) -- (-1,0);

\draw[dashed, color=gray] (1,0) -- (.5,.8660254038) -- (-.5,.8660254038) -- (-1,0) -- (-.5,-.8660254038) -- (.5,-.8660254038) -- cycle;

	\node[rectangle,draw] at (-2,-1) {Type $I_2(6)$};

\end{tikzpicture}

\end{center}

\newpage
Here are some root systems in 3d, using \ttfamily tikz-3dplot\rmfamily.

\begin{center}
\tdplotsetmaincoords{60}{120}
\begin{tikzpicture}[tdplot_main_coords, scale=1.6]

	\coordinate (O) at (0,0,0);
	\tdplotsetcoord{P}{1}{-100}{200}

	\draw[dashed, color=gray] (0,1,-1) -- (1,0,-1) -- (1,-1,0) -- (0,-1,1) -- (-1,0,1) -- (-1,1,0) -- cycle;

	\draw[thick,->] (0,0,0) -- (4,0,0) node[anchor=north east]{$x$};
	\draw[thick,->] (0,0,0) -- (0,2.5,0) node[anchor=north west]{$y$};
	\draw[thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};

	\draw[line width=3,color=red,->] (0,0,0) -- (1,-1,0) node[anchor=east]{$\alpha_1 = \varepsilon_1 - \varepsilon_2$};
	\draw[line width=3,color=red,->] (0,0,0) -- (0,1,-1) node[anchor=north west]{$\alpha_2 = \varepsilon_2 - \varepsilon_3$};

	\draw[->] (0,0,0) -- (1,0,-1) node[anchor=north]{$\tilde{\alpha} = \varepsilon_1 - \varepsilon_3$};

	\draw[color=gray, ->] (0,0,0) -- (-1,1,0);
	\draw[color=gray, ->] (0,0,0) -- (0,-1,1);
	\draw[color=gray, ->] (0,0,0) -- (-1,0,1);

	\draw[dashed,line width=1, <->] (-.7,-.7,1.4) -- (.7,.7,-1.4) node[anchor=north west]{$s_{\varepsilon_1 - \varepsilon_2}$};

	\node[rectangle,draw] at (0,3,2) {Type $A_2$};

\end{tikzpicture}

\bigskip

\tdplotsetmaincoords{80}{110} % change these parameters to rotate the 3d coordinate system
\begin{tikzpicture}[tdplot_main_coords, scale=2]

	\coordinate (O) at (0,0,0);
	\tdplotsetcoord{P}{1}{-100}{200}

	% draw axes

	\draw[thick,->] (0,0,0) -- (5,0,0) node[anchor=north east]{$x$};
	\draw[thick,->] (0,0,0) -- (0,2.5,0) node[anchor=north west]{$y$};
	\draw[thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};

	% simple roots

	\draw[line width=3,color=Magenta,->] (0,0,0) -- (1,-1,0) node[anchor=east]{$\alpha_1 = \varepsilon_1 - \varepsilon_2$};
	\draw[line width=3,color=Magenta,->] (0,0,0) -- (0,1,-1) node[anchor=north west]{$\alpha_2 = \varepsilon_2 - \varepsilon_3$};
	\draw[line width=3,color=Magenta,->] (0,0,0) -- (0,1,1) node[anchor=south west]{$\alpha_3 = \varepsilon_2 + \varepsilon_3$};

	% other positive roots

	\draw[->] (0,0,0) -- (1,1,0) node[anchor=west]{$\tilde{\alpha} = \varepsilon_1 + \varepsilon_2$};
	\draw[->] (0,0,0) -- (1,0,1) ;
	\draw[->] (0,0,0) -- (1,0,-1);

	% negative roots

	\draw[color=Gray,->] (0,0,0) -- (-1,0,1) ;
	\draw[color=Gray,->] (0,0,0) -- (-1,1,0) ;
	\draw[color=Gray,->] (0,0,0) -- (0,-1,1) ;
	\draw[color=Gray,->] (0,0,0) -- (-1,0,-1) ;
	\draw[color=Gray,->] (0,0,0) -- (-1,-1,0) ;
	\draw[color=Gray,->] (0,0,0) -- (0,-1,-1) ;

	% cube of side length 2

	\draw[dashed, color=gray] (1,1,1) -- (1,1,-1);
	\draw[dashed, color=gray] (1,1,1) -- (1,-1,1);
	\draw[dashed, color=gray] (1,1,1) -- (-1,1,1);

	\draw[dashed, color=gray] (1,1,-1) -- (-1,1,-1);
	\draw[dashed, color=gray] (1,1,-1) -- (1,-1,-1);

	\draw[dashed, color=gray] (1,-1,1) -- (-1,-1,1);
	\draw[dashed, color=gray] (1,-1,1) -- (1,-1,-1);

	\draw[dashed, color=gray] (-1,1,1) -- (-1,-1,1);
	\draw[dashed, color=gray] (-1,1,1) -- (-1,1,-1);

	\draw[dashed, color=gray] (-1,1,-1) -- (-1,-1,-1);
	\draw[dashed, color=gray] (1,-1,-1) -- (-1,-1,-1);
	\draw[dashed, color=gray] (-1,-1,1) -- (-1,-1,-1);

	\node[rectangle,draw] at (0,-2.5,1) {Type $D_3$};

\end{tikzpicture}
\end{center}

\newpage

\begin{center}
\tdplotsetmaincoords{80}{110}
\begin{tikzpicture}[tdplot_main_coords, scale=2.6]

	\coordinate (O) at (0,0,0);
	\tdplotsetcoord{P}{1}{-100}{200}

	\draw[thick,->] (0,0,0) -- (5,0,0) node[anchor=north east]{$x$};
	\draw[thick,->] (0,0,0) -- (0,2.5,0) node[anchor=north west]{$y$};
	\draw[thick,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};

	\draw[line width=3,color=blue,->] (0,0,0) -- (1,-1,0) node[anchor=east]{$\alpha_1 = \varepsilon_1 - \varepsilon_2$};
	\draw[line width=3,color=blue,->] (0,0,0) -- (0,1,-1) node[anchor=north west]{$\alpha_2 = \varepsilon_2 - \varepsilon_3$};
	\draw[line width=3,color=blue,->] (0,0,0) -- (0,0,1) node[anchor=south]{$\alpha_3 = \varepsilon_3$};

	\draw[->] (0,0,0) -- (1,1,0) node[anchor=west]{$\tilde{\alpha} = \varepsilon_1 + \varepsilon_2$};

	\draw[->] (0,0,0) -- (1,0,-1);
	\draw[->] (0,0,0) -- (-1,1,0) ;
	\draw[->] (0,0,0) -- (0,-1,1) ;
	\draw[->] (0,0,0) -- (-1,0,1) ;
	\draw[->] (0,0,0) -- (1,0,1) ;
	\draw[->] (0,0,0) -- (1,1,0) ;
	\draw[->] (0,0,0) -- (0,1,1) ;
	\draw[->] (0,0,0) -- (-1,0,-1) ;
	\draw[->] (0,0,0) -- (-1,-1,0) ;
	\draw[->] (0,0,0) -- (0,-1,-1) ;

	\draw[line width=2,color=gray,->] (0,0,0) -- (-1,0,0) ;
	\draw[line width=2,color=gray,->] (0,0,0) -- (0,-1,0) ;
	\draw[line width=2,color=gray,->] (0,0,0) -- (0,0,-1) ;
	\draw[line width=2,color=black,->] (0,0,0) -- (1,0,0) ;
	\draw[line width=2,color=black,->] (0,0,0) -- (0,1,0) ;

	% CUBE OF SIDE LENGTH 2

	\draw[dashed, color=gray] (1,1,1) -- (1,1,-1);
	\draw[dashed, color=gray] (1,1,1) -- (1,-1,1);
	\draw[dashed, color=gray] (1,1,1) -- (-1,1,1);

	\draw[dashed, color=gray] (1,1,-1) -- (-1,1,-1);
	\draw[dashed, color=gray] (1,1,-1) -- (1,-1,-1);

	\draw[dashed, color=gray] (1,-1,1) -- (-1,-1,1);
	\draw[dashed, color=gray] (1,-1,1) -- (1,-1,-1);

	\draw[dashed, color=gray] (-1,1,1) -- (-1,-1,1);
	\draw[dashed, color=gray] (-1,1,1) -- (-1,1,-1);

	\draw[dashed, color=gray] (-1,1,-1) -- (-1,-1,-1);
	\draw[dashed, color=gray] (1,-1,-1) -- (-1,-1,-1);
	\draw[dashed, color=gray] (-1,-1,1) -- (-1,-1,-1);

	% TETRAHEDRON

	\draw[color=gray] (1,0,0) -- (0,1,0) -- (0,0,1) -- cycle;
	\draw[color=gray] (1,0,0) -- (0,-1,0) -- (0,0,1) --  cycle;
	\draw[color=gray] (1,0,0) -- (0,0,-1) -- (0,-1,0) -- cycle;
	\draw[color=gray] (1,0,0) -- (0,0,-1) -- (0,1,0) -- cycle;

	\draw[color=gray] (-1,0,0) -- (0,1,0) -- (0,0,1) -- cycle;
	\draw[color=gray] (-1,0,0) -- (0,-1,0) -- (0,0,1) --  cycle;
	\draw[color=gray] (-1,0,0) -- (0,0,-1) -- (0,-1,0) -- cycle;
	\draw[color=gray] (-1,0,0) -- (0,0,-1) -- (0,1,0) -- cycle;

	\node[rectangle,draw] at (0,2,2) {Type $B_3$};

\end{tikzpicture}

\bigskip

\tdplotsetmaincoords{80}{110}
\begin{tikzpicture}[tdplot_main_coords, scale=2]

	\coordinate (O) at (0,0,0);
	\tdplotsetcoord{P}{1}{-100}{200}

	\draw[thick,->] (0,0,0) -- (6,0,0) node[anchor=north east]{$x$};
	\draw[thick,->] (0,0,0) -- (0,3.5,0) node[anchor=north west]{$y$};
	\draw[thick,->] (0,0,0) -- (0,0,3) node[anchor=south]{$z$};

	\draw[line width=3,color=ProcessBlue,->] (0,0,0) -- (1,-1,0) node[anchor=east]{$\alpha_1 = \varepsilon_1 - \varepsilon_2$};
	\draw[line width=3,color=ProcessBlue,->] (0,0,0) -- (0,1,-1) node[anchor=north west]{$\alpha_2 = \varepsilon_2 - \varepsilon_3$};
	\draw[line width=3,color=ProcessBlue,->] (0,0,0) -- (0,0,2) node[anchor=south]{$\alpha_3 = 2\varepsilon_3$};

	\draw[->] (0,0,0) -- (1,1,0);
	\draw[->] (0,0,0) -- (1,0,-1);
	\draw[->] (0,0,0) -- (-1,1,0) ;
	\draw[->] (0,0,0) -- (0,-1,1) ;
	\draw[->] (0,0,0) -- (-1,0,1) ;
	\draw[->] (0,0,0) -- (1,0,1) ;
	\draw[->] (0,0,0) -- (1,1,0) ;
	\draw[->] (0,0,0) -- (0,1,1) ;
	\draw[->] (0,0,0) -- (-1,0,-1) ;
	\draw[->] (0,0,0) -- (-1,-1,0) ;
	\draw[->] (0,0,0) -- (0,-1,-1) ;

	\draw[line width=2,color=Gray,->] (0,0,0) -- (-2,0,0) ;
	\draw[line width=2,color=Gray,->] (0,0,0) -- (0,-2,0) ;
	\draw[line width=2,color=Gray,->] (0,0,0) -- (0,0,-2) ;
	\draw[line width=2,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$\tilde{\alpha} = 2\varepsilon_1$} ;
	\draw[line width=2,color=black,->] (0,0,0) -- (0,2,0)  ;

	% CUBE OF SIDE LENGTH 2

	\draw[dashed, color=gray] (1,1,1) -- (1,1,-1);
	\draw[dashed, color=gray] (1,1,1) -- (1,-1,1);
	\draw[dashed, color=gray] (1,1,1) -- (-1,1,1);

	\draw[dashed, color=gray] (1,1,-1) -- (-1,1,-1);
	\draw[dashed, color=gray] (1,1,-1) -- (1,-1,-1);

	\draw[dashed, color=gray] (1,-1,1) -- (-1,-1,1);
	\draw[dashed, color=gray] (1,-1,1) -- (1,-1,-1);

	\draw[dashed, color=gray] (-1,1,1) -- (-1,-1,1);
	\draw[dashed, color=gray] (-1,1,1) -- (-1,1,-1);

	\draw[dashed, color=gray] (-1,1,-1) -- (-1,-1,-1);
	\draw[dashed, color=gray] (1,-1,-1) -- (-1,-1,-1);
	\draw[dashed, color=gray] (-1,-1,1) -- (-1,-1,-1);

	% TETRAHEDRON

	\draw[color=gray] (2,0,0) -- (0,2,0) -- (0,0,2) -- cycle;
	\draw[color=gray] (2,0,0) -- (0,-2,0) -- (0,0,2) -- cycle;
	\draw[color=gray] (2,0,0) -- (0,0,-2) -- (0,-2,0) -- cycle;
	\draw[color=gray] (2,0,0) -- (0,0,-2) -- (0,2,0) -- cycle;

	\draw[color=gray] (-2,0,0) -- (0,2,0) -- (0,0,2) -- cycle;
	\draw[color=gray] (-2,0,0) -- (0,-2,0) -- (0,0,2) -- cycle;
	\draw[color=gray] (-2,0,0) -- (0,0,-2) -- (0,-2,0) -- cycle;
	\draw[color=gray] (-2,0,0) -- (0,0,-2) -- (0,2,0) -- cycle;

	\node[rectangle,draw] at (0,2,2) {Type $C_3$};

\end{tikzpicture}

\end{center}

\newpage

\section{Adding extra space in tables}

Here's a table with a little extra height added to the columns and extra padding added in the cells:

\begin{center}
{ \renewcommand{\arraystretch}{1.8} % stretches the row height
\setlength{\tabcolsep}{10pt} % adds horizontal padding
\begin{tabular}{|c|c|c|c|c|c|} \hline
$x$ &0&${\pi/4} $&${\pi/2} $ &${3\pi/4} $ &${\pi} $ \\ \hline
$\cos(x)$ &1 &$\sqrt2/2$ &0 &$-\sqrt{2}/{2}$ &$-1$ \\ \hline
$\sin(x)$ &0 &$\sqrt2/2$ &1 &$\sqrt{2}/{2}$ &$0$ \\ \hline
\end {tabular}
}
\end{center}

\vfill\eject
\end{document}


\section{Sesquilinear forms}


\chapter{Code: quantinf Module}

The code developed to extend QuTiP with QI functionality, all put together in a single module file. Save it with the name \texttt{quantinf.py} in order to run the time evolution and Werner states programs from chapter 6. Save the programs in the same directory as this module for convenience, if not familiar with how to add a module to the Python path.\\
A copy can be obtained from\\
https://github.com/saad440/undergrad-project \\

\begin{verbatim}
# -*- coding: utf-8 -*-
"""
This module implements a number of quantum information functions
in QuTiP (Quantum Toolbox in Python)

Project: Investigation of Entanglement Measures in QuTiP
         (IIUI, Fall 2015)

@author: Muhammad Saad <muhammad.saad@yandex.com>
"""

__all__ = ['purity','ispure','purity_of_reduced','ismixed_reduced',
        'peres_horodecki_bipartite','schmidt_decomposition', 'dist_kl',
        'entropy_entg', 'entropy_linear_entg', 'negativity', 'log_neg',
        'linear_entropy', 'entropy_renyi', 'entropy_renyi_entg' ]

from qutip import ( Qobj, ket2dm, entropy_vn, ptrace, partial_transpose )
from numpy import log2
import numpy as np

def purity(dm):
    """ Calculates trace of density matrix squared

    Parameters
    ----------
    dm: qobj/array-like
        Input density matrix

    Returns
    -------
    purity:
        Purity of the state. 1 for pure, 0.5 for maximally mixed.

    """
    if dm.type == 'ket':
        dm = ket2dm(dm)
    if dm.type != 'oper':
        raise TypeError("Input must be a state ket or density matrix")
    purity = (dm**2).tr()
    return purity

def purity_of_reduced(rho):
    """ Calculates trace of reduced density matrix square

    Parameters
    ----------
    dm: qobj/array-like
        Input density matrix

    Returns
    -------
    purityreduced:
        Purity of the reduced DM. 1 for pure, 0.5 for maximally mixed.

    """
    rhopartial = ptrace(rho,0)
    purityreduced = purity(rhopartial)
    return purityreduced

def ispure(dm):
    """ Checks whether or not a density matrix represents a pure state

    Parameters
    ----------
    dm : qobj/array-like
        Density operator representing the state.

    -------
    pure : bool
        Whether or not the state is pure. True: Pure, False: Mixed.

    """
    if np.round(purity(dm),8) == 1:
        return True
    else:
        return False

def ismixed_reduced(dm):
    """ One way to check for entanglement is that the reduced density
    matrix is mixed. This function checks for that criterion.

    Parameters
    ----------
    dm : qobj/array-like
        Density operator representing the state.

    -------
    mixed : bool
        Whether or not the reduced DM is mixed. True: Mixed, False: Pure

    """
    if np.round(purity_of_reduced(dm),8) != 1:
        return True
    else:
        return False

def schmidt_decomposition(vec):
    """ Schmidt decomposition of a bipartite vector
    Based on the implementation in QETLAB 0.9
    which was written by Nathaniel Johnston (nathaniel@njohnston.ca)
    and as of this port, last updated on December 1, 2012

    Parameters
    ----------
    vec : qobj, ket vector of product state
        ket vector representing the bipartite state

    -------
    Returns:
    [s, u, v]
    s : list of floats
        Schmidt coefficients
    u : list of Qobj
        list of left Schmidt vectors of ket
    v : list of Qobj
        list of right Schmidt vectors of ket

    """
    if vec.type != 'ket':
        raise TypeError("Input must be a ket vector.")
    if len(vec.dims[0])==1:
        raise TypeError("Input must be a joint state.")

    dim = vec.dims[0][0]
    vecnp = vec.full()
    vecnpr = np.reshape(vecnp,[dim,dim])
    um,s,vm = np.linalg.svd(vecnpr)

    s = list(s)

    def extract_vecs(mat):
        veclist = list()
        for j in range(mat.shape[1]):
            veclist.append(Qobj(mat[:,j]))
        return veclist
    u = extract_vecs(um)
    v = extract_vecs(vm)

    return [s,u,v]

def peres_horodecki_bipartite(rho, mask=[0,1]):
    """ Tests the given bipartite state for Peres-Horodecki criterion

    Parameters
    ----------
    rho: qobj/array-like
        Density operator for the state
    mask: list of int, length 2
        mask used for partial transpose

    Returns
    -------
    isentangled: bool
        True for entangled, False for disentangled

    """
    if rho.type != 'oper':
        raise TypeError("Input must be a density matrix")
    rhopt = partial_transpose(rho,mask)
    rhopt_eigs = rhopt.eigenenergies()
    if min(rhopt_eigs) < 0:
        isentangled = True
    else:
        isentangled = False
    return isentangled

def entropy_entg(rho, base=2):
    """ Calculates the entropy of entanglement of a density matrix

    Parameters:
    -----------
    rho : qobj/array-like
        Input density matrix
    base:
        Base of log

    Returns:
    --------
    ent_entg: Entropy of Entanglement

    """
    if rho.type == 'ket':
        rho = ket2dm(rho)
    if rho.type != 'oper':
        raise TypeError("Input must be density matrix")
    rhopartial = ptrace(rho,0)
    ent_entg = entropy_vn(rhopartial,base)
    return ent_entg

def linear_entropy(dm, normalize=False):
    """ Returns the linear entropy of a state.

    Parameters
    ----------
    dm : qobj/array-like
        Density operator representing the state.
    normalize : bool
        Optional argument to normalize linear entropy such that the
        completely mixed state has LE = 1 rather than 1-1/d. [1]
        Default: False

    ----------
    le : float
        Linear entropy

    ----------
    References:
        [1] "Linear entropy and Bell inequalities", Santos and Ferrero,
            Phys. Rev. A 62, 024101

    """
    if dm.type not in ('oper','ket'):
        raise TypeError("Input must be a Qobj representing a state.")
    if dm.type=='ket':
        dm = ket2dm(dm)

    le = 1 - (dm**2).tr()
    if normalize:
        d = dm.shape[0]
        le = le * d/(d-1)
    return le

def entropy_linear_entg(rho, normalize=True):
    """ Calculates the linear entropy of entanglement of a density matrix

    Parameters:
    -----------
    rho : qobj/array-like
        Input density matrix

    Returns:
    --------
    linent_entg: Linear Entropy of Entanglement

    """
    if rho.type == 'ket':
        rho = ket2dm(rho)
    if rho.type != 'oper':
        raise TypeError("Input must be density matrix")
    rhopartial = ptrace(rho,0)
    linent_entg = linear_entropy(rhopartial,normalize)
    return linent_entg

def entropy_renyi(rho,alpha):
    """ Calculate Renyi entropy of the density matrix with given index
    (Currently limited to 2-level systems)

    Parameters
    ----------
    dm: qobj/array-like
        Input density matrix

    alpha: Renyi index alpha

    Returns
    -------
    ent_rn: Renyi Entropy

    """
    if rho.type != 'oper':
        raise TypeError("Input must be a density matrix")
    qi = rho.eigenenergies()

    if alpha == 1:
        ent_rn = entropy_vn(rho,2)
    elif alpha >= 0:
        ent_rn = ( 1/(1-alpha) ) * log2 ( sum( qi**alpha ) )
    else:
        raise ValueError("alpha must be a non-negative number")
    return ent_rn

def entropy_renyi_entg(rho,alpha):
    """ Calculate Renyi entropy of entanglement for the DM with given index
    (Currently limited to 2-level systems)

    Parameters
    ----------
    dm: qobj/array-like
        Input density matrix

    alpha: Renyi index alpha

    Returns
    -------
    ent_rn_entg: Renyi Entropy of Entanglement

    """
    rhopartial = ptrace(rho,0)
    ent_rn_entg = entropy_renyi(rhopartial,alpha)
    return ent_rn_entg

def negativity(rho,mask=[1,0]):
    """ Calculate the negativity for a density matrix

    Parameters:
    -----------
    rho : qobj/array-like
        Input density matrix

    Returns:
    --------
    neg : Negativity

    """
    if rho.type != 'oper':
        raise TypeError("Input must be a density matrix")
    rhopt = partial_transpose(rho,mask)
    neg = ( rhopt.norm() - 1 ) / 2
    return neg

def log_neg(rho,mask=[1,0]):
    """ Calculate the logarithmic negativity for a density matrix

    Parameters:
    -----------
    rho : qobj/array-like
        Input density matrix

    Returns:
    --------
    logneg: Logarithmic Negativity

    """
    if rho.type != 'oper':
        raise TypeError("Input must be a density matrix")
    rhopt = partial_transpose(rho,mask)
    logneg = log2( rhopt.norm() )
    return logneg

def dist_kl(rho, sgm):
    """ Calculates the Kullback-Leibler distance (a.k.a. relative entropy)
    between DMs rho and sgm representing two-level systems.

    Parameters
    ----------
    rho : qobj/array-like
        First density operator.

    sgm : qobj/array-like
        Second density operator.

    Returns
    -------
    kldist : float
        Relative Entropy between rho and sgm.

    """
    if rho.type != 'oper' or sgm.type != 'oper':
        raise TypeError("Inputs must be density matrices..")

    ent_vn = entropy_vn(rho,2)

    r_eigs = rho.eigenenergies()
    s_eigs = sgm.eigenenergies()
    # too small negtive values may give trouble
    s_eigs = np.round(s_eigs,8)

    kldist = -ent_vn
    for pj, qj in zip(r_eigs,s_eigs):
        if qj==0:
            pass
        else:
            kldist -= pj * log2(qj)

    kldist = abs(kldist)
    return kldist

\end{verbatim}


\chapter*{Appendix C3 - Example of generated VHDL code}
\label{cha:ex1-vhdl}

This is the code generated from program given in Listing~\ref{lst:rfsm-gensig}

\begin{lstlisting}[language=VHDL,frame=single,numbers=none,basicstyle=\small,caption=File g.vhd]
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity g is
  port(
        h: in std_logic;
        e: in std_logic;
        s: out std_logic;
        rst: in std_logic
        );
end entity;

architecture RTL of g is
  type t_state is ( E0, E1 );
  signal state: t_state;
begin
  process(rst, h)
    variable k: unsigned(2 downto 0);
  begin
    if ( rst='1' ) then
      state <= E0;
    elsif rising_edge(h) then
      case state is
      when E1 =>
        if ( k<to_unsigned(4,3) ) then
          k := k+to_unsigned(1,3);
        elsif  ( k = to_unsigned(4,3) ) then
          state <= E0;
        end if;
      when E0 =>
        if ( e = '1' ) then
          k := to_unsigned(1,3);
          state <= E1;
        end if;
    end case;
    end if;
  end process;
  process(state)
  begin
    case state is
    when E0 =>
      s <= '0';
    when E1 =>
      s <= '1';
    end case;
  end process;
end architecture;
\end{lstlisting}

\begin{lstlisting}[language=VHDL,frame=single,numbers=none,basicstyle=\small,caption=File tb.vhd]
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library rfsm;
use rfsm.core.all;

entity tb is
end tb;

architecture Bench of tb is

component g
  port(
        h: in std_logic;
        e: in std_logic;
        s: out std_logic;
        rst: in std_logic
        );
end component;

signal E: std_logic;
signal H: std_logic;
signal S: std_logic;
signal rst: std_logic;

begin

  inp_E: process
    type t_vc is record date: time; val: std_logic; end record;
    type t_vcs is array ( 0 to 2 ) of t_vc;
    constant vcs : t_vcs := ( (0 ns,'0'), (25 ns,'1'), (35 ns,'0') );
    variable i : natural := 0;
    variable t : time := 0 ns;
    begin
      for i in 0 to 2 loop
        wait for vcs(i).date-t;
        E <= vcs(i).val;
        t := vcs(i).date;
      end loop;
      wait;
  end process;
  inp_H: process
    type t_periodic is record period: time; t1: time; t2: time; end record;
    constant periodic : t_periodic := ( 9 ns, 0 ns, 80 ns );
    variable t : time := 0 ns;
    begin
      H <= '0';
      wait for periodic.t1;
      notify_ev(H,1 ns);
      while ( t < periodic.t2 ) loop
        wait for periodic.period;
        notify_ev(H,1 ns);
        t := t + periodic.period;
      end loop;
      wait;
  end process;

  U0: G port map(H,E,S,rst);

  process

  begin
    rst <= '1';
    wait for 1 ns;
    rst <= '0';
    wait for 100 ns;
    wait;

  end process;
end Bench;
\end{lstlisting}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "rfsm"
%%% End:


\documentclass{article}
\usepackage[utf8]{inputenc}

\title{Poisson, Gauss Fits and Cuts}
\author{Juan Camilo Bohorquez }
\date{October 2020}

\begin{document}

\maketitle

\section{Intro}

During our experimental cycle we use the presence (or absence) of an atom within our trap as the main metric for understanding it's state.

We measure an atom's presence by illuminating the trap with near-resonant beams along a cycling transition for an integration time $T$. In our experiment these are two 852nm beams near resonant a cycling transition on the D2 line, along with a repumper to ensure the atoms stay within the cycling manifold.
\begin{itemize}
    \item Cycling Transition $6S_{1/2}F=4 \rightarrow 6P_{3/2}F'=5$
    \item Repumping Transition $6S_{1/2}F=3 \rightarrow 6P_{3/2}F'=4$
\end{itemize}

We refer to this as a readout pulse, or a readout phase.

During the readout phase our photon detecting instrument (either a photon counter or a very sensitive camera) will collect some of the atomic fluorescence, as well as some photons from background sources.

We then determine whether an atom was present in the trap during readout by applying a cutoff we refer to as a cut, $n_c$. If the number of collected photons is below $n_c$ during a readout pulse, we label that pulse as having no atoms in the trap, otherwise that pulse as having had an atom in the trap.

With the set of functions in FittingH5.py we are interested in characterizing our readout by understanding the modeling parameters that best fit our photon counting data, and from those parameters establishing the best possible cut. We also want to know our uncertainty in that choice of cut, as well as the error rate in our discrimination.

\section{Photon counting probability distributions}

The methodology for photon counting and analysis of our data is to run experiments were many (hundreds) of measurements where readout pulses are performed under the same condition. Then number of photon counts detected during each of those measurements is then considered a data point. We plot all of those data points together in a histogram, then fit that histogram to a curve we expect to describe the behavior we measured.

\subsection{Poisson Distributions}

Photon counting is a Poisson process, and the photon counting statistics therefore follow a Poisson distribution.

In our case the Poisson distribution describes the probability that a number of photons $n$ are counted at the detector, when there is an expected number of photons $\mu$ that does not vary over the course of the experiment.

This probability distribution is:
\[P_{\mu}(n) = \frac{\mu^n e^{-\mu}}{n!}\]
And can be generalized to be continuous using the gamma function $\Gamma(x)$.
\[P_{\mu}(x) = \frac{\mu^x e^{-\mu}}{\Gamma(x+1)}\]

The distinction between the 0 atom case and the 1 atom  case is the expected number of photons, $\mu$.

In the case where there are no atoms in the trap, $\mu_0$ is determined by a variety of noise process.
\begin{enumerate}
    \item Electrical and Thermal noise on the detector
    \item Background photons from sources other than atomic fluorescence
\end{enumerate}

In the case where there is an atom in the trap, $\mu_1$ is determined by the sum of the background counts, and the counts due to atomic fluorescence.

Thus $\mu_1 > \mu_0$ for all of our experiments.

In the regime where a Poisson distribution is a convenient model, we fit our histogram to a double Poisson distribution. There we have two weighted Poisson curves corresponding to the photon counts from readouts where there was no atom in the trap and readout where there was an atom in the trap.

\[P_{\mu_0,\mu_1}(x) = a_0\frac{\mu_0^x e^{-\mu_0}}{\Gamma(x+1)}+a_1\frac{\mu_1^x e^{-\mu_1}}{\Gamma(x+1)}\]

Where:
\begin{itemize}
    \item $a_0, a_1$ correspond to the number of readouts with 0 or 1 atoms in the trap, respectively
    \item $\mu_0, \mu_1$ correspond to the expected number of photons in the case where there were 0 or 1 atoms in the trap, respectively.
\end{itemize}

\subsection{Gaussian Distributions}
In the case of large $\mu$ computing a Poisson distribution is often impossible with floating point numbers. Thus we make use of the fact that Poisson distribution can be approximated to a normal distribution (Gaussian) in this limit. With a standard deviation of $\sigma = \sqrt{\mu}$

\[P_{\mu,\sigma}(x) = \frac{1}{\sigma\sqrt{2\pi}}e^{-1/2\left(\frac{x-\mu}{\sigma}\right)^2}\]

This distribution is characterized by
\begin{itemize}
    \item $\mu$ a mean or expected value
    \item $\sigma$ a standard deviation
\end{itemize}

If our counting statistics are in this limit, we fit our photon counting histogram to a double Gaussian function

\[P_{\mu_0,\mu_1,\sigma_0,\sigma_1}(x) = \frac{a_0}{\sigma_0\sqrt{2\pi}}e^{-1/2\left(\frac{x-\mu_0}{\sigma_0}\right)^2}+\frac{a_1}{\sigma_1\sqrt{2\pi}}e^{-1/2\left(\frac{x-\mu_1}{\sigma_1}\right)^2}\]

\section{Determining Cuts}

We want to use the fit parameters from above to determine the optimal cut. We can consider a cut optimal if it minimizes the error in labeling a measurement as having had 0 or 1 atoms.

We identify our error rate in labeling as follows:
Error rate from false positives:
\[ E_p = a'_0\int_{n_c}^\infty P_0(x)dx\]
Error rate from false negatives
\[ E_n = a'_1\int_{-\infty}^{n_c} P_1(x)dx\]
Total Error Rate:
\[ E = a'_0\int_{n_c}^\infty P_0(x)dx + a'_1\int_{-\infty}^{n_c} P_1(x)dx\]

Where $P_i(x)$ is the probability density function for detecting $x$ photons, given $i$ atoms in the trap, and $a'_0$, and $a'_1$ are the normalized weights in our distribution:

$$a'_i \equiv \frac{a_i}{a_0+a_1}$$

We optimize the Error rate by minimizing it with respect to $n_c$

\[\frac{dE}{dn_c}(n_c = n_{opt}) = 0\]
and we find the relation:
\[ a_0 P_0(n_{opt}) = a_1 P_1(n_{opt})\]

Thus, we just have to find the intercept of the (weighted) functions to find the optimal cut between them.

\subsection{Optimal Cut for Poisson Discrimination}
If we model our photon collection as a Poisson process, then we have to solve the following equation for n:

\[ a_0\frac{\mu_0^{n_c} e^{-\mu_0}}{n_c!} = a_1\frac{\mu_1^{n_c} e^{-\mu_1}}{n_c!} \]
Which gives us
\[n_c = \frac{ln(\frac{a_1}{a_0})+\mu_0-\mu_1}{ln(\frac{\mu_1}{\mu_2})}\]

\subsection{Optimal Cut for Gaussian Distribution}

Given our two Gaussian curves we have to solve the following equation for n:
\[\frac{a_0}{\sigma_0\sqrt{2\pi}} e^{-1/2(\frac{n_c-\mu_0}{\sigma_0})^2} = \frac{a_1}{\sigma_1\sqrt{2\pi}} e^{-1/2(\frac{n_c-\mu_1}{\sigma_1})^2} \]

Which can be solved using the quadratic formula:
\[n_c = \frac{-b\pm \sqrt{b^2-4ac}}{2a}\]

Where:
\[a = \frac{1}{\sigma_1^2} - \frac{1}{\sigma_0^2}\]
\[b = -2\left(\frac{\mu_1}{\sigma_1^2} -\frac{\mu_0}{\sigma_0^2}\right)\]
\[c = \left(\frac{\mu_1}{\sigma_1}\right)^2-\left(\frac{\mu_0}{\sigma_0}\right)^2+2\left(ln\left(\frac{a_0}{a_1}\right)-ln\left(\frac{\sigma_0}{\sigma_1}\right)\right)\]

We choose the solution which falls in between our means. That is $\mu_0 < n_c \mu_1$. For an arbitrary set of parameters for these Gaussian functions, there is no guarantee than an intercept will fall between the means, but the assumption here is that there is some hope of labeling the measurements with decent fidelity, and in that regime there will always be one such intercept.

\section{Error analysis on optimal cuts}
Our optimal cuts above are derived from fitting parameters fit to (often) noisy counter data. As such there is an uncertainty in each of those fitting parameters, provided by the fitting functions we use.

Because of those uncertainties we can assume that there will be an uncertainty in the derived value, $n_c$. We can deduce the uncertainty we have in our cut by applying the following principle

For a property that is a function of set of variables $F(v_1,v_2,v_3...)$, with some uncertainties $\Delta v_1, \Delta v_2, \Delta v_3 ...$, we can estimate the uncertainty (to first order) as:
\[ \Delta F = \Delta v_1 \frac{\partial F}{\partial v_1} + \Delta v_2 \frac{\partial F}{\partial v_2} + \Delta v_3 \frac{\partial F}{\partial v_3} + ...\]

\subsection{Uncertainty in Poisson Cut}

In the case of the double Poisson fit we can use the above formula to find:
\[ \Delta n_c = \frac{1}{log\left(\frac{\mu_0}{\mu_1}\right)} \left(\frac{\Delta a_1}{a_1} - \frac{\Delta a_0}{a_0} + (\Delta\mu_0-\Delta\mu_1)\left(1-\frac{1}{log\left(\frac{\mu_0}{\mu_1}\right)}\right)\right)\]

\subsection{Uncertainty in Gaussian Cut}

In this case it's easier to find the uncertainty in our parameters $a$, $b$, and $c$ as a function of the fit parameters, then use those uncertainties to find the uncertainty in the cut.

\[\Delta n_c = \frac{1}{a}\left(\Delta a \left(-\frac{-b\pm Q}{a}\mp 2\frac{c}{Q}\right) +\Delta b \left(-1\pm \frac{b}{Q}\right) \mp 2\Delta c \frac{a}{Q}\right)\]
Where we define Q as the discriminant
$Q \equiv \sqrt{b^2-4ac}$

\[\Delta a = 2\left(\frac{\Delta\sigma_0}{\sigma_0^3}-\frac{\Delta\sigma_1}{\sigma_1^3}\right)\]
\[\Delta b = -2\left(\frac{\Delta\mu_1}{\sigma_1^2}-\frac{\Delta\mu_0}{\sigma_0^2}+2\Delta \sigma_0\frac{\mu_0^2}{\sigma_0^3}-2\Delta \sigma_1\frac{\mu_1^2}{\sigma_1^3}\right)\]
\[ \Delta c = 2\left(\Delta \mu_1 \frac{\mu_1}{\sigma_1^2}-\Delta \mu_0 \frac{\mu_0}{\sigma_0^2}+\Delta \sigma_0\left(\frac{\mu_0^2}{\sigma_0^3}-\frac{1}{\sigma_0^2} \right) - \Delta \sigma_1\left(\frac{\mu_1^2}{\sigma_1^3}-\frac{1}{\sigma_1^2} \right) + \frac{\Delta a_0}{a_0}- \frac{\Delta a_1}{a_1}\right)\]
\end{document}

H5_python3/Documentation/Gauss and Poisson Cuts.tex


\documentclass[11pt, oneside]{article}
\usepackage{geometry}
\geometry{letterpaper}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{float}
\usepackage{parskip}
\usepackage{fancyref}
\usepackage{fullpage}
\renewcommand{\tabcolsep}{1cm}
\renewcommand{\arraystretch}{1.5}

\title{Hidden Markov Models}
\author{Rapid Learning Session 2014}
\date{}

\begin{document}
\maketitle

This is intended to be a short and informal introduction to HMMs
\footnote{The notation and some parts of this tutorial are based Rabiner LR. (1989) A Tutorial on Hidden Markov Models and Selected Applications in Speech Recognition. \textit{Proceedings of the IEEE}, 77(2):257-286}.

\section{Introduction}
\subsection{What is a hidden Markov model?}
In general, a \textbf{Markov process} is a random process that switches between different states.
%generates values with probabilities that are dependent on the state of the system at that time.
%The system randomly switches between states
according to some \textit{transition probabilities}. The probability of being in a particular state at a given time step is dependent only on the the state at the previous time step - this is known as the \textbf{Markov property}. %When we look at data generated from a Markov process, we can see an ordered sequence of states (e.g. A, A, A, B, B) paired with values that were generated at that point in time (e.g. 1, 1, 2, 4, 5). We can use these kinds of data to calculate the transition probabilities between states and also the probabilities of generating particular values given the state of the system at time $t$.

% Maybe we should take this out...probably I think
%A toy example of such a system is the weather throughout the day, depicted in Figure \ref{fig:simple}.
%\begin{figure}[H]
%\label{fig:simple}
%\centering
%\includegraphics[width=0.5\textwidth]{../figures/g5016.png}
%\caption{A 2-state Markov chain}
%\end{figure}

In contrast, a \textbf{hidden Markov model} is a Markov process with unobserved or ``hidden'' states. However, we do have some noisy information about the states as each state emits observations according to a probability distribution that is characteristic of that state. We see the resulting emissions generated from the process and are not sure of the true underlying state of the Markov process at each given time point. Inferring information about the states of these processes and the probabilities that govern how such processes work has a wide range of applications, particularly for studying sequential data in which we are fairly certain the Markov property is satisfied.

In graphical model notation, an HMM is often represented as in Figure~\ref{fig:pgm}. This clearly shows that the HMM is a series of states with an observation (or emission) generated by each state. Only the emissions are observed and this is depicted by the shading of the respective nodes.

\begin{figure}[H]
\centering
\includegraphics[width=0.45\textwidth]{../figures/hmmTemplate.pdf}
\caption{General graphical model depiction of an HMM}
\label{fig:pgm}
\end{figure}

Sometimes, as in Figure~\ref{fig:gc}, you see an HMM depicted as its underlying Markov Process. Here, the emission probabilities are also shown. In this example we have a two-state HMM that models the GC content of a DNA sequence.

\begin{figure}[H]
\centering
\includegraphics[width=0.55\textwidth]{../figures/hmmGC.pdf}
\caption{Simple GC content HMM.}
\label{fig:gc}
\end{figure}

\subsection{What kind of data is well modeled by a HMM?}
Sequential data are well modeled by HMMs, especially when we are interested labeling sequence segments. Examples of these kinds of data are time series data and DNA sequence data.

\subsection{Well-known examples of HMMs in biology}

\begin{itemize}
\item Gene finding (GENSCAN: \url{http://genes.mit.edu/GENSCAN.html})
\item Modeling protein sequences and homologs (HMMER: \url{http://hmmer.janelia.org/})
\item Chromatin state annotation (ChromHMM: \url{http://compbio.mit.edu/ChromHMM/})
\end{itemize}

\section{Formal Definition of a HMM}
An HMM is defined by:
\begin{itemize}
\item A set of $s$ states.
\item An alphabet of $n$ possible emissions from each state.
\item A vector of length $s$ where the $i$th entry is the probability of starting in state $i$.
\item An $s\times s$ transition matrix $A$ where $a_{ij}$ is the probability of going from state $i$ to state $j$.
\item An $s \times n$ emission matrix $B$ where $b_{ij}$ is the probability that state $i$ emits symbol $j$.
\end{itemize}

The Markov assumption requires that the state at time $t$ depend only on the state at time $t-1$. We often also assume that the transition and emission probabilities are constant over time.

\section{Algorithms}

There are three main questions we generally want to answer when we have an HMM.

\begin{enumerate}
\item Given the model parameters, what is the probability of a particular observation sequence?
\item Given the model parameters, what is the most likely sequence of states that generated a particular observation sequence?
\item How can we learn the parameters of the model?
\end{enumerate}

The algorithm for each is described in the subsections below. We will use the following notation:

$Q = q_1q_2\cdots q_T$ is a sequence of states of length $T$\\
$O = O_1O_2\cdots O_T$ is an observation sequence of length $T$\\
$a_{q_iq_j}$ is the probability of going from state $q_i$ to state $q_j$\\
$b_{q_i}(O_j)$ is the probability that state $q_i$ emits symbol $O_j$\\
$\pi_{q_i}$ is the probability of starting in state $q_i$\\
$\lambda$ represents the model parameters, which includes both the emission and transition probabilities

\subsection{The Forward algorithm}

Finding the probability of an observation sequence given the model parameters can be found by summing the probability of seeing that sequence of observations for every possible sequence of states.
\begin{align*}
P(O|\lambda) &= \sum_{\textrm{all possible } Q} P(O,Q|\lambda)\\
&= \sum_{\textrm{all possible } Q} P(O|Q,\lambda)P(Q|\lambda)\\
&= \sum_{q_1q_2\cdots q_T}\pi_{q_1}b_{q_1}(O_1)a_{q_1q_2}b_{q_2}(O_2)\cdots
a_{q_{T-1}q_T}b_{q_T}(O_T)
\end{align*}

When calculating this quantity, you wouldn't want to actually sum over each of these $N^T$ possible state sequences. Many of the state sequences are similar and you can exploit this to calculate forward probabilities more efficiently.
\begin{itemize}
\item Define $\alpha_t(i) = P(O_1O_2\cdots O_t, q_t=S_i|\lambda)$.
\item Initialize $\alpha_1(i) = \pi_ib_i(O_1)$.
\item Then $\alpha_{t+1}(j) = \bigl[\sum_{i=1}^N \alpha_t(i)a_ij \bigr]b_j(O_{T+1})$.
\item Finally, $P(O|\lambda) = \sum_{i=1}^N\alpha_T(i)$
\end{itemize}

\subsection{The Viterbi Algorithm}

If we want the single most likely sequence of states we can do something similar to the forward algorithm, but instead of summing over all possible state sequences, we want the max. If you want the sequence of states and not just the max probability, you need to keep track of the states as you go and backtrack at the end to retrieve the sequence. See Rabiner tutorial for details.

%\begin{itemize}
%\item Define $\delta_t(i) = \textrm{max}_{q_1q_2\cdots q_{t-1}} P(q_1q_2\cdots q_t, O_1O_2\cdots O_t|\lambda)$.
%\item Initialize $\delta_1(i) = \pi_ib_i(O_1)$ and $\psi_1(i)=0$.
% need to adjust the part below
%\item Then $\alpha_{t+1}(j) = \bigl[\sum_{i=1}^N \alpha_t(i)a_ij \bigr]b_j(O_{T+1})$.
%\item Finally, $P(O|\lambda) = \sum_{i=1}^N\alpha_T(i)$
%\end{itemize}

\subsection{The Baum-Welch Algorithm}

This is the algorithm used to learn the parameters of an HMM given unlabeled training data.
It is a special case of the expectation-maximization (EM) algorithm. These types of algorithms work by iterating over two steps: the E-step and the M-step.

In the case of HMMs, if we knew the state that each emission came from, then we could easily infer the emission and transition probabilities (we will do this in Exercise 1). However, in the case of unlabeled data, we do not have this information. The idea is therefore to initialize the parameters with some values then find the most likely state assignment (E-step). With that assignment in hand, we now have labeled data and can use maximum likelihood estimation to update our estimates for the emission and transition parameter values (M-step). We keep iterating between the E- and M-steps until convergence. It is important to note that we may not arrive at an optimal solution. Different initializations of the parameter values can lead to different results.

The inference of the most likely sequence of states (E-Step) is done with the forward-backward algorithm, which returns a probability distribution over the states for each $t$. The backwards probabilities $\beta_t(i)$ are defined like the forwards probabilities $\alpha_t(i)$, but start at the end of the sequence. The probability of being in state $i$ at $t$ is $\frac{\alpha_t(i)\beta_t(i)}{\sum_j \alpha_t(j)\beta_t(j)}$. To use hard EM, you would select the single most likely state (i.e. the state with the highest assigned probability). A better idea is to use soft EM where you keep the soft assignments to states (i.e. the probability distribution).

%\subsection{Caveats}

\section{Exercise 1}
We will use the simple two-state HMM presented in Figure~\ref{fig:gc} for this example.
You have a sequence of observed emissions from this model and you also happen to know which state generated each emission (lucky you!).
Given these data, you will estimate the parameters of the HMM.

[Use starter code in exercise1.R]

\subsection{Estimate the emission probabilities for each of the two states}
\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|c|c|}
\hline
& A & T & G & C \\\hline
GC rich & & & &  \\\hline
not GC rich & & & & \\\hline
\end{tabular}
\end{table}

\subsection{Estimate the transition probabilities between states}
\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|}
\hline
& GC rich & not GC rich \\\hline
GC rich & &  \\\hline
not GC rich & &  \\\hline
\end{tabular}
\end{table}

How do these parameter estimates compare to the true parameters in Figure~\ref{fig:gc}?

\section{Exercise 2}
Consider an HMM of the same form as before, but this time the model parameters are different.
Again you observe a sequence of emissions.
However, this time the states are also unknown.
This time we will learn the parameters of the HMM without knowing the true sequence of states that generated the observations!

[Use starter code in exercise2.R]

\textit{Hint}: Think about how you want to initialize the algorithm for the parameter estimation.

\subsection{Estimate the parameters of the HMM}
Emission probabilities
\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|c|c|}
\hline
& A & T & G & C \\\hline
GC rich & & & &  \\\hline
not GC rich & & & & \\\hline
\end{tabular}
\end{table}

Transition probabilities
\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|}
\hline
& GC rich & not GC rich \\\hline
GC rich & &  \\\hline
not GC rich & &  \\\hline
\end{tabular}
\end{table}

\subsection{Predict the most likely state sequence using the parameters you just estimated}

\end{document}


\section{Data-analysis tips}\label{lab-4-data-analysis-tips}

In this mini-lab, you will be determining whether different kinds of
manipulations improve your ability to recall lists of words. Each
condition different subjects will read a list a words, and then recall
as many as they can on a sheet of paper. Then, you will measure recall
for each subject by counting the number of correctly recalled words. You
will try to get at least 10 subjects in each condition, the more the
merrier. The empirical question will be whether memory recall is differs
across the conditions. If they do differ, then some of those conditions
help you remember words better, and some conditions may hurt your
ability to remember words. With these kinds of experiments, we can learn
about the factors that influence our memory, as well as how cognitive
processes allow us to encode and retrieve memories.

The new tool you be using here is a one-way ANOVA, which you may
remember from your statistics classes. In particular, we will be
performing an independent samples ANOVA, because we are conducting a
between-subjects experiment, where different subjects contribute data in
each of the conditions. More specifically, we will be conducting an
omni-bus test. The omni-bus test is a catch-all test, that let's us
enter the data from as many conditions as we want, and ask the general
question: are any of the conditions different from one another. This is
different from a t-test, which only let's us make a comparison between
two conditions. In fact, the t-test and ANOVA are related, but this is a
topic that we will leave for now. Except to say, that if you ran a
t-test comparing two groups, or an ANOVA with only two groups, they
would return the same p-values, because they are testing the same
underlying question\ldots{}which is the likelihood the observed occurs
by chance alone.

One drawback about the ANOVA, is that it only tells us if there is some
difference, any difference, among the conditions we are comparing. But,
it does not tell us which specific conditions are different.
Fortunately, after we conduct the ANOVA, we can run follow-up t-tests
comparing any groups we want. We can also conduct more complex
comparisons using linear contrasts, but that is a topic for another day
as well.

We will again use to R to simulate a memory recall experiment with
multiple conditions. Then, we will create fake data, plot the data, then
analyze the data for differences using an ANOVA and follow-up tests.

\subsection{Simulating the data}\label{simulating-the-data}

Consider an experiment with five different memorizing conditions. This
will be a between-subjects experiment with 10 simulated subjects in each
condition. We will have condition A, B, C, D, and E. To simulate data
for each subject we need to make some assumptions. Let's that out of 30
words most people remember about 15 of them, but there is variation, so
some people do better and some people do worse. We can model this by
sampling numbers randomly from a distribution of our choice. For
convenience, we will use the normal distribution, which looks like
bell-curve (should be familiar from statistics class). Let's imagine
that condition A and B help memory more than C and D, and that memory is
worse in condition E. Take a look at the code and output for simulating
this kind of data.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{A<-}\KeywordTok{round}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{10}\NormalTok{,}\DecValTok{20}\NormalTok{,}\DecValTok{2}\NormalTok{))}
\NormalTok{B<-}\KeywordTok{round}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{10}\NormalTok{,}\DecValTok{20}\NormalTok{,}\DecValTok{2}\NormalTok{))}
\NormalTok{C<-}\KeywordTok{round}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{10}\NormalTok{,}\DecValTok{15}\NormalTok{,}\DecValTok{2}\NormalTok{))}
\NormalTok{D<-}\KeywordTok{round}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{10}\NormalTok{,}\DecValTok{15}\NormalTok{,}\DecValTok{2}\NormalTok{))}
\NormalTok{E<-}\KeywordTok{round}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{10}\NormalTok{,}\DecValTok{10}\NormalTok{,}\DecValTok{2}\NormalTok{))}
\NormalTok{all_data<-}\KeywordTok{data.frame}\NormalTok{(A,B,C,D,E)}
\KeywordTok{kable}\NormalTok{(all_data,}\DataTypeTok{format=}\StringTok{"latex"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{tabular}{r|r|r|r|r}
\hline
A & B & C & D & E\\
\hline
23 & 19 & 17 & 18 & 13\\
\hline
18 & 21 & 17 & 15 & 11\\
\hline
20 & 24 & 16 & 11 & 10\\
\hline
22 & 20 & 15 & 11 & 12\\
\hline
22 & 21 & 12 & 13 & 12\\
\hline
17 & 15 & 15 & 18 & 10\\
\hline
20 & 19 & 14 & 13 & 9\\
\hline
19 & 23 & 17 & 17 & 12\\
\hline
20 & 23 & 13 & 17 & 6\\
\hline
21 & 22 & 19 & 13 & 12\\
\hline
\end{tabular}

We have produced a table with fake data for 10 subjects in each
condition. The numbers all represent the number of correctly recalled
words for each simulated subject. For groups A and B we sample 10
numbers, from a distribution with mean 20, and standard deviation 2.
This is a higher mean than groups C and D (mean = 15). The lowest mean
was for Group E (mean = 10). So, on average, groups A and B should have
higher scores than C and D, which should be higher than E.

Ok, so what happened in our simulated experiment. We can see the numbers
in the table, but it would be nice to summarize them so we can more
easily look at differences. After all, it's hard to make sense of a
bunch of raw data in a table.

One way to summarize the data is to compute the group means for each
condition. This averages over the subjects, and gives us only 5 means to
look at, so it is easier to see the differences. We can ``easily'' do
this in R in a couple different ways. However, R often likes the data in
a particular format, in this case long-data format. So, we will first
convert to that format, and see what it looks like.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{long_data<-}\KeywordTok{data.frame}\NormalTok{(}\DataTypeTok{Conditions=}\KeywordTok{rep}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\StringTok{"A"}\NormalTok{,}\StringTok{"B"}\NormalTok{,}\StringTok{"C"}\NormalTok{,}\StringTok{"D"}\NormalTok{,}\StringTok{"E"}\NormalTok{),}\DataTypeTok{each=}\DecValTok{10}\NormalTok{),}
                      \DataTypeTok{Recall=}\KeywordTok{c}\NormalTok{(A,B,C,D,E))}
\KeywordTok{kable}\NormalTok{(long_data[}\DecValTok{1}\NormalTok{:}\DecValTok{25}\NormalTok{,],}\DataTypeTok{format=}\StringTok{"latex"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{tabular}{l|r}
\hline
Conditions & Recall\\
\hline
A & 23\\
\hline
A & 18\\
\hline
A & 20\\
\hline
A & 22\\
\hline
A & 22\\
\hline
A & 17\\
\hline
A & 20\\
\hline
A & 19\\
\hline
A & 20\\
\hline
A & 21\\
\hline
B & 19\\
\hline
B & 21\\
\hline
B & 24\\
\hline
B & 20\\
\hline
B & 21\\
\hline
B & 15\\
\hline
B & 19\\
\hline
B & 23\\
\hline
B & 23\\
\hline
B & 22\\
\hline
C & 17\\
\hline
C & 17\\
\hline
C & 16\\
\hline
C & 15\\
\hline
C & 12\\
\hline
\end{tabular}

I've only printed the first 25 lines, but the dataframe contains all of
the data for conditions, C, D, and E as well. You can see why they call
it long format. It's because each data point gets it's own row in the
table.

\subsection{Looking at the means}\label{looking-at-the-means}

Now that the data is in long format we can easily make a table of the
condition means

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{condition_means<-}\KeywordTok{aggregate}\NormalTok{(Recall~Conditions,long_data,mean)}
\KeywordTok{kable}\NormalTok{(condition_means,}\DataTypeTok{format=}\StringTok{"latex"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{tabular}{l|r}
\hline
Conditions & Recall\\
\hline
A & 20.2\\
\hline
B & 20.7\\
\hline
C & 15.5\\
\hline
D & 14.6\\
\hline
E & 10.7\\
\hline
\end{tabular}

We can now see the group means, but we can't see any measure of how
variable the data are in each condition. We might, for example, also
want to compute the standard deviation as well as the mean, and put them
both in the table. We could run the same code from above and substite sd
for mean, which would give us a table of standard deviations. However,
we will use a more advanced function from the plyr package, called
ddply. ddply let's you compute multiple statistics and put them all in a
single table. The syntax is a bit different, but it doesn't take long to
get used to it.

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{library}\NormalTok{(plyr)}
\NormalTok{condition_means<-}\KeywordTok{ddply}\NormalTok{(long_data,.(Conditions),summarise,}
                       \DataTypeTok{MeanRecall=}\KeywordTok{mean}\NormalTok{(Recall),}
                       \DataTypeTok{StdDeviation=}\KeywordTok{sd}\NormalTok{(Recall))}
\KeywordTok{kable}\NormalTok{(condition_means,}\DataTypeTok{format=}\StringTok{"latex"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{tabular}{l|r|r}
\hline
Conditions & MeanRecall & StdDeviation\\
\hline
A & 20.2 & 1.873796\\
\hline
B & 20.7 & 2.626785\\
\hline
C & 15.5 & 2.121320\\
\hline
D & 14.6 & 2.756810\\
\hline
E & 10.7 & 2.057507\\
\hline
\end{tabular}

\subsection{Plotting the data}\label{plotting-the-data}

It's often very desirable to plot the data in a graph, rather than just
present the means in a table. People find it easier to look at graphs,
because the differences in the data just pop-out much easier than
looking at numbers in a table. R has a fantastic graphing package called
ggplot2. ggplot2 is a whole philosophy for visual design and
data-presentation, and it can be daunting at first. But, it's complexity
makes it very powerful, and when you get the hang of it you can very
quickly make all sorts of beautiful graphs to present data. Here is some
code to make ggplot create a bar graph to plot the means, along with
error bars. In this case the error bars with represent standard errors
of the mean, rather than standard deviations. R does not have a built in
function for the standard error of the mean, so we have to write it
ourselves.

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{library}\NormalTok{(ggplot2)}
\NormalTok{sde<-function(x)\{}\KeywordTok{sd}\NormalTok{(x)/}\KeywordTok{length}\NormalTok{(x)\}}
\NormalTok{plot_means<-}\KeywordTok{ddply}\NormalTok{(long_data,.(Conditions),summarise,}
                       \DataTypeTok{MeanRecall=}\KeywordTok{mean}\NormalTok{(Recall),}
                       \DataTypeTok{SE=}\KeywordTok{sde}\NormalTok{(Recall))}

\NormalTok{limits <-}\StringTok{ }\KeywordTok{aes}\NormalTok{(}\DataTypeTok{ymax =} \NormalTok{MeanRecall +}\StringTok{ }\NormalTok{SE, }\DataTypeTok{ymin =} \NormalTok{MeanRecall -}\StringTok{ }\NormalTok{SE)}

\KeywordTok{ggplot}\NormalTok{(plot_means,}\KeywordTok{aes}\NormalTok{(}\DataTypeTok{x=}\NormalTok{Conditions, }\DataTypeTok{y=}\NormalTok{MeanRecall))+}
\StringTok{  }\KeywordTok{geom_bar}\NormalTok{(}\DataTypeTok{position=}\StringTok{"dodge"}\NormalTok{,}\DataTypeTok{stat=}\StringTok{"identity"}\NormalTok{)+}
\StringTok{  }\KeywordTok{geom_errorbar}\NormalTok{(limits, }\DataTypeTok{width=}\NormalTok{.}\DecValTok{1}\NormalTok{)+}
\StringTok{  }\KeywordTok{theme_classic}\NormalTok{(}\DataTypeTok{base_size=}\DecValTok{12}\NormalTok{)+}
\StringTok{  }\KeywordTok{ylab}\NormalTok{(}\StringTok{"Mean Correctly }\CharTok{\textbackslash{}n}\StringTok{ Recalled Words"}\NormalTok{)+}
\StringTok{  }\KeywordTok{xlab}\NormalTok{(}\StringTok{"Condition"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\includegraphics{Lab4_files/figure-latex/unnamed-chunk-5-1}

Now it is easy to the differences between conditions. Just as we had
hoped, Groups A and B appear to have recalled more words than Groups C
and D, which remembered more words than group E.

\subsection{Conducting the ANOVA}\label{conducting-the-anova}

Although the graph and the tabe show some clear differences in the
means, we still want to find out the probability that this kind of
finding occurs by chance alone. We can be confident in the differences
when we know that they do not occur very often by chance alone. The
first step is conduct a one-way ANOVA. This is very easy in R.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{aov.out<-}\KeywordTok{aov}\NormalTok{(Recall~Conditions,long_data)}
\end{Highlighting}
\end{Shaded}

We're done! It's only one line of code. However, we need a couple more
to see the results.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{aov_summary<-}\KeywordTok{summary}\NormalTok{(aov.out)}
\KeywordTok{kable}\NormalTok{(}\KeywordTok{xtable}\NormalTok{(aov_summary),}\DataTypeTok{format=}\StringTok{"latex"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{tabular}{l|r|r|r|r|r}
\hline
  & Df & Sum Sq & Mean Sq & F value & Pr(>F)\\
\hline
Conditions & 4 & 694.52 & 173.630000 & 32.46095 & 0\\
\hline
Residuals & 45 & 240.70 & 5.348889 & NA & NA\\
\hline
\end{tabular}

The ANOVA table gives us a bunch of information. We will go into much
greater detail about the meaning of each number in the table, but also
assume for now that you are somewhat familiar with these ideas because
you have already taken statistics, right?

We are mainly interested in the p-value, which tells how often results
like the ones we found can occur by chance. But, when we report the
results of our ANOVA, we also provide additional information about the
F-value, the degrees of freedom values, and the mean squared error term.
The reason is that if you know these numbers, you can actually
reconstruct all of the other numbers. The results of our ANOVA are
significant. You could report this in a sentence like the following.

The main effect of condition was significant, F(4, 45) = 32.46, MSE =
5.35, p \textless{} .001.

\subsection{Comparisons between
conditions}\label{comparisons-between-conditions}

The p-value from above is much smaller than .05, which shows the
difference between conditions in the data does not occur very often by
chance alone. However, because we conducted an omni-bus test, we only
know that there is some difference between conditions, but we do not
know which specific conditions are different from one another.

So, we have to conduct additional tests between specific conditions.
There are multiple strategies for conducting these tests. For now, we
will simply run t-tests between comparisons of interest.

Remember, our data simulated the pattern that memory recall would be
better for groups A and B, which would be better than groups C and D,
which would better than group E. In other words A=B \textgreater{} C=D
\textgreater{} E.

We can confirm this pattern by conducting tests to see if it holds up.
For example, how would we test the pattern A=B \textgreater{} C=D
\textgreater{} E, all of the following comparisons need to be true,

\begin{itemize}
\item
  A = B
\item
  A \textgreater{} C
\item
  A \textgreater{} D
\item
  B \textgreater{} C
\item
  B \textgreater{} D
\item
  C = D
\end{itemize}

and, all of the conditions should be greater than E

\begin{itemize}
\item
  A \textgreater{} E
\item
  B \textgreater{} E
\item
  C \textgreater{} E
\item
  D \textgreater{} E
\end{itemize}

Let's conduct a few of these tests, and then report the findings.

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{library}\NormalTok{(broom)}
\CommentTok{#conduct t-tests}
\NormalTok{ab<-}\KeywordTok{tidy}\NormalTok{(}\KeywordTok{t.test}\NormalTok{(A,B,}\DataTypeTok{var.equal =} \OtherTok{TRUE}\NormalTok{))}
\NormalTok{ac<-}\KeywordTok{tidy}\NormalTok{(}\KeywordTok{t.test}\NormalTok{(A,C,}\DataTypeTok{var.equal =} \OtherTok{TRUE}\NormalTok{))}
\NormalTok{cd<-}\KeywordTok{tidy}\NormalTok{(}\KeywordTok{t.test}\NormalTok{(C,D,}\DataTypeTok{var.equal =} \OtherTok{TRUE}\NormalTok{))}
\NormalTok{de<-}\KeywordTok{tidy}\NormalTok{(}\KeywordTok{t.test}\NormalTok{(D,E,}\DataTypeTok{var.equal =} \OtherTok{TRUE}\NormalTok{))}

\CommentTok{#put the results in a table}
\NormalTok{alltests<-}\KeywordTok{rbind}\NormalTok{(ab,ac,cd,de)}
\NormalTok{alltests<-}\KeywordTok{cbind}\NormalTok{(alltests,}\DataTypeTok{Comparison=}\KeywordTok{c}\NormalTok{(}\StringTok{"AB"}\NormalTok{,}\StringTok{"AC"}\NormalTok{,}\StringTok{"CD"}\NormalTok{,}\StringTok{"DE"}\NormalTok{))}
\NormalTok{finaltable <-}\StringTok{ }\KeywordTok{subset}\NormalTok{(alltests, }\DataTypeTok{select =} \KeywordTok{c}\NormalTok{(Comparison,estimate1,estimate2,statistic,p.value,parameter))}
\KeywordTok{kable}\NormalTok{(finaltable,}\DataTypeTok{format=}\StringTok{"latex"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{tabular}{l|r|r|r|r|r}
\hline
Comparison & estimate1 & estimate2 & statistic & p.value & parameter\\
\hline
AB & 20.2 & 20.7 & -0.4900286 & 0.6300329 & 18\\
\hline
AC & 20.2 & 15.5 & 5.2511144 & 0.0000541 & 18\\
\hline
CD & 15.5 & 14.6 & 0.8181818 & 0.4239528 & 18\\
\hline
DE & 14.6 & 10.7 & 3.5851808 & 0.0021158 & 18\\
\hline
\end{tabular}

\subsection{Writing it all up}\label{writing-it-all-up}

The following is an example results section for our hypothetical
experiment. This could serve as a model for your own results section.

The number of correctly recalled words for each subject in each
condition were submitted to a one-way ANOVA, with memorization condition
(A, B, C, D, and E) as the sole between-subjects factor. Mean recall
scores in each condition are displayed in Figure 1.

The main effect of memorization condition was significant, F(4, 45) =
32.46, MSE = 5.35, p \textless{} .001. Figure 1 shows that Groups A and
B had higher recall scores than Groups C and D, which had higher recall
scores than Group E. This pattern was confirmed across four independent
sample t-tests. Group A (M = 20.2) and Group B (M = 20.7) were not
significantly different t(18) = -0.49, p =0.63. Group A recalled
significantly more words than Group C (M = 15.5), t(18) = 5.25, p =0.
Group C and Group D (M = 14.6) were not significantly different t(18) =
0.82, p =0.424. Finally, Group D recalled significantly more words than
Group E (M = 10.7), t(18) = 3.59, p =0.002.