\documentclass[11pt]{article}
\usepackage{latexsym}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{epsfig}
\usepackage[right=0.8in, top=1in, bottom=1.2in, left=0.8in]{geometry}
\usepackage{listings}
\usepackage{setspace}
\usepackage{graphicx} %package to manage images
\graphicspath{ {images/} }

\spacing{1.06}


\lstset{
  basicstyle=\ttfamily,
  mathescape
}

\newcommand{\handout}[5]{
  \noindent
  \begin{center}
  \framebox{
    \vbox{\vspace{0.25cm}
      \hbox to 5.78in { {COMS E6998-9:\hspace{0.12cm}Algorithmic
          Techniques for Massive Data} \hfill #2 }
      \vspace{0.48cm}
      \hbox to 5.78in { {\Large \hfill #5  \hfill} }
      \vspace{0.42cm}
      \hbox to 5.78in { {#3 \hfill #4} }\vspace{0.25cm}
    }
  }
  \end{center}
  \vspace*{4mm}
}
\newcommand{\lecture}[4]{\handout{#1}{#2}{#3}{Scribe:\hspace{0.08cm}#4}{Lecture #1}}

\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{observation}[theorem]{Observation}
\newtheorem{example}[theorem]{Example}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{fact}[theorem]{Fact}
\newtheorem{assumption}[theorem]{Assumption}
\newcommand{\E}{\textbf{E}}
\newcommand{\var}{\text{var}}


\begin{document}

\lecture{5 -- Precision Sampling (cont), Streaming for Graphs}{Sep 22, 2015}{Instructor:\hspace{0.08cm}\emph{Alex Andoni}}{\emph{Nikhil Mitra}}

\section*{Plan}
\begin{itemize}
\item Precision Sampling (continuation)
\item Streaming for Graphs
\end{itemize}

\section{Precision Sampling (continuation)}
\subsection{Recap}
Last time we proved the prescision sampling lemma that we can (with 90\% success) get O(1) additive error and 1.5 multiplicative error :
\begin{align}
\frac { s }{ 1.5 } -O(1)<\tilde { s } <1.5s+O(1)
\end{align}
with average cost equal to O($\log{n}$)
\\
\noindent The algorithm:
\begin{itemize}
\item Draw each $u_i$ randomly from Exp(1), a probability distribution described
  roughly by $e^{-x}$
\item Return $\widetilde{S} = \max_i \widetilde{a_i}/u_i$
\end{itemize}

\subsection{Proof of correctness}
\begin{align}
max(\frac { a_{ i } }{ u_{ i } } )\sim \sum { \frac { a_i }{Exp(1)  }  } 
\end{align}
Therefore,
\begin{align}
max(\frac { \tilde { a_{ i } }  }{ u_{ i } } )\sim \frac { \sum { a_{ i } }  }{ Exp(1) } \pm 1
\end{align}

\section{p-moment via Prescision Sampling}
\subsection{Theorem}
Linear Sketch for the p-moment with O(1) approximation and $O({ n }^{ 1-2/p }){ \log ^{O(1)} { n }  }$ space (with 90\% success probability) can be found\\

\subsection{Sketch}
\begin{itemize}
\item Pick random ${ r }_{ i }\in \left\{ \pm 1 \right\} $ and $u_i\sim Exp(1) $
\item Let $y_ i = f_i\cdot r_i/u_i^{1/p}$
\item Hash into Hash Table S
\end{itemize}
\\
\includegraphics[scale=0.2]{map.png}
\\

The width of table S is w, where
\begin{align}
w=O({ n }^{ 1-2/p }){ \log ^{O(1)} { n }  }
\end{align}
\subsection{Estimator}
Use the estimator $\max _{ j }{ |{ S\left[ j \right]  }|^{ p } } $

\subsection{Algorithm}
\begin{lstlisting}
Initialize(w):
    array S[w]
    hash functions $h$,  into $[w]$
    hash functions $R$,  into $[\pm1]$
    reals $u_i$, from Exp distribution

Process(vector $f\in \Re ^n$):
    for (i = 0; i < n; ++j)
        S[$h_i$] += $\frac { f_{ i }r_{ i } }{ { u_{ i } }^{ 1/p } }$

Estimator:
    $\max _{ j }{ |{ S\left[ j \right]  }|^{ p } } $
\end{lstlisting}

\subsection{Correctness of Estimator}

\begin{theorem}
$\max _{ j }{ |{ S\left[ j \right]  }|^{ p } } $ is O(1) ￼￼approximation with 90\% probability, with $w=O({ n }^{ 1-2/p }){ \log ^{O(1)} { n }  }$ cells
\end{theorem}
\begin{proof}
To prove the theorem, we use precision sampling lemma.
\begin{align}
a_{ i }&={ |f_{ i }| }^{ p } \\
\sum { a_{ i } } &=\sum { { |f_{ i }| }^{ p } } 
\tilde { a_{ i } } /u_{ i }={ |S(H(i))| }^{ p }
\end{align}
Now we need to show that $|a_i -\tilde { a_{ i } }| $ is small. More prescisely speaking, we need to prove
\begin{align}
\left| \frac { \tilde { a_{ i } }  }{ u_{ i } } -\frac { a_{ i } }{ u_{ i } }  \right| \le \epsilon F_{ p }
\end{align}
\begin{claim}
$\left| { S(H(i)) }^{ p }-f_{ i }^{ p }/u_{ i } \right| <O(\epsilon F_{ p })$
\end{claim}
\begin{proof}
Consider cell $z = h(i)$
\begin{align}
s(z)=\frac { f_{ i }r_{ i } }{ { u_{ i } }^{ 1/p } } +C
\end{align}
Where $r_i =\pm 1$ and $u_i$ is an exponential random variable.
Now we need to estimate the value of C i.e how much chaff is there. \\
\\
Let $y(i) = \frac { f_{ i }r_{ i } }{ { u_{ i } }^{ 1/p } }$
\begin{align}
y(i) &= \frac { f_{ i }r_{ i } }{ { u_{ i } }^{ 1/p } }\\
C&=\sum _{ j\neq i }^{  }{ y_{ i } } \cdot \chi [h(j)=z]
\end{align}
Now E[C] = 0, and hence does not serve as a good indicator of value. $E[C] = 0$ because $r_i =\pm 1$. Therefore, we find out $E[C^2]$
\begin{align}
E(C^{ 2 })\quad =\quad E\left( \sum _{ j1,j2\neq i }^{  }{ Y_{ j1 }Y_{ j2 }\cdot \chi \left[ h(j1)=z \right] \cdot \chi \left[ h(j2)=z \right]  }  \right) 
\end{align}
Now all elements where $j1 \neq j2$ disappear.
\begin{align}
E(C^{ 2 }) &= E\left( \sum _{ j1,j2\neq i }^{  }{ Y_{ j }^{ 2 }\cdot \chi ^{ 2 }\left[ h(j)=z \right]  }  \right) \\
&= E\left( \sum _{ j1,j2\neq i }^{  }{ Y_{ j }^{ 2 }\frac { 1 }{ w }  }  \right) \\
&\leq \frac { \left\| y \right\| ^{ 2 } }{ w } 
\end{align}
Now,
\begin{align}
E\left[ \sum { y_{ j }^{ 2 } }  \right] &=E\left[ \sum _{ j }^{  }{ \frac { { f_{ j } }^{ 2 } }{ { u_{ j } }^{ 1/p } }  }  \right] \\
&= \sum _{ j }^{  }{ { f_{ j } }^{ 2 }E\left[ \frac { 1 }{ { u_{ j } }^{ 1/p } }  \right]  } 
\end{align}
Now, using the concavity property of the function,
\begin{align}
&\leq \sum _{ j }^{  }{ { f_{ j } }^{ 2 }{ (\log { n } ) }^{ 1/p } } 
\end{align}
Now, Using Holder's inequality, we can write
\begin{align}
\left\| f \right\| ^{ 2 }\le { n }^{ 1-2/p }{ \left\| f \right\|  }_{ p }^{ 2 }
\end{align}
Using Markov's, we can write
\begin{align}
C^{ 2 }\le { \left\| f \right\|  }_{ p }^{ 2 }\cdot { n }^{ 1-2/p }\cdot O(\log { n } )/w
\end{align}
Setting $w=\frac { 1 }{ { \epsilon  }^{ 2/p } } { n }^{ 1-2/p }\cdot O(\log { n } )$
\begin{align}
\left| C \right| ^{ p }<{ \left\| f \right\|  }_{ p }^{ p }=\epsilon F_{ p }
\end{align}
\end{proof}
\end{proof}
\subsection{Recap}
\begin{itemize}
\item We claimed $\left| { S(H(i)) }^{ p }-f_{ i }^{ p }/u_{ i } \right| <O(\epsilon F_{ p })$
\item ${ S(H(i)) }^{ p }={ \left( \frac { f_{ i } }{ { u_{ i } }^{ 1/p } } +C \right)  }^{ p }$, where $C=\sum _{ j\neq i }^{  }{ y_{ i } } \cdot \chi [h(i)=h(j)]$

\item We proved $E(C^{ 2 })\leq \frac { \left\| y \right\| ^{ 2 } }{ w } $. This implies that $\left| C \right| ^{ p }<\epsilon F_{ p }$ with 90\% probability for a fixed i. But we need it for all i.

\item What we want is a $\left| C \right| ^{ 2 }<\beta { \left\| y \right\|  }^{ 2 }/w$ with high probability for a smallish w. We can indeed prove that $\beta =O(\log^2 { n } )$ using a strong concentration inequality (Bernstein)
\end{itemize}
\includegraphics[scale=0.4]{comp_scale.png}

\section{Streaming for Graphs}
\subsection{Graphs}
Suppose we have a graph G with $n$ vertices and $m$ edges. Suppose the data stream is of the list of edges. There are multiple such examples where such graphs are used to model the data. For example,
\begin{itemize}
\item Web
\item Socialgraphs
\item Phonecalls
\item Maps
\item Geographical data etc.
\end{itemize}
\subsection{Why Streaming for Graphs}
Suppose we have a graph G which consists of a large number of vertices and even larger number of edges. It is typical to store such graphs on the hard drive. The usual algorithms for graphs (e.g. breadth first search) are typically random access.If we used a streaming algorithm, we would need to do a linear scan through all the edges. For typical hard drives, linear scan is much more efficient than random access. Further, most of the usual graph algorithms use random access. Some problems associated with graphs are
\begin{itemize}
\item Connectivity
\item Distances (similarities) between nodes
\item PageRank (stationary distribution of random walk) \item Counting \# of triangles (measure of clusterability) – Various other statistics
\item Matchings
\item Graph partitioning
\end{itemize}

\subsection{Parameters for graph algorithms}
The usual aim of streaming graph algorithms is to use $O(n)$ space or $O(n\log{n})$. An $O(n\log{n})$ algorithm would still take much less space than an $O(m)$ algorithm, because $m$ can be of the order of $n^2$.
\\
\\
The usual space bound for streaming algorithms, which is sublinear, is generally not possible.

\subsection{Problem 1: Connectivity}
The problem is stated as, Given a graph G, check wether the graph G is connected. Using a streaming approach, we can do it on $O(n)$ space.
\\
\\
The basic idea is to use a minimum spanning tree of the graph. The algorithm can be stated as
\begin{itemize}
\item Keep a subgraph $H$ (starts empty)
\item When we see an edge (i,j), if this edge does not create a cycle in $H$, then add it to $H$
\end{itemize}
Space: $\leq n-1$ edges only.
\\
\\
This subgraph $H$ can be used to 
\begin{itemize}
\item find connectivity between 2 nodes
\item number of connected components
\end{itemize}

\subsection{Problem 2: Distance}
The problem can be stated as, given a graph G and 2 nodes s,t in it, find the distance between them upto and approximation of $\alpha$, where $\alpha$ is an odd integer.
\\
\\
We can do this with slight modification to the previous algorithm.
\begin{itemize}
\item Keep a subgraph $H$
\item When we encounter edge (i,j), if $d_h(i,j) > \alpha$, then add it to $H$.
\\
\end{itemize}
With regards to the space complexity, we can see that all cycles in $H$ have length $\gte \alpha +2$, then according to Bollobas' theorem, $\left| H \right| \le O({ n }^{ 1+\frac { 2 }{ \alpha +1 }  })$
\begin{theorem}
(Bollobas) If all cycles in a graph are of length $\gte \alpha +2$, then $\left| H \right| \le O({ n }^{ 1+\frac { 2 }{ \alpha +1 }  })$
\end{theorem}
\begin{proof}
For a simplified case, let us assume all nodes have degree $d$.
\begin{itemize}
\item Suppose $\alpha = 2k-1$
\item Explore a vertex v.
\item At depth k, all nodes differ. Therefore, 
\begin{align}
d^k  &\le n\\
d &= n^(1/k)\\
m &\le n^{1+1/k}\\
  &= n^{ 1+\frac { 2 }{ 1+\alpha  }  }
\end{align}
\end{itemize}
\end{proof}
\end{document}