\subsection{Using IVs}

Let's say the demand function is:

\(Q_d=\alpha+\beta P + \epsilon \)

How can we estimate this?

OLS will give biased results if \(P\) is correlated with \(\epsilon \).

We can estimate if we have an instrumental variable for \(P\).

\subsection{Power of IVs}

need variation. if factor v important, little price movelemtn. may be hard to esimate that fact.


\subsection{Implementing Statistics Calculator in C} % (fold)
\label{sub:implementing_statistics_calculator_in_c}

\sref{sec:arrays_using_these_concepts} of this Chapter introduced the Statistics Calculator. A partial implementation of this program is shown in Listing \ref{lst:c-stats-calc}, with the logic in the \texttt{max} and \texttt{variance} functions still to be implemented. This program reads a number of values from the user into an array, and then calculates and outputs the \textbf{sum}, \textbf{mean}, \textbf{variance}, and \textbf{maximum} value from this data.

\straightcode{\ccode{lst:c-stats-calc}{C code for the Statistics Calculator}{code/c/array/simple-stats.c}}

\mynote{
\begin{itemize}
  \item \texttt{strings.h} is included to give access to the various functions needed to manipulate string values. See the comments associated with \lref{clst:populate_array}.
  \item \texttt{math.h} is included to give access to the \texttt{pow} function that will be needed in the implementation of the \texttt{variance} function.
  \item Arrays in C are always passed by reference.
  \item C does not keep track of the size of an array, the \texttt{size} parameter in each function call carries this data along with the array.
  \item The \texttt{DATA\_SIZE} constant stores the number of values that will be stored in the array. This can easily be changed to allow the program to read a different number of values.
\end{itemize}
}

% subsection implementing_statistics_calculator_in_c (end)


\documentclass[12pt]{article}
\usepackage[intlimits]{amsmath}
\usepackage{MnSymbol}
%\usepackage{fullpage}
\usepackage[top=1in, bottom=1in, left=0.8in, right=1in]{geometry}
\usepackage{multicol}
\usepackage{wrapfig}

\newcommand{\Sp}{\text{ }}
\newcommand{\Var}{\text{Var}}
\newcommand{\Bin}{\text{Bin}}
\newcommand{\Poi}{\text{Poi}}
\newcommand{\HypG}{\text{HypG}}
\newcommand{\Geo}{\text{Geo}}
\newcommand{\Exp}{\text{Exp}}
\newcommand{\Norm}{\text{N}}
\newcommand{\Where}{\Sp\text{ where }}

\setlength{\columnsep}{0.1pc}

\title{Random Variables}
\author{Stephen Koo}

\begin{document}
\maketitle
\vspace{-0.3in}
\rule{\linewidth}{0.4pt}

\section{Discrete Random Variables}
\subsection{Bernoulli}
An experiment that results in "success" or "failure."
\begin{align*}
    X& \sim \text{Ber}(p) \\
    P(X = 0)& = 1 - p \\
    P(X = 1)& = p \\
        E[X]& = p \\
     \Var(X)& = p(1-p) \\
        M(t)& = e^t p + 1 - p
\end{align*}

\subsection{Binomial}
The number of successes in an experiment with $n$ trials and $p$ probability of success on each trial.
\begin{align*}
    X& \sim \Bin(n,p) \\
    P(X = i) = p(i)& = \binom{n}{i} p^i (1-p)^{n-i} \Where i = 0,1,\ldots, n\\
               E[X]& = np \\
            \Var(X)& = np(1-p) \\
               M(t)& = (pe^t + 1 - p)^n
\end{align*}
\\
If $X_i \sim \Bin(n_i, p)$ for $1 \leq i \leq N$, then
\[
    \left( \sum_{i=1}^N X_i \right) \sim \Bin\left(\sum_{i=1}^N n_i, p \right)
\]
Note that the binomial distribution is a generalization of the Bernoulli distribution, since $\text{Ber}(p) \sim \Bin(1, p)$.

\subsection{Poisson}
Approximates the binomial random variable when $n$ is large and $p$ is small enough to make $np$ "moderate"---generally when $n > 20$ and $p < 0.05$---and approaches the binomial distribution as $n \rightarrow \infty$ and $p \rightarrow 0$.
\begin{align*}
    X& \sim \Poi(\lambda) \Where \lambda = np \\
    P(X = i)& = e^{-\lambda} \frac{\lambda^i}{i!} \Where i = 0,1,2,\ldots\\
        E[X]& = \lambda \\
     \Var(X)& = \lambda \\
        M(t)& = e^{\lambda (e^t - 1)}
\end{align*}
The approximations also works to a certain extent when the successes in the trials are not entirely independent, and when the probability of success in each trial varies slightly. \\
\\
If $X_i \sim \Poi(\lambda_i)$ for $1 \leq i \leq N$, then
\[
    \left( \sum_{i=1}^N X_i \right) \sim \Poi\left(\sum_{i=1}^N \lambda_i \right)
\]

\subsection{Geometric}
The number of independent trials until a success, where the probability of success is $p$.
\begin{align*}
    X& \sim \Geo(p) \\
    P(X = n)& = (1-p)^{n-1} p \Where n = 1, 2, \ldots\\
        E[X]& = 1/p \\
     \Var(X)& = (1-p)/p^2
\end{align*}

\subsection{Negative Binomial}
The number of independent trials until $r$ successes, with probability $p$ of success.
\begin{align*}
    X& \sim \text{NegBin}(r, p) \\
    P(X = n)& = \binom{n-1}{r-1} p^r (1-p)^{n-r} \Where n = r, r+1, \ldots \\
        E[X]& = r / p \\
     \Var(x)& = r(1-p)/p^2 \\
     \Geo(p)& \sim \text{NegBin}(1, p)
\end{align*}
Note that the negative binomial distribution generalizes the geometric distribution, with $\Geo(p) \sim \text{NegBin}(1, p)$.

\subsection{Hypergeometric}
The number of white balls drawn after drawing $n$ balls (without replacement) from an urn containing $N$ balls, with $m$ white balls and $N-m$ other ("black") balls.
\begin{align*}
    X& \sim \HypG(n,N,m) \\
    P(X = i)& = \frac{\binom{m}{i} \binom{N-m}{n-i}}{\binom{N}{n}} \Where i = 0, 1, \ldots, n \\
        E[X]& = n(m/N) \\
     \Var(X)& = \frac{nm(N-n)(N-m)}{N^2(N-1)} \\
\HypG(n,N,m)& \rightarrow Bin(n, m/N) \text{ , as } N \rightarrow \infty \text{ and } m/N \text{ stays constant}
\end{align*}

\subsection{Multinomial}
The multinomial distribution further generalizes the binomial distribution: given an experiment with $n$ independent trials, where each trial results in one of $m$ outcomes, with respective probabilities $p_1, p_2, \ldots, p_m$ such that $\sum_{i=1}^{m} p_i = 1$, then if $X_i$ denotes the number of trials with outcome $i$ we have
$$P(X_1 = c_1, X_2 = c_2, \ldots, X_m = c_m) = \binom{n}{c_1, c_2, \ldots, c_m} p_1^{c_1} p_2^{c_2} \cdots p_m^{c_m}$$
where $\sum_{i=1}^{m} c_i = n$ and $\binom{n}{c_1, c_2, \ldots, c_m} = \frac{n!}{c_1! c_2! \cdots c_m!}$.

\section{Continuous Random Variables}
If $Y$ is a non-negative continuous random variable
$$E[Y] = \int_{0}^{\infty} P(Y > y) dy$$
\subsection{Uniform}
\begin{align*}
    X& \sim \text{Uni}(\alpha, \beta) \\
 f(x)& = \left\{
        \begin{array}{ll}
            \frac{1}{\beta - \alpha} & \alpha \leq x \leq \beta \\
                                   0 &\text{otherwise}
        \end{array}
    \right. \\
    E[X]& = \frac{\alpha + \beta}{2} \\
 \Var(X)& = \frac{(\beta - \alpha)^2}{12}
\end{align*}

\subsection{Normal}
For values in common natural phenomena, especially when resulting from the sum of multiple variables.
\begin{align*}
    X& \sim \Norm(\mu, \sigma^2) \\
 f(x)& = \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}} \Where -\infty < x < \infty \\
 E[X]& = \mu \\
    \Var(X)& = \sigma^2 \\
       M(t)& = e^{\left( \frac{\sigma^2 t^2}{2} + \mu t\right)}
\end{align*}
Letting $X \sim N(\mu, \sigma^2)$ and $Y = aX + b$, we have
\begin{align*}
    Y& \sim \Norm(a\mu + b, a^2\sigma^2) \\
     F_Y(x)& = F_X(\frac{x - b}{a})
\end{align*}
The Standard (Unit) Normal Random Variable $Z \sim N(0, 1)$ has a cumulative distribution function (CDF) commonly labeled $\Phi(z) = P(Z \leq z)$ that has some useful properties.
\begin{align*}
    \Phi(z)& = \int_{-\infty}^{z} \frac{1}{\sqrt{2\pi}} e^{-x^2/2} dx \\
   \Phi(-z)& = 1 - \Phi(z)\\
P(Z \geq -z)& = P(Z > z)
\end{align*}
Given $X \sim N(\mu, \sigma^2)$ where $\sigma > 0$, we can then compute the CDF of $X$ using the CDF of the standard normal variable.
$$F_X(x) = \Phi(\frac{x - \mu}{\sigma})$$
By the de Moivre-Laplace Limit Theorem, the normal variable can approximate the binomial when $\Var(X) = np(1-p) \geq 10$. If we let $S_n$ denote the number of successes (with probability $p$) in $n$ independent trials, then
$$ P \left( a \leq \frac{S_n - np}{\sqrt{np(1-p)}} \leq  b \right) \overset{n \rightarrow \infty}{\rightarrow} \Phi(b) - \Phi(a)$$
\\
If $X_i \sim \Norm(\mu_i, \sigma_i^2)$ for $i = 1, 2, \ldots, n$, then
\[
    \left( \sum_{i=1}^n X_i \right) \sim \Norm\left( \sum_{i=1}^n \mu_i, \sum_{i=1}^n \sigma_i^2 \right)
\]

\subsection{Exponential}
Represents time until some event, with rate $\lambda > 0$.
\begin{align*}
    X& \sim \Exp(\lambda) \\
 f(x)& = \left\{
        \begin{array}{ll}
            \lambda e^{-\lambda x} &\text{if } x \geq 0 \\
                                 0 &\text{if } x < 0
        \end{array}
    \right. \\
    E[X]& = \frac{1}{\lambda} \\
 \Var(X)& = \frac{1}{\lambda^2} \\
    F(x)& = 1 - e^{-\lambda x} \Where x \geq 0
\end{align*}
Exponentially distributed random variables are memoryless.
$$P(X > s + t | X > s) = P(X > t)$$

\subsection{Beta}
\begin{align*}
    X& \sim \text{Beta}(a, b) \\
 f(x)& = \left\{
        \begin{array}{ll}
            \frac{1}{B(a,b)}x^{a-1}(1-x)^{b-1} &0 < x < 1 \\
                                             0 &\text{otherwise}
        \end{array}
    \right. \\
    B(a,b)& = \int_{0}^{1} x^{a-1} (1-x)^{b-1} dx \\
      E[X]& = \frac{a}{a+b} \\
   \Var(X)& = \frac{ab}{(a+b)^2(a+b+1)}
\end{align*}
If $X \sim \text{Uni}(0, 1)$ and $N$ denotes the number of heads resulting from a number of coin flips with some unknown probability of getting heads, then
$$X|(N = n, m+n \text{ trials}) \sim \text{Beta}(n + 1, m+ 1)$$

\end{document}


\vfill \eject
\par
\section{Serial Solution of $A X = Y$ using an $QR$ factorization}
\label{section:QR-serial}
\par
Let us review the steps is solving $A X = Y$ using a $QR$
factorization.
\begin{itemize}
\item
{\bf communicate} the data for the problem as $A$, $X$ and $Y$.
\item
{\bf reorder} as
${\widetilde A} {\widetilde X} = Y$, where
${\widetilde A} = A P^T$ and
${\widetilde X} = P X$.
and $P$ is a permutation matrix.
\item
{\bf factor} $ {\widetilde A} = Q R$,
where $Q$ is orthogonal and $R$ is upper triangular.
\item
{\bf solve}  $R^T R (P X) = A^T Y$ (if real)
or {\bf solve}  $R^H R (P X) = A^H Y$ (if complex).
\end{itemize}
\par
A complete listing of a sample program
is found in Section~\ref{section:QR-serial-driver}.
We will now begin to
work our way through the program to illustrate the use
of {\bf SPOOLES} to solve a system of linear equations.
\par
\subsection{Reading the input parameters}
\label{subsection:QR:input-data}
\par
The input parameters are identical to those of the serial $LU$
driver program described in
Section~\ref{subsection:serial:input-data}
with the exception that the {\tt symmetryflag} is not present.
\par
\subsection{Communicating the data for the problem}
\label{subsection:QR:communicating-data}
\par
This step is identical to the serial code, as described in
Section~\ref{subsection:serial:communicating-data}
\par
\subsection{Reordering the linear system}
\label{subsection:QR:reordering}
For the $LU$ factorization of $A$, we used the graph of $A + A^T$.
For the $QR$ factorization of $A$, we need the graph of $A^TA$.
The only difference between the two orderings is how we create
the {\tt IVL} object for the graph.
For the $QR$ factorization, we use
{\tt InpMtx\_adjForATA()}, as we see below.
\begin{verbatim}
adjIVL = InpMtx_adjForATA(mtxA) ;
nedges = IVL_tsize(adjIVL) ;
graph = Graph_new() ;
Graph_init2(graph, 0, neqns, 0, nedges, neqns, nedges, adjIVL,
            NULL, NULL) ;
frontETree = orderViaMMD(graph, seed, msglvl, msgFile) ;
\end{verbatim}
The minimum degree method is the simplest of the ordering methods
provided in the {\bf SPOOLES} library.
For more information on ordering, please see the user document
{\it ``Ordering Sparse Matrices and Transforming Front Trees''}.
\par
\subsection{Non-numeric work}
\label{subsection:QR:non-numeric}
\par
The next phase is to obtain the permutation matrix $P$, (stored
implicitly in a permutation vector), and apply it to the matrix $A$.
This is done by the following code fragment.
\begin{verbatim}
oldToNewIV = ETree_oldToNewVtxPerm(frontETree) ;
oldToNew   = IV_entries(oldToNewIV) ;
newToOldIV = ETree_newToOldVtxPerm(frontETree) ;
newToOld   = IV_entries(newToOldIV) ;
InpMtx_permute(mtxA, NULL, oldToNew)) ;
InpMtx_changeStorageMode(mtxA, INPMTX_BY_VECTORS) ;
\end{verbatim}
The {\tt oldToNewIV} and {\tt newToOldIV} variables are {\tt IV}
objects that represent an integer vector.
The {\tt oldToNew} and {\tt newToOld} variables are pointers to
{\tt int}, which point to the base address of the {\tt int} vector
in an {\tt IV} object.
Once we have the permutation vector, we apply it to the front tree,
by the {\tt ETree\_permuteVertices()} method.
We need $A P^T$, so we permute the {\tt InpMtx}
object using a {\tt NULL} pointer for the row permutation (which
means do not permute the rows) and the {\tt oldToNew} vector for
the column permutation.
At this point the {\tt InpMtx} object holds $AP^T$ in the form
required by the factorization.
\par
The final steps are to compute the symbolic factorization,
which is stored in an {\tt IVL} object, and to permute the vertices
in the front tree.
The symbolic factorization differs slightly from the $LU$ case.
\begin{verbatim}
symbfacIVL = SymbFac_initFromGraph(frontETree, graph) ;
IVL_overwrite(symbfacIVL, oldToNewIV) ;
IVL_sortUp(symbfacIVL) ;
ETree_permuteVertices(frontETree, oldToNewIV) ;
\end{verbatim}
We do not have the $A^TA$ matrix object, so we constuct the
symbolic factorization using the front tree and the {\tt Graph} object.
Note, at this point in time, both the graph and front tree are in
terms of the original ordering, so after the {\tt IVL} object is
created, its vertices must be mapped into the new permutation and
sorted into ascending order.
Then the vertices in the front tree are mapped into the new ordering.
\par
\subsection{The Matrix Factorization}
\label{subsection:QR:factor}
\par
The numeric factorization step begins by initializing the {\tt
FrontMtx} object with the {\tt frontETree} and {\tt symbacIVL}
objects created in early steps.
The {\tt FrontMtx} object holds the actual factorization.
The code segment for the initialization is found below.
\begin{verbatim}
frontmtx = FrontMtx_new() ;
mtxmanager = SubMtxManager_new() ;
SubMtxManager_init(mtxmanager, NO_LOCK, 0) ;
if ( type == SPOOLES_REAL ) {
   FrontMtx_init(frontmtx, frontETree, symbfacIVL, type,
                 SPOOLES_SYMMETRIC, FRONTMTX_DENSE_FRONTS,
                 SPOOLES_NO_PIVOTING, NO_LOCK, 0, NULL,
                 mtxmanager, msglvl, msgFile) ;
} else {
   FrontMtx_init(frontmtx, frontETree, symbfacIVL, type,
                 SPOOLES_HERMITIAN, FRONTMTX_DENSE_FRONTS,
                 SPOOLES_NO_PIVOTING, NO_LOCK, 0, NULL,
                 mtxmanager, msglvl, msgFile) ;
}
\end{verbatim}
This differs little from the initialization in
Section~\ref{subsection:serial:factor}, except that the matrix type
is symmetric or Hermitian, and no pivoting is used for stability.
\par
The numeric factorization is performed by the
{\tt FrontMtx\_QR\_factor()} method.
The code segment from the sample program for the numerical
factorization step is found below.
\begin{verbatim}
chvmanager = ChvManager_new() ;
ChvManager_init(chvmanager, NO_LOCK, 1) ;
DVzero(10, cpus) ;
facops = 0.0 ;
FrontMtx_QR_factor(frontmtx, mtxA, chvmanager, cpus, &facops, msglvl, msgFile) ;
ChvManager_free(chvmanager) ;
\end{verbatim}
Working storage used during the factorization is found in the form
of block {\it chevrons}, in a {\tt Chv} object, which hold the partial
frontal matrix for a front.
Much as with the {\tt SubMtx} object, the {\tt FrontMtx} object does
not concern itself with managing working storage, instead it relies
on a {\tt ChvManager} object to manage the {\tt Chv} objects.
On return {\tt facops} contains the number of floating point
operations performed during the factorization.
\par
The factorization is performed using a one-dimensional
decomposition of the factor matrices.
Keeping the factor matrices in this form severely limits the amount
of parallelism for the forward and backsolves.
We perform a post-processing step to convert the one-dimensional
data structures to submatrices of a two-dimensional block
decomposition of the factor matrices.
The following code fragment performs this operation.
\begin{verbatim}
FrontMtx_postProcess(frontmtx, msglvl, msgFile) ;
\end{verbatim}
\par
\subsection{Solving the linear system}
\label{subsection:QR:solve}
\par
The following code fragment solves the linear system
$R^T R {\widehat X} = {\widehat A}^T Y$ if real
or
$R^H R {\widehat X} = {\widehat A}^H Y$ if complex.
\begin{verbatim}
mtxX = DenseMtx_new() ;
DenseMtx_init(mtxX, type, 0, 0, neqns, nrhs, 1, neqns) ;
FrontMtx_QR_solve(frontmtx, mtxA, mtxX, mtxB, mtxmanager,
                  cpus, msglvl, msgFile) ;
\end{verbatim}
Last, we permute the rows of ${\tt widehat X}$ back into $X$.
\begin{verbatim}
DenseMtx_permuteRows(mtxX, newToOldIV) ;
\end{verbatim}
\par
\subsection{Sample Matrix and Right Hand Side Files}
\label{subsection:QR:input-files}
\par
Immediately below are two sample files:
{\tt qr.matrix.input} holds the matrix input
and {\tt qr.rhs.input} holds the right hand side.
This simple example is an $8 \times 6$ matrix $A$
and a single right hand side.
The solution is the vector of all ones.
Note how the indices are zero-based as for C, instead of one-based
as for Fortran.
\begin{center}
\begin{tabular}{|l|}
\multicolumn{1}{c}{\tt matrix.input} \\ \hline
\begin{minipage}[t]{0.5 in}
\begin{verbatim}
8 6 18
0 1 1.0
0 3 2.0
1 2 3.0
1 3 1.0
1 5 1.0
2 0 1.0
2 2 2.0
3 0 3.0
3 2 4.0
3 4 2.0
4 3 1.0
5 1 2.0
5 4 3.0
5 5 1.0
6 0 2.0
6 3 3.0
7 1 1.0
7 4 3.0
\end{verbatim}
\end{minipage}
\\ \hline
\end{tabular}
\qquad
\begin{tabular}{|l|}
\multicolumn{1}{c}{\tt rhs.input} \\ \hline
\begin{minipage}[t]{0.5 in}
\begin{verbatim}
8 1
0 3.0
1 5.0
2 3.0
3 9.0
4 1.0
5 6.0
6 5.0
7 4.0
\end{verbatim}
\end{minipage}
\\ \hline
\end{tabular}
\end{center}
\par


\documentclass[main.tex]{subfiles}
\begin{document}

\section{Sheet 8}

\subsection{Acceleration in Rindler coordinates}

Rindler coordinates for the Minkowski (1, 1) space, originally parametrized with \((t, x)\), are defined by
%
\begin{subequations}
\begin{align}
  \begin{cases}
      t = \rho \sinh \eta \\
      x = \rho \cosh \eta
  \end{cases}
\,.
\end{align}
\end{subequations}

The metric is given by
%
\begin{align}
  \dd{s^2} = - \dd{t^2} + \dd{x^2} =
  - \rho^2 \dd{\eta^2} + \dd{\rho^2}
\,.
\end{align}

We defined Rindler coordinates so that our uniformly accelerated observer would have velocity only along \(\eta \), so we can find the general expression of the 4-velocity by computing the normalization: since it will look like \(u^{\alpha } = (N, 0)\) for some \(N\) and we want \(u^{\alpha } u_{\alpha } = -1\), we get that \(N^2(-\rho^2) = -1 \), which means \(N = 1/ \rho \).

The only nonzero Christoffel symbols are \(\Gamma^{\eta }_{\eta \rho } = 1/\rho \) and \(\Gamma^{\rho }_{\eta \eta }= \rho \).

The computation of the acceleration then can be started:
%
\begin{subequations}
\begin{align}
  \dv{}{\tau } u^{\mu } &= u^{\nu } \nabla_{\nu } u^{\mu }  \\
  &= u^{\eta } \qty(\cancelto{}{\partial_{\eta } u^{\mu }} + \Gamma^{\mu }_{\eta \nu } u^{\nu })  \\
  &= \frac{1}{\rho^2} \Gamma^{\mu }_{\eta \eta }
\,,
\end{align}
\end{subequations}
%
so the only nonzero component is the one where \(\mu = \rho \), which is \(a^{\rho } = 1/\rho \), or in other words
%
\begin{subequations}
\begin{align}
  a^{\mu } = \left[\begin{array}{c}
  0 \\
  \kappa
  \end{array}\right]
\,,
\end{align}
\end{subequations}
%
where \(\kappa = 1/ \rho \) is the modulus of the 4-acceleration. Indeed
%
\begin{align}
  a^{\mu } a^{\nu } g_{\mu \nu } = \kappa^2 g_{\rho \rho } = \kappa^2
\,.
\end{align}
%

\subsection{Acceleration in Schwarzschild motion}

\subsubsection{Acceleration computation}

The acceleration is given in general by
%
\begin{align}
  a^{\mu } = u^{\nu } \qty(\partial_{\nu } u^{\mu } + \Gamma^{\mu  }_{\nu \rho } u^{\rho })
\,,
\end{align}
%
and we can see that in this formula we can only have a nonzero result if \(\mu = t, r, \varphi \), \(\nu = t, \varphi \) and \(\rho = t, \varphi \).

Now we use the following facts: the velocity is both stationary (\(\partial_{t} u^{\mu } = 0\)), rotationally symmetric (\(\partial_{\varphi } u^{\mu } = 0\)), and the the Christoffel symbols with the upper index different from \(r\) must have at least one \(r\) between the lower ones in order to be nonzero, therefore the terms containing them must be zero since they must then be contracted with \(u^{r} =0 \).
This gives us that the only nonzero component of the acceleration is
%
\begin{align}
  a^{r } = u^{\nu } u^{\nu } \Gamma^{r}_{\nu \nu }
  = \qty(u^{t})^2 \Gamma^{r}_{tt} + \qty(u^{\varphi })^2 \Gamma^{r}_{\varphi \varphi }
\,.
\end{align}

This already confirms that \(u^{\mu } a_{\mu } =0\), since the Schwarzschild metric is diagonal.

The symbols which appear are
%
\begin{align}
  \Gamma^{r}_{tt} = \frac{1}{2} g^{rr} \qty(- g_{tt, r})
  = \qty(1 - \frac{2GM}{r_{*}}) \frac{GM}{r^2_{*}}
\,
\end{align}
%
and
%
\begin{align}
  \Gamma^{r}_{\varphi  \varphi } =
  \frac{1}{2} g^{rr} \qty(-g_{\varphi \varphi , r})
  = - \qty(1 - \frac{2GM}{r_{*}}) r_{*}
\,.
\end{align}

What are the components of the \(4-\)velocity? We can use the normalization \(u^{\mu } u_{\mu } = -1\); inserting the variable name \(u^{\varphi } = \omega \) this gives us
%
\begin{align}
  u^{t} u^{t} g_{tt} + \omega^2 g_{\varphi \varphi } = -1
\,,
\end{align}
%
which can be written as
%
\begin{align}
  u^{t} u^{t} = \frac{1 + \omega^2 r_{*}^2}{1 - \frac{2GM}{r_*}}
\,.
\end{align}
%
Let us plug this expression into the acceleration one:
%
\begin{align}
  a^{r} = \frac{1 + \omega^2 r_{*}^2}{1 - \frac{2GM}{r_*}}
  \qty(1 - \frac{2GM}{r_{*}}) \frac{GM}{r_{*}^2} - \omega^2 \qty(1 - \frac{2GM}{r_{*}}) r_{*}
\,,
\end{align}
%
which simplifies to
%
\begin{subequations}
\begin{align}
  a^{r} &= \frac{GM}{r_{*}^2} + \omega^2 GM - \omega^2 r_{*} + 2GM \omega^2  \\
  &= \frac{GM}{r_{*}^2} + 3GM \omega^2 - \omega^2 r_{*}
\,.
\end{align}
\end{subequations}
%
If we set it to zero we find a relation which we can express in terms of \(l = g_{\varphi \varphi } u^{\varphi } = r^2_{*} \omega \). We get
%
\begin{subequations}
\begin{align}
  0 &= \frac{GM}{r_{*}^2} + 3GM \frac{l^2}{r^{4}} - \frac{l^2}{r_{*}^{3}}  \\
  &= GMr_{*}^2 +3GMl^2 - l^2 r_{*}
\,,
\end{align}
\end{subequations}
%
which  is the relation we know for the angular momentum in circular orbits.

\subsubsection{Acceleration modulus limits}

The modulus of the acceleration is given by \(\abs{\vec{a}}^2 = a^{r} a^{r} g_{rr}\), so we will have
%
\begin{align}
  \abs{\vec{a}}^2 = \frac{1}{1- \frac{2GM}{r_{*}}} \qty(
  \frac{GM}{r_{*}^2} + 3GM \omega^2 - \omega^2 r_{*})^2
\,,
\end{align}
%
which can be written in terms of the adimensionalized variables \(R = r / 2GM\) and \(\widetilde{\omega} = 2GM \omega \):
%
\begin{align}
  \abs{\vec{a}}^2 = \frac{1}{(4GM)^2} \frac{R_{*}}{R_{*} - 1}
  \qty(\frac{1}{R_{*}^2} + \widetilde{\omega}^2 \qty(3 - 2R_{*}))^2
\,.
\end{align}
%
This diverges as \(R_{*} \rightarrow 1\), as we might expect: a \emph{stationary} observer with respect to the Schwarzschild radial coordinate must have ever more acceleration in order to stay on their non-geodesic path.

Of we set \(\omega = 0\) it becomes
%
\begin{align}
  \abs{\vec{a}}^2 = \frac{1}{(4GM)^2} \frac{R_{*}}{R_{*}- 1} \frac{1}{R_{*}^4}
\,,
\end{align}
%
while for \(R_{*} \gg 1\) it becomes
%
\begin{align}
  \abs{\vec{a}}^2 \sim \frac{1}{(4GM)^2} \qty(\frac{1}{R_{*}^2}
   - 2\widetilde{\omega}^2 R_{*})^2
\,,
\end{align}
%
which can become 0 (that is, we have an orbit, a geodesic) if we set \(2\widetilde{\omega}^2 R_{*}^3= 1\), or \(\omega^2 r_{*}^3 = GM\), (the spherical orbit formulation of) Kepler's third law.

We neglected only the \(3 \widetilde{\omega}^2 \) term since it is the smallest one: in terms of powers of \((GM)\) and of \(c\) we have: \(R_{*}^{-2} \sim (GM)^{-2}\), \(\widetilde{\omega}^2\sim (GM)^{-2} c^{-2}\) while \(\widetilde{\omega}^2 R_{*}^2 \sim (GM) c^{-2}\).

\subsubsection{Some comments on orbits (complement)}

Another interesting thing to note is the fact that at \(R_{*} = 3/2\) the acceleration becomes independent of \(\omega \), and at \(R_{*} < 3/2\) the effect of the rotation is to \emph{increase} the acceleration instead of decreasing it; this corresponds to the fact that there are no orbits (not even unstable ones) for \(R_{*}<3/2\).

An interesting fact which was not mentioned in class: there exist orbits for any \(R_{*}\) between \(3/2\) and \(3\), although they are unstable.

We found that the radius of a circular orbit is given by
%
\begin{align}
  R = L^2 \qty(1 \pm \qty(\sqrt{1 - \frac{3}{L^2}}))
\,,
\end{align}
%
where \(L = l / 2GM\) and \(R = r / 2GM\).

The two branches of this expression correspond to stable and unstable orbits: in both cases we have \(\sqrt{3} < L < \infty \), and for the stable (plus sign) branch we find \(R > 3\) and \(\dv*{R}{L} > 0\) everywhere, while for the unstable branch we have \(3/2 < R < 3\) and \(\dv*{R}{L} < 0 \) everywhere.

\subsection{Perturbed rotating metrics}

We want to prove that, to first order in \(\delta g_{\mu \nu }\), the inverse of \(g_{\mu \nu } = \overline{g}_{\mu \nu } + \delta g_{\mu \nu }\) is
%
\begin{align}
  g^{\mu \nu } =
  \overline{g}^{\mu \nu } + \overline{g}^{\mu \alpha } \overline{g}^{\nu \beta } \delta g_{\alpha \beta } + O((\delta g_{\mu \nu })^2)
\,.
\end{align}

This can be proved directly by verifying \(g_{ \mu \nu } g^{\nu \rho } = \delta_{\mu }^{\rho } + O((\delta g)^2)\): it comes out to be
%
\begin{subequations}
\begin{align}
  &\qty(\overline{g}_{\mu \nu } + \delta g_{\mu \nu })
  \qty(\overline{g}^{\nu \rho } - \overline{g}^{\nu  \alpha } \overline{g}^{\rho  \beta } \delta g_{\alpha \beta } + O((\delta g)^2)) \\
  &= \delta_{\mu }^{\rho } + \delta g_{\mu \nu } \overline{g}^{\nu \rho } - \overline{g}_{\mu \nu }\overline{g}^{\nu \alpha } \overline{g}^{\rho \beta } \delta g_{\alpha \beta } + O((\delta g)^2)  \\
  &=  \delta_{\mu }^{\rho } + \delta g_{\mu \nu } \overline{g}^{\nu \rho } - \delta_{\mu}^{\alpha } \delta g_{\alpha \beta } \overline{g}^{\rho \beta }  + O((\delta g)^2)
\,,
\end{align}
\end{subequations}
%
so we can notice that the first order terms cancel: we have the inverse, up to first order.

\subsubsection{Inverse perturbed Schwarzschild}

The Schwarzschild metric is
%
\begin{subequations}
\begin{align}
  \overline{g}_{\mu \nu } = \left[\begin{array}{cccc}
  -\qty(1 - \frac{2GM}{r}) & 0 & 0 & 0 \\
  0 & \qty(1 - \frac{2GM}{r})^{-1} & 0 & 0 \\
  0 & 0 & r^2 & 0 \\
  0 & 0 & 0 & r^2 \sin^2 \theta
  \end{array}\right]
\,,
\end{align}
\end{subequations}
%
and its inverse is
%
\begin{subequations}
\begin{align}
  \overline{g}^{\mu \nu } = \left[\begin{array}{cccc}
  -\qty(1 -\frac{2GM}{r})^{-1}  & 0 & 0 & 0 \\
  0 & \qty(1- \frac{2GM}{r}) & 0 & 0 \\
  0 & 0 & r^{-2} & 0 \\
  0 & 0 & 0 & r^{-2} \sin^{-2} \theta
  \end{array}\right]
\,.
\end{align}
\end{subequations}

We want to compute \(\overline{g}^{\mu \alpha } \overline{g}^{\nu \beta } \delta g_{\alpha \beta }\), and we know that \(\delta g_{\alpha \beta } \) has only one independent component:
%
\begin{align}
  \delta g_{t \varphi } = - \frac{2 GJ  \sin^2\theta }{r}
\,.
\end{align}

This, combined with the fact that the background metric is diagonal, gives us the result that we only have one entry in the sum:
%
\begin{align}
  \overline{g}^{\mu \alpha } \overline{g}^{\nu \beta } \delta g_{\alpha \beta }
  = \overline{g}^{tt} \overline{g}^{\varphi \varphi }
  \delta g_{\varphi  t}
  =(-)^2 \frac{2GJ \sin^2 \theta /r }{(1 - \frac{2GM}{r}) r^2 \sin^2 \theta }
  = \frac{2GJ}{(r - 2GM) r^2}
  \,,
\end{align}
%
so the  full inverse metric to first order in \(J\) is given by subtracting this off of the regular Schwarzschild inverse's \(t \varphi \) components:
%
\begin{subequations}
\begin{align}
  g^{\mu \nu } = \left[\begin{array}{cccc}
    -\qty(1 -\frac{2GM}{r})^{-1}  & 0 & 0 & -\frac{2GJ}{(r - 2GM)r^2} \\
    0 & \qty(1- \frac{2GM}{r}) & 0 & 0 \\
    0 & 0 & r^{-2} & 0 \\
    -\frac{2GJ}{(r - 2GM)r^2} & 0 & 0 & r^{-2} \sin^{-2} \theta
    \end{array}\right]
\,.
\end{align}
\end{subequations}

\subsubsection{Ricci component computation}

We want to compute the 00 component of the Ricci tensor, \(R_{00} = R^{\alpha }_{0 \alpha 0}\). It is given by
%
\begin{align}
  R_{00} = \Gamma^{\alpha }_{00, \alpha }
  - \Gamma^{\alpha }_{0 \alpha, 0}
  + \Gamma^{\alpha }_{\alpha \lambda }
  \Gamma^{\lambda }_{00}
  - \Gamma^{\alpha }_{0\lambda }
  \Gamma^{\lambda }_{0 \alpha }
\,,
\end{align}
%
and we will show that each of these 4 terms is either constant with respect to \(J\) or quadratic in \(J\), when computed with respect to the metric
%
\begin{subequations}
\begin{align}
  g_{\mu \nu } =
  \left[\begin{array}{cccc}
  -\qty(1- \frac{2GM}{r}) & 0 & 0 & - \frac{2GJ}{r} \sin^2\theta  \\
  0 & \qty(1 - \frac{2GM}{r})^{-1} & 0 & 0 \\
  0 & 0 & r^2 & 0 \\
  - \frac{2GJ}{r} \sin^2\theta  & 0 & 0 & r^2 \sin^2 \theta
  \end{array}\right]
\,.
\end{align}
\end{subequations}

First of all, note that the only derivatives of the metric which can give \(J\)-dependent contributions are \(g_{03,1}\), \(g_{03, 2}\) or these terms with \(0\) and \(3\) exchanged.

The sum \(\Gamma^{\alpha }_{00, \alpha } \) is independent of \(J\): the only terms which can contribute in the sum are \(\alpha = r, \theta \) and then the three indices in the Christoffel symbol are either \(001\) or \(002\): in either case we cannot form the \(J\)-dependent metric component \(g_{03}\).

More explicitly: the expression is
%
\begin{align}
  \Gamma^{\alpha }_{00} = \frac{1}{2} g^{\alpha \beta } \qty(2g_{\beta 0,0}- g_{00, \beta } )
\,,
\end{align}
%
and the time derivatives vanish, terms with \(\beta = 1, 2\) could contribute but in neither case would we have the possibility to form the \(g^{03}\) component.

The term \(\partial_{0} \Gamma^{\alpha }_{0\alpha }\) is zero by stationarity: the metric is \(t\)-independent.

In the term \(\Gamma^{\alpha }_{\alpha \lambda } \Gamma^{\lambda }_{00}\) we ask ourselves: where can the metric component \(g_{03}\) or \(g^{03}\) appear? As we saw above it cannot appear in the second symbol, while for it to appear in the first symbol we would need to have \(\alpha, \lambda = 0, 3\) (in either order), but then the third index in that symbol would also be \(0\) or \(3\), so the metric component \(g_{03}\) would be differentiated with respect to \(t\) or \(\varphi \), and it is independent of both. So, in order to have the symbol \(\Gamma^{\lambda }_{00} \) not be zero we need to have \(\lambda = 1, 2\).
Then, in the expression
%
\begin{align}
  \Gamma^{\alpha }_{\alpha \lambda }  = \frac{1}{2}
  g^{\alpha \beta } \qty(g_{\beta \alpha , \lambda }
  + g_{\beta \lambda , \alpha }
  - g_{ \alpha \lambda , \beta })
\,
\end{align}
%
the last two terms of the sum cannot depend on \(J\) since they have an index which is neither 0 nor 3.
Terms such as those with \(\alpha , \beta = 0,3\) or the inverse can contribute: however in these terms we have to multiply a \(g^{03}\), which is linear in \(J\), with a \(g_{03}\), which also is. So in the end the term is quadratic in \(J\).

The term \(\Gamma^{\alpha }_{0 \lambda } \Gamma^{\lambda}_{0 \alpha }\) is also \(O(J^2)\); to see this, let us write a symbol \(\Gamma^{\alpha }_{0 \lambda }\): it is
%
\begin{align}
  \Gamma^{\alpha }_{0 \lambda } =
  \frac{1}{2} g^{\alpha \beta } \qty(g_{\beta 0, \lambda } +  \cancelto{}{g_{\beta \lambda, 0 } }
  - g_{0 \lambda , \beta })
\,,
\end{align}
%
and we ask ourselves: how can this depend on \(J\)?
We could have \(\alpha , \beta = 0, 3\): then the term \(g_{0 \lambda , \beta }\) vanishes and we have \(g^{03} g_{30, \lambda }\) which is already quadratic in \(J\).

We could have \(\alpha , \beta = 3, 0\): then \(g_{0 \lambda , \beta }\) vanishes. We could have a nonzero term \(g^{30} g_{00, \lambda }\) if \(\lambda = 1, 2\): in this case the whole term would look like \(\Gamma^{3}_{0 1} \Gamma^{1}_{03}\) or  \(\Gamma^{3}_{0 2} \Gamma^{2}_{03}\). In either case, in both symbols the sum of derivatives of the metric the only nonvanishing term will be necessarily linear in \(J\) since it will be differentiated with respect to the 1 or 2 index. Therefore, the product of the two Christoffels will be at least quadratic in \(J\).

The final case for the single Christoffel is \(\alpha = \beta \): in that case, to have \(J\)-dependence we need to have either \(\beta =3\) which means \(\alpha = 3\) or \(\lambda =3\). When we set one of the two indices \(\alpha , \lambda \) to \(3\) the other one must necessarily be \(1\) or \(2\), since otherwise the derivatives would vanish.
Then we get back to the case in which only one term in the sum of the three derivatives of the metric survives, which means that the symbol is linear in \(J\) as a whole, but we have two symbols for which this holds multiplied together, so on the whole the term is quadratic in \(J\).

In the end then the sum, when expressed as a function of \(J\), looks like:
%
\begin{align}
  R_{00} = \const(J)+  O(J^2)
\,,
\end{align}
%
and we know that if \(J=0\) then \(R_{00} = 0\), so we are done: \(R_{00} = O(J^2)\).

\end{document}


\chapter*{Appendix B: Noise Modeling the Wavelet Space}
\addcontentsline{toc}{chapter}{Appendix B: Noise Modeling the Wavelet Space}

\subsection*{Gaussian noise}
\index{noise}
We have the probability density
\begin{eqnarray}
p(w_j(x,y)) = \frac{1}{\sqrt{2\pi} \sigma_j} e^{{-w_j(x,y)^2}/2\sigma^2_j}
\end{eqnarray}

So we need to estimate, in the case of Gaussian noise models,
 the noise standard deviation at each scale.  These standard deviations can
be determined analytically in the case of some transforms, including the
\`a trous transform, but the calculations can become complicated.

The appropriate value of $\sigma_j$
in the succession of wavelet planes is assessed
from the standard deviation of the noise $\sigma_I$ in the original image
$I$,
and from study of the noise in the wavelet space.  This study consists of
simulating an image containing Gaussian noise with a standard deviation
equal to 1, and taking the wavelet transform of this image.  Then we
compute the standard deviation $\sigma^e_j$ at each scale.  We get a curve
$\sigma^e_j$ as a function of $j$, giving the behavior of the noise in the
wavelet space.
(Note that if we had used an orthogonal wavelet transform, this curve would
\index{wavelet transform}
be linear.)  Due to the properties of the wavelet transform, we have
$ \sigma_j = \sigma_I \sigma^e_j $.
The standard deviation of the noise at a scale $j$ of the image is equal to
the standard deviation of the noise of the image multiplied by the
standard deviation of the noise of  scale $j$ of the wavelet transform.

\subsection*{Poisson noise}
\index{noise}

If the noise in the data $I$ is Poisson, the Anscombe transform
\begin{eqnarray}
t(I(x,y)) = 2\sqrt{I(x,y) + \frac{3}{8}}
\label{eqn_noise_anscombe}
\end{eqnarray}
acts as if the data arose from a
Gaussian white noise model (Anscombe, \cite{rest:anscombe48}),
with $\sigma = 1$, under the
assumption that the mean value of $I$ is large.
\index{Anscombe transformation}

For Poisson parameter values under about 20, the Anscombe transformation
looses control over the bias.  In this case, an alternative approach to
variance stabilization is needed. An approach for very small numbers of
counts, including frequent zero cases, has been described in
in \cite{astro:slezak93}, \cite{astro:bijaoui94} and \cite{astro:bury95},
and  will be described below.
Small numbers of detector counts will most likely be associated  with the
image background.
Note that errors related to small values carry the risk of
removing real objects, but not of amplifying noise.

\subsection*{Gaussian and Poisson Noise}
\index{variance stabilization}
\index{noise}

The arrival of photons, and their expression by electron counts, on CCD
detectors may be modeled by a Poisson distribution.  In addition, there is
additive Gaussian read-out noise.
The Anscombe
transformation (eqn.\ \ref{eqn_noise_anscombe}) has been extended \cite{starck:mur95_2}
to take this combined noise into account.
As an
approximation, consider the signal's value, $I(x,y)$, as a sum of a Gaussian
variable, $\gamma$, of mean $g$ and standard-deviation $\sigma$; and a
Poisson variable, $n$, of mean $m_0$: we set
$I(x,y) = \gamma + \alpha n $ where $\alpha$
is the gain.

The generalization of the variance stabilizing Anscombe formula is:
\begin{eqnarray}
t = \frac{2}{\alpha} \sqrt{\alpha I(x,y) + \frac{3}{8} \alpha^2 + \sigma^2 -
\alpha g}
\label{eqn_noise_bijaoui}
\end{eqnarray}
With appropriate values of $\alpha$, $\sigma$ and $g$, this reduces to
Anscombe's transformation (eqn.\ \ref{eqn_noise_anscombe}).
\index{Anscombe transformation}

\subsection*{Poisson Noise with Few Photons or Counts}
\index{noise}
\label{noise_few_photons}

A wavelet coefficient at a given position and at a given scale $j$ is
\begin{eqnarray}
w_j(x,y) =  \sum_{k \in K} n_k \psi(\frac{x_k - x}{2^j} , \frac{y_k - y}{2^j})
\end{eqnarray}
where $K$ is the support of the wavelet function  $\psi$ and $n_k$ is the
number  of events which contribute to the calculation of $w_j(x,y)$ (i.e.\ the
number of
photons included in the support of the dilated wavelet centered at ($x$,$y$)).
\index{wavelet transform}

If a wavelet coefficient $w_j(x,y)$ is due to the noise, it can be considered
as a realization of the sum $\sum_{k \in K} n_k$ of
independent random variables
with the same distribution as that of the wavelet function ($n_k$
being the number of photons or events used for the calculation of $w_j(x,y)$).
Then we compare the wavelet coefficient of the data to the values
which can be taken by the sum of $n$ independent variables.

The distribution of one event in the wavelet space is directly
given by the histogram $H_1$ of the wavelet $\psi$. Since
independent events are considered, the distribution of the random variable
$W_n$ (to be associated with a wavelet coefficient) related to $n$
events is given by $n$ autoconvolutions of $H_1$
\begin{eqnarray}
H_n = H_1 \otimes  H_1 \otimes ... \otimes H_1
\end{eqnarray}
For a large number of events, $H_n$ converges to a Gaussian.

In order to facilitate the comparisons, the variable $W_n$ of distribution
 $H_n$
 is reduced by
\begin{eqnarray}
c = \frac{W_n - E(W_n)}{\sigma(W_n)}
\end{eqnarray}
and the cumulative distribution  function is
\begin{eqnarray}
F_n(c) = \int_{-\infty}^{c} H_n(u) du
\end{eqnarray}

From $F_n$, we derive $c_{min}$ and $c_{max}$ such
that $F(c_{min}) = \epsilon$
and $F(c_{max}) = 1 - \epsilon$.

Therefore a reduced wavelet coefficient $w^r_j(x,y)$, calculated from
$w_j(x,y)$, and  resulting
from $n$ photons or counts is
significant if:
\begin{eqnarray}
F(w^r) > c_{max}
\end{eqnarray}
or
\begin{eqnarray}
F(w^r) < c_{min}
\end{eqnarray}
and $w^r_j(x,y)$ is obtained by
\begin{eqnarray}
w^r_j(x,y)  & = &   \frac{w_j(x,y)}{\sqrt{n} \sigma_{\psi_j}} \\
             & =  & \frac{w_j(x,y)}{\sqrt{n} \sigma_{\psi}} 4^j
\end{eqnarray}
where $\sigma_{\psi}$ is the standard deviation of the wavelet function, and
$\sigma_{\psi_j}$ is the standard deviation of the dilated wavelet function
($\sigma_{\psi_j} = \sigma_{\psi}/4^j$).

\subsection*{Root mean square map}
If, associated to the data $I(x,y)$, we have the root mean square map
$R_{\sigma}(x,y)$, the noise in $I$  is non homogeneous.
For each wavelet coefficient $w_j(x,y)$ of $I$, the
exact standard deviation $\sigma_j(x,y)$ have to be calculated from
 $R_{\sigma}$. A wavelet coefficient $w_j(x,y)$ is obtained by
the correlation product between the image $I$ and a function
$g_j$:
\begin{eqnarray}
 w_j(x,y) = \sum_k \sum_l I(x,y)  g_j(x+k,y+l)
\end{eqnarray}

Then we have
\begin{eqnarray}
\sigma_j^2(x,y) =  \sum_k \sum_l R_{\sigma}^2(x,y) g_j^2(x+k,y+l).
\end{eqnarray}

In the case of the \`a trous algorithm, the coefficients $g_j(x,y)$
 are not known exactly, but they can easily be computed by taking the
wavelet transform of a Dirac $w^{\delta}$. The map $\sigma_j^2$ is calculated
by correlating the square of the wavelet scale $j$ of  $w^{\delta}$
by $R^2_\sigma(x,y)$.

\subsection*{Speckle Noise}
Speckle occurs in all types of coherent imagery such as synthetic aperture
 radar (SAR) imagery,  acoustic imagery and laser illuminated imagery.
 The probability density function (pdf) of the modulus of a homogeneous
 scene is a Rayleigh distribution:
\begin{eqnarray*}
p(\rho)={\rho\over \sigma^2}e^{-{\rho^2\over 2\sigma^2}}
\quad  M_{\rho} = \sqrt{ \frac{\pi}{2} } \sigma \quad \sigma_{\rho}=\sqrt {\frac{4-\pi}{2}}\sigma
 \end{eqnarray*}
The ratio $\sigma_{\rho}/M_{\rho}$ is a constant of value $\sqrt{\frac{4-\pi}{\pi}}$.
This
means that the speckle is a multiplicative noise. The pdf of the  modulus of a log-transformed
 speckle noise is:
\begin{eqnarray*}
p(\ell) =  \frac{e^{2\ell}}{ \sigma^2} e^{-\frac{e^{2\ell}}{2 \sigma^2} } \quad
M_{\ell} = 0.058 + \log(\sigma) \quad \sigma_{\ell}= \sqrt{\frac{\pi^2}{24}} = 0.641
\end{eqnarray*}

A better estimator for Rayleigh distribution is the  energy ($I=\rho^2$)
which is known to have an exponential ({\it i.e.} Laplace)
distribution of parameter $a=2\sigma^2$
\begin{eqnarray*}
p(I)={1\over a}e^{-\frac{I}{a}}
\end{eqnarray*}

\subsection*{Other Types of Noise}
For any type of noise, an analogous study can be carried out in order to find
the detection level at each scale and at each position. The
types of noise considered so far in this chapter correspond to the general
cases in astronomical imagery.
We now describe briefly methods which can be used for non-uniform and
multiplicative noise.

\subsubsection*{Additive Non-Uniform Noise}
\label{noise_addi_uni}
If the noise is additive, but non-uniform, we cannot estimate a standard
deviation for the whole image. However, we can often assume that the noise
is locally Gaussian, and we can compute a local standard deviation of the
noise for each pixel. In this way, we obtain a standard deviation
map of the noise, $I_{\sigma}(x,y)$.
A given wavelet coefficient $w_j(x,y)$ is calculated
from the pixels of the input image $I$ in the range $I(x-l \dots x+l, y-l
\dots y+l)$
where $l$ is dependent on the wavelet transform algorithm, the wavelet
function,
and the scale $j$. An upper limit $u_j(x,y)$ for the noise associated with
$w_j(x,y)$ is
found by just considering the maximum value in
$I_{\sigma}(x-l \dots x+l,y-l \dots y+l)$ and
 by multiplying this value by the constant $\sigma_j^e$ (defined in the
subsection ``Gaussian noise'' at the beginning of this Appendix).
\begin{eqnarray}
u_j(x,y) = \max(I_{\sigma}(x-l \dots x+l, y-l \dots y+l)) \sigma_j^e
\end{eqnarray}
The detection level is not constant over each scale.

\subsubsection*{Multiplicative Noise}
If the noise is multiplicative, the image can be transformed by taking
its logarithm. In the resulting image, the noise is additive, and
a hypothesis of Gaussian noise can be used in order to find the
detection level at each scale.

\subsubsection*{Multiplicative Non-Uniform Noise}
In this case, we take the logarithm of the image, and the resulting image
is treated as for additive non-uniform noise above.

\subsubsection*{Unknown Noise}
If the noise does not follow any known distribution,
we can consider as significant
only wavelet coefficients which are greater than their local standard deviation
multiplied by a constant: $w_j(x,y)$ is significant if
\begin{eqnarray}
\mid w_j(x,y) \mid \ > \ k \sigma(w_j(x-l \dots x+l, y-l \dots y+l))
\end{eqnarray}


\documentclass[12pt]{article}
% \usepackage[margin=1in]{geometry}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage[]{algorithm2e}
% \usepackage[table]{xcolor}          % table alternate background shading
% \usepackage[LGRgreek]{mathastext}   % Dirty solution: change all math font to upright
\usepackage[style=alphabetic]{biblatex}

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

\addbibresource{rec-notes.bib}

\title{Recommender System Notes}
\author{Tiangang Chen, Mengqiao Zhang}
\begin{document}
\maketitle
\section{Intro}
In our project, we implemented a naive version of Twitter's preliminary recommender system \cite{wtf} for recommending who to follow. We also implemented a very simple cosine-distance based content-filtering algorithm as a complement.

These two algorithms are written in Python scripts, intended to be executed by the OS scheduler on fixed time interval. So the recommendation is not reactive immediately to user input.

This document serves to record the details of our understanding and implementation, primarily as our self-reference.

\section{Content Filtering}

We collect the following raw personal information: gender, major, and tags. The tags are predefined predicates of a person's hobbies/traits that the user may select as he/she sees fit.

We model the tags as a boolean vector with dimension of number of tags available.

The rank/similarity score between two users $u$ and $v$ is calculated as follows:

\[\frac{u \cdot v}{\norm{u}_2 \norm{v}}_2\]

Which is readily available via \texttt{1 - scipy.spatial.distance.cosine(u,v)}.

\section{Collaborative Filtering}

The following illustrates an overview of the algorithm described in \cite{wtf}.

\begin{figure}[h]
\begin{center}
\includegraphics[width=0.5\textwidth]{wtf-algorithm}
\caption{overview of the algorithm}
\end{center}
\end{figure}

\subsection{PageRank}

The setup for PageRank \cite{pagerank} is as follows: let $u$ be a web page, $F_u$ be the set of pages that $u$ points to, and $B_u$ be the set of pages that points to $u$. Let $N_u = |F_u|$, which is the number of links originating from $u$. $c$ is the factor for normalization.

The simplified PageRank:

\[R(u) = c \sum_{v \in B_u}{\frac{R(v)}{N_v}}\]

\[R = cAR\]

Where $A$ is the matrix representation of the graph. $A_{u,v} = \frac{1}{N_u}$ if there is an edge from $u$ to $v$, otherwise $0$.

Simplified PageRank suffers from ``rank sink'' when we encounter situation similar to: two pages pointing only to each other, then some other page points to one of them. Then the rank will accumulate in the two pages but never distribute.

The improved PageRank includes a source of rank $E(u)$:

\[R(u) = c \sum_{v \in B_u}{\frac{R(v)}{N_v} + cE(u)}\]

\[R=c(AR+E)\]

We aim to maximize $c$ and keep $\norm{R}_1 = 1$. Because $\norm{R}_1 = 1$, we can rewrite $R = c(A+E \cdot 1)R$ where $1$ is a vector of all ones. The introduction of vector $E$ remedies the rank sink. Generally, we can populate $E$ with uniform value. By giving $E$ some bias we can obtain a ``personalized'' ranking focusing on a particular webpage.

We simply implement PageRank as follows, identical to the original \cite{pagerank} algorithm:

\begin{center}
\begin{algorithm}[h!]
\KwData{$R$ the rank vector\;
$A$ matrix representation of the graph\;
$E$ the initialization vector\;
$\epsilon$ convergence limit\;}
initialize: $R_0 \gets E$ \;
 \While{$\delta > \epsilon$}{
  $R_{i+1} \gets AR_i$\;
  $d \gets \norm{R_i}_1 - \norm{R_{i+1}}_1$\;
  $R_{i+1} \gets R_{i+1} + dE$\;
  $\delta \gets \norm{R_{i+1} - R_i}_1$\;
 }
 \caption{PageRank}
\end{algorithm}
\end{center}

\subsection{SALSA}

SALSA \cite{salsa} operates on a bipartite graph, traversing while assigning scores to nodes on both sides. The two sets of nodes are called hubs and authorities. In our case, the set of hub nodes consist of top results from personalized PageRank for a user, called the ``circle of trust'', and the set of authority nodes consist of direct (one degree) neighbors of those hub nodes.

We set up SALSA as follows: initially we have a collection (set) of pages, denoted by $\mathcal{C}$, edges are directed in this collection. Now we convert $\mathcal{C}$ to an undirected bipartite $G = (V_h, V_a, E)$, where

\[V_h = \{ s_h | s \in \mathcal{C}, \; \mathrm{outDegree(s)} > 0 \}\]
\[V_a = \{ s_a | s \in \mathcal{C}, \; \mathrm{inDegree(s)} > 0 \}\]
\[E = \{ (s_h, r_a) | s \rightarrow r \; in \; \mathcal{C} \}\]

So a page with both nonzero in-degree and out-degree will appear on both sides of the bipartite. Our $\mathcal{C}$ consists of the previously mentioned ``circle of trust'' and the nodes that they point to, which is naturally a bipartite.

Now we perform two distinct random walks on $G$. The two walks start from opposite side of the bipartite, traversing two edges in each iteration. So they will end up at the same side where they started. This process is represented as two Markov chains. The transition matrices are defined as follows:

\[h_{i,j} = \sum_{\{k | (i_h, k_a), (j_h, k_a) \in G\}}{\frac{1}{deg(i_h)} \cdot \frac{1}{deg(k_a)}}\]
\[a_{i,j} = \sum_{\{k | (k_h, i_a), (k_h, j_a) \in G\}}{\frac{1}{deg(i_a)} \cdot \frac{1}{deg(k_h)}}\]

Our goal is to find the pricipal eigenvectors of the hub and autority matrix, which are eigenvectors with eigenvalues of the largest magnitude. It has been argued in \cite{salsa} that such eigenvalue/eigenvector exists and is unique (has multiplicity of one). The values within are the assigned scores for the hub and authority nodes. Higher values stand for higher probability of the random walk ends up at the nodes.

\printbibliography
\end{document}


\begin{document}
\section{Difficulty from Beatmaps}

We turn our attention to how we can figure out difficulty from the map itself, the expected output we want would be:

$$ difficulty := \lbrace(offset_1, difficulty_1), (offset_2, difficulty_2), ..., (offset_n, difficulty_n)\rbrace $$

Whereby we estimate difficulty at offset \textbf{n} from the map itself:

$$ difficulty_n \approx model \left( reading_n, \sum_{k=1}^{keys} \left(strain_k \right), ... \right)$$

There are more factors (denoted by $...$) that contribute to difficulty, but we will regard them as noise in this research and fine tune this equation later.

\paragraph{Reading} This denotes how hard is it to read all the patterns on the screen. We can draw similarities between this and density, however density focuses a lot more on its previous and future surroundings where reading looks at the future ones only.

\paragraph{Density} This focuses on the \textbf{imminent} density of the offset. contrary to strain, it disregards the global trends of patterns. We will not use this in our network as strain does a better job in calculation.

\paragraph{Strain} This is reliant on $density$ whereby continuous high values of $ density$ will result in a high $strain$. This has an additional hyperparameter, $decay$, where it denotes how fast the player can recover from $strain_n$. Finger $strain$ on the same hand will likely affect the other $strain$ values of the other fingers.

\subsection{Note Type Weights}

This will define the \textbf{weightages} of each note type.
\paragraph{$weight_{NN}$} defines for normal notes
\paragraph{$weight_{LNh}$} defines for long notes heads
\paragraph{$weight_{LNt}$} defines for long notes tails
\paragraph{$weight_{SSh}$} defines for \textbf{strain shift} for hands \textbf{(explained later)}
\paragraph{$weight_{SSb}$} defines for \textbf{strain shift} for body \textbf{(explained later)}

\subsection{Reading}

$$ reading_{(n,n+\theta)} :=
count(NN), count(LNh), count(LNt)
= \lbrace n \leq offset \leq (n+ \theta) \rbrace$$

Where,

\paragraph{$n$} is the initial offset
\paragraph{$\theta$} is the hyperparameter for length.
We will not take into consideration the length of $note_{long}$

\subsection{Density}

We will look into density before strain as it's derived from this.

Considering the notes on the $k$ column
$$ \lbrace ..., n-2, n-1, n, n+1, n+2, ... \rbrace $$
$$ \Delta_{nx}^k = \frac{1}{|n - x|}$$
$$ density_n^k =
\sum_{N=n-\sigma}^{n+\sigma}
\left(
\Delta_{nN}^k
\right)$$

So for $\sigma = 2$ and
$$ column_k := \lbrace a, b, n, d, e\rbrace$$
$$ density_n^k = \Delta_{na}^k + \Delta_{nb}^k + \Delta_{nd}^k + \Delta_{ne}^k $$
$$ density_n^k = \frac{1}{|n-a|} + \frac{1}{|n-b|} + \frac{1}{|n-d|} + \frac{1}{|n-e|}$$

\paragraph{$\Delta_{nx}^k$} will be the the inverse of the (ms) distance between notes $n$ and $x$ on column $k$. Notes that are further away will be penalized more heavily.

\paragraph{$\sigma$} defines the range, front and back of the search. Higher sigma may prove to be useless with further $\Delta_{nx}^k$ being too small.

\subsection{Strain}

This will work in relationship with $density$, whereby a $strain$ is a cumulative function of $density$ with a \textbf{linear decay function}.

Notes:
\begin{enumerate}
	\item Better players have \textbf{higher decay gradients}
	\item If $decay > density$, $strain$ will \textbf{decrease}
	\item If $decay < density$, $strain$ will \textbf{increase}
	\item There will be a point where $strain$ is high enough to affect physical performance, indirectly affecting accuracy.
\end{enumerate}

\subsubsection{Strain Shift}

Strain will not only affect one finger, it will affect the hand and both after time, just on a smaller scale

\paragraph{Hand} We will denote the strain shift hyperparameter of one finger to another on the same hand to be $SS_H$
\paragraph{Body} Likewise, for body, we will denote as $SS_B$

\subsubsection{Strain Example}

Consider the case, without \textbf{Strain Shift}
$$ Where, weight_{NN} = 1, \sigma = 2 $$
\begin{center}
	\begin{tabular}{|c|c|c|c|c|c|c|}
	\hline
	2500 & 0 			& 0 & 0 &       & 0.022 & 0.016\\ \hline
	2000 & $weight_{NN}$& 0 & 0 & 0.003 & 0.022 & 0.017\\	\hline
	1500 & $weight_{NN}$& 0 & 0 & 0.005 & 0.019 & 0.015\\	\hline
	1000 & $weight_{NN}$& 0 & 0 & 0.006 & 0.014 & 0.011\\	\hline
	 500 & $weight_{NN}$& 0 & 0 & 0.005 & 0.008 & 0.006\\	\hline
	   0 & $weight_{NN}$& 0 & 0 & 0.003 & 0.003 & 0.002\\	\hline
    -500 & 0 			& 0 & 0 & 		& 0	 	& 0	\\	\hline
   -1000 & 0 			& 0 & 0 & 		& 0	 	& 0	\\
	\hline
	Offset(ms) & k=1 & k=2 & k=3 & $\approx Density$ & Strain (dec=0) & Strain (dec=0.001) \\
	\hline
\end{tabular}
\end{center}

Consider the case, with \textbf{Strain Shift}
\begin{center}
	\begin{tabular}{|c|c|c|c|}
	\hline
	2500 & 0			  & 0 		& 0 	\\ \hline
	2000 & $weight_{NN}$  & $weight_{SSh}$ 	& $weight_{SSb}$\\	\hline
	1500 & $weight_{NN}$  & $weight_{SSh}$ 	& $weight_{SSb}$\\	\hline
	1000 & $weight_{NN}$  & $weight_{SSh}$ 	& $weight_{SSb}$\\	\hline
	 500 & $weight_{NN}$  & $weight_{SSh}$ 	& $weight_{SSb}$\\	\hline
	   0 & $weight_{NN}$  & $weight_{SSh}$ 	& $weight_{SSb}$\\	\hline
    -500 & 0			  & 0 		& 0 	\\	\hline
   -1000 & 0			  & 0 		& 0 	\\
	\hline
	Offset(ms) & k=1 & k=2 & k=3\\
	\hline
\end{tabular}
\end{center}

It's hard to include the calculations in the table, so we'll look at $density_{(1,1000)}$.

$$density_{1000}^1 =
(\Delta_{(1000,0)}^{1}) +
(\Delta_{(1000,500)}^{1}) +
(\Delta_{(1000,1500)}^{1}) +
(\Delta_{(1000,2000)}^{1})$$

$$density_{1000}^1 =
\frac{1}{1000} +
\frac{1}{500} +
\frac{1}{500} +
\frac{1}{1000} = 0.006$$

$$density_{1000}^2 =
(\Delta_{(1000,0)}^{2}) +
(\Delta_{(1000,500)}^{2}) +
(\Delta_{(1000,1500)}^{2}) +
(\Delta_{(1000,2000)}^{2})$$

$$ density_{1000}^2 =
(\frac{weight_{SSh}}{1000}) +
(\frac{weight_{SSh}}{500}) +
(\frac{weight_{SSh}}{500}) +
(\frac{weight_{SSh}}{1000}) =
\frac{3 * weight_{SSh}}{250} $$

$$ density_{1000}^3 =
\frac{3 * weight_{SSb}}{250} $$

$$ density_{1000} :=
{density_{1000}^1, density_{1000}^2, density_{1000}^3} =
\lbrace0.006,
\frac{3 * weight_{SSh}}{250},
\frac{3 * weight_{SSb}}{250}\rbrace $$

\subsection{Density Generalization}

In the case where we want to find $density_n$, where, n is the offset index, k is key count.

\[
\begin{bmatrix}
	weight_{(n+\sigma,1)} & weight_{(n+\sigma,2)} & \dots  & weight_{(n+\sigma,k)} \\
	\vdots & \vdots & \udots & \vdots \\
	weight_{(n+1,1)} & weight_{(n+1,2)} & \dots  & weight_{(n+1,k)} \\
	weight_{(n,1)} & weight_{(n,2)} & \dots  & weight_{(n,k)} \\
    weight_{(n-1,1)} & weight_{(n-1,2)} & \dots  & weight_{(n-1,k)} \\
    \vdots & \vdots & \ddots & \vdots \\
    weight_{(n-\sigma,1)} & weight_{(n-\sigma,2)} & \dots  & weight_{(n-\sigma,k)}
\end{bmatrix}
\]
$$ * $$
\[
\begin{bmatrix}
	offset_{n+\sigma} & \dots & offset_{n+1} & offset_{n} & offset_{n-1} & \dots & offset_{n-\sigma}
\end{bmatrix}
\]
$$ = $$
\[
\begin{bmatrix}
	density_{n+\sigma} & \dots & density_{n+1} & density_{n} & density_{n-1} & \dots & density_{n-\sigma}
\end{bmatrix}
\]

$$
density_n :=
\begin{bmatrix}
	density_{n+\sigma} & \dots & density_{n+1} & density_{n} & density_{n-1} & \dots & density_{n-\sigma}
\end{bmatrix}
$$

From here, we can calculate the strain by running the through a python code.
\subsection{Allocating Notes to Fingers}

We cannot assume that $column_1$ where $keys = 4$ is the same as $column_1$ where $keys = 7$. This is due to how \textbf{different fingers interact with the same column}.

As to counter this, we need to find out the \textbf{most common set-up} for players.

\begin{center}
	\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}
	\hline
	key & LP & LR & LM & LI & S  & RI & RM & RR & RP\\
	\hline
	4   & {} & {} & 1  & 2  & {} & 3  & 4  & {} & {}\\
	5   & {} & {} & 1  & 2  & 3  & 4  & 5  & {} & {}\\
	6   & {} & 1  & 2  & 3  & {} & 4  & 5  & 6  & {}\\
	7   & {} & 1  & 2  & 3  & 4  & 5  & 6  & 7  & {}\\
	8   & 1  & 2  & 3  & 4  & {} & 5  & 6  & 7  & 8\\
	8S  & 1  & 2  & 3  & 4  & 5  & 6  & 7  & 8  & {}\\
	9   & 1  & 2  & 3  & 4  & 5  & 6  & 7  & 8  & 9\\
	\hline
\end{tabular}
\end{center}

\textbf{L} represents left, \textbf{R} is right, the second letter will be th	e name for the fingers (LP: Left Pinky, LR: Left Ring and so on...)

This allocation will give us a consistent result for all beatmaps, so $key=1$ will always mean \textbf{Left Pinky}, $key=2$ for \textbf{Left Ring}, and so on...

\subsubsection{8 Key Scratch Bias}
The issue with 8 Key maps is how maps will usually have a \textit{scratch column}, this will create a setup that \textbf{excludes a pinky but includes the thumb}. Due to this, we will shift the configuration to left pinky and right thumb, excluding the right pinky. See the above \textbf{8S}

\subsection{Assigning Hyperparameters}

In this section alone, we have used quite a few hyperparameters. To recap:

\paragraph{(Reading) $\theta$} is the hyperparameter for reading length.
\paragraph{(Density) $\sigma$} defines the range, front and back of the density search. Higher sigma may prove to be useless with further $\Delta_{nx}^k$ being too small.

\paragraph{(Density) $weight_{NN}$} defines for normal notes
\paragraph{(Density) $weight_{LNh}$} defines for long notes heads
\paragraph{(Density) $weight_{LNt}$} defines for long notes tails
\paragraph{(Density) $weight_{SSh}$} defines for \textbf{strain shift} for hands
\paragraph{(Density) $weight_{SSb}$} defines for \textbf{strain shift} for body

Now what we need to do is to assign a reasonable values to these, and run the results to find our:
$$ difficulty := \lbrace(offset_1, difficulty_1), (offset_2, difficulty_2), ..., (offset_n, difficulty_n)\rbrace $$

Whereby we estimate difficulty at offset \textbf{n} from the map itself:

$$ difficulty_n \approx model \left( reading_n, \sum_{k=1}^{keys} \left(strain_k \right), ... \right)$$

We can further expand this to:

$$ difficulty_n \approx model \left( count(NN), count(LNh), count(LNt), \sum_{k=1}^{keys} \left(strain_k \right)  \right)  $$

Where strain

\subsubsection{Values of Hyperparameters}

There will definitely be issues when it comes to assuming hyperparameters because of how it will affect accuracy of the model. However, as long as we \textbf{reasonably} assign them, most of the errors will be offset by the neural network learning. We just need to focus on if a certain value should be \textbf{larger/smaller} or \textbf{negative/positive}.

\paragraph{(Reading) $\theta$} 1000 (ms)

\paragraph{(Density) $\sigma$} 2

\paragraph{(Density) $weight_{NN}$} 1
\paragraph{(Density) $weight_{LNh}$} 0.75 (we will follow Reading)
\paragraph{(Density) $weight_{LNt}$} 0.75 (we will follow Reading)
\paragraph{(Density) $weight_{SSh}$} 0.25
\paragraph{(Density) $weight_{SSb}$} 0.1

\end{document}


\documentclass{jhwhw}

\usepackage{listings}

\author{}
\title{PHYS 7364 -- Homework \#2}
\date{28 January 2022}

\begin{document}

\problem{Gauge freedom in Bloch wave functions}

Wave functions generally have a freedom of what is chosen in the phase.
This is also true of Bloch wave functions $\psi_{n\mathbf k}(\mathbf r)$ which we explore here.
Define a new set of Bloch wave functions by
\begin{equation}
  \label{eq:1}
  \ket{\tilde \psi_{n\mathbf k}} = e^{-i\beta_{n}(\mathbf k)}\ket{\psi_{n\mathbf k}},
\end{equation}
where $\beta_{n}$ is a real function of $\mathbf k$. The transformation from the old set to the new set is what we will call a ``gauge transformation.''
\begin{enumerate}
  \item A ``periodic gauge'' is one for which $\ket{\psi_{n,\mathbf k+ \mathbf G}} = \ket{\psi_{n\mathbf k}}$ (i.e., equal with the same phase). What has to be true about $\beta_{n}(\mathbf k)$ if it is to preserve the periodicity of the gauge?
  \item Show that the $\ket{u_{n\mathbf k}}$ transform in the same way as the $\ket{\psi_{n\mathbf k}}$ under a gauge transform. (recall $\psi_{n\mathbf k}(\mathbf r) = e^{i \mathbf k\cdot \mathbf r} u_{n\mathbf k}(\mathbf r)$ where $u_{n\mathbf k}(r)$ is periodic with respect to a lattice vector $\mathbf R$.)
  \item We will soon be introducing the concept of ``Berry connection'' $\mathbf A_{n}(\mathbf k) = i \braket{u_{n\mathbf k} | \nabla_{\mathbf k} u_{n\mathbf k}}$. Derive an expression that describes how this transforms under a gauge transformation. That is, express $\tilde{\mathbf A}_{n}(\mathbf k) = i \braket{\tilde u_{n\mathbf k} | \nabla_{\mathbf k} \tilde u_{n\mathbf k}}$ in terms of $\mathbf A_{n}(\mathbf k)$ plus a correction.
  \item Show that $\nabla_{\mathbf k} \times \mathbf A_{n}$ is gauge-invariant.
\end{enumerate}

\problem{Bloch's theorem, finite lattices, and flux}

Consider a finite lattice given by
\begin{equation}
  \label{eq:5}
  H = -t \sum_{n=0}^{L-1} (\ket{(n+1)a}\bra{na} + \ket{na}\bra{(n+1)a}),
\end{equation}
\begin{enumerate}
  \item For the boundary conditions $\ket{L} = \ket{0}$ (periodic boundary conditions), solve this Hamiltonian for eigenvectors and eigenvalues.
  \item For the boundary conditions $\ket{L} = e^{i\vartheta} \ket{0}$ (``twisted'' boundary conditions), solve the Hamiltonian for eigenvectors and eigenvalues.
  \item Returning to $\ket{L} =\ket{0}$ (periodic), we can thread magnetic flux through the system, this is often included by \emph{Peierls substitution}, where we transform the hopping terms in the Hamiltonian $\ket{m}\bra{n} \rightarrow e^{i \int_{na}^{m a} A(x) dx} \ket{m}\bra{n}$ in the Hamiltonian, for a vector potential $A(x)$ (defined as the angular component). If this is a ring then $\oint A(x) dx = \Phi$ for an enclosed flux $\Phi$. Assuming that $A(x)$ is constant in $x$, find the eigenvalues and eigenvectors of this ring. How is $\Phi$ related to $\vartheta$ from the previous question?
  \item Now, assume we have the simple, infinite tight-binding model
        \begin{equation}
          \label{eq:7}
            H = -t \sum_{n=-\infty}^{\infty} (\ket{(n+1)a}\bra{na} + \ket{na}\bra{(n+1)a}),
        \end{equation}
        we can solve this, inefficiently, by picking a ``unit cell'' of size $L$. In particular, first show that Hamiltonian can be rewritten as
        \begin{multline}
          \label{eq:8}
          H = -t \sum_{m=-\infty}^{\infty}\bigg[ \sum_{n=0}^{L-2}( \ket{m L + n + 1}\bra{m L + n} + \ket{mL + n}\bra{mL + n + 1} ) \\ + \ket{(m+1)L}\bra{mL + L-1} + \ket{mL + L-1} \bra{(m+1)L}\bigg].
        \end{multline}
        If we take as our translation operator $\hat T_{L} = e^{-i \hat k L}$, and its eigenvalues $0 \leq kL < 2\pi$, this defines a Brillouin zone of size $2\pi/L$. What is the $L$-dimensional $k$-space Hamiltonian we get by stricting to an eigenspace of $\hat T_{L}$? Relate it back to what we found in (b) and (c). How is $k$ related to $\Phi$ and $\vartheta$? (Hint: $\ket{mL + n} = \hat T_{L}^{m} \ket{n}$)
\end{enumerate}

While we explored this in a simple 1D model, the ideas here easily generalize to higher dimensions and with more complicated unit cells.

\problem{Constructing a ``protected'' edge state}

In many models, we can pick a point in the Brillouin zone where we ``expand'' in small wave vectors and get effective ``continuum'' models.
One such case is the SSH model when $|t_{2}-t_{1}|\ll t_{1,2}$.

For this problem, we can begin with the $k$-space Hamiltonian
\begin{equation}
  \label{eq:2}
  H(\mathbf k) =
  \begin{pmatrix}
    0 & t_{1} + t_{2} e^{2 i  k a} ,\\
t_{1} + t_{2} e^{-2 i k a}  & 0
  \end{pmatrix}.
\end{equation}
\begin{enumerate}
  \item In the limit of $|t_{2}-t_{1}|\ll t_{1,2}$, what $\mathbf k$ vector has the smallest gap between energies? If this happens at $\mathbf k_{0}$, expand the Hamiltonian $H(\mathbf k_{0} + \mathbf q)$  for small $|\mathbf q|$, keeping only terms linear in $\mathbf q$.
  \item The above problem should take the form
        \begin{equation}
          \label{eq:3}
          h = v_{\mathrm F} q \sigma_{y} + m \sigma_{x},
        \end{equation}
        Find the energy eigenvalues and eigenvectors of this Hamiltonian and how they depend on $q$.
  \item To make this a continuum model let $q = -i\partial_{x}$. Further, let $m$ depend on space such that
        \begin{equation}
          \label{eq:4}
          h = -i v_{\mathrm F} \sigma_{y} \partial_{x} + m_{0} \tanh(x) \sigma_{x}.
        \end{equation}
        Find a solution to this equation with zero eigenvalue when $m_{0}>0$ and when $m_{0}<0$;  plot its magnitude in space. Finally, relate $m_{0}$ back to $t_{2}$ and $t_{1}$; what is the difference between $x<0$ and $x>0$ in the original chain? This continuum solution is due to the ``domain wall'' in the mass $m$ and is due to Jackiw and Rebbi. It is a topologically protected edge state.
\end{enumerate}

\problem{An intro to {\sc PythTB.py}}

We will use this software package to explore tight-binding models, you can find it at \url{https://www.physics.rutgers.edu/pythtb/}.
To install it on your local machine, you will need python, which can be found at \url{https://conda.io}. Once python is installed (either 2.7 or 3.x), you can install PythTB at the command prompt (terminal) with

\vspace{10pt}
{\tt pip install pythtb --upgrade}
\vspace{10pt}

or if you do not have root permissions

\vspace{10pt}
{\tt pip install pythtb --upgrade --user}
\vspace{10pt}

You will also need some standard python packages like {\sc numpy} (numerics) and {\sc matplotlib} (plotting).
This problem is to help get you acquainted with this python package. Download \texttt{benzene.py} from the course website (or see code on the next page).
If you need any help, please do not hesistate to contact me.

In this example, we will look at the tight-binding model of benzene, which is made with $p_{z}$ orbitals of Carbon atoms. The Hamiltonian is very much like we considered in Problem 2
\begin{equation}
  \label{eq:9}
  H = E_{p} \sum_{j} \ket{j}\bra{j} + t \left(\sum_{j=0}^{5} \ket{j+1} \bra{j} + \mathrm{h.c.}\right), \quad \ket{6} = \ket{0}.
\end{equation}
However, these atoms exist in a two-dimensional plane at points $\mathbf r_{j} = r (\cos(j \pi/3), \sin(j \pi/3)) $. We will need this for considering external fields.

\begin{enumerate}
  \item Identify the parameters in the code, and run the code. It should output the energies and eigenvectors (real part of them). Do these match what you found in Problem 2a?
  \item Now, we mess with the code! Modify it to have a uniform electric field in the $\hat x$ or $\hat y$ direction (your choice) by raising or lowering site energies in a way that is linear in their spatial coordinates. Make a plot of the six eigenvalues versus electric field strength. Does the behavior make sense? Explain why.
  \item Instead of an external field, now modify model by changing the hopping strength alternate between bonds such that hopping between 0-1, 2-3, and 4-5 have strength $t+\delta$ and 1-2, 3-4, and 5-0 have stengths $t-\delta$. Make a plot of the six eigenvalues versus $\delta$. Does anything special happen at $\delta=t$? Explain why?
\end{enumerate}

\newpage

\section*{{\sc benzene.py} -- From Berry Phases in Electronic Structure Theory, Appendix D.2}
\begin{lstlisting}[language=Python]
#!/usr/bin/env python
from __future__ import print_function # python3 style print

# ----------------------------------------------------------
# Tight-binding model for p_z states of benzene molecule
# ----------------------------------------------------------

from pythtb import *

# set up molecular geometry
lat=[[1.0,0.0],[0.0,1.0]]        # define coordinate frame: 2D Cartesian
r=1.2                            # distance of atoms from center
orb=np.zeros((6,2),dtype=float)  # initialize array for orbital positions
for i in range(6):               # define coordinates of orbitals
  angle=i*np.pi/3.0
  orb[i,:]= [r*np.cos(angle), r*np.sin(angle)]

# set site energy and hopping amplitude, respectively
ep=-0.4
t=-0.25

# define model
my_model=tbmodel(0,2,lat,orb)
my_model.set_onsite([ep,ep,ep,ep,ep,ep])
my_model.set_hop(t,0,1)
my_model.set_hop(t,1,2)
my_model.set_hop(t,2,3)
my_model.set_hop(t,3,4)
my_model.set_hop(t,4,5)
my_model.set_hop(t,5,0)

# print model
my_model.display()

# solve model and print results
(eval,evec)=my_model.solve_all(eig_vectors=True)

# print results, setting numpy to format floats as xx.xxx
np.set_printoptions(formatter={'float': '{: 6.3f}'.format})
# Print eigenvalues and real parts of eigenvectors, one to a line
print("  n   eigval   eigvec")
for n in range(6):
    print(" %2i  %7.3f  " % (n,eval[n]), evec[n,:].real)
\end{lstlisting}

\end{document}


\documentclass[12pt]{cdblatex}
\usepackage{exercises}
\usepackage{fancyhdr}
\usepackage{footer}

\begin{document}

% --------------------------------------------------------------------------------------------
\section*{Exercise 4.1 Differentiate a polynomial -- a limited method}

\begin{cadabra}
   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w#}::Indices(position=independent).

   def deriv (poly):

       \delta^{a}::Weight(label=\epsilon).

       bah := @(poly).

       substitute     (bah,$x^{a} -> x^{a} + \delta^{a}$)
       distribute     (bah)

       foo := @(bah) - @(poly).

       keep_weight    (foo, $\epsilon = 1$)
       sort_product   (foo)
       rename_dummies (foo)
       factor_out     (foo, $\delta^{a?}$)
       substitute     (foo, $\delta^{a} -> 1$)

       return foo

   # ---------------------------------------------------------------

   poly := c^{a}
         + c^{a}{}_{b} x^b
         + c^{a}{}_{b c} x^b x^c.    # cdb (ex-0401.100,poly)

   dpoly = deriv (poly)              # cdb (ex-0401.101,dpoly)

\end{cadabra}

\begin{dgroup*}
   \Dmath*{  p = \Cdb*{ex-0401.100} }
   \Dmath*{ dp = \Cdb*{ex-0401.101} }
\end{dgroup*}

\clearpage

% --------------------------------------------------------------------------------------------
\section*{Exercise 4.1 Differentiate a polynomial -- a better method}

\begin{cadabra}
   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w#}::Indices(position=independent).

   def deriv (poly):

       \partial{#}::PartialDerivative.
       \delta^{a}_{b}::KroneckerDelta.

       x^{a}::Depends(\partial{#}).

       bah := \partial_{b}{@(poly)}.

       distribute     (bah)
       unwrap         (bah)  # drop all terms that don't explicitly depend on a derivative operator
       product_rule   (bah)
       distribute     (bah)
       substitute     (bah,$\partial_{b}{x^{a}}->\delta^{a}_{b}$)
       eliminate_kronecker (bah)

       sort_product   (bah)
       rename_dummies (bah)

       return bah

   poly := c^{a}
         + c^{a}{}_{b} x^b
         + c^{a}{}_{b c} x^b x^c.    # cdb (ex-0401.200,poly)

   dpoly = deriv (poly)              # cdb (ex-0401.201,dpoly)

\end{cadabra}

\begin{dgroup*}
   \Dmath*{  p = \Cdb*{ex-0401.200} }
   \Dmath*{ dp = \Cdb*{ex-0401.201} }
\end{dgroup*}

\end{document}