\documentclass{amsart}
\usepackage{style/preamble}
\usepackage{parskip}
\begin{document}
\section*{Classification of surfaces}

\begin{theorem}
  Every compact Riemann surface is homeomorphic(=topologically isomorphic) to a surface of genus $g$.
  \begin{figure}[H]
    \centering \includegraphics[width=0.85\linewidth]{images/GegusGSurfaces}
    \caption{Torus, genus 2 surface, higher genus surfaces}
  \end{figure}
  Upto isomorphism, there is exactly one Riemann surface of genus 0, namely the Riemann sphere $\bbp^1$.
\end{theorem}

The genus can be thought of as the number of ``handles'' in the surface.

\textbf{Word of caution:} Two Riemann surfaces being homeomorphic does not mean that they are isomorphic as Riemann surfaces.
We will show that every elliptic curve is homeomorphic to the genus 1 surface (=torus) but not all elliptic curves are isomorphic to each other as Riemann surfaces.

\section*{Euler characteristic}
  It is possible to compute the genus using triangulations of surfaces.
  For any triangulation of a genus $g$ surface $M$ with $V$ vertices, $E$ edges, and $F$ faces, we have the following identity:
  \begin{align*}
    2 - 2g = V - E + F.
  \end{align*}
  The important point here is that the right-hand side depends on the triangulation but the left-hand side does not. The right-hand is called the Euler characteristic of $M$, denoted $\chi(M)$.

  \begin{figure}[H]
  \centering
    % \includegraphics[width=0.5\textwidth]{example-image}
    \includegraphics[width=0.45\textwidth]{images/SphereTriangulation.jpg}
    \caption{Triangulation of $S^2$ (genus=0) with $V = 4$, $E=6$, and $F = 4$ so that $V - E + F = 2 = 2 - 2 \cdot 0$.}
  \end{figure}

  \section*{Coverings of simply-connected spaces}

  A topological space $Y$ is said to be \emph{simply-connected} if it is connected and every loop in $Y$ can be continuously contracted to a point.

  \begin{figure}[H]
  \centering
    % \includegraphics[width=0.5\textwidth]{example-image}
    \includegraphics[width=0.9\textwidth]{images/S2isSimplyConnected.jpg}
  \end{figure}

  For example, the Riemann sphere $\bbp^1$ is simply-connected. If we remove a single point or a single path-connected set from $\bbp^1$, the resulting space is still simply-connected.

  But if $Y$ is the space obtained by removing two or more points from the Riemann sphere, then $Y$ is not simply-connected.

  This is the only example that concerns us.

  \begin{theorem}
    If $f: X \rightarrow Y$ is a continuous $n:1$ (covering) map and $Y$ is simply-connected then $X$ is topologically isomorphic to $n$ disjoint copies of $Y$.
  \end{theorem}
  For this theorem we do not allow any ramification points, so $f$ needs to a genuine $n:1$ (covering) map.

\end{document}


\title{Generative Adversarial Networks}

\subsection{Generative Adversarial Networks}

Generative adversarial networks (GANs) are a powerful approach for
probabilistic modeling \citep{goodfellow2014generative,goodfellow2016nips}.
They posit a deep generative model and they enable fast and accurate
inferences.

We demonstrate with an example in Edward.
An interactive version with Jupyter notebook is available
\href{http://nbviewer.jupyter.org/github/blei-lab/edward/blob/master/notebooks/gan.ipynb}{here}.

\begin{lstlisting}[language=Python]
M = 128  # batch size during training
d = 100  # latent dimension

DATA_DIR = "data/mnist"
IMG_DIR = "img"
\end{lstlisting}

\subsubsection{Data}

We use training data from MNIST, which consists of 55,000 $28\times
28$ pixel images \citep{lecun1998gradient}. Each image is represented
as a flattened vector of 784 elements, and each element is a pixel
intensity between 0 and 1.

\includegraphics[width=450px]{/images/gan-fig0.png}

The goal is to build and infer a model that can generate high quality
images of handwritten digits.

During training we will feed batches of MNIST digits. We instantiate a
TensorFlow placeholder with a fixed batch size of $M$ images.

\begin{lstlisting}[language=Python]
from tensorflow.examples.tutorials.mnist import input_data

mnist = input_data.read_data_sets(DATA_DIR)
x_ph = tf.placeholder(tf.float32, [M, 784])
\end{lstlisting}

\subsubsection{Model}

GANs posit generative models using an implicit mechanism. Given some
random noise, the data is assumed to be generated by a deterministic
function of that noise.

Formally, the generative process is
\begin{align*}
\mathbf{\epsilon} &\sim p(\mathbf{\epsilon}), \\
\mathbf{x} &= G(\mathbf{\epsilon}; \theta),
\end{align*}
where $G(\cdot; \theta)$ is a neural network that takes the samples
$\mathbf{\epsilon}$ as input. The distribution
$p(\mathbf{\epsilon})$ is interpreted as random noise injected to
produce stochasticity in a physical system; it is typically a fixed
uniform or normal distribution with some latent dimensionality.

In Edward, we build the model as follows, using TensorFlow Slim to
specify the neural network. It defines a 2-layer fully connected neural
network and outputs a vector of length $28\times28$ with values in
$[0,1]$.

\begin{lstlisting}[language=Python]
from edward.models import Uniform
from tensorflow.contrib import slim

def generative_network(eps):
  h1 = slim.fully_connected(eps, 128, activation_fn=tf.nn.relu)
  x = slim.fully_connected(h1, 784, activation_fn=tf.sigmoid)
  return x

with tf.variable_scope("Gen"):
  eps = Uniform(tf.zeros([M, d]) - 1.0, tf.ones([M, d]))
  x = generative_network(eps)
\end{lstlisting}

We aim to estimate parameters of the generative network such
that the model best captures the data. (Note in GANs, we are
interested only in parameter estimation and not inference about any
latent variables.)

Unfortunately, probability models described above do not admit a tractable
likelihood. This poses a problem for most inference algorithms, as
they usually require taking the model's density.  Thus we are
motivated to use ``likelihood-free'' algorithms
\citep{marin2012approximate}, a class of methods which assume one
can only sample from the model.

\subsubsection{Inference}

A key idea in likelihood-free methods is to learn by
comparison (e.g., \citet{rubin1984bayesianly,gretton2012kernel}): by
analyzing the discrepancy between samples from the model and samples
from the true data distribution, we have information on where the
model can be improved in order to generate better samples.

In GANs, a neural network $D(\cdot;\phi)$ makes this comparison,
known as the discriminator.
$D(\cdot;\phi)$ takes data $\mathbf{x}$ as input (either
generations from the model or data points from the data set), and it
calculates the probability that $\mathbf{x}$ came from the true data.

In Edward, we use the following discriminative network. It is simply a
feedforward network with one ReLU hidden layer. It returns the
probability in the logit (unconstrained) scale.

\begin{lstlisting}[language=Python]
def discriminative_network(x):
  h1 = slim.fully_connected(x, 128, activation_fn=tf.nn.relu)
  logit = slim.fully_connected(h1, 1, activation_fn=None)
  return logit
\end{lstlisting}

Let $p^*(\mathbf{x})$ represent the true data distribution.
The optimization problem used in GANs is

\begin{equation*}
\min_\theta \max_\phi~
\mathbb{E}_{p^*(\mathbf{x})} [ \log D(\mathbf{x}; \phi) ]
+ \mathbb{E}_{p(\mathbf{x}; \theta)} [ \log (1 - D(\mathbf{x}; \phi)) ].
\end{equation*}

This optimization problem is bilevel: it requires a minima solution
with respect to generative parameters and a maxima solution with
respect to discriminative parameters.
In practice, the algorithm proceeds by iterating gradient updates on
each. An additional heuristic also modifies the objective function for the
generative model in order to avoid saturation of gradients
\citep{goodfellow2014on}.

Many sources of intuition exist behind GAN-style training. One, which
is the original motivation, is based on idea that the two neural
networks are playing a game. The discriminator tries to best
distinguish samples away from the generator. The generator tries
to produce samples that are indistinguishable by the discriminator.
The goal of training is to reach a Nash equilibrium.

Another source is the idea of casting unsupervised learning as
supervised learning
\citep{gutmann2010noise,gutmann2014statistical}.
This allows one to leverage the power of classification—a problem that
in recent years is (relatively speaking) very easy.

A third comes from classical statistics, where the discriminator is
interpreted as a proxy of the density ratio between the true data
distribution and the model
\citep{sugiyama2012density,mohamed2016learning}. By augmenting an
original problem that may require the model's density with a
discriminator (such as maximum likelihood), one can recover the
original problem when the discriminator is optimal. Furthermore, this
approximation is very fast, and it justifies GANs from the perspective
of approximate inference.

In Edward, the GAN algorithm (\texttt{GANInference}) simply takes the
implicit density model on \texttt{x} as input, binded to its
realizations \texttt{x_ph}. In addition, a parameterized function
\texttt{discriminator} is provided to distinguish their
samples.

\begin{lstlisting}[language=Python]
inference = ed.GANInference(
    data={x: x_ph}, discriminator=discriminative_network)
\end{lstlisting}

We'll use ADAM as optimizers for both the generator and discriminator.
We'll run the algorithm for 15,000 iterations and print progress every
1,000 iterations.

\begin{lstlisting}[language=Python]
optimizer = tf.train.AdamOptimizer()
optimizer_d = tf.train.AdamOptimizer()

inference.initialize(
    optimizer=optimizer, optimizer_d=optimizer_d,
    n_iter=15000, n_print=1000)
\end{lstlisting}

We now form the main loop which trains the GAN. At each iteration, it
takes a minibatch and updates the parameters according to the
algorithm. At every 1000 iterations, it will print progress and also
saves a figure of generated samples from the model.

\begin{lstlisting}[language=Python]
sess = ed.get_session()
tf.global_variables_initializer().run()

idx = np.random.randint(M, size=16)
i = 0
for t in range(inference.n_iter):
  if t % inference.n_print == 0:
    samples = sess.run(x)
    samples = samples[idx, ]

    fig = plot(samples)
    plt.savefig(os.path.join(IMG_DIR, '{}.png').format(
        str(i).zfill(3)), bbox_inches='tight')
    plt.close(fig)
    i += 1

  x_batch, _ = mnist.train.next_batch(M)
  info_dict = inference.update(feed_dict={x_ph: x_batch})
  inference.print_progress(info_dict)
\end{lstlisting}

Examining convergence of the GAN objective can be meaningless in
practice. The algorithm is usually run until some other criterion is
satisfied, such as if the samples look visually okay, or if the GAN
can capture meaningful parts of the data.

\subsubsection{Criticism}

Evaluation of GANs remains an open problem---both in criticizing their
fit to data and in assessing convergence.
Recent advances have considered alternative objectives and
heuristics to stabilize training (see also Soumith Chintala's
\href{https://github.com/soumith/ganhacks}{GAN hacks repo}).

As one approach to criticize the model, we simply look at generated
images during training. Below we show generations after 14,000
iterations (that is, 14,000 gradient updates of both the generator and
the discriminator).

\includegraphics[width=500px]{/images/gan-fig1.png}

The images are meaningful albeit a little blurry. Suggestions for
further improvements would be to tune the hyperparameters in the
optimization, to improve the capacity of the discriminative and
generative networks, and to leverage more prior information (such as
convolutional architectures).

\subsubsection{References}\label{references}


\documentclass{article}

\usepackage{defaults}
\usepackage[exp]{macros}
\usepackage[caption, title, reference]{document_style}

\usepackage{txfonts}

\begin{document}

\section{Section}%
\label{sec:section}

1\supscr{st} 2\subscr{eme}

\raggedright{}
\textit{i.e.}  \textit{e.g.} \textit{etc.} \textit{viz.} \textit{et al.}
\textit{vice versa}\par
\textit{i.e.}\  \textit{e.g.}\ \textit{etc.}\ \textit{viz.}\ \textit{et al.}\
\textit{vice versa}\par
\ie{}\ \eg{}\ \etc{}\ \viz{}\ \etal{}\ \vive{}

$\dif{x}$ $\diff{y}{x}$ $\pdif{x}$ $\pdiff{y}{x}$

$\vec{a}$ $\unit{b}$ $\norm{\vec{c}}$

$\trans{\vec{M}}$

\begin{equation}
  \e{- \beta k_{\mathrm{B}} T}
  \label{eq:boltzmann}
\end{equation}

A famous statistical mechanics expression \cref{eq:boltzmann}

$\epsilon$ $\varepsilon$

$\phi$ $\varphi$

\cref{sec:section}

\section{Another Section}

\end{document}


\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
%% Language and font encodings
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{float}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsmath}

\algdef{SE}[DOWHILE]{Do}{doWhile}{\algorithmicdo}[1]{\algorithmicwhile\ #1}

\usepackage{url}
\usepackage[top=2.5cm, bottom=2.5cm, left=2.5cm,
	right=2.5cm, marginparwidth=1.7cm]{geometry}
\usepackage{lastpage}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhead[R]{Page \thepage\ of\ \pageref{LastPage}}
\fancyhead[C]{SSMES}
\fancyhead[L]{}

\usepackage[colorlinks=true, allcolors=blue]{hyperref}

\title{School of Science and Math Exam Scheduler (SSMES) Help File\footnote{\url{https://github.com/maxhirsch/ssmes}}}
\date{Spring 2019}

\begin{document}

\maketitle
\tableofcontents
\newpage

\section{Introduction}
The School of Science and Math Exam Scheduler (SSMES) is the result of a 2019 Mini-Term project at the North Carolina School of Science and Mathematics which aimed to reduce the number of exam conflicts at the school. Students involved in the Mini-Term were Daniel Carter, Edward Feng, Kathleen Hablutzel, and Max Hirsch. This documentation serves as a help guide in running the interface for the code which minimizes exam conflicts.

\section{About the Minimization Algorithm}
Below we outline the general algorithm for determining low-conflict exam schedules. It by no means produces the lowest-conflict schedule, but it maintains similar structure to previous exam schedules while reducing conflicts. The algorithm is more precisely described in the code on \href{https://github.com/maxhirsch/ssmes}{Github}. In the algorithm, a \textit{conflict} is when a student has more than one exam in the same exam block. Previously, NCSSM had three exams each day during exam week, allowing another type of conflict in which a student had three exams in a 24 hour period. Our solution was to remove one exam period from each day so that students could no longer have this conflict.
\begin{algorithm}
	\caption{Creating low-conflict exam schedule}
	\textbf{Result:} Exam blocks with relatively few conflicts
	\begin{algorithmic}[1]
		\Procedure{Reduce Conflicts}{}
		\For{n trials}
			\State Split departments
			\State Randomly assign departments to exam blocks
			\Do
				\State Swap departments between exam blocks if the swap reduces conflicts
			\doWhile{conflicts reduced}
		\EndFor
		\EndProcedure
	\end{algorithmic}
\end{algorithm}

\begin{algorithm}
	\label{alg:split}
	\caption{Splitting Departments}
	\textbf{Result:} Departments which may or may not be split into two
	\begin{algorithmic}[1]
		\Procedure{Split Departments}{$definite\_split$, $restricted\_split$}
		\For{n trials}
			\State Split $definite\_split$ departments
			\State Split any non $restricted\_split$ departments if there are courses with no intra-department conflicts
		\EndFor
		\EndProcedure
	\end{algorithmic}
\end{algorithm}

\section{Available Settings}
In this section, we describe each of the settings in SSMES.

\subsection{Term Schedule}
Under \textit{Settings $\to$ Term Schedule}, the school schedule can be toggled from trimester to semester.
\subsection{Total Random Trials}
Under \textit{Settings $\to$ Total Random Trials}, the number of random initializations of schedules can be set. The default value is 5. Larger values of this setting will result in fewer conflicts, but the minimization will take a longer time.
\subsection{Random Seed}
Under \textit{Settings $\to$ Random Seed}, the random seed for Total Random Trials can be set. The default value is 42.

\section{Entry Fields}
In this section, we describe each of the fields on the main screen of SSMES.

\subsection{Term}
Term is the trimester (T1, T2, or T3) or semester (S1 or S2) for which you would like to create an exam schedule. The term must chosen in the list before any data can be loaded.
\subsection{Data File}
The data file field is where you input the name/location of the file which contains course enrollment data. You can browse for this data by clicking "Choose File" beside the entry field. The data file must follow a specific format which we outline below.
\subsubsection{Data File Format}
The data file with course enrollment data is a .csv file formatted in the following way:\newline\newline
StudentID,Trimester,Course1,Course2,...\newline
1,1,0,1,...\newline
2,1,0,0,...\newline
3,1,1,0,...\newline
\newline
\noindent If on a semester schedule, "Semester" would appear in the header line rather than "Trimester." Course1, Course2,... represent the course numbers with two alphabetic characters followed by three numeric characters (e.g. CH401). Each row is the student ID followed by the term (1, 2, or 3 if a Trimester schedule; 1 or 2 if Semester), and a list of 1s and 0s according to whether or not respectively a student is taking that column's course. An example file can be found on the project \href{https://github.com/maxhirsch/ssmes}{Github}.
\subsection{Number of Exam Days}
Number of Exam Days is the number of days on which exams will be held. If, for example, it is 4, then there will be $2*4=8$ exam blocks.
\subsection{Courses and Excluded Courses}
\label{sec:excludedcourses}
The Courses field will be populated when you load data in the Data File field. You can then exclude courses from the minimization (e.g. classes without exams or with final papers instead of exams) by clicking the course then clicking "To Excluded." You can move an excluded course back to the Courses field by clicking on the course in the Excluded Courses field and clicking "From Excluded." Once data is loaded from the Data File field, you can also load excluded courses into the Excluded Courses field by choosing an Excluded Courses file. This can be done with the Excluded Courses File field which is found below the Excluded Courses field. This file must be formatted in a particular way which we describe below.
\subsubsection{Excluded Courses File}
The Excluded Courses file should be formatted such that each excluded course is on its own line with no other characters surrounding it. For example:\newline\newline
MA470\newline
RE120\newline
MA472\newline
\newline
and so on.
\subsection{Departments}
The Departments field will be populated when data is loaded in the Data File field. Departments can be split in the algorithm. We allow the user to explicitly split or not split departments by moving departments to the Definite Split Departments and Restricted Split Departments fields respectively in a manner similar to that of moving courses to excluded courses described in subsection \ref{sec:excludedcourses}. The splitting of departments can also be inferred according to the rule described in algorithm \ref{alg:split}. This inference can be enabled by checking the Infer Splits checkbox below the Restricted Split Departments field.

\section{Output}
The result of the optimization is two files. The user will provide a filename, \textit{fn}, and a popup will allow the user to select a folder to which the files should be saved. The files will be saved as $\textit{fn}\text{\_department\_courses.json}$ and $\textit{fn}\text{\_exam\_blocks.json}$. $\textit{fn}\text{\_department\_courses.json}$ contains the departments and their associated courses (a split department will end with a suffix to denote this). $\textit{fn}\text{\_exam\_blocks.json}$ will contain each exam block with the departments in that exam block. Note that there is no actual ordering to the exam blocks, as the order of the blocks themselves will not affect the total number of conflicts.

\end{document}