\documentclass[11pt]{article}

\usepackage[normalem]{ulem}
\usepackage{classDM}
\usepackage{hyperref}

\newcommand{\JS}{\ensuremath{\textsf{\small JS}}}
\newcommand{\Ham}{\ensuremath{\textsf{\small Ham}}}
\newcommand{\Andb}{\ensuremath{\textsf{\small Andb}}}
\newcommand{\Dice}{\ensuremath{\textsf{\small S-Dice}}}

\title{Asmt 3: Distances and LSH}
\author{Turn in through Canvas by 2:45pm, then come to class: \\
Wednesday, February 5 \\
100 points}
\date{}


\begin{document}
\maketitle





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{Overview}

In this assignment you will explore LSH and Euclidean distances.  

You will use a data set for this assignment:
\begin{itemize} \denselist
\item \href{http://www.cs.utah.edu/~jeffp/teaching/cs5140/A3/R.csv}{\texttt{http://www.cs.utah.edu/\~{}jeffp/teaching/cs5140/A3/R.csv}}
\end{itemize}

\vspace{.1in}

\emph{It is recommended that you use LaTeX for this assignment (or other option that can properly digitally render math).  If you do not, you may lose points if your assignment is difficult to read or hard to follow.  Find a sample form in this directory:
\url{http://www.cs.utah.edu/~jeffp/teaching/latex/}}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Choosing $r,b$ (35 points)}

Consider computing an LSH using $t = 160$ hash functions.  We want to find all object pairs which have Jaccard similarity above $\tau = .85$.  

\paragraph{A: (15 points)} 
Use the trick mentioned in class and the notes to estimate the best values of hash functions $b$ within each of $r$ bands to provide the S-curve 
\[
f(s) = 1- (1-s^b)^r
\]
with good separation at $\tau$.  Report these values.  

\paragraph{B: (15 points)}
Consider the $4$ objects $A,B,C,D$, with the following pair-wise similarities:
\begin{center}
\begin{tabular}{r||cccc}
& A & B & C & D
\\ \hline
A & 1 & 0.77 & 0.25 & 0.33\\
B & 0.77 & 1 & 0.20 & 0.55 \\
C & 0.25 & 0.20 & 1 & 0.91 \\
D & 0.33 & 0.55 & 0.91 & 1\\
\end{tabular}
\end{center}

Using your choice of $r$ and $b$ and $f(\cdot)$, what is the probability of each pair of the four objects for being estimated to having similarity greater that $\tau = 0.85$?  
Report $6$ numbers.  
\emph{(Show your work.)}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Generating Random Directions  (30 points)}

\paragraph{A:  (10 points)}
Describe how to generate a single random unit vector in $d=10$ dimensions using only the operation $u \leftarrow \mathsf{unif}(0,1)$ which generates a uniform random variable between $0$ and $1$.  
\emph{(This can be called multiple times.)}


\paragraph{B:  (20 points)}
Generate $t = 160$ unit vectors in $\mathbb{R}^d$ for $d=100$.    Plot of cdf of their pairwise dot products (yes, you need to calculate ${t \choose 2}$ dot products).  





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Angular Hashed Approximation (35 points)}

Consider the $n = 500$ data points in $\mathbb{R}^d$ for $d=100$ in data set $R$, given at the top.  We will use the angular similarity, between two vectors $a,b \in \mathbb{R}^d$:
\[
\s{s}_\mathrm{ang}(a,b) = 1- \frac{1}{\pi} \arccos(\langle \bar a, \bar b \rangle) 
\]
If $a,b$ are not unit vectors (e.g., in $\mathbb{S}^{d-1}$), then we convert them to 
$\bar a = a/\|a\|_2$ and $\bar b = b/\|b\|_2$.  The definition of $\s{s}_\mathrm{ang}(a,b)$ assumes that the input are unit vectors, and it takes a value between $0$ and $1$, with as usual $1$ meaning most similar.  

\paragraph{A: (15 points)} 
Compute all pairs of dot products \emph{(Yes, compute ${n \choose 2}$ values)}, and plot a cdf  of their angular similarities.  
Report the number with angular similarity more than $\tau =0.85$.  



\paragraph{B:  (20 points)}
Now compute the dot products and angular similarities among ${t \choose 2}$ pairs of the $t$ random unit vectors from \s{Q2.B}.  Again plot the cdf, and report the number with angular similarity above $\tau = 0.85$.  





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Bonus (3 points)}

Implement the banding scheme with your choice of $r,b$, using your $t=160$ random vectors,  to estimate the pairs with similarity above $\tau = 0.85$ in the data set $R$.  Report the fraction found above $\tau = 0.85$.  Compare the runtime of this approach versus a brute force search.  

\end{document}
