\documentclass[12pt]{article}
\usepackage{fancyhdr}
\usepackage{color}
\usepackage{multicol}
\usepackage{enumitem}
\usepackage{graphicx}
\usepackage{sectsty}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage{array}
\newcommand{\sectionbreak}{\clearpage}

\usepackage{tikz}
	\usetikzlibrary{arrows,shapes,trees}
	\usetikzlibrary{calc}

\usepackage{pgfplots}
	\usepgfplotslibrary{polar}
\usepgflibrary{shapes.geometric}

\usepackage{tkz-euclide}
\usetkzobj{all}

\allsectionsfont{\centering}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[makestderr]{pythontex}

\usepackage[margin=1in, headsep=0pt]{geometry}
\setlength{\parindent}{0cm}
\pagestyle{empty}

\begin{document}

Mr. Wolf\\
wolf-math.com

\section*{General Angles, Radian Measure, and The Unit Circle}

\subsection*{Goals}

\textbf{I will be able to} define general angles.\\

\textbf{I will be able to} convert from degrees to radians.\\

\textbf{I will be able to} evaluate trigonometric functions of any angle.\\

\textbf{I will be able to} use the unit circle.\\

\textbf{I will be able to} identify all of the reference angles and use them to my benefit.\\

%\textbf{I will be able to} use and manitpulate trigonometric identities.\\

%\textbf{I will be able to} graph periodic trig functions.\\

\subsection*{Standards}

\textbf{Trigonometric Functions 	\hfill F-TF}\\

\textbf{Extend the domain of trigonometric functions using the unit circle}\\

\begin{enumerate}

\item Understand radian measure of an angle as the length of the arc on the
unit circle subtended by the angle.

\item Explain how the unit circle in the coordinate plane enables the
extension of trigonometric functions to all real numbers, interpreted as
radian measures of angles traversed counterclockwise around the unit
circle.

\item (+) Use special triangles to determine geometrically the values of sine,
cosine, tangent for $\frac{\pi}{3}$, $\frac{\pi}{4}$ and $\frac{\pi}{6}$, and use the unit circle to express
the values of sine, cosines, and tangent for $x$, $π+x$, and $2π–x$ in terms of
their values for $x$, where $x$ is any real number.

\item (+) Use the unit circle to explain symmetry (odd and even) and
periodicity of trigonometric functions.

\end{enumerate}

\textbf{Model periodic phenomena with trigonometric functions}\\

\begin{enumerate}[resume]

\item Choose trigonometric functions to model periodic phenomena with
specified amplitude, frequency, and midline. ★

\item (+) Understand that restricting a trigonometric function to a domain
on which it is always increasing or always decreasing allows its inverse
to be constructed.

\item (+) Use inverse functions to solve trigonometric equations that arise
in modeling contexts; evaluate the solutions using technology, and
interpret them in terms of the context. ★\\

\end{enumerate}

\textbf{Prove and apply trigonometric identities}\\

\begin{enumerate}[resume]

\item Prove the Pythagorean identity $\sin^2(\theta) + cos^2 (\theta) = 1$ and use it to calculate trigonometric ratios.

\item (+) Prove the addition and subtraction formulas for sine, cosine, and tangent and use them to solve problems.

\end{enumerate}

\subsection*{Connections}

\textbf{Before} we learned about how trigonometry applied to triangles, and general graphing of circles.\\

\textbf{Now} we are learning about trigonometry on the coordinate plane and circles.\\

\textbf{Later} we will learn about graphing periodic trigonometric functions.\\

\let\stdsection\section
\renewcommand\section{\newpage\stdsection}

\section*{General Angles}

Putting trig on the coordinate plane is called \textit{analytic geometry}. The starting point on the coordinate plane in the \textit{origin}, where the \textit{x-axis} and \textit{y-axis} meet $(0,0)$. The rotation starts from the right side of the \textit{x-axis} and opens counter-clockwise.\\

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

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);
	\coordinate (e) at (0,0);
	\draw[line width=2pt, <->](a) -- (b);
	\draw[line width=2pt, <->](c) -- (d);
%	\draw[blue,line width=2pt, ->] (0,0) -- (.8,0);
	\node at (0,1.4) {$y$};
	\node at (0,1.2) {$90^\circ$};
	\node at (1.4,0) {$x$};
	\node at (1.2,0) {$0^\circ$};
	\node at (-1.2,0) {$180^\circ$};
	\node at (0,-1.2) {$270^\circ$};
	\node at (.5,.5) {I};
	\node at (-.5,.5) {II};
	\node at (-.5,-.5){III};
	\node at (.5,-.5) {IV};

	\end{tikzpicture}
\end{center}

The \textit{initial side} comes from the origin along the \textit{x-axis} towards the right (positives). The \textit{terminal side} is drawn \textbf{counter-clockwise} around the origin. The angle is between the initial side and the terminal side. \\

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

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);
	\coordinate (e) at (0,0);
	\coordinate (f) at (-.5,.866);
	\draw[line width=2pt, <->](a) -- (b);
	\draw[line width=2pt, <->](c) -- (d);
	\draw[red, line width=2pt, ->] (e) -- (f);
	\draw[blue, line width=2pt, ->] (e) -- (.8,0);
	\draw[green, line width=2pt](.65,0)arc[radius=.65, start angle=0, end angle= 120];
	\node at (0,1.4) {$y$};
	\node at (0,1.2) {$90^\circ$};
	\node at (1.4,0) {$x$};
	\node at (1.2,0) {$0^\circ$};
	\node at (-1.2,0) {$180^\circ$};
	\node at (0,-1.2) {$270^\circ$};
	\node[blue] at (.5,-.2) {initial side};
	\node[red] at (-.9,.4) {terminal side};

	\end{tikzpicture}
\end{center}

This is called \textbf{Standard Position} of an angle.\\

\pagebreak

\subsection*{Standard Position}

\begin{multicols}{2}

\textbf{Example 1) } Approximate the angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=3]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);
	\coordinate (e) at (0,0);
	\coordinate (f) at (.5,0.866);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);
	\draw[red, line width=2pt, ->] (e) -- (f);
	\draw[blue, line width=2pt, ->] (0,0) -- (.9,0);

	\end{tikzpicture}

\columnbreak

\textbf{Example 2)} Draw a $210^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=3]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}
\end{multicols}

\vspace{32pt}

\textbf{You Try:}

\begin{multicols}{2}

Approximate the angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=3]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);
	\coordinate (e) at (0,0);
	\coordinate (f) at (-.85,0.85);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);
	\draw[red, line width=2pt,->] (e) -- (f);
	\draw[blue, line width=2pt, ->] (0,0) -- (.9,0);

	\end{tikzpicture}

\columnbreak

Draw a $100^\circ$ angle.\\

\vspace{12pt}

	\begin{tikzpicture}[scale=3]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}
\end{multicols}

\pagebreak

\subsection*{Negative Angles}

A negative angle will go \textit{clockwise} instead of \textit{counter-clockwise}\\

\begin{multicols}{2}

\textbf{Example 3)} Approximate the angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=3]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);
	\coordinate (e) at (0,0);
	\coordinate (f) at (.866,-0.5);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);
	\draw[red,line width=2pt,->] (e) -- (f);
	\draw[blue, line width=2pt, ->] (0,0) -- (.9,0);

	\end{tikzpicture}

\columnbreak

\textbf{Example 4)} Draw a $-100^\circ$ angle;

\vspace{12pt}

	\begin{tikzpicture}[scale=3]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}
\end{multicols}

\vspace{32pt}

\textbf{You Try:}

\begin{multicols}{2}

Approximate the angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=3]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);
	\coordinate (e) at (0,0);
	\coordinate (f) at (-.707,0.707);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);
	\draw[red,line width=2pt,->] (e) -- (f);
	\draw[blue, line width=2pt, ->] (0,0) -- (.9,0);

	\end{tikzpicture}

\columnbreak

Draw a $-80^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=3]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}
\end{multicols}

\pagebreak

\subsection*{Co-Terminal Angles}

Two angles with the same terminal side are called \textbf{co-terminal angles}. ($0^\circ = 360^\circ$ or $90^\circ=-270^\circ$)\\

\begin{multicols}{2}

\textbf{Example 5)} Two ways to write the angle.\\

\vspace{12pt}

	\begin{tikzpicture}[scale=3]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);
	\coordinate (e) at (0,0);
	\coordinate (f) at (.707,0.707);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);
	\draw[red,line width=2pt,->] (e) -- (f);
	\draw[blue, line width=2pt, ->] (0,0) -- (.9,0);

	\end{tikzpicture}

\columnbreak

\textbf{Example 6)} What is coterminal to $210^\circ$?\\

\vspace{12pt}

	\begin{tikzpicture}[scale=3]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}
\end{multicols}

\vspace{32pt}

\textbf{You Try:}\\

\begin{multicols}{2}

Two ways to write the angle.\\

\vspace{12pt}

	\begin{tikzpicture}[scale=3]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);
	\coordinate (e) at (0,0);
	\coordinate (f) at (.707,-0.707);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);
	\draw[red,line width=2pt,->] (e) -- (f);
	\draw[blue, line width=2pt, ->] (0,0) -- (.9,0);

	\end{tikzpicture}

\columnbreak

What is coterminal to $500^\circ$?\\

\vspace{12pt}

	\begin{tikzpicture}[scale=3]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}
\end{multicols}

\section*{Radians}

There are two main ways to measure angles. The first one that you know is called \textit{degree angle measure}. The new type that we're learning is called \textit{radian angle measure} (which is what ''rad'' stands for on your calculator).\\

The circumference of a circle is $2\pi r$. So a circle with a radius of $1$ has a circumference of $2\pi$.

$$360^\circ = 2\pi  \text{ radians} \hspace{1in} \pi \text{ radians}=180^\circ$$

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

%	\draw[thick] (0,0)circle[radius=.9];
	\draw[thick, <->] (1.1,0) -- (-1.1,0);
	\draw[thick, <->] (0,1.1) -- (0,-1.1);
	\node at (1.2,0) {$x$};
	\node at (0,1.2){$y$};
	\node at (.5,-.1){$r=1$};
	\draw[line width=2pt,teal](1,0) arc [radius=1,start angle=0,end angle=90];
	\draw[line width=2pt,blue] (.95,0) arc [radius=.95,start angle=0, end angle=180];
	\draw[line width=2pt,red] (.9,0) arc[radius=.9,start angle=0, end angle=270];
	\draw[line width=2pt,violet] circle[radius=.85];
	\node[blue] at (-1,.8){$\pi$ radians};
	\node[violet] at (1,-.8){$2\pi$ radians};
	\node[teal] at (1,.8){$\frac{\pi}{2}$ radians};
	\node[red] at (-1,-.7){$\frac{3\pi}{2}$ radians};

\end{tikzpicture}
\end{center}

To convert from degree to radian $\times \frac{\pi}{180}$\\

\vspace{12pt}

To convert from radian to degree $\times \frac{180}{\pi}$\\

\begin{multicols}{2}
\begin{enumerate}
	\setlength\itemsep{24pt}

	\item $190^\circ$ is how many radians?\\

	\item 2 radians is how many degrees?\\

	\item $270^\circ$ is how many radians?\\

	\item $\frac{\pi}{6}$ radians is how many degrees?\\

	\item $45^\circ$ is how many radians?\\

	\item $\frac{\pi}{3}$ is how many degrees?\\

	\item $100^\circ$ is how many radians?\\

	\item $\frac{3\pi}{2}$ is how many degrees?\\

\end{enumerate}
\end{multicols}

\section{Practice}

Draw a $\frac{3\pi}{4}$ radians\\
\begin{tikzpicture}[scale=3]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Draw a $-\frac{5\pi}{6}$ radians\\
\begin{tikzpicture}[scale=3]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Find the angle between $0$ and $2\pi$ that is coterminal to $-\frac{23\pi}{10}$

\section*{Tips on Radians}

\subsection*{Multiples of $90^\circ$}

\begin{multicols}{2}

$90^\circ=\frac{\pi}{2}$ radians \\

$180^\circ=\frac{2\pi}{2}$ radians $=\pi$ radians \\

$270^\circ=\frac{3\pi}{2}$ radians \\

 $360^\circ=\frac{4\pi}{2}$ radians $=2\pi$ radians\\

\end{multicols}

\subsection*{Multiples of $60^\circ$}

\begin{multicols}{2}

$60^\circ=\frac{\pi}{3}$ radians \\

$120^\circ=\frac{2\pi}{3}$ radians \\

$180^\circ=\frac{3\pi}{3}$ radians $=\pi$ radians \\

$240^\circ=\frac{4\pi}{3}$ radians \\

$300^\circ=\frac{5\pi}{3}$ radians \\

$360^\circ=\frac{6\pi}{3}$ radians $=2\pi$ radians \\

\end{multicols}

\subsection*{Multiples of $45^\circ$}

\begin{multicols}{2}
$45^\circ=\frac{\pi}{4}$ radians \\

$90^\circ=\frac{2\pi}{4}$ radians $=\frac{\pi}{2}$ radians \\

$135^\circ=\frac{3\pi}{4}$ radians \\

$180^\circ=\frac{4\pi}{4}$ radians $=\pi$ radians \\

$225^\circ=\frac{5\pi}{4}$ radians \\

$270^\circ=\frac{6\pi}{4}$ radians $=\frac{3\pi}{2}$ radians \\

$315^\circ=\frac{7\pi}{4}$ radians \\

$360^\circ=\frac{8\pi}{4}$ radians $=2\pi$ radians \\
\end{multicols}

\subsection*{Multiples of $30^\circ$}

\begin{multicols}{2}

$30^\circ=\frac{\pi}{6}$ radians \\

$30^\circ=\frac{2\pi}{6}$ radians $=\frac{\pi}{3}$ radians \\

$90^\circ=\frac{3\pi}{6}$ radians $=\frac{\pi}{2}$ radians \\

$120^\circ=\frac{4\pi}{6}$ radians $=\frac{2\pi}{3}$ radians \\

$150^\circ=\frac{5\pi}{6}$ radians \\

$180^\circ=\frac{6\pi}{6}$ radians $=\pi$ radians \\

$210^\circ=\frac{7\pi}{6}$ radians \\

$240^\circ=\frac{8\pi}{6}$ radians $=\frac{4\pi}{3}$ radians \\

$270^\circ=\frac{9\pi}{6}$ radians $=\frac{3\pi}{2}$ radians \\

$300^\circ=\frac{10\pi}{6}$ radians $=\frac{5\pi}{3}$ radians \\

 $330^\circ=\frac{11\pi}{6}$ radians\\

$360^\circ=\frac{12\pi}{6}$ radians $=2\pi$ radians \\

\end{multicols}

\section*{Evaluating Trig Functions of Any Angle \\ Extending the Trig Ratios}

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

	\draw[line width=1pt] (0,0) circle[radius=1];
	\draw[line width=2pt,<->] (0,1.1) -- (0,-1.1);
	\draw[line width=2pt,<->] (1.1,0) -- (-1.1,0);
	\draw[red, line width=2pt,->] (0,0) -- (1,0);
	\draw[red,line width=2pt, ->] (0,0) -- (0.64278761,0.766044443);
	\draw[line width=1pt] (0.64278761,0.766044443) -- (0.64278761,0);
%	\draw[fill](0.64278761,0.766044443)circle[radius=.04];
	\node at (.9,0.76604443){$(x,y)$};
	\node at (.3,.5){$r$};
	\node at (.3,-.1){$x$};
	\node at (.7,.4){$y$};

	\coordinate (a) at (1,0);
	\coordinate (b) at (0,0);
	\coordinate (c) at (0,1);
	\coordinate (d) at (0.64278761,0.766044443);
	\coordinate (e) at (0.64278761,0);
	\tkzMarkRightAngle[size=.1](b,e,d)
	\tkzLabelAngle[pos=.15](a,b,d){$\theta$}

\end{tikzpicture}
\end{center}

$$\sin(\theta)=\frac{y}{r}$$

$$\cos(\theta)=\frac{x}{r}$$

$$\tan(\theta)=\frac{y}{x}$$

\hrulefill

Use the Pythagorean Theorem to find $r$, $r=$\\

\begin{multicols}{2}

\begin{center}
\begin{tikzpicture}[scale=.7]

	\draw[line width=1pt] (0,0) circle[radius=5];
	\draw[line width=2pt,<->] (0,5.5) -- (0,-5.5); %y-axis
	\draw[line width=2pt,<->] (5.5,0) -- (-5.5,0); %x-axis
	\draw[red, line width=2pt,->] (0,0) -- (5,0); %initial side
	\draw[red,line width=2pt, ->] (0,0) -- (-4,3); %terminal side
	\draw[line width=1pt] (-4,3) -- (-4,0);
	\node at (-5,3.2){$(-4,3)$};
	\node at (-2.2,2.3){$r$};
	\node at (-2,-.5){$-4$};
	\node at (-4.3,1.3){$3$};

	\draw[line width=2pt,blue,->] (5,0) arc[radius=5,start angle=0, end angle=143.1301024];

	\coordinate (a) at (5,0);
	\coordinate (b) at (0,0);
	\coordinate (c) at (0,5);
	\coordinate (d) at (-4,3);
	\coordinate (e) at (-4,0);
	\tkzMarkRightAngle[size=.8](b,e,d)
	\tkzLabelAngle[pos=1.3](a,b,d){$\theta$}
	\tkzMarkAngle(a,b,d)

\end{tikzpicture}
\end{center}
\columnbreak

$$x=-4 , y=3, r=5$$

$$\sin(\theta)=\frac{\hspace{.5cm}}{}$$

$$\cos(\theta)=\frac{\hspace{.5cm}}{}$$

$$\tan(\theta)=\frac{\hspace{.5cm}}{}$$

\end{multicols}

\pagebreak

Use the Pythagorean Theorem to find $r$, $r=$\\

\begin{multicols}{2}

\begin{center} %Make this one Quadrant 3
\begin{tikzpicture}[scale=.25]

	\draw[line width=1pt] (0,0) circle[radius=13];
	\draw[line width=2pt,<->] (0,14) -- (0,-14); %y-axis
	\draw[line width=2pt,<->] (14,0) -- (-14,0); %x-axis
	\draw[red, line width=2pt,->] (0,0) -- (13,0); %initial side
	\draw[red,line width=2pt, ->] (0,0) -- (-12,-5); %terminal side
	\draw[line width=1pt] (-12,-5) -- (-12,0);
	\node at (-16,-6){$(-12,-5)$};
	\draw[line width=2pt,blue,->] (13,0) arc[radius=13,start angle=0, end angle=204.6243184];

	\coordinate (a) at (5,0);
	\coordinate (b) at (0,0);
	\coordinate (c) at (0,5);
	\coordinate (d) at (-12,-5);
	\coordinate (e) at (-12,0);
	\tkzMarkRightAngle[size=1.2](b,e,d)
	\tkzLabelAngle[pos=-3](a,b,d){$\theta$}
	\tkzMarkAngle[size=2](a,b,d)

\end{tikzpicture}
\end{center}
\columnbreak

$$x=\underline{\hspace{1cm}} , y=\underline{\hspace{1cm}}, r=\underline{\hspace{1cm}}$$

$$\sin(\theta)=\frac{y}{r}=$$

$$\cos(\theta)=\frac{x}{r}=$$

$$\tan(\theta)=\frac{y}{x}=$$

$$\theta = ?$$
\end{multicols}

\hrulefill

Use the Pythagorean Theorem to find $r$, $r=$\\

\begin{multicols}{2} %Make this one Quadrant 4

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

	\draw[line width=1pt] (0,0) circle[radius=2];
	\draw[line width=2pt,<->] (0,2.5) -- (0,-2.5); %y-axis
	\draw[line width=2pt,<->] (2.5,0) -- (-2.5,0); %x-axis
	\draw[red, line width=2pt,->] (0,0) -- (2,0); %initial side
	\draw[red,line width=2pt, ->] (0,0) -- (1,-1.732050808); %terminal side
	\draw[line width=1pt] (1,-1.732050808) -- (1,0);
	\node at (1.5,-2){$(1,\sqrt{3})$};

	\draw[line width=2pt,blue,->] (2,0) arc[radius=2,start angle=0, end angle=300];

	\coordinate (a) at (2,0);
	\coordinate (b) at (0,0);
	\coordinate (c) at (0,2);
	\coordinate (d) at (1,-1.732050808);
	\coordinate (e) at (1,0);
	\tkzMarkRightAngle[size=.2](b,e,d)
	\tkzLabelAngle[pos=-.9](a,b,d){$\theta$}
	\tkzMarkAngle[size=.5](a,b,d)

\end{tikzpicture}
\end{center}
\columnbreak

$$x=\underline{\hspace{1cm}} , y=\underline{\hspace{1cm}}, r=\underline{\hspace{1cm}}$$

$$\sin(\theta)=$$

$$\cos(\theta)=$$

$$\tan(\theta)=$$

\end{multicols}

\section*{The Unit Circle}

The unit circle is a circle whose radius is 1 and has a center about the origin. The values of $\sin(\theta)$ and $\cos(\theta)$ are just the $y$-values and $x$-values respectively. \\

%$$(\cos\theta,\sin\theta)$$

% based on http://www.texample.net/tikz/examples/unit-circle/
%
    \begin{tikzpicture}[scale=5.3,cap=round,>=latex]
        % draw the coordinates
        \draw[->] (-1.5cm,0cm) -- (1.5cm,0cm) node[right,fill=white] {$x$};
        \draw[->] (0cm,-1.5cm) -- (0cm,1.5cm) node[above,fill=white] {$y$};

        % draw the unit circle
        \draw[thick] (0cm,0cm) circle(1cm);

        \foreach \x in {0,30,...,360} {
                % lines from center to point
                \draw[gray] (0cm,0cm) -- (\x:1cm);
                % dots at each point
                \filldraw[black] (\x:1cm) circle(0.4pt);
                % draw each angle in degrees
                \draw (\x:0.6cm) node[fill=white] {$\x^\circ$};
        }

		\foreach \x in {45,135,225,315}{
				\draw[gray](0cm,0cm) -- (\x:1cm);
				\filldraw[black] (\x:1cm) circle(0.4pt);
				\draw (\x:0.6cm) node[fill=white] {$\x^\circ$};
		}

        % draw each angle in radians
        \foreach \x/\xtext in {
            30/\frac{\pi}{6},
            45/\frac{\pi}{4},
            60/\frac{\pi}{3},
            90/\frac{\pi}{2},
            120/\frac{2\pi}{3},
            135/\frac{3\pi}{4},
            150/\frac{5\pi}{6},
            180/\pi,
            210/\frac{7\pi}{6},
            225/\frac{5\pi}{4},
            240/\frac{4\pi}{3},
            270/\frac{3\pi}{2},
            300/\frac{5\pi}{3},
            315/\frac{7\pi}{4},
            330/\frac{11\pi}{6},
            360/2\pi}
                \draw (\x:0.85cm) node[fill=white] {$\xtext$};

        \foreach \x/\xtext/\y in {
            % the coordinates for the first quadrant
            30/\frac{\sqrt{3}}{2}/\frac{1}{2},
            45/\frac{\sqrt{2}}{2}/\frac{\sqrt{2}}{2},
            60/\frac{1}{2}/\frac{\sqrt{3}}{2},
            % the coordinates for the second quadrant
            150/-\frac{\sqrt{3}}{2}/\frac{1}{2},
            135/-\frac{\sqrt{2}}{2}/\frac{\sqrt{2}}{2},
            120/-\frac{1}{2}/\frac{\sqrt{3}}{2},
            % the coordinates for the third quadrant
            210/-\frac{\sqrt{3}}{2}/-\frac{1}{2},
            225/-\frac{\sqrt{2}}{2}/-\frac{\sqrt{2}}{2},
            240/-\frac{1}{2}/-\frac{\sqrt{3}}{2},
            % the coordinates for the fourth quadrant
            330/\frac{\sqrt{3}}{2}/-\frac{1}{2},
            315/\frac{\sqrt{2}}{2}/-\frac{\sqrt{2}}{2},
            300/\frac{1}{2}/-\frac{\sqrt{3}}{2}}
                \draw (\x:1.25cm) node[fill=white] {$\left(\xtext,\y\right)$};

        % draw the horizontal and vertical coordinates
        % the placement is better this way
        \draw (-1.25cm,0cm) node[above=1pt] {$(-1,0)$}
              (1.25cm,0cm)  node[above=1pt] {$(1,0)$}
              (0cm,-1.25cm) node[fill=white] {$(0,-1)$}
              (0cm,1.25cm)  node[fill=white] {$(0,1)$};
    \end{tikzpicture}

\section*{Reference Angles}

Reference help us remember certain trig values. As can been seen from the unit circle, the points on the circle are the same all around except for the negative signs. Basically, knowing the first quadrant values will you to know all of the angles.\\

\subsection*{Quadratal Angles}

These are angles whose terminal sides are on the axis, multiples of $90^\circ$ or $\frac{\pi}{2}$.\\

\subsection*{Reference Agnles}

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

	\draw[line width=2pt,<->](1.1,0)--(-1.1,0);
	\draw[line width=2pt,<->](0,1.1)--(0,-1.1);
	\draw(0,0)circle[radius=1];
	\node at (0,1.2){$\frac{\pi}{2},(0,1)$};
	\node at (0,-1.2){$\frac{3\pi}{2},(0,-1)$};
	\node at (-1.5,0){$\pi,(-1,0)$};
	\node at (1.5,0){$2\pi,(1,0)$};
	\draw[blue, line width=1.5pt,->](0,0)--(0.866025404,0.5); %30 degree angle
		\draw[red,dashed, line width=1.5pt,->](0,0)--(-0.866025404,0.5); %reference angle q2
		\draw[red,dashed, line width=1.5pt,->](0,0)--(0.866025404,-0.5); %reference angle q4
		\draw[red,dashed, line width=1.5pt,->](0,0)--(-0.866025404,-0.5); %reference angle q3

	\node at (1.2,.6){$(\sqrt{3},\frac{1}{2})$};
	\node at (-1.2,.6){$(-\sqrt{3},\frac{1}{2})$};
	\node at (1.2,-.6){$(\sqrt{3},-\frac{1}{2})$};
	\node at (-1.3,-.6){$(-\sqrt{3},-\frac{1}{2})$};

	\node at (.5,.4){$\frac{\pi}{6}$};
	\node at (-.5,.4){$\frac{5\pi}{6}$};
	\node at (-.5,-.45){$\frac{7\pi}{6}$};
	\node at (.5,-.45){$\frac{11\pi}{6}$};

\end{tikzpicture}
\end{center}

The $x$ and $y$ values are the same on each of these

\bgroup
\def\arraystretch{3.3}%  1 is the default, change whatever you need
\setlength{\tabcolsep}{.4in}
\begin{tabular}{c c c c}

$\sin\frac{\pi}{6}=$ & $\sin\frac{5\pi}{6}=$ & $\sin\frac{7\pi}{6}=$ & $\sin\frac{11\pi}{6}=$ \\

$\cos\frac{\pi}{6}=$ & $\cos\frac{5\pi}{6}=$ & $\cos\frac{7\pi}{6}=$ & $\cos\frac{11\pi}{6}=$ \\

$\tan\frac{\pi}{6}=$ & $\tan\frac{5\pi}{6}=$ & $\tan\frac{7\pi}{6}=$ & $\tan\frac{11\pi}{6}=$ \\

\end{tabular}
\egroup

\section*{Unit Review}

\hfill NAME:\underline{\hspace*{3in}}

\subsection*{General Angles}

Draw each angle, name the quadrant, list one positive and one negative coterminal angle. (4 points each)\\

\begin{enumerate}
\begin{multicols}{3}
\item Draw a $210^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\columnbreak

\item Draw a $66^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\columnbreak

\item Draw a $345^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\end{multicols}
\end{enumerate}

\subsection*{Radians}

Convert from radians to degrees, or from degrees to radians. (2 points each).\\

\begin{enumerate}[resume]
\begin{multicols}{2}

\item $30^\circ$\\

\item $80^\circ$\\

\item $225^\circ$\\

\item $110^\circ$\\

\item $330^\circ$\\

\columnbreak

\item $\frac{\pi}{9}$\\

\item $\frac{2\pi}{9}$\\

\item $\frac{7\pi}{4}$\\

\item $\frac{9\pi}{10}$\\

\item $\frac{3\pi}{2}$\\

\end{multicols}
\end{enumerate}

\pagebreak

\subsection*{Evaluating Trig functions}

Evaluate $\sin$, $\cos$, and $\tan$ at the given point. (4 points each)\\

\begin{center}
$\sin\theta=\frac{y}{r}$ \ $cos\theta=\frac{x}{r}$ \ $\tan\theta=\frac{y}{x}$\\
\end{center}

\vspace{12pt}

\begin{enumerate}[resume]
\begin{multicols}{2}

\item $(12,5)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(-6,8)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(-2,-2)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(4,-3)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\end{multicols}
\end{enumerate}

\subsection*{Unit Circle \& Reference Angles}

Use your unit circle (2 points each)\\

\begin{enumerate}[resume]

\item What is the reference angle for $300^\circ$?\\

\item Name 2 angles whose reference angle is $45^\circ$\\

\item How many reference angles are there for $30^\circ$\\

\item What is the $\sin$ and $\cos$ value at $150^\circ$?\\

\end{enumerate}

\section*{Unit Test.}

\hfill NAME:\underline{\hspace*{3in}}

\subsection*{General Angles}

Draw each angle, name the quadrant, list one positive and one negative coterminal angle. (4 points each)\\

\begin{enumerate}
\begin{multicols}{3}
\item Draw a $110^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\columnbreak

\item Draw a $-56^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\columnbreak

\item Draw a $45^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\end{multicols}
\end{enumerate}

\subsection*{Radians}

Convert from radians to degrees, or from degrees to radians. (2 points each).\\

\begin{enumerate}[resume]
\begin{multicols}{2}

\item $45^\circ$\\

\item $210^\circ$\\

\item $160^\circ$\\

\item $18^\circ$\\

\item $600^\circ$\\

\columnbreak

\item $\frac{\pi}{18}$\\

\item $\frac{5\pi}{18}$\\

\item $\frac{7\pi}{9}$\\

\item $\frac{3\pi}{4}$\\

\item $\frac{\pi}{6}$\\

\end{multicols}
\end{enumerate}

\pagebreak

\subsection*{Evaluating Trig functions}

Evaluate $\sin$, $\cos$, and $\tan$ at the given point. (4 points each)\\

\begin{center}
$\sin\theta=\frac{y}{r}$ \ $cos\theta=\frac{x}{r}$ \ $\tan\theta=\frac{y}{x}$\\
\end{center}

\vspace{12pt}

\begin{enumerate}[resume]
\begin{multicols}{2}

\item $(5,-12)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(8,-6)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(1,1)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(-4,3)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\end{multicols}
\end{enumerate}

\subsection*{Unit Circle \& Reference Angles}

Use your unit circle (2 points each)\\

\begin{enumerate}[resume]

\item What is the reference angle for $210^\circ$?\\

\item Name 2 angles whose reference angle is $30^\circ$\\

\item How many reference angles are there for $60^\circ$\\

\item What is the $\sin$ and $\cos$ value at $120^\circ$?\\

$\sin(120^\circ)=$ \hspace{1in} $\cos(120^\circ)=$

\end{enumerate}

\section*{Unit Test:}

\hfill NAME:\underline{\hspace*{3in}}

\subsection*{General Angles}

Draw each angle, name the quadrant, list one positive and one negative coterminal angle. (4 points each)\\

\begin{enumerate}
\begin{multicols}{3}
\item Draw a $70^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\columnbreak

\item Draw a $190^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\columnbreak

\item Draw a $315^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\end{multicols}
\end{enumerate}

\subsection*{Radians}

Convert from radians to degrees, or from degrees to radians. (2 points each).\\

\begin{enumerate}[resume]
\begin{multicols}{2}

\item $25^\circ$\\

\item $150^\circ$\\

\item $240^\circ$\\

\item $10^\circ$\\

\item $315^\circ$\\

\columnbreak

\item $\frac{\pi}{90}$\\

\item $\frac{2\pi}{90}$\\

\item $\frac{\pi}{5}$\\

\item $\frac{2\pi}{3}$\\

\item $\frac{3\pi}{4}$\\

\end{multicols}
\end{enumerate}

\pagebreak

\subsection*{Evaluating Trig functions}

Evaluate $\sin$, $\cos$, and $\tan$ at the given point. (4 points each)\\

\begin{center}
$\sin\theta=\frac{y}{r}$ \ $cos\theta=\frac{x}{r}$ \ $\tan\theta=\frac{y}{x}$\\
\end{center}

\vspace{12pt}

\begin{enumerate}[resume]
\begin{multicols}{2}

\item $(3,4)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(-8,6)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(-1,-1)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(-7,24)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\end{multicols}
\end{enumerate}

\subsection*{Unit Circle \& Reference Angles}

Use your unit circle (2 points each)\\

\begin{enumerate}[resume]

\item What is the reference angle for $330^\circ$?\\

\item Name 2 angles whose reference angle is $30^\circ$\\

\item How many reference angles are there for $60^\circ$\\

\item What is the $\sin$ and $\cos$ value at $240^\circ$?\\

$\sin(240^\circ)=$ \hspace{1in} $\cos(240^\circ)=$

\end{enumerate}

\section*{Unit Test::}

\hfill NAME:\underline{\hspace*{3in}}

\subsection*{General Angles}

Draw each angle, name the quadrant, list one positive and one negative coterminal angle. (4 points each)\\

\begin{enumerate}
\begin{multicols}{3}
\item Draw a $100^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\columnbreak

\item Draw a $200^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\columnbreak

\item Draw a $300^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\end{multicols}
\end{enumerate}

\subsection*{Radians}

Convert from radians to degrees, or from degrees to radians. (2 points each).\\

\begin{enumerate}[resume]
\begin{multicols}{2}

\item $100^\circ$\\

\item $150^\circ$\\

\item $200^\circ$\\

\item $250^\circ$\\

\item $300^\circ$\\

\columnbreak

\item $\frac{\pi}{10}$\\

\item $\frac{\pi}{5}$\\

\item $\frac{5\pi}{4}$\\

\item $\frac{7\pi}{3}$\\

\item $\frac{3\pi}{5}$\\

\end{multicols}
\end{enumerate}

\pagebreak

\subsection*{Evaluating Trig functions}

Evaluate $\sin$, $\cos$, and $\tan$ at the given point. (4 points each)\\

\begin{center}
$\sin\theta=\frac{y}{r}$ \ $cos\theta=\frac{x}{r}$ \ $\tan\theta=\frac{y}{x}$\\
\end{center}

\vspace{12pt}

\begin{enumerate}[resume]
\begin{multicols}{2}

\item $(24,7)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(-5,12)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(-3,3)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(-3,4)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\end{multicols}
\end{enumerate}

\subsection*{Unit Circle \& Reference Angles}

Use your unit circle (2 points each)\\

\begin{enumerate}[resume]

\item What is the reference angle for $135^\circ$?\\

\item Name 2 angles whose reference angle is $30^\circ$\\

\item How many reference angles are there for $45^\circ$\\

\item What is the $\sin$ and $\cos$ value at $210^\circ$?\\

$\sin(210^\circ)=$ \hspace{1in} $\cos(210^\circ)=$

\end{enumerate}

\section*{Unit Test}

\hfill NAME:\underline{\hspace*{3in}}

\subsection*{General Angles}

Draw each angle, name the quadrant, list one positive and one negative coterminal angle. (4 points each)\\

\begin{enumerate}
\begin{multicols}{3}
\item Draw a $10^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\columnbreak

\item Draw a $100^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\columnbreak

\item Draw a $177^\circ$ angle\\

\vspace{12pt}

	\begin{tikzpicture}[scale=2]

	\coordinate (a) at (0,1);
	\coordinate (b) at (0,-1);
	\coordinate (c) at (-1,0);
	\coordinate (d) at (1,0);

	\draw[line width=2pt, <->] (a) -- (b);
	\draw[line width=2pt, <->] (c) -- (d);

	\end{tikzpicture}

Quadrant:\underline{\hspace{1in}}\\

+ coterminal:\underline{\hspace{1in}}\\

- coterminal:\underline{\hspace{1in}}

\end{multicols}
\end{enumerate}

\subsection*{Radians}

Convert from radians to degrees, or from degrees to radians. (2 points each).\\

\begin{enumerate}[resume]
\begin{multicols}{2}

\item $30^\circ$\\

\item $60^\circ$\\

\item $90^\circ$\\

\item $120^\circ$\\

\item $81^\circ$\\

\columnbreak

\item $\frac{\pi}{3}$\\

\item $\frac{2\pi}{3}$\\

\item $\frac{3\pi}{2}$\\

\item $\frac{\pi}{30}$\\

\item $\frac{6\pi}{5}$\\

\end{multicols}
\end{enumerate}

\pagebreak

\subsection*{Evaluating Trig functions}

Evaluate $\sin$, $\cos$, and $\tan$ at the given point. (4 points each)\\

\begin{center}
$\sin\theta=\frac{y}{r}$ \ $cos\theta=\frac{x}{r}$ \ $\tan\theta=\frac{y}{x}$\\
\end{center}

\vspace{12pt}

\begin{enumerate}[resume]
\begin{multicols}{2}

\item $(-5,5)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(6,-8)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(-3,-4)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\item $(24,7)$, r=\underline{\hspace{.7in}}\\

$\sin\theta=$\underline{\hspace{1in}}\\

$\cos\theta=$\underline{\hspace{1in}}\\

$\tan\theta=$\underline{\hspace{1in}}\\

\end{multicols}
\end{enumerate}

\subsection*{Unit Circle \& Reference Angles}

Use your unit circle (2 points each)\\

\begin{enumerate}[resume]

\item What is the reference angle for $225^\circ$?\\

\item Name 2 angles whose reference angle is $30^\circ$\\

\item How many reference angles are there for $60^\circ$\\

\item What is the $\sin$ and $\cos$ value at $180^\circ$?\\

$\sin(180)=$ \hspace{1in} $\cos(180)=$

\end{enumerate}

\section*{Graphing Trig Functions}

\pyc{2^5}

%check this out http://gma.math.ufl.edu/files/tikz.pdf

%\begin{tikzpicture}
%	\begin{axis}[my style, xtick={-3,-2,...,3}, ytick={-3,-2,...,3},
%	xmin=-3, xmax=3, ymin=-3, ymax=3]
%	\end{axis}
%\end{tikzpicture}

$y = a \sin(b x + c) + d$\\

$a=$ amplitude\\
$b=$ period (horizontal strech/compression)\\
$c=$ phase (horizontal) shift\\
$d=$ vertical shift\\

period = $\dfrac{2\pi}{b}$\\

phase shift = $-\dfrac{c}{b}$

\end{document}


\documentclass[12]{scrartcl}
\usepackage{amssymb,amsmath,gensymb,dsfont,calc,multicol,fullpage}
\makeatletter
\newcommand\Aboxed[1]{
   \@Aboxed#1\ENDDNE}
\def\@Aboxed#1&#2\ENDDNE{%
   &
   \settowidth\@tempdima{$\displaystyle#1{}$}
   \setlength\@tempdima{\@tempdima+\fboxsep+\fboxrule}
   \kern-\@tempdima
   \boxed{#1#2}
}
\makeatother

\begin{document}

\title{Homework 10, Section 2.5: 6, 12, 14, 15, 23}
\author{Alex Gordon}
\date{\today}
\maketitle
\section*{Homework}
\subsection*{6.}
Contradicting statement: There can be an integer that is both even and odd. \\ \\
First off, let me define and odd and even integer. An even integer is one that can be defined in the form $2j$ where $j$ is any integer. Let an odd integer be defined in the form $2n + 1$. Given these definitions, if an integer is both even and odd, then it must match the form\\
\begin{center}$2n = 2n+1$\end{center}
Since no number can ever equal itself plus one, that statement is not true, meaning the contradicting statement, "there is no integer that can be both even and odd" is true.
\subsection*{12.}
Let $a$ be a rational number and let $b$ be an irrational number. Assume that $a + b = c$ contains all rational numbers.
\\
If this is the case there must exist integers $a$, $b$ and $c$ such that $a = \frac{c}{b}$, and $a$ and $c$ can be chosen to be relatively prime (no factors in common). This must also be true then that $b^2 = \frac{c}{b}^2$
\subsection*{14. A)}
\begin{center}$n = \frac{5}{3}$\end{center}
\subsection*{14. B)}
\begin{center}$n = 1,000,000,000$\end{center}
\subsection*{14. C)}
\begin{center}$n = 8$\end{center}
\subsection*{15.}
Contradicting statement: The $\sqrt{5}$ is rational.
Suppose that $\sqrt{5}$ is rational. That means $\sqrt{5} = \frac{a}{b}$ where $a$ and $b$ are some integers that are relatively prime. This means that if we were to square both sides then $(\sqrt{5})^2 = (\frac{a}{b})^2$. It then follows that
\begin{align*}
(\sqrt{5})^2 &= \frac{a^2}{b^2}
\\ 5 &= \frac{a^2}{b^2}
\\ 5b^2 &= a^2\\
\end{align*}

If $a$ and $b$ are in lowest terms (as supposed), their squares would each have an even number of prime factors. $5b^2$ has one more prime factor than $b^2$, meaning it would have an odd number of prime factors. Every composite has a unique prime factorization and can't have both an even and odd number of prime factors, this shows that $\sqrt{5}$ is not rational.

\subsection*{23.}
Contradicting statement: If the average net weight of seven boxes of cereal is 17 ounces, then at least one of the boxes does not have a net weight of at least 17 ounces. \\
\\
Let $k_1, … k_7$ represent the weight of the 7 cereal boxes. Of $k_1, ... k_7$, since none of them have a net weight of at least 17 ounces, we know that their sum is less than 119 ounces. This means that \\
\begin{center} $k_1 + k_2 + k_3... k_7 \  \textless \ 119$ \end{center}
However, based on the proposition that the average weight is 17 ounces, then
\begin{center} $k_1 + k_2 + k_3... k_7 \  \geq \ 119$ \end{center}
and it also means that
\begin{center} $\frac{119} {k_1 + k_2 + k_3... k_7}  \leq 1$ \end{center}
This means at least one of the boxes is 17 ounces because if they were all less that 17 ounces then
\begin{center} $\frac{119} {k_1 + k_2 + k_3... k_7}  \geq 1$ \end{center}
which is not true.
\end{document}


\documentclass{article}

\usepackage{mathtools}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage{listings}
\usepackage{placeins}
\usepackage{subcaption}
\usepackage[hidelinks]{hyperref}
\usepackage{cleveref}

\geometry{
  top=2cm,
  bottom=2cm,
  left=3.5cm,
  right=3.5cm
}

\titleformat{\section}
  {\large\bfseries}
  {\llap{\hspace*{-2.5em}Q\thesection:\hfill}}
  {0pt}
  {}
\titlespacing*{\section}
  {0pt}
  {2ex}
  {1ex}
\titleformat{\subsection}
  {\itshape\bfseries}
  {\llap{\hspace{-2.5em}
  \rm\bf(\alph{subsection})
  \hfill}}
  {0pt}
  {}
\titlespacing*{\subsection}
  {0pt}
  {2ex}
  {1ex}
\titleclass{\appx}{straight}[\section]
\newcounter{appx}
\renewcommand{\theappx}{\Alph{appx}}
\titleformat{\appx}
  {\large\bfseries}
  {\llap{\hspace*{-6.6em}Appendix \theappx:\hfill}}
  {0pt}
  {}
\titlespacing*{\appx}
  {0pt}
  {2ex}
  {1ex}

\newcommand{\mail}[1]{
  \href{mailto:#1}{#1}
}

\lstset{
  frame=single,
  numbers=left,
  breaklines=true,
  basicstyle=\small
}

\newcommand{\codesnippet}[5]{
  \begin{figure}[!ht]
    \lstinputlisting[
      language=#2,
      firstline=#3,
      lastline=#4,
      firstnumber=#3
    ]{#1}
  #5
  \end{figure}
}

\newcommand{\mandelbrotsource}{../mandelbrot/mandelbrot.c}
\newcommand{\plotsource}{../mandelbrot/plot.py}

\begin{document}

\begin{center}
  \textbf{
    \LARGE Homework 1 \\
    \large SF2568 - Parallel Computation for Large Scale Problems \\
    Lukas Bjarre - \mail{lbjarre@kth.se} \\
    \rule{0.75\textwidth}{0.4pt}
  }
\end{center}

\section{Difference between a \emph{process} and a \emph{processor}}
A \emph{process} is defined by the instructions that are needed to compute a problem.
A \emph{processor} refers to the physical hardware which executes a process.

\section{Performance calculation}
$10\%$ of the time the computer is operating at single processor performance, i.e. $2$ Gflops.
The remaining $90\%$ of the time all 100 processors are computing in parallel
at a performance of $200$ Gflops.
The total performance will therefore be
\begin{equation}
  0.1 \cdot 2 + 0.9 \cdot 200 = 180.2 \text{ Gflops}
\end{equation}

\section{Is a system efficiency larger than 100\% possible?}
The system efficiency $\eta_P$ for $P$ processors is given by
\begin{equation}
  \label{eq:sysefficiency}
  \eta_P = \frac{S_P}{P} = \frac{T^*_s}{PT_P}
\end{equation}
where $T^*_s$ is the fastest serial runtime
and $T_P$ is the parallel runtime for $P$ processes.
Assuming (unrealistically) no communication in the parallel implementation,
the optimal parallel runtime will be $T^*_P = T^*_sP^{-1}$.
This implementation inserted into \eqref{eq:sysefficiency} would result in
a system efficiency of $100\%$.
However, this is a lower bound for the parallel runtime,
hence $\eta_P \leq 1$.

\section{Modified Parallel Rank Sort}
Since we have 10 times as many elements as processors 10 elements can be allocated to each processor.
Each processor has to then loop through each of the allocated elements and execute the original
Parallel Rank Sort for each of them.
The resulting rank arrays then needs to be shared to the rest of the processors,
which can be done for example in a recursive doubling procedure.

\section{Parallel speedup}
\subsection{What fraction of the serial runtime is spent in serial procedures?}
We have $T^*_s = 64$ s and $T_P = 22$ s for $P=8$.
The serial fraction of the program depends on which law you apply to the numbers.
The serial fraction as given by Amdahl's law is
\begin{equation}
  \begin{aligned}
    f
    &= \frac{PT_P - T^*_s}{T^*_s\left( P - 1 \right)} \\
    &= \frac{8\cdot 22 - 64}{64\cdot 7} \\
    &= \frac{1}{4} = 0.25
  \end{aligned}
\end{equation}
The serial fraction as given by Gustafson's law is
\begin{equation}
  \begin{aligned}
    f'
    &= \frac{PT_P - T^*_s}{T_P\left( P - 1 \right)} \\
    &= \frac{8\cdot 22 - 64}{22\cdot 7} \\
    &= \frac{8}{11} \approx 0.72
  \end{aligned}
\end{equation}

\subsection{Determine the parallel speedup}
The speedup once again depends on which law you apply.
The speedup as given by Amdahl is
\begin{equation}
  \begin{aligned}
    S_P
    &= \frac{1}{\left( 1-f \right)P^{-1} + f} \\
    &= \frac{1}{0.75P^{-1} + 0.25}
  \end{aligned}
\end{equation}
For $P=8$ we have a speedup of $S_8 \approx 2.9$.
We also see that even if we let $P\rightarrow\infty$,
the speedup would only converge to $S_\infty = 4$.

The scaled speedup as given by Gustafson is
\begin{equation}
  \begin{aligned}
    S'_P
    &= f' + (1 - f')P \\
    &= \frac{8 + 3P}{11}
  \end{aligned}
\end{equation}
For $P=8$ we have a scaled speedup of $S'_8 \approx 2.9$,
i.e. the same as predicted by Amdahl.
However, unlike $S_P$, $S'_P$ grows unbounded as $P\rightarrow\infty$.

\subsection{Parallel speedup on three phased program}
We notate the serial runtimes for each program phase as $T_{pi}$,
where $i=1,\,2,\,3$ describes the different phases.
We also know the relation between each phase's serial runtime and the optimal serial runtime
as $T_{p1} = 0.2T^*_s$, $T_{p2} = 0.2T^*_s$, and $T_{p3} = 0.6T^*_s$.
In the parallel version of the program each program phase will be sped up by a optimal
factor of $k^*_{pi}$ for each program phase.
We will assume perfect speedup for each phase given the given optimal process count,
i.e. $k^*_{pi} = P^{*-1}_{pi}$ for optimal process count $P^{*-1}_{pi}$.
The total speedup will be
\begin{equation}
  \begin{aligned}
    S_P
    &= \frac{T^*_s}{T^*_s\left( 0.2k^*_{p1} + 0.2k^*_{p2} + 0.6k^*_{p3} \right)} \\
    &= \frac{1}{\frac{1}{25} + \frac{1}{50} + \frac{3}{75}} \\
    &= \frac{750}{75} \\
    &= 10
  \end{aligned}
\end{equation}

\section{Parallel Mandelbrot implementation}

\subsection*{Implementation}
My parallel implementation of the mandelbrot set calculation is similair to the one
presented in the lecture slides,
except with some small alterations to increase usability and performance.
The code can be found in the appendix.

The first change is how the data is distributed between the processors.
The version presented in the lecture slides separated the complex plane grid into vertical slices,
i.e. common $x$-coordinates and iterating over the $y$-coordinates.
However, when the data is saved we want to save rows and not columns,
i.e. common $y$-coordinates and iterating over the $x$-coordinates.
I therefore changed the data distribution to horizontal strips of the complex plane grid instead
to better accomodate the saved data structure.

The second change has also to do with the saved data structure.
I wanted to make the saved file as similair to the complex plane as possible.
Since the complex plane usually is plotted with positive complex values on the top
and the negatives on the bottom,
the first row of the saved file should contain the highest complex values
and the last row the file the lowest.
Therefore, the sign of the starting $y$-position
and the direction in which the complex values was iterated in was flipped.

Finally, the viewport in which the complex plane is evaluated was generalized.
The method used in the lecture slide assumed a viewport of $[-b,\,b] \times [-b,\,b]$,
i.e. a square with sides $2b$ placed with its center at the origin.
This was changed to a viewport of $[x_s,\,x_s+x_w] \times [y_s,\,y_s-y_h]$,
i.e. a more general rectangle placed with its upper left corner at $(x_s,\,y_s)$
and with width $x_w$ and height $y_h$.

\subsection*{Output Images}
Below are some images produced by the code.
\begin{figure}[!ht]
  \centering
  \includegraphics[width=0.45\textwidth]{../mandelbrot/full.pdf}
  \caption{Plot of the Mandelbrot set within $[-2,\,2] \times i[-2,\,2]$.}
  \label{fig:standardview}
\end{figure}

\begin{figure}[!ht]
  \centering

  \begin{subfigure}[t]{0.45\textwidth}
    \centering
    \includegraphics[width=0.9\textwidth]{../mandelbrot/zoom1.pdf}
    \caption{$[-0.970,\,-0.995] \times i[0.245,\,0.270]$}
  \end{subfigure}
  ~
  \begin{subfigure}[t]{0.45\textwidth}
    \centering
    \includegraphics[width=0.9\textwidth]{../mandelbrot/zoom2.pdf}
    \caption{$[-1.50,\,-1.55] \times i[-0.025,\,0.025]$}
  \end{subfigure}
  ~
  \begin{subfigure}[t]{0.45\textwidth}
    \centering
    \includegraphics[width=0.9\textwidth]{../mandelbrot/zoom3.pdf}
    \caption{$[0.3981,\,0.3982] \times i[0.23312,\,0.23322]$}
  \end{subfigure}
  ~
  \begin{subfigure}[t]{0.45\textwidth}
    \centering
    \includegraphics[width=0.9\textwidth]{../mandelbrot/zoom4.pdf}
    \caption{$[-0.1555,\,-0.1535] \times i[0.6522,\,0.6542]$}
  \end{subfigure}

  \caption{Various zoomed in plots on the Mandelbrot set.}
\end{figure}

\newpage
\appx{Parallel Mandelbrot Sourcecode}
Below is the source code for the program which implements the parallel version
of the Mandelbrot set calculation.
The code is quite lengthy, so it is broken down into smaller snippets containing separate functions
together with a small annotation describing its function.

\codesnippet{\mandelbrotsource}{C}{1}{8}{
Library imports and our constants.
The constants define how the color picking is set by the maximum iteration count
(the number of possible colors)
and the squared escape distance that for the semi-stable convergence definition.
Constants defining the pixel size of the viewport are also set.
}

\codesnippet{\mandelbrotsource}{C}{10}{27}{
The function which assigns colors to each pixel.
This implementation uses slightly more memory than the straight-forward approach,
but saves a couple of operations for each loop.
}

\codesnippet{\mandelbrotsource}{C}{29}{45}{
Next we have the main calculation loop for each process.
It iterates over the pixels assigned to the processor,
converts each pixel to a complex number,
and saves the calculated color value in the array $M$.
}

\codesnippet{\mandelbrotsource}{C}{47}{56}{
The function for writing the results to a file is fairly basic.
}

\codesnippet{\mandelbrotsource}{C}{58}{71}{
A small function for setting up all the MPI stuff outside of the main procedure.
This function also checks to make sure that the number of processes
evenly divide the pixel grid height.
If not, it returns a negative flag to main.
}

\codesnippet{\mandelbrotsource}{C}{73}{89}{
This function sets the variables defining the viewport,
either through argv or as defaults if no arguments are passed.
Returns a negative flag if argv is of incorrect length.
}

\codesnippet{\mandelbrotsource}{C}{91}{130}{
The main procedure calls the initializing functions,
sets up and calculates the mandelbrot for the process height,
and sends everything to the 0 rank process.
The 0 rank process saves some memory by overwriting the already allocated $M$-vector
after writing its contents to the output file
}

\FloatBarrier
\newpage
\appx{Plotting Sourcecode}
Below is the sourcecode for the Python script
used to read the data produced by the C code and produce images.
\codesnippet{\plotsource}{Python}{1}{34}{}

\end{document}


\documentclass[11pt]{article}
\usepackage{setspace}
\usepackage{pxfonts}
\usepackage{graphicx}
\usepackage{geometry}

\geometry{letterpaper,left=.5in,right=.5in,top=0in,bottom=.75in,headsep=5pt,footskip=20pt}

\title{Problem Set 4 -- Hodgkin-Huxley neuron model}
\author{Computational Neuroscience Summer Program}
\date{June, 2011}

\begin{document}
\maketitle

In this problem set you will be building a Hodgkin-Huxley model neuron.  Write up your results in a text editor of your choosing.  Include any relevant figures.  Include a printout of your Matlab code as well as any calculations that aren't in the code.  You may work individually or in groups, but each student should hand in their own report.

\subsection*{Equations}

\begin{center}
\begin{tabular}{l|l|l}
$\tau_x(V)\frac{dx}{dt} = x_\infty(V) - x$ & $\tau_x(V) =
\frac{1}{\alpha_x(V) + \beta_x(V)}$ & $x_\infty(V) =
\frac{\alpha_x(V)}{\alpha_x(V) + \beta_x(V)}$ \\
\hline
$\alpha_n(V) = \frac{0.01(V+55)}{1 - exp(-.1(V+55))}$ &
$\alpha_m(V) = \frac{0.1(V+40)}{1 - exp(-.1(V+40))}$ &
$\alpha_h(V) = 0.07*exp(-.05(V+65))$\\
\hline
$\beta_n(V) = 0.125*exp(-0.0125(V+65))$ &
$\beta_m(V) = 4*exp(-.0556(V+65))$ &
$\beta_h(V) = \frac{1}{1 + exp(-.1(V+35))}$\\
\hline
$P_K = n^4$ & $P_{Na} = m^3h$ &\\
\hline
$g_K = \bar{g}_KP_K$ & $g_{Na} = \bar{g}_{Na}P_{Na}$ &\\

\end{tabular}
\end{center}

\subsection*{Problems}

\paragraph{1.} Build a Hodgkin-Huxley model using the following
equation, in addition to those listed above:

\[
V(t+dt) = V(t) +\frac{\left[-i_m + \frac{I_{ext}}{A}\right]dt}{c_m},
\]
where
\[
i_m = \bar{g}_L(V(t) - E_L) + g_K(V(t) - E_K) + g_{Na}(V(t) - E_{Na}),
\]
and where $\bar{g}_L = 0.003$ mS/mm$^2$, $\bar{g}_K = 0.36$ mS/mm$^2$,
$\bar{g}_{Na} = 1.2$ mS/mm$^2$, $E_L = -54.387$ mV, $E_K = -77$ mV,
$E_{Na} = 50$ mV, and $c_m = 0.1$ nF/mm$^2$.  Set $V(0) = E = -65$ mV.  You should simulate a 15
ms segment (use $dt \leq 0.01$ ms).  Pulse the neuron with a 5 nA/mm$^2$
pulse between 5 and 8 ms in your simulation; this should result in a
single action potential at between 5 and 10 ms.  Plot the $V$, $n$, $m$, and $h$
as a function of time.  Congratulations --- you've just replicated a
Nobel prize-worthy result!

\paragraph{2.}  Explain what's happening in problem 1.  In particular:
what do $V$, $n$, $m$, and $h$ mean in terms of the simulated neuron?
Explain the relative time course of each of these variables.  How do
$n$, $m$, and $h$ interact to produce $V$?

\paragraph{3.}  Tetrodotoxin (TTX), a pufferfish-derived toxin, selectively blocks
voltage-sensitive sodium channels, effectively setting $P_{Na} = 0$.
Simulate the addition of TTX at $t = 0$ ms, and re-plot $V$, $n$, $m$,
and $h$.  Does the neuron still fire an action potential?  Why or why
not?

\paragraph{4.}  Tetraethylammonium (TEA) selectively blocks
voltage-sensitive potassum channels, effectively setting $P_{K} = 0$.
Simulate the addition of TEA at $t = 0$ ms, and re-plot $V$, $n$, $m$,
and $h$.  Does the neuron still fire an action potential?  Why or why
not?  (Remember to remove TTX first!)

\paragraph{5.  Challenge problem.}  How might you compute the firing rate of your
Hodgkin-Huxley neuron?  Simulate a 1000 ms run with a pulse from
250 to 750 ms, and measure how many spikes are fired.  Repeat this procedure for 10 pulse strengths between 0.01 and 10 nA.  Plot firing rate as a function of pulse strength.

\end{document}


\documentclass[hyperpdf,bindnopdf,twocolumn]{article}
\usepackage{
amsmath,
booktabs,
cancel,
caption,
cleveref,
colortbl,
csquotes,
datatool,
helvet,
mathpazo,
multirow,
listings,
pgfplots,
xcolor,}

%==============
%useful physics
\usepackage{siunitx}
\usepackage{physymb} % by David Zaslavsky
%==============

\begin{document}
    \section{Units}
    Numbers:\\
        \num{12345,67890} \\
        \num{1+-2i}       \\
        \num{.3e45}       \\
        \num{1.654 x 2.34 x 3.430}\\

    List/Range of numbers:\\
        \numlist{10;20;30}                    \\
        \SIlist{0.13;0.67;0.80}{\milli\metre} \\
        \numrange{10}{20}                     \\
        \SIrange{0.13}{0.67}{\milli\metre}\\

    Units:\\
        \si{kg.m.s^{-1}}                \\
        \si{\kilogram\metre\per\second} \\
        \si[per-mode=symbol]
        {\kilogram\metre\per\second}  \\
        \si[per-mode=symbol]
        {\kilogram\metre\per\ampere\per\second}\\
        \ang{10}\\ %degree

    Numbers and Units:\\
        \SI[mode=text]{1.23}{J.mol^{-1}.K^{-1}}\\

    SI base units:\\
    \si{\ampere}\\
    \si{\candela}\\
    \si{\kelvin}\\
    \si{\kilogram}\\
    \si{\meter }\\
    \si{\mole  }\\
    \si{\second}\\
    SI derived units:\\
    \si{\becquerel} \\
    \si{\newton}    \\
    \si{\degreeCelsius} \\
    \si{\ohm}       \\
    \si{\coulomb}   \\
    \si{\pascal}    \\
    \si{\farad}     \\
    \si{\radian}    \\
    \si{\gray}      \\
    \si{\siemens}   \\
    \si{\hertz}     \\
    \si{\sievert}   \\
    \si{\henry}     \\
    \si{\steradian} \\
    \si{\joule}     \\
    \si{\tesla}     \\
    \si{\katal}     \\
    \si{\volt}      \\
    \si{\lumen}     \\
    \si{\watt}      \\
    \si{\lux}       \\
    \si{\weber}     \\
    \si{\angstrom}     \\
    \si{\electronvolt}     \\

    \section{Formulas}

    From physymb:\\
    \begin{align*}
        \sn{6.23}{6}\\
        \snunit{3.1}{6}{meter^3}\\ % conflict with siunitx
        \asin \acos \sech \\
        \intset \realset \\
        \ud{y}{x}\\
        \pd{y}{x}\\
        \pddd{y}{x}\\
        \udc\\
        \iint e^{i\vec{k}\cdot\vec{x}}\udds\vec{x}\\ % use s because we want a small space between the integrand and the d symbol
        \div \grad \curl \lapl\\
        \conj{z}  \real{z} \realop \\
        \unitx \unity \uniti \unite \unitomega \unit{\phi}\\
        \commut{A}{B} \acommut{A}{B}  \herm{A}\\
        \commut{\frac{\hat{A}}{c}}{\hat{B}}\\
        \left[\hat{A},\hat{B}\right]\\
        \exd \hodge \\
        classmech \pbrac{f}{g} \\
        QM \ket{\phi} \braket{\phi}{\psi} \melement{\phi}{A}{\psi} \expect{A}
    \end{align*}

\end{document}


\documentclass[12pt]{article}
	\usepackage{hyperref, fancyhdr, setspace, enumerate}
	\usepackage{tabulary}
	\usepackage{enumitem}
	\usepackage{amsmath, amsthm, amssymb, array, keycommand, lastpage, amssymb, xcolor, mathtools}
	\usepackage{multiaudience}
	\usepackage{tabularx}
	\usepackage{makecell}
	\usepackage[margin=1 in]{geometry}
	\allowdisplaybreaks
	\hypersetup{
		%colorlinks=true, %set true if you want colored links
		linktoc=all, %set to all if you want both sections and subsections linked
		linkcolor=black, %choose some color if you want links to stand out
	}
	\author{Allan Wang}
	\date{Last updated: \today}
	\title{Comp 551: Machine Learning}
	\pagestyle{fancy}
	\lhead{COMP 551}
	\chead{\leftmark}
	\rhead{Allan Wang}
	\cfoot{Page \thepage \ of \pageref{LastPage}}

	% Only number for sections
	\setcounter{secnumdepth}{1}

	\setlength{\parindent}{0pt}

	\setlist[enumerate]{itemsep=0mm}
	\setlist[itemize]{itemsep=0mm}

	% \newcommand{\tab}[1]{\hspace{.2\textwidth}\rlap{#1}}

	\newcommand{\comment}[1]{}

	\newcommand{\mathcomment}[0]{\quad\color{blue}}

	\newcommand{\norm}[1]{\left\lVert#1\right\rVert}

	\newcommand{\real}[0]{\mathbb{R}}

	\newcommand{\uu}[1]{\underbracket{#1}}

	\newcommand{\bb}[1]{\left\{#1\right\}}
	\newcommand{\bbb}[1]{\left[#1\right]}
	\newcommand{\pp}[1]{\left(#1\right)}
	\newcommand{\abs}[1]{\left|#1\right|}

	\newcommand{\divider}[0]{\par\textcolor{lightgray}{\rule{\textwidth}{0.1pt}}}

	\newenvironment{eqn}{\equation\alignedat{3}}{\endalignedat\endequation}

	\newcommand{\todo}[0]{\textcolor{red}{\textbackslash\textbackslash TODO \ }}

\begin{document}
\onehalfspacing
\maketitle
\tableofcontents
\pagebreak

\section{Linear Regression}

\begin{itemize}
	\item Classification - discrete set output
	\item Regression - continuous output
	\item Supervised learning - given training examples with labels, find model to predict labels given input
	\item i.i.d assumption - training set is assumed to be \textit{independently} and \textit{identically distributed}
	\item Linear hypothesis - find weights to minimize
	\begin{eqn}
		Err() = \Sigma_{i = 1:n} (y_i - w^T x_i)^2
	\end{eqn}
\end{itemize}

\subsection{Least-Squares Error}

\begin{eqn}
	f_w &= argmin \Sigma_{i=1:n}(y_i - w^T x_i)^2 \\
	\hat{w} &= (X^T X)^{-1} X^T Y
\end{eqn}
\begin{itemize}
	\item Note that both w and x vectors have an extra dimension (m + 1) for a dummy/intercept term (all 1s for x)
	\item Computational cost is $O(m^3 + nm^2)$ for n inputs and m features
	\item Only works if $X^T X$ is nonsingular (no correlation between features)
	\begin{itemize}
		\item If a feature is a linear function of others, you can drop it
		\item If the number of features exceeds number of training examples, you can reduce the number of features
	\end{itemize}
\end{itemize}

\subsection{Gradient Descent}

\begin{eqn}
	w_{k + 1} &= w_k - \alpha_k \frac{\partial Err(w_k)}{\partial w_k} \\
	\frac{\partial Err(w)}{\partial w} &= 2(X^T Xw - X^T Y)
\end{eqn}
\begin{itemize}
	\item Less expensive approach; weights calculated through iterations
	\item Goal is to reduce the weight errors from the previous iteration
	\item Repeat until $\abs{w_{k + 1} - w_k} < \epsilon$
	\item $a_k > 0$ is the learning rate for iteration $k$
	\begin{itemize}
		\item If too large, oscillates forever
		\item If too small, takes longer to reach local minimum
	\end{itemize}
	\item Robbins-Monroe conditions prove convergence:
	\begin{eqn}
		\Sigma_{k = 0:\infty} \alpha_k &= \infty  \\
		\Sigma_{k = 0:\infty} \alpha_k^2 &< \infty
	\end{eqn}
	\item Not that convergence is to local minimum only, not always global
\end{itemize}

\divider

\begin{itemize}
	\item Feature design - if features cannot fully represent a model, we can transform them using non linear functions (eg powers, binary thresholds, etc) into new features. Note that the weights are still linear combinations.
	\item Overfitting - hypothesis explains training data well, but does not generalize to new data; high variance, low bias
	\item Underfitting - does not capture trend; low variance, high bias
	\item Simple model - high training error, high test error
	\item Complex model - low training error, high test error
	\item Training error always goes down with complexity, but at some point in between, test error will be at its lowest
\end{itemize}

\subsection{Validation}

\begin{itemize}
	\item Validation set should be separate from training data
	\item K-Fold cross validation
	\begin{itemize}
		\item Create $k$ partitions for available data
		\item For each iteration, train with $k - 1$ subsets, then validate on remaining subset. Repeat $k$ times
		\item Return average prediction error
	\end{itemize}
	\item Leave-One-Out Cross Validation
	\begin{itemize}
		\item K-fold where $k = n$
	\end{itemize}
\end{itemize}

\section{Linear Classification}

\subsection{Binary Classification}

\begin{itemize}
	\item Probabilistic - estimate conditional probability $P(y | x)$ given feature data
	\item Decision boundaries - partition feature spaces into different regions
\end{itemize}

\subsection{Discriminative Models}

\begin{itemize}
	\item Directly estimate $P(y | x)$
	\begin{itemize}
		\item Answers what what the features tell us about the class
		\item Difficult to estimate
	\end{itemize}
	\item Log-odds ratio
	\begin{eqn}
		a = ln \frac{P(y = 1 | x)}{P(y = 0 | x)}
	\end{eqn}
	\begin{itemize}
		\item Outputs likelihood of $y = 1$ vs $y = 0$
		\item Decision boundary is set of points for which $a = 0$
	\end{itemize}
	\item Logistic function - predicted probability for $y = 1$
	\begin{eqn}
		\sigma(w^T x) = \frac{1}{1 + e^{-w^T x}}
	\end{eqn}
	\item Likelihood
	\begin{eqn}
		L(D) &= P(y_1, y_2, ..., y_n | x_1, x_2, ..., x_n, w) \\
		&= \prod_{i = 1}^n \sigma(w^T x_i)^{y_i} (1 - \sigma(w^T x_i))^{1 - y_i}
	\end{eqn}
	\begin{itemize}
		\item Numerically unstable for lots of small numbers
	\end{itemize}
	\item Log-Likelihood
	\begin{eqn}
		l(D) &= ln(L(D)) \\
		&= \Sigma_{i=1}^n y_i ln(\sigma(w^T x_i)) + (1 - y_i)ln(1 - \sigma(w^T x_i))
	\end{eqn}
	\begin{itemize}
		\item Easier to optimize
		\item Negative log-likelihood = cross-entropy loss \\
		Maximizing log-likelihood = minimizing cross-entropy loss
	\end{itemize}
	\item Many kinds of losses exist, eg absolute error, or binary;
	however, these losses are not always easy to optimize (not differentiable)
	\item Gradient descent update rule
	\begin{eqn}
		w_{k + 1} = w_k + \alpha_k \Sigma_{i = 1:n} x_i(y_i - \sigma(w_k^T x_k))
	\end{eqn}
\end{itemize}

\subsection{Generative Models}

\begin{itemize}
	\item Use Bayes' rule to estimate
	\begin{eqn}
		P(y = 1 | x) = \frac{P(x | y = 1) P(y = 1)}{P(x)}
	\end{eqn}
	\begin{itemize}
		\item Finds the marginal probability of a class
		\item Easy to estimate
	\end{itemize}
	\item Linear Discriminant Analysis (LDA)
	\begin{eqn}
		P(x | y) = \frac{e^{-\frac{1}{2} (x - \mu)^T \Sigma^{-1}(x - \mu)}}{(2 \pi)^{\frac{1}{2}} \abs{\Sigma}^{\frac{1}{2}}}
	\end{eqn}
	\begin{itemize}
		\item Every class assumed to be Gaussian/normally distributed
		\item Both classes have same covariance matrix $\Sigma$, but different means $\mu$
		\item Estimations
		\begin{eqn}
			P(y = 0) &= \frac{N_0}{N_0 + N_1} \\
			P(y = 1) &= \frac{N_1}{N_0 + N_1} \\\\
			\mu_0 &= \frac{\Sigma_{i=1:n} I(y_i = 0) x_i}{N_0} \\
			\mu_1 &= \frac{\Sigma_{i=1:n} I(y_i = 1) x_i}{N_1} \\\\
			\Sigma &= \frac{\Sigma_{k=0:1} \Sigma_{i=1:n} I(y_i = k) (x_i - \mu_i)(x_i - \mu_k)^T}{N_0 + N_1 - 2}
		\end{eqn}
		\begin{itemize}
			\item $N_0$ and $N_1$ are the \# of training samples from classes 1 and 0 respectively
			\item $I(x)$ is an indicator function: $I(x) = 0$ if $x = 0$, $I(x) = 1$ if $x = 1$
		\end{itemize}
		\item Cost is $O(m^2)$ for $m$ classes
	\end{itemize}
	\item Quadratic Discriminant Analysis (QDA)
	\begin{itemize}
		\item Allows different covariance matrices, $\Sigma_y$ for each class $y$
		\item Cost is $O(nm^2)$ for $m$ classes and $n$ features
	\end{itemize}
	\item Naïve Bayes
	\begin{itemize}
		\item Assumes $x_j$ is conditionally independent given $y$
		\begin{eqn}
			P(x_j | y) = P(x_j | y, x_k) \forall j, k
		\end{eqn}
		\item Still one $\Sigma_y$ per class, but they are diagonal
		\item Cost is $O(nm)$ for $m$ classes and $n$ features
	\end{itemize}
	\item Laplace smoothing
	\begin{itemize}
		\item Replace maximum likelihood estimator:
		\begin{eqn}
			&\text{Before:} \\
			&Pr(x_j | y = 1) = \frac{(\text{number of instances with } x_j = 1 \text{ and } y = 1)}{(\text{number of examples with } y = 1)} \\
			&\text{After:} \\
			&Pr(x_j | y = 1) = \frac{(\text{number of instances with } x_j = 1 \text{ and } y = 1) + 1}{(\text{number of examples with } y = 1) + 2}
		\end{eqn}
		\item Allows data we previously did not encounter to have a probability greater than 0
	\end{itemize}
\end{itemize}

\section{Evaluation}

\subsection{Evaluating Classification}

\begin{itemize}
	\item True positive (m11) - expect 1, predict 1
	\item False positive (m01) - expect 0, predict 1; type I error
	\item True negative (m00) - expect 0, predict 0
	\item False negative (m10) - expect 1, predict 0; type II error
	\item
	\begin{eqn}
		&\text{Error rate} &&\frac{m01 + m10}{m} \\
		&\text{Accuracy} &&\frac{TP + TN}{ALL} \\
		&\text{Precision} \qquad &&\frac{TP}{TP + FP} \\
		&\text{Recall/Sensitivity} &&\frac{TP}{TP + FN} \\
		&\text{Specificity} &&\frac{TN}{FP + TN} \\
		&\text{False positive rate} &&\frac{FP}{FP + TN} \\
		&\text{F1 measure} &&F = 2 \cdot \frac{precision \cdot recall}{precision + recall}
	\end{eqn}

	\item Receiver operating characteristic (ROC)
	\begin{itemize}
		\item Plot true negative and true positive prediction rates based on a moving boundary
		\item Comparison done by looking at area under ROC curve (AUC)
		\item In a perfect algorithm, $AUC = 1$; for random algorithms, $AUC = 0.5$
	\end{itemize}
\end{itemize}

\subsection{Evaluating Regression}

\begin{itemize}
	\item Mean Square Error
	\begin{eqn}
		MSE = \frac{1}{n} \Sigma_{i=1}^n (\hat{y}_i - y_i)^2
	\end{eqn}
	\item Root Mean Square Error
	\begin{eqn}
		RMSE = \sqrt{\frac{1}{n} \Sigma_{i=1}^n (\hat{y}_i - y_i)^2}
	\end{eqn}
	\item Mean Absolute Error
	\begin{eqn}
		MAE = \frac{1}{n} \Sigma_{i=1}^n \abs{\hat{y}_i - y_i}
	\end{eqn}
\end{itemize}

\section{Regularization}

\begin{itemize}
	\item High bias - simple model
	\item High variance - overly complex model
	\item Regularization
	\begin{itemize}
		\item Reduce overfitting
		\item Reduce variance at the cost of bias
	\end{itemize}
\end{itemize}

\subsection{L2 Regularization}

\begin{itemize}
	\item Aka ridge regression
	\begin{eqn}
		\hat{w}^{ridge} &= argmin_w (\Sigma_{i=1:n}(y_i - w^T x_i)^2 + \lambda \Sigma_{j=0:m} w_j^2) \\
		&= (X^T X + \lambda I)^{-1} X^T Y
	\end{eqn}
	\begin{itemize}
		\item $\lambda$ can be selected manually or by cross validation
		\item Not equivariant under scaling of data; typically need to normalize inputs first
		\item Can also modify penalty by adding penalty term $2\lambda w$
		\begin{eqn}
			\frac{\partial Err(w)}{\partial w} &= 2(X^T Xw - X^T Y) + \underline{2 \lambda w}
		\end{eqn}
		\item Tends to lower all weights
	\end{itemize}
\end{itemize}

\subsection{L1 Regularization}

\begin{itemize}
	\item Aka lasso regression
	\begin{eqn}
		\hat{w}^{lasso} = argmin_w (\Sigma_{i=1:n}(y_i - w^T x_i)^2 + \lambda \Sigma_{j=1:m} \abs{w_j})
	\end{eqn}
	\item More computationally expensive than L2
	\item Sets the weights of less relevant input features to 0
	\item Can also modify penalty by adding penalty term $\lambda sign(w)$ where
	\begin{itemize}
		\item $sign(x) = 1$ if $x > 0$
		\item $sign(x) = 0$ if $x = 0$
		\item $sign(x) = -1$ if $x < 0$
	\end{itemize}
\end{itemize}

\divider

\begin{itemize}
	\item Elastic net combines L2 and L1
\end{itemize}

\section{Decision Trees}

\begin{itemize}
	\item Nodes represent partitions
	\item Internal nodes are tests based on different features
	\begin{itemize}
		\item Typically branch on all possibilities for discrete features
		\item Typically branch on threshold values for continuous features
	\end{itemize}
	\item Leaf nodes include set of training examples satisfying all tests along the branch
	\item Can express every boolean function; goal is to encode functions compactly
	\item Typically constructed sing recursive top-down procedure + pruning to avoid overfitting
	\item Advantages: fast, easy to interpret, accurate
	\item Disadvantages: sensitive to outliers, bad for learning functions with smooth, curvilinear boundaries
	\item Approach
	\begin{enumerate}
		\item If training instances have same class, create leaf with that class label and exit
		\item Else, pick best test to split on
		\item Split training data
		\item Recurse on 1-3 for each subset
	\end{enumerate}
\end{itemize}

\subsection{Finding Best Test}

\begin{itemize}
	\item If event $E$ with probability $P(E)$ has occurred with certainty, we received $I(E)$ bits of information, where
	\begin{eqn}
		I(E) = log_2 \frac{1}{P(E)}
	\end{eqn}
	\item Events with smaller probabilities produce more bits of information
	\item Entropy (H(S))- average amount of information from source $S$, which emits symbols $\{s_1, ..., s_k\}$ with probabilities $\{p_1, ..., p_k\}$
	\begin{eqn}
		H(S) = \Sigma_i p_i I(s_i) = - \Sigma_i p_i log_2 p_i
	\end{eqn}
	\item Conditional entropy
	\begin{eqn}
		H(y | x) = \Sigma_v P(x = v) H(y | x = v)
	\end{eqn}
	\item Information gain - reduction in entropy obtained by knowing $x$
	\begin{eqn}
		IG(x) = H(D) - H(D | x)
	\end{eqn}
	\item Binary Classification
	\begin{itemize}
		\item Given $p$ positive samples and $n$ negative samples:
		\begin{eqn}
			H(D) = -\frac{p}{p + n} log_2 \frac{p}{p + n} - \frac{n}{p + n} log_2 \frac{n}{p + n}
		\end{eqn}
		\item Example: Given 40 examples with 30 positive and 10 negative, as well as a test $T$ that divides to [15+, 7-] for true and [15+, 3-] for false, we obtain entropy
		\begin{eqn}
			H(D | T) = \frac{22}{40}\left[ -\frac{15}{22} log_2 \frac{15}{22} - \frac{7}{22} log_2 \frac{7}{22} \right] + \frac{18}{40} \left[ -\frac{15}{18} log_2 \frac{15}{18} - \frac{3}{18} log_2 \frac{3}{18} \right] = 0.788
		\end{eqn}
	\end{itemize}
	\item For classification, choose test with highest information gain
	\item For regression, choose test with lowest MSE
	\item For real-valued features, can select possible thresholds based on midpoints of data values
\end{itemize}

\subsection{Avoiding Overfitting}

\begin{itemize}
	\item Remove some nodes for better generalization
	\item Early stopping - stop growing tree if splits do not improve information gain of validation step
	\item Post pruning - grow full tree then remove lower nodes with low information gain on validation set (generally better)
	\begin{itemize}
		\item For each node:
		\item Evaluate validation set accuracy if subtree is pruned
		\item Greedily remove nodes that most improve validation set accuracy
		\item Replace removed node by leaf with majority class of corresponding examples
		\item Stop when pruning hurts validation set accuracy
	\end{itemize}
\end{itemize}

\section{Features}

\begin{itemize}
	\item Strategies
	\begin{itemize}
		\item Domain knowledge to construct ``add hoc'' features
		\item Normalization
		\item Non-linear expansions
		\item Regularization
	\end{itemize}
	\item NLP Features
	\begin{itemize}
		\item Words (binary, absolute frequency, relative frequency)
		\item TF-IDF
		\item N-grams
		\item Syntactic features
		\item Word embeddings
		\item Stopwords (common words that may not provide much information)
		\item Lemmatization (inflectional morphology)
	\end{itemize}
	\item Approaches
	\begin{itemize}
		\item Wrapper \& filter - applied during preprocessing
		\item Embedded - integrated in optimization method (eg regularization)
	\end{itemize}
\end{itemize}

\subsection{Principal Component Analysis (PCA)}

\begin{itemize}
	\item Project data into lower-dimensional sub-spaces
	\item Solves
	\begin{eqn}
		argmin_{W, U} \Sigma_{i=1:n} \norm{X - XWU^T}^2
	\end{eqn}
	\item Solution $W$ given by eigen-decomposition of $X^T X$; columns are orthogonal
\end{itemize}

\subsection{Variable Ranking}

\begin{itemize}
	\item Rank features using scoring features; select the highest ranked features
	\item Simple \& fast, but requires a scoring function
	\item Scoring functions
	\begin{itemize}
		\item Correlation
		\item Mutual information (finds  nonlinear relationships)
	\end{itemize}
\end{itemize}

\section{Instance Learning}

\begin{itemize}
	\item Parametric supervised learning
	\begin{itemize}
		\item Assumes we have labelled examples
		\item Learns parameter vector of fixed size
	\end{itemize}
	\item Non-parametric learning
	\begin{itemize}
		\item Store all training examples $\langle x_i, y_i \rangle$
		\item With new query, compute value based on most similar points
		\item Requires distance function (eg euclidian distance)
		\begin{itemize}
			\item Often domain specific
			\item May require feature preprocessing
			\item Can sometimes be learned
		\end{itemize}
	\end{itemize}
\end{itemize}

\subsection{One-Nearest Neighbour}

\begin{itemize}
	\item Lazy learning - generalization upon query
	\item Requires no learning (just store data)
	\item For new point $x_{new}$, find nearest sample $x_{i^*} = argmin_i d(x_i, x)$ and predict $y_{new} = y_{i^*}$
	\item Essentially results in a decision boundary where each boundary is equidistance between two points of opposite classes
\end{itemize}

\subsection{K-Nearest Neighbour (KNN)}

\begin{itemize}
	\item Requires no learning (just store data)
	\item For new point $x_{new}$, find $k$ nearest training samples
	\item For regression, predict mean/median of neighbouring $y$ values
	\item For classification, predict majority or empirical probability of each class
	\item Low k results in low bias and high variance
	\item High k results in high bias and low variance
	\item Sensitive to small variations
\end{itemize}

\subsection{Distance-Weighted (kernel-based) NN}

\begin{itemize}
	\item For new point $x_{new}$, compute $w_i = w(d(x_i, x_{new}))$ for all $x_i$ in training data, where $d$ is a weighting function and predict $y = \dfrac{\Sigma_i w_i y_i}{\Sigma_i w_i}$
	\item Example of a weighting function is the inverse euclidean distance
	\item For gaussian weighting, bigger $\sigma$ results in more variance
\end{itemize}

\divider

\begin{itemize}
	\item Instance based learning is useful when
	\begin{itemize}
		\item A good distance metric exists
		\item There aren't too many attributes per instance (otherwise distances will be similar, leading to noise)
	\end{itemize}
\end{itemize}

\section{Support Vector Machines (SVM)}

\subsection{Perceptron}

\begin{eqn}
	h_w(x) = sign(w^T x)
\end{eqn}

\begin{itemize}
	\item Outputs +1 if $w^T x \ge 0$, -1 otherwise
	\item Decision boundary is $w^T x = 0$
	\item Gradient-descent learning
	\begin{eqn}
		Err(w) = \Sigma_{i=1:n} \left\{ 0 \text{ if } y_i w^T x_i \ge 0; -y_i w^T x \text{ otherwise} \right\}
	\end{eqn}
	\begin{itemize}
		\item Error is 0 for correctly classified example
		\item Error shows how much to shift for incorrectly classified example
		\item Error is 0 if all examples are classified correctly
	\end{itemize}
	\item Learning converges within finite number of updates for linearly separable datasets; otherwise, there will be oscillation
	\item Dual representation
	\begin{eqn}
		w = \Sigma_{i=1:n} \alpha_i y_i x_i
	\end{eqn}
	\begin{itemize}
		\item $\alpha_i$ is sum of step sizes used for all updates applied to example $i$
	\end{itemize}
	\item Solution often non-unique; depends on order of updates
\end{itemize}

\subsection{Linear SVM}

\begin{itemize}
	\item Choose $w$ such that margin is maximized
	\item Margin is twice the Euclidean distance from hyper-plane to nearest training example
	\item Let $\gamma_i$ be the distance from $x_i$ to decision boundary, connected at point $x_i^0$. Let $w$ be the normal to the decision boundary. We can define:
	\begin{eqn}
		x_i^0 = x_i - \frac{\gamma_i w}{\norm{w}}
	\end{eqn}
	\begin{itemize}
		\item $\dfrac{w}{\norm{w}}$ is the unit normal
		\item $\gamma_i$ is the scalar distance from $x_i$ to $x_i^0$
	\end{itemize}
	\item Goal is to minimize $\frac{1}{2} \norm{w}^2$ with respect to $w$ such that $y_i w^T x_i \ge 1$
	\item \todo{Lagrangian optimization; 439}
	\item Support vectors - points lying on edge of margin, affecting the decision boundary
	\item \todo{Hinge loss; 461}
	\item Multiple classes
	\begin{itemize}
		\item One-vs-all - learn K separate binary classifiers
		\begin{itemize}
			\item Can be inconsistent
			\item Training sets are imbalanced
		\end{itemize}
		\item Multi-class SVM
	\end{itemize}
\end{itemize}

\section{Ensembles}

Run base algorithms multiple times, then combine predictions for a final prediction

\subsection{Bagging}

\begin{itemize}
	\item Create K independent models by training same base algorithm on different subsets of training data
	\item Reduces variance, increases bias
	\item Good for ``reasonable'' classifiers
	\item Bootstrapping - cross-validation but using random sampling with replacement
	\begin{itemize}
		\item For new dataset, randomly select value from full dataset with replacement until size is sufficient
	\end{itemize}
	\item Incremental construction
	\begin{itemize}
		\item Hypotheses should not be constructed independently
		\item New hypotheses should focus on problematic instances
	\end{itemize}
	\item Random forest
	\begin{itemize}
		\item Use K bootstrap replicates to train K different trees
		\item For each node, pick $m$ variables at random (where $m < M$, $M$ being the total number of features)
		\item Determine best test using normalized information gain
		\item Recurse until depth is reached without pruning
		\item Resulting trees have high variance, but ensemble uses average, which reduces variance
		\item Fast \& can handle lots of data
		\item Can circumvent difficulties in optimization
		\item Low interpretability
		\item New predictions may be more expensive (need to go through all trees)
	\end{itemize}
\end{itemize}

\subsection{Boosting}

\begin{itemize}
	\item Incrementally train K models, where each successive model tries to fix mistakes of previous models
	\item Reduces bias \& increases classification margin
	\item Tends not to overfit
	\item Good for very simple classifiers
	\item Problematic if lots of data is mislabelled
	\item Algorithm
	\begin{itemize}
		\item Train simple predictor
		\item Re-weight training examples, putting more weight on those that were not properly classified
		\item Repeat n times
	\end{itemize}
	\item Adaboost adapts error rate to reduce training error exponentially fast
\end{itemize}

\subsection{Stacking}

\begin{itemize}
	\item Stacking - train K different models and combine their output
	\item Predictions from base models become features of new meta-model
	\item Works well when base models have complimentary strengths and weaknesses
\end{itemize}

\section{Neural Networks}

\begin{itemize}
	\item A single perceptron can represent linear boundaries, but cannot represent non-linearly separated functions like XOR.
	However, stacking perceptrons to create new datasets allows more functions to become linearly separable
	\item Sigmoid function provides ``soft threshold'', whereas perceptron provides ``hard threshold''
	\item Feed-forward neural network
	\begin{itemize}
		\item Connections from one layer to the next in one direction; no connections between units of the same layer
		\item Hidden units are $h_i = \sigma(w_i^T x + b_i), \forall i$
		\item Unlike stacking, we jointly train the entire network
		\item Can have multiple output units
		\item Depth - number of layers
		\item Fully-connected - if all units in layer $j$ provide input to all units in layer $j + 1$
	\end{itemize}
	\item Neural network with two hidden layers can approximate any function to arbitrary accuracy
	\item Activation function can be an arbitrary non-linear function, not just limited to sigmoid
\end{itemize}

\subsection{Gradient Descent}

\begin{itemize}
	\item Used to minimize errors, as hypothesis is differentiable and too complex to compute optimal weights directly
	\item Stochastic gradient descent
	\begin{enumerate}
		\item Initialize weights to small random numbers
		\item Pick single training example $x$
		\item Feed example then compute correction
		\item Compute correction for output unit
		\begin{eqn}
			\frac{\partial J}{\partial w_{out}} = \delta_{out} x
		\end{eqn}
		\item Compute correction for each hidden unit $j$
		\begin{eqn}
			\frac{\partial J}{\partial w_j} = \delta_{out} w_{out, j} \sigma(w_j^T x + b)(1 - \sigma(w_j^T x + b))x
		\end{eqn}
		\item Update each network weight
		\begin{eqn}
			w_j &= w_j - \alpha \frac{\partial J}{\partial w_j} \forall j \\
			w_{out} &= w_{out} - \alpha \frac{\partial J}{\partial w_{out}}
		\end{eqn}
		\item Repeat from step 2 until convergence
	\end{enumerate}
	\item Batch gradient descent
	\begin{itemize}
		\item Compute error on all examples
		\item Loop through training data, accumulating weight changes
		\item Update all weights and repeat
	\end{itemize}
	\item Mini-batch gradient descent
	\begin{itemize}
		\item Compute error on randomly selected subset
	\end{itemize}
\end{itemize}

\section{Backpropagation}

\subsection{Activation Functions}

\begin{itemize}
	\item Sigmoid
	\begin{eqn}
		\phi(z) = \frac{1}{1 + e^{-z}}
	\end{eqn}
	\begin{itemize}
		\item Easy to differentiate
		\item Easily saturates; inputs outside of [-4, 4] remain essentially constant, making it hard to train
	\end{itemize}
	\item Tanh
	\begin{eqn}
		\phi(z) = tanh(z) = \frac{e^z - e^{-z}}{e^z + e^{-z}}
	\end{eqn}
	\begin{itemize}
		\item Easy to differentiate ($1 - tanh^2(z)$)
		\item Slightly less prone to saturation than sigmoid
	\end{itemize}
	\item ReLU
	\begin{eqn}
		ReLU(z) = max(z, 0)
	\end{eqn}
	\begin{itemize}
		\item Unbounded range; never saturates
	\item De facto standard
	\end{itemize}
	\item Softplus
	\begin{eqn}
		softplus(z) = ln(1 + e^x)
	\end{eqn}
	\begin{itemize}
		\item Similar to ReLU but smoother
		\item Expensive derivative compared to ReLU
	\end{itemize}
\end{itemize}

\subsection{Derivatives}

\begin{itemize}
	\item Tell us how much we impact another node if we change one node by one unit
	\item For non-neighbouring nodes, sum over all possible paths from one node to the other, multiplying derivatives on each edge of the path
	\item Computationally intensive, so we can instead factor paths by summing derivatives of all inputs to a node first
	\item Forward mode - start from source, and at each node, sum all incoming edges/derivatives
	\item Reverse mode - start from sink, and at each node, sum all outgoing edges/derivatives
	\item Both only touch each edge once, but since we want derivatives of the output/loss with respect to all previous layers, reverse mode is better
	\item Reverse-mode automatic differentiation (RV-AD) = backpropagation
\end{itemize}

\divider

\begin{itemize}
	\item Guaranteed convergence to local minimum
	\item Use random restarts to find better minimum
	\item Overtraining occurs if weights take on large magnitudes; \# of training updates is also a hyper-parameter
	\item Adaptive optimization algorithms change learning rates for each parameter based on history of gradient updates
\end{itemize}

\subsection{Momentum}

On $i^{th}$ gradient descent, add momentum (second term)

\begin{eqn}
	\Delta_i w = \alpha \frac{\partial J}{\partial w} + \beta \Delta_{i-1}w
\end{eqn}

\begin{itemize}
	\item Allows us to pass small local minima
	\item Keeps weights moving if error is flat
	\item However, can get out of a global maximum
	\item Is tunable, increasing chance of divergence
\end{itemize}

\section{Convolutional Neural Network (CNN)}

\begin{itemize}
	\item Often used in computer vision
	\item Input usually 3D tensor for 2D RGB image
	\item Local receptive fields
	\begin{itemize}
		\item Hidden unit connected to patch of input image
		\item Unit connected to all 3 colours channels
	\end{itemize}
	\item Share matrix of parameters across units
	\begin{itemize}
		\item Units within depth slice at all positions have same weights
		\item Feature map computed via discrete convolution with kernel matrix
	\end{itemize}
	\item Pooling/subsampling of hidden units in same neighbourhood
	\begin{itemize}
		\item Dimensionality reduced, making features more high-level \& abstract
	\end{itemize}
	\item Convolutional ``kernels'' aim to extract useful information (eg blurring/edge detection)
	\item Can have multiple layers, vary width/size of receptive fields, and vary stride (spacing between receptive fields)
	\item Pooling layers often added between convolutional layers; takes max of inputs in receptive fields
	\item Dropout regularization
	\begin{itemize}
		\item Helps generalize better \& reduce overfitting
		\item Independently set each hidden unit to zero with probability $p$ (often $p = 0.5$)
	\end{itemize}
	\item Batch normalization
	\begin{itemize}
		\item Compute mean \& variance independently for each dimension and normalize each input
		\item Usually done already at input layer, but this extends it to other layers
		\item Results in more stable gradient estimates
	\end{itemize}
	\item Can use softmax instead of sigmoid for multi-class classification (not the same as multi-output classification)
\end{itemize}

\subsection{Recurrent Neural Network (RNN)}

\begin{itemize}
	\item Often used in text \& speech
	\item Allows us to retain temporal information in sequences
	\item Add cycles with time delay (affects next step, to avoid infinite loops); see recurrence below [\ref{sec:recurrence}]
	\item Output types
	\begin{itemize}
		\item One at the end of the sequence (eg sentiment classification)
		\item One at each time step (eg language generation)
		\begin{itemize}
			\item Use softmax
			\item Usually add an ``end of sentence'' token for stopping
		\end{itemize}
	\end{itemize}
	\item One-hot vectors
	\begin{itemize}
		\item Map each value to column of a weight matrix
		\item Removes bias associated with categorical value
	\end{itemize}
	\item Train using backpropagation through time (BPTT)
	\begin{itemize}
		\item Same as regular backpropagation, but we unroll the computation graphto find the flow through all layers
		\item Can truncate flow by using only last k time steps
	\end{itemize}
\end{itemize}

\subsection{Recurrence}
\label{sec:recurrence}

Elman RNN

\begin{eqn}
	h_t = \sigma(Wh_{t-1} + Ux_t + b) \\
	o_t = \phi(Vh_t + c)
\end{eqn}

Jordan RNN

\begin{eqn}
	h_t = \sigma(Wo_{t-1} + Ux_t + b) \\
	o_t = \phi(Vh_t + c)
\end{eqn}

\begin{itemize}
	\item Elman usually better, as output is often constrained, resulting in information loss
\end{itemize}

\subsection{Long Short-Term Memory (LSTM)}

\begin{itemize}
	\item Long-term dependencies are hard to learn. Given that the transition matrix $W$ is the same for each step, a small offset from 1 will cause gradients to explode or vanish
	\item Can avoid exploding gradients through gradient clipping. If gradient magnitude is better than threshold, set it to $threshold * sign(gradient)$
	\item Can also use non-multiplicative interactions like LSTM (additive)
	\item LSTM has a hidden state (past info for next prediction) and cell state (past info for future predictions)
	\item Uses gates to control information flow
	\item Input gate - what info from current input \& previous hidden state do we want to transfer to cell state?
	\begin{eqn}
		i_t &= \sigma(W_i \cdot \left[ h_{t-1}, x_t \right] + b_i) \\
		\tilde{C}_t &= tanh(W_C \cdot \left[ h_{t-1}, x_t \right] + b_C)
	\end{eqn}
	\item Cell update - additive linear combination of old cell state \& processed input
	\begin{eqn}
		C_t = f_t * C_{t-1} + i_t * \tilde{C}_t
	\end{eqn}
	\item Output gate - what information from cell state do we need for next prediction?
	\begin{eqn}
		o_t &= \sigma(W_o \left[ h_{t-1}, x_t \right] + b_o) \\
		h_t &= o_t * tanh(C_t)
	\end{eqn}
	\item Use bidirectional LSTMs to increase expressiveness; apply both left-ro-right and right-to-left
	\item Can also add attention by adding connections from encoder hidden states to context vector
\end{itemize}

\divider

\begin{itemize}
	\item To produce output of a different length from input, use two RNNs. `Encoder' RNN transforms input to vector. `Decoder' RNN generates sequence from vector. Vector is often referred to as the ``context'' vector, and as used as input to the decoder at every timestep, along with the output at the previous timestep.
	\item Teacher forcing - train model by inputting ground-truth instead of input from previous iteration. No change done for testing as we don't have labels.
\end{itemize}

\end{document}