\documentclass{article}
\usepackage{amssymb}
\usepackage{amsmath}
%\usepackage{slide-article-tom}
\usepackage[landscape]{slide-article-tom}

\usepackage{amsthm}
\newtheorem{thm}{Theorem}

\ifx\pdfoutput\undefined
     \usepackage[dvips]{graphicx}
\else
     \usepackage[pdftex]{graphicx}
     \pdfcompresslevel 9
\fi

\usepackage[all]{xy}
\setlength{\unitlength}{1cm}


\usepackage{fixltx2e}

\usepackage{wrapfig}


\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,arrows,shapes.arrows,shapes.gates.logic.US,shapes.gates.logic.IEC}
\usepackage{calc}
\usepackage{circuitikz}

\tikzset{
%MyCube/.style={scale=1.0,x={(-.4cm,-0.3cm)},y={(0.6cm,-0.3cm)},z={(0.2cm,0.7cm)}},	
MyCube/.style={scale=1.0,x={(-0.55cm,-0.3cm)},y={(1cm,0cm)},z={(0cm,1cm)}},
	MyFaceA/.style={green!70!,draw=black},
	MyFaceB/.style={blue!50!,draw=black},
	MyFaceC/.style={blue!30!green!30!,draw=black}
	}

\newcommand{\cube}[4]{%
	% parameters #1,#2,#3 = coordinates of the center, parameter #4 = length of edge
 	\pgfmathparse{0.5*#4}%
	\let\sd\pgfmathresult{}%
 	\coordinate (A) at ({#1+\sd},{#2+\sd},{#3+\sd});
 	\coordinate (E) at ({#1+\sd},{#2+\sd},{#3-\sd});
	\coordinate (B) at  ({#1+\sd},{#2-\sd},{#3+\sd});
	\coordinate (F) at  ({#1+\sd},{#2-\sd},{#3-\sd});
	\coordinate (C) at  ({#1-0.7*\sd},{#2-0.7*\sd},{#3+\sd});
	\coordinate (G) at  ({#1-\sd},{#2-\sd},{#3-\sd});
 	\coordinate (D) at ({#1-0.7*\sd},{#2+\sd},{#3+\sd});
 	\coordinate (H) at ({#1-0.7*\sd},{#2+\sd},{#3-0.7*\sd});
	\fill[MyFaceA] (A)--(E)--(H)--(D)--cycle;
	\fill[MyFaceB] (A)--(B)--(C)--(D)--cycle;
	\fill[MyFaceC] (A)--(B)--(F)--(E)--cycle;
	\draw (A)--(E)--(H)--(D)--cycle;
	\draw (D)--(C)--(B)--(A);
	\draw (B)--(F)--(E);
}

\usepackage[titles]{tocloft}
\setlength{\cftbeforesecskip}{-2ex}
\setlength{\cftbeforesubsecskip}{-2ex}

\usepackage{hyperref}

\hypersetup{colorlinks,
            linkcolor=blue,
            citecolor=blue,
            %pdfpagemode=FullScreen
            pdfpagemode=UseNone
            }


%\newcommand\@linkcolor{red}
%\newcommand\@linkcolor{blue}
%\newcommand\@anchorcolor{black}
%\newcommand\@citecolor{red}
%\newcommand\@filecolor{cyan}
%\newcommand\@urlcolor{magenta}
%\newcommand\@menucolor{red}
%\newcommand\@pagecolor{red}


\newcommand\pagedone{\newpage}

\newcommand\tthdump[1]{#1}


\newcommand\sectionhead[1]{\begin{center}\section*{#1 \hyperlink{Contents}{\hfil$\leftarrow$}}
             \end{center}
     \addcontentsline{toc}{section}{#1}
     \vspace{-\baselineskip}
     }
     
\newcommand\subsectionhead[1]{\begin{center}\subsection*{#1 \hyperlink{Contents}{\hfil$\leftarrow$}}
             \end{center}
     \addcontentsline{toc}{subsection}{#1}
     \vspace{-\baselineskip}
     }
     
\newcommand\cyrsubsectionhead[1]{\begin{center}\subsection*{#1 \hyperlink{Contents}{\hfil$\leftarrow$}}
             \end{center}
     \addcontentsline{toc}{subsection}{#1}
     \vspace{-\baselineskip}
     }


\newcommand\exercises[1]{\begin{center}\subsection*{#1 -~exercises
            \hyperlink{Contents}{\hfil$\leftarrow$}}\end{center}
    \addcontentsline{toc}{subsection}{#1 (exercises)}
     \vspace{-\baselineskip}
     }
     

\newcommand\quotesection[1]{\begin{center}{\LARGE\hypertarget{#1}
     {#1}\hyperlink{The quotes}{\hfil$\twoheadleftarrow$}}\end{center}}

\newcommand\httimes{\times}

\newcommand\mybigtriangledown{\bigtriangledown}

\newcommand\htvec[1]{\vec{#1}}

\newcommand\myspan{\mathrm{span}}
\newcommand\mymatrix{\mathrm{matrix}}

\newcommand\myreal{\mathbb{R}}

\newcommand\mycomplex{\mathbb{C}}
\newcommand\myfield{\mathbb{F}}
\newcommand\myquaternions{\mathbb{H}}
\newcommand\myrationals{\mathbb{Q}}
\newcommand\myintegers{\mathbb{Z}}

%\newcommand\dim\mathrm{dim}
\newcommand\im{\mathrm{im}}
\newcommand\deriv{\mathrm{D}}
\newcommand\trace{\mathrm{trace}}
\newcommand\detm{\mathrm{det}_m}
\newcommand\detv{\mathrm{det}_v}
\newcommand\perm{\mathrm{perm}}
\newcommand\sign{\mathrm{sign}}

% kets and bras etc.
\newcommand\ket[1]{|{#1}\rangle}
\newcommand\bra[1]{\langle{#1}|}
\newcommand\braket[2]{\langle{#1}|{#2}\rangle}

%boolean operators
\newcommand\myand{$\wedge$ }
\newcommand\myor{$\vee$ }

% defines a 2 element column vector.
\newcommand\col[2]{\left(\begin{array}{c}#1\\#2\end{array}\right)}
\newcommand\tcol[2]{(#1, #2)^T}

\begin{document}
\raggedright

\pagestyle{myfooters}
%\pagestyle{plain}

\thispagestyle{empty}

%Slide 1
\title{{\LARGE\bf A Surprising Fact About Friendship}\newline
}
\author{
\begin{wrapfigure}{r}{0.35\textwidth}
  \vspace{-2cm}
  \begin{center}
    {\fontsize{5}{5}\selectfont  
       http://csustan.csustan.edu/\~\ tom
    }
   {\hyperref{http://csustan.csustan.edu/\~tom}{}{}
     {    \includegraphics[width=0.2\textwidth]{tom-carter-QR-pic.png}
     }
   }
  \end{center}
  \end{wrapfigure}
      Tom Carter \newline
      \newline
     Computer Science \newline
     CSU Stanislaus\newline
\newline
{\hyperref{mailto:tom@csustan.csustan.edu}{}{}
     {tom@csustan.csustan.edu}}
\vfill
{\hyperref{http://csustan.csustan.edu/\~tom/Lecture-Notes/Friendship-paradox/Friendship-paradox.pdf}{}{}
     {http://csustan.csustan.edu/\~\ tom/Lecture-Notes/Friendship-paradox/Friendship-paradox.pdf}}
}

%\date{Fall, 2011}
\date{\today}


\maketitle

\renewcommand\contentsname{Our general topics:\hypertarget{Contents}{}}
%% \newcommand\listfigurename{List of Figures}
%% \newcommand\listtablename{List of Tables}

\tableofcontents

\pagedone




\sectionhead{Expected values and averages}

     Suppose we have a {\em probability distribution} $\mathcal{P} = \{p(i) | i \in I\}$, where $I$ is a finite {\em index set},
     with $0 \le p(i) \le 1$,
     and $\sum_{i \in I} p(i) = 1$.  We think of the probabilities $p(i)$ as telling us the probability that index $i$ in the
     {\em index set} $I$ will occur.
     
     Now, suppose that we have some function $X: I \to \mathbb{R}$, which gives a particular value $X(i)$
     whenever index $i$ occurs.  We call $X$ a {\em random variable} over the probability distribution $\mathcal{P}$.
     We can then calculate the {\em expected value} (or the {\em mean}) of the random variable $X$ as:
          $$ <X> = \sum_{i \in I} X(i) p(i).$$

     The {\em expected value} has some nice properties.

\pagedone

     Suppose $X$ and $Y$ are random variables over the same probability distribution $\mathcal{P}$, and $c \in \mathbb{R}$.
     Then we have:
          $$<X + Y> = <X> + <Y>$$
     and
          $$<cX> = c<X>$$
     (in other words, {\em expected value} is {\em linear}).  These properties follow easily from the definition.
     
     We also have the obvious property that if $X(i) = c$ for all $i$, then
          $$<X> = <c> = c.$$
          
     This also implies that, since $<X>$ is independent of $i$, we have
          $$<<X>> = <X>.$$
     
\pagedone
     The {\em first moment} (often denoted $\mu$) is the expected value of $X$:
          $$ \mu = <X>.$$
          
     The {\em second moment} (usually called the {\em variance}, or $\sigma^2$) is:
          $$\sigma^2(X) = Var(X) = <(X - \mu)^2>.$$
          
     We can do the quick calculation:
     \begin{align*}
          Var(X) & = \sigma^2(X) \\
                     & = <(X - \mu)^2> \\
                     & = <X^2 - 2X\mu + \mu^2> \\
                     & = <X^2> - <2X\mu> + <\mu^2> \\
                     & = <X^2> - 2\mu<X> + \mu^2 \\
                     & = <X^2> - 2<X>^2 + <X>^2 \\
                     & = <X^2> - <X>^2.
     \end{align*}
\pagedone
   
\sectionhead{Average number of friends}

     Let's do some calculations about an ``acquaintanceship'' network \ldots
     
     Let $G = (V, L)$ be an undirected graph (an ``acquaintanceship'' network) where $V$ is a (finite)
     set of vertices (or nodes), and $L$ is a set of unordered pairs of vertices from $V$ (links, or edges).
     We will assume there are no self-edges (i.e., if $(v_i, v_j) \in L$, then $v_i \ne v_j$), and no duplicate
     edges.  For simplicity, we can assume $i < j$.  Let $N = | V |$, the number of vertices,
     and $E = | L |$, the number of edges.
     
     For this example, we will be interested in the {\em degrees} of the vertices.  In particular,
     for each $v \in V$, the degree of a vertex $v$ is
          $$d_1(v) = | \{ (v_i, v_j) | v = v_i \text{ or } v = v_j \} |,$$
     This is the number of vertices that can be reached in 1 step from $v$, or the number of paths
     of length one leaving $v$.
     
     Note that we will have
          $$\sum_{v \in V} d_1(v) = 2 E$$
     since each edge contributes to the degrees of two vertices.
     
     Let's calculate the average degree of vertices in the graph.  Let $D_1$ be the random variable corresponding
     with the degree of a vertex $v$ chosen (uniformly) randomly (that is, the number of paths of length one
     leaving $v$).
     
     The average degree will be:
          \begin{align*}
               <D_1> & = \sum_{v \in V} d_1(v) p(v) \\
                       & = \sum_{v \in V} d_1(v) \frac{1}{N} \\
                       & = \frac{1}{N} \sum_{v \in V} d_1(v) \\
                       & = \frac{1}{N} * 2 E \\
                       & = \frac{2E}{N}
          \end{align*}
     Note that $p(v) = \frac{1}{N}$ is the (uniform) probability of choosing vertex $v$.
     
     (This result is no surprise at all . . . :-)
\pagedone
\sectionhead{Friends of friends}

     Let's generalize this a bit.  Let's look at the distribution of degrees of vertices that are one step away from
     a given vertex.  In other words, we're looking at the distribution of how many friends your friends have.
     We'll do this by looking at paths of length two.
     
     Let $D_2$ be the random variable expressing the number of vertices connected to a vertex by paths
     of length two -- that is, the number of paths of length two leaving a vertex.
     
     Let $p_1(i)$ be the distribution of degrees:
          $$p_1(i) = \frac{n_i}{N}$$
     where $n_i$ is the number of vertices of degree $i$, and $N$ is the total number of vertices.
     
     Now we calculate $p_2(i)$, the probability that starting at a random vertex, there are $i$ paths of
     length 2 leaving that vertex.  First we calculate the total number $N_2$ of paths of length 2.  We can do
     this by summing over the possible degrees of the vertices in the middle of such paths, and observing
     that each node of degree $i$ is in the middle of $i^2$ paths of length 2:
          \begin{align*}
               N_2 & = \sum_i i^2 n_i \\
                       & = \sum_i i^2 N p_1(i) \\
                       & = N \sum_i i^2 p_1(i) \\
                       & = N < D_1^{\ 2}> \\
          \end{align*}
\pagedone
     This means that the average number of paths of length 2 starting at a uniformly randomly chosen vertex will be
          \begin{align*}
               <D_2>  & = \frac{N_2}{N}  = \frac{N < D_1^{\ 2}>}{N} \\
                            & = < D_1^{\ 2}>. \\
          \end{align*}
     From this we can calculate the average number of friends a friend has (on average):
          \begin{align*}
                     & \frac{\text{average number of friends of friends}}{\text{average number of friends}} = \frac{<D_2>}{<D_1>} \ \ \ \ \ \ \\
                          & \ \ \ \ \ = \frac{< D_1^{\ 2}>}{<D_1>} \\
          \end{align*}
     We can do some minor calculations with this:
          \begin{align*}
                  \frac{< D_1^{\ 2}>}{<D_1>} & = <D_1> + \frac{< D_1^{\ 2}>}{<D_1>} - <D_1> \\
                          & = <D_1> + \frac{< D_1^{\ 2}> - <D_1>^2}{<D_1>} \\
                          & = <D_1> + \frac{Var(D_1)}{<D_1>} \\
          \end{align*}
          
     Note that since $Var(D_1) = \sigma^2(D_1) \ge 0$, this means that, unless everybody has exactly the
     same number of friends, then 
     
     {\large On average, your friends have more friends than you do \ldots}
     
\pagedone
     
     One further observation \ldots
     
     We have that the excess average degrees of neighbors (on average) is
          $$ \frac{Var(D_1)}{<D_1>} $$
     Thus, the larger the variance, the larger the excess.  So, for example, if the degree distribution is
     (approximately) a {\em power law}, we can expect the variance to be large \ldots
     
\pagedone
\sectionhead{Notes}

     I'm leaving a few notes here, potentially for future reference \ldots

     We have that $p(i)$ is the distribution of degrees, or paths of length 1.  As noted, we have:
          $p(i) = \frac{n_i}{N}.$
     
     We also want to look at the distribution of paths of length 2.  Let $p_2(i)$ be the probability that,
     starting at a random vertex, there are $i$ paths of length 2 leaving that vertex.  We may be able to
     calculate this by first looking at the probability $q(i)$ of arriving at a degree $i$ node by following
     an edge.  We can calculate this by calculating how many ends of edges are at vertices with
     degree $i$, and dividing by the total number of ends of edges.  We will have:
          \begin{align*}
               q(i) & = \frac{\text{number of ends at degree } i \text{ vertices}}{\text{total number of ends of edges}} \\
                     & = \frac{i * \text{(number of degree } i \text{ vertices)}}{\text{total number of ends of edges}} \\
                     & = \frac{i * (N * p(i))}{2E} \\
                     & = i *  \frac{N}{2E} * p(i) \\
                     & = i * \frac{1}{<D_1>} * p(i) \\
                     & = \frac{i}{<D_1>}p(i). \\
           \end{align*}
     Quick check:  note that $\sum q(i) = 1$, as needed.
     
     \pagedone     

     Another possible approach: let $C_1(v)$ be the set of neighbors of $v$, and
     $C_2(v)$ be the set of neighbors of neighbors of $v$.  Then
          \begin{align*}
               d_2(v) & = | C_2(v) | \\
                          & = \sum_{w \in C_1(v)} d_1(w) \\
           \end{align*}
     We then have
          \begin{align*}
               <D_2> & = \sum_i | C_2(v_i) | p(i) \\
                           & = \sum_i \sum_{w \in C_1(v_i)} d_1(w) p(i)\\
                           & = \sum_i d_1(v_i)^2 p(i) \\
                           & = <D_1^{\ 2}> \\               
          \end{align*}
     
\pagedone
        
     And some more rough notes \ldots

     We have $p_1(i)$ = distribution of degrees.
     
     Now look at edges:
     
     Let $q_1(i)$ be the probability distribution of arriving at a degree $i$ node by following an edge.  We
     will have:
          $$q_1(i) = \frac{i}{\sum_j j p_1(j)} p_1(i)= \frac{i p_1(i)}{<D_1>}$$

         note $\sum_i q_1(i) = \sum_i \frac{i p_1(i)}{<D_1>} = 1$  (as required)
         
    Now we can look at the average number of neighbors of neighbors, per neighbor:
         \begin{align*}
              \frac{<D_2>}{<D_1>} & = \sum_i i q_1(i) \\
                          & = \sum_i i \frac{i p_1(i)}{<D_1>} \\
                          & = \sum_i \frac{i^2 p_1(i)}{<D_1>} \\
                          & = \frac{<D_1^{\ 2}>}{<D_1>} \\
         \end{align*}
     
\pagedone
 \footnotesize
 \bibliographystyle{plain} 
 


\marginpar{\hyperlink{Contents}{\hfil$\leftarrow$}}

\vspace{-\baselineskip}
\vspace{-\baselineskip}
\vspace{-\baselineskip}
 
 \begin{thebibliography}{12}

\addcontentsline{toc}{section}{References}

\bibitem{feld}
Feld, Scott L. (1991), \\
Why your friends have more friends than you do, \\
American Journal of Sociology 96 (6): 1464-1477, \\
\href{http://dx.doi.org/10.1086\%2F229693}
           {doi:10.1086/229693, JSTOR 2781907}

\bibitem{newman}
Newman, M.E.J. (2002), \\
Random Graphs as Models of Networks,\\
SFI WORKING PAPER: 2002-02-005, \\
\href{http://www.santafe.edu/media/workingpapers/02-02-005.pdf}
          {http://www.santafe.edu/media/workingpapers/02-02-005.pdf}

\end{thebibliography}

\hyperlink{Contents}{\hfil To top $\leftarrow$}


\end{document}
