\subsection{Quivers}\label{subsec:quivers}

\begin{definition}\label{def:quiver}
  A \term{quiver} or \term{directed multigraph} is an extension of \hyperref[def:undirected_multigraph]{undirected multigraphs}. A quiver consists of the following:
  \begin{thmenum}
    \thmitem{def:quiver/vertices} A set \( V \) of \term{vertices}.
    \thmitem{def:quiver/arcs} A disjoint from \( V \) set \( A \) of \term{arcs}. It is conventional to call them arcs or even directed edges rather than simply edges.
    \thmitem{def:quiver/head} A \term{head} function \( h: A \to V \).
    \thmitem{def:quiver/tail} A \term{tail} function \( t: A \to V \).
    \thmitem{def:quiver/adjacency} We say that the arc \( a \) is a \term{successor} of \( b \) and that \( b \) is a \term{predecessor} of \( a \) if \( t(a) = h(b) \). We also say that \( a \) and \( b \) are \term{consecutive}.

    For vertices, we say that \( w \) is a successor of \( v \) and that \( w \) is consecutive to \( w \) if there exists an arc from \( u \) to \( v \).

    \thmitem{def:quiver/forgetful} For each quiver \( Q = (V, A, h, t) \), we have an \enquote{underlying} undirected multigraph
    \begin{equation}\label{eq:def:quiver/forgetful}
      \begin{aligned}
        &G: A \to V, \\
        &G(a) \coloneqq \set{ h(a), t(a) }.
      \end{aligned}
    \end{equation}

    All properties of \( G \) are inherited by \( Q \), although some of them do not really fit or need adaptation.

    We denote this graph by \( U(Q) \coloneqq G \) and will regard it as a forgetful functor --- see \fullref{def:multigraph_orientation}.

    \thmitem{def:quiver/opposing} One adaptation is that the arcs \( a \) and \( b \) are called \term{opposing} they are successors of each other and the term \enquote{parallel} is reserved for arcs which are parallel in the sense of \fullref{def:hypergraph/parallel_hyperedges} but not opposing.

    \thmitem{def:quiver/simple} If there are no parallel and opposing arcs or loops, we call the quiver \term{simple}. The term \term{simple directed graph} is more commonly used.

    For a simple directed graph, we often write \( G = (V, E) \), where \( E \) is an \hyperref[def:binary_relation/irreflexive]{irreflexive} binary relation.

    We say that the simple directed graph is \term{symmetric} if this relation is symmetric. For many purposes, symmetric directed graphs can be regarded as undirected --- see \fullref{rem:symmetric_directed_graphs}.

    \thmitem{def:quiver/submodel} The \term{subquivers} of \( Q \) are the precisely \hyperref[def:undirected_multigraph/submodel]{subgraphs} of \( G \). In particular, the \term{full subquivers} are the \hyperref[def:undirected_multigraph/submodel]{full subgraphs}, that are maximal among the subgraphs with the same vertices.
  \end{thmenum}

  \begin{figure}
    \begin{equation}\label{eq:fig:def:quiver}
      \begin{aligned}
        \includegraphics[page=1]{output/def__quiver.pdf}
      \end{aligned}
    \end{equation}
    \caption{A quiver with a pair of parallel arcs, a pair of opposing arcs and a loop. Removing the dashed arcs makes it a simple directed graph.}\label{fig:def:quiver}
  \end{figure}
\end{definition}

\begin{example}\label{ex:infinite_integer_graphs}
  A very simple example of an infinite quiver is the \hyperref[def:relation_closures/transitive]{transitive reduction} of the positive integers, i.e. the simple directed graph
  \begin{equation}\label{eq:ex:infinite_integer_graphs/positive}
    \begin{aligned}
      \includegraphics[page=1]{output/ex__infinite_integer_graphs.pdf}
    \end{aligned}
  \end{equation}

  Since the graph is simple, we have
  \begin{equation*}
    \deg(n) = \begin{cases}
      1 = 0 + 1, &n = 0, \\
      2 = 1 + 1, &n > 0 \\
    \end{cases}
  \end{equation*}
  and thus \( \deg(G) = 2 \).

  The \hyperref[def:categorical_diagram]{categorical diagrams} corresponding to this quiver is used to define direct limits in \fullref{def:direct_and_inverse_limits/direct}.

  Another related graph is based on the negative integers:
  \begin{equation}\label{eq:ex:infinite_integer_graphs/negative}
    \begin{aligned}
      \includegraphics[page=2]{output/ex__infinite_integer_graphs.pdf}
    \end{aligned}
  \end{equation}

  The \hyperref[def:categorical_diagram]{categorical diagrams} corresponding to this quiver is used to define inverse limits in \fullref{def:direct_and_inverse_limits/inverse}.

  Finally, the union of the two with zero added gives us the following quiver:
  \begin{equation}\label{eq:ex:infinite_integer_graphs/two_sided}
    \begin{aligned}
      \includegraphics[page=3]{output/ex__infinite_integer_graphs.pdf}
    \end{aligned}
  \end{equation}

  All three graphs are infinite but \hyperref[def:hypergraph/degree]{locally finite}.
\end{example}

\begin{definition}\label{def:category_of_small_quivers}
  Suppose that we are given a \hyperref[def:grothendieck_universe]{Grothendieck universe} \( \mscrU \), which is safe to assume to be the smallest suitable one as explained in \fullref{def:large_and_small_sets}.

  We denote the \hyperref[def:category]{category} of \( \mscrU \)-small \hyperref[def:hypergraph]{quivers} by \( \ucat{Quiv} \) or, if the universe is clear from the context, simply by \( \cat{Quiv} \). See \fullref{def:category_size} for a further discussion of universes and categories.

  A more \enquote{categorical} definition, in which this category arises naturally, is given in \fullref{ex:quivers_as_functors}.

  For simple directed graphs, we denote the category using \( \cat{SimpQuiv} \).

  \begin{itemize}
    \item The \hyperref[def:category/objects]{set of objects} \( \obj(\cat{Quiv}) \) is the set of all \( \mscrU \)-small quivers, i.e. the quivers \( Q = (V, A, h, t) \) such that \( V \) and \( A \) are both members of \( \mscrU \).

    \item The \hyperref[def:category/morphisms]{set of morphisms} \( \cat{Quiv}(Q, R) \) from \( Q \) to \( R \) is the set quiver homomorphisms. Given two quivers \( Q = (V_Q, A_Q, h_Q, t_Q) \) and \( R = (V_R, A_R, h_R, t_R) \), a \term{quiver homomorphism} is a pair of functions
    \begin{equation}\label{eq:def:category_of_small_quivers/homomorphism}
      \begin{cases}
        f_V: V_Q \to V_R \\
        f_A: A_Q \to A_R
      \end{cases}
    \end{equation}
    such that
    \begin{align}
      h_R \bincirc f_A &= f_V \bincirc h_Q \label{eq:def:category_of_small_quivers/homomorphism/head} \\
      t_R \bincirc f_A &= f_V \bincirc t_Q \label{eq:def:category_of_small_quivers/homomorphism/tail}
    \end{align}

    See \fullref{ex:quivers_as_functors} for a categorical justification of this definition, including reducing the above conditions to the diagram \eqref{eq:ex:quivers_as_functors/index/diagram}.

    Clearly every quiver homomorphism is a \hyperref[eq:def:category_of_small_hypergraphs/homomorphism]{hypergraph homomorphism}.

    Note that \enquote{quiver embedding} commonly refers to an embedding of its \hyperref[def:quiver_geometric_realization/undirected]{geometric realization}, hence we will avoid the term when referring to injective quiver homomorphisms. Furthermore, it should be clarified whether we mean \enquote{injective on vertices} or \enquote{injective on arcs}, which is an important distinction in category theory --- see \fullref{def:functor_invertibility}.

    \item The \hyperref[def:category/composition]{composition of quiver morphisms} is pointwise composition --- the same as composition of hypergraph homomorphisms.

    \item The \hyperref[def:category/identity]{identity morphism} on the quiver \( Q = (V, A, h, t) \) is the pair of \hyperref[def:multi_valued_function/identity]{identity functions} \( (\id_V, \id_A) \).
  \end{itemize}
\end{definition}

\begin{definition}\label{def:multigraph_orientation}\mcite{nLab:oriented_graph}
  Given an \hyperref[def:undirected_multigraph]{undirected (multi)graph} \( G = (V, E, \mscrE) \), constructing a quiver requires a choice of head and tail for every edge. We can view undirected graphs as equivalence classes of quivers. A head function is merely a \hyperref[def:choice_function]{choice function} on the set \( \set{ \mscrE(e) \given e \in E } \), and a choice function can be provided by the \hyperref[def:zfc/choice]{axiom of choice} even for infinite graphs.

  For a given choice function \( c \), we denote by \( O_c(G) = (V, E, h, t) \) the quiver obtained by identifying the head \( h(e) \) with \( c(\mscrE(e)) \) and the tail \( t(e) \) with the other endpoint of \( e \), if one exists, and with \( h(e) \) for loops. We call \( O_c(G) \) the \term{orientation} induced by the choice function \( c \).

  Note that \( O_c \) is not left adjoint to \( U \) --- see \fullref{ex:def:category_adjunction/multgph_quiv}.
\end{definition}

\begin{remark}\label{rem:graphs_linear_algebra_and_topology}
  As we shall see, the \hyperref[def:hypergraph/adjacency]{adjacency} and \hyperref[def:hypergraph/incidence]{incidence} of a quiver can be studied using linear algebra via \hyperref[def:graph_adjacency_matrix]{adjacency} and \hyperref[def:hypergraph_incidence_matrix]{incidence matrices}, while the \hyperref[def:quiver_connectedness]{connectedness} can be studied using \hyperref[def:quiver_connectedness]{topology} via \hyperref[def:quiver_geometric_realization/embedding]{graph embeddings}.
\end{remark}

\begin{definition}\label{def:quiver_incidence_matrix}\mcite[ch. 1, sec. 2.1]{GondranMinoux1984Graphs}
  Let \( Q = (A, E, h, t) \) be a finite quiver. Its \term{incidence matrix}
  \begin{equation*}
    M = \seq{ M_{va} }_{v \in V, a \in A}
  \end{equation*}
  has elements
  \begin{equation*}
    M_{va} \coloneqq \begin{cases}
      1,  &v = h(e) \\
      -1, &v = h(e) \\
      0,  &\T{otherwise.}
    \end{cases}
  \end{equation*}

  Compare this definition to \fullref{def:hypergraph_incidence_matrix}.
\end{definition}

\begin{example}\label{ex:quiver_matrices}
  The \hyperref[def:quiver_incidence_matrix]{incidence matrix} of the simple directed graph \eqref{eq:fig:def:quiver} is
  \begin{equation}\label{ex:quiver_matrices/incidence}
    \begin{blockarray}{cccccccc}
        & e_1       & e_2       & e_3       & e_4       & e_5       & e_6       & e_7       \\
      \begin{block}{c(ccccccc)}
      a & 1         & 1         &           &           &           &           &           \\
      b & \fbox{-1} &           & 1         &           &           &           &           \\
      c &           & \fbox{-1} &           & 1         & 1         &           &           \\
      d &           &           & \fbox{-1} & \fbox{-1} &           & 1         &           \\
      e &           &           &           &           & \fbox{-1} &           & 1         \\
      f &           &           &           &           &           & \fbox{-1} & \fbox{-1} \\
      \end{block}
    \end{blockarray}
  \end{equation}

  It can be read column-by-column. Every column contains exactly two nonzero elements whose rows correspond to the head (positive) and tail (negative).

  To obtain the incidence matrix for the underlying undirected graph \eqref{eq:fig:def:undirected_multigraph}, we need to simply flip the sign of the boxed elements above.

  The \hyperref[def:graph_adjacency_matrix]{adjacency matrix} is,
  \begin{equation}\label{ex:quiver_matrices/adjacency}
    \begin{blockarray}{cccccccc}
        & a        & b        & c        & d        & e        & f \\
    \begin{block}{c(ccccccc)}
      a &          & 1        & 1        &          &          &   \\
      b & \fbox{1} &          &          & 1        &          &   \\
      c & \fbox{1} &          &          & 1        & 1        &   \\
      d &          & \fbox{1} & \fbox{1} &          &          & 1 \\
      e &          &          & \fbox{1} &          &          & 1 \\
      f &          &          &          & \fbox{1} & \fbox{1} &   \\
    \end{block}
    \end{blockarray}
  \end{equation}
  where the boxed elements are nonzero only in the adjacency matrix for \eqref{eq:fig:def:undirected_multigraph} and not \eqref{eq:fig:def:quiver}.

  The matrix can be read either column-by-column or row-by-row.
  \begin{itemize}
    \item The \( v \)-th column lists the vertices \( u \) such that there is an arc from \( u \) to \( v \).
    \item The \( u \)-th row lists the vertices \( v \) such that there is an arc from \( v \) to \( u \).
  \end{itemize}
\end{example}

\begin{proposition}\label{thm:graph_undirected_iff_adjacency_matrix_is_symmetric}
  Every square finite matrix over the two-element field \hyperref[thm:ring_of_integers_modulo_zero_divisors]{\( \BbbF_2 \)} corresponds to a \hyperref[def:quiver]{quiver} without parallel arcs.

  If the matrix is symmetric, we obtain its underlying \hyperref[def:undirected_multigraph]{undirected graph}.
\end{proposition}
\begin{proof}
  Trivial.
\end{proof}

\begin{remark}\label{rem:symmetric_directed_graphs}
  It is sometimes convenient to conflate symmetric \hyperref[def:quiver/simple]{simple directed graphs} with \hyperref[def:undirected_multigraph]{simple undirected graphs}.

  This is partially justified by \fullref{thm:graph_undirected_iff_adjacency_matrix_is_symmetric}.
\end{remark}

\begin{definition}\label{def:quiver_path}
  Let \( Q = (V, A, h, t) \) be a \hyperref[def:quiver]{quiver}.

  \begin{thmenum}
    \thmitem{def:quiver_path/directed} A \term{directed path} or simply \term{path} in \( Q \) a finite or infinite sequence of \hyperref[def:quiver/adjacency]{consecutive arcs} with a specified head vertex. Formally, it is a sequence \( p = (v, e_1, e_2, \ldots) \), where \( h(e_k) = t(e_{k-1}) \) for every index \( k \).

    This is a simplification of \fullref{def:undirected_multigraph_path} since every arc has a head and tail. It is also too restrictive for some purposes.

    The definitions of \hyperref[def:undirected_multigraph_path/endpoints]{path endpoints}, \hyperref[def:undirected_multigraph_path/empty]{empty path}, \hyperref[def:undirected_multigraph_path/length]{length}, \hyperref[def:undirected_multigraph_path/domain]{domain}, \hyperref[def:undirected_multigraph_path/concatenation]{concatenation} and \hyperref[def:undirected_multigraph_path/characteristic_vector]{characteristic vector} of a directed path are inherited from \fullref{def:undirected_multigraph_path}.

    \thmitem{def:quiver_path/cycle} A \term{directed cycle} is a directed path whose endpoints coincide. The term \term{circuit} is also used, for example in \cite[ch. 1, sec. 3.2]{GondranMinoux1984Graphs}. A quiver without cycles is called \term{acyclic} and a simple acyclic directed graph is commonly abbreviated as \term{DAG}.

    \thmitem{def:quiver_path/simple} Similarly to \fullref{def:undirected_multigraph_path/simple}, we say that a directed path is \term{simple} if it contains to directed cycles.

    \thmitem{def:quiver_path/undirected} If \( p = (v, e_1, e_2, \ldots) \) is a path in the \hyperref[def:undirected_multigraph]{undirected multigraph} \( U(Q) \),
    \begin{equation*}
      D(p) \coloneqq (v, e_1, e_2, \ldots)
    \end{equation*}
    is a sequence of adjacent arcs in \( Q \) (with a specified head vertex).

    The head and tail of \( D(p) \) are defined as the head and tail of \( p \). This definition obviously differs from \fullref{def:quiver_path}.

    We say that the arc \( e_k \) of \( D(p) \) is \term{positively oriented} if the head \( h_k \) of the edge \( e_k \) in \( Q \) equals the head \( h(e_k) \) of the arc \( e_k \) in \( D(p) \). If \( e_k \) is not positively oriented, we say that it is \term{negatively oriented}.

    We conflate \( p \) and \( D(p) \) where this does not cause confusion.

    Undirected paths are also called \term{chains} in \cite[ch. 1, sec. 3.2]{GondranMinoux1984Graphs}.
  \end{thmenum}
\end{definition}

\begin{example}\label{ex:def:quiver_path}
  An example of an infinite \hyperref[def:quiver_path/directed]{directed path} is the reduced positive integer graph \eqref{eq:ex:infinite_integer_graphs/positive} regarded as a path of the reduced integer graph \eqref{eq:ex:infinite_integer_graphs/two_sided}. It is also simple since the degree of \eqref{eq:ex:infinite_integer_graphs/positive} is \( 2 \).

  Now consider again the quiver \eqref{eq:fig:def:quiver}. The solid lines in \eqref{fig:ex:def:quiver_path} describe a path.
  \begin{equation}\label{fig:ex:def:quiver_path}
    \begin{aligned}
      \includegraphics[page=1]{output/ex__def__quiver_path.pdf}
    \end{aligned}
  \end{equation}

  \begin{itemize}
    \item This path corresponds to the sequence
    \begin{equation*}
      p = \parens{ a, \underbrace{a \to c}_{e_2}, \underbrace{c \to d}_{e_4}, \underbrace{d \to f}_{e_6} }.
    \end{equation*}

    \item Its \hyperref[def:undirected_multigraph_path/characteristic_vector]{characteristic vector} is
    \begin{equation*}
      \vect{p}
      =
      \begin{blockarray}{ccccccr}
        e_1 & e_2 & e_3 & e_4 & e_5 & e_6 & e_7 \\
      \begin{block}{(ccccccr)}
        0   & 1   & 0   & 1   & 0   & 1   & 0   \\
      \end{block}
      \end{blockarray}
      {}^T.
    \end{equation*}

    Furthermore, \( p \) can be identified from the characteristic vector.

    \item The \hyperref[def:quiver_path]{endpoints} are \( h(p) = h(e_1) = a \) and \( t(p) = t(e_7) = f \).

    \item It is a \hyperref[def:undirected_multigraph_path/simple]{simple path} because \( \deg(a) = \deg(f) = 1 \) and \( \deg(c) = \deg(d) = 2 \) in the induced subgraph.

    \item The \hyperref[def:undirected_multigraph_path/converse]{converse undirected path}
    \begin{equation*}
      p^{-1} = (f, d \to f, c \to d, a \to c),
    \end{equation*}
    is not a directed path because every arc is negatively oriented.
  \end{itemize}
\end{example}

\begin{definition}\label{def:quiver_condensation}
  Let \( Q = (V, A, h, t) \) be a \hyperref[def:quiver]{quiver}. We say that the vertex \( w \) is \term{reachable} from \( v \) if there exists a \hyperref[def:quiver_path/directed]{directed path} from \( v \) to \( w \).

  Define the equivalence relation
  \begin{equation*}
    v \sim w \iff v \T{is reachable from} w \T{and} w \T{is reachable from} u.
  \end{equation*}

  Now define the binary relation \( \widetilde{A} \) on the \hyperref[def:equivalence_relation/quotient]{quotient set} \( \widetilde{V} \coloneqq V / {\sim} \) as
  \begin{equation*}
    ([u], [v]) \in \widetilde{A} \iff v \T{is reachable from} w \T{but not vice versa}.
  \end{equation*}

  It is well-defined because if \( ([v_1], [w_1]) \in \widetilde{A} \), \( v_2 \in [v_1] \) and \( w_2 \in [w_1] \), then by the transitivity of reachability we have that \( w_2 \) is reachable from \( v_2 \) and thus \( ([v_2], [w_2]) \in \widetilde{A} \).

  As discussed in \fullref{def:quiver/simple}, irreflexive relations over sets can be regarded as simple directed graphs. Therefore, the pair \( \widetilde{G} \coloneqq (\widetilde{V}, \widetilde{A}) \) is a directed graph. It is called the \term{condensation} of the quiver \( Q \).

  Compare this definition to \fullref{def:undirected_multigraph_connectedness/condensation}.
\end{definition}

\begin{example}\label{ex:def:quiver_condensation}
  The \hyperref[def:quiver_condensation]{condensation} of the quiver in \eqref{eq:fig:def:quiver} is (isomorphic to) the graph itself. If we add the arc \( f \to a \) to \eqref{eq:fig:def:quiver}, the condensation would be an edgeless quiver with a single vertex.

  We can add new arcs \( e_8 \) and \( e_9 \) to the quiver in \eqref{eq:fig:def:quiver} to make the example more interesting:
  \begin{equation}\label{eq:ex:def:quiver_condensation/uncondensed}
    \begin{aligned}
      \includegraphics[page=1]{output/ex__def__graph_condensation.pdf}
    \end{aligned}
  \end{equation}

  Its condensation is
  \begin{equation}\label{eq:ex:def:quiver_condensation/condensed}
    \begin{aligned}
      \includegraphics[page=2]{output/ex__def__graph_condensation.pdf}
    \end{aligned}
  \end{equation}

  These are the \hyperref[def:quiver_connectedness/strong]{strongly connected components} of \eqref{eq:ex:def:quiver_condensation/uncondensed}.
\end{example}

\begin{proposition}\label{thm:graph_condensation_is_acyclic_dag}
  The \hyperref[def:quiver_condensation]{condensation} of a quiver is a \hyperref[def:undirected_multigraph_path]{directed acyclic graph}.
\end{proposition}
\begin{proof}
  Let \( \widetilde{G} = (\widetilde{V}, \widetilde{E}) \) be the condensation of the quiver \( Q = (V, A, h, t) \). We have already discussed in \fullref{def:quiver_condensation} that it is a directed graph. It remains to show that it is acyclic.

  Aiming at a contradiction, suppose that there exist cosets \( [u] \) and \( [v] \) and a path
  \begin{equation*}
    \parens[\Big]{ [u] \to [w_1], \cdots, [w_n] \to [v] }
  \end{equation*}
  in \( \widetilde{G} \) that connects them. We can easily prove by induction that \( v \) is reachable from \( u \), thus contradicting the definition of \( \widetilde{A} \).

  Therefore, \( \widetilde{G} \) is acyclic.
\end{proof}

\begin{definition}\label{def:quiver_connectedness}
  Let \( Q = (V, E, h, t) \) be a quiver and let \( \widetilde{G} = (\widetilde{V}, \widetilde{E}) \) be its condensed directed graph.

  \begin{thmenum}
    \thmitem{def:quiver_connectedness/strong}\mcite[ch. 1, sec. 3.5]{GondranMinoux1984Graphs} For every coset \( [v] \) in \( \widetilde{V} \), the \hyperref[def:hypergraph/submodel]{subquiver} of \( Q \) induced by the vertices \( [v] \) is called a \term{strongly connected component} of \( Q \).

    The \term{strong connectivity number} of \( Q \) is the cardinality \( \card(\widetilde{V}) \).

    If \( Q \) has only one strongly connected component, we say that it itself is \term{strongly connected}.

    \thmitem{def:quiver_connectedness/weak}\mcite[ch. 1, sec. 3.3]{GondranMinoux1984Graphs} Similarly, the subquiver \( Q' \) of \( Q \) is called a \term{weakly connected component} if is a connected component, in the sense of \fullref{def:undirected_multigraph_connectedness/components}, of the underlying undirected multigraph \( U(Q) \).

    The \term{weak connectivity number} of \( Q \) is the connectivity number of \( U(Q) \).

    If \( Q \) has only one weakly connected component, we say that it itself is \term{weakly connected}.
  \end{thmenum}

  This definition generalizes symmetric and transitive closures of binary relations not commuting --- see \fullref{ex:thm:def:relation_closures/symmetric_and_transitive}.

  Compare this definition to \fullref{def:undirected_multigraph_connectedness}.
\end{definition}

\begin{proposition}\label{thm:quiver_connectedness_via_chains}
  Let \( Q \) be a \hyperref[def:quiver]{quiver}.

  \begin{thmenum}
    \thmitem{thm:quiver_connectedness_via_chains/strong} \( Q \) is \hyperref[def:quiver_connectedness/strong]{strongly connected} if and only if there exists a \hyperref[def:quiver_path/directed]{directed path} connecting every pair of vertices.

    \thmitem{thm:quiver_connectedness_via_chains/weak} \( Q \) is \hyperref[def:quiver_connectedness/weak]{weakly connected} if and only if there exists an \hyperref[def:quiver_path/undirected]{undirected path} connecting every pair of vertices.
  \end{thmenum}
\end{proposition}
\begin{proof}
  Trivial.
\end{proof}

\begin{remark}\label{rem:well_founded_graphs}
  We can regard any set \( A \) in the sense of \hyperref[def:zfc]{\logic{ZFC}} as the simple directed graph \( (A, \in) \).

  The \hyperref[def:zfc/foundation]{axiom of foundation} (via \fullref{thm:set_membership_is_well_founded}) implies that the relation \( \in \) is well-founded.

  In the terminology if graph theory, this well-foundedness means that, for every vertex \( v \), there exists no infinite \hyperref[def:quiver_path]{path} that ends with \( v \).

  This implies that the graph is \hyperref[def:undirected_multigraph_path]{acyclic}. For finite graphs the converse holds, but an infinite graph this is not so. For example, the chain \eqref{eq:ex:infinite_integer_graphs/positive} is acyclic but not well-founded.

  Well-founded graphs are important for \fullref{thm:well_founded_induction}.
\end{remark}

\begin{definition}\label{def:quiver_free_category}
  Let \( Q = (V, A, h, t) \) be a \hyperref[def:quiver]{quiver}. We define the \term{free category} \( F(Q) \) generated by \( Q \) as follows:
  \begin{itemize}
    \item The \hyperref[def:category/objects]{set of objects} \( \obj(F(Q)) \) is the set of vertices \( V \).

    \item The \hyperref[def:category/morphisms]{set of morphisms} \( \cat{F(Q)}(v, w) \) is the set of all paths from \( v \) to \( w \).

    \item The \hyperref[def:category/composition]{composition of the morphisms} \( p \) and \( q \) with \( h(q) = t(p) \) is the \hyperref[def:undirected_multigraph_path/concatenation]{concatenation}
    \begin{equation*}
      q \bincirc p = p \cdot q.
    \end{equation*}

    \item The \hyperref[def:category/identity]{identity morphism} on the vertex \( v \) is the \hyperref[def:undirected_multigraph_path/empty]{empty path} at \( v \). This is the primary motivation for having a distinct empty path at every vertex.
  \end{itemize}

  Since \( F(Q) \) is already defined for every quiver \( Q \), if we also define how it acts on \hyperref[eq:def:category_of_small_quivers/homomorphism]{quiver homomorphisms}, this will make \( F \) a \hyperref[def:functor]{functor} from the category \hyperref[def:category_of_small_quivers]{\( \ucat{Quiv} \)} of \( \mscrU \)-small quivers to the category \hyperref[def:category_of_small_quivers]{\( \ucat{Cat} \)} of \( \mscrU \)-small categories, for every \hyperref[def:grothendieck_universe]{Grothendieck universe} \( \mscrU \) containing \( Q \).

  For every \( \mscrU \)-small category \( \cat{C} \) and every quiver homomorphism \( (g_V, g_A): Q \to U(\cat{C}) \), we define the following functor:
  \begin{equation}\label{eq:def:quiver_free_category/functor_from_homomorphism}
    \begin{aligned}
      &G: F(Q) \to \cat{C}, \\
      &G(v) \coloneqq g_V(v) \\
      &G(v, a_1, \ldots, a_n) \coloneqq \begin{cases}
        \id_v,                                        &n = 0, \\
        g_A(a_n) \bincirc G(v, a_1, \ldots, a_{n-1}), &n > 0,
      \end{cases}
    \end{aligned}
  \end{equation}

  The functor \( G \) \enquote{evaluates} paths in \( Q \) inside \( \cat{C} \). Put \( F(f_V, f_A) \coloneqq G \). Parameterized on \( (f_V, f_A) \), this defines \( F \) is a functor from \( \ucat{Quiv} \) to \( \ucat{Cat} \).

  We will see in \fullref{ex:def:category_adjunction/quiv_cat} that \( F \) is actually left adjoint to the forgetful functor \( U \). The new identity loops are an important part of this adjunction.
\end{definition}


\chapter{Rosetta Stone}
Bayesian statistics has a lot of terminology floating around, and sometimes
different communities use different terms for the same concept. This appendix
lists various common terms that are basically synonymous (they mean the same thing).
I may even throw in the different terms from time to time, intentionally or
unintentionally!

\subsection*{Event, Hypothesis, Proposition, Statement}
These are all basically the same thing.
A proposition is something that can be either true or false, such as ``my age is
greater than 35'' or ``the number of Aardvarks in my room is either zero or
one''. These are the things that go in our
probability statements: If we write $P(A|B)$, $A$ and $B$ are both propositions,
that is, statements that may be true or false. Event is the preferred term in
classical statistics.

\subsection*{Sampling Distribution, Probability Model for the Data,
Generative Model, Likelihood Function, Likelihood}
This is the thing that we
write as $p(x|\theta)$. Sometimes it is called the sampling distribution or
a generative model because
you can sometimes think of the data as having been ``drawn from''
$p(x|\theta)$ but using the true value of $\theta$, which you don't actually
know. There is a subtlety here, and that is that the word likelihood can be
used to mean either $p(x|\theta)$ before $x$ is known (in which case it is the
thing you would use to predict possible data) or after $x$ is known. In the latter
case $p(x|\theta)$ is only a function of $\theta$ because $x$ is fixed at the
observed value. The term likelihood function is often used at this point.

\subsection*{Probability Distribution}
The term probability distribution is used to refer to either a probability density
function (in the continuous case) or a probability mass function (in the discrete
case). The latter gives the probability of each particular value, whereas the
former only gives a probability if you integrate it within some region.

\subsection*{Marginal Likelihood, Evidence, Prior Predictive Probability, Normalising
Constant}
This is the $p(x)$ or $P(x)$ term in the denominator of Bayes' rule,
and it is also the total of the {\tt prior} $\times$ {\tt likelihood} column
of a Bayes' Box. This is the probability of getting the data that you actually got,
before you observed it: hence the terminology ``prior predictive probability''.
It is also the thing you use to normalise the posterior distribution (make it sum
or integrate to 1), hence the term normalising constant. Marginal likelihood makes
sense because it is a probability of data (like the regular likelihood) but
``marginalised'' (i.e. not caring about) the value of the parameter(s). It is
also called ``evidence'' because it can be used to compare different models, or
to ``patch together'' two Bayes' Boxes after the fact (see the hypothesis testing
chapter).


% Document type
\documentclass[]{amsbook}
%----------------------------------------------------------
% Packages
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{mathtools}
\usepackage[pdftex, bookmarks, colorlinks=true]{hyperref}
\usepackage{tikz-cd}
\usepackage{bbm}
%----------------------------------------------------------
% User-defined environments
\theoremstyle{plain}
\newtheorem{acknowledgement}{Acknowledgement}
\newtheorem{algorithm}{Algorithm}[section]
\newtheorem{axiom}{Axiom}[section]
\newtheorem{case}{Case}[section]
\newtheorem{claim}{Claim}[section]
\newtheorem{conclusion}{Conclusion}[section]
\newtheorem{condition}{Condition}[section]
\newtheorem{conjecture}{Conjecture}[section]
\newtheorem{corollary}{Corollary}[section]
\newtheorem{criterion}{Criterion}
\newtheorem{definition}{Definition}[section]
\newtheorem{example}{Example}[section]
\newtheorem{exercise}{Exercise}[section]
\newtheorem{lemma}{Lemma}[section]
\newtheorem{notation}{Notation}[section]
\newtheorem{problem}{Problem}[section]
\newtheorem{proposition}{Proposition}
\newtheorem{remark}{Remark}[section]
\newtheorem{solution}{Solution}[section]
\newtheorem{summary}{Summary}[section]
\newtheorem{theorem}{Theorem}[section]
\numberwithin{equation}{section}

\theoremstyle{definition}
\newtheorem{xca}{Exercise}[section]
%-----------------------------------------------------------
% User-defined commands
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}

\newcommand{\dps}{\displaystyle}
\newcommand{\mb}[1]{\mathbf{#1}}
\newcommand{\mbb}[1]{\mathbb{#1}}
\newcommand{\mf}[1]{\mathfrak{#1}}
\newcommand{\mc}[1]{\mathcal{#1}}
\newcommand{\opn}[1]{\operatorname{#1}}
\newcommand{\tb}[1]{\textbf{#1}}

\newcommand{\catname}[1]{\mathbf{#1}}
\newcommand{\0}{\mathbf{0}}
\newcommand{\1}{\mathbf{1}}

\newcommand{\la}{\langle}
\newcommand{\ra}{\rangle}

\newcommand{\q}{\quad}
\newcommand{\qq}{\quad \quad}
\newcommand{\qqq}{\quad \quad \quad}

\newcommand{\oldemptyset}{\emptyset}
\renewcommand{\emptyset}{\varnothing}
%-----------------------------------------------------------
% Math operators
\DeclareMathOperator{\End}{End}
\DeclareMathOperator{\Hom}{Hom}
\DeclareMathOperator{\lcm}{lcm}
%-----------------------------------------------------------
\begin{document}
\frontmatter
\title[`Algebra: Chapter 0']{Solutions to Exercises from `Algebra: Chapter 0'}

\begin{abstract}
Solutions to exercises from the book `Algebra: Chapter 0' by Paolo Aluffi.
\end{abstract}

\maketitle
\tableofcontents

\chapter*{Preface}

\markboth{PREFACE}{PREFACE} This document contains my attempt at writing
(hopefully correct!) solutions to exercises from Aluffi's book, while engaging
in some self-study of modern abstract algebra with the ultimate aim of teaching
myself some modern algebraic geometry.
\mainmatter

\include{chapters/set-theory-and-categories}
\include{chapters/groups-first-encounter}

\end{document}


\lab{Algorithms}{ARMA Models}{ARMA Models}
\label{lab:arma}
\objective{Fit and forecast ARMA models.}

An $\text{ARMA}(p,q)$ model is a covariance-stationary discrete stochastic
process $\{z_t\}$ that satisfies
\begin{align}
    \label{eq:arma:def}
    z_t - \mu = \left(\sum_{i=1}^p \phi_{i}(z_{t - i} - \mu)\right) + a_t +
    \left(\sum_{j=1}^{q} \theta_{j}a_{t-j} \right)
\end{align}
where $\mu = E[z_t]$ and $a_t$ are identically Gaussian distributed with
variance $\sigma_a^2$. We note that the assumption that $\{z_t\}$ is
covariance-stationary is eqivalent to the condition that the roots of the
polynomial in $B$
\begin{align}
    \label{eq:arma:characteristic}
    \phi(B) = 1 - \sum_{i=1}^p\phi_iB^i
\end{align}
lie without the unit circle.

The first sum on the right hand side of \ref{eq:arma:def} is interpreted as an
``autoregression'' since it is a linear combination of previously observed
values of $z_t$. The second sum is interpreted as a ``moving average'' of the
current and previous error terms; though formally similar to an average, note
that the $\theta_j$ need not be positive nor sum to one. We say that an
$\text{ARMA}(p,q)$ model is an ``autoregressive moving-average model of order
p, q''.

\section*{Likelihood via Kalman Filter}

In a general $\text{ARMA}(p,q)$ model, the likelihood is a function of the
unobserved error terms $a_t$ and is not trivial to compute. Simple
approximations can be made, but these may be inaccurate under certain
circumstances. Explicit derivations of the likelihood are possible, but
tedious. However, when the $\text{ARMA}$ model is placed in state-space, the
Kalman filter affords a straightforward, recursive way to compute the
likelihood.

We demonstrate a state-space representation of an $\text{ARMA}(p,q)$ model. If
$r = \max(p, q+1)$, we write
\begin{align}
    F &= \begin{bmatrix}
        \phi_1 & \phi_2 & \cdots & \phi_{r-1} & \phi_r\\
        1 & 0 & \cdots & 0 & 0\\
        0 & 1 & \cdots & 0 & 0\\
        \vdots & \vdots & \cdots & \vdots & \vdots\\
        0 & 0 & \cdots & 1 & 0
    \end{bmatrix}\\
    H &= \begin{bmatrix}
        1 & \theta_1 & \theta_2 & \cdots & \theta_{r-1}
    \end{bmatrix}\\
    Q &= \begin{bmatrix}
        \sigma_a^2 & 0 & \cdots & 0\\
        0 & 0 & \cdots & 0\\
        \vdots & \vdots & \cdots & \vdots\\
        0 & 0 & \cdots & 0
    \end{bmatrix}\\
    w_t &\sim \text{MVN}(0, Q)
\end{align}
where $\phi_i = \theta_j = 0$ for $i > p, j > q$. Then the linear stochastic
dynamical system
\begin{align}
    x_{t+1} &= Fx_t + w_t\\
    z_t &= Hx_t + \mu
\end{align}
describes the same process as the original $\text{ARMA}$ model.

Let $\Theta = \{\phi_i, \theta_j, \mu, \sigma_a^2\}$ be the set of parameters
for an $\text{ARMA}(p,q)$ model. Using the chain rule, we can factorize the
likelihood as
\begin{align}
    \label{eq:arma:factorized}
    p(\{z_t\} | \Theta) = \prod_{t=1}^{n} p(z_t | z_{t-1}, \ldots, z_{1},
    \Theta)
\end{align}
Since we have assumed that the error terms are Gaussian, each conditional
distribution in \ref{eq:arma:factorized} is also Gaussian, and is completely
characterized by its mean and variance. But these two quantities are easily
found via the Kalman filter, namely
\begin{align}
    \text{mean} & \quad H\hat{x}_{t|t-1} + \mu \\
    \text{variance} & \quad HP_{t|t-1}H^T
\end{align}
where $\hat{x}_{t|t-1}, P_{t|t-1}$ are found during the Predict step. Our
likelihood becomes
\begin{align}
    \label{eq:arma:likelihood}
    p(\{z_t\} | \Theta) = \prod_{t=1}^{n} N(z_t;\; H\hat{x}_{t|t-1} + \mu,\;
    HP_{t|t-1}H^T)
\end{align}
We begin the recursion by letting
\begin{align}
    \hat{x}_{1|0} &= \mathbb{E}(x_1) = 0 \\
    \text{vec}(P_{1|0}) &= \mathbb{E}\left[(x_1 - \mathbb{E}x_1)(x_1 -
    \mathbb{E}x_1)^T\right] = \left[I_{r^2} - (F \otimes F)\right]^{-1} \cdot
    \text{vec}(Q)
\end{align}
where $\text{vec}$ flattens a matrix and $\otimes$ is the Kronecker product
({\tt numpy.kron}).

\begin{problem}
\label{prob:arma:likelihood}
Write a function that computes the log-likelihood of an $\text{ARMA}(p,q)$
model, given a time series $z_t$. You may reuse your Kalman filter code from
Lab \ref{lab:kalman}.

\begin{lstlisting}
def arma_likelihood(time_series, phis=array([]), thetas=array([]), mu=0.,
        sigma=1.):
    """
    Return the log-likelihood of the ARMA model parameters, given the time
    series.

    Parameters
    ----------
    time_series : ndarray of shape (n,1)
        The time series in question
    phis : ndarray of shape (p,)
        The phi parameters
    thetas : ndarray of shape (q,)
        The theta parameters
    mu : float
        The parameter mu
    sigma : float
        The parameter sigma

    Returns
    -------
    log_likelihood : float
        The log-likelihood of the model
    """
    pass
\end{lstlisting}

\vspace{3mm} \noindent
For example,
\begin{lstlisting}
>>> arma_likelihood(time_series_a, phis=array([0.9]), mu=17., sigma=0.4)
-77.6035
\end{lstlisting}
\end{problem}

\section*{Identification and Fitting}

When modeling a data set with an $\text{ARMA}(p,q)$ model, the order of the
model must be determined as well as the other parameters. The process of
choosing $p$ and $q$ is called model identification. Different methods have
been used; for example, Box and Jenkins propose a methodology that involves
examining the estimated autocorrelation and partial-autocorrelation functions
of the data. We will choose $p$ and $q$ that minimize the Akaike information
criterion with a correction (AICc), given by
\begin{align}
    2k\left(1 + \frac{k+1}{n-k}\right) - 2 \ell(\Theta)
\end{align}
where $n$ is the sample size, $k = p + q + 2$ is the number of parameters in
the model, and $\ell(\Theta)$ is the maximum likelihood for the model class.

To compute the maximum likelihood for a model class, we need to optimize
\ref{eq:arma:likelihood} over the space of parameters $\Theta$. We can do so
using our function from Problem \ref{prob:arma:likelihood} along with some
optimization routine, such as {\tt scipy.optimize.fmin}.

\begin{problem}
\label{prob:arma:mle}
Write a function that accepts a time series $\{z_t\}$ and returns the
parameters of the model that minimizes the AICc, given the constraint that $p
\leq 3$, $q \leq 3$.

\begin{lstlisting}
def arma_fit(time_series):
    """
    Return the ARMA model that minimizes AICc for the given time series,
    subject to p,q <= 3.

    Parameters
    ----------
    time_series : ndarray of shape (n,1)
        The time series in question

    Returns
    -------
    phis : ndarray of shape (p,)
        The phi parameters
    thetas : ndarray of shape (q,)
        The theta parameters
    mu : float
        The parameter mu
    sigma : float
        The parameter sigma
    """
    pass
\end{lstlisting}

\vspace{3mm} \noindent
For example,
\begin{lstlisting}
>>> arma_fit(time_series_a)
(array([ 0.9087]), array([-0.5759]), 17.0652..., 0.3125...)
\end{lstlisting}
\end{problem}

\begin{problem}
\label{prob:arma:data}
Use your solution from Problem \ref{prob:arma:mle} to fit models to the data
found in {\tt time\_series\_a.txt}, {\tt time\_series\_b.txt}, {\tt
time\_series\_c.txt}. Report the fitted parameters $p, q, \Theta$.
\end{problem}

\section*{Forecasting}
The Kalman filter provides a straightforward way to predict future states, by
giving the mean and variance of the conditional distribution of future
observations.
\begin{align}
    z_{t + k} | z_{1}, \cdots, z_{t} \sim N(z_k;\; H\hat{x}_{t+k|t} + \mu,\;
    HP_{t+k|t}H^T)
\end{align}
Recall the relations
\begin{align}
    \hat{x}_{t+k|t} &= F\hat{x}_{t+k-1|t}\\
    P_{t+k|t} &= FP_{t+k-1|t}F^T + Q
\end{align}

\begin{problem}
\label{prob:arma:forecast}
Forecast each data set ahead 20 intervals using the parameters discovered from
Problem \ref{prob:arma:data}, and plot their expected values along with the
original data set. Also plot the expected values plus and minus $\sigma_{t+k}$,
and plus and minus $2\sigma_{t+k}$ to demonstrate credible intervals.

\begin{lstlisting}
def arma_forecast(time_series, phis=array([]), thetas=array([]), mu=0.,
        sigma=1., future_periods=20):
    """
    Return forecasts for a time series modeled with the given ARMA model.

    Parameters
    ----------
    time_series : ndarray of shape (n,1)
        The time series in question
    phis : ndarray of shape (p,)
        The phi parameters
    thetas : ndarray of shape (q,)
        The theta parameters
    mu : float
        The parameter mu
    sigma : float
        The parameter sigma
    future_periods : int
        The number of future periods to return

    Returns
    -------
    evls : ndarray of shape (future_periods,)
        The expected values of z for times n + 1, ..., n + future_periods
    sigs : ndarray of shape (future_periods,)
        The deviations of z for times n + 1, ..., n + future_periods
    """
    pass
\end{lstlisting}

\vspace{3mm} \noindent
For example,
\begin{lstlisting}
>>> arma_forecast(time_series_a, phis, thetas, mu, sigma, 4)
(array([ 17.3762,  17.3478,  17.322 ,  17.2986]),
 array([ 0.3125,  0.3294,  0.3427,  0.3533]))
\end{lstlisting}
\end{problem}

\begin{comment}

The Box-Jenkins methodology may be too esoteric, in light of straightforward
alternatives such as the AICc. I have decided to leave this material out.

\section*{Identification}

If we have a time series $\{z_t\}$ and wish to fit an $ARMA(p,q)$ to it, we
must first identify the order of the model, that is, what $p$ and $q$ should
be. We discuss a methodology presented by Box and Jenkins that depends on the
autocorrelations and partial-autocorrelations of the data. Alternative methods
exist, such as using the Akaike information criterion with a correction (AICc).

\subsection*{Autocorrelation}

The autocorrelation between between $z_{t}, z_{t+k}$ is defined as the
normalized covariance between the two random variables, verbosely given as
\begin{align}
    \label{eq:arma:autocorrelation}
    \text{cor}[z_{t}, z_{t+k}] = \frac{E[(z_{t} - E[z_{t}])(z_{t+k} -
    E[z_{t+k}])]}{\sqrt{E[(z_{t} - E[z_{t}])^2(z_{t+k} - E[z_{t+k}])^2]}}
\end{align}
Since the $\{z_t\}$ is assumed to be covariance-stationary,
\ref{eq:arma:autocorrelation} depends only on the lag $k$, not on $t$. This
justifies the notation
\begin{align}
    \rho_k = \text{cor}[z_{t}, z_{t+k}] \quad \forall t
\end{align}
When $\rho_k$ is considered a function of $k$, it is called the autocorrelation
function. Since $\rho_0 = 1, \rho_{-k} = \rho_k$, we will be interested in the
cases when $k > 0$. We can estimate $\rho_k$ from sample data as
\begin{align}
    \label{eq:arma:autocorrelation_estimate}
    \hat{\rho}_k = \frac{\sum_{t=1}^{N-k}(z_t - \hat{\mu})(z_{t+k} -
    \hat{\mu})}{\sum_{t=1}^{N}(z_t - \hat{\mu})^2}
\end{align}
where $\hat{\mu}$ is the sample mean. This is one of a number of estimates of
autocorrelation.

\begin{problem}
\label{prob:arma:autocorrelation}
Write a function that computes the autocorrelation estimate described in
\ref{eq:arma:autocorrelation_estimate}, given a time series and a lag $k$.
Plot $\hat{\rho}_k$ for $1 \leq k \leq 20$ for each of the three data sets.
\end{problem}

\subsection*{Partial-Autocorrelation}

\end{comment}


\documentclass[../PHYS306Notes.tex]{subfiles}

\begin{document}
\section{Lecture 3}
\subsection{Lecture Notes - Lagrangian Mechanics Part 3}
\subsubsection{Review of Variations}
Recall \textbf{Hamilton's Principle}, where we consider a trajectory between $t_1$, $t_2$, and variations from that trajectory $\eta(t)$. The true trajectory taken by the physical system is given by $\bar{q}(t)$. We parameterize the variations with an $\alpha$ term, where $q(t) = \bar{q}(t) + \alpha\eta(t)$. $\bar{q}(t)$ minimizes the action functional $S[q]$ if $S[\bar{q}] < S[q]$ for any other trajectories $q$. Our functional $S[q]$ is given by:
\[S[q] = \int_{t_1}^{t_2}
L(q, \dot{q}, t)dt\]
We found a method to find $\bar{q}$ by taking the derivative of the action (i.e. a stationary point):
\[\left. \dod{S[\bar{q} + \alpha \eta]}{\alpha}\right|_{\alpha = 0} = 0\]
or alternatively, the statement that the (first order) variation must vanish:
\[\delta S[\bar{q}] = \lim_{\alpha \rightarrow 0} \frac{1}{\alpha}\left(S[\bar{q} + \alpha\eta] - S[\bar{q}]\right) = 0\]
We will explore this more on Monday when we look at constraint forces.

\subsubsection{Invariance, The Functional Derivative, and Multiple Variables}
\begin{enumerate}
    \item Form invariance of Euler-Lagrange equations. Going from generalized coordinates $q \rightarrow \tilde{q}$, then we have that:
    \[\LL(\tilde{q}, \dot{\tilde{q}}, t) = \LL(q, \dot{q}, t)\]
    by the definition of the Lagrangian. Alternatively, see that the action is invariant of the choice of general coordinates:
    \[\tilde{S}[\tilde{q}] = \int_{t_{1}}^{t_2} \tilde{\LL}\left(\tilde{q}, \dot{\tilde{q}}, t\right) d t=\int_{t_{1}}^{t_2} \mathcal{L}(q, \dot{q}, t) d t=S[q]\]
    \item One can take a functional derivative and set this to zero. The variation can be written using a functional derivative (indicated by lowercase $\delta$):
    \[\delta S[q] = \int \frac{\delta S}{\delta q} \eta(t) dt\]
    What is the definition of the functional derivative? It's very similar to the conventional derivative:
    \[\frac{\delta S}{\delta q(t)} = \lim_{\alpha = 0} \frac{S[q + \alpha \delta(t)] - S[q]}{\alpha} = \dpd{\LL}{q} - \dod{}{t}\dpd{\LL}{\dot{q}}\]
    Therefore, $\frac{\delta S}{\delta q} = 0$ implies the Euler Lagrange equations. The way you can think about it is like the partial derivative. We are familiar with the total differential of a function (the sum of the partial differentials, see HW1 as an example). Now, imagine we have a function that depends continuously on a function $q$; its like a partial derivative with an index that is continuous (rather than discrete).
    \item If we have multiple variables, the generalization is straightforwards; for $n$ variables, the action functional becomes:
    \[S = \int_{t_1}^{t_2}\LL(q_1, q_2, \cdots, q_n, \dot{q}_1, \dot{q}_2, \cdots, \dot{q}_n, t)dt\]
    So we would get $n$ Euler-Lagrange equations:
    \[\dpd{\LL}{q_i} = \dod{}{t}\dpd{\LL}{\dot{q}_i}\]
    Where $\dpd{\LL}{q_i}$ is  the generalized force, and $\dpd{\LL}{\dot{q}_i}$ is the generalized momentum.
\end{enumerate}

\subsubsection{Torque, Angular Momentum, and Generalized Momentum Conservation}
See derivation in Worksheet three for the relation:
\[\dpd{\LL}{\phi} = \dod{}{t}\dpd{\LL}{\dot{\phi}}\]
Which corresponds to:
\[\Gamma = \dod{L}{t}\]
So if there is zero torque, we have conservation of angular momentum. Generally, if $\LL$ is independent of $q_i$, then the generalized momentum $\pd{\LL}{\dot{q}_i}$ is conserved. We have a conservation law that comes from a certain property in the Lagrangian. We call variables that do not appear in the Lagrangian as a "cyclic" or "ignorable" variable.
\end{document}


\section{Searching}

%%%%%%%%%%%%%%%%%%%%
\begin{frame}{$\max/\min$ differences (Problem 4.5)}
  \begin{enumerate}[(a)]
	\item unsorted; $\max |x - y|$; $O(n)$
	\item sorted; $\max |x - y|$; $O(1)$
	\item unsorted; $\min |x - y|$; $O(n \log n)$
	\item sorted; $\min |x - y|$; $O(n)$
  \end{enumerate}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Searching in matrix (Problem 4.6)}
  \begin{itemize}
	\item $M$: matrix $m \times n$
	\item row: increasing from left to right
	\item col: increasing from top to down
	\item Is $x \in M$?
  \end{itemize}

  \pause
  \centerline{Divide and conquer.}

  \pause
  \[
	T(m,n) = 3T(\frac{m}{2}, \frac{n}{2}) + 1
  \]

  % \pause
  % \[
  %   m = n \implies T(n) = 3T(\frac{n}{2}) + 1 \pause \implies T(n) = \Theta(n^{\log_{2}3})
  % \]

  \pause
  \centerline{Always checking the lower left corner.}

  \pause
  \[
	T(m, n) = m + n - 1
  \]
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Searching in matrix (Problem 4.6)}
  \[
	\text{Assume } M: n \times n
  \]

  \[
	W(n) \le 2n - 1
  \]

  \pause
  \vspace{0.30cm}
  \centerline{$W(n) \ge 2n - 1$ by adversary argument!}

  \pause
  \begin{align*}
	i + j \le n - 1 &\implies x > M_{ij} \\
	i + j > n - 1 &\implies x < M_{ij} \\
  \end{align*}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Local minimum (Problem 4.11)}
  \begin{itemize}
	\item Array $A[0 \ldots n-1]$
	\item Boundary conditions:
	  \begin{align*}
		A[0] &\ge A[1] \\
		A[n-2] &\le A[n-1]
	  \end{align*}
	\item Local minimum $A[i]$:
	  \[
		A[i-1] \ge A[i] \le A[i+1]
	  \]
	\item Goal: Find \emph{any} local minimum.
  \end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Local minimum (Problem 4.11)}
  \begin{enumerate}
	\item Checking each element:
	  \[
		T(n) = O(n)
	  \]
	\item $\min A$:
	  \[
		T(n) = O(n)
	  \]
	\pause
	\item Required:
	  \[
		T(n) = O(\log n)
	  \]

	  \pause
	  \[
		T(n) = T(\frac{n}{2}) + 1
	  \]
  \end{enumerate}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Local minimum (Problem 4.11)}
  2D local minimum:
  \begin{itemize}
	\item Matrix $M: n \times n$
	\item Boundary conditions:
	  \[
		\infty
	  \]
	\item Local minimum $A[i,j]$:
	  \begin{align*}
		A[i,j-1] &\ge A[i,j] \le A[i,j+1] \\
		A[i-1,j] &\ge A[i,j] \le A[i+1,j]
	  \end{align*}
	\item Goal: Find \emph{any} local minimum.
  \end{itemize}

  \pause
  \[
	O(n^2) \pause \implies O(n \log n) \pause \implies O(n) \implies \textcolor{red}{O(\log n)}
  \]
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{$a_i = i$ (Problem 4.2)}
  \begin{itemize}
	\item Sorted integer sequence $\set{a_1, a_2, \ldots, a_n}$:
	  \[
		\forall i \neq j: a_i \neq a_j
	  \]
	\item Goal:
	  \[
		\exists? i: a_i = i
	  \]
  \end{itemize}

  \pause
  \[
	T(n) = O(n)
  \]

  \pause
  \[
	T(n) = T(\frac{n}{2}) + 1 = O(\log n)
  \]
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Smallest missing positive integer (Problem 4.3)}
  \begin{itemize}
	\item Sorted array $A[1 \ldots n]$:
	  \begin{gather*}
		a_i \in \mathbb{Z}^{+} \\
		\forall i \neq j: a_i \neq a_j
	  \end{gather*}
	\item Goal: Find the smallest missing positive integer.
  \end{itemize}

  \pause
  \[
	T(n) = O(n)
  \]

  \pause
  \[
	T(n) = T(\frac{n}{2}) + 1 = O(\log n)
  \]
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Computing $\lceil \sqrt{N} \rceil$ (Problem 4.12)}
  \begin{itemize}
	\item Given an $n$-bit natural number $N$ ($0 \le N < 2^{n} - 1$)
	\item Goal: Compute $\lceil \sqrt{N} \rceil$ using $O(n)$ additions and shifts.
  \end{itemize}

  \vspace{0.30cm}
  \begin{columns}
    \column{0.55\textwidth}
	  \pause
	  \begin{block}{Elementrary operations:}
	    \begin{itemize}
	      \item $n$-bit + $n$-bit: $O(1)$
	      \item $n$-bit shifted by $1$-bit: $O(1)$
	      \item $\Rightarrow x^2: O(n)$
	    \end{itemize}
	  \end{block}
	\column{0.45\textwidth}
	  \pause
	  \begin{enumerate}[<+->]
	    \item Na{\"i}ve search: $O(2^{n} \cdot n)$
	    \item Binary search: $O(n \cdot n)$
	    \item Binary search in range:
		  \[
			2^{\lfloor \frac{n-1}{2} \rfloor} \le \lceil \sqrt{N} \rceil \le 2^{\lceil \frac{n}{2} \rceil}
		  \]
		  \[
			\lg{(2^{\lceil \frac{n}{2} \rceil} - 2^{\lfloor \frac{n-1}{2} \rfloor})} = O(n)
		  \]
		  \[ O(n \cdot n) \]
	  \end{enumerate}
  \end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Computing $\lceil \sqrt{N} \rceil$ (Problem 4.12)}
  \begin{block}{A Little History:}
    \begin{description}
	  \item[$2007$:] Mid-term problem \\
		\centerline{$O(n)$ required; NO $O(n)$ solutions, however}
	  \item[$\sim 2013$:] $O(n^2)$
	  \pause
	  \item[$2014$:] $O(n)$
		\fignocaption{width = 0.80\textwidth}{figs/square-root-cs-se.png}
    \end{description}
  \end{block}

  \pause
  \[
	x^2: O(n) \to O(1)
  \]
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Computing $\lceil \sqrt{N} \rceil$ (Problem 4.12)}
  Given
  \[
	M = \lfloor N/4 \rfloor
  \]

  \[
	x = \lceil \sqrt{M} \rceil \textrm{ and } (x, x^2),
  \]

  what is
  \[
    y = \lceil \sqrt{N} \rceil \textrm{ and } (y, y^2)?
  \]

  \pause
  \begin{exampleblock}{An Example:}
  \[
	\begin{array}{lll}
	  N = 280 & y = \lceil \sqrt{280} \rceil = 17 & y^2 = 289 \\ \pause
	  M = \lfloor 280/4 \rfloor = 70 & x = \lceil \sqrt{70} \rceil = 9 & x^2 = 81 \\ \pause
	  M = \lfloor 70/4 \rfloor = 17 & x = \lceil \sqrt{17} \rceil = 5 & x^2 = 25 \\
	  M = \lfloor 17/4 \rfloor = 4 & x = \lceil \sqrt{4} \rceil = 2 & x^2 = 4 \\
	  M = \lfloor 4/4 \rfloor = 1 & x = \lceil \sqrt{1} \rceil = 1 & x^2 = 1
	\end{array}
  \]
  \end{exampleblock}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Computing $\lceil \sqrt{N} \rceil$ (Problem 4.12)}
  \begin{algorithm}[H]
    \caption{Computing $\lceil \sqrt{N} \rceil$.}
    \begin{algorithmic}[]
      \Procedure{Sqrt-Root}{$N$}
	    \If{$N < 3$}
	      \State \Return $1 \Rightarrow (1,1); 2 \Rightarrow (2,4); 3 \Rightarrow (2,4)$
	    \EndIf
	    \State $M \gets \lfloor N/4 \rfloor$
	    \State $(x, x^2) \gets \textsc{Sqrt-Root}{(M)}$
		\State \Return the $(y, y^2)$ with $y^2 \sim N$:
           \[
			(y, y^2) = \left\{ \begin{array}{ll}
			y = 2x & y^2 = 4x^2 \\
			y = 2x + 1 & y^2 = 4x^2 + 4x + 1 \\
			y = 2x - 1 & y^2 = 4x^2 - 4x + 1
			\end{array} \right.
	      \]
	  \EndProcedure
    \end{algorithmic}
  \end{algorithm}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Computing $\lceil \sqrt{N} \rceil$}
  \[ \xout{T(n) = T(n/4) + O(1) = \Theta(\lg n)} \]

  \[ T(n) = T(n - 2) + O(1) = \Theta(n) \]
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Space for hashing (Problem 4.4)}
  \begin{description}
	\item[Key:] $x$
	\item[Node:] $y$
	\item[Load factor:] $\alpha$
  \end{description}

  \pause
  \begin{itemize}
	\item Closed-address hashing
	  \[
		h_c + \alpha y h_c
	  \]
	\item Open-address hashing
	  \[
		\frac{\alpha h_c}{\frac{h_c + \alpha y h_c }{x}} = \frac{\alpha x}{1 + \alpha y}
	  \]
  \end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%
\begin{frame}[noframenumbering]
  \fignocaption{width = 0.50\textwidth}{figs/thankyou.jpg}
\end{frame}
%%%%%%%%%%%%%%%%%%%%


\chapter{GPS}

Suppose that the Earth is a spheroid
\begin{equation}
  \label{eq:spheroid}
  \frac{x^2}{a^2} + \frac{y^2}{a^2} + \frac{z^2}{b^2} = 1, \quad a
  \geq b > 0,
\end{equation}
with its centre of symmetry in the origin of the Cartesian coordinate
system and axes overlapping axes of coordinate system.

Let $P$ be a point on the ellipsoid~\eqref{eq:spheroid}. Define
geographical coordinates: latitude and longitude as follows. Latitude
of $P$ is the angle between the normal to the ellipsoid at the point
$P$ and the plane $z = 0$ (see figure \ref{fig:spheroid_coordinates}).
Longitude of $P$ is the angle between the plane $y = 0$ and the plane
perpendicular to the plane $z = 0$ passing through the point $P$ and
the origin of the coordinate system.

\begin{figure}[ht]
\begin{center}
\resizebox{6cm}{!}{\includegraphics{1.pdf}}
\end{center}
\caption{Cartesian and geographic coordinates on the spheroid.}
\label{fig:spheroid_coordinates}
\end{figure}

Denote latitude by $-\frac{\pi}{2} \leq \varphi \leq \frac{\pi}{2}$,
longitude by $-\pi \leq \lambda \leq \pi$. The $X$ axis passes through
the point $(a, 0, 0)$ with latitude $0^\circ$ and longitude $0^\circ$
($\varphi = 0, \lambda = 0$), the $Y$ axis passes through the point
$(0, a, 0)$ with latitude $0^\circ$ and longitude $90^\circ$ east
($\varphi = 0, \lambda = \frac{\pi}{2}$) and the $Z$ axis passes
through the north pole $(0, 0, b)$ with latitude $90^\circ$ north
($\varphi = \frac{\pi}{2}, -\pi \leq \lambda \leq \pi$).

\section{Conversion of coordinates}

Let $P$ be a point on the ellipsoid~\eqref{eq:spheroid} with latitude
$0 < |\varphi| < \frac{\pi}{2}$ and longitude $-\pi \leq \lambda \leq
\pi$. We are looking for its coordinates $(x, y, z)$. As the
$Z$-coordinate depends only on $\varphi$, take a point $P'$ with
latitude $\varphi$ and longitude $0$, lying on the plane $y = 0$ (see
figure \ref{fig:plane_y_0}). The line passing through $P'$ and
inclined to the $x$-axis at the angle $\varphi$ is a normal to the
ellipse
\begin{equation} \label{eq:ellipseXZ}
  \frac{x^2}{a^2} + \frac{z^2}{b^2} = 1
\end{equation}
at a point $(x_0, z_0)$ and intersects the $x$-axis at the point
$(x_1, 0)$.

\begin{figure}[ht]
\begin{center}
\resizebox{6cm}{!}{\includegraphics{2.pdf}}
\end{center}
\caption{Position of the point $P'$ on the plane $y = 0$.}
\label{fig:plane_y_0}
\end{figure}

\noindent Hence it follows that
\begin{equation} \label{eq:first_eq_for_z}
  \tg \varphi = \frac{z_0}{x_0 - x_1}.
\end{equation}
This normal has the equation
\[
z_0x - (x_0 - x_1)z - z_0x_1 = 0.
\]
On the other hand, a normal to the ellipse \eqref{eq:ellipseXZ} at its
point $(x_0, z_0)$ has the equation \cite [pp.~215,~244]
{bronsztejn-siemiendiajew-musiol-muhlig-2004}
\[
a^2z_0x - b^2x_0z - (a^2 - b^2)x_0z_0 = 0.
\]
These two lines must overlap, so there must be
\[
\frac{z_0}{a^2z_0} = \frac{x_0 - x_1}{b^2x_0} = \frac{z_0x_1}{(a^2 -
  b^2)x_0z_0}
\]
and
\begin{equation} \label{eq:x1}
  x_0 - x_1 = \frac{b^2}{a^2}x_0, \quad x_1 = \frac{a^2 -
    b^2}{a^2}x_0.
\end{equation}
From \eqref{eq:ellipseXZ} we have
\begin{equation} \label{eq:x0_from_XZ}
  x_0 = \frac{a}{b}\sqrt{b^2 - z_0^2}.
\end{equation}
Using \eqref{eq:x1} and \eqref{eq:x0_from_XZ} in
\eqref{eq:first_eq_for_z} we obtain
\[
z_0 = p \frac{\sin \varphi}{\sqrt{1 - e^2\sin^2 \varphi}},
\]
where $p = b^2 / a$ \cite [p.~214]
{bronsztejn-siemiendiajew-musiol-muhlig-2004} and
\[
e = \frac{\sqrt{a^2 - b^2}}{a}
\]
is the eccentricity of the ellipse~\eqref{eq:ellipseXZ} \cite [p.~214]
{bronsztejn-siemiendiajew-musiol-muhlig-2004}.
From~\eqref{eq:x0_from_XZ} we obtain
\[
x_0 = a \frac{\cos \varphi}{\sqrt{1 - e^2\sin^2 \varphi}}.
\]
$X$ and $Y$ coordinates can be calculated from the parametric equation
of the circle $x^2 + y^2 = x_0^2$ for the angle $\lambda$: $x = x_0
\cos \lambda$, $y = x_0 \sin \lambda$.

The complete coordinates are
\begin{align*}
  x &= a \frac{\cos \varphi}{\sqrt{1 - e^2\sin^2 \varphi}} \cos \lambda \\
  y &= a \frac{\cos \varphi}{\sqrt{1 - e^2\sin^2 \varphi}} \sin \lambda \\
  z &= p \frac{\sin \varphi}{\sqrt{1 - e^2\sin^2 \varphi}}
\end{align*}
These formulas are valid also for $\varphi = 0$ and $\varphi = \pm
\frac{\pi}{2}$.

If a point lies on the normal with distance $h$ from the surface of
the ellipsoid, then the corresponding values of $z_0$ and $x_0$ should
be increased by $h \sin \varphi$ and $h \cos \varphi$, respectively.
Therefore, if a point is specified by coordinates $(\varphi, \lambda,
h)$, corresponding Cartesian coordinates are
\begin{align}
  \label{eq:x_coord}
  x &= \left( \frac{a}{\sqrt{1 - e^2\sin^2 \varphi}} + h \right) \cos
  \varphi \cos \lambda \\
  \label{eq:y_coord}
  y &= \left( \frac{a}{\sqrt{1 - e^2\sin^2 \varphi}} + h \right) \cos
  \varphi \sin \lambda \\
  \label{eq:z_coord}
  z &= \left( \frac{p}{\sqrt{1 - e^2\sin^2 \varphi}} + h \right) \sin
  \varphi
\end{align}

\section{Parameters of the spheroid}

We specify the spheroid of the Earth by two parameters\footnote{See
  \url{https://en.wikipedia.org/wiki/World_Geodetic_System}.}:
semi-major axis $a = 6378137.0$ metres and inverse flattening $1 / f =
298.257223563$, where $f = (a - b) / a$.


\chapter*{\uppercase{Abbreviations and Notation} \label{appendix-notation}}

\section{Abbreviations}

\begin{description}[leftmargin=!,labelwidth=0.5in,font=\normalfont]
	\item
\end{description}

\section{Mathematical Notation}
\begin{description}[leftmargin=!,labelwidth=0.5in,font=\normalfont]
	\item
\end{description}

\subsection{General Notation}

% EDIT BELOW AND REMOVE WHAT YOU DO NOT NEED
\begin{description}[leftmargin=!, labelwidth=0.7in]
  \item[$x$]             italicized, Roman or Greek letter, denotes scalar values
  \item[$\bs{x}$]        italicized, bold, lowercase Roman or Greek letter, denotes a column vector
  \item[$\bs{X}$]        italicized, bold, uppercase Roman or Greek letter, denotes a matrix
	\item[$\bs{X}_{ij}$] 	 denotes the component of matrix $\bs{X}$ occupying row $i$ and column $j$

  \item[$x \in (a, b)$]  the value $x$ is within the interval such that $a < x < b$
  \item[{$x \in (a, b]$}]  the value $x$ is within the interval such that $a < x \leq b$
  \item[$x \in [a, b)$]  the value $x$ is within the interval such that $a \leq x < b$
  \item[{$x \in [a, b]$}]  the value $x$ is within the interval such that $a \leq x \leq b$
  \item[$1_{A}\left(x\right)$] the indicator function,\[1_{A}\left(x \right) = \begin{cases} 1 & x \in A \\ 0 & x \notin A \end{cases}.\]
  \item[$\bs{1}_n$] an column vector of $n$ $1$s
  \item[$\bs{I}$] the identity matrix
  \item[$\bs{I}_n$] the $n \times n$ identity matrix
  \item[$\bs{X}^{-1}$] the inverse matrix, i.e., the operator satisfying $\bs{X}^{-1} \bs{X} = \bs{X} \bs{X}^{-1} = \bs{I}.$
  \item[$\bs{X}^{\top{T}}$] transpose, i.e. the operator satisfying $X_{i,j} = X_{j, i} \; \forall \; i,j \in \mathbb{N}$
  \item[$\otimes$] Kronecker product
  \item[$\odot$] element-wise multiplication
\end{description}

\subsection{Sets}

\begin{description}[leftmargin=!, labelwidth=0.8in]
  \item[$\set{x, y, z, \ldots}$]  the set comprising the elements of $x,$ $y,$ $z,$ $\ldots$
  \item[$\set{x, y, z} \backslash x$]  the set comprising the elements of $y$ and $z$\footnote{In other words, the backslash removes an element (or a subset) from the original set.}
  \item[$\sett{x_i}{i = 1}{n}$]  the set comprising the elements of $x_1, x_2, x_3, \ldots, x_n$
  \item[$\RR$] set of real numbers
	\item[$\NN$] set of natural numbers
  \item[$\bs{x} \in \mathbb{R}^n$] $\bs{x}$ is a vector with $n$ elements, all of which are real numbers
\end{description}

\subsection{Statistical Distributions}
\begin{description}[leftmargin=!, labelwidth=0.8in]
  \item[$\mathcal{N} \left( \mu, \sigma^2 \right)$] the uni-variable Gaussian distribution with mean $\mu$ and variance $\sigma^2$
  \item[$\mathcal{N} \left( \bs{\mu}, \bs{\Sigma} \right)$] the multi-variable Gaussian distribution with mean vector $\bs{\mu}$ and variance-covariance matrix $\bs{\Sigma}$
  \item[$\phi(x)$] the standard Gaussian density function
\end{description}

\subsection{Specialized Notation}
This notation refers to values defined explicitly in the context of this thesis.

\begin{itemize}
\itembox{$\M$} a model that takes input parameters to an (observable) state space
\itembox{$u$} an observable state space from which data is to be collected
\itembox{$\param$} a (model) parameter into model $\M$
\itembox{$\obs$} a Parameter-to-Observables (PtO) map, also denoted $\obs( u\lam )$ or $\obs\lam$, each component of which is a functional  $\obs_i: u\lam \to \RR$ on the observable state\footnote{This map represents performing an individual experiment, which may consist of one or more observations (either in space or time). Arranging observational data into a vector defines the map.}
\itembox{$\qoi$} a Quantity of Interest (QoI) map, also denoted $\qlam$, which acts on observable data to transform the data into a scalar or vector quantity\footnote{For example, it may be the average of measurements encompassed in $\obs$. Technically, this map encompasses the following set of compositions: $Q(\obs(u\lam))$.}
\itembox{$\data$} data representing an individual output of a (possibly vector-valued) QoI map for a particular parameter $\param$, i.e. $\qlam = \data$
\end{itemize}

[TK - add Measure-Theory notation into this section, based on what you have in your newcommands.tex file]


\section{Queueing Theory}
\label{sec:Queueing-Theory}

The queueing theory is built on the stochastic modeling and analysis, which represents service demands and interarrivals as random variables.
It is the theory behind what makes queues appear and how to make them go away.
It is the study of queueing behavior in systems and networks.

Queueing theory applies anywhere that queues come up. It is also at the heart of any computer system.

Queueing theory has its origins in research by Agner Krarup Erlang when he created models to describe the Copenhagen telephone exchange.

Queues results from variability in service time and/or interarrival time distribution.

A major reason why computer scientists are so slow to adopt queueing theory is that standard assumptions often do not fit. In some cases they are very far from reality: for example, in the case of high variability and correlations. However there are often ways to work around these assumptions.

The goals of a queueing theorist is \textit{predicting} the system performance and \textit{designing} it to improve performance.

There are many questions in computer systems design that lend themselves to a queueing-theoretic solution (e.g., power management, priority scheduling, and so on).
However, there are  lots of problems that we can at best only analyze approximately (e.g., mean response time for M/G/k queue). Typically, approximations are very poor when jobs size variability gets high \cite{gupta2010inapproximability}.

\subsection{Queue Metrics}
\label{sec:Queue-Metrics}

A queue node is described by the following parameters and performance metrics:

\begin{description}
	\item [Service Order] The scheduling discipline.

	\item [Average Arrival Rate]  ($\lambda$) The rate at which jobs arrive to the node.

	\item [Interarrival Time] ($\tau$) The time between successive job arrivals.

	\item [Mean Interarrival Time] ($\expected{\tau}=\frac{1}{\lambda}$) The average time between successive job arrivals.

	\item [Service Requirement, Size] ($S$) The time taken by a job to run on server.

	\item [Average Service Rate] ($\mu$) The rate at which jobs are served by the server.

	\item [Mean Service Time] ($\expected{S}=\frac{1}{\mu}$) The average time required to serve a job.

	\item [Waiting Time, Delay] ($T_{Q}$) The time that the job spends in the queue.

	\item [Response Time, Turnaround Time] ($T$) The time during which the job is in the node. Thus $T=T_{departure}-T_{arrival}$. Note that $\expected{T}=\expected{T_{Q}}+\expected{S}$.

	\item [Number of System Jobs] ($N$) The number of jobs in the queue plus the ones being served.

	\item [Number of Queued Jobs] ($N_{Q}$) The number of jobs in the queue.

	\item [Utilization] ($\varrho$) The fraction of time the server is busy, the probability of the server to be busy, the mean number of jobs in that node.

	\item [Throughput] ($X$) The rate of completions at server.
\end{description}

\subsection{Kendall notation}
A queue node il classified using the Kendall notation \cite{kendall1953stochastic}.

\begin{equation}
A/S/m/c/N/D
\end{equation}

where

\begin{description}
	\item [A] the arrival process, the value indicates the probability distribution of inter-arrival times.

	\item [S] the service process, the value indicates the probability distribution of service times.

	\item [A] the number of servers.

	\item [c] the capacity of the system (that is, the number of servers plus the buffer size).

	\item [N] the size of the population, that is the total number of jobs.

	\item [D] the scheduling discipline.
\end{description}

The arrival process \textit{A} and service process \textit{S} could be equal to

\begin{description}
	\item [$M$] Exponential distribution.

	\item [$D$] Deterministic distribution.

	\item [$E_{n}$] Erlang distribution of order $n$.

	\item [$H_{n}$] Hyper-exponential distribution of order $n$.

	\item [$G$] Generic distribution of independent variables.
\end{description}

The scheduling discipline \textit{D} could be equal to

\begin{description}
	\item [$FCFS (FIFO)$] first come, first served.

	\item [$LCFS (LIFO)$] last come, first served.

	\item [$RO$] random order.

	\item [$RR$] round robin.

	\item [$PS$] processor sharing.

	\item [$P$] custom priority.
\end{description}

When the final three parameters are not specified (e.g. M/M/1 queue), it is assumed $K=\infty$, $N=\infty$ and $D=FIFO$.

\subsection{Classification of Queueing Networks}
\label{sec:Classification-Queueing-Networks}

Queueing networks can be classified into two categories:

\begin{description}
	\item [Open Networks] They have external arrivals and departures. In such systems, $X=\lambda$

	\item [Closed Networks] They have no external arrivals or departures. In such systems, $X=\mu$. The number of jobs in the system is fixed to $N$, and it is called \textit{load} or \textit{multiprogramming level (MPL)}. $\expected{T}=\expected{T_{R}}+\expected{Z}$. Closed networks can be classified in two categories:

	\begin{description}
		\item [Interactive Networks] There are $N$ \textit{terminals} which submit jobs to a network of queues, called \textit{central subsystem}. After submission, a terminal waits for job completion, then sleeps for a think-time $Z$, then can submit again. Thus, a terminal oscillates between a submission-state and a think-state. The goal is to limit the rise of $\expected{T_{R}}$ with $N$.

		\item [Batch Networks] They are interactive networks with no think-time ($Z=0$). The goal is to obtain high throughput.
	\end{description}

\end{description}

%\begin{figure}[tp]
%\label{fig:Open-Network-Sample}
%	\centering
%	\includegraphics{fig/Open-Network-Sample}
%	\caption{An Open network.}
%\end{figure}

%\begin{figure}[tp]
%\label{fig:Interactive-Network-Sample}
%	\centering
%	\includegraphics{fig/Interactive-Network-Sample}
%	\caption{An Interactive network.}
%\end{figure}

%\begin{figure}[tp]
%\label{fig:Batch-Network-Sample}
%	\centering
%	\includegraphics{fig/Batch-Network-Sample}
%		\caption{A Batch network.}
%\end{figure}

\cite{schroeder2006open} proposed the notion of \textit{partly-open networks}. Here terminals arrive from outside as in open networks, but make request as in closed ones.

\subsection{Utilization}
\label{sec:Utilization}

The utilization of a queue node is the fraction of time the node is busy, the probability that it is busy, and the mean number of jobs in that node.

\begin{theorem}[Utilization Law]
\label{thm:Utilization-Law}

	For every stable queue node, we have that:

	\begin{equation}
	\label{eqn:Utilization-Law}
	\varrho = \frac{\lambda}{\mu} = X \cdot \mathbf{E}[S]
	\end{equation}

	\begin{proof}
		Let us consider the definition of throughput ($X=\frac{C}{\tau}$) and utilization ($\varrho=\frac{B}{\tau}$). We have that

		\begin{equation*}
			X = \frac{C}{\tau} = \frac{C}{B} \cdot \frac{B}{\tau} = \frac{C}{B} \cdot \varrho
		\end{equation*}

		Since $\frac{B}{C}=\expected{S}$ and $\frac{C}{B}=\mu$, we have that

		\begin{equation*}
			X = \mu \cdot \varrho \equiv \frac{\varrho}{\expected{S}} \Rightarrow \varrho = X \cdot \expected{S}
		\end{equation*}
	\end{proof}
\end{theorem}

\subsection{Stability}
\label{sec:Stability}

The stability condition guarantees that the queue cannot grow unbounded.

\begin{theorem}
\label{thm:Stability}
	A queue node is stable if and only if \footnote{The condition is necessary, but there are more complex networks (not examined here) where it is not sufficient \cite{bramson2008stability}.}

	\begin{equation}
	\label{eqn:Stability}
	\lambda < \mu
	\end{equation}

	\begin{proof}
		Let's prove that if $\lambda > \mu$ then the queue would grow to infinity over time.
		Given a time $t$, the number of system jobs $N(t)$, the number of arriving jobs $A(t)$ and the number of departing jobs $D(t)$, we have that

		\begin{equation*}
		\expected{N(t)}=\expected{A(t)}-\expected{D(t)} \geq t(\lambda - \mu)
		\end{equation*}

		where the inequality holds because the server is not always busy, then the departures at time $t$ are less than $\mu t$.
		At the end, we have that

		\begin{equation*}
		\lambda > \mu \Rightarrow \lim_{t \to \infty} \expected{N(t)} = \infty
		\end{equation*}
	\end{proof}
\end{theorem}


\section{Numerical Solution for Burgers' Equation}
	Let $\mathcal{H} = L^2 (0, 1)$. Let's consider an initial value problem for (\ref{burgers_stochastic}) as follows
	\begin{align}
	\label{burgers_stochastic2}
	d X(\xi, t) = \left[\alpha \partial_{\xi}^2 X(\xi, t) + \frac{1}{2} \partial_\xi \left(X^2 (\xi, t)\right) \right] dt + dW_t (\xi, t), \hspace{0.2cm} \xi \in [0, 1]
	\end{align}
	The boundary condition and its initial condition are respectively
	\begin{align*}
	%\label{IC_burgers_stochastic2}
	X(0, t) &= X(1, t) = 0 , \hspace{0.2cm} t > 0 \\
	X(\xi, 0) &= x(\xi), \hspace{0.2cm}  x \in \mathcal{H},
	\end{align*}
	where $W$ is a cylindrical Wiener process on $\mathcal{H}$ as was given by \ref{cylindrical}, associated to a stochastic basis $(\Omega, \mathcal{F}, \mathbb{P}, \{\mathcal{F}_t\}_{t \geq 0})$, and as usually $\alpha > 0$ is the viscosity coefficient. \\

	Using the above problem, we will proceed to develop the implementation of the method described in the previous section.

	\input{burgers_equation/stochastic/numerical_experiments/Implementation}
	\input{burgers_equation/stochastic/numerical_experiments/Initial_Condition}
	\input{burgers_equation/stochastic/numerical_experiments/Numerical_Experiments}


\section{Approach}
The user-based collaborative filtering \cite{Schafer2007} approach was selected to make movie recommendation for a set of users. This meant that recommendations for an individual user would be based on what similar users have liked that the current user have not yet rated/seen. This is based on the theory that users with similar taste are likely to provide good recommendations to each other. The key here lies in how is similarity between users determined, in this instance the Pearson correlation coefficient measurement \cite{Wikipedia2017} was selected as the primary method to evaluate similarity, it measures similarity of users by making a linear correlation between what user x and y have rated in terms the score they applied to a set that contains the intersection of movies rated by x and y. The inspiration for this approach was drawn from \cite{Lead} where this was applied in conjunction with a weighted similarity score that makes sure that users you agree most with are rated higher in terms of movie recommendations.

This technology was selected based on multiple factors. This included the suggestions made by \cite{Burke2011} about movie recommendation systems and their domain features including the low risk value of the recommendation, the homogeneous nature of the system and the stability in terms of preference that users have in terms of how much can you rely on previous received information e.g. user's rating history to make future predictions. In terms of technology variation, collaborative filtering provides multiple approaches, e.g. user-based or item based filtering \cite{Yao}. Both of these have merits, the user-based approach increases in computational cost as the number of users increases. The item based however grows whenever new items are added. In this instance the number of users/items is stable since it is not a live system a choice was made to use the user based approach since the dataset contains 671 users and 9125 movies.

\section{Required Knowledge}

The knowledge required for this approach to work include user histories of movie ratings from which user similarity can be based upon. To achieve this a number of public available datasets containing user movie ratings were evaluated. This included the Netflix Prize dataset \cite{bennett0netflix} , the IMDb academic dataset \cite{IMDb2017} and the MovieLens \cite{Harper2015} dataset. From these the MovieLens 100K dataset was chosen as being the most appropriate. The reason for this was that the original Netflix dataset only contained data about when a user rated a movie and not how it was rated. The reason for this was that it was the task for the algorithm to predict the number of reviews and not the actual rating a movie would receive in 2006.  Similar to this the IMDb dataset contained rating of movie's but they weren't tied to any users, meaning that user-based collaborative filtering wasn't feasible. The MovieLens dataset on the other hand doesn't have any of these missing features, meaning that it contained users which had committed at least 20 ratings with a value between 1.0 and 5.0 to different movies. Because of this the MovieLens dataset was selected as the most appropriate to develop this movie recommendation system.

However it was discovered later in the process that there has been developed an altered version of the Netflix dataset which provides actual ratings of movies \cite{Netflix2009}, this was discovered after the MovieLens dataset had been applied.

\section{Algorithm}
	The pseudo code for the similarity and recommendation functions can be seen in Algorithm \ref{alg:simpearsons} and \ref{alg:recommendations}. The similarity function uses Pearson correlation coefficient to determine user similarity on a shared set of movies. The similarity is calculated by basically drawing a line through the rating values of the shared movies. If two users agree on the rating of their shared set of movies the result would be a positive correlation between them, meaning that they are expected to have similar taste. After the similarity has been calculated the recommendation function is run \ref{alg:recommendations}. This function finds movie recommendations for each user by ranking the unseen movies that similar users have seen. The proposed rating for the unseen movies is proportional to how similar the user who has seen is to the current user, i.e. \textit{weighted\_sum[rating.movie\_id] + = [rating.value * similarity]}. After this has been completed for every user the proposed movies are ranked based on their estimated rating.

	Upon completion the correlation is stored in the user/user \textit{df\_similarities} matrix and later persisted in the underlying database for later retrieval when a user requests movie recommendations. See \cite{Munk2017} for the full implementation.

	\begin{algorithm}[H]
		\caption{Recommender.sim\_pearsons()}
		\label{alg:simpearsons}
		\begin{algorithmic}
			\STATE $df\_movies\_rated[user] \leftarrow$ Series containing movies rated by user
			\STATE $df\_similarities \leftarrow$ DataFrame consisting of user Id's on the x and y axis

			\FORALL{user\_x in users}
				\FORALL{user\_y in users}
					\IF{df\_similarities[user\_x][user\_y] is null \AND user\_x != user\_y}
						\STATE $intersection \leftarrow$ shared movies between user\_x and user\_y
						\IF{$intersection \geq 5$}
							\STATE $x\_ratings \leftarrow$ list of user\_x rating values
							\STATE $y\_ratings \leftarrow$ list of user\_y rating values
							\STATE $pearson \leftarrow personr(x\_ratings, y\_ratings)$
							\STATE $df\_similarities[user\_x][user\_y] \leftarrow pearson$
							\STATE $df\_similarities[user\_y][user\_x] \leftarrow pearson$
						\ENDIF
					\ENDIF
				\ENDFOR
			\ENDFOR

			\STATE $Recommender.users\_ratings\_similarities \leftarrow df\_similarities$
		\end{algorithmic}
	\end{algorithm}

	\begin{algorithm}[H]
		\caption{Recommender.recommendations() Page 16 \cite{Lead}}
		\label{alg:recommendations}
		\begin{algorithmic}
			\STATE $weighted\_sum \leftarrow \{\}$
			\STATE $similarity\_sum \leftarrow \{\}$
			\STATE $num\_rows \leftarrow length(users)$

			\FORALL{user in users}
				\STATE $df\_similar\_users \leftarrow Recommender.users\_ratings\_similarities[user.id]$
				\STATE $df\_similar\_users \leftarrow $ Remove users that aren't similar.
				\STATE $user\_movies \leftarrow $ user rated movie ids
				\FORALL{target\_user\_id, similarity in df\_similar\_users}
					\IF{$similarity \textgreater 0$}
						\FORALL{rating in users[target\_user\_id].ratings}
							\IF{rating.movie\_id not in user\_movies}
								\STATE $weighted\_sum.setdefault(rating.movie, 0) $
								\STATE $weighted\_sum[rating.movie\_id]\  + =\ (rating.value * similarity)$

								\STATE $similarity\_sum.setdefault(rating.movie\_id, 0)$
								\STATE $similarity\_sum[rating.movie_id]\ + =\ similarity$
							\ENDIF
						\ENDFOR
					\ENDIF
				\ENDFOR

				\STATE Rank the ratings, users who agree alot with the current user will have their ratings affect the final score the most
				\STATE $rankings \leftarrow [(w\_score / similarity\_sum[movie\_id], movie\_id)$
				\bindent
				    \STATE $for\ movie\_id,\ w\_score\ in\ weighted\_sum.items()]$
				\eindent
				\STATE $rankings.sort()$
				\STATE $rankings.reverse()$
				\STATE $Recommender.recoms[user] \leftarrow rankings$
			\ENDFOR
		\end{algorithmic}
	\end{algorithm}

\section{Evaluation \& Reflection}

To evaluate whether the recommendations made by the correlation filter was actually usable to the users a series of offline tests were conducted. This included randomly splitting the set of user ratings into a training and testing set in of either 60/40 or 80/20 distribution. This was then used to apply the training dataset to the recommendation engine to evaluate whether the engine would be accurately be able to predict the rating contained in the test data Beyond this the amount of minimum shared rated movies were also varied between either above 0 or equal to and above 5. The hypothesis was that by sharing more movie ratings the algorithm would be able to better predict the missing ratings.

To evaluate the precision of the recommendation predictions the root mean squared error(RMSE) was calculated to determine the accuracy of the predicted ratings. The reason for this was that as described in \cite{Schafer2007} the RMSE emphasizes large errors and penalizes the performance value by how far each individual prediction is from the true value/rating.

The results of the testing can be seen in \ref{table:results}. The results are from running the recommendation test 20 times for each configuration on the MovieLens 100K dataset and extracting the top 100 recommendations. The reason for multiple runs is that because the testing data is a randomly selected sample that by chance could extract a very good set of users. i.e they have rated more movies than the average.

As Table \ref{table:results} shows the mean RMSE improves when the number of required shared movies is increased. T-tests at the 1\% level also shows that there is a significant difference in the results gathered i.e. (p-value = 0,00004) for the 80/20 configurations and (p-value = 4.43e-13) for the 60/40's. However, when looking the percentage between the training/test distributions it indicates no significant difference in the achieved predictions with (p-value = 0.58) between the 60/40 1 or more shared movies vs the 80/20's configuration or (p-value = 0.13) with 60/40 5 or more shared movies vs the 80/20's.

\begin{table}[H]
	\caption{\label{table} Testing Results}
	\centering
	\label{table:results}
	\begin{tabular}{c c c c}
		\hline
		Train \% & Test \% & Shared Movies & Mean RMSE  \\
		\hline
		60 & 40 & 1 or more &  1,58840 \\
		60 & 40 & 5 or more &  1,23029 \\
		80 & 20 & 1 or more &  1,54424 \\
		80 & 20 & 5 or more &  1,29246 \\
		\hline
	\end{tabular}
\end{table}

Reflecting on these results it shows that in terms of the configuration parameters for the user-based collaborative filtering approach using the Pearson correlation coefficient similarity function the results supports the proposed hypothesis. I.e that an increase in shared movies has a significant impact on the RMSE with a lower prediction average which means that the prediction ability of the system improves. Whether the recommended movies are actually engaging and interesting to the users is another matter and can't be claimed based on these results.

In terms of overall drawbacks of the user-based approach, whenever a user adds a new rating that users recommendations has to be recalculated. This could pose a significant query time whenever a user attempts to retrieve recommendations. To mitigate this the current recommendations are pre-calculated when the system is launched, however this does mean that if a user rates a new item it won't be reflected in the recommendations before the system is relaunched. To counter this in general the item-based approach does seem preferable in that the similarity of each item can be precomputed, hence whenever a user commits a new rating the recommendations can be updated subsequently.


\chapter{Constant functions}
\section{Defined on $\mdr$}
\begin{lemma}
Let $f:\mdr \rightarrow \mdr$, $f(x) := c$ with $c \in \mdr$ be a constant function.

Then $(x_P, f(x_P))$ is the only point on the graph of $f$ with
minimal distance to $P$.
\end{lemma}

The situation can be seen in Figure~\ref{fig:constant-min-distance}.
\begin{figure}[htp]
    \centering
    \begin{tikzpicture}
        \begin{axis}[
            legend pos=north west,
            legend cell align=left,
            axis x line=middle,
            axis y line=middle,
            grid = major,
            width=0.8\linewidth,
            height=8cm,
            grid style={dashed, gray!30},
            xmin=-5, % start the diagram at this x-coordinate
            xmax= 5, % end   the diagram at this x-coordinate
            ymin= 0, % start the diagram at this y-coordinate
            ymax= 3, % end   the diagram at this y-coordinate
            axis background/.style={fill=white},
            xlabel=$x$,
            ylabel=$y$,
            tick align=outside,
            minor tick num=-3,
            enlargelimits=true,
            tension=0.08]
          \addplot[domain=-5:5, thick,samples=50, red] {1};
          \addplot[domain=-5:5, thick,samples=50, green] {2};
          \addplot[domain=-5:5, thick,samples=50, blue, densely dotted] {3};
          \addplot[black, mark = *, nodes near coords=$P$,every node near coord/.style={anchor=225}] coordinates {(2, 2)};
          \addplot[blue, mark = *, nodes near coords=$P_{h,\text{min}}$,every node near coord/.style={anchor=225}] coordinates {(2, 3)};
          \addplot[green, mark = x, nodes near coords=$P_{g,\text{min}}$,every node near coord/.style={anchor=120}] coordinates {(2, 2)};
          \addplot[red, mark = *, nodes near coords=$P_{f,\text{min}}$,every node near coord/.style={anchor=225}] coordinates {(2, 1)};
          \draw[thick, dashed] (axis cs:2,0) -- (axis cs:2,3);
          \addlegendentry{$f(x)=1$}
          \addlegendentry{$g(x)=2$}
          \addlegendentry{$h(x)=3$}
        \end{axis}
    \end{tikzpicture}
    \caption{Three constant functions and their points with minimal distance}
    \label{fig:constant-min-distance}
\end{figure}

\begin{proof}
The point $(x, f(x))$ with minimal distance can be calculated directly:
\begin{align}
    d_{P,f}(x) &= \sqrt{(x - x_P)^2 + (f(x) - y_P)^2}\\
               &= \sqrt{(x^2 - 2x_P x + x_P^2) + (c^2 - 2 c y_P + y_P^2)} \\
               &= \sqrt{x^2 - 2 x_P x + (x_P^2 + c^2 - 2 c y_P + y_P^2)}\label{eq:constant-function-distance}\\
 \xRightarrow{\text{Theorem}~\ref{thm:fermats-theorem}} 0 &\stackrel{!}{=} (d_{P,f}(x)^2)'\\
              &= 2x - 2x_P\\
  \Leftrightarrow x &\stackrel{!}{=} x_P
\end{align}

So $(x_P,f(x_P))$ is the only point with minimal distance to $P$. $\qed$
\end{proof}

This result means:

\[S_0(f, P) = \Set{x_P} \text{ with } P = (x_P, y_P)\]
\clearpage

\section{Defined on a closed interval $[a,b] \subseteq \mdr$}
\begin{theorem}[Solution formula for constant functions]
Let $f:[a,b] \rightarrow \mdr$, $f(x) := c$ with $a,b,c \in \mdr$ and
$a \leq b$ be a constant function.

Then the point $(x, f(x))$ of $f$ with minimal distance to $P$ is
given by:
\[\underset{x\in [a,b]}{\arg \min d_{P,f}(x)} = \begin{cases}
 S_0(f,P) &\text{if } S_0(f,P) \cap [a,b] \neq \emptyset \\
  \Set{a} &\text{if } S_0(f,P) \ni x_P < a\\
  \Set{b} &\text{if } S_0(f,P) \ni x_P > b
    \end{cases}\]
\end{theorem}

\begin{figure}[htp]
    \centering
    \begin{tikzpicture}
        \begin{axis}[
            legend pos=north west,
            legend cell align=left,
            axis x line=middle,
            axis y line=middle,
            grid = major,
            width=0.8\linewidth,
            height=8cm,
            grid style={dashed, gray!30},
            xmin=-5, % start the diagram at this x-coordinate
            xmax= 5, % end   the diagram at this x-coordinate
            ymin= 0, % start the diagram at this y-coordinate
            ymax= 3, % end   the diagram at this y-coordinate
            axis background/.style={fill=white},
            xlabel=$x$,
            ylabel=$y$,
            tick align=outside,
            minor tick num=-3,
            enlargelimits=true,
            tension=0.08]
          \addplot[domain=-5:-2, thick,samples=50, red] {1};
          \addplot[domain=-1:3, thick,samples=50, green] {1.5};
          \addplot[domain=3:5, thick,samples=50, blue, densely dotted] {3};
          \addplot[black, mark = *, nodes near coords=$P$,every node near coord/.style={anchor=225}] coordinates {(2, 2)};

          \addplot[blue, mark = *, nodes near coords=$P_{h,\text{min}}$,every node near coord/.style={anchor=225}] coordinates {(3, 3)};
          \addplot[green, mark = x, nodes near coords=$P_{g,\text{min}}$,every node near coord/.style={anchor=120}] coordinates {(2, 1.5)};
          \addplot[red, mark = *, nodes near coords=$P_{f,\text{min}}$,every node near coord/.style={anchor=225}] coordinates {(-2, 1)};

          \draw[thick, dashed] (axis cs:2,1.5) -- (axis cs:2,2);
          \draw[thick, dashed] (axis cs:2,2) -- (axis cs:-2,1);
          \draw[thick, dashed] (axis cs:2,2) -- (axis cs:3,3);
          \addlegendentry{$f(x)=1, D = [-5,-2]$}
          \addlegendentry{$g(x)=1.5, D = [-1,3]$}
          \addlegendentry{$h(x)=3, D = [3,5]$}
        \end{axis}
    \end{tikzpicture}
    \caption{Three constant functions and their points with minimal distance}
    \label{fig:constant-min-distance-closed-intervall}
\end{figure}

\begin{proof}
\begin{align}
    \underset{x\in[a,b]}{\arg \min d_{P,f}(x)} &= \underset{x\in[a,b]}{\arg \min d_{P,f}(x)^2}\\
   &=\underset{x\in[a,b]}{\arg \min} \big ((x-x_P)^2 + \overbrace{(y_P^2 - 2 y_P c + c^2)}^{\text{constant}} \big )\\
   &=\underset{x\in[a,b]}{\arg \min} (x-x_P)^2
\end{align}

which is optimal for $x = x_P$, but if $x_P \notin [a,b]$, you want
to make this term as small as possible. It gets as small as possible when
$x$ is as similar to $x_p$ as possible. This yields directly to the
solution formula.$\qed$
\end{proof}