% This will include the results of the hyperparameter optimization
\section{Detailed Hyperparameter Optimization Results}\label{appendix:hpoptimresults}

\begin{table}[h!]
	\centering
	\begin{tabular}{@{}clllll@{}}
		\toprule
		& \multicolumn{5}{c}{Parameter} \\\cmidrule(lr){2-6}
		Run Number & Learning rate & Optimizer & Momentum & Epsilon & Loss criterion \\ \midrule
		1 & $2.017 \times 10^{-5}$ & Adam & - & 0.8 & MCE \\
		2 & $3.567 \times 10^{-5}$ & Adam & - & 0.95 & MCE \\
		3 & $8.073 \times 10^{-5}$ & Adam & - & 0.4 & MCE \\
		4 & $2.116 \times 10^{-5}$ & SGD & 0.5 & - & MCE \\ \bottomrule
	\end{tabular}
	\caption[Hyperparameter Tuning Configurations]{Hyperparameter configurations used for each run performed. These were the values selected by the bayesian optimization and hyperband algorithm used to optimized the hyperparameters for the CurbNet model.}
	\label{tab:appendix-hpoptimconfig}
\end{table}

% Please add the following required packages to your document preamble:
% \usepackage{booktabs}
\begin{table}[h!]
	\centering
	\begin{tabular}{@{}crrrr@{}}
		\cmidrule(r){1-4}
		& \multicolumn{3}{c}{IoU} &  \\ \cmidrule(lr){2-4}
		Run Number & Curb & Curb Cut & Ignore & mIoU \\ \midrule
		1 & 0.918\% & 0.125\% & 50.919\% & 17.320\% \\
		2 & 0.860\% & 0.136\% & 51.222\% & 17.406\% \\
		3 & 0.080\% & 22.450\% & 83.008\% & 35.179\% \\
		4 & 0.414\% & 0.289\% & 68.653\% & 23.11\% \\ \bottomrule
	\end{tabular}
	\caption[Hyperparameter Tuning Results]{Hyperparameter tuning results based on the configurations in Table \ref{tab:appendix-hpoptimconfig} after performing bayesian optimization and hyperband tuning with a budget of 5-10 epochs for each configuration.}
	\label{tab:appendix-hpoptimresults}
\end{table}


\chapter{Periodic Detection}\label{chapter:detection}

As noted in XXX, XXX, and XXX, it is possible to frame the problem as a convex optimization program where the reconstruction error is minimized. However, it is important to note that the aim of this dissertation is to examine the application of the periodicity transform to audio processing (encoding to an extent). This means that there is a set of qualitative criteria that we would do well to adhere to. Specifically, the ``atoms'' into which a signal is decomposed must be ``meaningful'' in the sense that manipulating the atoms individually results in something that resembles ``atomic processes'' themselves. In other words, the idea is qualitative \emph{coherence} versus \emph{incoherence} of the atoms themselves. This will become increasingly clear in the remaining chapters.

This is essentially extending the idea of linearity into the qualitative domain.

The atoms are the periodic bases that describe the signal according to some qualitiative criteria which may or may not comport with the exact solution of a complete power minimization of the input signal.

This means that although the problem is framed as a power minimization problem, minimization qua minimization is not necessarily the end goal here. We are less concered with the encoding of information so as to create a perfect reconstruction of the input with a set of atoms as with the manipulation of the information after decomposition so that the combined result is qualitatively coherent with the original signal and underlying proceses.

The words ``bases'' and ``atoms'' are often used interchangebly in this text, although, in general, ``atoms`` refer to a single $p$-periodic component of length $p$ and ``bases'' refers to those atoms periodically extended to $N$, the length of the input signal.

Therefore, the primary concern is with retrieving an appropriate set of periodic atoms that describe the input signal to some tolerance such that the period $p$ of the base is such that $p \leq p_{\text{max}} < N$. These atoms must further be constrained by the qualitative condition that they must be "listenable components" in that when periodically extended, they sound as if they are a component of the sound that is analyzed. This will become clear in Chapter \ref{chap:issues} when the difficulties of non-integer periods are explored. Briefly, it is possible to construct a periodic signal with virtually no residual using the Natural Bases by means of periodic functions that bear no resemblance, apart from their mathematical derivation, to the input.\footnote{See the sound installation \emph{same old person, new mistakes (didn't even notice)} in the author's catalog for an aesthetic exploitation of this phenomenon.}

The process in this chapter describes a way by which one may decompose an input signal into component periodic waveforms that are "listenable". The enumerated list below shows and briefly describes each step. We begin by letting $x$ be the input signal and we initialize $x_r = x$.
\begin{enumerate}
    \item\textbf{Detection:} Choose the best periodic projection, $x_{r_{_p}}$, for $x_r$. Keep a record of all best periods found so far in the set $Q_i$ for step $i$. The addition of this result to $Q$ is then checked against the \emph{stop function}, briefly described below.
    \item\textbf{Reconstruction:} Construct a basis matrix that spans the space of $x$ as described by periods $Q_i$ using the Natural Bases. Compute the reconstruction and the residual error by means of a convex program.
    \item\textbf{Stop Function:} Compute the value of a stop function, $s()$, that determines whether or not to continue processing. This function is arbitrary and may have arbitrary arguments.
    \item\textbf{Recursion:} If one continues processing, set $x_r = x - \sum_{q \in Q} x_q$ and repeat the process until $s()$ calls to stop.
\end{enumerate}
The fundamental difference between this and \cite{sethares1999periodicity} is the difference in computing the residual. That is, one can frame the residual computation as a quadratic program which allows one to alter the result of the Natural Basis to one that minimizes the reconstruction error.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Detection}
Given an input, the first task is to derive what integer-valued period best describes the signal. Several methods have been described in the literature (LIST SOME REFS HERE) and has been the primary are of research on the topic of periodicity transforms. For the purposes of audio manipulation and processing not limited to encoding and reconstruction, some proved to be more useful than others. The method outlined here has shown, in practice, to provide the most useful results for audio processing and is essentially a combination of the iterative methods of \cite{sethares1999periodicity} and the underlying processes of \cite{muresan2003orthogonal}.

In general, period detection is a maximum likelihood estimator (MLE) where the power of some period $p$ is taken on all allowable $p$'s and the result with the maximum power is chosen. Let $P_x$ be the ordered collection of periodic powers in $x$, calculated using one of the methods presented below. To choose the most likely integer period that describes the data, one simply does:
\begin{align}
    \hat{p}_{i} = argmax(P_x)
\end{align}
where $\hat{p}_{i}$ is the most likley period in $x$ at step $i$. Notice that due to the nature of this process, we select a \emph{single} best period and choose additional periods during recusion and as a function of the stop function.

    \subsection{Non-orthogonalized Selection}
    The non-orthogonal method of Sethares and Staley's $M$-best $\gamma$ has proven to be useful in recovering component periods although it is prone to noise and miscategorization of hidden periods. Notably, it is often the case that common divisors of hidden periods are chosen in the MLE since the combined power of each component sharing a common divisor is often large due to the construction of Equation \eqref{eq:intro:sethares:periodicNormGamma}. That is, the columns of the $P_p$ matrix are not orthogonal to each other. It is therefore possible, indeed likley, that during reconstruction, two projections $x_{p_0}$ and $x_{p_1}$ will both contribute to a common divisor period, $d$. Moreover, the $M$-best $\gamma$ periodic power equation biases toward smaller periods, increasing the likelihood that $d$ would be chosen in the example above.

    In order to calculate $P_x$, one must project $x$ independently onto all possible $p$'s, then take the periodic power of each $x_p$, selecting the one with the highest power:
    \begin{align}
        P_{x_{p}} = \frac{||x_p||^2} {\sqrt{Np}}
    \end{align}
    The projection itself is performed by using Equation \eqref{eq:intro:setharesProjection}.
    \footnote{When projecting, it is often easist (and fastest) to rearrange the single row of input $S$ into a rectuangular matrix, zero-padded as necessary. Suppose $x$ is of length $N$ and we are searching for the projection of period $p$ where $N \neq pm$ for an integer $m$. We first extend $x$ by zero-padding the appropriate number of samples until $N = pm$ and reshape $x$ into a rectangular matrix:
    \begin{align}
        &\overline{x} = \text{zp}(x, N - (N \text{ mod } p)) \label{eq:detection:overlineS} \\
        &\overline{x}^{\text{ } 1 \times N} \rightarrow \overline{x}^{\text{ } m \times p} \label{eq:detection:overlineSReshaped}
    \end{align}
    where $m$ is an integer such that $N = mp$. This is equivalent projecting onto the $\bm{B}_p$ subspace and omitting the zeros in the $\delta^s_p$ functions. As such, one can the sum the matrix column-wise and divide each entry by the number of rows except for the final $N - (N \text{ mod } p)$ columns, which are divided by the number of rows minus 1. Notice that this simply averages the values in the columns which correspond to a particular $\delta^s_p$ vector, as \cite{sethares1999periodicity} does.}

    % Each basis matrix of period $p$ has $\varphi(p)$ columns that are unique to $P_p$. This means that it is possible to take an orthogonal version of $P_p$ by taking only the first $\varphi(p)$ columns of $P_p$ and setting the rest of the columns to zero. Unfortunately, doing this directly results in projections which have $p - \varphi(p)$ zeros in every periodic repetition. This is untenable for a vareity of reasons.

    % In order to distinguish a set of basis vectors constructed using the Natural Basis, let $\bm{B}_p$ be a $N \times p$ matrix whose columns are periodic with period $p$ so that
    % \begin{align}
    %     \bm{B}_p &= \begin{bmatrix}
    %             \delta^0_p(N) &
    %             \delta^1_p(N) &
    %             \hdots &
    %             \delta^{p-1}_p(N) &
    %         \end{bmatrix}^{T}
    % \end{align}
    % where $\delta^s_p(N)$ is Eq. \ref{eq:naturalBasisVector}.

        %
        %
        % \subsubsection{Windowed Projection}
        % If $N - (N \text{ mod } p) \neq 0$, the projection will contain artifacts at values around $N - (N \text{ mod } p)$ since by cutting the $p$-periodic component at a partial repetition, one introduces a step function. This effect is exacerbated as $p$ approaches $N$. \cite{muresan2003orthogonal} suggests truncating the input $x$ to be a multiple of $p$ but this is not always desirable or possible if $N$ is small relative $p$. We can mitigate the the artifacts of $N$ not being an integer multiple of the proposed period $p$ by windowing the input and dividing by the appropriate value which will not be the same for each column. This is an application of a weighted mean to a window where the mean is each element multiplied by its weight divided by the sum of the weights:
        % \begin{align}
        %     \overline{m}_{xw} = \frac{\sum_{i=0}^{N-1} x[n]w[n]} {\sum_{n=0}^{N-1} w[n] }
        % \end{align}
        % where $x$ is a sequence of length $N$ and $w$ is a 1-normalized window function also of length $N$. Notice that this works only if $\sum_{i=0}^{N-1} w[n] \geq 1$ which is why one must normalize. By normalizing, we ensure that the sum will always be greater than 1 and that the proportion of the weights is maintained.
        %
        % In order to derive the values by which we outght to divide by when using a window, we take the window function $w$ and apply the same process as in Equations \eqref{eq:detection:overlineS} and \eqref{eq:detection:overlineSReshaped}, then sum downwards. This results in a vector of length $p$ whose values are used to divide, column-wise, by the same length vector resulting from the column-wise summation of $\overline{S}^{\text{ } m \times p}$. The windowing in essense more heavily ``weights'' the center of the signal where a complete period is more likley to be present and unweights the edges where partial repetitions may be present. This is easily expanded for a no window situation, where we can essntially say that the window is a boxcar (all 1's). Moreover, the application of a window does not exacerbate the effect of an analysis and/or recovery if $N$ is not a large multiple of the contained periods.
        %
        % This windowing method has the additional benefit of offsetting some of the effects if the signal is enveloped. Suppose $S$ is a signal which is the composite of two sawtooth waves with periods $p_0$ and $p_1$ with a ramp envelope from $0.5$ to $1$. Here $N$ is not an integer multiple of either $p_0$, $p_1$, nor $p_0 p_1$. Figure XXX, top, shows the composite signal signal; the envelope is plainly visible. In the lower portion, the solid lines shows the recovered waveforms without windowing (or with a boxcar window) while the dashed lines shows the recovered waveforms when applying a Hann window.
        %
        % For the rest of this document, we will always include a window function where appropriate and denote it $w$. Thinking specifically of the sections where we project with $A$ and stuff. Probably. Show that this actually gives a better residual.

    \subsection{Orthogonal Detection}
    It is often far preferable to detect the periodic components \emph{orthogonally}; that is, using the method of \cite{muresan2003orthogonal}, described in Section \ref{section:intro:orthgonalDecomp}. This is mainly due to the aforementioned fact that for the method of Sethares and Staley above, energies become concentrated in common divisors of the actual periodic components. We follow \cite{muresan2003orthogonal} in avoiding the direct calculation of the orthogonal subspace $P_{p}^{\perp}$ by using Equation \eqref{eq:intro:orthgonalProjection}. We can see that the distribution of powers is much more like what we would expect versus the method of \cite{sethares1999periodicity}:

    FIGURE HERE

    The computational advantage here is that one need only project \emph{once} after $p_{i}$ is found for a given iteration. An important note here is that the orthogonal method of Muresan and Parks \emph{always} truncates the input signal to an integer multiple of the proposed period $p$. This, however, has not been shown to be problematic in practice.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Reconstruction}
Let $Q_i$ be the set of periods found in $x$ by means of a projection method at step $i$. (Note that $|Q_i| = i + 1$ at the end of the detection stage in step $i$) We now ask ourselves: what is the best representation of $x$ using only periods in $Q_i$? For convience, we will often denote $Q_i$ as simply $Q$, though a particular $i$ is implied.

In \cite{sethares1999periodicity}, the reconstruction is computed by simply summing the projections $x_q$ for $q \in Q$. That is:
\begin{align}
    \hat{x} &= \sum_{q \in Q} x_q
\end{align}

In other literature, reconstruction of $x$ is performed similarly by solving
\begin{align} \label{eq:detection:convex}
    \bm{A}x &= b
\end{align}
then doing
\begin{align}
    \hat{x} = \bm{D}_{Q}^{T} b
\end{align}
where $\bm{A}$ is a the covariance matrix of $\bm{D}_Q$ which is a matrix of basis vectors that spans the space of $x$ using periods $Q$ with linearly independent columns. In most cases, $D_Q$ will not be a square matrix since its row dimension is $N$. For the purposes of this dissertation, this is the primary method of reconstruction. The question now becomes: how must one construct $\bm{D}_Q$?

    \subsection{Construction of $\bm{D}_Q$}\label{section:detection:D_Q}
    Let $\bm{D}_Q$ be a ``basis matrix'', or a matrix of linearly independent columns which span the space of the sequence $x$ with periods $q \in Q$ of shape $N \times c_{\bm{D}_Q}$. The column dimensionality, $c_{\bm{D}_Q}$, is defined as
    \begin{align}
        R &= \bigcup_{q_i \in Q} \text{factors}(q_i) \label{eq:A:R} \\
        c_{\bm{D}_Q} &= \sum_{R_i \in R} \varphi(R_i) \label{eq:A:c_A}
    \end{align}
    where $R$ is the union of all the factors of the periods in $Q$, $\text{factors}(n)$ is a function which returns the set of factors of an integer $n$, and $\varphi(n)$ is Euler's totient function. The columns of $\bm{D}_Q$ itself are the Natural Basis of period $p$ as defined in Eq. \ref{eq:naturalBasis}:
    \begin{align}\label{eq:detection:overdeterminedDQ}
        D_Q = \begin{bmatrix}
            \bm{B}_{q_{0}} & \bm{B}_{q_{1}} & \hdots & \bm{B}_{q_{i}}
        \end{bmatrix}^{T}
    \end{align}

    Recall two things at this point: that the subspace $P_p$ for a given period $p$ is a matrix of shape $N \times p$ and that each $P_p$ is not orthogonal to others. This means that $D_Q$ as constructed in Equation \eqref{eq:detection:overdeterminedDQ} is overdetermined. Therefore, in order to avoid introducing additional power at the period $d$ for $d|p$ and have linearly independent columns, one must remove columns from each $\bm{P}_p$ accordingly. But what columns to remove?

    According to Lemma XX in \ref{tenneti2016unified}, a Natural Basis matrix that is a full rank consists of keeping the first $\varphi(p)$ columns of $\bm{P}_p$ for all integers betwen 1 and $p$. A complete and not overdetermined dictioary of Natural Bases for periods 1 to $p_{\text{max}}$ therefore consists of keeping the first $\varphi(p)$ columns of each $\bm{B}_p$ for $1 \leq p \leq p_{\text{max}}$. This is essentially saying that for a periodic subspace of period $p$, there are $\varphi(p)$ degrees of independence between $p$ and all other possible $p$'s. In this case, however, it is not true that we want $\bm{D}_Q$ to contain all periods between 1 and $p_{\text{max}}$ but rather only those periods $q \in Q$.
     Nonetheless, this gives an idication of how to proceed of which there are two ways: (1) we can construct $\bm{D}_Q$ so that we separate out every factor which appears in two or more $q \in Q$ and take care to remove that factor from $\bm{B}_p$ by removing columns or, (2) we can construct $\bm{D}_Q$ by keeping track of what periods have been added so far, taking care to not add a factor twice. Although both methods result in a matrix with spans the same space and are functionally equuivalent, the coefficients returned from the convex program have different meanings. The importance of this will become clear in subsequent sections.
    %%%%% ^^^^ should probably prove that these are equivalent?!?! ^^^^^^^^

        \subsubsection{Separating out common factors in $\bm{D}_Q$}\label{detection:A:separateFactors}
        For this method, we create a separate subspace for a period $d$ for any $d$ such that for any two periods $q_n, q_m \in Q$, $d \in \text{factors}(q_n)$ and $d \in \text{factors}(q_m)$. In other words, suppose $Q = \{8, 10\}$. There are two common factors, 1 and 2. Therefore, the 1-space and 2-space (which itself is absent the 1-space it contains) are separated out into separate basis matricies. In this case, then,
        \begin{align*}
            D_Q = \begin{bmatrix}
                \bm{B}_{1} & \bm{B}_{2} & \bm{B}_{8} & \bm{B}_{10}
            \end{bmatrix}^{T}
        \end{align*}
        Notice that although 8 also contains a factor of 4 and 10 contains a factor of 5, there is no need to separate out these spaces since any energy in the 5-space will \emph{only} be contained in the 10-space. Likewise with the 4-space and 8-space.

        Begin by defining $R_i$:
        \begin{align}\label{eq:A:commonFactors:R}
            R_i &= \Bigg( \bigcup_{p, q \in Q_i} \text{factors}(p) \cap \text{factors}(q) \Bigg) \cup Q_i
        \end{align}
        Notice that $R_i$ contains all elements of $Q_i$ as well as any common factors between elements in $Q_i$. In accordance with the previous convention, we will remove the subscript $i$ for simplicity of notation. To find the column dimensionality, $c_{r}$, of the basis matrix $\bm{B}_r$ for $r \in R$:
        \begin{align}\label{eq:A:commonFactors:cp}
            c_{r} &= r - \sum_{d|r \in R \setminus r} \varphi(d)
        \end{align}
        Therefore, to constuct $\bm{D}_Q$, we simply concatenate the subspaces $\bm{B}_r$ for $r \in R$:
        \begin{align}\label{eq:A:commonFactors:A}
            \bm{D}_Q &= \begin{bmatrix}
                    \bm{B}_{r_0}^{c_{r_0}} &
                    \bm{B}_{r_1}^{c_{r_1}} &
                    \hdots &
                    \bm{B}_{r_n}^{c_{r_n}}
                \end{bmatrix}
                , \text{ } r \in R
        \end{align}
        where the superscript indicates the number of columns of $\bm{B}$ to keep. Using this method, it is not imporant which order we concatenate the subspaces but only that we do not doubly count a particular subspace.\footnote{In practice and in conjunction with the extraction method presented in Chapter \ref{chapter:extraction}, knowing the order of the columns and what part of what period they represent is of critical importance.} One can confirm the dimensionality by using Eq. \eqref{eq:A:c_A} and checking that $\sum_{i = 0}^{|R| - 1} c_{r_i} = c_{\bm{D}_Q}$ where $|R|$ is the cardinality of $R$.

        As an example, suppose $Q = \{8, 10, 15\}$. According to Eq. \eqref{eq:A:P}:
        \begin{align*}
            R &=
                \big(
                \text{ } ( \text{factors}(8) \cap \text{factors}(10) ) \text{ } \cup
                \text{ } ( \text{factors}(8) \cap \text{factors}(15) ) \text{ } \cup
                \text{ } ( \text{factors}(10) \cap \text{factors}(15) )
                \text{ } \big)
                \text{ } \cup \{8, 10, 15\} \\
            R &= \{1, 2, 5\} \text{ } \cup \text{ } \{8, 10, 15\} \\
            R &= \{1, 2, 5, 8, 10, 15\}
        \end{align*}
        Now we can calculate the dimensionality of an arbitrary $p \in P$ in any order:
        \begin{align*}
            c_1 &= 1 - \sum_{d|1 \in \{2, 5, 8, 10, 15\}} \varphi(d) = 1 \\
            c_2 &= 2 - \sum_{d|2 \in \{1, 5, 8, 10, 15\}} \varphi(d) = 1 \\
            \vdots \\
            c_{10} &= 10 - \sum_{d|10 \in \{1, 2, 5, 8, 15\}} \varphi(d) = 10 - (1 + 1 + 4) = 4 \\
            \text{etc...}
        \end{align*}
        We see then that in this case,
        \begin{align*}
            D_Q = \begin{bmatrix}
                \bm{B}_{1}^{1} &
                \bm{B}_{2}^{1} &
                \bm{B}_{5}^{4} &
                \bm{B}_{8}^{6} &
                \bm{B}_{10}^{4} &
                \bm{B}_{15}^{10} &
            \end{bmatrix}^{T}
        \end{align*}

    \subsubsection{Progressive concatenation of $\bm{D}_Q$}\label{detection:A:progressiveConcatenation}
    What if one wants to construct $\bm{D}_Q$ in such a way as to \emph{only} include subspaces which are constructed from the elements of $Q$? The advantages of this method is that it is not necessary to add subspaces of factors for the periods we are actually interested in and that it (somewhat) simplifies the process of computing the waveforms containing their subcomponents. However, it requires one to keep track of the order in which periods are added to the subspace. That is, each periodic component $q \in Q$ also contains the components $d|q$ and one must construct the basis matrix with this in mind, taking care to remove the component from a subspace if it is already present.

    To do so, we exploit the fact that $n = \sum_{f|n} \varphi(f)$. Let $c_{\bm{D}_{Q_i}}$ denote the column dimensionality of $\bm{D}_Q$ at step $i$. We also redefine Eq. \eqref{eq:A:R}:
    \begin{align}\label{eq:A:onlyPeriods:R}
        R_i = \bigcup^i_{q_j \in Q_i} f(q_j)
    \end{align}
    Given the above, the total column dimensionality $c_{\bm{D}_{Q_i}}$ at step $i$ is:
    \begin{align*}
        c_{\bm{D}_{Q_i}} = \sum_{r \in R_i} \varphi(r)
    \end{align*}
    Therefore, the column dimensionality for any $q$ at step $i$ is:
    \begin{align}\label{eq:A:noFactors:cp}
        c_{q_i} =
            \begin{cases}
                q_i, & \text{if } i = 0 \\
                c_{\bm{D}_{Q_i}} - c_{\bm{D}_{Q_{i-1}}}, & \text{otherwise}
            \end{cases}
    \end{align}
    Again, we will simplify the notation going forwrd by omitting the subscript $i$. We construct $\bm{D}_Q$ as:
    \begin{align*}
        \bm{D}_Q &= \begin{bmatrix}
                \bm{B}_{q_0}^{c_{q_0}} &
                \bm{B}_{q_1}^{c_{q_1}} &
                \hdots &
                \bm{B}_{q_n}^{c_{q_n}}
            \end{bmatrix}
            , \text{ } \forall q \in Q
    \end{align*}
    In doing so, we ensure that for every subsequent subspace in $\bm{D}_Q$ is orthogonal to all existing subspaces in $\bm{D}_Q$.

    Returning to the example in the previous section, we see that
    \begin{align*}
        c_{q_0} &= c_{8} = 8 - 0 = 8 \\
        c_{q_1} &= c_{10} = 16 - 8 = 8 \\
        c_{q_2} &= c_{15} = 26 - 16 = 10 \\
    \end{align*}
    Therefore:
    \begin{align*}
        \bm{D}_Q = \begin{bmatrix}
            \bm{B}_{8}^{8} & \bm{B}_{10}^{8} & \bm{B}_{15}^{10}
        \end{bmatrix}
    \end{align*}
    The total column dimensionality can again can be double-checked using Eq. \eqref{eq:A:c_A}.

    \subsection{Approximation of $x$ using $\bm{D}_Q$}
    Once $\bm{D}_Q$ has been appropriately constructed, we can compute $\bm{A}$ as the covariance matrix of $\bm{D}_Q$:
    \begin{align}
        \bm{A} = \bm{D}_Q \bm{D}_Q^T
    \end{align}
    One then simply puts $\bm{A}$ in the convex program and solves for the reconstruction, $\hat{x}$, with matrix multiplication:
    \begin{align}
        \bm{A}x &= b \label{eq:detection:reconstruction:coefficients} \\
        \hat{x} &= \bm{A} b^{T} \label{eq:detection:reconstruction:xHat}
    \end{align}

    Notice that due to the reconstitution of $\bm{D}_Q$ on each iteration, which in turn recomputes $\bm{A}$, the resulting basis vectors, when retrived using the method described in Chapter \ref{chapter:extraction} can change so as to minimize $x - \hat{x}$. This possible change of the bases on each iteration is also part of the motation of the stop function, briefly described in \ref{section:detection:stopFunction} below. Further, reconstituting $\bm{D}_Q$ each iteration means that the coefficients $b$ and reconstruction $\hat{x}$ is identical to projecting onto the subspaces $P_q$ for $q \in Q$ simultaneously as is possible with orthogonal dictionaries of each component and its factors.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Stop Function}\label{section:detection:stopFunction}
The selection of a stop function is critical for periodic decomposition success if one wishes to pay respect to the qualitiative criteria at the start of this chapter. That is, any formulation of the periodicity transform will invariably detect a peroidic waveform of some period $p$ with an input of Gaussian noise. In other words, just because the detection step returns a ``best'' period does not mean that that period has any correspondence to the actual content of the signal and would be of no interest in audio processing. The ``best'' period in the residual may contribute to minimizing the reconstruction error but this is a fundamentally different prospect than retriving the integer periods which best describe the signal.

It is important to note that the stop function is evaluated \emph{before} the detection step on each iteration. This topic will be discussed further in Section \ref{section:audioEffects:stopFunction} but suffice it to say, for now, that it is almost always a necessary condition of the detection stage as described in this dissertation.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Recursion}\label{section:detection:recursion}
This step hardly needs explaination: if the criteria in the stop function is met, cease processing. Otherwise, continue to process, adding to the total set of periods found.

% Define $P$:
% \begin{align*}
%     P &= \Bigg( \bigcup_{\forall p, q \in Q} f(p) \cap f(q) \Bigg) \cup Q
% \end{align*}
% i.e. the union of the intersections of the factors of all the elements in $Q$.
%
% To find the column dimensionality, $c_{p}$, of the basis matrix $\bm{B_p}$ for $p \in P$:
% \begin{align*}
%     % c_{p} &= p - \sum_{f : f(p) \cap P \setminus p} \varphi(f)
%     c_{p} &= p - \sum_{d|p \in P \setminus p} \varphi(d)
% \end{align*}
%
% %% If N is the columns
% % We then define $\bm{A}$ as:
% % \begin{align*}
% %     \bm{A} &= \begin{bmatrix}
% %             \bm{B}_{p_0} \\
% %             \bm{B}_{p_1} \\
% %             \vdots \\
% %             \bm{B}_{p_n} \\
% %         \end{bmatrix}
% %         , \text{ } \forall p \in P
% % \end{align*}
% % where there are $n$ elements in $\bm{P}$.
%
% To find the total column dimensionality, $c_{\boldsymbol{A}}$ of the matrix $\bm{A}$:
% \begin{align*}
%     c_{\bm{A}} &= \sum_{p \in P} c_p
% \end{align*}

% In this way, we can be assured that not only are the basis vectors in $\bm{A}$ linearly independent, but also that all traces of some period $q$ are removed from the residual signal $h$.

% \subsection{This also works}
% We can also get a basis matrix for the periods in $q$ by using the same equation as above that uses $varphi(n)$ by creating $\bm{A}$ along the way and keeping track of which periods (and factors of the periods) we've added along the way.
%
% Let $F = \emptyset$. To find the column dimensionality, $c_q$, for $q \in Q$:
% \begin{align}
%     c_q &= q - \sum_{d|q \in F} \varphi(d)
% \end{align}
%
% We then add elements to $F$ every time we add a basis matrix $\bm{B}_q$ to $\bm{A}$:
% \begin{align*}
%     F &= \{ F \cup f(q) \}_{\neq}
% \end{align*}
% i.e. every time we process a period $q$, add all the factors of $q$ to $F$, removing duplicates.
%
% Repeat this process for every $q \in Q$, adding to $F$ along the way. (This means that we need to keep track of which factors we've added along the way which makes it uglier in some ways, better in others.)
%
% Therefore, we then define $\bm{A}$ as:
% \begin{align*}
%     \bm{A} &= \begin{bmatrix}
%             \bm{B}_{q_0} &
%             \bm{B}_{q_1} &
%             \hdots &
%             \bm{B}_{q_n}
%         \end{bmatrix}
%         , \text{ } \forall q \in \bm{Q}
% \end{align*}
% where there are $n$ elements in $\bm{Q}$.
%
% \section{Not a real section but describing getting the real periods back}


\section{Related Work}
\label{sec:relatedwork}

In the past, many algorithms have been proposed to mine subgraphs from a
given database of graphs. These algorithms can be mainly divided in to
two classes depending on how the candidate patterns are generated.
Algorithms like those in \cite{IWM03,FSG01,HWP03} are Apriori
based methods, i.e., a candidate pattern of size $k+1$ is generated by
combining two frequent graphs of size $k$ that have a common $k-1$ sized
subgraph.  Algorithms like those in \cite{gSpan,borgelt2002mmf,HWP03},
on the other hand, belong to the class of pattern growth algorithms in
which a candidate pattern is generated by extending a frequent pattern
with an edge.

Mining subgraphs from a single graph is a related problem which is
surprisingly difficult compared to mining from a database of graphs.  In
\cite{kuramochi2005ffp}, they defined the support of a pattern
in a single graph as the maximum number of edge disjoint isomorphisms,
which is itself a $NP$-Hard problem.  In \cite{fiedler2007support}, they
proposed a definition of support based on overlapping ancestor
isomorphisms.  In \cite{2012-kais}, they proposed
CMDB-Miner\xspace to mine frequent patterns from a single large graph.
Support of a pattern is defined as the maximum flow in an appropriately
constructed flow network with capacities. This method estimates the
support of a pattern without enumerating its isomorphisms. The authors
also proposed methods to summarize the maximal frequent patterns
extracted from the graph. In \cite{li2010dessin}, they proposed an
algorithm to extract frequent patterns from dense graphs. It uses
GADDI index proposed in \cite{Gaddi2009} to efficiently extract the
isomorphisms of a subgraph.

There been little work in approximate subgraph
mining.  In \cite{gapprox}, they proposed $gApprox$ to mine approximate
frequent subgraphs.  The degree of approximation between a pattern and its
isomorphism includes label mismatches and missing edges. The search space
is explored in a depth first order and the support of a pattern is
computed by enumerating its isomorphisms. This approach is not feasible
for large graphs with label multiplicities as there are potentially
exponential number of isomorphisms \cite{2012-kais}.
In \cite{JiaZH11}, they proposed APGM to approximate frequent
subgraphs from a database of graphs. The method is similar to the
$gApprox$ method in that it stores the complete set of approximate
embeddings of the current frequent pattern. The difference, however, is
that in \cite{JiaZH11} the entire $1$-hop neighborhood of the current
embeddings is explored to enumerate all extensions of the frequent
pattern and their corresponding embeddings, whereas $gApprox$ enumerates
the embeddings for a single extension in each step.
In \cite{SpeedUpFAS}, the authors proposed strategies
to speed up the existing mining algorithms, by
limiting the number of candidates and also the number of duplicate
checks performed.
In \cite{RAM2008}, they proposed a randomized algorithm to mine
approximate patterns from a database graphs. In this method, an edge in
the approximate pattern is required to have at least a given number of
occurrences.

Graph querying is another problem that is related to
subgraph mining. The goal is to find matches of a given query graph in a
single graph or database of graphs.  In \cite{TALE}, they proposed an
indexing method to extract the approximate occurrences of a given graph
query in large graph databases.  The algorithm proposed in
\cite{yan.icde:2006} extracts selective fragments from the query graph
and queries against an index constructed from the fragments of the
database graphs. In \cite{RandomMatching}, they proposed a polynomial
time algorithm for detecting isomorphism between spectrally
distinguishable graphs. An isomorphism, if it exists,
is obtained by matching
the steady state vectors of Markov chains in both the graphs.  In
\cite{BerettiIndexing}, they proposed indexing and retrieval methods for
graph models. The problem with most of the indexing approaches is that
they are efficient in retrieving a single match for the query graph but
fail at retrieving all matches, and thus are not suited to mine frequent
patterns. Furthermore, they assume that the query given, and thus they
do not perform pattern enumeration as required in graph mining.

Frequent pattern mining algorithms usually return a large number of
patterns and interpreting them is a big challenge. This is especially
true if the output is presented to a human user for further analysis.
Sampling approaches like those proposed in
\cite{2009-graphsampling,2012-kais,RAM2008} mine a representative set of
maximal patterns from a database of graphs or a single graph.
In our work, we perform a random walk in the search space
to enumerate a maximal pattern.

%The concept of using derived labels based on the
%structure and the attributes is frequently used in detecting graph
%isomorphism \cite{zampelli} and computing graph kernels
%\cite{shervashidzeJmlr,shervashidzeNips}.
%Our methods to prune representative sets are somewhat similar to
%the wiesfieler lehman kernel to test isomorphism between two graphs
%$G_1$ and $G_2$ \cite{weisfeiler}, where after every iteration the labels are
%sorted and renamed with a different string in such a way that the pairwise
%relationship is maintained. $G_1$ is not isomorphic to $G_2$
%if the label set of the graphs differ. The specifics of how and what
%information we update is different, and also we use the information for
%subgraph isomorphism instead of graph isomorphism.


\input{../header.tex}
\title{\vspace{-2cm}INF3490/INF4490 Exercises - Optimization & Performance}
\author{Eivind Samuelsen\input{../author_footnote.tex}}
\date{}

% Removing paragraph indents is sometimes useful:
\setlength\parindent{0pt}
% ==============================================================================

% ================================= DOCUMENT ===================================
\begin{document}
    \renewcommand\marginsymbol[1][0pt]{%
  \tabto*{0cm}\makebox[-1cm][c]{$\mathbb{P}$}\tabto*{\TabPrevPos}}

\maketitle
\input{../intro.tex}

\section{Pareto Optimality}
\begin{figure}[H]
  \centering
  \begin{minipage}[b]{0.45\textwidth}
    \includegraphics[width=\textwidth]{front_points_1.pdf}
    \caption{a}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{0.45\textwidth}
    \includegraphics[width=\textwidth]{front_points_2.pdf}
    \caption{b}
  \end{minipage}
\end{figure}

For figure a and b above, find the Pareto optimal set when
\begin{itemize}
    \item Minimizing both \(f_1\) and \(f_2\)
    \item Minimizing \(f_1\), maximizing \(f_2\)
    \item Maximizing \(f_1\), minimizing \(f_2\)
    \item Maximizing both \(f_1\) and \(f_2\)
\end{itemize}
\section{Weighted sum}
In figures a and b, what would be the maximum point when using weighted sum:
\begin{itemize}
    \item \(w_1 = 1\),  \(w_2 = 1\)
    \item \(w_1 = -1\), \(w_2 = 1\)
\end{itemize}
\section{Hybrid Algorithm}
Why can hybrid algorithms make it harder to maintain diversity?
\section{Measuring algorithm performance}
Why is it usually better to use the number of fitness function evaluations as a time measure,
rather than the number of generations, or the amount of CPU time spent?

\input{../contact.tex}
\end{document}
% ==============================================================================


\chapter{Determinants}
\label{cha:determinants}


\documentclass[a4paper,twocolumn]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{fullpage}
\usepackage[small]{titlesec}

% patch titlesec bug of not showing (sub)title numbering http://tex.stackexchange.com/a/300259
\usepackage{etoolbox}
\makeatletter
\patchcmd{\ttlh@hang}{\parindent\z@}{\parindent\z@\leavevmode}{}{}
\patchcmd{\ttlh@hang}{\noindent}{}{}{}
\makeatother

\newcommand*\mean[1]{\overline{#1}}

\title{The Cascade-Correlation Learning Architecture $-$ summary}
\author{Matěj Nikl}

\begin{document}
\maketitle
\noindent
The Cascade-Correlation Architecture (CCA) is a architecture as well as a supervised learning algorithm for artificial neural networks (ANNs). Conventional way of training ANNs is to \textit{somehow} choose a fixed network topology and then train it using back-propagation algorithm.
CCA eliminates the need of choosing a fixed network topology and provides a way of training this kind of a dynamic network.

\section{Principles of growing}
The network starts with no hidden units, only output units are present. Then, one hidden unit is added at a time, receiving all network inputs and all outputs of the previously added hidden units, each time adding more complexity to the network, possibly creating more and more complex feature detectors.

\begin{figure}[!h]
    % \centering
    \includegraphics[width=0.475\textwidth]{cascade.png}
    \caption{The CCA after two hidden units have been added. The vertical lines sum all incoming activations. Boxed connections are frozen, X connections are trained repeatedly.}
\end{figure}

\section{Training}
The process of training can be divided into two parts, which will be described in the following subsections, however one constraint holds through both of them: once a new hidden unit is added, its input weights are forever frozen.
% \begin{itemize}
%     \item \ref{ssec:nn} training the network output
%     \item \ref{ssec:unit} training a new hidden unit, to-be added to the network
% \end{itemize}
\subsection{Network output training} \label{ssec:nn}
Having everything except output units' weights frozen translates into optimization of a single layer network, which was one of the authors' goals (to avoid slow back-propagation). The following steps take place:
\begin{enumerate}
    \item optimize the single layer network, until a convergence is achieved
    \item evaluate the test error and if it is low enough, stop
    \item otherwise, proceed to subsection \ref{ssec:unit}
\end{enumerate}

\subsection{New unit training} \label{ssec:unit}
If network's test error is not low enough, we need to add a new hidden unit. To do so, the following steps take place:
\begin{enumerate}
    \item create a pool of \textit{candidate} units, having their input weights randomly initialized, each receiving all available inputs
    \item maximize $S$, the sum of covariances between the candidate unit's value and the residual output error of all output units, for each candidate unit, by adjusting their input weights, until convergence
\[
    S = \sum_{o \in O} \left| \sum_{p \in P} (V_p - \mean{V})(E_{p,o} - \mean{E_o}) \right|
\]
    \begin{itemize}
        \item $O$ is a set of output units
        \item $P$ is a set of training patterns (training data)
        \item $V_p$ is candidate unit's value for pattern $p$
        \item $E_{p,o}$ is the residual output error at output unit $o$ for pattern $p$
        \item averages are computed across $P$
    \end{itemize}

    \item choose the candidate unit with the largest $S$ and add it to the network, proceed to \ref{ssec:nn}
\end{enumerate}

\section{Principles of modularization}
The only sense of modularization in the CCA can be seen in viewing individual hidden units as modules, since they are being added throughout the learning process. However, the network as a whole is not modular in the full sense. Hidden units cannot be detached from a network and reattached to a different one. A hidden unit can only be used in conjunction with the hidden units it has been trained with and nowhere else.
\paragraph{Similar design}
A similar partially modular design can be seen in Progressive Neural Networks, where new columns (full-blown NNs) are being added with lateral connections to all of the previously trained columns, showing the same aspects of \textit{(non)modularity} as CCAs.

\end{document}


% !TEX root = ../00_thesis.tex

% ------------------------------------------------------------------------------
\section{Performance of the \TTW Scheduler}
\label{sec:ttw_evaluation_sched}
% ------------------------------------------------------------------------------

The following two sections present the performance evaluation of our \TTW implementation, presented in~\cref{sec:ttw_implementation}.
We first evaluate the performance of the scheduler. In particular, we illustrate the benefits of the minimal inheritance strategy presented in \cref{sec:multi_mode} and we show that the complexity of the schedule synthesis is tractable.

% ------------------------------------------------------------------------------
\subsection{Benefits of Minimal Inheritance}

\begin{figure}
  \centering
  \href{\ttwfig{Figure-11}}{%
  \includegraphics[scale=1]{inheritance_eval}}
  \caption{Number of rounds in the different modes' schedule, depending on the inheritance approach considered.
  \capt{We consider the number of rounds scheduled over 80\s, which is the least common multiple of the modes' hyperperiod.}}
  \label{fig:inheritance_eval}
\end{figure}

Every round introduces some overhead (mainly from  sending the beacon), which consumes energy.
To reduce the energy consumption, \TTW aims to minimize the number of rounds \objective{1}.
The schedule synthesis for a single mode is optimal in this respect; that is, the procedure guarantees that the schedule minimizes the number of communication rounds~(\cref{sec:single_mode}).

\squarepar{%}
  The second objective of the scheduler is to allow persistent applications to keep the same schedule in different operation modes \objective{2}.
  This creates additional constraints that break the optimality guarantee: in other words, the schedule of mode \modej, when constrained to be compatible with mode \modei, may contain more rounds than required to schedule the mode \modej alone.
  A naive solution to meet \objective{2} is to completely ``reserve the space'' of previously scheduled modes. This is equivalent to consider that all applications executing in mode \modei are also executing in \modej, even if it is not actually the case. We call this the \emph{full inheritance} approach.
  This approach does guarantee compatibility but it is very pessimistic: it leads to an excessive increase of the number of rounds and find problems to be non-schedulable when they may in fact be feasible.%
}

\begin{figure}
  \centering
  \includegraphics[scale=1]{modeGraph_eval}
  \caption{The mode graph \modeGraph' used in the inheritance evaluation scenario.
  Mode \modei has priority $i$. The applications executing in each mode are listed in~\cref{append:inheritance_eval}.}
  \label{fig:modeGraph_eval}
\end{figure}

In \cref{sec:multi_mode}, we derived the minimal set of constraints that are necessary to guarantee the compatibility between modes \objective{2}, which we refer to as \emph{minimal inheritance}.
We now illustrate with a simple example that the minimal inheritance does not overly increase the number of communication round required and performs much better than the full inheritance.
%
We consider the following configuration (fully detailed in \cref{append:inheritance_eval}): The system is composed of 13 nodes, running 15 different applications including 45 tasks and 30 messages.
The periods and deadlines vary between 10 and 80\s. The applications are executing in 5 different modes connected by the mode graph shown in~\cref{fig:modeGraph_eval}.
Finally, all applications are considered persistent.
We synthesize the schedule for the 5 modes while considering
(i)~no inheritance,%
%
\footnote{Considering no inheritance is equivalent to set all applications as non-persistent. In other words, there are no constraints between the different modes and the individual mode schedules are guaranteed to be optimal in terms of number of rounds~(\cref{sec:single_mode}).}
%
(ii)~our minimal inheritance approach, and (iii)~the naive full inheritance approach.
The results are shown in \cref{fig:inheritance_eval}.

One important observation is that the number of rounds steadily increases with the full inheritance approach, which is expected: the full inheritance assumes that all previously scheduled applications are still executing. Thus, the number of applications to schedule only increases, and so does the number of round required. Ultimately, this not only wastes energy, it also limits scalability with the number of operation modes.
In comparison, our minimal inheritance approach performs much better: Since only the required constraints are included, the minimal inheritance does not suffer from the scalability issue mentioned above. In this example, the minimal inheritance performs optimally (\ie it does not schedule more rounds that the minimum, captured by the ``no inheritance'' case); but note that this is {\bf not true in general}, it simply happens to be the case in this example.

\fakepar{Conclusion}
The minimal inheritance approach derived in \cref{sec:multi_mode} efficiently addresses the challenge of synthesizing compatible schedules~\objective{2} while minimizing the energy impact in terms of number of rounds scheduled~\objective{1}.
This approach does increase the complexity of the synthesis formulation; however, it is implemented in our \TTW scheduler, it induces no overhead for the user, and it does not affect the synthesis solving time, as discussed below.

% ------------------------------------------------------------------------------
\subsection{Offline Solving Time}

\squarepar{%}
  We computational complexity of the schedule synthesis is made tractable by \TTW's sequential approach: modes are scheduled individually, in order of priority~(\cref{sec:multi_mode}) and for each mode, the number of rounds to schedule is kept fixed then incremented until a solution is found~(\cref{sec:single_mode}).

  For the evaluation scenario described above, the solving time for one mode grows up to ten minutes~(\cref{table:solvingTimes}) and is generally correlated with the complexity of the mode to schedule: mode \mode{3} and \mode{4} contains the most applications~(\cref{append:inheritance_eval}), leading to more constraints in the formulation.
  Furthermore, we note that the minimal inheritance strategy does not increase the overall solving time compared to ``no inheritance''. The intuition is that, by reserving some applications' schedule, we fix the value of some of the problem variables, thereby reducing the complexity of the problem.
  However, as shown by the full inheritance approach, if too many variables are fixed, the resulting problem might become harder to solve: more communication rounds become required, which increases the number of variables and thus the complexity.

  \fakepar{Conclusion}
  The evaluation scenario is simple but representative of a middle-sized \CPS. Our evaluation shows that the computational complexity may grow to the scale of minutes for challenging modes, which remains perfectly tractable for a task that needs to be performed only once and before deployment.%
}

\begin{table}
  \centering
  \caption{Approximate solving time for the different modes of the inheritance evaluation~(\cref{sec:ttw_evaluation_sched}).
  \capt{Time expressed in seconds; all computation performed on a commodity laptop.}}
  \label{table:solvingTimes}
  {\smaller \input{\TablePath/solvingTimes.csv}}
  \vspace{-5pt}
\end{table}

\vspace{-10pt}
% -----------------------------------------------------------------------------
\section{Performance of \TTnet}
\label{sec:ttw_evaluation_implem}
% ------------------------------------------------------------------------------

After the evaluation of the \TTW scheduler~(\cref{sec:ttw_evaluation_sched}), we now consider the performance of our \TTnet implementation, described in \cref{subsec:implem_ttnet}.

% ------------------------------------------------------------------------------
\subsection{Memory Utilization}

First, we consider the memory utilization induced by storing the scheduling tables in the nodes' memory.
For a given operation mode, the entire schedule contains the task offsets, the message offsets and deadlines, the round starting times, and the allocations of messages to rounds~(\cref{table:ttw_inputs_outputs}).
In addition, nodes must know the task periods and the mode hyperperiod to compute the absolute start time of the tasks and rounds.

Since we dedicate the execution of tasks and the wireless communication to different processors~(\cref{sec:ttw_implementation}), the memory cost for storing the schedule can be splitted.
On the application side, we must store the task offsets and periods, which are required to know when to execute the tasks; \ie 2 variables per task.
On the communication side, we must store the mode hyperperiod and the rounds information, \ie the offset and allocation of the rounds scheduled within the mode's hyperperiod; \ie $(\nslotsmax+1)$ variables per round.
The message deadlines are not required at runtime and do not need being stored.
As a result, we can generally estimate that the scheduling tables represent tens to hundreds of variables per mode for each processor.

\squarepar{%}
  \fakepar{Conclusion}
  Our application and communication processors feature 64\kB~\cite{msp432} and 4\kB\cite{CC430F6137} of RAM, respectively. Thus, considering an average size of two\bytes per variable, storing the scheduling tables represent a significant overhead and limits the scalability of the system, in particular on the communication processor.
  This limitation would be significantly relaxed with newer platforms, which commonly feature 256\kB of RAM~\cite{nRF52840}.%
}

% ------------------------------------------------------------------------------
\subsection{\TTnet Model}
\label{subsec:model}

\squarepar{%}
  As discussed in \cref{sec:ttw_implementation}, we implement \TTnet using \baloo, which allows to derive a precise model of
  (i)~the execution time of a communication round and
  (ii)~the time spent with the radio turned on, which correlates with the energy consumed for communication.
  Estimating the communication time is necessary to synthesize the schedules since the scheduler must know how long the rounds last.
  This model should be as tight as possible not to ``waste'' time and thus minimize the end-to-end deadlines schedulable by \TTW, but it must be a safe upper-bound in order to prevent deadline misses.
  This section presents our \TTnet model and derives the theoretically achievable performance in terms of minimal message latency and the energy savings expected from using rounds.%
}

Let $\app.\delta$ denote the latency of an application \app. This latency represents the delay for a complete execution of \app; that is, the completion of all tasks in \app.\predG. Let $\app.c$ be a \emph{chain} in \app.\predG.
A chain is defined as a path of \app.\predG starting with a task without predecessor and ending with a task without successor.%
%
\footnote{For example, $(\tau_2, m_2, \tau_4)$ is a chain of \predG in \cref{fig:precedence_graph}.}
%
The minimum achievable latency for a single message in \TTW is the length of a round composed of only one slot, denoted $\Tround(L,1)$ where $L$ is the payload size. Thus $\app.\delta$ is lower-bounded by
\begin{align}
\label{eq:min_deadline}
\app.\delta \;
	& \geq \; \max_{\app.c \,\in\, \app.\predG}
		\left(
			\; \sum_{\tau \, \in \, \app.c} \tau.e \,+\, \sum_{m \, \in \, \app.c} \Tround(L,1) \;
		\right)
\end{align}

\begin{remark}
  By comparison, the best possible guarantee for the latency of a single message provided by  \DRP~(\cref{ch:drp}) is of the order of $2*\Tround(L,\nslotsmax)$.
  Since $\Tround(L,\nslotsmax) \approx \nslotsmax*\Tround(L,1)$, \TTW reduces the minimal guarantee on message latency by a factor of approximately $2*\nslotsmax$.
  For a relatively small number of slots per round, such as $\nslotsmax=5$, this represents an order of magnitude improvement.
  This difference stems from the loose coupling between the task and message schedules in \DRP, whereas \TTW statically schedules all tasks and messages.
\end{remark}

\afterpage{
\begin{figure}
\centering
\includegraphics[scale=1]{Tslot}
\caption{%
Break-down of a communication round.
\capt{%
At the slot level, the colored boxes identify phases where the radio is on.
In the ``idle'' phase, the radio is turned off in practice, but this idle time depends on each node's distance to the initiator.
To estimate the energy saving of rounds (\cref{fig:energy_ratio}), we assume that the radio stays on for the whole time of \Tglossy, as specified in~\cref{eq:Ton}.
}
}
\label{fig:Tslot}
\end{figure}}

A round \Tround is composed of up to $(\nslotsmax+1)$ slots in which Glossy floods~\cite{ferrari2011Glossy} are executed.
An entire slot completes in time $\Tslot$, decomposed into
\begin{equation}
  \Tslot = \Twakeup + \Tstart + \Tglossy + \Tgap
\end{equation}
The composition of a slot in our implementation is detailed in~\cref{fig:Tslot}.
First, all nodes wake up (\Twakeup) and switch on their radio (\Tstart).
Then the message flood starts. We denote by \Thop the time required for one protocol step, \ie a one-hop transmission. The total length of the flood is
%
\begin{align}
\Tglossy = (H+2N-1)*\Thop
\end{align}
with $H$ the network diameter and $N$ the number of times each node transmits each packet.%
%
\footnote{Glossy achieves more than 99.9\% packet reception rate using $N =2$~\cite{ferrari2011Glossy}.}
%
\Thop is itself divided into
%
\begin{align}
\Thop = \Td + \Tcal + \Theader + \Tpayload
\end{align}
where \Td is a radio delay, and \Tcal, \Theader and \Tpayload are the transmission times of the clock calibration message, the Glossy header and the message payload, respectively.
With a bit rate of \Rbit, the transmission of $L$\bytes takes
%
\begin{align}
T(L) = 8L/\Rbit
\end{align}
Once the flood is completed, some gap time \Tgap is necessary to process the received packet.
This time is used (among other things) to execute \baloo's \texttt{on\_slot\_post()} callback, where the received messages are written into \bolt.
We divide \Tslot into \Ton and \Toff, which denote the time spent with radio on and off, respectively.
%
\begin{align}
\Toff &\,=\,
	\Twakeup + \Tgap \\
\nonumber
\Ton(L) &\,=\,
	\Tstart + \\
\label{eq:Ton}
  & \qquad (H+2N-1) * \left( \Td + 8(\Lcal + \Lheader + L)/\Rbit \right) \\
\Tslot(L) &\,=\,
  \Toff + \Ton(L) \\
\Tround(L)
	&\,=\,
	\Tslot(\Lbeacon) + B*\Tslot(L) + \Tpreprocess
\end{align}

Sending beacons is necessary to let the nodes know about the current state of the system; \ie which mode is executing and ``how far'' is the system in the scheduling table. Without that information, it is impossible for a failing node to recover and resume its normal operation.
Moreover, beacons prevent message collisions by guaranteeing that the nodes always know the system's state when a round starts.
In a design \emph{without} round, each message transmission should be preceded by its own beacon to provide the same guarantees. Thus, the transmission time for \nslots messages of size $L$, denoted $\Tworound(L)$, would take
%
\begin{align}
\Tworound(L) =  B*( \, \Tslot(\Lbeacon) + \Tslot(L) \, )
\end{align}
%
We can then derive the relative energy savings $E$ granted by using a round-based design, which we compute as $E= (\Tworoundon - \Troundon)/\Tworoundon$.

\afterpage{
\begin{figure}
  \begin{subfigure}{\linewidth}
    \centering
    \href{\ttwfig{Figure-14}}{%
    \includegraphics[scale=1]{T=f(H,B)}}
  \end{subfigure}
  \begin{subfigure}{\linewidth}
    \centering
    \href{\ttwfig{Figure-14}}{%
    \includegraphics[scale=1]{Overhead=f(H,B)}}
  \end{subfigure}
  \caption{Example values of round length (top) and protocol overhead (bottom) computed using the \TTnet model~(\cref{subsec:model}).
  The protocol overhead is computed as the percentage of time spent to send the beacons relative to the overall communication time for a round containing \nslots slots.
  Payload is set to 16\bytes and we use $N = $2 transmissions in the Glossy floods~\cite{ferrari2011Glossy}.}
  \label{fig:TTWmodel}
\end{figure}
}

The complete \TTnet model is available in Appendix~(\cref{appendix:ttw_artifacts}). We use this model to compute the round length \Tround and the energy savings $E$ for different values of number of slots per rounds (\nslots), message payload size ($L$), network diameter $H$, and number of transmissions in Glossy floods ($N$).
Selected results are shown in \cref{fig:TTWmodel,fig:energy_ratio}.
\linebreak
For example, with $N$ set to 2, it takes less than 100\ms to complete a 10-slot round sending 16-bytes messages over a 4-hop network~(\cref{fig:TTWmodel}, top).

% ------------------------------------------------------------------------------
\subsection{Model Validation}

\squarepar{%}
  We now evaluate the runtime execution of our implementation and aim to validate our \TTnet model.
  In particular, it is important that the round length model gives safe upper-bounds since the \TTW scheduler relies on the model to schedule messages and tasks: if a round overruns, this may delay the execution of subsequent tasks and cause deadline misses.
  We test our \TTnet implementation for different number of slots per round \nslots and payload size $L$, we measure the round length and radio-on time experienced by the different nodes in the network, and we compare the results with the \TTnet model.%
}

\fakepar{Evaluation scenario}
We program the network to execute, one round with \nslots slots, followed by \nslots rounds with one slot.
For each of these rounds, we collect the round length and the radio-on time. Both values are measured in software (\ie the measurement is implemented in the firmware) and use a 32\kHz timer, leading to a measurement accuracy of about 30\us.

\begin{table}
  \centering
  \caption{\triscale parameters for the experimental validation of \TTnet's model}
  \label{table:ttw_triscale_param}
  {\smaller \input{\TablePath/triscale_param.csv}}
\end{table}

\fakepar{Experiment design}
We design the evaluation using the \triscale framework (introduced in \cref{ch:triscale}). The evaluation parameters are listed in \cref{table:ttw_triscale_param}.
Our evaluation scenario is terminating (there is a finite task to accomplish); thus there is no need to test for convergence.
The round length evaluation aims to validate that the \TTnet model is a safe upper-bound; thus, we use the maximum measured round length across all nodes as metric for a run.
For the same reason, we choose a large KPI (95th percentile) and a high confidence level (95\%), which leads to a minimal number of 59 runs per series.
To investigate the reproducibility of the results, we choose the median and a 75\% level of confidence for the variability scores, leading to a minimal number or 3 series.
To evaluate the average savings provided by using communication rounds, we use the median values across nodes as metric.
We perform the evaluation on FlockLab~\cite{FlockLab}, an indoor testbed located in an office building. It has been shown that the experimental conditions on FlockLab exhibits weekly seasonal components~(\cref{subsec:network_profiling}); therefore, to avoid biasing our evaluation, we perform our series of runs using a span of one week, during which we schedule randomly 60 runs per set of parameters. We test our \TTnet implementation using 5, 10, and 30 slots per round, and payloads of 8, 16, and 64\bytes.
The three series of tests were performed between May and October 2019.
The KPI values from our evaluation are listed in~\cref{table:KPIs}.

\afterpage{
\begin{figure}
  \centering
  \href{\ttwfig{Figure-15}}{%
  \includegraphics[scale=1]{energy_savings}}
  \caption{Relative radio-on time savings by using rounds compared to single messages.
  \capt{The energy savings induced by a round-based design grow with the number of number of slots per round (X-axis). Conversely, these savings become less significant as the payload size increases (lighter colors).
  The diamonds show our evaluation KPIs and thus estimate, with a probability of 95\%, the average energy savings expected in 95\% of the test runs. $H = 4$, $N = 2$.}}
  \label{fig:energy_ratio}
\end{figure}}

\begin{remark}
  \squarepar{%}
  Observe that certain values in~\cref{table:KPIs} are reported with a {\ssymbol{1}} or {\ssymbol{2}} symbol.
  The {\ssymbol{1}} marks series where \triscale independence test fails; this indicates that the metric data do not appear to be \iid and therefore the KPI value loose its predictive power (\ie it does not allow to infer what is the expected performance).
  However, in our evaluation, the autocorrelation plots show no significant differences between the series that passes the test and those that do not~(data available in~\cref{appendix:ttw_artifacts}).
  Moreover, the round length KPI values are almost the same in all series.
  Together, these two facts increase our confidence in the results and suggests that the reported KPIs are robust estimates of the expected performance.\\
  The {\ssymbol{2}} marks series where we could not collect enough data in order to compute the KPIs. This appended in Series 3 due to construction work taking place in the FlockLab building, where many test runs were lost due to sporadic power outages.
  In both cases, the table shows the maximum round length or minimum energy savings metric values obtained across all the runs in the series.%
  }
\end{remark}

\fakepar{Results -- Round length}
The results for the round length are extremely stables~(\cref{table:KPIs}):
the differences of KPI values between series are at most one time tick ($\approx$ 30\us), which is our measurement accuracy.
Concretely, this means that, in all series, the largest round length measured by any node is essentially the same.

Furthermore, the KPI values are (i)~very close to and (ii)~consistently lower than the model. By definitions of the KPI, we can estimate with 95\% probability that (at least) 95\% of runs will yield a maximal round length smaller than the KPI value, and thus smaller than the model value.
\cref{fig:exampleSeries} (top) shows the distribution of the round length measurements from all the nodes collected during one series of 60 runs. We observe that the distribution is narrow (less than 300\us of spread), which is expected. Indeed, the \TTnet rounds are fully time-triggered; thus, the measurement differences between nodes mainly come from the difference in execution time of \baloo's end-of-round operations, which is expected to be small.

\squarepar{%}
  In our entire evaluation, there was one case where a node reported a value (77.85\ms) larger than the model (77.52\ms). This concerned only one node: in this run%
  \footnote{FlockLab test number 66992; data available in~\cref{appendix:ttw_artifacts}.}
  the second highest value reported (77.12\ms) was smaller than the model value.
  It is hard to know a posteriori what may have cause this.
  However, we argue that this one overshoot is more likely imputable to some sporadic hardware delay than due to a miscalibration of the model.%
}

\afterpage{
\begin{figure}
  \centering
  \begin{subfigure}{\linewidth}
    \centering
    \href{\ttwfig{Figure-16}}{%
    \includegraphics[scale=1]{serie2_T_round_H4_N2_L16_B5}}
  \end{subfigure}
  \begin{subfigure}{\linewidth}
      \centering
      \href{\ttwfig{Figure-16}}{%
      \includegraphics[scale=1]{serie2_T_on_round_H4_N2_L16_B5}}
  \end{subfigure}
  \caption{Distributions of round length (top) and radio-on time (bottom) measurements from all the nodes, collected in one series of 60 runs (Serie 2, $L=16$, $\nslots=5$).
  \capt{
    While the distribution of round length is very narrow, the radio-on time exhibits a much larger spread. We can see that the \TTnet model provides a generally overestimate the radio-on time, which is expected since it assumes that nodes keep their radio on for the entirety of \Tflood~\textup{(}\cref{eq:Ton}\textup{)}, which is not the case in practice: nodes turn the radio off when they have transmitted a packet $N$ times.
  }}
  \label{fig:exampleSeries}
\end{figure}}

\fakepar{Results -- Energy savings}
The energy savings results show more fluctuations than the round length, which is not surprising: (i)~the energy model is less precise and (ii)~the dynamic interference conditions affect the radio-on time, as nodes may need to keep their radio on for a longer share of \Tglossy.
\cref{fig:energy_ratio} shows the model and our energy savings KPIs together.
\cref{fig:exampleSeries} (bottom) shows the distribution of radio-on time measurements from all the nodes, collected in one series of 60 runs: nodes experience significant differences in radio-on time during a round. This is expected since nodes terminate a flood as soon as they have transmitter a packet $N$ times, which happens earlier for nodes that are closer to the initiator,

Overall, the energy savings come from the ``distribution'' of the overhead from sending beacons between the slots. Thus, the more slots (increasing \nslots) and the smaller the slots (decreasing $L$), the more radio-on time is spared by using rounds.
For a payload of 16\bytes, we obtain an average energy savings of about 30\% with only 10 slots per round.

\afterpage{
\begin{landscape}
\begin{table}
  \centering
  \caption{
  KPIs from the performance evaluation described in~\cref{sec:ttw_evaluation_implem} and corresponding model values for the \TTnet round length \Tround and energy savings $E$; other settings: $H=4$ and $N=2$.
  \capt{
    The value marked in bold corresponds to the one case where the round length KPI is larger than the model value.
    {\ssymbol{1}} marks series where \triscale independence test failed.
    {\ssymbol{2}} marks series without enough samples for computing the KPIs.
    In these two cases, reported values are the maximum round length or minimum energy savings metric values for all the runs in the series.
  }}
  \label{table:KPIs}
  {\smaller \input{\TablePath/KPIs.csv}}
\end{table}
\end{landscape}
}

\fakepar{Conclusion}
We validated the tightness and safeness of \TTnet round length model, which was found to be an upper-bound of the effective round length for all but one in about 14k measurements collected.
Furthermore, we showcased that, even with small beacons (2\bytes in our implementation), a round-based design yields significant reduction of radio-on time, and therefore helps minimizing the overall energy consumption~(\feature{Efficiency}).


\subsection{Algebra on a field}


\subsubsection{Image Change Detection}
\label{subsubsec:image_change_detection}

This section describes the implementation of the image change detection.
The difference computation and the averaging among all the pixels is done for every frame except the first one ($\texttt{FID} \geq 1$).
The threshold comparison and the throw detection is done for every frame after the threshold has been determined (see section \ref{subsubsec:threshold}).

% --------------------------------
\paragraph{Difference Computation}
The absolute difference pixel matrix $D$ can be calculated using equation \ref{eq:abs_diff}.
The implementation uses the OpenCV function \texttt{cv::absdiff} to calculate the per-element absolute difference between the two pixel matrices and saves it into \texttt{cv\_abs}, as shown in appendix \ref{app:throw_detection} on line \ref{lst:ln:abs_diff} \cite{opencv_ooa_absdiff}.

\begin{equation}
  D = |I_\text{FID} - I_\text{FID-1}| \quad\quad \text{with} \quad\quad \text{FID} \geq 1
  \label{eq:abs_diff}
\end{equation}

\begin{tabular}{rl}
  $D =$ & absolute difference pixel matrix \\
  $I =$ & image pixel matrix \\
\end{tabular}
\\

% --------------------------------------
\paragraph{Average among all the pixels}
The mean absolute difference $\overline{\text{MD}}$ can be calculated using equation \ref{eq:mean_diff}.
The implementation uses the OpenCV function \texttt{cv::sum} to return the sum of array elements for each channel independently, as shown in appendix \ref{app:throw_detection} on line \ref{lst:ln:mean_diff}.
Since the Baumer \texttt{BayerRG8} pixel format consists of only one channel, the zeroth element is used \cite{opencv_ooa_sum}.

\begin{equation}
  \overline{\text{MD}} = \frac{1}{w\cdot h} \cdot \sum\limits_{i=1}^h \sum\limits_{j=1}^w D_{i,j}
  \label{eq:mean_diff}
\end{equation}

\begin{tabular}{rl}
  $\text{MD} =$ & mean absolute difference \\
  $D =$ & absolute difference pixel matrix \\
  $w =$ & width of the image in px \\
  $h =$ & height of the image in px \\
\end{tabular}
\\

% --------------------------------------------------
\paragraph{Threshold Comparison and Throw Detection}
Listing \ref{lst:throw_detection} shows the implementation of the threshold comparison and the throw detection.
Due to the specific implementation, it is possible to detect a single frame change.
This means that the image changes between two consecutive frames and then stays the way it is (e.g. sudden change of the ambient light).
Such a glitch is not a valid throw and shall therefore be ignored (see line \ref{lst:ln:glitch_removal}).
Figure \ref{subfig:algorithm_example_1} shows that a valid throw of an object would create at least two changes between individual frames.
The first one by entering and the second one by leaving the frame.

As long as no throw is detected, the current Baumer \texttt{Buffer} object is released after each processed frame (see listing \ref{lst:buffer_release}).
Whenever a glitch is removed, the size of the Baumer image buffer (\texttt{BS}) is reduced by one.
This is due to the fact that no reference to past \texttt{Buffer} objects is kept.
Such a reference is necessary to release the respective buffer entry.
It would be easy to solve this by keeping track of at least one past \texttt{Buffer} object.
However, this is not necessary, provided that the buffer size is large enough.

\clearpage

\begin{lstlisting}[style=C++, caption={Throw detection and glitch removal}, label=lst:throw_detection]
  if (mean_diff >= threshold) {
      if (!throw_bgn) {
        throw_bgn_idx = frame_id;
        throw_bgn = true;
      }
  } else {
    if (throw_bgn) {
      throw_end_idx = frame_id;

      // Remove glitches (single frame changes)
      if ((throw_end_idx - throw_bgn_idx) == 1) {(*\label{lst:ln:glitch_removal}*)
        throw_bgn = false;
      } else {
        throw_end = true;
      }
    }
  }
\end{lstlisting}

% BUG: Should not be released directly but with a delay of one!
\begin{lstlisting}[style=C++, caption={Release of the filled Baumer \texttt{Buffer} object}, label=lst:buffer_release]
  if (!throw_bgn) {
    pBufferFilled->QueueBuffer();
  }
\end{lstlisting}


\section{Related Work}
\label{sec:related-work}
% different classes of CHC solvers:
A significant body of previous work has presented solvers for
different classes of Constrained Horn Clauses, or finding inductive
invariants of programs that correspond to solutions of CHCs.
% solving linear systems:
\impact attempts to verify a given sequential procedure by iteratively
selecting paths and synthesizing invariants for each path. This
approach corresponds to solving a recursive linear CHC
system~\cite{mcmillan06}.

% interprocedural verification:
Previous work also proposed a verifier for recursive
programs~\cite{heizmann10}.
%
The proposed approach selects interprocedural paths of a program and
synthesizes invariants for each as nested interpolants.
%
Such an approach corresponds to attempting to solve a recursive CHC
system $S$ by selecting derivation trees of $S$
and solving each tree.

% solving recursive systems:
Previous work has proposed solvers for recursive systems that, given a
system $S$, attempt to solve $S$ by generating and
solving a series of recursion-free unwindings of $S$.
%
In particular, \eldarica attempts to solve each unwinding
$S'$ by reducing to and solving body-disjoint systems~\cite{rummer13a,rummer13b}.
%
\duality attempts to avoid solving all derivation-trees (i.e
body-disjoint systems) by using lazy annotation~\cite{bjorner13}.
%
Other optimizations select derivation trees to solve using
symbolic analogs of Prolog evaluation with
tabling~\cite{jaffar09,mcmillan14}.
%

\whale attempts to verify sequential recursive programs by generating
and solving hierarchical programs, which correspond to recursion-free CHC
systems~\cite{albarghouthi12b}.
%
To solve a particular recursion-free system, \whale solves a linear
inlining of the input using a procedure named
\vinta~\cite{albarghouthi12a}.
%
In general, the linear inlining may be exponentially larger than the
input.

\sys is similar to the recursion-free CHC approaches given above in
that it reduces the problem to solving a CHC system in a
directly-solvable class.
%
\sys is distinct in that it reduces to solving Clause-Dependent
Disjoint (CDD) systems.
%
As discussed in \autoref{sec:overview}, the class of CDD systems is a
superset of classes used by the approaches above. CDD systems can
also be solved directly.

\sys solves general CHC systems using the same strategy as proposed by
the above approaches.
%
Specifically, it solves a series of recursion-free unwindings of the
original system, and tries to synthesize a general solution from the
recursion-free solutions.

Previous work describes solvers for non-linear Horn clauses over
particular theories.
%
In particular, verifiers have been proposed for recursion-free systems
over the theory of linear arithmetic~\cite{komuravelli14}.
%
Because the verifier relies on quantifier elimination, it is not clear
if it can be extended to richer theories that support interpolation,
such as the combination of linear arithmetic with uninterpreted
functions.
%
Other work describes a solver for the class of \emph{timed pushdown
systems}, a subclass of CHC systems over the theory of linear real
arithmetic~\cite{hoder12}.
%
Unlike these approaches, \sys can solve systems over any theory that
supports interpolation.

% DAG inlining:
DAG inlining attempts to generate compact verification conditions for
hierarchical programs~\cite{lal-qadeer15}.
%
\sys attempts to solve recursion-free CHC systems by reducing them to
compact CDD systems.
%
Because hierarchical programs and recursion-free CHC systems are
closely related, algorithms that operate on hierarchical programs
correspond to algorithms that operate on recursion-free Horn Clauses.
%
However, it is not apparent whether such algorithms can be used directly
to synthesize solutions.


\chapter{Introduction}

The goal of this Capita Selecta is to investigate the possibilities for a fast MATLAB based implementation of the Block MLDU algorithm.\\

\noindent High performance solvers are usually written in languages like C/C++ because they are compiled, avoiding the sometimes costly step of the interpreter. Languages like MATLAB are dynamically typed and interpreter based, which make them great for prototyping purposes.\\

\noindent The Block MLDU algorithm shows great possibilities, but the lack of a high performance implementation makes it prohibitive to use for large matrices. This is a problem because research projects sometimes encounter very large matrices that need to be solved with the Block MLDU algorithm.\\

\noindent This project tries to alleviate the problem by investigating the performance bottlenecks of a MATLAB based implementation and provide workarounds for them. This should result in a much faster implementation without requiring the extra work associated with a full C/C++ version.\\

\noindent The biggest advantage of this workflow is that the time required to implement a workaround for a bottleneck will be much lower in MATLAB than in C/C++, making it easier to try different approaches to the problems. The lessons learned at this stage will still be useful when the code does finally get ported to C/C++.\\

\noindent The biggest disadvantage to sticking to MATLAB is that the interpreter will always provide some overhead compared to C/C++. The hope is that this overhead will be small compared to the other bottlenecks encountered.

\newpage

\section{The Block MLDU algorithm}

The Block MLDU algorithm is very comparable to the well known LU decomposition. The main difference between the Block MLDU algorithm and LU decomposition is the "block" nature of the splitting.

\subsection{Example}

A simple example will be provided to highlight the differences between LU and Block MLDU. Let matrix $A$ be $4 \times 4$:\\

$
\hspace{20mm} A =
\left\lbrack\begin{array}{rrrr}
           1&           0&           1&           0\\
           2&           1&          -1&           0\\
           0&          -1&           0&           1\\
          -2&           0&           1&           3
\end{array}\right\rbrack
$
$
\hspace{30mm} s =
\left\lbrack\begin{array}{rrr}
           2&           1&           1
\end{array}\right\rbrack
$\\

\noindent As stated by row $s$, matrix $A$ will first be split using a $2 \times 2$ block, followed by two $1 \times 1$ blocks.\\

\noindent \textbf{Step one:}\\

$
\left\lbrack\begin{array}{rr|rr}
          D1&          D1&          U1&          U1\\
          D1&          D1&          U1&          U1\\ \hline
          L1&          L1&          M1&          M1\\
          L1&          L1&          M1&          M1
\end{array}\right\rbrack
$
$
\hspace{10mm} L1 =
\left\lbrack\begin{array}{rr}
           0&          -1\\
          -2&           0
\end{array}\right\rbrack
$
$
\hspace{6mm} D1 =
\left\lbrack\begin{array}{rr}
           1&           0\\
           2&           1
\end{array}\right\rbrack
$
$
\hspace{6mm} U1 =
\left\lbrack\begin{array}{rr}
           1&           0\\
          -1&           0
\end{array}\right\rbrack
$\\

$
Schur1 = L1 D1^{-1} U1 =
$
$
\left\lbrack\begin{array}{rr}
           3&           0\\
          -2&           0
\end{array}\right\rbrack
$
$
\hspace{20mm} A - Schur1 =
\left\lbrack\begin{array}{rrrr}
           1&           0&           1&           0\\
           2&           1&          -1&           0\\
           0&          -1&  \textbf{-3}&  \textbf{1}\\
          -2&           0&   \textbf{3}&  \textbf{3}
\end{array}\right\rbrack
$\\

\noindent \textbf{Step two:}\\

$
\left\lbrack\begin{array}{rr|r|r}
          D1&          D1&          U1&          U1\\
          D1&          D1&          U1&          U1\\ \hline
          L1&          L1&          D2&          U2\\ \hline
          L1&          L1&          L2&          M2
\end{array}\right\rbrack
$
$
\hspace{10mm} L2 =
\left\lbrack\begin{array}{r}
           3
\end{array}\right\rbrack
$
$
\hspace{18mm} D2 =
\left\lbrack\begin{array}{r}
           -3
\end{array}\right\rbrack
$
$
\hspace{10mm} U2 =
\left\lbrack\begin{array}{r}
           1
\end{array}\right\rbrack
$\\

$
Schur2 = L2 D2^{-1} U2 =
$
$
\left\lbrack\begin{array}{r}
           -1
\end{array}\right\rbrack
$
$
\hspace{12mm} A - Schur1 - Schur2 =
\left\lbrack\begin{array}{rrrr}
           1&           0&           1&           0\\
           2&           1&          -1&           0\\
           0&          -1&          -3&           1\\
          -2&           0&           3&   \textbf{4}
\end{array}\right\rbrack
$\\

\noindent \textbf{Step three:}\\

$
\left\lbrack\begin{array}{rr|r|r}
          D1&          D1&          U1&          U1\\
          D1&          D1&          U1&          U1\\ \hline
          L1&          L1&          D2&          U2\\ \hline
          L1&          L1&          L2&          D3
\end{array}\right\rbrack
\\$\\

\noindent \textbf{Result:}\\

$
L =
\left\lbrack\begin{array}{rrrr}
           0&           0&           0&           0\\
           0&           0&           0&           0\\
   \textbf{0}& \textbf{-1}&          0&           0\\
  \textbf{-2}&  \textbf{0}&  \textbf{3}&          0
\end{array}\right\rbrack
$
$
\hspace{10mm} D =
\left\lbrack\begin{array}{rrrr}
   \textbf{1}&  \textbf{0}&          0&           0\\
   \textbf{2}&  \textbf{1}&          0&           0\\
           0&           0&  \textbf{-3}&          0\\
           0&           0&           0&   \textbf{4}
\end{array}\right\rbrack
$
$
\hspace{10mm} U =
\left\lbrack\begin{array}{rrrr}
           0&           0&   \textbf{1}&  \textbf{0}\\
           0&           0&  \textbf{-1}&  \textbf{0}\\
           0&           0&           0&   \textbf{1}\\
           0&           0&           0&           0
\end{array}\right\rbrack
\\$\\

$
\\
A = (L + D)D^{-1}(D + U)
$


\chapter{Conclusion}\label{chap:conclusion}

We looked at how the give token and random token orders solved the two main problems: Deadlocks and infinite executions. We discussed that there are three different ways to introduce a token, two of them solve both problems. The table token does not solve the deadlock problem because there is the possibility that no agent takes the token off the table. This is illustrated in the following table:

\begin{table}[h!]
\centering
\resizebox{\textwidth}{!}{%
\begin{tabular}{|l|l|l|l|}
\hline
 & table token & random token & give token \\ \hline
empower token & \begin{tabular}[c]{@{}l@{}}solves infinite executions \\ $\longrightarrow$ Proposition 1 \\ does not solve deadlocks\end{tabular} & \begin{tabular}[c]{@{}l@{}}solves infinite executions\\ $\longrightarrow$ Proposition 1 \\ solves deadlocks \\ $\longrightarrow$ Proposition 4 \end{tabular} & \begin{tabular}[c]{@{}l@{}}solves infinite executions\\ $\longrightarrow$ Proposition 1 \\ solves deadlocks \\ $\longrightarrow$ Proposition 4 \end{tabular} \\ \hline
force action token & \begin{tabular}[c]{@{}l@{}}solves infinite executions \\ $\longrightarrow$ Proposition 2 \\ does not solve deadlocks\end{tabular} & \begin{tabular}[c]{@{}l@{}}solves infinite executions\\ $\longrightarrow$ Proposition 2 \\ solves deadlocks \\ $\longrightarrow$ Proposition 3  \end{tabular} & \begin{tabular}[c]{@{}l@{}}solves infinite executions\\ $\longrightarrow$ Proposition 2 \\ solves deadlocks \\ $\longrightarrow$ Proposition 3 \end{tabular}  \\ \hline
\end{tabular}%
}
\end{table}

This means that there are positive results with the introduction of a token based order. In every case, if an agent that has found a plan gets the token, the goal will be reached in a finite number of steps.

For future work, the way the token changes the search of a plan should be researched. With tokens, the search tree of a plan might have a smaller width because the agents can be prevented from acting. The tree will also have a deeper depth because the agents each have a new action of handing the token to the next player.\\
We also did not look at how a tokenized planning task changes the existence of i-strong policies. It is unclear if some planning problems become unsolvable through the tokenize function.

There could also be future research in researching the fairness of the tokens.\\
Another field of research for the future could be impatient players and the table token execution order. An impatient player will wait for the other player to take the token first, but only for a limited amount of time. For this we would need to extend the formalism since we cannot model time or a waiting agent explicitly.