\documentclass{memoir}
\usepackage{notestemplate}

% \begin{figure}[ht]
%     \centering
%     \incfig{riemmans-theorem}
%     \caption{Riemmans theorem}
%     \label{fig:riemmans-theorem}
% \end{figure}

\begin{document}

\section{Finite Fields}
\label{sec:finite_fields}
\begin{thm}
	Let \(F\) be a finite field. \(\left| F \right| = p^{k}\), \(p\) prime. Conversely, for every \(p^{k}\) there exists exactly one \(F\) such that \(\left| F \right| = p^{k}\)
\end{thm}
\begin{proof}
We will show that the \( \textrm{dim} = k\); namely that there exists a basis \(b_1,\ldots,b_k\) that generates all elements in \(F\) uniquely by
\begin{align*}
	a = \lambda_1 b_1 + \ldots + \lambda_k b_k
\end{align*}
where \(\lambda_1,\ldots,\lambda_k \in \Z_p\), which by our other theorem is a subfield. This is isomorphic to \(\Z_p[x] / (g)\) which is \(F\). Observe that \( \textrm{deg}g = k\)These are the residues mod \(g\), or
\begin{align*}
	a_0 + a_1x + \ldots + a_{k-1}x^{k-1}
\end{align*}
Each \(a_i\) can be chosen \(p\) ways, so then \(\left| F \right| = p^{k}\), as desired.
\end{proof}
\begin{thm}
	For any element \(a \in F\) a finite field,
	\begin{align*}
		a + \ldots + a = 0
	\end{align*}
	where \(a\) is added exactly \(p\) times.
\end{thm}
\begin{proof}
For all \(a\) there exists an \(n\) such that
\begin{align*}
	a+\ldots+a = 0
\end{align*}
when \(a\) is added \(n\) times, because eventually the sequence \(a, a+a, a+a+a, \ldots\) must repeat, and then you'll have your \(n\). There are infinite solutions, but finitely many elements in \(F\). This implies that
\begin{align*}
	a + \ldots + a = a + \ldots + a
\end{align*}
where on the LHS, \(a\) is added \(i\) times, and on the RHS added \(j\) times.\\
Assume that \(i < j\). Observe that
\begin{align*}
	a + \ldots + a = 0
\end{align*}
for \(j-i\) additions. Now assume that \(a \neq 0\). Then multiply both sides by \(b\) implies
\begin{align*}
	\forall b, b + \ldots + b = 0
\end{align*}
because we can factor. Thus the assumption holds. Now we want to find the smallest \(n>0\). Assume for the sake of contradiction that \(n = kl\), both greater than \(1\) (not prime). Then we can separate the sum into blocks of \(k\) and blocks of \(l\). Then
\begin{align*}
	\underbrace{a+\ldots+a}_k + \underbrace{\ldots}_{l} + \underbrace{a+\ldots+a}_k = 0
\end{align*}
By assumption  \(a+\ldots+a\) is non-zero, so it is some \(b \in F\). But then \(\underbrace{b+\ldots+b}_l = 0\), which is a contradiction. So it has to be prime, as desired.
\end{proof}
\begin{thm}
	Let \(F\) be a finite field. Then
	\begin{align*}
		F = \left\{ 0,1,\alpha,\alpha^2,\ldots,\alpha ^{\left| F \right| -2}\right\}
	\end{align*}
	and \(\alpha ^{\left| F \right| -1} = 1\)
\end{thm}
\begin{thm}[Finite Field Extensions]
	For all finite fields \(F\),there exists an \(H\leq F\) such that \(H \cong \Z_p\) for some \(p\). Furthermore, \(F\) is a vector space over \(\Z^{p}\).
\end{thm}
\(F\) is then a field extension of \(H\).
Consider
\begin{align*}
	H = \left\{ 0,1,1+1,\ldots,\underbrace{1+\ldots+1}_{p-1} \right\}
\end{align*}
Observe that adding and multiplying elements works like traditional addition and subtraction; namely that
\begin{align*}
(t\cdot 1)+(s\cdot 1) = (s+t) \pmod p \cdot 1
\end{align*}
for \(0\leq t\leq p-1\) and
\begin{align*}
	(\underbrace{1+\ldots+1}_t)\cdot (\underbrace{1+\ldots+1}_s) = ( ts) \pmod p \cdot 1
\end{align*}
and so the isomorphism to \(\Z_p\) holds, as all the elements can then be written by multiplication of \(0\leq t\leq p-1\) and \(1\).
\begin{thm}
	For any finite field \(F\), \(F \cong \Z_{p[x]} / (g)\) where \(g\) is a polynomial over \(\Z_p\), \( \textrm{deg }g = k\), \(g\) irreducible over \(\Z_p\)
\end{thm}
\end{document}

Abstract Algebra - Introductory/Algebra I/Notes/source/2020-03-11-FiniteFields.tex


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% UMB-CS114-2015F: Introduction to Programming in Java
% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>
% Creative Commons Attribution-ShareAlike 4.0 International License
% More info: https://github.com/ghorbanzade/UMB-CS114-2015F
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \topDirectory {.}
\def \texDirectory {\topDirectory/src/main/tex}

\documentclass[12pt,letterpaper,twoside]{article}
\usepackage{\texDirectory/template/style/directives}
\usepackage{\texDirectory/template/style/assignment}
\input{\texDirectory/template/config}

\begin{document}

\doc{title}{Midterm Exam}
\doc{points}{20}

\prepare{header}

\section*{Question 1}

The following programs have each a \textbf{single} compilation error given below.
You are expected to find and fix the error so that given command-line arguments will lead to expected output as indicated.

\begin{enumerate}[label=\textbf{(\alph*)}]

\item Execution Script \hfill Expected Output\\
\texttt{java HelloWorld President} \hfill \texttt{Hello President!}
\begin{lstlisting}
public class HelloWorld {
	public static void main(String[] args) {
		System.out.println("Hello + args[0] + "!");
	}
}
\end{lstlisting}

\begin{terminal}
HelloWorld.java:3: error: ')' expected
    System.out.println("Hello + args[0] + "!");
HelloWorld.java:3: error: unclosed string literal
    System.out.println("Hello + args[0] + "!");
HelloWorld.java:3: error: ';' expected
    System.out.println("Hello + args[0] + "!");
HelloWorld.java:5: error: reached end of file while parsing
}
4 errors
\end{terminal}

\newpage

\item Execution Script \hfill Expected Output\\
\texttt{java Feet2Centimeters 5} \hfill \texttt{152.4}
\begin{lstlisting}
public class Feet2Centimeters {
	public static void main(String[] args) {
		double conversion = 30.48;
		double cm = args[0] * conversion;
		System.out.println(cm);
	}
}
\end{lstlisting}

\begin{terminal}
Feet2Centimeters.java:4: error: bad operand types for binary operator '*'
        double cm = args[0] * conversion;
1 error
\end{terminal}

\item Execution Script \hfill Expected Output\\
\texttt{java SphereSurface 7} \hfill \texttt{615.75}

\begin{lstlisting}
public class SphereSurface {
	public static void main(String[] args) {
		double radius = Double.parseDouble(args[0]);
		double surface = 4 * Math.PI * pow(radius, 2);
		System.out.printf("%.2f\n", surface);
	}
}
\end{lstlisting}

\begin{terminal}
SphereSurface.java:4: error: cannot find symbol
        double surface = 4 * Math.PI * pow(radius, 2);
1 error
\end{terminal}

\newpage

\item Execution Script \hfill Expected Output\\
\texttt{java Factorial 5} \hfill \texttt{120}

\begin{lstlisting}
public class Factorial {
	public static void main(String[] args) {
		int num = Integer.parseInt(args[0]);
		int counter = 1;
		int result = 1;
		do
			result *= counter;
			counter++;
		while (counter <= num);
		System.out.println(result);
	}
}
\end{lstlisting}

\begin{terminal}
Factorial.java:7: error: while expected
	result *= counter;
Factorial.java:8: error: illegal start of expression
	counter++;
Factorial.java:8: error: ';' expected
	counter++;
Factorial.java:9: error: not a statement
	while (counter <= num);
4 errors
\end{terminal}

\end{enumerate}

\newpage

\section*{Question 2}

The following code snippet had been written on a scrap of paper found in a trashcan of a classroom.
The program is error-free and functions as expected but unfortunately no one knows what it does.
Read the code snippet and explain how it works.
No assumption can be made about user input except that the input is always an integer.

\begin{lstlisting}
import java.util.Scanner;
public class FiveStar {
	public static void main(String[] args) {
		Scanner key = new Scanner(System.in);
		System.out.printf("Insert Number: ");
		int num = key.nextInt();
		int rand = (int) (Math.random() * 100) + 1;
		double result = num * Math.pow(1, rand);
		double sum = 0;
		int var = 0;
		while (var != 6) {
			sum += Math.pow(-1, var) * result;
			var++;
		}
		System.out.printf("Result is %.2f\n", sum);
	}
}
\end{lstlisting}

\newpage

\section*{Question 3}

Write a program \texttt{NumberLimit.java} that prompts user for a strictly positive integer number $x$ and prints the largest non-negative integer number $y$ such that $y^3 < x$.
For simplicity, assume the user input is always a strictly positive integer number.
Following is an expected sample run of your program.

\begin{terminal}
$ javac NumberLimit.java
$ java NumberLimit
Upper Limit? 70
Number is 4.
\end{terminal}

\end{document}


%\documentclass[letterpaper,12pt]{report}
\documentclass[letterpaper,12pt]{article}

% set 1" margins on 8.5" x 11" paper
% top left is measured from 1", 1"
\topmargin 0in
\oddsidemargin 0in
\evensidemargin 0in
\headheight 0in
\headsep 0in
\topskip 0in
\textheight 9in
\textwidth 6.5in

% Packages
%\usepackage{graphicx}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{amsmath}
\usepackage[version=4]{mhchem}
\usepackage{siunitx}
\usepackage{esvect}

% Configuration
% Unit display preferences
\sisetup{per-mode = symbol-or-fraction,inter-unit-product = \ensuremath{{}\cdot{}}}
%\sisetup{per-mode = fraction,inter-unit-product = \ensuremath{{}\cdot{}}}

\begin{document}
\pagestyle{plain}
%\markright{Valuation}

\title{PHYS212 - Chap 21 Notes - Coulomb's Law}
\author{Sam Nelson}
\date{5/6/2020}
\maketitle

\setcounter{tocdepth}{1} % whether to display sub- or subsubsections in toc
\tableofcontents

% set these after the TOC
\setlength{\parindent}{0em}
\setlength{\parskip}{1em}
\setlength\arraycolsep{2pt}

\section{Introduction}

\textit{Electrostatic force exerted by charged particles}

Charles-Augustin de Coulomb - 1785

The mathmatical form of the law (vector):

\begin{equation} \label{x1}
	\vec{F} = k\frac{q_1 q_2}{r^2}\hat{r}
\end{equation}

Where:

\begin{tabular}{l|l}
	$q_1$ & Charge 1 \\
	$q_2$ & Charge 2 \\
	$r$ & Particle separation \\
	$\hat{r}$ & Unit vector \\
	$k$ & Electrostatic/Coulomb Constant \\
\end{tabular}

Note the similarity between Coulomb's law and Newton's equation for the gravitational force between two particles

\begin{equation}
	\vv*{F} = G\frac{m_1 m_2}{r^2}\hat{r}
\end{equation}

The unit of charge is known as a \textit{Coulomb} and is defined in relation to the
\textit{Ampere}

\begin{equation} \label{x2}
	i = \frac{dq}{dt}
\end{equation}

In this case, current is defined as the rate at which charge moves past a point or region.

Re-arranging, the units are related as so:

\begin{equation}
	1C = 1A \times 1s
\end{equation}

The magnitude of the electrostatic force is represented by:

\begin{equation}
	F = \frac{1}{4\pi\epsilon_0}\frac{|q_1||q_2|}{r^2}
\end{equation}

where $k = \frac{1}{4\pi\epsilon_0} = \SI{8.99e9}{\newton\meter\squared\per\coulomb\squared}$

or

\begin{equation}
	k = \frac{1}{4\pi\epsilon_0} = \SI{8.99e9}{\newton\meter\squared\per\coulomb\squared}
\end{equation}

with $\epsilon_0$ known as the \textit{Permittivity constant}
\begin{equation}
	\epsilon_0 = \SI{8.85e-12}{\coulomb\squared\per\newton\meter\squared}
\end{equation}

Principle of superposition. To find the net force on a particle, sum all the forces acting on that
particle.

\begin{equation}
	\vec{F_{1,net}} = \vec{F_{12}} + \vec{F_{13}} + \vec{F_{14}} + \vec{F_{15}} + \cdots + \vec{F_{1n,}}
\end{equation}

\begin{equation}
	\vv*{F}{1,\text{net}} = \vv*{F}{12} + \vv*{F}{13} + \vv*{F}{14} + \vv*{F}{15} + \cdots + \vv*{F}{1n,}
\end{equation}

%\begin{figure}[h]
%	\centering
%	\includegraphics[scale=0.8]{sine}
%	\caption{$\sin(x)$}
%	\label{sine}
%\end{figure}

%\begin{tikzpicture}
%	\begin{axis}[domain=3/4:5/4,legend pos=outer north east,trig format plots=rad]
%		\addplot {sin(2*pi*x)};
%		\addplot {cos(2*pi*x)};
%		\legend{$\sin(2 \pi x)$,$\cos(2 \pi x)$}
%	\end{axis}
%\end{tikzpicture}

\paragraph{Shell theory 1} A charged particle outside a shell with charge uniformly distributed on its surface is attracted to or repelled as if the shell's charge were concentrated as a particle at its center.

\paragraph{Shell theory 2} A charged particle inside a shell with charge uniformly disributed on its surface has no net force acting on it due to the shell.

\begin{tikzpicture}
\begin{axis}[
  axis lines=middle,
  grid=major,
  xmin=-5,
  xmax=5,
  ymin=-3,
  ymax=5,
  xlabel=$x$,
  ylabel=$y$,
  xtick={-4,-3,...,4},
  ytick={-2,-1,...,4},
  tick style={very thick},
  legend style={
  at={(rel axis cs:0,1)},
  anchor=north west,draw=none,inner sep=0pt,fill=gray!10}
]
\addplot[blue,thick,samples=100] {x^2};
\addlegendentry{$y=x^2$}
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[
  axis lines=middle,
  grid=major,
  xmin=-2,
  xmax=2,
  ymin=-2,
  ymax=2,
  xlabel=$x$,
  ylabel=$y$,
  xtick={-2,-1,...,2},
  ytick={-2,-1,...,2},
  tick style={very thick},
]
\draw [->,very thick,teal] (0,0) -- node[above] {$\vv*{F}{1}$} (2,1);
	\draw [->,very thick,red] (0,0) -- node[below,left] {$\vv*{F}{2}$} (-1,2);
\end{axis}
\end{tikzpicture}

\section{Quantization of Charge}

Any positive or negative charge $q$ that can be detected, can be written as

\begin{equation}
	q = ne, \quad n = \pm 1, \pm 2, \pm 3, \dots ,
\end{equation}

In which $e$, the \textbf{elementary charge,} has the approximate value

\begin{equation}
	e = \SI{1.602e-19}{\coulomb}
\end{equation}

\section{Conservation of Charge}

Charge is not created or destroyed, it is transfered. This hypothesis is known as \textbf{conservation of charge}.
\\
An example is the radioactive decay of uranium-238 ($\ce{^{238}_{}U}$).

\begin{equation}
	\ce{^{238}_{}U -> ^{234}_{}Th + ^{4}_{}He,}
\end{equation}

The \textit{parent} nucleus $\ce{^{238}_{}U}$ contains 92 protons, with a charge of $+92e$, the \textit{daughter} nucleus \ce{^{234}_{}Th} contains 90 protons, with a charge of $+90e$ and the emitted alpha particle \ce{^{4}_{}He} contains 2 protons, with a charge of $+2e$. Total charge is $+92e$ before and after the decay, thus charge is conserved.
\\
Another example of this charge conservation is when an electron $\mathrm{e}^-$ (charge $-e$) and its antiparticle, the \textit{positron} $\mathrm{e}^+$ (charge $+e$), undergo an \textit{annihilation process}, transforming into two \textit{gamma rays}:

\begin{equation}
	e^- + e^+ \longrightarrow \gamma + \gamma \quad \text{(annihilation).}
\end{equation}

In \textit{pair production}, charge is also conserved. Example, a gamma ray transforming into an electron and a positron:

\begin{equation}
	\gamma \longrightarrow e^- + e^+ \quad \text{(pair production).}
\end{equation}

\end{document}


\section{The \isheapuntil algorithm}
\Label{sec:isheapuntil}

The \isheapuntil algorithm of the \cxx Standard Library \cite[\S
28.7.7.5]{cxx-17-draft} works on generic sequences.
For our purposes we have modified the generic implementation
to that of an array of type \valuetype.
The signature now reads:

\begin{lstlisting}[style = acsl-block]

    size_type is_heap_until(const value_type* a, int n);
\end{lstlisting}

The algorithm \isheapuntil returns the largest range of an array, beginning at the first position, where it still satisfies the heap properties
we have semi-formally described in the beginning of this chapter.
In particular, \isheapuntil will return the size of the array,
called with the array argument from Figure~\ref{fig:heap-array}.

\clearpage

\subsection{Formal specification of \isheapuntil}

The specification of \isheapuntil is shown in the following listing.
The index \inl{\\result} returned by \isheapuntil indicates
that the array \inl{a[0..\\result-1]} is a heap.
In addition the postcondition \inl{last} states, that for all indices
greater than or equal to \inl{i} the predicate \logicref{Heap} is not satisfied.

\input{Listings/is_heap_until.h.tex}

\subsection{Implementation of \isheapuntil}

The following listing shows one way to implement the function \isheapuntil.

\input{Listings/is_heap_until.c.tex}

The algorithms starts at the index~1, which is the smallest index,
where a child node of the heap might reside.
The algorithms checks for each (child) index whether
the value at the corresponding parent index
is greater than or equal to the value at the child index.
If the value at a parent index is smaller than the value at a (child) index,
\isheapuntil returns the (child) index.
Otherwise, if the algorithm iterates through the whole array,
the size of the array is returned.


% -----------------------------------------------
% Template for ISMIR Papers
% 2018 version, based on previous ISMIR templates

% Requirements :
% * 6+n page length maximum
% * 4MB maximum file size
% * Copyright note must appear in the bottom left corner of first page
% * Clearer statement about citing own work in anonymized submission
% (see conference website for additional details)
% -----------------------------------------------

\documentclass{article}
\usepackage{ismir,amsmath,cite,url}
\usepackage{graphicx}
\usepackage{color}

% Title.
% ------
\title{GraphDitty: A Software Suite for Geometric Music Structure Visualization}

% Note: Please do NOT use \thanks or a \footnote in any of the author markup

% Single address
% To use with only one author or several with the same address
% ---------------
\oneauthor
 {Christopher J. Tralie}
 {Duke University Department of Mathematics}

\sloppy % please retain sloppy command for improved formatting
\graphicspath{{Figures/}}

\begin{document}

%
\maketitle
%
\begin{abstract}
    In this work, we present a new twist on music structure analysis and visualization.  We devise a technique\footnote{This is a refinement of / followup to our prior works ``scaffolding and spines'' \cite{bendichgeometric} and ``Loop Ditty'' \cite{tralie2017Dissertation}} to create clean audio self-similarity matrices at the song level by fusing multiple features upstream.  We then derive multiple geometric features from this representation to elucidate hierarchical structure, including Laplacian eigenvectors, spring graph layouts, and diffusion maps.  We then provide a suite of Javascript visualization tools to view the SSMs and derived features synchronized with the audio they represent.  Our code is clean with the help of Numpy/Scipy/Librosa on the Python end and d3.js on the Javascript end, but it can be treated as a blackbox for users who would like to engage with the visualizations without delving into the technical details.  Code can be found at \url{http://www.github.com/ctralie/GraphDitty}, and a live demo is present at \url{http://www.covers1000.net/GraphDitty}.
\end{abstract}

\section{Similarity fusion}\label{sec:fusion}

The self-similarity matrix (SSM) is a common data structure through which to visualize recurrence in musical audio.  For a particular feature type, the SSM is a symmetric distance matrix $D$ which records all pairwise distances between windows in time, as measured by that feature.  Let $D^C$ be a matrix measuring the cosine distance between stacked-delayed\footnote{We use stack-delayed features to promote diagonal structures, as shown in \cite{tralie2017quasi}}\cite{serra2009cross} chroma features, and let $D^M$ be a matrix measuring the Euclidean distance between stack-delayed MFCCs.  The we can apply a {\em similarity kernel} to each of them so that $W^C_{ij} = \exp (-(D^C_{ij})^2 / (2 \sigma_{ij}^2) )$, and likewise for $W^M$ for $D^M$, where $\sigma_{ij}$ is a mutual nearest neighbor autotuned distance (see \cite{wang2012unsupervised, wang2014similarity} for more details); that is, large values indicate more similar  windows.  We then run a graph-based algorithm known as {\em similarity network fusion (SNF)}\cite{wang2012unsupervised, wang2014similarity, Chen2017CSFusion}  to create an aggregated similarity kernel $W^F$ from $W^C$ and $W^M$, which promotes the strengths of both feature types and mitigates their weaknesses.  This is similar to what we did for cover songs in \cite{tralie2017cover}, though it works on self-similarity instead of cross-similarity, and it does not require beat-synchronous features.  We can also compute eigenvectors of the graph laplacian on $W^F$ indicator functions of hierarchical structural elements, as in \cite{mcfee2014analyzing}.  This combination of stacked delay embeddings and SNF can be viewed as a more general, global alternative to similarity diagonal promotion which has previously been used to preprocess the graph Laplacian \cite{mcfee2014analyzing}.  As can be seen in Figures~\ref{fig:SSMFused} and ~\ref{fig:SSMChroma}, it at least qualitatively does a much better job at making clean similarity matrices and Laplacian eigenvectors than Chroma by itself.

\begin{figure}
    \centering
    \includegraphics[width=0.85\columnwidth]{SimilarityMatrix_Laplacian.pdf}
    \caption{Similarity matrix $W^F$ and Laplacian eigenvectors after applying similarity network fusion to stack-delayed Chroma and MFCC features for the song ``Smooth Criminal'' by Michael Jackson.  The SSM and eigenvectors are much cleaner than those with just raw chroma in Figure~\ref{fig:SSMChroma}.}
    \label{fig:SSMFused}
   \end{figure}

\begin{figure}
    \centering
    \includegraphics[width=0.85\columnwidth]{SimilarityMatrix_Chroma.pdf}
    \caption{Similarity matrix $W^C$ using the cosine distance on stack-delayed Chroma features, along with the corresponding weighted Laplacian eigenvectors.  While the stacked delay embedding helps diagonals to appear which indicate repeated structure, it is not as clean as the fused SSM in Figure~\ref{fig:SSMChroma}.}
    \label{fig:SSMChroma}
\end{figure}

\section{Visualizing Time-Ordered Similarity}

\begin{figure}
    \includegraphics[width=\columnwidth]{ForceGraph.pdf}
    \caption{A dynamic weighted spring layout based on the weights in Figure~\ref{fig:SSMFused}, which is rendered with the help of d3.js \cite{bostock2012d3}.}
    \label{fig:ForceGraph}
\end{figure}

\begin{figure}
    \centering
    \includegraphics[width=0.8\columnwidth]{DiffusionMaps.pdf}
    \caption{3D Diffusion maps rendered by WebGL, synchronized to the music.}
    \label{fig:DiffusionMaps}
\end{figure}

The first facet of our GUI simply allows the user to view audio synchronized with the SSM, but enables a powerful way to visualize and jump between repeated elements in the song\footnote{This is similar to the cross-similarity GUI viewer we created for cover songs \cite{tralie2017cover}.}.  The second visualization performs a spring layout of the weighted graph induced from $W^F$, with the help of d3.js \cite{bostock2012d3}, as shown in Figure~\ref{fig:ForceGraph}.  Since we have applied a similarity kernel, the spring constant is proportional to how similar windows are; the simulation encourages more similar windows to be closer together.  Note that the simulation is dynamic; nodes in the graph can be moved around, and the simulation will settle in a local min of energy. Finally, we present a GUI for showing music synchronized to 3D diffusion maps \cite{coifman2006diffusion}.  This is the most similar GUI to our previous ``Loop Ditty'' GUI\cite{tralie2017Dissertation}, though it works purely on similarity information and not on coordinates in feature space, so it is much more general.

In future work, we would like to explore all of these structures for pruning in large scale audio cover song identification, similar to the aligned hierarchies work \cite{kinnaird2016aligned} on symbolic cover song identification.

% For bibtex users:
\small
\bibliography{main}

\end{document}


\section{Introduction}
\subsection{Purpose}
By its nature, genomic data can include information of a confidential nature about the health of individuals.
%
It is important that such information is not accidentally disclosed.
%
One part of the defence against such disclosure is to, as much as possible, keep the data in an encrypted format.
%

This document describes a file format that can be used to store data in an encrypted and authenticated state.
%
Existing applications can, with minimal modification, read and write data in the encrypted format.
%
The choice of encryption also allows the encrypted data to be read starting from any location, facilitating indexed access to files.

\subsection{Requirements}
The keywords ``MUST'', ``MUST NOT'', ``REQUIRED'', ``SHALL'', ``SHALL
NOT'', ``SHOULD'', ``SHOULD NOT'', ``RECOMMENDED'', ``MAY'', and
``OPTIONAL'' in this document are to be interpreted as described
in~\cite{RFC2119}.

\subsection{Terminology}
%
\begin{description}
\item[Elliptic-curve cryptography (ECC)] %
An approach to public-key cryptography based on the algebraic   structure of elliptic curves over finite fields.
%
\item[Curve25519] %
A widely used FIPS-140 approved ECC algorithm for asymmetric key encryption, not encumbered by any patents~\cite{RFC7748}.
%
\item[ChaCha20-Poly1305] %
ChaCha20 is a symmetric stream cipher built on a pseudo-random function that gives the advantage that one can efficiently seek to any position in the key stream in constant time.
%
It is not patented.
%
Poly1305 is a cryptographic message authentication code (MAC).
%
It can be used to verify the data integrity and the authenticity of a message~\cite{RFC8439}.
%
\item[ciphertext] %
The encrypted version of the data.
%
\item[plaintext] %
The unencrypted version of the data.
%
\end{description}


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{amssymb }

\title{CS5820 HW9}
\author{Renhao Lu, NetID: rl839}

\begin{document}
	\maketitle

	\section{NP-Complete proof sketches}
	\subsection{UNSAT}
	The approach is not correct. Because UNSAT is not a NP problem. No matter which certificate we are provided, we can not prove that there is no other input that make $\Phi$ true.
	\subsection{Magnet Problem}
	The approach is correct. The complete proof is in below:
	\subsubsection{Magnet problem is in NP}
	Certificate: a set of strings (may contain replicate strings)\\
	Check: if the set of strings used up all symbols in the symbol collection, the answer is yes. If the number of strings is $a$ and the number of symbols is $b$, the checking time is $n(ab)$, which is polynomial.
	\subsubsection{Reduce Hamilton Cycle problem to Magnet problem}
	\paragraph{Convert input}
	Given a directed graph $G=(V,E)$. For every node $v\in V$, create two letters $v_1,v_2$. For every edge $(u,v)\in E$, create a string $u_2v_1$.
	\paragraph{Convert output}
	If Magnet problem has a yes answer, Hamilton cycle problem has a yes answer. Otherwise, the answer of Hamilton cycle problem is no.
	\paragraph{Running time}
	Assume $|V|=n$, $|E|=m$. We will create $2n$ symbols and $m$ strings, and the length of all strings are $2$. Hence, the total running time is $O(n+m)$, which is polynomial.
	\paragraph{Correctness}
	We will prove that the yes/no answer of magnet problem is equivalent to the answer of Hamilton problem.\\
	If Hamilton problem has a solution, we note this cycle $C=\{(v_1,v_2),(v_2, v_3),...,(v_n,v_{n-1})\}$ where $V=\{v_1, v_2,...,v_n\}$. We know that for each node $v_i\in V$, exist exactly two edges $(v_i,v_j),(v_{j'},v_i)\in C$. Then we created symbols $v_{i1},v_{i2}$ and strings as we previously described. Here, for each edge $(v_i,v_j)\in C$, we add the string $v_{i2} v_{j1}$ into our collection. Because each node $v_i$, appeared twice in two different edge at left side and right side respectively, each symbol $v_{i1},v_{i2}$ must appear in the string collection exactly once. Meanwhile, all symbol must have been used because Hamilton cycle must travel throught all nodes. Hence, the string collection would be a solution for Magnet problem. \\
	If the Magnet problem has a solution, we note the alphabet as $A=\{v_{11}, v_{12}, v_{21}, v_{22},...,v_{n1},v_{n2}\}$ the solution string collection $S=\{v_{i2}v_{j1}, v_{i'2}v_{j'1},...\}$. For each symbol, we have exactly one "amgnet", so each symbol must appear exactly once in $S$. So we know for each $v_{i1} and v_{i2}$, exist one string $v_{j2}v_{i1}$ and $v_{i2}v_{j'1}$ in $S$. Hence, we pick one random symbol $v_{i_2}$ as the start point and reorginze $S$ in a end-to-end pattern as following: $\{v_{i2}v_{j1}, v_{j2}v_{k1},...,v_{p2}v_{t1},v_{t2}v_{i1}\}$. Then we create a cycle as for the solution for Hamilton cycle problem: $C=\{(v_i, v_j),(v_j,v_k),...,(v_p, v_t),(v_t,v_i)\}$. This cycle doesn't have any replicates because no replicates exists in $S$. Meanwhile $C$ covers all nodes because $S$ covers all symbols in $A$. Hence $C$ is a correct solution for Hamilton problem.

	\subsection{Subway Riding}
	The apporach is not correct. From the porblem we can know that $\sum_{i=1}^n {w_i}\geq W$. Hence createing $n$ cycles will need totally $(\sum_{i=1}^n {w_i}) -n+1$ nodes in $G$. Creating new graph $G$ will take at least $O(W-n)$, which is not polynomial time.

	\section{Disrupting an Enemy's Railway Network II}
	Railway problem is in P, and it can be reduced to the original railway disruption problem.
	\paragraph{Step 1: convert input}
	Given the input of the railway problem directed graph $G=(V,E)$, $h\in V$, $T\subseteq V$, and integer $k<|T|$. We create a new directed graph $G'=(V',E')$ for the input of original railway problem. We first add $h$ to $V'$. Then For each node $v_i\in V (v_i\neq h)$, we add two nodes $v_{i-in}, v_{i-out}$ into $V'$, and we add edges $(v_{i-in}, v_{i-out})$ to $E'$ with capacity $c_e=1$. For each edge $(v_i, v_j)\in E$, we add edge $(v_{i-out},v_{j-in})$ into $E'$ with capacity $c_e=+\infty$. For all $v_i\in T$, we add $v_i-out$ to $T'$. And we set all $w_i=+\infty$ for $v_{i-out}\in T'$. Then we pass the directed graph $G'$, the capacity of the edges $\{c_e\}$, set $T'$, and $\{w_i\}$ as the input of the oringinal railway problem. Because all $w_i=+\infty$, we only need to find the minimized $\sum_{c\in F}{c_e}$ in the original railway problem.
	\paragraph{Step 2: convert output}
	We note the output of the original railway problem is a set $F$ of edges to be destroyed. If $|F|\leq k$, the answer for the railway problem II is yes. Otherwise, the answer is no.
	\paragraph{Step 3: Running time}
	Assume for the input of railway problem II $G=(V,E)$, $|V|=n,|E|=m, |T|=p<n$. \\
	Converting input: in $G'=(V',E')$, $|V'|=2n-1$, $|E'|=m+n-1$, so building up the graph and setting the edge capacities will take $O(m+n)$. Initializing $|T'|$ and $\{w_i\}$ takes $O(p)<O(n)$, so toal would still be $O(m+n)$\\
	Converting output: Getting the output $F$ size can take at most $O(m+n)$, and comparing size with $k$ is $O(1)$. So total is $O(m+n)$\\
	Find the solution for the original railway problem I: The maximum possible flow in equal to $|T'|=|T|=p$. So the running time for the original railway problem is $O(|E'|p)=O((m+n)p)<O((m+n)n)$.\\
	The total running time of this reductions is $O(m+n)+O(m+n)+O((m+n)n)=O((m+n)n)$, which is polynomial.
	\paragraph{Step 3: Correctness}
	We claim that $|F|\leq k$ from the original railway problem is equivalent to the yes answer in the railway problem II.\\
	1. If $|F|\leq k$ from the original railway problem I, we can prove that railway problem II have a solution. We can first claim that All edges in $F$ is $(v_{i-in},v_{i-out})$ and doesn't contain any edge like $(v_{i-out},v_{j-in})$, because all edges $(v_{i-out},v_{j-in})$ has a capacity of $+\infty$, and they cannot be seperated by minimum s-t cut. Then we create a set of node $Q$, and add each $v_i$ if $(v_{i-in},v_{i-out})\in F$. We can tell that $|Q|=|F|\leq k$. Because $w_i=+\infty$, all terminal nodes must be disconnected. So $Q$ is a solution for railway problem II. \\
	2. If railway problem II has a solution, we can prove that the solution $|F|$ not larger than $k$. We note $Q=\{v_{i1},v_{i2},...,v_{ik}\}$ is a set of statations as the solution of railway problem II. Then we set $F_1=\{(v_{i1-in},v_{i1-out}),(v_{i1-in},v_{i1-out}),...,(v_{ik-in},v_{ik-out})\}$. Because in railway problem II, disabling the statations in $Q$ can disconnect all terminals in $T$, destroying edges in $F_1$ can disconnect all terminals in railway problem I as well. Because for all $(v_{i-in},v_{i-out}), c_e=1$, $|F|_{optimal}=min\{\sum_{c\in F}{c_e}\}\leq \sum_{c\in F_1}{c_e}=|F_1|=k$. Hence the optimal $|F|\leq k$,
	\section{Side gig problem}
	\subsection{Side gig problem is in NP}
	Certificate: a set of jobs you plan to do during the summber $J={i_1,i_2,i_3,...}$\\
	Check: If for any two $i,j\in J, D_i\cap D_j=\O$, and $\sum_{i\in J}{p_i}\geq C$, the answer is yes.
	\subsection{Reduce independent set problem to side gig problem}
	\paragraph{Convert input}
	Given the input of independent set problem, undirected graph $G=(V,E)$ and integer $k$. We assume $V={1,2,3,...,n},|V|=n$ and $E={e_1,e_2,...,e_m}, |E|=m>n$. Then we create $n$ jobs, each job $i'$ corresponds to a node $i\in V$, and each job has the same payment $p_i=1$. Then we set summer break as $m$ days. For each edge $e_p=(i,j)\in E$, we add day $p$ into $D_i$ and $D_j$. At last we set the credit card debit $C=k$. Now we can pass $n,m,{D_i}, C$ as the input of side gig problem.
	\paragraph{Convert output}
	If the answer of side gig problem is yes, the output of independent set is also yes. Otherwise, the output of independent set is no.
	\paragraph{Running time}
	Converting input: Creating new job set, takes $O(n)$. Creating m days of summer break takes $O(m)$. Setting up ${D_i}$ need to update 2 times for each edge, so takes $O(2m)=O(m)$. Hence, converting input totally take $O(n+m)$, which is polynomial.
	\paragraph{Correctness}
	We claim that the answer of independent set problem is equivalent to the answer of side gig problem.\\
	1. If independent set problem has a solution, we note this solution as set $S={i_1, i_2,...,i_k}$, then we create a job set $P={i_1',i_2',...,i_k'}$. The total payment $\sum_{i\in P}{p_i}=k=C$, hence the credit card debit can be paied off. Meanwhile, because in the independent set $S$, no two node share one edge, we know that in $P$, no two jobs share a same day. Hence, we know set $P$ is a solution for the side gig problem. \\
	2. If the side gig problem has a solution, we note this soltion as a set of jobs $P={i_1',i_2',i_3',...,i_k',...}$. Becasue the debit $C=k$, $|P|\geq C=k$. We select the first $k$ members in $P$ and transfor the jobs into another set of node which the jobs are corresponding to, $S={i_1,i_2,...,i_k}, |S|=k$. We claim that $S$ is an independent set because if some two nodes $i,j\in S$ and $(i,j)=e_p\in E$, $D_i\cap D_j ={p}\neq \O$, which is a contradiction. Hence, $P$ is a solution for independent set problem.

\end{document}


\documentclass[a4paper,11pt]{book}
\usepackage{import}
\usepackage{preamb}

\makeindex

\begin{document}

\input{head}
\newpage
\input{Title}
% \section{Blocks and Community structure}

\begin{subbox}{subbox}{}
\centering
\Large{\textbf{Graph/Node embedding}}
\end{subbox}

\begin{subbox}{subbox}{Disclaimer}
Graph/Node embeddings are a recent field of research, with hundreds of publications in the last few years, and scores of new papers published in every machine learning and network science conference. This class is thus only an introduction to the mechanism underlying those approaches.
\end{subbox}

\begin{textbox}{Embedding of networks}
In the context of \textbf{graph embedding}, embedding is a shortcut for \textbf{embedding in low dimensions}, and can be understood as assigning to some \textbf{elements} of the graph a \textbf{vector} (i.e., a list of numbers) composed of \textbf{d} elements. \textbf{d} is the number of dimensions in the embedding space, and \textbf{d} should be small.
\end{textbox}

\begin{textbox}{Types of Network Embedding}
According to the type of element which is embedded, we can differentiate:
\begin{itemize}
    \item Node Embedding (one vector per node)
    \item Edge Embedding (one vector per edge)
    \item Substructure Embedding (e.g., one vector per community)
    \item Whole Graph Embedding (one vector per graph)
\end{itemize}

In this class, we will introduce only Node Embedding, which is the most popular approach.

Whole graph embedding is also quite popular, for instance to classify types of networks.
\end{textbox}

\begin{textbox}{Node Embedding}
In \textbf{node embedding}, the vector assigned to each node should be a proxy, a sort of numeric summary of the position of the node in the graph, in term of topology. Several types of embeddings exist that capture different aspects of the network topology, in particular we will differentiate \textit{locational embedding} from \textit{role embedding}. Note that node embedding is sometimes called \textbf{graph embedding} in the literature.
\end{textbox}

\begin{textbox}{Embedding distance}
Since each node is represented by a vector, it is possible to compute a \textbf{distance between nodes} in the embedding. Intuitively, two nodes occupying similar positions in the network (according to what the chosen embedding capture) should have similar embedding vectors. The notion of distance to use (cosine, euclidean, etc.) also depends on the chosen embedding.
\end{textbox}

\begin{textbox}{Adjacency matrix(A) as an embedding}
A naive way to choose an embedding (in $n$ dimensions) could be to consider each row of the adjacency matrix as the vector representation of the node it corresponds to.

This embedding would capture what is called the \textbf{structural equivalence}, i.e. the fact that nodes share similar neighborhoods. Two nodes with the same neighborhoods would have the same vectors. If the \textit{Manhattan distance} were used, the distance between nodes in the embedding would correspond to the number of different neighbors.
\end{textbox}

\begin{textbox}{What is a good embedding?}
What is a good embedding depends on the task that we want to achieve. In the perspective of this class, embeddings are mostly used as features for machine learning tasks. As such, they must be 1) In as few dimensions as possible: Machine learning suffers from what is known as the \textbf{curse of dimensionality}, and tends to work better with lower dimensions, without talking about computational advantages. 2) As dense as possible. Sparsity --usually associated with high dimensions-- makes learning harder.

Furthermore, the embedded properties must be meaningful for the task to achieve. For instance, the notion of distance captured by the adjacency matrix seems in contradiction with the intuition: in graphs, one usually use the number of common neighbors, and/or normalized fraction of neighbors (Jaccard, etc.) rather than a raw count of different neighbors.
\end{textbox}

\begin{textbox}{Embedding and Dimensionality Reduction}
In Machine Learning, when a dataset is composed of too many features, \textbf{dimensionality reduction} algorithms can be used to generate a smaller number of synthetic features, defined as combination of the original ones. Common algorithms to do so are for instance \textbf{PCA} (Principal Component Analysis) and \textbf{T-SNE}\footcite{maaten2008visualizing}.

A simple method to generate a better embedding from the adjacency matrix would be to apply Dimensionality Reduction on it to reduce its number of dimension. Its counter-intuitive definition of distance would nevertheless remain a problem.
\end{textbox}

\begin{textbox}{Notations}
\begin{tabular}{p{0.12\textwidth}|p{0.8\textwidth}}\scriptsize
$y$ & Embedding of the graph \\
$y_i$ & Vector corresponding to node $i$ in the embedding $y$\\
$S$ & Similarity matrix. For each pair of node $i,j$, $S_{ij}$ represents the graph similarity that we want to preserve.
\end{tabular}
By default, $S=A$: two nodes have a maximal similarity of 1 if they are connected, and similarity 0 if they are not connected. But one can use a different notion, such as a random walk distance, a neighborhood similarity heuristic, etc.
\end{textbox}

\begin{textbox}{Node Embedding: LE}
\textbf{Laplacian Eigenmaps} (LE)\footnote{Belkin2003LaplacianEF} is a method that can be used for node embedding, whose objective function is defined as follows:
\[
y=\min \sum_{i\neq j}\lVert y_i - y_j \rVert ^2 S_{ij}
\]
This can be read as follows: to find the embedding $y$ of a graph, we need to assign an embedding $y_i$ to each node $i$ such as the sum (over all node pairs) of the equation $\lVert y_i - y_j \rVert ^2 S_{ij}$ is minimal.
Said differently, its objective is to minimize the product between the \textbf{euclidean distance} in the embedding ($\lVert y_i - y_j \rVert ^2$) and the \textbf{similarity} in the graph $S_{ij}$.

If two nodes are similar/close in the graph (high value), we need to make them as close as possible in the embedding (small value). Nodes dissimilar/distant in the graph can be distant in the embedding with a lesser penalty. To forbid a trivial solution of all nodes being on the same location, the sum of distance between points in the embedding must be equal to a constant.
\end{textbox}

\begin{textbox}{Node Embedding: HOPE}
\textbf{Higher-Order Proximity preserved Embedding}  (HOPE)\footnote{ou2016asymmetric} objective function is:
\[
y=\min \sum_{i,j} |S_{ij}-y_i y_j^T |
\]
Said differently, its objective is to minimize the difference between the graph \textbf{similarity} $S_{ij}$ and the similarity in the embedding, computed as the product of embedding vectors. Vectors are imposed to be normalized, thus $y_i y_j^T$ corresponds to the \textit{cosine similarity}.

Two nodes close (resp. far) in the graph should therefore be close (far) in the embedding. Relative distances should also be conserved.
\end{textbox}

\begin{textbox}{LE - HOPE: Complexity}
Discovering the solution of LE and HOPE methods can be done efficiently using matrix decomposition approaches. For instance, finding the embedding according to LE in $d$ dimensions for the adjacency matrix can be formalized as finding the $d$ eigenvectors of lowest eigenvalues of $D^{-1/2}LD^{-1/2}$, with $D$ the degree matrix and $L$ the Laplacian matrix.

The computation of the $S$ matrix however, if it is not the adjacency matrix, can be costly since in the general case, it requires $n^2$ computations.
\end{textbox}

\begin{textbox}{Random Walk NN based embedding}
In recent years, new approaches based on random walks and neural networks have encountered a large success and relaunched a large interest in graph embedding for various applications. They are transpositions of techniques developed for the embedding of words to the graph setting.
\end{textbox}

\begin{textbox}{Word Embedding}
Machine Learning on text suffers from a problem similar to Machine Learning on graphs: words are not numbers and cannot be naturally represented as (meaningful) vectors. Word embedding objective is to assign a (low dimensional) vector to each word such as two words with \textbf{similar semantic} have similar vectors.
\end{textbox}

\begin{subbox}{subbox}{Matrix decomposition and Eigenvectors}
A diagonizable matrix $A$ can be factorized using eigenvectors as follows:
\[
\mathbf{A}=\mathbf{Q}\mathbf{\Lambda}\mathbf{Q}^{-1}
\]
where $Q$ is the  $n \times n$ matrix whose $i$th column is the eigenvector $q_i$ of $A$, and $\mathbf{\Lambda}$ is the diagonal matrix whose diagonal elements are the corresponding eigenvalues, $\mathbf{\Lambda}_{ii} = \mathbf{\lambda}_i$. Keeping as embedding the eigenvectors associated with the largest eigenvalues means that we can reconstruct the original matrix with a good precision. This is the same method used by PCA (Principal Component Analysis), on a covariance(or correlation) matrix, which is also a form of similarity matrix.
\end{subbox}

\begin{textbox}{Word Embedding: word2vec - context}
The principle proposed in a famous method called word2vec is to use the context, i.e., the words encountered around a word in sentences of a corpus, to discover the semantic similarity. In summary, the more two words are encountered in a same context, the more they are considered similar. For instance, a corpus might contain sentences such as: \textit{the dog eat dry food}, and \textit{the cat eat dry food}: \textit{cat} and \textit{dog} are found in similar contexts, which should drive them closer in the embeddding. In other sentences, their contexts differs, which should drive them away in the embedding.
\end{textbox}

\begin{textbox}{Word Embedding: Skipgram/word2vec}
In practice, a word is considered to be in the context of another if it is at a distance less than $l$ in a sentence. From a corpus, one then extracts the probability $p(w_j|w_i)$ for each word $w_i$, that a word taken at random in its context is $w_j$.

The objective function of word2vec can be expressed as:
\[
y=\min \sum_{(i,j)} p(w_j|w_i)-\sigma(y_i y_j^T)
\]
with $\sigma$ the softmax function defined as $\frac{e^x}{\sum e^x}$, a function commonly used in neural networks to add non-linearity while ensuring that the solution is a probability.
\end{textbox}

\begin{textbox}{Skipgram: a neural network formulation}
The skipgram algorithm is solved, in practice, using tools and methods of neural networks, which make it scalable to large datasets. It can then be represented as follows:

\centering

\colorbox{white}{\includegraphics[width=0.8\linewidth]{pics/skipgram.pdf}}
\end{textbox}

\begin{textbox}{Word2vec efficacy}
Word2Vec (and following word embedding approaches) have encountered an enormous success in the Natural Language Processing domain, and its descendants are used for most practical tasks such as automatic language translation, sentiment analysis, personal assistants, etc.

Various other fields, including network science, have therefore adapted the mechanism to embed other complex items.
\end{textbox}

\begin{textbox}{DeepWalk}
DeepWalk\footcite{perozzi2014deepwalk} is the direct transcription of Word2vec to graphs. The principle is to generate random walks in the graph, playing the role of sentences in a corpus. The probability of finding a word in the vicinity of another therefore translates in the probability of encountering a node in a random walk from another.

To sum up, the objective function can now be expressed as:
\[
y=\min \sum_{(i,j)} p(n_j|n_i)-\sigma(y_i y_j^T)
\]
with $p(n_j|n_i)$ the probability to encounter node $n_j$ in a random walk of a chosen length starting from node $n_i$. Its objective is therefore to make the distance in the embedding proportional to a random walk based distance in the graph.
\end{textbox}

\begin{textbox}{DeepWalk complexity}
Contrary to matrix decomposition based approaches, DeepWalk do not requires explicitly a similarity matrix $S$. All pairs $(i,j)$ are obtain by $k$ random walks of length $l$ starting from each of the $n$ nodes. The complexity of obtaining the input data is therefore in $\mathcal{O}(n)$ ($l$ and $k$ being small constants).
\end{textbox}

\begin{textbox}{Node2vec}
\textbf{Node2vec}\footcite{grover2016node2vec} is a popular variant of DeepWalk, introducing \textbf{biased random walks}. Two parameters guide the random walks: $p$ affect the probability to revisit the previous node, while $q$ affect the probability to explore farther nodes, i.e., nodes that were not neighbors of the origin node. It allows to mimic \textbf{breadth-first} or \textbf{depth-first} like exploration of the graph, capturing more local or more global network structures.
\end{textbox}

\begin{textbox}{Node2vec}
Illustration of random walk procedure in node2vec.

\centering
\includegraphics[width=0.6\linewidth]{pics/n2v.pdf}

The walk just transitioned from the previous node $p$ to the current one $c$ and is now evaluating its next hop. Edge labels indicate the bias as a function of parameters $p$ and $q$.
\end{textbox}

\begin{textbox}{Role Embedding}
Node2Vec and DeepWalk are \textbf{locational} embedding: nodes with similar vectors tend to be close in the graph, in term of graph distance.

Another notion of graph similarity is \textbf{role} similarity. Two nodes have similar roles in the graph if their neighborhood is similar, \textbf{ignoring node labels}.
\end{textbox}

\begin{textbox}{Role2Vec — Struc2Vec}
Two popular methods for role embedding are Struc2Vec\footcite{ribeiro2017struc2vec} and Role2Vec\footcite{ahmed2019role2vec}. They are based on a similar principle: as DeepWalk, they use random walks and SkipGram to generate embedding from contexts. But instead of generating sequences composed of the \textbf{labels} of encountered nodes, it generate contexts based on the \textbf{attributes/labels/features} of encountered nodes. Nodes with similar vectors thus corresponds to nodes that tend to encounter \textbf{nodes with similar properties} in random walks starting from them.

Examples of properties could be node features (age, genre, etc.) or structural properties (degree, clustering coefficient, graphlet belonging, etc).
\end{textbox}

\begin{textbox}{Node Classification with embeddings}
Machine Learning algorithms such as Logistic Regression or Decision Tree can be trained to predict a property of a node from a vector of features representing the node property. We have seen in a previous class that these features could be manually chosen heuristics such as node centralities.

Vectors yielded by embedding algorithms can naturally be used in the same way. Locational embeddings could be used, for instance to attribute category to objects or political opinions to social media accounts, while role embedding could be used to identify suspicious accounts in social media.
\end{textbox}

\begin{textbox}{Link Prediction with embeddings: unsupervised}
If we consider that the property captured by the embedding is correlated with the probability of being connected by an edge, then the distance in the embedding can be used a heuristic for link prediction.

For instance, with LE and HOPE with $S=A$ or with random walks based approach, the embedding tries to put pairs of nodes connected by an edge closer than unconnected ones. As a consequence, we can assume that the closer two nodes are in the embedding, the more likely it is that they should be connected by an edge.
\end{textbox}

\begin{textbox}{Link Prediction with embeddings: supervised}
In the second approach, we consider each dimension of the embedding as a node feature. For each pair of nodes, we compute a vector by \textbf{combining nodes' vectors}.

As with heuristics, a machine learning algorithm is then trained to predict, from the combined vector, how likely it is to have an edge between nodes.
\end{textbox}

\begin{textbox}{Combining node vectors}
There are several methods to combine node vectors. Although it has been observed empirically that the Hadamard product often gives the best results, this choice is often considered a \textbf{hyper-parameter}, i.e., all variants are tested and the most efficient is used for the final prediction.

The most used operators are:
\begin{center}
\begin{tabular}{ c| c }
\hline
 Average & (a+b)/2 \\
 \hline
 Concat & $[a_1,a_2,...,a_d,b_1,b_2,...,b_d]$\\
 Hadamard & $[a_1*b_1,a_2*b_2,...,a_d*b_d]$  \\
  Weighted L1 & $[|a_1-b_1|,|a_2-b_2|,...,|a_d-b_d|]$ \\
 Weighted L2 & $[(a_1-b_1)^2,(a_2-b_2)^2,...,(a_d-b_d)^2]$\\
 \hline
\end{tabular}

with $a=[a_1,a_2,...,a_d]$ and $b=[b_1,b_2,...,b_d]$
\end{center}
\end{textbox}

\begin{textbox}{How many dimensions?}
There is no universal method to choose a number of dimensions for the embedding. In the literature, for large graphs, a common value is $d=128$ dimensions. As a general rule, $d<<n$.

Too few dimensions limit the capacity to embed complex information, but too many dimensions limit cross-learning, generalization,(i.e., overfits), and make learning from embeddings harder. More dimensions also require (usually) more computation.
\end{textbox}

\begin{textbox}{Visualization and embeddings}
Network visualization is a domain in itself. Its objective is to assign positions to nodes in a two dimensional space in order to plot the network in a meaningful way.

Algorithms such as HOPE or node2vec are not well adapted to generate visually interpretable 2-dimentional spaces, in part because the distance in the embedding is based on the cosine distance, while humans naturally assume euclidean distance. When embeddings are used for visualization, the first step consists in embedding in a moderate number of dimensions (e.g., 128), and in a second step, a dimensionality reduction algorithm more adapted for visualization such as T-SNE\footcite{van2008visualizing} is used to reduce this number to 2 dimensions.
\end{textbox}

\begin{textbox}{Community detection with embeddings}
Community detection in graphs is equivalent to the \textbf{clustering} task in non-network data. Intuitively, clustering methods try to group elements with similar features, and separate those that are different. Applying a clustering algorithm such as \textbf{k-means} on an embedding will therefore yield clusters of nodes, that can be considered as communities. In practice, it has been observed that communities detected by this approach are often similar to those found by modularity maximization.

Note that unlike with modularity, it is often required to provide the desired number of clusters --or a distance scale-- to clustering methods.
\end{textbox}

\begin{textbox}{Going Further}

Python Libraries: Karate-club(\cite{karateclub})(\cite{goyal2018gem})

Surveys on graph embedding: (\cite{goyal2018graph})(\cite{cai2018comprehensive})(\cite{cui2018survey})

Graph Embedding and link prediction (\cite{mara2020benchmarking})

Distances in Graph embedding (\cite{vaudaine2020comparing})

Comparing heuristics and Graph Embedding for link prediction (\cite{sinha2018systematic})

Stacking embeddings and heuristics models for link prediction: (\cite{ghasemian2020stacking})

\end{textbox}

\input{tail}

\end{document}


% !TeX root = ./growth_modelling.tex
\documentclass[letterpaper, 11pt]{article}
\usepackage{microtype}
\usepackage[bottom=1in, margin=0.75in]{geometry}
\usepackage{mathpazo}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{amsmath}
\onehalfspacing
\setlength\itemsep{5pt}
\setlength{\footskip}{-10pt}
\title{Constructing a Dynamical Model of Nutrient-Dependent Growth}
\author{Griffin Chure}
\date{\today}
\begin{document}
\maketitle

\section{Theoretical Underpinnings}
\subsection{Translation-Limited Growth}\label{sec:translation_limited_growth}
We begin by considering balanced exponential growth on a single carbon source.
For the time being, we will consider a growth regime where translation is
limiting and we will assume that nutrients are in abundance.
In this phase of growth, we can consider the formation of protein mass
as the most resource-intensive process and can relate the total
protein mass of the cell $M$ to the characteristic growth rate $\lambda$ via
\begin{equation}\label{eq:grow_def}
\frac{dM}{dt} = \lambda M.
\end{equation}
This protein mass $M$ is the product of the pool of ribosomes which catalyze the
formation of peptide bonds via translation. Equation \eqref{eq:grow_def} can be
cast in terms of the total number of actively translating ribosomes $N_R^{(act.)}$
as
\begin{equation}
\frac{dM}{dt} = N_R^{(act.)}k_R,
\end{equation}
where $k_R$ represents the average translation rate per active ribosome with
dimensions of $[MT^{-1}]$. It's important to note that here we are considering
only  the \textit{actively} translating ribosomes. Whether through active
regulation (such as through ppGpp) or ribosomes waiting to bind an mRNA or
awaiting the arrival of a charged tRNA, there is always some pool of ribosomes
that are \textit{inactive}, $N_R^{(inact)}$. Given knowledge of the total number
of ribosomes $N_R = N_R^{(act.)} + N_R^{(inact.)}$, we can state
\begin{equation}
    \frac{dM}{dt} = \left[N_R - N_R^{(inact.)}\right] k_R.
    \label{eq:growth_Nr}
\end{equation}
Equating this with Equation \eqref{eq:grow_def} yields an expression for the
growth rate $\lambda$,
\begin{equation}
\lambda = \frac{\left[N_R - N_R^{(inact.)}\right]k_R}{M}.
\label{eq:lam_nr}
\end{equation}
Rather than keeping track of the number of ribosomes, we can refer to the total
ribosomal mass $M_R$ and $M_R^{(inact.)}$ given knowledge of the unit mass of
one ribosome $m_R$,
\begin{equation}
M_R = m_R N_R.
\label{eq:ribo_mass}
\end{equation}
Doing so allows us to cast Equation \eqref{eq:lam_nr} in terms of the
\textit{ribosomal mass fraction} $\phi_R$ and $\phi_R^{(inact.)}$,
\begin{equation}
\lambda = \frac{\left[M_R - M_R^{(inact.)}\right]k_R}{M m_R} = \gamma\left[\phi_R - \phi_R^{(inact.)}\right]
\label{eq:growth_law_gamma}
\end{equation}
where we've introduced $\gamma = \frac{k_R}{m_R}$, a term commonly referred to
as  the \textit{translational capacity}. This term $\gamma$ has dimensions of
$[T^{-1}]$ and can be thought of as effective translation rate. The inverse of
this term has dimensions of $[T]$ and defines the amount of time it takes for
the synthesis of one ribosomes' worth of protein mass. Equation
\eqref{growth_law_gamma} can be rearranged to describe the mass fraction
$\phi_R$ as a function of the growth rate,
\begin{equation}
\phi_R = \phi_R^{(inact.)} + \frac{\lambda}{\gamma}.
\label{eq:growth_law_gamma_phir}
\end{equation}
In the limit where the cell is not growing (i.e. $\lambda \rightarrow 0$), we
find that $\phi_R = \phi_R^{(inact.)}$, illustrating that $\phi_R^{(inactt.)}$
is the \textit{minimal} fraction of the protein mass that is occupied by
ribosomes. Therefore, we will make the definition of
\begin{equation}
\phi_R^{(inact.)} \equiv \phi_R^{(min)}
\label{eq:phir_min_def}
\end{equation}
for notational clarity.

\subsection{Nutrient-Limited Growth}
We now turn our attention to the fact that, in order for ribosomes to form
peptide bonds, nutrients must be metabolized to produce tRNAs charged with amino
acids. Thus, the nutritional extent of the growth medium will dependent on
how the cell maximizes the flux from raw nutrients to amino acids.

Let's consider some amino acid $a$ whose total mass in the cell is $M_a$. In
balanced exponential growth, this mass $M_a$ is defined by the flux of of $a$
into the cell (via a combination of transport of nutrients and metabolism to
form $a$) and the rate at which they are consumed via translation.
Mathematically, this can be stated as
\begin{equation}
\frac{dM_a}{dt} = J_a - \beta \frac{dM}{dt},
\label{eq:dma_dt}
\end{equation}
where $J_a$ is the flux of $a$ into the cell and $\beta$ is the frequency with
which it is integrated into the proteome. For example, if we are considering a
single species of amino acid and we make the approximation that amino acids are
used with equal frequencies, $\beta = \frac{1}{20}$.

In reality, there is always some non-zero concentration of free amino acids that
the cell must maintain. We can consider the relative
masses of the standing pool of amino acids and the mass of the total proteome as
a measure of concentration,
\begin{equation}
    \theta_a \equiv \frac{M_a}{M}.
    \label{eq:theta_a_def}
\end{equation}
Given this formulation, Equation \eqref{eq:dma_dt} can be amended to include
maintenance of the free amino acid concentration as
\begin{equation}
\frac{dM_a}{dt} = J_a - (\beta + \theta_a)\frac{dM}{dt}.
\label{eq:dma_dt_theta_a}
\end{equation}
Dividing both sides of Equation \ref{eq:dma_dt_theta_a} by the total proteome
mass $M$ reparameterizes the entire dynamics in terms of the nutrient mass fraction $\theta_a$, yielding
\begin{equation}
\frac{1}{M}\frac{dM_a}{dt} = \frac{d\theta_a}{dt} = \frac{J_a}{M} - \lambda (\beta + \theta_a).
\label{eq:dtheta_a_dt}
\end{equation}
In steady-state growth, the fluxes are balanced, allowing us to enumerate an
expression for the growth rate $\lambda$ as
\begin{equation}
\lambda = \frac{J_a}{M\left(\beta + \theta_a\right)}.
\label{eq:lambda_ja_betatheta}
\end{equation}

The inward flux of nutrients to produce charged tRNAs $J_a$ represents the
concerted action of a battery of metabolic enzymes, including transporters and
potentially entire metabolic pathways. We can coarse-grain this entire process
by considering the total protein mass of all of the metabolic proteins involved
in processing a given nutrient as $M_P$. Together, these proteins produce amino
acids at some effective rate $k_P$ such that
\begin{equation}
    J_a = k_P M_P,
    \label{eq:ja_mp_def}
\end{equation}
where $k_P$ has dimensions of $[T^{-1}]$. It is important to note that this is
not exactly an enzymatic rate, however, but represents the total mass of
nutrient that can be transported/synthesized per unit mass of metabolic protein
per unit time. Plugging Equation \eqref{eq:ja_mp_def} into Equation
\eqref{eq:lambda_ja_betahtheta} yields a complete expression for the growth rate
\begin{equation}
\lambda = \frac{k_P}{\beta + \theta_a} \frac{M_P}{M} = \frac{k_P}{\beta + \theta_a} \phi_P,
\label{eq:lambda_phip}
\end{equation}
where we have introduced the notation $\phi_P$ to denote the mass fraction of
the proteome occupied by metabolic proteins.

In Section \ref{sec:translation_limited_growth}, we used similar notation to
denote the mass fraction of the proteome which is occupied by ribosome $\phi_R$.
As $\phi_P$ and $\phi_R$ are both bounded by the total mass of the proteome,
they must by definition compete for resources. If we consider these two categories are the only classes
of proteins making up the proteome, there exists the constraint that
\begin{equation}
\phi_P + \phi_R = 1.
\end{equation}
However, neither $\phi_P$ nor $\phi_R$ can ever be equal to $1$. Rather, we can
state that there exists a maximum fraction of the proteome that can be occupied
by either class of proteins. For consistency with Section
\ref{sec:translation_limited_growth}, we can cast this constraint in terms of
the maximal ribosomal mass fraction $\phi_R^{(max)}$ as
\begin{equation}
\phi_P + \phi_R = \phi_R^{(max)},
\label{eq:phip_phir_constraint}
\end{equation}
which captures the fact that any increase in $\phi_P$ must come at the expense
of $\phi_R$.

Using this constraint, Equation \eqref{eq:lambda_phip} can be defined in terms
of the ribosomal mass fraction as
\begin{equation}
\lambda = \frac{k_P}{\beta + \theta_a}\left[\phi_R^{(max)} - \phi_R\right].
\label{eq:lambda_metab_phiR}
\end{equation}
In typical physiological conditions, the standing pool of amino acids is small
when compared to its incorporation in the the proteome, permitting the
approximation that $\beta + \theta_a \approx \beta$. Making this approximation
allows us simplify Equation \ref{eq:lambda_metab_phiR} to yield
\begin{equation}
\lambda = \frac{k_P}{\beta}\left[\phi_R^{(max)} - \phi_R\right] = \nu \left[\phi_R^{(max)} - \phi_R\right].
\label{eq:growth_law_nu}
\end{equation}
The parameter $\nu$ is often referred to as the \textit{nutritional capacity}.
This parameter relates the rate at which nutrient mass (per unit mass of
metabolic protein) is produced to its corresponding frequency of usage. This
result is classically rewritten to express the ribosomal mass fraction $\phi_R$
as a function of growth rate,
\begin{equation}
\phi_R = \phi_R^{(max)} - \frac{\lambda}{\nu}.
\end{equation}

\subsection{Condition-Dependent Regulation of $\gamma$ and $\nu$}
Thus far, we have presented $\gamma$ and $\nu$ as constants. For a given growth
condition (such as a single growth medium) this is approximately true. However,
both of these parameters are the target of regulation given the availability of
precursors or charged tRNAs. There are many ways we can consider how these
parameters are tuned as a function of the environment.

For now, we can make the reasonable assumption that the translational
capacity $\gamma$ follows a simple Michaelis-Menten dependence on the
standing pool of the amino acid concentration $\theta_a$,
\begin{equation}
\gamma(\theta_a) = \frac{\gamma^{(max)}}{1 + \frac{\theta_0}{\theta_a}},
\label{eq:gamma_michaelis_menten}
\end{equation}
where $\theta_a^*$ is the Michaelis-Menten constant and represents the
concentration of amino acids at which the translational capacity is half
maximal. In this formulation, the translational capacity will be maximized when
the standing pool of the amino acids is large such that $\theta_a >> \theta_0$.
As the nutrient conditions dwindle, however, $\gamma$ will asymptotically
approach $0$ as $\theta_a <<  \theta_0$.

In a similar fashion, we can make the assumption that the nutritional capacity
of a given growth condition will be dependent on the concentration of the
nutrients. In the condition when nutrients are plentiful, the yield of amino
acids per unit mass of metabolic protein should be maximal. This should be true
of $\nu$ \textit{for a given nutrient source}, assuming that nutrient's
concentration is the tunable parameter. Thus, the standing amino acid pool
$\theta_a$ is less important in setting the value of $\nu$ than is the
concentration of the actual nutrient, which we will denote hereafter as $c$. For
a given concentration, we can define the nutritional capacity as having the form
of a Monod expression,
\begin{equation}
\nu(c) = \frac{\nu^{(max)}}{1 + \frac{K_M}{c}},
\label{eq:nu_monod}
\end{equation}
where $K_M$ is the Monod constant for growth on the specific nutrient source.

As $\nu$ depends on the composition of the \textit{medium} (rather than the
intercellular composition), we must now describe how the nutrient composition
$c$ changes as the biomass of the culture increases. In virtually all realistic
situations, the nutrients in the growth medium need to pass through a complex
metabolic pathway to be "converted" into amino acids that are charged to tRNAs.
Thus, to keep track of the nutrient concentration, we have to specify a yield
parameter $\Omega$ that describes the mass of amino acids produced per unit mass
of nutrient. The dynamics of the growth medium is then described by
\begin{equation}
\frac{dc}{dt} = -\frac{\nu(c)\left(\phi_R^{(max)} - \phi_R\right)}{\Omega}.
\label{eq:dc_dt}
\end{equation}

\section{A Dynamical Model for Diauxic Growth}
\subsection{Growth on a Single Carbon Source}
With the preceding sections, we now have a complete dynamical description for
growth on a single nutrient source. To summarize, the system of equations is
governed by the accumulation of biomass via
\begin{equation}
    \frac{dM}{dt} = \gamma(\theta) \phi_R M.
    \label{eq:mass_ode}
\end{equation}
The dynamics of the pool of amino acids $\theta_a$ is defined by the action of
the metabolic sector of the proteome $\phi_P$ as
\begin{equation}
\frac{d\theta_a}{dt} = \nu(c)\phi_P M - \frac{dM}{dt} = \nu(c)\left[\phi_R^{(max)} - \phi_R\right]M - \frac{dM}{dt}.
\end{equation}
These amino acids, as described in the last section, ultimately come from the
nutrients of the medium, which are at some concentration $c$. The dynamics of
this component is governed by
\begin{equation}
    \frac{dc}{dt} = -\frac{\nu(c)\phi_P M}{\Omega} = -\frac{\nu(c)\left[\phi_R^{(max)} - \phi_R\right]M}{\Omega}.
\end{equation}

Finally, the translational and nutritional capacities of the system are governed
by the size of the amino acid pool and the nutrient concentration of the growth
medium, respectively. These dependencies are codified mathematically as
\begin{equation}
   \gamma(\theta) = \gamma^{(max)}\left(1 + \frac{\theta_0}{\theta_a}\right)^{-1}\,\,;\,\, \nu(c) = \nu^{(max)}\left(1 + \frac{K_m}{c}\right)^{-1}.
   \label{eq:capacity_redefs}
\end{equation}

This set of equations [Equation \eqref{eq:mass_ode} --
\eqref{eq:capacity_redefs}] completely describe growth on a single nutrient
source. Figure \ref{fig:single_nutrient} shows how the biomass, nutrient
concentration, and amino acid pool size changes as a function of time using
parameters that are characteristic of \textit{E. coli} growing on glucose. It is
important to note that, for the parameters considered here, there exists an
"optimal" ribosomal mass fraction $\phi_R$ where the rate of biomass growth is
maximized. This can be clearly seen in Figure \ref{fig:single_nutrient}(A) as
the darkest and lightest color show slower growth of biomass compared the
the light blue or teal curves which are between the two extremes.

\begin{figure}
\centering{
\includegraphics[width=\textwidth]{figures/single_nutrient_dynamics.pdf}
\caption{\textbf{Dynamics of growth on a single nutrient source.} (A) Biomass of
the system relative to the initial condition $M(t=0)$. (B) The fractional
concentration of the nutrients in the growth medium relative to that of $c(t =
0)$. (C) The relative mass fraction of amino acids $\theta_a$ relative to
$\theta_a(t = 0)$. For all plots, parameters were chosen to be approximately
similar to growth of \textit{E.  coli} on a glucose-based medium. Explicitly,
the model parameters used here are $\phi_R^{(max)} = 0.4$, $\gamma^{(max)} =
8.25\,\text{hr}^{-1}$, $\nu^{(max)} = 2.5\,\text{hr}^{-1}$, $\theta_0 = 0.002$,
$c = 50\,\text{mM}$, $\Omega = 0.3$, and $K_M = 5\,\mu\text{M}$. The initial
conditions were arbitrarily set to be $M_0 = 0.001$ and $\theta_a =
\frac{M_0}{10}$.}
\label{fig:single_nutrient}
}
\end{figure}
\subsection{Growth on Two Carbon Sources}
Given a dynamical model of growth on a single nutrient source, it becomes
relatively simple to include the presence of a second nutrient source whose
metabolism is not preferred.

Let us consider two nutrient sources $x$ and $y$. Nutrient $x$ is the
"preferred" nutrient, meaning that its metabolism is prioritized over $y$.
The As $x$ and $y$ are different substrates, they require different sets of
metabolic proteins $M_x$ and $M_y$ and corresponding proteome mass fractions
$\phi_x$ and $\phi_y$. Additionally, as the nutrients are different, so too
are the nutritional capacities $\nu_x$ and $\nu_y$ which are determined given
the concentrations $c_x$ and $c_y$ and Monod constants $K_{M,x}$ and
$K_{M,y}$, respectively. The translational capacity, however, is shared
between the two nutrient sources as it is dependent only on the amino acid
pool $\theta_a$ resulting from the metabolism of $x$ or $y$.

How do we define a "preferred" substrate? In order to regulate what is
metabolized, we must think of how the expression of the metabolic proteins are
regulated. We will begin by considering that the expression of the metabolic
proteins responsible for consuming each the preferential nutrient $x$ will be
proportional to its concentration $c_x$. Mathematically, we can model the mass
fraction $\phi_x$ to have Monod-like dependence on the concentration $c_x$,
yielding
\begin{equation}
\phi_x(c_x) = \frac{\phi_x^{(max)}}{1 + \frac{K_{M, x}}{c_x}}.
\label{eq:phix_monod}
\end{equation}

\end{document}


I have explored the GNFW model pretty extensively at this point, and
have encountered a number of issues with it:

\begin{list}{}{\labelwidth 0.4in \leftmargin \labelwidth \addtolength{\leftmargin}{\labelsep}}

\item[1] {The A10 and N07 normalizations don't agree, even for the same set of fit parameters}

\item[2] {For a given M500, the A10 normalization predicts a pressure
  (and therefore an SZ decrement) that is significantly lower than
  what we actually measure for real clusters thought to be close to that M500

  Another way of saying the same thing is that for a fixed SZ
  decrement, the GNFW model normalization predicts an M500 that is
  significantly larger than what you get from joint fits to SZ + Xray}

\item[3] {The A10 model is not self-consistent.  If you start with an
  M500 and use the A10 normalization to construct the corresponding
  pressure profile, the M500 that you get by integrating that pressure
  profile out to R500 does not agree with the M500 you started with}

\end{list}

In the next couple sections, I address each of these in turn.

\subsubsection{Comparing the A10 and N07 P500}

Substituting $f_B = 0.175, \mu = 0.59, \mu_e = 1.14, G = 6.67384\times 10^{-8} {\rm cm^{3}/(g\, s^2)}$, $h(z) \equiv H(z) / H_0$, we have

\begin{eqnarray}\nonumber
\P500 &=& {{\mu}\over{\mu_e}} f_B {{3}\over{8\pi}} \left( {{500 G^{-1/4} H(z)^2}\over{2}} \right)^{4/3}\M500^{2/3}\\\nonumber
      &=& (4197.54) \, H(z)^{8/3}\M500^{2/3}\\\nonumber
      &=& (4197.54) \, h(z)^{8/3}H_0^{8/3}\M500^{2/3}\\\nonumber
      &=& (4197.54) \, (70~{\rm km/s/Mpc})^{8/3}\,(3\times10^{14}\Msolar)^{2/3}\,h(z)^{8/3}h_{70}^{8/3}\left[{{\M500}\over{3\times10^{14}\Msolar}}\right]^{2/3}\\
      &=& 1.65\times10^{-3} \, h(z)^{8/3}h_{70}^{8/3}\left[{{\M500}\over{3\times10^{14}\Msolar}}\right]^{2/3} {\rm keV\,cm^{-3}}
\label{eq:arnaud}
\end{eqnarray}

This is to be compared to Eq~13 of A10, with which it agrees exactly.
I therefore conclude that there are no arithmetic errors in the
derivation of Arnaud's P500/M500 relationship.

Note that if we instead normalize \mathM500\ to
$1\times10^{15}\Msolar$, and take $h_{70} = 1$ or $h = 0.7$, as Nagai et al do, we
have:

\begin{equation}
\P500 = 5.89\times10^{-12} \, h(z)^{8/3}\left[{{\M500}\over{1\times10^{15}\Msolar}}\right]^{2/3} {\rm erg\,cm^{-3}}
\end{equation}

This is to be compared to Eq~3 of Nagai et al, with $h = 0.7$, which yields

\begin{equation}
\P500 = 1.14\times10^{-11} \, h(z)^{8/3}\left[{{\M500}\over{1\times10^{15}\Msolar}}\right]^{2/3} {\rm erg\,cm^{-3}}
\end{equation}

(Note that $h(z)$ is equivalent to the $E(z)$ of Nagai et al.  And N07
actually take $h = 0.72$, but I've used $h = 0.7$ for simplicity)

The ratio of these two expressions is very close to 2, and the reason
is that N07 have dropped a factor of $h^2$ in their Eq~3, which
as-written is proportional to $h^{2/3}$ and not $h^{8/3}$, which is
clearly required by Eq~\ref{eq:p500}.  So that mystery amounts to
nothing more than typo in N07.

\subsubsection{Comparing P500 and M500}
\label{sec:confusion}

To make contact with $P_0$ of Equation~\ref{eq:ytop}, we have

\begin{eqnarray}
P_0 &=& p_0\times1.65\times10^{-3}h(z)^{8/3}\left[{\M500\over{3\times10^{14}h^{-1}_{70}\Msolar}}\right]^{2/3+\alpha_P}\,h^2_{70}\,{\rm keV\,cm^{-3}}
\label{eq:arnaudnorm}
\end{eqnarray}

(if we ignore $\alpha^\prime_P$).  This suggests, on the face of it,
that given a cosmology, we can relate an observed central decrement $y(0)$ to the Arnaud pressure normalization and therefore \mathM500\, by plugging $P_0$ into Equation~\ref{eq:ytop}.  However, I can't quite make sense of the numbers I get if I attempt to do this.

Let's take Abell~1914 as a test case.  This cluster has a redshift $z
= 0.168$, which yields $h(z) = 1.089$ and $D_A = 0.59$~Gpc.  For A1914, the central
decrement is roughly $-2$~mK, or $y(0) \sim 4\times 10^{-4}$.  The Arnaud fits
give a typical $\theta_c\sim 2^{\,\prime}$, yielding:

\begin{equation}
P_0 = 0.29~{\rm keV/cm^3}
\end{equation}

from Equation~\ref{eq:ytop}.  Plugging the numbers into Equation~\ref{eq:arnaudnorm}, we have:

\begin{equation}
P_0 = 1.74\times 10^{-2}\left[{\M500\over{3\times10^{14}\Msolar}}\right]^{2/3+\alpha_P}~{\rm keV/cm^3},
\end{equation}

or

\begin{equation}
\M500 = 1\times10^{16}\Msolar
\end{equation}

which seems about an order of magnitude too large (estimates of the virial mass for A1914 I've seen are somewhere in the neighborhood of $2-3\times10^{15}\Msolar$).

\subsubsection{The A10 Model is not Self-consistent}

As noted above, if you start with an M500, you can use
Eq~\ref{eq:arnaud} to determine \mathP500\ and thus the normalization of
the cluster pressure profile, via Eq~\ref{eq:ytop}, in particular:

\begin{equation}\nonumber
P(r) = \P500\,p(r).
\end{equation}

where $p(r)$ is the GNFW profile in Eq~\ref{eq:gnfw}.

This suggests that if the cluster were an isothermal sphere, then
$P(\R500)/\P500 = p(\R500) = 1.0$.  For A10's parameter values,
however, $p(\R500) = 0.48$ (which is suspiciously close to the ratio
of $(70/100)^2$).  It is also consistent with my empirical observation
that the \mathP500\ normalization predicts an SZ decrement that is
about a factor of 2 smaller than observed, for a set of clusters for
which we have independent SZ + X-ray mass estimates.

From Eq~\ref{eq:ysph} and Eq~\ref{eq:mgas} we also have:

\begin{eqnarray}
\M500 &=& {1\over{f_{gas}}}\left({{m_p\mu_e}\over{k_B T_e}}\right)\integral{\R500}{0}{P(r)}{V}\\
&=& {1\over{f_{gas}}}\left({{m_p\mu_e}\over{k_B T_e}}\right)\P500\,p_0\integral{\R500}{0}{p(r)}{V}
\end{eqnarray}

If I take measured X-ray temperatures for a set of clusters and the
A10 pressure profile fits, I can integrate this expression and
compare it to what the A10 normalization would predict for \mathM500,
and again I find that the masses I obtain in this manner are factors
of ~several lower than the best-fit \mathM500.

All of which suggests that an appropriate way to proceed with my
simulations is to rescale $p_0$ to force self-consistency with the
input \mathM500.  That is, I find the value of $p_0$ that gives me the
same integrated \mathM500\ that I put in the model in the first place.
This factor is shown in Figure~\ref{fig:rescale}.

\begin{figure}[th]
\begin{center}
\includegraphics[scale=0.5]{figures/rescale.png}\\
\end{center}
\caption{Plot of factor by which the A10 $p_0$ needs to be rescaled to
  recover the same integrated \mathM500\ that is put into the model normalization}
\label{fig:rescale}
\end{figure}


\documentclass[11pt]{article}

\usepackage{alltt,fullpage,graphics,color,epsfig,amsmath, amssymb}
\usepackage{hyperref}
\usepackage{boxedminipage}
\usepackage[ruled,vlined]{algorithm2e}

\newcommand{\floor}[1]{\lfloor #1 \rfloor}
\newcommand{\ceil}[1]{\lceil #1 \rceil}

\title{CS 510 Assignment 3:}
\author{Daniel Campos}
\date{April 11th,2021}
\begin{document}
\maketitle
\section{Problem 1}
\subsection{Write down the likelihood for log p(D| $\theta$) }
$log p(D | \theta)= \sum_{w \in D} log((1-\eta) p(w|\theta) +  (\eta) p(w|C))$ where C is the background language model. Since we do not care about the background language model we can set $\eta=0$ since no words will be generated by the background language model. Thus, the like hood becomes $log p(D| \theta) = \sum_{w \in D} log(p(w|\theta))$
\subsection{Derive the E-step and M-step for estimating the unknown parameter $\lambda$ in iteration t, for t = 1, 2}
Since the background model never occurs we can just set $p(z_{d,w}=B) = 0$ and only focus on updating $p(z_{d,w}=\theta) =\frac{\pi_{d, \theta}^(n) (w| \theta)}{\pi_{d,\theta'} p^(n) (w|\theta')}$ for the E-Step and for M-Step $\pi_{d,j}^(n+1)= \frac{\sum_{w \in V} c(w,d)(1-p(z_{d,w} = \theta')p(z_{w, d} = \theta)}{\sum_{w \in V} c(w,d)(1-p(z_{d,w} = \theta')p(z_{w, d} = \theta')}$
\section{Derive the E-step and M-step for estimating p(w|H).}
First off, we can treat this as having two language models, for writer h given by $\theta_h$ and writer t given by $\theta_t$. We know $\theta_h=0.9$, $\theta_t=0.1$ and we know the $p(w| t)$ but not $p(w|h)$. We initialize $p(w | \theta_h)$ to a random value and use EM. For our optimization we set our E-step to : \\
$p(z = 1| \theta_h) = \frac{\theta_h p^{(n)} p(w| \theta_h)}{\theta_h p^{(n)} p(w| \theta_h) + p(\theta_t) p^{(n)} p(w| \theta_t)}$
since we already know $\theta_h$ we and the true distribution for writer t we can replace their probability with a constant which allows us to simplify to e-step to$p(z = 1| \theta_h) = \frac{0.9p^{(n)} p(w| \theta_h)}{0.9p^{(n)} p(w| \theta_h) + c_w}$ where $c_w$ is the constant for $\theta_t*p(w|\theta_t)$.
For the M-Step modify the formula to update the word distribution. $p^(n+1) (w| \theta_h) = \frac{c(w,d)(1-p(z=1|\theta_h))p(w|D)}{\sum_{w' \in V} \sum_{d \in D} c(w',d)(1-p(z=h))p(z=t)}$
\section{Question 3}
To estimate the remaining 900 documents we apply the EM for PLSA as covered in lecture. First, we initialize all unknown parameters(true topic mapping of word distributions) randomly. Next we repeat the E-Step and the M step (covered shortly) until convergence. \\
E-step: Our hidden variable in this question is our topic indicator by word denoted by $z_{d,w}$ where $z_{d,w} \in {B, 1,2}$ where B is background, 1 is Seattle and 2 is Chicago. We run $(z_{d,w} = 1) = \frac{\pi_{d,j}^(n) p^(n) (w| \theta_1)}{\sum_{j'=2} \pi_{d,j}^(n) p^(n)(w| \theta_2)}$, $(z_{d,w} = 2) = \frac{\pi_{d,j}^(n) p^(n) (w| \theta_2)}{\sum_{j'=1} \pi_{d,j}^(n) p^(n)(w| \theta_1)}$ and $p(z_{d,w} = B) = \frac{\lambda_b p(w|\theta_b)}{\lambda_b p(w|\theta_b) + (1-\lambda_b)\sum_{j=1}^2 \pi_{d,j}^(n) p^(n) w| \theta_j)}$. \\
The M-step re-estimates the probability of doc d covering a topic $\theta_j$ where: $\pi_{d,j}^(n+1) = \frac{\sum_{w \in V} c(w,d)(1-p(z_{d,w}=B))p(z_{d,w} = j)}{\sum_{j'} \sum_{w \in V} c(w,d)(1-p(z_{d,w}=B))p(z_{d,w} = j')}$ and re-estimates the probability of word $w$ for topic $\theta_j$ by: $p^(n+1)(w| \theta_j) = \frac{\sum_{w \in V} c(w,d)(1-p(z_{d,w}=B))p(z_{d,w} = j)}{\sum_{w' \in V} \sum_{d \in D} c(w',d)(1-p(z_{d,w'}=B))p(z_{d,w'} = j)}$
\section{Topic Estimation}
\subsection{Question 1.1}
Implemented
\subsection{Question 1.2}
The first sequence, sampleseq1 and samplemod1 tags every a with 0 and b with 1 since output probabilities for 0 have been set to be A 0.9999 and for 1 have set to be b for 0.99999 and the transmission probabilities bet weens states are equal. This mean that it is most unlikely that any B receive a 0, a receive a 1 and transferring between 0 to 1 is as common as staying. \\
For the second sequnce, sampleseq2 and samplemod2 we produce eight zeros followed by 8 ones because of the different mix in transmission probabilities and output probabilities. Our first 8 outputs are 0 because it is dominated by As and as As are unlikley to be produced by 1 the sequence is likely zeros. Once the sequence transitions mostly to b, it is more probable that we had the minor odds of transitioning from 0 to 1 than producing that many B with state 0 so the second eight states are 1.
\subsection{Question 1.3}
See zip.
\subsection{Question 2.1}
See zip.
\subsection{Question 2.2}
See zip.
\subsection{Question 3.1}
The probabilities are slighly off as the model has 0.85583, 0.156617 which should be 0.8, 0.2 and 0.144053, 0.843271 which should be 0.2, 0.8. \\
The learned tagging is the same as the tagging produced by samplemod2.
\subsection{Question 3.2}
Yes this is able to identify DNA and amino acids. \\
If I insert one P it is able to identify as amino because there are no DNA sequences with P.\\
If I insert six P after the second A they are also all correctly identified as Aminos. If we look at the trained model we see for P 0.0736726 5.70029e-07 meaning P is never a DNA sequence and always an amino. Even when it is unlikely to go from DNA to amino (0 to 1 0.960808 0.0701715 and 1 to 0 0.0391916 0.929828) since P is never DNA it doesn't change.
\end{document}


\section{Linearize Cluster Assignment via Spectral Ordering}

\textit{Linearize Cluster Assignment via Spectral Ordering} by Chris Ding. \\
Cited by 69. \textit{Machine learning. ACM, 2004.}
\newline

\textbf{Main point} is that \begin{inparaenum}[\itshape a\upshape)]
\item that K-way clustering method depends on a linear ordering provided by the spectral ordering,
\item paper provide a ordering objective function.
\end{inparaenum}

\subsection{Linearized cluster assignment}
The linearized assignment algorithm depends on three techniques \begin{inparaenum}[\itshape a\upshape)]
\item an ordering of the data objects,
\item clustering crossing,
\item the connectivity matrix,
\end{inparaenum}

The actual linearization is performed via the cluster clustering, the sum of similarities symmetrically across a cut point along the linear ordering.


\problemname{Jackdaws And Crows}

\illustration{0.42}{jackdaws}{\href{https://www.flickr.com/photos/duncanh1/7874001966}{A Clattering of Jackdaws} by Dun.can on flickr, cc by}%
\noindent
Nick is a bird watcher and often visits the forum ``CrowFinders'' to discuss his hobby with like-minded people.
CrowFinders has a voting system where users can upvote or downvote comments, which increases or decreases their score by $1$.
This means that each comment can end up with any integer score (including negative scores).
Once when Nick was browsing a heated discussion about the classification of jackdaws as crows, he found something very pleasing: a chain of comments
that alternated between positive and negative scores. But a few days later, he found that the comment chain was no longer alternating.
Now Nick wants to make it alternating again.

A comment chain is alternating if the scores $s_1, s_2, \ldots, s_n$ of the comments all are non-zero, and every pair of adjacent scores $s_i$, $s_{i+1}$ have opposite signs.
In particular, a single comment with a non-zero score or even a comment chain without any comment is an alternating comment chain.

There are two operations Nick can do to make the comment chain alternating:
\begin{enumerate}
    \item Create a fake account and upvote/downvote some of the comments. This increases/decreases their respective scores by $1$.
    Each fake account can only upvote/downvote each comment at most once, but it can vote on any subset of the comments.
    It takes $c$ seconds to create an account and use it to vote (regardless of how many comments are upvoted/downvoted).
    \item Report one specific comment to remove it from the chain. Thinking of convincing reasons for the report takes $r$ seconds.
    (Nick is an excellent arguer, so once the report is filed, the comment is guaranteed to be removed.)
\end{enumerate}

Nick can apply these operations in any order, any number of times. How fast can he make the comment chain alternating?

For example, consider Sample Input 1 below, where the scores in the comment chain are $8, 8, 2, -2$, and it takes Nick $10$ seconds to create an
account and $50$ seconds to file a report for one comment. In this case it is optimal to first create $3$ fake accounts and use them to upvote
the fourth comment and downvote the third, followed by reporting the first comment. This results in the scores $8, -1, 1$, which is
an alternating chain. The time used for this is $80$ seconds.

\section*{Input}
The input consists of:
\begin{itemize}
  \item One line with three integers $n$, $c$, and $r$ ($1 \leq n \leq 5\cdot 10^5$, $1 \leq c,r \leq 10^9$), the number of comments in the chain,
    the time it takes to create a fake account and the time it takes to report one comment respectively.
  \item One line with $n$ integers $s_1, \ldots, s_n$ ($-10^9 \leq s_i \leq 10^9$ for all $i$), the current score of each comment in the chain.
\end{itemize}

\section*{Output}
Output the smallest time to make the comment chain alternating by applying the operations above.


\subsection{Modelling Variants of Concern (VoC)}
To consider the effects of VoC on infection dynamics and the vaccination programs, we explicitly simulated three competing strains to represent the wild-type or ancestral virus, Alpha and Delta VoC strains, which are the two main VoC strains that circulated in Sri Lanka during the study period. The two VoC strains were associated with increased transmissibility relative to wild-type and the respective transmisibility levels of each VoC strain were calibrated from the model. Susceptible individuals can be infected with either the wild-type or VoC strain and infectious individuals contribute to the force of infection with their respective infecting strain only. VoC strains are seeded into the model such that 25 additional persons per day are infected with a particular VoC strain for a duration of ten days, with the time that this ten-day period commences varied during model calibration.


\section{Discussion}
For the previous genetic programming approach that did not incorporate modularization, results were compared to those in the existing literature \cite{owen1999tubular, luukka2009pca, dash2013comparative} and it was noted that - while additional research is necessary to explore the application of a GP approach using a larger data set - the classifiers produced by the genetic programming approach performed relatively well. For this assignment, modularization - in the form of automatically defined functions - has been added to the genetic programming approach to investigate its effect in terms of accuracy, computational effort and structural complexity.

When compared to the results of the approach that did not incorporate modularization, the classifiers produced after adding modularization showed similar results in terms of accuracy. For instance, the best accuracy achieved on the training set before modularization was 87.14\% and, after modularization, this decreased slightly to 85.71\%. On the evaluation set, however, the best accuracy improved from 75\% to 80\% - indicating that introducing modularization may lead to better generalization.

% \begin{table}[H]
% \resizebox{\textwidth}{!}{\begin{tabular}{|c|c|c|c|}
% \hline
% \textbf{}               & \textbf{Average Accuracy} & \textbf{Best Accuracy} & \textbf{Standard Deviation} \\ \hline
% \textbf{Training Set}   & 83.71\%                   & 87.14\%                & 3.14\%                      \\ \hline
% \textbf{Evaluation Set} & 66.00\%                   & 75.00\%                & 6.63\%                      \\ \hline
% \textbf{Overall}        & 79.77\%                   & 82.22\%                & 2.43\%                      \\ \hline
% \end{tabular}}
% \caption{Classification Accuracy Before Modularization}
% \label{tab:classification_accuracy_before}
% \end{table}

In terms of computational effort, since no solutions were able to classify the data with a 100\% accuracy, it is unfortunately not possible to calculate how many programs have to be evaluated before a solution can be found. As an alternative for determining affects on computational effort, the runtimes for 10 test runs using the genetic programming approaches with and without modularization were recorded and are shown in figure \ref{fig:runtimes}. As can be seen, runtimes for the approach that incorporates modularization are consistently shorter than the previous approach. Considering the approaches used the same genetic algorithm parameters, this is a strong indicator that introducing modularization has decreased computational effort.

\begin{figure}[H]
\centering
\includegraphics[width=\textwidth]{report/08_discussion/runtimes.png}
\caption{Runtimes for 10 Test Runs With and Without Modularization}
\label{fig:runtimes}
\end{figure}

Finally, in considering the structural complexity of individuals produced by either approach, we consider the number terminal and function nodes that individuals are composed of. For the approach that did not incorporate modularization, the fittest individuals for each of 10 test runs had an average of 48.11 terminal and function nodes. For the approach that did incorporate modularization, this average was 36.03. Hence, it would seem that the approach using modularization evolves towards less complex individuals. However, since only the best individual per test run was considered in this calculation, no conclusions are drawn regarding the complexity of individuals during the evolutionary process.

In conclusion, expanding the previous genetic programming approach to produce a classifier for postoperative patient diagnosis by adding modularization led to similar results in terms of accuracy and improvements in both computational effort and structural complexity.


\section{Gesture Detection Methodologies} \label{sec:ges_}
    Gesture Recognition and Gesture Classification are two distinct aspects of the final application. Classification pertains to the attribution of meaning to a detected Gesture, and is therefore handled by the cultural layer, as each gesture may have different interpretation dependent on the culture chosen. Recognition is the prior step and is involved in how the system identifies meaningful gestures from among all gestures performed by the human users, in real time.\\
    There are a couple of approaches to handle recognition, between mathematical models and soft computing. Before tackling those, first it’d be important to quickly list the types of gestures that can be recognized and how they’re processed. These depend on the supporting instruments, which target different portions of the human body, obtain different sensor stimuli: Electric, Optic, Acoustic, Magnetic and Mechanic. These devices include: Gloves, Body Suits, Optical Trackers among others. Furthermore, vision-based techniques are incredibly varied and have several factors differentiating among themselves, by which broad fields of research and business are formed. The basic structure of a Gesture Recognition controller’s analysis involves two main tasks: Segmentation and Feature Extraction, features which are forwarded into a recognition module to build models. Segmentation is the extraction of the limbs of interest from background and determination of its location, while feature extraction is the determination of valuable data and cues among the segments. Not all input methods require the latter step, for example, magnetic sensors.\\
    The Recognition module follows up with different approaches: \emph{Hidden Markov Models} are a process governed by an underlying Markov chain with a finite number of states, and a random set of functions, each associated with each state. The transitions between states are based on probabilities. After each of a discrete amount of time, the system will be in one state and will observe a new symbol that feeds into the functions which will either yield a new state for the system, or output a recognized gesture for the followed chain. The chain involved a lot of mathematical modelling, producing a lot of deterministic integration, however, it can be seen as merely a sequence of observations and states, and thus it received the term “Hidden”. \emph{Particle Filtering} or alternatively, Sequential Monte Carlo, are approximations to simulation-based methods. Works by representing probabilities of noisy and partial samples, building a predictive model for the likelihood of following states. The benefit of these over grid-based filters such as conventional Markov models, is these do end up modelling uncertainty. \emph{The Finite State Machine} approach, by which a gesture is ordered by a sequence of states that vary in space and time. Each state is a datapoint of trajectory data, and the gesture is divided by each substantial change in trajectory data, sampled in a 2D space. Addition of gestures is achieved by constructing new FSM models and each gesture is matched to all the deterministic FSM’s. This does mean that adapting the system to more gestures requires incremental computational power, as well as adding winning criteria between gestures to choose the most likely when multiple are matched. \emph{Soft Computing}, which is a number of techniques which involve computational intelligence and computer learning with high degree of tolerance for imprecisions and uncertainty. The system can be trained even while in use and adapts to users. Methods include fuzzy logic, genetic algorithms, artificial neural networks. These, however, require a large amount of data and iterations to find adequate robustness.