\hypertarget{structIir_1_1Butterworth_1_1BandShelf}{}\doxysubsection{Iir\+::Butterworth\+::Band\+Shelf$<$ Filter\+Order, State\+Type $>$ Struct Template Reference}
\label{structIir_1_1Butterworth_1_1BandShelf}\index{Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$@{Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$}}

{\ttfamily \#include $<$Butterworth.\+h$>$}

Inheritance diagram for Iir\+::Butterworth\+::Band\+Shelf$<$ Filter\+Order, State\+Type $>$\+:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[height=2.434783cm]{structIir_1_1Butterworth_1_1BandShelf}
\end{center}
\end{figure}
\doxysubsubsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item
void \mbox{\hyperlink{structIir_1_1Butterworth_1_1BandShelf_a0de40c55dae63d23127cf4dd21bcf050}{setup}} (double sample\+Rate, double center\+Frequency, double width\+Frequency, double gain\+Db)
\item
void \mbox{\hyperlink{structIir_1_1Butterworth_1_1BandShelf_aa3f716cf9d393509c2caefb9e10ae8cc}{setup}} (int req\+Order, double sample\+Rate, double center\+Frequency, double width\+Frequency, double gain\+Db)
\item
void \mbox{\hyperlink{structIir_1_1Butterworth_1_1BandShelf_a43e02ec9dcfcd382b87ce20bc48f2ee2}{setupN}} (double center\+Frequency, double width\+Frequency, double gain\+Db)
\item
void \mbox{\hyperlink{structIir_1_1Butterworth_1_1BandShelf_a96cc173942cd6789b5aff603b37e5b2f}{setupN}} (int req\+Order, double center\+Frequency, double width\+Frequency, double gain\+Db)
\end{DoxyCompactItemize}

\doxysubsubsection{Detailed Description}
\subsubsection*{template$<$int Filter\+Order = 4, class State\+Type = Direct\+Form\+II$>$\newline
struct Iir\+::\+Butterworth\+::\+Band\+Shelf$<$ Filter\+Order, State\+Type $>$}

\mbox{\hyperlink{namespaceIir_1_1Butterworth}{Butterworth}} Bandshelf filter\+: it is a bandpass filter which amplifies at a specified gain in dB the frequencies in the passband.
\begin{DoxyParams}{Parameters}
{\em Filter\+Order} & Reserves memory for a filter of the order Filter\+Order \\
\hline
{\em State\+Type} & The filter topology\+: \mbox{\hyperlink{classIir_1_1DirectFormI}{Direct\+FormI}}, \mbox{\hyperlink{classIir_1_1DirectFormII}{Direct\+Form\+II}}, ... \\
\hline
\end{DoxyParams}

\doxysubsubsection{Member Function Documentation}
\mbox{\Hypertarget{structIir_1_1Butterworth_1_1BandShelf_a0de40c55dae63d23127cf4dd21bcf050}\label{structIir_1_1Butterworth_1_1BandShelf_a0de40c55dae63d23127cf4dd21bcf050}}
\index{Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$@{Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$}!setup@{setup}}
\index{setup@{setup}!Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$@{Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$}}
\doxyparagraph{\texorpdfstring{setup()}{setup()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily template$<$int Filter\+Order = 4, class State\+Type  = Direct\+Form\+II$>$ \\
void \mbox{\hyperlink{structIir_1_1Butterworth_1_1BandShelf}{Iir\+::\+Butterworth\+::\+Band\+Shelf}}$<$ Filter\+Order, State\+Type $>$\+::setup (\begin{DoxyParamCaption}\item[{double}]{sample\+Rate,  }\item[{double}]{center\+Frequency,  }\item[{double}]{width\+Frequency,  }\item[{double}]{gain\+Db }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}

Calculates the coefficients with the filter order provided by the instantiation
\begin{DoxyParams}{Parameters}
{\em sample\+Rate} & Sampling rate \\
\hline
{\em center\+Frequency} & Centre frequency of the passband \\
\hline
{\em width\+Frequency} & Width of the passband \\
\hline
{\em gain\+Db} & The gain in the passband \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{structIir_1_1Butterworth_1_1BandShelf_aa3f716cf9d393509c2caefb9e10ae8cc}\label{structIir_1_1Butterworth_1_1BandShelf_aa3f716cf9d393509c2caefb9e10ae8cc}}
\index{Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$@{Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$}!setup@{setup}}
\index{setup@{setup}!Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$@{Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$}}
\doxyparagraph{\texorpdfstring{setup()}{setup()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily template$<$int Filter\+Order = 4, class State\+Type  = Direct\+Form\+II$>$ \\
void \mbox{\hyperlink{structIir_1_1Butterworth_1_1BandShelf}{Iir\+::\+Butterworth\+::\+Band\+Shelf}}$<$ Filter\+Order, State\+Type $>$\+::setup (\begin{DoxyParamCaption}\item[{int}]{req\+Order,  }\item[{double}]{sample\+Rate,  }\item[{double}]{center\+Frequency,  }\item[{double}]{width\+Frequency,  }\item[{double}]{gain\+Db }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}

Calculates the coefficients
\begin{DoxyParams}{Parameters}
{\em req\+Order} & The actual order which can be less than the instantiated one \\
\hline
{\em sample\+Rate} & Sampling rate \\
\hline
{\em center\+Frequency} & Centre frequency of the passband \\
\hline
{\em width\+Frequency} & Width of the passband \\
\hline
{\em gain\+Db} & The gain in the passband \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{structIir_1_1Butterworth_1_1BandShelf_a43e02ec9dcfcd382b87ce20bc48f2ee2}\label{structIir_1_1Butterworth_1_1BandShelf_a43e02ec9dcfcd382b87ce20bc48f2ee2}}
\index{Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$@{Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$}!setupN@{setupN}}
\index{setupN@{setupN}!Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$@{Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$}}
\doxyparagraph{\texorpdfstring{setupN()}{setupN()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily template$<$int Filter\+Order = 4, class State\+Type  = Direct\+Form\+II$>$ \\
void \mbox{\hyperlink{structIir_1_1Butterworth_1_1BandShelf}{Iir\+::\+Butterworth\+::\+Band\+Shelf}}$<$ Filter\+Order, State\+Type $>$\+::setupN (\begin{DoxyParamCaption}\item[{double}]{center\+Frequency,  }\item[{double}]{width\+Frequency,  }\item[{double}]{gain\+Db }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}

Calculates the coefficients with the filter order provided by the instantiation
\begin{DoxyParams}{Parameters}
{\em center\+Frequency} & Normalised centre frequency (0..1/2) of the passband \\
\hline
{\em width\+Frequency} & Width of the passband \\
\hline
{\em gain\+Db} & The gain in the passband \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{structIir_1_1Butterworth_1_1BandShelf_a96cc173942cd6789b5aff603b37e5b2f}\label{structIir_1_1Butterworth_1_1BandShelf_a96cc173942cd6789b5aff603b37e5b2f}}
\index{Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$@{Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$}!setupN@{setupN}}
\index{setupN@{setupN}!Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$@{Iir::Butterworth::BandShelf$<$ FilterOrder, StateType $>$}}
\doxyparagraph{\texorpdfstring{setupN()}{setupN()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily template$<$int Filter\+Order = 4, class State\+Type  = Direct\+Form\+II$>$ \\
void \mbox{\hyperlink{structIir_1_1Butterworth_1_1BandShelf}{Iir\+::\+Butterworth\+::\+Band\+Shelf}}$<$ Filter\+Order, State\+Type $>$\+::setupN (\begin{DoxyParamCaption}\item[{int}]{req\+Order,  }\item[{double}]{center\+Frequency,  }\item[{double}]{width\+Frequency,  }\item[{double}]{gain\+Db }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}

Calculates the coefficients
\begin{DoxyParams}{Parameters}
{\em req\+Order} & The actual order which can be less than the instantiated one \\
\hline
{\em center\+Frequency} & Normalised centre frequency (0..1/2) of the passband \\
\hline
{\em width\+Frequency} & Width of the passband \\
\hline
{\em gain\+Db} & The gain in the passband \\
\hline
\end{DoxyParams}

The documentation for this struct was generated from the following file\+:\begin{DoxyCompactItemize}
\item
iir/Butterworth.\+h\end{DoxyCompactItemize}


\chapter*{Introduction}   \addcontentsline{toc}{chapter}{Introduction} \label{intro}

The beginning of the computing era is inherently linked with the use of computing devices for numerical algorithms.
While the first implementations had been carried out in assembly language, the FORTRAN language then provided a means for efficiently abstracting the underlying hardware.
%However, even today the implementation of mathematical algorithms is accomplished in \emph{FORTRAN-style}, i.e. numbers are manipulated at an array level.
This approach to programming is still common for the implementation of numerical algorithms today:
Mathematical primitives such as polynomials or functions are in one way or another represented as an array of numbers already in user code.
The mathematical meaning of these numbers is, if at all, only implicitly deducible for a programmer.

Abstraction facilities provided by modern programming languages such as C++ are much more powerful and mature compared to an abstraction at an array level.
However, implementation guidelines in numerical textbooks written in the past cannot reflect the current state-of-the-art in programming,
thus algorithms are often still implemented without making use of additional abstraction mechanisms.
One of the reasons is that first attemps of using object-oriented programming have reported poor performance due to additional indirections at runtime.
However, this issue (and several others) have been adressed by language improvements and/or programming techniques.

The aim of {\ViennaMath} is to show by example that preserving the mathematical abstraction by means of a symbolic math engine can make code much more readable without sacrificing performance.
Even though {\ViennaMath} makes use of object-oriented programming, certain calculations and optimizations can already be carried out already at compile time, thus eliminating many expensive indirections at runtime.
Consequently, the process of hand-tuning code, i.e.~the use of information already available at compile time, is shifted from the user to the compiler.
This increases productivity without reducing performance.

%% Mention related work

%% Why ViennaMath is 'better':


\begin{document}

\chapter{Discussion}

\label{chapter:discussion}

This chapter discusses the results stated in Chapter~\ref{chapter:results}, compare and contrast them with the Wei et al.\ study~\cite{wei_kinect_calibration}. For each of the primary tasks, namely Stationary, Steps, and Walk, the discussion will consist of how the average coordinates and joints distances change with different Kinect placements. The spread of distances values over different joint types in each task will also be discussed.

It is worth noting that Wei et al only studied Stationary and Steps tasks, with near parallel and 45$^{\circ}$ apart Kinects. The current work will compare results with those in Wei et al's study where appropriate~\cite{wei_kinect_calibration}.

\section{Stationary}
\label{sec:discussion_stationary}

This section discusses results in the Stationary task.

The Stationary task shows best results when the Kinects are parallel to each other and worst when they are 90$^{\circ}$ apart. All measures of distances follow the same trend, from $\Delta x$ to $\Delta z$ (See Figure~\subref*{fig:stationary_coordinates}). The results show that coordinates distances in the Stationary task increases with increasing angle between Kinects.

In general, the $\Delta x$ values are the highest, then $\Delta z$ and $\Delta y$. This shows that the tracking algorithm makes the largest errors in the coordinates transformation of the x axis and least errors in the y axis. A feasible explanation would be that the heights of both Kinects are the same, and the participants are not moving on the y axis.

The standard deviations of $\Delta d$ in the average case is within the range of standard deviations across different Kinect placements. This shows that in the Stationary task the coordinates distances are consistent both within and between different Kinect placements.

The average joints distances are smallest for joints in the torso, namely the head, hips, knees, neck, shoulders, and spine (See Figure~\subref*{fig:stationary_joints}). These joints appear to have similar coordinates distances. On the contrary, joints in the arm and foot regions have higher coordinates distances. The researcher speculates that the results are influenced by Kinect's internal performance; it produces more reliable and consistent results in the torso compared to other regions of the body.

All average coordinates distances are also higher for the left joints compared to right joints. In summary, right hand side joints in the torso have the smallest coordinates distances, whereas left hand side joints in the arm and foot regions have the highest coordinates distances. The researcher also speculates that these results are due to the Kinect itself, which produces higher quality depth map in the torso.

Wei et al reported lower values compared to the current study~\cite{wei_kinect_calibration}. In their Stationary task (Average Difference before Movement) with Parallel ($4.25^{\circ}$) apart Kinects, the coordinates distances are $0.00$, $1.00$, and $2.00$ cm for $\Delta x$, $\Delta y$, and $\Delta z$, respectively. The $\Delta d$ will be $2.24$ cm, which is lower than the $3.52$ cm (See Table~\ref{table:stationary_coordinates_values}) found in the current study. In their same task with $45^{\circ}$ ($44.37^{\circ}$) apart Kinects, the coordinates distances are $1.00$, $1.00$, and $1.50$ cm for $\Delta x$, $\Delta y$, and $\Delta z$, respectively. The $\Delta d$ will be $2.06$ cm, also lower than the $6.95$ cm found in the current study.

The average coordinates distances over time in the Stationary task with different Kinect placements are near constant (See Figure~\subref*{fig:stationary_coordinates_over_time}). The result verifies the claim that the tracking algorithm produces persistent results over time when the target is stationary, regardless of Kinect placements.

\section{Steps}
\label{sec:discussion_steps}

This section discusses results in the Steps task.

The coordinates distances in the Steps task are higher compared to those in the Stationary task for every type of Kinect placements. The increase in coordinates distances is anticipated, because the task requires the participants to walk around in the environment, causing them to move closer or further away from the cameras. The movements will lead to increased likelihood of the tracking algorithm making more errors compared to when the participants are standing still. The following section will comment and explain the similarities and differences in the results between the Steps and Stationary tasks.

The Steps task also shows best results when the Kinects are parallel to each other and worst when they are 90$^{\circ}$ apart. All measures of distances follow the same trend, from $\Delta x$ to $\Delta z$ (See Figure~\subref*{fig:steps_coordinates}). Alike to the results in the Stationary task, the studies for the Steps task show that coordinates distances in also increase with increasing angle between Kinects.

For all Kinect placements, the $\Delta x$ values are the highest, then $\Delta z$ and $\Delta y$. The results support the findings in the Stationary task. This shows that the tracking algorithm produces consistent coordinates transformation across different tasks.

The standard deviation of $\Delta d$ within each type of Kinect placement is lower than the same setup in the Stationary task. The standard deviations of $\Delta d$ in the Stationary task are $1.33$, $2.67$, $4.45$, and $3.95$ cm, for Parallel, 45$^{\circ}$, and 90$^{\circ}$ apart Kinects, respectively. On the other hand, the Steps task yields $0.90$, $1.92$, $3.46$, and $9.32$ for the same measures. These values suggest that the algorithm produces less variations within different Kinect configurations in the Steps task compared to the Stationary task. However, the Steps task has a higher standard deviation of $\Delta d$ in the average case, compared to that of in the Stationary task. Even though the system shows smaller variations within different Kinect placements in the Steps task, it produces large variations between different conditions of Kinect placements. The system copes better to changes in Kinect placements in the Stationary task than in the Steps task.

There is a less visible difference in the coordinates distances between joints in the torso and other body regions (See Figure~\subref*{fig:steps_joints}), but it remains when examined closely. However, the pattern that left joints have higher coordinates distances is still very noticeable. Overall, the variations of the distances in each joint are still large, except for the $\Delta y$ distances. The $\Delta y$ distances and their standard deviations remain small.

Wei et al also reported lower results compared to the current study. In their Steps task (Average Difference after Movement) with Parallel ($4.25^{\circ}$ apart) Kinects, the coordinates distances are $2.00$, $1.28$, and $3.78$ cm for $\Delta x$, $\Delta y$, and $\Delta z$, respectively. The $\Delta d$ will equal to $4.46$ cm, which is lower than the $6.87$ cm (See Table~\ref{table:steps_coordinates_values}) found in the current study. In their same task with $45^{\circ}$ ($44.37^{\circ}$) apart Kinects, the coordinates distances are $4.28$, $1.64$, and $5.28$ cm for $\Delta x$, $\Delta y$, and $\Delta z$, respectively. The $\Delta d$ will equal to $6.99$ cm, also lower than the $12.80$ cm found in the current study.

The average coordinates distances over time in the Steps task with different Kinect placements shows rapid changes when the participant follows the instruction and takes a step to a new position (See Figure~\subref*{fig:steps_coordinates_over_time}). This is expected, because the participant will move towards a position, away from the center, that leads to less accurate coordinate transformation. When the participant isn't moving, the coordinates distances over time remain constant, as shown in the Stationary task.

\section{Walk}
\label{sec:discussion_walk}

This section discusses results in the Walk task.

The coordinates distances in the Walk task are higher compared to those in the Stationary and Steps tasks for every type of Kinect placements. The increase in coordinates distances in the Walk task has the same cause as previously mentioned in section~\ref{sec:discussion_steps} for the Steps task. Because walking movements are even larger than the stepping and stationary movements, the results in the Walk task will be higher compared to the other two tasks.

Similar to the previous two tasks, the results in the Walk task show smaller coordinates distances with parallel Kinects, and increasing distances with larger angles (See Figure~\subref*{fig:walk_coordinates}). Likewise, the $\Delta x$ values are still the highest, followed by $\Delta z$ and $\Delta y$. $\Delta y$ is still nearly invariant to changes in Kinect placement (See Figure~\ref{fig:walk_joints}). Its standard deviation is the lowest compared to the standard deviations of all other distances measures, in all the tasks seen so far (Stationary, Steps, and Walk) with all different Kinect placements (Parallel, $45^{\circ}$, and $90^{\circ}$ apart Kinects).

The average and standard deviation of $\Delta y$ is the only value that hardly changes across different tasks and Kinect placements. In the Stationary task, the average $\Delta y$ is $3.07$ cm, with a standard deviation of $1.60$ cm. In the Walk task, the average $\Delta y$ only increases to $4.81$ cm, with a standard deviation of $1.42$ cm. The average $\Delta y$ in the Steps task is in between these values. The results can be found in Table~\ref{table:stationary_coordinates_values}, Table~\ref{table:steps_coordinates_values}, and Table~\ref{table:walk_coordinates_values}. These support the argument that $\Delta y$ is steady throughout the tracking process, regardless of tasks and Kinect placements.

In both the Steps and Walk tasks, the standard deviation of coordinates distances within each Kinect placement is small compared to the same value in the average case. The same relationship is not observable in the Stationary task. The researcher argues that increasing angle between multiple Kinects have a larger impact in non-stationary tasks.

There are common patterns in the joints distances between different tasks. Firstly, all three tasks show higher distances values for the left joints. Furthermore, there is a difference between joints in the torso and other body regions, to varying degrees across tasks. In additional, all three tasks show that $\Delta x$ and $\Delta z$ are closer to each other than to $\Delta y$.

Wei et al did not run experiments containing longer, continuous walking tasks. The researcher has not found results for a similar task in the literature.

The average coordinates distances over time in the Walk task with different Kinect placements shows even more rapid changes when the participant walks diagonally and around the perimeter (See Figure~\subref*{fig:walk_coordinates_over_time}). There appears to be a correlation between the distance moved from the starting position and the amount of coordinates differences between multiple skeletons. The further away a person is from the starting position, the larger errors the coordinates transformation will produce.

\section{Stationary, Steps, Walk}
\label{sec:discussion_scenarios}

The tasks Stationary, Steps, and Walk are ordered in increasing complexity, where the former requires zero movements, and the latter requires constant movements. The studies show that coordinates distances increase with increasing complexity of the tasks (See Figure~\ref{fig:results_coordinates_kinect_all}). The relationship can be attributed to increasing amount of joints movements and turning of the shoulder, of which the coordinates transformation uses for calculating the angle between the Kinects and the person. In addition, when averaged over different Kinect placements, the coordinates distances for different joints in Stationary, Steps, and Walk tasks are roughly the same, but there is a distinct difference between coordinates of the left and right joints (See Figure~\ref{fig:results_joints_kinect_all}). This observation may attribute to the fact that the studies are done using Kinects which are placed within the positive $90^{\circ}$ angle, and the differences between the left and right joints may disappear if the results are averaged over Kinect placements that are within the negative $90^{\circ}$ angle.

The Kinect placements of parallel, 45$^{\circ}$ and 90$^{\circ}$ are ordered in increasing angle. The studies show that coordinates distances increase with increasing angle (See Figure~\ref{fig:results_coordinates_task_all}). The angle between Kinects correlates to the degree of rotation used in the transformation of multiple skeletons. The larger the angle is between Kinects, the skeletons will be rotated more, hence producing larger coordinates differences. The joints distances follow a similar pattern as shown in the plot with different tasks averaged over different Kinect placements. The left joints also have larger coordinates differences compared to the right joints, but there is less variation between joints, and the averages are slightly smaller (See Figure~\ref{fig:results_joints_kinect_all}).

When varying only either the complexity of the tasks or the angle of Kinect placement, the results will show similar trends. In short, the more complex the task or the larger the angle between multiple Kinects, the worse results will be. The scenario where $\Delta d$ is the smallest is the Stationary task with parallel Kinects ($3.52$ cm), and the scenario where $\Delta d$ is the highest is the Walk task with 90$^{\circ}$ apart Kinects ($32.38$ cm). However, the average cases of varying only the task or Kinect placement show promising results, $14.10$ cm and $10.57$, respectively.

The worse average cases show that the $\Delta d$ distances are around $20$ cm (See Figure~\ref{fig:results_three_coordinates_joints}). This boundary is still within the personal space, or the space where only one person is most likely to exist. The results show preliminary success in tracking people using transformed 3D coordinates to find their spatial positions and joints.

The coordinates distances over time for the three tasks with different Kinect placements show that the larger the movements, which in turn correspond to the complexity of the task, the larger the coordinates differences will be observed (See Figure~\ref{fig:results_three_coordinates_over_time}). The argument also holds true for every joint in the human body (See Figure~\ref{fig:results_three_joints_over_time}).

\section{Obstacle and Interactions}
\label{sec:discussion_obstacle}

The Obstacle and Interactions tasks demonstrate that the tracking algorithm will acquire as complete as possible joints coordinates for the same person from multiple Kinects when the person is under partial occlusion. The system will attempt to construct an average skeleton to its best under the particular constraints of the viewing angle. This has implications in scenarios where one Kinect has a clear view of a target and another Kinect does not. In such cases, the system can still utilize the Kinect which has the most personal information for tracking the target's movement. A use case would be a two-players interactive gaming system where the players are provided with feedback consisting of the other player's position behind an obstacle, such as a wall. Another example would be a group of robots jointly search a person with particular appearance features in a large, occluded environment. The current system shows that it can reconstruct a person's average skeleton when they reappear from occlusion. Under the assumption that people are not constantly under occlusion, the current system can be used to capture a person's motion or behaviour over time, providing other applications an easy way to collect human data.

\section{Summary}

The researcher summarizes the findings as follows:

\begin{enumerate}
  \item $\Delta x$, $\Delta y$, $\Delta z$, and $\Delta d$ increase with increasing complexity of tasks, from remaining stationary to walking.
  \item $\Delta x$, $\Delta y$, $\Delta z$, and $\Delta d$ increase with increasing angle between different Kinects
  \item The torso (head, hip, knee, neck, shoulder, and spine) is more reliable than other body regions.
  \item $\Delta d$ is less than $15$ cm on average over different tasks and Kinect placements. The value is within the margin of personal space, thus allowing additional algorithms which takes personal body regions as inputs to be incorporated to the current system.
\end{enumerate}

\section{Criticisms}
\label{sec:discussion_criticisms}

The data collection, or the logging, procedure was flawed due to software failure. The logger did not log the same length of stationary movement for all participants and different Kinect placements. The lengths of the results in the Stationary task do not all equal to ten seconds as described in Chapter~\ref{chapter:studies}.

The data cleaning process is also not rigorous. In both the Steps and Walk tasks, the participants remained in the same positions between instructions. The skeletons data for when the participants remained in the same positions should be discarded before doing any further analysis investigating the effects of task complexity and Kinect placements.

The analysis did not include significance testings on the hypotheses. Therefore, the results are only descriptive, and inferential. The studies are carried out with Kinects placed at the same height and tilting angle, hence the results do not fully describe the limitations of the current tracking algorithm. Furthermore, the studies only use two Kinects. The relationship between the number of Kinects and the accuracy of the tracking algorithm is not investigated.

The current approach relies the Kinect BodyFrame. Unlike some algorithms in previous research which use color and depth data, the current system is limited to tracking up to six people due to the constraint of the Kinect BodyFrame API.

\section{Future Work}
\label{sec:discussion_future_Work}

Future work can be divided into two areas, the application and user studies.

There are some implementations which have not been completed. Firstly, the server should listen at another port if the current one is in use. Secondly, the application should have a recalibration button which prompts the tracker to initiate the calibration process, in case the tracking algorithm mismatches the skeletons and does not correct it. In the current client framework, the client will keep the Kinect running before it establishes a connection with the server. There is no visual feedback about the connection status to the server, except some simple output on the console. In future revisions, the client can provide more visual feedback. The server waits for a number of Kinects to be connected; the number is specified by the end user through the setup dialog. However, it may be more convenient if the server can accept any number of Kinect connections, without using a predefined count.

The application has the potential to incorporate other algorithms which uses the joint information from the tracking results, because the average coordinates distances ($\Delta d$) are within the personal space. The algorithms may be gesture recognition or motion tracking. Furthermore, the current application can send image patches around the joints to other applications for different purposes. A potential application would be to track the blood oxygenation level of the users during occlusion.

The current work is based on Wei et al.\'s coordinate transformation algorithm. Future work can compare the current methodology with other tracking and calibration techniques, in particular, the average coordinates distances when using different approaches for the same set of tasks. The current calibration method requires all joints of a person to be visible to all Kinects in the scene. For example, an alternative for calibration would be based on triangulation of static objects in the scene, instead of relying on the shoulder joints of the targets. The alternative would give more flexibility to the system, allowing anyone to enter and leave the scene freely without recalibrating. In addition, the tradeoffs between running the tracking algorithm locally and distributed can be studied.

The current work discards the cost of using multiple Kinects. An interesting extension would be to derive a cost function which determines the optimal placement of the Kinects in a known environment for obtaining the largest possible field of view, while minimizing the average coordinates distances.

The current studies examine the efficacy of the tracking algorithm with only two people; however, real world environments are usually more chaotic, and many scenarios consist of groups of more than two people. The system should demonstrate the same capabilities with more people. In addition, the results from the user studies can be further analyzed using significance testings, such as using ANOVA to compare the coordinates distances between different tasks and Kinect placements. The different types of Kinect placements used in the experiments can include different heights and tilting angles. In addition, further studies should be done in realistic, cluttered environments such as outdoor areas and office space.

\end{document}


\section{Introduction}

\subsection{Purpose}

\newcommand\nadt[2]{\item \texttt{#1} - #2}

The \modna{} library is a collection of arithmetic operations
on a range of mathematical objects:
\begin{enumerate}
\nadt{Integer}{machine size integers}
\nadt{BigInteger}{integers of arbitrary size}
\nadt{Float}{machine oriented floating point numbers}
\nadt{Complex}{complex numbers}
\nadt{Polar}{2D vectors in polar representation}
\nadt{Fraction}{fractions of arbitrary objects}
\nadt{Vector}{vectors of arbitrary size}
\nadt{Matrix}{}
\nadt{Polynomial}{}
\nadt{Root}{roots of polynomials}
\nadt{PhysicalValue}{numbers equipped with physical units}
\end{enumerate}
It includes algorithms for
special functions,
fourier transform,
interpolation,
root finding,
random numbers
as well as routines for generating \LaTeX{} output and
function plots.

All datatypes presented except of the floating point numbers
allow for exact computation.
That's why one can no longer talk of a library
that is specialized for numerical analysis.
Though any instantiations of one
of the composed datatypes with floating point numbers
requires algorithms specialized for the problems
of numerical operations.

There are many libraries around
that deal with mathematical operations,
computer algebra and function plotting,
so what is the sense of a new library of this kind?
The reason is simply to provide
a mathematical tool in the static type safe, logical, comfortable
but efficient programming environment of Modula 3.
Even expensive computer algebra tools like Maple or Mathematica
or wide-spread numeric tools like MatLab
can't provide static type safety.
Instead they declare the missing static typing as advantage
but in practice it proves to be a source of many programming bugs.
Same applies for scripting languages like Python and Perl.
C++ and Ada may seem to be alternatives because they provide
overloading of operators.
In fact this technique is syntactic sugar
and if heavily used it let the user completely lose control
of which functions are actually called.
The unlogical syntax of C prohibits Java and again C++.

The only alternative for programming languages
suitable for mathematical computations or
programming in general is Haskell and
similar functional languages.
Haskell provides static type checking
with easy accessible polymorphism
while short programming texts
but reducing the user's control over
time and memory consumption.

\subsection{History}

Modula 3 numerical analysis library was started in 1996 and
maintained sinced then by Harry George.
Many people contributed to it
but for many years there was only few or even no further activity on it.
In 2003 I (Henning Thielemann) started on this code
and restructured the modules to be more generic.
E.g. now it is possible to combine each data type with almost each other,
say polynomials with complex numbers as coefficients.
Module templates are used to achieve this flexibility
while being efficient in runtime but unfortunately not in code size.

The restructured \modna{} library preserves all of the previous functions
but it is no longer compatible with the original version.
I hope that the greater flexibility will excuse this.

\subsection{Present}

Because of the heavy restructuring of the library
this document is currently not conform
to the contents of the modules, unfortunately.
Also some funny words may have been produced by stupid
find/replace of the old module names by the new one.

The library is still evolving and
due to the currently small user base
no one can foresigh if the API is appropriate
in the general case.
That's why everything should be handled with care and scepticism.
Still the API may change in order to get a better structure!

\subsection{Future}

For the documentation I suggest the usage
of a documentation extraction tool
to simplify updates of modules and their documentations.
This tool should capable of typesetting formulas
with the quality of \LaTeX{}.

Further extensions of the library will contain interfaces
to \hyperref{LAPACK}{http://www.netlib.org/}
to make use of well tested state-of-the-art
numeric linear algebra algorithms
as well as to the function plotting package
\hyperref{plplot}{http://plplot.sourceforge.net/}.
This way we can make use of advantages in this libraries
while accessing them through a safe and comfortable interface.


\section{Abstract}
Emergency departments (EDs) in hospitals are usually under pressure to achieve a
target amount of time that describes the arrival of patients and the time it takes
to receive treatment.
For example in the UK this is often set as 95\% of patients to be treated within
4 hours.
There is empirical evidence to suggest that imposing targets in the ED results in
gaming at the interface of care between the EMS and ED.
If the ED is busy and a patient is stable in the ambulance, there is little
incentive for the ED to accept the patient whereby the clock will start ticking
on the 4 hour target.
This in turn impacts on the ability of the EMS to respond to emergency calls.

This study explores the impact that this effect may have on an ambulance's
utilisation and their ability to respond to emergency calls.
More specifically multiple scenarios are examined where an ambulance service needs
to distribute patients between neighbouring hospitals.
The interaction between the hospitals and the ambulance service is defined in a
game theoretic framework where the ambulance service has to decide how many patients
to distribute to each hospital in order to minimise the occurrence of this effect.
The methodology involves the use of a queueing model for each hospital that is used
to inform the decision process of the ambulance service so as to create a game for
which the Nash Equilibria can be calculated.


\newcommand{\st}{subprogram\xspace}

\section{Introduction}\label{sect:intro}
%Genetic programming is a general algorithmic technique in which the principles of neo-Darwinian evolution are translated  to algorithmic form in order to generate programs of specific functionality.
Our general goal is to improve the level of program complexity that genetic programming(GP) can routinely evolve\cite{koza1992genetic}. This is toward fulfilling its potential to occupy a significant niche in the ever advancing field of program synthesis\cite{weimer2010automatic, rinard2012example, gulwani2010dimensions}.  Behavioral genetic programming (BGP) is an extension to GP that advances toward this compelling goal\cite{krawiecGecco2014,KrawiecBPS2016}. The intuition of the BGP paradigm is that, during evolutionary search and optimization, information characterizing programs by behavioral properties that extend beyond how accurately they match their target outputs. This information from a program ``trace'' can be effectively integrated into extensions of the algorithm's fundamental mechanisms of fitness-based selection and genetic variation.

To identify useful subprograms BGP commonly exploits program \textit{trace} information (first introduced in \cite{krawiec2013pattern} which is a capture of the output of every subprogram within the program for every test data point during fitness evaluation.  %Consider a simple program, which computes the mathematical function $f(x) = \ln(x1) + (x1 - x2)$ and the sample data set in Table \ref{table:sample_data}. Conventional genetic programming will only consider the outputs for each data point: $\ln(3) + 1$, $\ln(5) + 2$, and compare those values to the desired output.  However, each subtree has its own output, which is ignored by the genetic programming process.
%\begin{table*}[ht]
%\centering
%\begin{tabular}{ c c | c }
%\hline\hline
%$x_{1}$ & $x_{2}$ & $y$ \\ [0.5ex]
%\hline
%3 & 2 & 3 \\
%5 & 3 & 4 \\[1ex]
%\hline
%\end{tabular}
%\caption{Sample data set.}
%\label{table:sample_data}
%\end{table*}
%
%The collection of the outputs on each subtree for all of the data points is called the trace.  For the program in Figure \ref{figure:gp_tree} and the fitness cases in Table \ref{table:sample_data}, the trace is shown in Table \ref{table:sample_trace}.
%
%\begin{table*}[ht]
%\centering
%\begin{tabular}{ c c c c c c }
%\hline\hline
%$s_{1}$ & $s_{2}$ & $s_{3}$ & $s_{4}$ & $s_{5}$ & $s_{6}$ \\ [0.5ex]
%\hline
%3 & $\ln(3)$ & 3 & 2 & 1 & $\ln(3)$ + 1 \\
%5 & $\ln(5)$ & 5 & 3 & 2 & $\ln(5)$ + 2 \\[1ex]
%\hline
%\end{tabular}
%\caption{The trace of the program from Figure \ref{figure:gp_tree} for the data set in Table \ref{table:sample_data}.}
%\label{table:sample_trace}
%\end{table*}
The trace is stored in a matrix where the number of rows is equal to the number of test suite data points, and the number of columns is equal to the number of subtrees in a given program. % There is no set order of the columns, although here they are presented in the depth first traversal order of the subtrees that produce the values.
The trace captures a full snapshot of all of the intermediate states of the program evaluation.

BGP then uses the trace to estimate the merit of each subprogram by treating its column as a feature (or explanatory variable) in a \textit{model regression} on the desired program outputs.  The accuracy and complexity of the model reveals how useful the subprograms are. The model, if it has feature selection capability, also reveals  specific subprograms within the tree that are partially contributing to the program's fitness.  BGP uses this information in two ways. It can integrate \textit{model error }and \textit{model complexity} into the program's fitness. Second, it maintains an archive of the most useful subtrees identified by modeling each program and uses them in an \textit{archive-based crossover}. BGP has a number of variants that collectively yield impressive results, see \cite{krawiecGecco2014,KrawiecBPS2016}.

%It demonstrates that we should look at how a program behaves during execution because partial behavior, if it can be identified and isolated, can be used to direct GP toward better program synthesis.
%  move previous sentence to conclusion? redundant here?
\newcommand{\ct}{$T^c$}
%BGP is a paradigm rich with possible extensions to explore, many of which could give deeper insight into genetic programming synthesis methods.

In this work,  we explore various extensions to the BGP paradigm that are motivated by 2 central topics: \begin{inparaenum}

\item \textbf{The impact of bias from the inference model on useful subprogram identification and program fitness.}  Model techniques and even the implementation of the same technique can differ in inductive  \textit{bias}, i.e. error from assumptions in the learning algorithm, e.g. implementation of a ``decision tree'' algorithm. These differences, in turn, impact which subprograms are inserted/retrieved from the BGP archive and the model accuracy and model complexity factors that are integrated into a program's fitness. Therefore, we investigate how much BGP is sensitive to model bias. %in terms of its impact on estimations of merit for subprograms and the ensuing integration of this estimates in program fitness and archiving and crossover.
\textit{How important is it which subprograms the model technique selects and how accurate a model is? }  We answer these questions by comparing BGP competence under 2 different implementations of decision tree modeling which we observe have different baises. Our investigation contrasts feature identification and model accuracy under the two implementations.

\item \textbf{``Plays well with others?''}: \textbf{Alternate ways to identify useful subprograms}. BGP uses the trace matrix from a program implying all the subprograms of one program are treated as a set of features during modeling. This means that feature selection and subprogram fitness estimation occurs within the program context.  Essentially, each subprogram is juxtaposed with ``relatives'' -- its parent, neighbors and even child in GP tree terms. Does this context provide the best means of identifying useful subprograms? It may not. Crossover moves a subprogram into another program so, to work most effectively, it should explore recombinations of subprograms that \textit{work well in other subprograms and programs in the population}. We examine this idea by concatenating program traces from a set of programs, not solely one program. This demands a new measure of fitness to reflect subprogram participation in the model as a means of archive selection and program fitness. We examine concatenation of the entire population and sub-populations based on fitness to ask whether fitter programs with concatenated traces are more effective than an open playing field. i.e. the entire population of subprograms.
  %Perhaps program context does not reflect how well a subprogram ``\textit{plays with other subprograms in the population}''.
\end{inparaenum}

Our specific demonstration focus herein is  symbolic regression. We choose SR because it remains a challenge and have good benchmarks~\cite{benchmarks} so it allows us to measure progress and extensions. It also has real world application to system identification and, with modest modification, machine learning regression and classification.  In passing, we replicate BGP logic, making our project software available with an open source license.

We proceed as follows. We start with related work in Section~\ref{sec:related-work}. In Section~\ref{sect:foreground} we provide descriptions of our methods of comparison and investigation. In Section~\ref{sect:experiments} we provide implementation and experimental details and results. Section~\ref{sect:conc} concludes and mentions future work.


\documentclass[../main/thesis_msc.tex]{subfiles}
\externaldocument{../appendex1.tex}
\begin{document}

\chapter{Scientific analysis}
In the course of this chapter, the results from the images obtained from the LOFAR data are explained.
\section{Spectral index mapping}
\paragraph{Overview of method used:} Spectral index mapping involves several steps. One may use the task \verb|COMB| in \verb|AIPS|\footnote{\url{http://www.aips.nrao.edu/cgi-bin/ZXHLP2.PL?COMB}} or the task \verb|immath| in  \verb|CASA|\footnote{\url{https://casa.nrao.edu/docs/taskref/immath-task.html}}. However, it is not possible to obtain a satisfactory error distribution map using these methods. Hence, I obtained the spectral index map and the error map using the method described in this section. \\

\noindent The maps being used to obtain spectral index are of different frequencies, and hence have different inherent beam sizes. Hence, the map with higher spatial resolution is re-sampled to the resolution (lower) of the other map. This is generally done using the \textbf{convolution} operation. The Full Width at Half Maximum (FWHM) for both the synthesized beams values are converted to standard deviation using the formula valid for Gaussian distributions (Equation \ref{gaussian}).

\begin{equation}
\sigma=\frac{\mathrm{FWHM}}{2\sqrt{2\textrm{ln}2}}.
\label{gaussian}
\end{equation}

The synthesized beams for the images that have been used in my case are circular. Equation \ref{convolution} shows the convolution formula used. $\sigma_{\textrm{New kernel}}$ is the standard deviation for the new Gaussian kernel that is to be used for convolving the higher resolution image. $\sigma_{\textrm{Higher frequency}}$ is the standard deviation of the synthesized beam of higher frequency image. $\sigma_{\textrm{LOFAR frequency}}$ is the standard deviation of synthesized beam for the LOFAR image.

\begin{equation}
\sigma_{\textrm{New kernel}}=\sqrt{\left(\sigma_{\textrm{LOFAR frequency}}^2 - \sigma_{\textrm{Higher frequency}}^2\right)}
\label{convolution}
\end{equation}

The beam size is converted to pixel units by multiplying it with the pixel scale in the image. Once the size of the convolution kernel is known in pixel units, we Gaussian smooth (convolve) the higher resolution image to have the resolution of the lower resolution image. The images are usually of different sizes, and hence, to ensure that both the images are of the same size, bi-linear interpolation method using the `resize' function in sci-kit library of python can be used. Spectral index is calculated using the assumption that the intensity, I $\sim \nu^{-\alpha}$. The error maps are estimated using standard Gaussian error propagation.

\subsection{IC\,342}
For IC\,342, the spectral index map is made using the images at 1.49~GHz frequency \citep{2015A&A...578A..93B} and the LOFAR map (at 145~MHz), as shown in Figure \ref{ic342_spectr}. The UV data from the VLA map uses the baselines from 200~$\lambda$ to 5200~$\lambda$. Though the LOFAR visibilities also have several short baselines due to the dense core, the shorter baselines need to be clipped so that both the maps are sensitive to the same angular scales. The images thus obtained are gridded to have the same grid using the \verb|AIPS| task \verb|OHGEO|. The LOFAR map is calibrated using the flux density scale as described in \citet{2012MNRAS.423L..30S}, while the VLA map was calibrated using the flux density scale as described in \citet{2017ApJS..230....7P}. The spectral index map is then computed pixel by pixel. The maps presented in this paper are made using a five-sigma filter on the noise levels for both the input images. Both the maps from the two frequencies have a resolution of 45~arcsec. The images of this resolution have been used because the higher resolution images from the LOFAR map still contain several artifacts, while the 45~arcsec image can be seen to have better depiction of diffuse emission. \\

We plot the histogram showing the distribution of spectral indices values from the Figure \ref{ic342_spectr} in the Figure \ref{icsp}, and find that the median value is -0.52 for IC\,342. The binning has been done using the Freedman-Diaconis rule\footnote{According to this rule, the bin size, B = 2 $\times \frac{\textrm{IQR(x)}}{\sqrt[3]{\textrm{n}}}$, where IQR(x) is the interquartile range, and n is the number of observations in the sample $x$.}\\
\begin{figure}
  \centering
  \begin{tabular}{@{}c@{}}
    \includegraphics[scale=0.25]{13ic_Spectral.png} \\[\abovecaptionskip]
    \includegraphics[scale=0.35]{13Spectral_error_ic.png} \\[\abovecaptionskip]
  \end{tabular}
  \caption{\textit{Above:} The spectral index map of IC\,342 obtained from 1.4~GHz VLA map and 145~MHz LOFAR map at 45" resolution. It uses values above 5$\times$ the noise level (5$\sigma$) from the VLA and LOFAR maps. The contours on the map are 0.2, 0.4, 0.6, 0.8, 1, 0 $\times$ -1. \textit{Below:} The error map for the spectral index map. The contours are the same  for both the images.}
	\label{ic342_spectr}
\end{figure}

\begin{figure}
\centering
\includegraphics[scale = 0.5]{spectral__histogram_cumu_ic.png}
\caption{The spectral index distribution for IC\,342 for the spectral index map shown in Figire \ref{ic342_spectr}. The binning is done according to  Freedman-Diaconis Rule \citep{Freedman1981}}
\label{icsp}
\end{figure}

\subsection{NGC\,628}
For NGC\,628, the spectral index maps depicted in Figure \ref{ngc_spectr}, have been made using the maps from frequency 3~GHz using VLA data and 141~MHz LOFAR map. Due to the absence of UV calibrated data, we convolve both LOFAR and VLA maps to have the same resolution of 20~arcsec. The images are then regridded using \verb|OHGEO| task in \verb|AIPS| and the spectral index map is made with 3-sigma flux densities (3 times the noise level in the individual maps) for both the images. The 20~arcsec image was chose for the LOFAR map because it has a higher Signal to Noise ratio than the other images, while curbing the artifacts. The VLA image used had a resolution of 18~arcsec, and is convolved to have a resolution of 20~arcsec. \\

In the Figure \ref{ngcsi}, one can take a look at the histogram showing the distribution of spectral index values from the Figure \ref{ngc_spectr}. The median value for the spectral index values is -0.86, which is the steepness expected from synchrotron emission.

\begin{figure}
	\centering
    \begin{tabular}{@{}c@{}}
	\includegraphics[scale = 0.45]{ngc_3sig_13.png} \\[\abovecaptionskip]
	\includegraphics[scale = 0.45]{ngc_3sig_13_err.png}\\[\abovecaptionskip]
	\end{tabular}
	\caption{\textit{Above:} The spectral index map for NGC\,628 obtained from 3~GHz VLA map and 145~MHz LOFAR map at 20" resolution. This is a 3-sigma spectral index map. The contours on the map are 0.2, 0.4, 0.6, 0.8, 1, 0 with unit contour level of -1. \textit{Below:} The error map for the spectral index map. The contours are the same for both the images.}
	\label{ngc_spectr}
\end{figure}

\begin{figure}
\centering
\includegraphics[scale = 0.45]{spectral__histogram_cumu.png}
\caption{This histogram shows the distribution of the spectral index values for NGC\,628. The median lies at -0.86 (expected value).}
\label{ngcsi}
\end{figure}

\section{Interpretation of spectral index maps}

One can learn about the process involved in the galaxy with the help of spectral index maps. The Figure \ref{therm} shows various process involved in a galaxy at low radio frequencies that influence the spectrum can be seen. The spectral index for synchrotron emission is -0.7 and that of thermal emission is -0.1. Thermal absorption is a process that is important especially in star forming galaxies, and explains the flat spectrum when very low frequencies are considered. If one considers the spectral index values between frequencies $\nu_2$ and $\nu_3$, a flat spectral index is seen. This flatness is because of the thermal emission at the $\nu_3$ frequency. If one considered the spectral index between frequencies $\nu_1$ and $\nu_2$, the flat spectral index is explained by thermal absorption.

\begin{figure}
\centering
\includegraphics[scale = 0.5]{SED_corr.png}
\caption{Spectral Energy Distribution (SED) for the three process important in star forming galaxies like IC\,342. The red dashed line indicates synchrotron emission, and has a spectral index value ($\alpha$) of -0.7. The thermal emission is indicated by the blue dotted line, and has a spectral index value of -0.1. Thermal absorption process is indicated by the green curve. This process is responsible for the flattening of the spectral index at low radio frequencies. Based on the two frequencies considered to obtain the spectral index, the flattening and steepening of the spectrum can be explained.}
\label{therm}
\end{figure}

\subsection{IC\,342}
The Figure \ref{ic342_spectr} shows the spectral index map obtained for IC\,342. The edges and the inter-arm regions of IC\,342 can be seen to have a steep spectral index. This means that the flux density for the galaxy in the VLA map is much lower than that of the LOFAR map. This implies the presence of a higher level of the synchrotron emission that is traced at lower frequencies. A steep spectral index indicates the presence of low energy, older electrons that have traveled farther away from the spiral arms and the central region where the star formation occurs. Hence, the steep spectral index is expected at these regions.\\

Flatter spectral index (0.2 to -0.2) can be seen in the center of the galaxy. Flat spectral indices imply that the flux density values for VLA and the LOFAR maps have only a small difference. With the help of the Spectral Energy Distribution (SED), it can be argued that the flat spectral index can happen because of either an increase in the flux density of the galaxy in the VLA map because of thermal emission, or from a decrease in the flux density of the galaxy in LOFAR map because of thermal absorption.

\paragraph{Thermal emission:} To examine which process results in the flat spectral index in my case, we first try to obtain the thermal fractions required to explain such a flat spectral index. The thermal and non-thermal components are separated by assuming a constant spectral index ($\alpha_{\textrm{nth}}$) of $-$0.7 and $-$0.5 for synchrotron emission, and a thermal spectral index ($\alpha_{\textrm{th}}$) of $-$0.1 for thermal emission. The resulting thermal fractions ($f_{\textrm{th}}$) are listed in Table \ref{allph}. These fractions seem too high for a galaxy. \citet{2015A&A...578A..93B} found that the thermal fraction at $\lambda$6.2~cm is about 50\% in the central region and 20\% to 30\% in the spiral arms and 10\% or less in the inter-arm region\footnote{Although it was argued that the thermal fraction is overestimated in the spiral arms because of their method used.} at 1.49~GHz.\\

\begin{table}
\centering
        \begin{tabular}{cccccc}
        \hline\hline
             $\alpha_{\textrm{obs}}$ & $f_{\textrm{th}_{-0.7}}$ (145~MHz) & $f_{\textrm{th}_{-0.7}}$ (1490 MHz) & $f_{\textrm{th}_{-0.5}}$ (145 MHz) & $f_{\textrm{th}_{-0.5}}$ (1490 MHz)\\
            \hline
            $-$0.7 & 0\% & 0\% &-&-\\
			$-$0.6 & 9\% & 28\% &-&-\\
			$-$0.5 & 19\% & 49\% &0\% & 0\%\\
			$-$0.4 & 33\% & 67\% & 17\% & 34\%\\
			$-$0.3 & 51\% & 81\% & 39\% &61\%\\
			$-$0.2 & 72\% & 91\% & 66\% & 83\%\\
			$-$0.15 & 85\% & 96\%& 82\% & 92\%  \\
			$-$0.1 & 100\% & 100\% & 100\%& 100\%\\
            \hline
        \end{tabular}
\caption{If a spectral index for synchrotron emission is assumed as $-$0.7 and thermal emission is assumed as $-$0.1, the percentage of thermal fraction for the observed spectral index values (between frequencies of 145 to 1490~MHz, $\alpha_{\textrm{obs}}$) are obtaind ( represented as $f_{\textrm{th}_{-0.7}}$), at the two frequencies --- 145~MHz and 1.49~GHz. The same is done when the spectral index for synchrotron emission is assumed to be $-$0.5 and the thermal fraction is represented as $f_{\textrm{th}_{-0.7}}$ These values have been obtained using the code from Dr. Beck (priv. comm).}
\label{allph}
\end{table}

\citet{2017ApJ...836..185T} found that the thermal fractions in galaxies is around 10\%. If one uses this value to be the thermal fraction in IC\,342, then for the observed spectral index values of $-$0.4, $-$0.3, $-$0.2 and $-$0.15, one must assume that the synchrotron spectral index value is $-$0.63, $-$0.53, $-$0.42, $-$0.32, $-$0.21 and $-$0.16 respectively. This shows that for these spectral indices, thermal emission does not satisfactorily explain the observed flat spectral indices, as it is not physically valid according to existing models of cosmic ray electron accelaration. \\

\paragraph{Thermal absorption:} In order to see if the flat spectral index values are because of free-free absorption, the thermal map obtained from 1.49~GHz is overlaid on the spectral index map. The thermal map traces the regions of star formation activity. Hence, the regions in which the thermal flux density is higher, there is a higher Star Formation Rate (SFR). These SF regions would result in \textbf{free-free absorption}, resulting in a decrease in the flux density of the galaxy at the lower frequency.  \\

From the Figure \ref{hlaph_ic}, we can see that the higher thermal flux density region coincides with the regions of flatter spectral index. Furthermore, from \citet{ic342_3}, we know that several dense (with electron densities of around 104-105 cm$^{-3}$), and compact ($\leq$0.1~pc) H II regions are predicted to exist in the nucleus of the galaxy. These regions are known to be heated by the ionizing photons from the early-type stars. They are cooled by lines excited from collisions such as C II line of wavelength 158~$\mu$m. Free-free absorption is especially pronounced in H\,II regions as explained in Chapter 1. So, we can conclude that the LOFAR synchrotron flux density in the nuclear region is decreased due to the presence of such H\,II regions, that give rise to free-free absorption. In the Figure \ref{swr}, we can take a look at the position of the H\,II regions existing in the nucleus of the galaxy. \\
\begin{figure}
\centering
\includegraphics[scale = 0.435]{13_thermal_IC.png}
\caption{This image depicts the correlation of the flatter spectral index and the presence of thermal emission. The contours are 0.5, 5, 18, 32, 80 of the thermal map with unit contour level of 10~mJy/beam }
\label{hlaph_ic}
\end{figure}
In order to understand the correlation better, we plot the correlation between the flux densities of the thermal map with the spectral index values for each pixel. From the Figure \ref{corr_ic}, we can see that the pixels with a higher flux density of the thermal map, have a much flatter spectral index value. Thus, we can conclude that the free-free absorption regions with high star formation give rise to flat spectral index. \\
\begin{figure}
\centering
\includegraphics[scale = 0.5]{IC_corre.png}
\caption{Correlation of the thermal intensity values with the spectral index map values for IC\,342. The spectral index values are obtained by clipping the values of flux densities lower than 5$\times$ the noise level in 1.49~GHz and 145~MHz map, for each pixel. From the Figure, it is evident that regions with higher radio thermal flux density which indicate the presence of free-free absorption from star forming regions, have a flatter spectral index values. The 'tail' seen at the right hand portion showing the discrepency may be because of the missing diffuse flux density that affects spectral indices at low intensity.}
\label{corr_ic}
\end{figure}
I also plot a Far Infra Red (FIR) map of 350~nm over the galaxy, that is from the KINGFISH project (Key Insights on Nearby Galaxies: a Far-Infrared Survey with Herschel) \citep{2011PASP..123.1347K}. FIR emission comes from re-radiation by dust, which has been heated by ultra violet (UV) photons. These photons are emitted by massive and short-lived stars. The diffusion length of a CRE is much larger than the mean free path of an FIR photon, a radio continuum image would appear as a smoothed version of a FIR image. The Figure \ref{FIRic} shows the correlation of the star forming regions with that of flat spectral index, indicated by the redder regions.
\begin{figure}
\centering
\includegraphics[scale = 0.5]{13_FIR_IC.png}
\caption{The overlaid plot is the FIR map of IC\,342 at 350$\mu$m. One can notice the correlation of flatter spectral index and higher flux density of this map. The contours represent 0.2, 0.4, 0.6, 0.8, 1, 1.5, 2, 3 $\times$ 15~Jy/beam.}
\label{FIRic}
\end{figure}

\subsection{Case of missing flux}
\noindent We plot the integrated flux density within successive radii of width 0.5~arcmin and obtain the plots shown in Figure \ref{ic342_ring}. This is done for both the 20~cm map and the LOFAR map, with full UV coverage for both the maps. We find that the total flux density integrated to 10', S$_{\textrm{LOF}}$ = 4.82$\pm$0.22~Jy for the LOFAR map. For the 20~cm map, this value is S$_{\textrm{VLA}}$ = 2.26$\pm0.13$~Jy. This shows that there is a lot of missing flux in the LOFAR map, if we consider the existence of only synchrotron emission.\\
In order to figure out the amount of missing flux, we first extrapolate the flux density values obtained for IC\,342 using the values found by \citet{2017ApJ...836..185T} at higher frequencies, and obtain the spectral index as -0.76. As can be seen from figure \ref{taba}, the $\alpha$ value is extrapolated to 145~MHz, we expected flux density value is obtained, S$_{\textrm{EXP}}$ = 10.7~Jy. \\

\begin{figure}[h]
\centering
\includegraphics[scale = 0.5]{Taba_SED_values_IC342.png}
\caption{This plot shows the flux density values from previous study done for the galaxy by \citet{2017ApJ...836..185T} for IC\,342 as blue dots, with the fit shown in blue line. The green dashed line represents the extrapolated fit with the slope of -0.76. The pink star represents the flux density from the LOFAR map, and the red star represents the expected flux density for the frequency of 145~mHz.}
\label{taba}
\end{figure}

Thus, the amount of missing flux density, $\Delta$S = S$_{\textrm{EXP}} -$S$_{\textrm{LOF}} \approx$ 5.9~Jy. The missing flux density per unit beam is given by:
\begin{equation}
\frac{\Delta\textrm{S}}{\textrm{N}} = \Delta\textrm{S} \left(\frac{\textrm{Area of integration (in arcmin)} \times \textrm{cos}i}{1.13 \times \textrm{Resolution of image (in arcmin)}}\right) \approx 14~\textrm{mJy/beam},
\end{equation}
where $i$ is the angle of inclination. This value is almost 36 times the rms noise in the image. This means that a lot of the diffuse flux density is missing.\\

One explanation for the flux density to be low is thermal absorption. The inner part of IC\,342 has a high amount of thermal absorption as is seen from the flat spectral index at the center. Hence, we obtain the amount of missing flux density due to thermal absorption by obtaining the flux density value within 3' radius of the galaxy (with the galaxy's center as its center). This is done between maps that have the same UV baseline coverage with the rest of the baselines clipped, as the diffuse flux in both the maps would be missing, leading to a fair comparision between the two maps. \\

The amount of thermal absorption is obtained by extrapolating the flux density of the VLA map within 3' to obtain the expected flux density at the frequency of LOFAR, using the relation S $\propto \nu^{\alpha}$, with alpha being the spectral index (-0.5\footnote{This spectral index is taken as a combined $\alpha$ value for thermal emission and synchrotron emission.}). S$_{\text{3'}}$ is the flux density observed in the LOFAR map within the radius of 3'.
\begin{alignat}{2}
\frac{\textrm{S}_1}{\textrm{S}_2}
&= \left(\frac{\nu_1}{\nu_2}\right)^{\alpha}\\
\textrm{S}_1
&= \textrm{S}_2 \left(\frac{\nu_1}{\nu_2}\right)^{-0.5}\\
\textrm{S}_1 & =273\text{~mJy} \left(\frac{145}{1490}\right)^{-0.5} \approx 870\text{~mJy}\\
\text{S}_{\text{3'}}
&=555\text{~mJy} \\
\Rightarrow \text{Flux lost due to thermal absorption}
& \approx 300 \text{~mJy}
\end{alignat}
With the help of this correction flux density value, we can figure out the amount of flux density missing in the overall galaxy (i.e., for the galaxy upto a radius of 10').
\begin{alignat}{2}
  \textrm{Correction}
  &\approx 300\text{~mJy}\\
  \text{S}_{\textrm{EXP}}
  &=688\left(\frac{1.49}{0.145}\right)^{0.74}
  \approx 3.72\text{~Jy}&\\
  \text{S}_{\textrm{LOF}}
  &=\underbrace{1.4}_{\textbf{A}} + \underbrace{0.3}_{\textbf{B}} \text{~Jy}  \approx 1.7 \text{~Jy}& \label{lofex}\\
  \Rightarrow \Delta\text{S} &=3.72-1.7 \approx 2.02  \text{~Jy}\\
  \text{Missing flux/beam} &=\frac{\Delta\text{S}}{\text{N}}\approx 4.47\text{~mJy}&
\end{alignat}
where \textbf{A} and \textbf{B} in Equation \ref{lofex} represents the flux from my LOFAR map of the galaxy upto a radius of 10' and the thermal absorption flux density of the galaxy obtained respectively. If one considers the value of -0.5 as the value of the overall spectral index of the galaxy upto a radius of 10', then this value is reduced is \textbf{1.1~mJy}. This value of only 1.6 times the noise level.\\
\paragraph{Scale height:}The integrated flux density values for IC\,342 for successive radii in rings with a width of 0.5' (about 0.5~kpc) are obtained, with the center of the rings aligned at the center of the galaxy. The plot with the radial profile using the obtained values is shown in Figure \ref{ic342_ring}. This is done for the images of the two frequencies- 145~MHz and 1.49~GHz, with the maps made using the full UV range. We also obtain the scale lengths \footnote{The scale length is defined as the radius at which the flux density of the galaxy has fallen off by a factor of e (2.71828) from the center. The flux density can be written as the function:
\begin{center}
I=I$_0$exp$\left(^-\frac{r}{r_0}\right)$
\end{center}
Here, I$_0$ is the flux density in the center of the galaxy and $r_0$ is the scale length. Hence, when plotting lnI as a function of the radius r, the scale length is given by r$_0$ = $-\frac{1}{\textrm{S}}$, where S is the slope of the fitted linear line}for the two maps. For the LOFAR map, it is 15~arcmin, which is around 14.8~kpc. The scale height for the 20~cm map, it is 19~arcmin, which is around 18.7~kpc. Scale length shows the distance traveled by the CRE that is giving out that frequency photon. Here, an electron emitting the photon in LOFAR frequency (145~MHz) travels a distance of 14.8~kpc. Due to the longer life-time of the cosmic ray electrons that are detected using the LOFAR map, we should be able to see a longer scale length in the case of LOFAR map. However, this is not the case, which shows that the LOFAR map has less diffuse flux from the extended emission than is expected.

\begin{figure}
	%\centering
	\subfloat[]{{\includegraphics[scale = 0.5]{VLA_scale_length.png}}}
	\centering
	\subfloat[]{{\includegraphics[scale = 0.5]{LOFAR_scale_length.png}}}
	\caption{The radial profiles for the full UV range maps. \textit{Left:} The radial profile of the galaxy IC\,342 i.e., radius vs log of integrated flux density for 20~cm map. \textit{Right:} The radial profile for the LOFAR map. The bright background source for both the images has been subtracted before the integration has been performed.}
	\label{ic342_ring}
	\end{figure}

\paragraph{Comparision with spectral index maps at other frequencies:}The Figure \ref{specic} shows the spectral index values obtained between $\lambda$6.2~cm and $\lambda$20.1~cm at 25" resolution \citep{2015A&A...578A..93B}. As the wavelengths of the two maps in Figure \ref{specic} are lower, the flatness in the spectral index can be explained by thermal emission (the flux density in this case is higher for the lower wavelength--- $\lambda$6.2~cm map, resulting in a flat spectrum). The spectral index in the inter-arm regions and in the outer disk is steep, as expected, due to synchrotron emission.

\begin{figure}
\centering
\includegraphics[scale = 0.45]{icspectral.png}
\caption{This is the spectral index map obtained between $\lambda$6.2~cm and $\lambda$20.1~cm at 25" resolution. Contours show the total intensity at $\lambda$6.2 cm. It has been taken from \citet{2015A&A...578A..93B}.}
\label{specic}
\end{figure}

\subsection{NGC\,628}

\noindent The spectral index map of NGC\,628 can be seen in the Figure \ref{ngc_spectr}. The regions with flatter spectral index values are depicted in red. One can trace the presence of spiral arms in the red regions, and the outer edges of the galaxy have a steeper spectrum, sa shown by the green regions. This shows that the spiral arms have flatter spectral index which are the regions with younger recently formed stars. The steepness in the outer regions is indicative of the older electron population, where the flux density of the LOFAR map is much higher than that of the VLA map.\\

In order to study the star forming regions in NGC\,628, and understand the flattening of the various regions, we overlay an H alpha image onto the spectral index map\footnote{H-alpha emission has a wavelength of 656.28 nm in the visible spectral range. It occurs when a hydrogen electron falls from its third to second lowest energy level.}. We can see a clear correlation between the flattening of the spectrum and the H alpha region. We can also see the two arms of the galaxy that are traced by both the H alpha region and the flatter (depicted by red) in the galaxy. The steeper part of the galaxy that contains the synchrotron emission from the diffuse electrons can be seen between the two arms. This shows that most of the star formation takes place in the arms while the diffuse older electrons that have traveled away from the spiral arms are present in the inter-arm regions. This part of the galaxy is marked as region \textbf{A} ,\textbf{B} and region \textbf{E} in the Figure \ref{hlaph_ng}.\\
\begin{figure}
\centering
\includegraphics[scale = 0.4]{h-alpha_regions.png}
\caption{This image depicts the correlation of the flatter spectral index and the presence of H-$\alpha$ emission. The contours are 0.5, 1, 3, 5, 8, 12, 18, 32, 44, 80 of the h-alpha map with unit contour level of 5~mJy/beam. The regions are described in the text.}
\label{hlaph_ng}
\end{figure}
However, something peculiar is seen in the region marked as \textbf{D}. It appears to be much steeper even though there is a clear increase of the intensity in the H alpha map. In order to understand it better, I overlay the LOFAR map with an optical image as can be seen in the Figure \ref{optical}. In this image, this region is shown in yellow meaning that it is not an H II region. However, in the paper \citet{1980ApJ...241..573K}, this source has been listed as an H II region, of the name ``NGC 0628:[H76] 566", although not much is known about this region. Hence, this discrepancy may be because the red continuum has not been sufficiently subtracted in the H alpha map, which may be because of the presence of a bright star in H alpha image. \\
\begin{figure}
\centering
\includegraphics[scale = 0.3]{ngc_optical_edit.png}
\caption{Overlaying the LOFAR map onto an optical image from SDSS shows that this region contains a stellar object. This was done inorder to understand the region marked \textbf{D}.}
\label{optical}
\end{figure}
The Figure \ref{spectr} shows the various regions and their correlations. The two spiral arms have different slopes in the correlation plot. This may be because of different levels of star formation in the two arms, which gives rise to different levels of thermal absorption in the galaxy at various regions. It is interesting to note that the Figure \ref{corr_ic}, depicting the same correlations does not show this feature of differing slopes.
\begin{figure}
	%\centering
	\subfloat[]{{\includegraphics[scale = 0.62]{13Regions_halpha.png}}}
	\centering
	\subfloat[]{{\includegraphics[scale = 0.62]{13Regions_thermal_region_all.png}}}
	\caption{Correlation plots of the thermal intensity values value with the spectral index map values, for each pixel. The various regions have different slops of correlation, which is interesting. \textit{Left:} The correlation plot of the H-alpha map flux density. the region marked \textbf{D} in this case seems to have a higher flux in H-alpha map, but with a steep spectral index. \textit{Right:} The correlation plot of the thermal radio map. The region \textbf{D} in this plot vanishes. Hence, the discrepancy seen in region \textbf{D} was because of an improper continuum subtraction.}
\label{spectr}
\end{figure}

In order to understand the discrepancy in the region \textbf{D}, we try to do the correlation plot using the thermal radio map obtained at a frequency of 3~GHz \citep{2017A&A...600A...6M}. In this case, the region \textbf{D} does not have a higher intensity value in the thermal map, and hence, the steep spectral index is correct. This map can be seen in the Figure \ref{ngc_ther}.

\begin{figure}
\centering
\includegraphics[scale = 0.5]{ngc_ther.png}
\caption{Correlation of the flatter spectral index in NGC\,628 and the presence of thermal radio emission at 3~GHz frequency. The contours are 0.1, 0.2, 0.4, 0.6, 1 $\times$ 0.1~mJy/beam.}
\label{ngc_ther}
\end{figure}

\paragraph{Integrated flux density:} The integrated flux density values for NGC\,628 for successive radii in rings with a width of 0.5' (about 1.1~kpc) are obtained, with the center of the rings aligned at the center of the galaxy. The plot with the radial profile using the obtained values is shown in Figure \ref{ngc_ring}. This is done for the images of the two frequencies- 145~MHz and 3~GHz. I then find the integrated flux density of the galaxy up to a radius of 5' of NGC\,628 (around 11~kpc) in the VLA map at a frequency of 3~GHz to be 108 $\pm$ 3~mJy. The value for the LOFAR map for this integrated flux at 145~MHz is 680 $\pm$ 120~mJy. This value seems to show that the spectral index of the map is -0.61. This shows that overall, synchrotron emission dominates in the LOFAR frequency for the galaxy.

\begin{figure}
\centering
\includegraphics[scale = 0.7]{LOFAR_VLA_ring.png}
\caption{The radial profile of the galaxy NGC\,628 i.e., radius vs log of integrated flux density for 3~GHz map \citep{2017A&A...600A...6M} and 145~MHz LOFAR map.}
\label{ngc_ring}
\end{figure}

\section{Star Formation in the two galaxies}
In this section, I shall discuss star formation in the two galaxies- IC\,342 and NGC\,628. Star formation in spiral galaxies is usually seen to take place in the spiral arms. It would be interesting to understand whether spiral arms trigger star formation, or if they rearrange the stars and molecular gas such that majority of star formation (SF) is seen in the arms. One may hypothesize that the sudden increase in the density in the spiral arms results in mechanisms of gravitational collapse such that conditions for SF is acquired. Stars are formed from molecular gas. However, most of the molecular H$_2$ is cold (10-20~K) and hence, invisible. It is also not easily excitable as requires a large amount of energy to be excited\footnote{First level rotational level, which is accessible only from a quadrupolar transaction, occurs at a temperature above 500~K.}. Hence, CO, the next most abundant molecule is used as its tracer. Using the well known Kennicutt-Schmidt (K-S) law, one can obtain the SF Rate (SFR) of a galaxy \citep{1959ApJ...129..243S}:
\begin{equation}
\Sigma_{SFR} \textrm{(M}_\odot\textrm{ yr}^{-1} \textrm{kpc}^{-2}) \propto (\Sigma_{gas})^N \textrm{(M}_\odot \textrm{kpc}^{−2})
\end{equation}
Here, $\Sigma_{SFR}$ represents the  SFR surface density and $\Sigma_{gas}$ represents the gas surface density. Usually, the gas surface density is replaced by the H$_2$ as most of the molecular gas is in this form. Then with the help of the CO surface density, using a conversion factor, one can obtain the $\Sigma_{H_2}$.\\
\noindent In the paper \citet{2014PASJ...66...27P}, it is found that IC\,342 is an H$_2$ dominated spiral galaxy where significant amount of SF could occur. The SF mechanisms discused in the paper include gravitational instability in the disk and at the galactic center, and a combination of gravitational instability and cloud-cloud collission at the galactic center. This is because the `\textit{N}' value varies from 1.4 in the low-H$_2$ domain (where $\Sigma_{H_2} <<$ 100~M$_{\odot}$ pc$^{-2}$) to 2-3 in the high H$_2$ domain. In the Figure\ \ref{sfric342}, one can see the SFRs obtained from this method, and how it change radially.

\begin{figure}
  \centering
    \includegraphics[scale=0.3]{SFRic.png}
  \caption{The SFR are shown as small triangles \citep{2014PASJ...66...27P}. Each radial step here is 10". One can see a similarity in the two plots. In the center, high star formation exists, and that region has a flat spectral index.}\label{sfric342}
\end{figure}

Unfortunately, in NGC\,628, I cannot do a comparison of the spectral indices and the star formation rates, as the flux density at the center of the galaxy is zero. In the paper \citet{2017A&A...600A...6M}, it is seen that NGC\,628 at 8.35~GHz has an asymmetric pattern with a lot of emission coming in from the northern part of the galaxy, and not at the center. This would be in concurrence with the explanation that there is a rapid decline in the star formation at the inner region as described in \citet{2001ApJS..132..129M}. In the JVLA image, at the frequency of 3.1~GHz, there was a presence of `holes' which line up with the type 1 H I holes\footnote{HI holes are characterized by the absence of neutral hydrogen and have the dimensions from 100~pc to 1~kpc.}, as seen in \citet{2011AJ....141...23B}. The absence of flux density can be attributed to rapid decline in SFR. However, I cannot be ascertain this in any way.

Using the Star Formation Rates given in \citet{2011PASP..123.1347K}, we can try to understand why the median values of the spectral indices of the two galaxies are so different. The SFR of IC\,342 is 1.87~M$_{\odot}$ pc$^{-1}$ while that of NGC\,628 is 0.68~M$_{\odot}$ pc$^{-1}$. Thus one could expect a flatter spectral index of IC\,342 than that in NGC\,628. Also, IC\,342 suffers from a higher level of thermal absorption, indicating the presence of a higher level of star formation, especially at the nucleus of the galaxy.

\section{Discussion}
Further work needs to be done to fully understand the significance of thermal absorption in the galaxies at such low frequencies. Measurement of the spectra at low frequencies should be done using the LOFAR LBA data, and obtain the spectral energy distribution to see how much flux density of the galaxies is removed due to thermal absorption.

\end{document}


\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[osf]{libertine}
\usepackage[scaled=0.8]{beramono}
\usepackage[margin=1.5in]{geometry}
\usepackage{url}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{nicefrac}
\usepackage{microtype}

\usepackage{sectsty}
\sectionfont{\large}
\subsectionfont{\normalsize}

\usepackage{titlesec}
\titlespacing{\section}{0pt}{10pt plus 2pt minus 2pt}{0pt plus 2pt minus 0pt}
\titlespacing{\subsection}{0pt}{5pt plus 2pt minus 2pt}{0pt plus 2pt minus 0pt}

\setlength{\parindent}{0pt}
\setlength{\parskip}{1ex}

\newcommand{\acro}[1]{\textsc{\MakeLowercase{#1}}}
\newcommand{\given}{\mid}
\newcommand{\mc}[1]{\mathcal{#1}}
\newcommand{\data}{\mc{D}}
\newcommand{\intd}[1]{\,\mathrm{d}{#1}}

\begin{document}

\section*{Inference}

In this course, we will focus on \emph{probabilistic inference.}  This
is the process of inferring unknown properties of a system given
observations via the mechanics of probability theory.

For example, suppose we want to understand some aspect of the
population of the United States, such as the portion of adults who
prefer Coca Cola over Pepsi.  Let this unknown value be called
$\theta$.  How can I gain insight into this value?

One thing I could do is ask people what they believe about $\theta$,
which they might reasonably compactly communicate via a probability
distribution (or equivalently by a drawing curve on a piece of paper).
Note that different people might give different answers to this
question!  (What do \emph{you} think are plausible values of
$\theta$?)

Of course, the Coca Cola corporation probably wouldn't be too happy if
I simply drew my personal beliefs about this value and submitted a
report.  Instead, we could conduct a survey to gain some more
information about $\theta$.  So we contact some adults and ask them if
they prefer Coca Cola over Pepsi, and record the results.  Let's call
the results of this experiment $\data$ (for ``data'').

What do we do with this data once we've measured it?  The goal of
probabilistic inference is to make some statements about $\theta$
given these observations.

\section*{Probability}

There are just two laws of probability you need to know.  The first is
the \emph{sum rule,} also called the \emph{rule of total probability.}
Suppose $X$ is some event (an event is simply a collection of things
that could be true, for example ``the total value shown on two dice is
less than six''), and suppose $\{Y_i\}_{i = 1}^N$ are some mutually
exclusive and exhaustive events (``for example, $Y_i$ could be the
event ``the first rolled die has value $i$,'' for $i \in \{1, 2,
\dotsc, 6\}$).  Then:
\begin{equation*}
  \Pr(X) = \sum_{i = 1}^N \Pr(X, Y_i),
\end{equation*}
so the total probability of $X$ is the sum of the probabilities of $X$
occurring alongside each of the scenarios described by the $\{Y_i\}$.

The second law of probability to know is the \emph{product rule:}
\begin{equation*}
  \Pr(X, Y) = \Pr(Y \given X)\Pr(X).
\end{equation*}
Here $\Pr(Y \given X)$, read ``the probability of $Y$ given $X$,'' is
the probability of event $Y$ when we restrict to only cases where $X$
is true.  This is easy to see from a Venn diagram.  By manipulating
the product rule, we arrive at \emph{Bayes' theorem:}
\begin{align*}
  \Pr(Y \given X) &= \frac{\Pr(X \given Y)\Pr(Y)}{\Pr(X)} \\
                  &= \frac{\Pr(X \given Y)\Pr(Y)}{\sum \Pr(X \given Y)\Pr(Y)}.
\end{align*}
One possible way to interpret this result is as follows.  Suppose we
are interested in the truth of $Y$.  We begin with a prior belief
about $Y$, $\Pr(Y)$.  We then learn that $X$ is true.  We use the
formula above to update our belief about $Y$ by conditioning on this
new information, giving $\Pr(Y \given X)$.  Bayes' theorem therefore
gives a probabilistically consistent way to update one's beliefs given
new information.  In this context the value $\Pr(Y)$ is called a
\emph{prior probability}, as it represents our beliefs prior to
observing $X$.  The output, $\Pr(Y \given X)$ is called the
\emph{posterior probability.}

The process of updating beliefs in this way is often called
\emph{probability inversion,} because after observing $X$, we first
calculate $\Pr(X \given Y)$ (``how likely was it to observe $X$ if $Y$
were true?''), then invert it using Bayes' theorem to give the desired
probability (``how likely is $Y$ now that I've seen $X$?'').  Many
classical paradoxes arise because these probabilities can be quite
different from each other, depending on the prior $\Pr(Y)$.

What is the prior probability that the outcome of rolling two dice is
less than six?  What if I told you that the value of the first die was
a five, does that change anything?

The above results are only valid for discrete random variables $X$.
Although this can be useful in machine learning (for example, if these
variables correspond to different hypotheses we wish to compare), in
practice, we will often be interested in continuous variables, such as
$\theta$ above.  Thankfully, we above formulas are perfectly valid for
continuous random variables $x$ and $\theta$, where we replace
probabilities $\Pr$ with probability density functions $p$ and replace
sums with integrals:
\begin{align*}
  p(x) &= \int p(x, y) \intd{y}; \\
  p(y \given x) &= \frac{p(x \given y) p(y)}{\int p(x \given y) p(y) \intd{y}}.
\end{align*}
We will always assume that probability density functions exist,
because the cases where they don't are not typically encountered in
machine learning.  It also saves us from having to state ``when the
density exists'' all the time.

Returning to our survey example, we might begin with a prior belief
about the value of $\theta$, represented by a prior probability
distribution $p(\theta)$. To couple our observations $\data$ to the
value of interest, we construct a probabilistic model $\Pr(\data
\given \theta)$, which describes how likely we would see a particular
survey result $\data$ given a particular value of $\theta$.  Note that
this model could have any form and we are free to make it as
complicated as we'd like: was there bias in the sampling mechanism?
Do people always tell the truth?

Finally, we use these to compute the posterior probability of $\theta$
given the survey results, $p(\theta \given \data)$.  This posterior
distribution encapsulates our entire belief about $\theta$! We can
use it to answer various questions we might be about $\theta$.

\section*{The Bayesian Method}

There are four main steps to the Bayesian approach to probabilistic
inference:\footnote{These are summarized from Tony O'Hagan and
  Jonathan Forster's eloquent introduction in \emph{Kendall's Advanced
    Theory of Statistics Volume 2B.}}
\begin{itemize}
\item \textbf{Likelihood.} First, we construct the likelihood (or
  \emph{model}), $p(\data \given \theta)$.  This serves to describe
  the mechanism giving rise our observations $\data$ given a
  particular value of the parameter of interest $\theta$.
\item \textbf{Prior.} Next, we summarize our prior beliefs about the
  parameters $\theta$, which we encode via a probability distribution
  $p(\theta)$.
\item \textbf{Posterior.} Given some observations $\data$, we obtain
  the posterior distribution $p(\theta \given \data)$ using Bayes'
  theorem.
\item \textbf{Inference.} We now use the posterior distribution to
  draw further conclusions as required.
\end{itemize}
The last step is purposely open-ended. For example, we can use it to
make predictions about new data (as in supervised learning), we can
summarize it in various ways (for example, point estimation if we must
report a single ``best guess'' of $\theta$), use it to compare
alternative models (giving rise to Bayesian model comparison),
determine which data to obtain next (optimal design of experiments,
called ``active learning'' in machine learning), and more.  We will
consider several of these in this course.

\section*{Issues}

Bayesian inference is a completely consistent system for probabilistic
reasoning.  Unfortunately, it is not without its issues, some of which
we list below.

\subsection*{Origin of priors}

In contrast to the model $p(\data \given \theta)$, it is not usually
clear where the prior $p(\theta)$ should come from.  There is an
entire branch of study concerning prior elicitation, but for now we
will simply treat it as given.  We will continue to discuss this
throughout the course.  Indeed, we will see that several ``tricks''
often encountered in alternative approaches (such as
\emph{regularization}) can be interpreted as implicitly placing
particular prior beliefs on $\theta$.

\subsection*{The meaning of probability}

Another problem is what exactly \emph{probability} means.  The
dominant statistical practice for many years (known as the
\emph{classical} or \emph{frequentist} theory) defines probability in
terms of the limit of conducting infinitely many random experiments.
Therefore it is impossible to consider the ``probability'' of a
statement such as ``at least 50\% of adults prefer Coca Cola.''  This
statement is either true or false, so its frequentist probability is
either zero or one (but we might not know which).  In the Bayesian
interpretation, we allow probabilities instead to describe
\emph{degrees of belief} in such a proposition.  In this way, we can
treat everything as a random variable and use the tools of probability
to carry out all inference.  That is, in Bayesian probability,
parameters, data, and hypotheses are all treated the same.  This
viewpoint is not universally accepted, and there is a lot of
fascinating philosophical writing on the subject, which we will
largely avoid.

Note that the two interpretations of probability agree on the axioms
and theorems of probability theory.  No one argues the truth of Bayes'
theorem.  The main difference is that a frequentist would not allow a
probability distribution to be placed on parameters such as $\theta$,
so the use of Bayes' theorem to update beliefs about parameters in
light of data is not allowed in that framework.

\subsection*{Intractable integrals}

Unfortunately, the integral in the denominator of Bayes' theorem:
\begin{equation*}
  p(x) = \int p(x \given y) p(y) \intd{y}
\end{equation*}
is not in general tractable for arbitrary combinations of priors and
likelihoods.  For this reason, we will spend a lot of time discussing
various schemes to approximate the posterior distribution in such
cases.  Sometimes this can be more of an art than a science.

\end{document}

lecture_notes/Introduction to the Bayesian Method/notes.tex


\section{HashPipe Prototype in P4}
\label{sec:prototype}

%- add details of p4 prototype
%- code fragments?
%- some details of barefoot compiler; and configurations there.
%- p4 to OVS compiler?

We built a prototype of \TheSystem using P4 version 1.1~\cite{p4-v1.1-spec} and verified that our prototype produced the same results as our HashPipe simulator. We did this by running a small number of artificially generated packets on the switch behavioral model \cite{p4-bm} as well as our simulator and ensuring that the hash table was identical in both cases at the end of the measurement interval.

\begin{figure}
 \begin{lstlisting}[basicstyle=\footnotesize, caption=
  First HashPipe stage with insertion of new flow. Fields prefixed with m are metadata fields, label=q1:p4-code, captionpos=b, basicstyle=\footnotesize, breaklines = true,
numbers=left, xleftmargin=2em,frame=single,framexleftmargin=2.0em]
 action doStage1(){
   mKeyCarried = ipv4.srcAddr;
   mCountCarried = 0;
  modify_field_with_hash_based_offset(mIndex, 0, stage1Hash, 32);

   // read the key and value at that location
   mKeyTable = flowTracker[mIndex];
   mCountTable = packetCount[mIndex];
   mValid = validBit[mIndex];

   // check for empty location or different key
   mKeyTable = (mValid == 0) ? mKeyCarried : mKeyTable;
   mDif = (mValid == 0) ? 0 : mKeyTable -  mKeyCarried;

   // update hash table
   flowTracker[mIndex] = ipv4.srcAddr;
   packetCount[mIndex] = (mDif == 0) ? mCountTable+1: 1;
   validBit[mIndex] = 1;

   // update metadata carried to the next table stage
   mKeyCarried = (mDiff == 0) ? 0 : mKeyTable;
   mCountCarried = (mDiff == 0) ? 0 : mCountTable;
}
 \end{lstlisting}
 \end{figure}

At a high level, \TheSystem uses a match-action stage in the switch pipeline for each hash table. In our algorithm, each match-action stage has a single default action---the algorithm execution---that applies to every packet. Every stage uses its own P4 \emph{register array}---stateful memory that persists across successive packets---for the hash table. In this context, every stage's P4 registers act as a hash table where the flow identifiers and the associated counts are maintained. The P4 action blocks for the first two stages are presented in Listings \ref{q1:p4-code} and \ref{q2:p4-code}; all stages from stage $2$ onward are identical to that of stage $2$. The remainder of this section walks through the P4 language constructs with specific references to their usage in our \TheSystem prototype.\\

 \noindent \textbf{Hashing to sample locations:} The action in each stage of the match-action pipeline  hashes on the flowid (\texttt{srcip} address in this case) with a custom hash function as indicated in line $4$ of Listing \ref{q1:p4-code}. This is used to pick the location where we check for the key and if absent, the flow is used as one of the samples for approximating the minimum. The P4 behavioral model \cite{p4-bm} allows customized hash function definitions. We use hash functions of the type $(a_i\cdot x + b_i)\%p$ where the chosen $a_i, b_i$ are co-prime to ensure independence of the hash functions across stages. Hash functions of this sort are also implementable on hardware and have been used in previous approaches~\cite{univmon,li2016flowradar}.

\noindent \textbf{Registers for storing flow statistics:} The flows are tracked and updated using three registers: one to track the flow identifiers, one for the packet count, and one to test validity of a certain index. The output of the hash function is used to index on the registers for reads and writes. Register reads occur in lines $6$-$9$ and register writes occur in lines $15$-$18$ of Listing \ref{q1:p4-code}. When a particular flow id is read from the register, it is checked against the one currently being carried. Depending on whether there is a match or mismatch, the counter value written back is $1$ or the current value incremented by $1$.

\noindent \textbf{Packet metadata for tracking current minimum:} The values read from the registers are placed in packet metadata since we cannot test conditions directly on the register values in P4. This is crucial in local minimum computation before any write-back into the register happens (lines $11$-$13$ of Listing \ref{q1:p4-code} and lines $3$, $6$, and $9$ of Listing \ref{q2:p4-code}). Apart from helping with updates in the same stage, packet metadata plays a central role in conveying state (the current minimum flow id, in this case) from one stage to another. This is then used for checks downstream. The updates that set these metadata fields across stages are similar to lines $20$-$22$ of Listing \ref{q1:p4-code}.

\begin{figure}
 \begin{lstlisting}[basicstyle=\footnotesize, caption=
Second HashPipe stage with rolling minimum. Fields prefixed with m are metadata fields, label=q2:p4-code, captionpos=b, basicstyle=\footnotesize, breaklines=true,
numbers=left, xleftmargin=2em,frame=single,framexleftmargin=2.0em]
action doStage2{
  ....
 mKeyToWrite =  (mCountInTable <  mCountCarried) ? mKeyCarried : mKeyTable));
 flowTracker[mIndex] = (mDiff == 0) ? mKeyTable : mKeyToWrite;

 mCountToWrite =  (mCountTable < mCountCarried) ? mCountCarried : mCountTable;
 packetCount[mIndex] = (mDiff == 0) ? (mCountTable + mCountCarried) :  mCountToWrite;

 mBitToWrite = (mKeyCarried == 0) ? 0 : 1);
 validBit[mIndex] = (mValid == 0) ? mBitToWrite : 1);
 .....
}
\end{lstlisting}
\end{figure}

\noindent \textbf{Conditional updates to compute local minimum:} The first stage involves conditional updates to the register to distinguish between an empty location, a match, or a mismatch for the incoming flow. However, subsequent stages must compare the flow present in the table against the flow and count in the metadata to evict ``a relative minimum'' at the end of the pipeline. To achieve this, we use a second condition to determine if an update is necessary based on the relative sizes of the two flows. %This ensure than an update happens if and only if the flow in our metadata is larger than the flow currently in the table, the flow matches the entry in the table or if the location in the table is currently empty.
If an update is not warranted, the metadata simply continues to the next stage in the pipeline. These kinds of conditional updates are possible at line rate~\cite{domino,tpp}.

%Our implementation uses version 1.1 of P4 since we use ternary operators for our conditional updates that aren't supported in previous versions. There is no compiler, currently, to compile down P4 version 1.1 to a hardware target. However, the only addition in version 1.1 from the supported version 1.0 other than syntactic sugar around assignment statements, is the ability to perform a read, test on a condition and a consequent update to a register location as opposed to a simple read, modify, write. However, these conditional updates are possible at line-rate (\cite{domino}, \cite{tpp}) and there will be a compiler to compile them down to hardware in the near future \vls{@Srinivas,is this needed?}.

\iffalse
\begin{figure}[h]
\lstinputlisting[language=c]{stage2.c}
\caption{Second and subsequent stages in our scheme where incoming flow is compared against the flow in the location that it hashes to and a conditional update is made depending on which of the two is larger in size currently; The code is identical to the action block from Stage 1 except that the update to the hsh table (lines 18 - 22) is replaced with the conditional update in this figure}
\label{fig:Stage2P4}
\lstset{numbers=left, numberstyle=\tiny, stepnumber=1, numbersep=5pt, escapechar=`,linewidth=8cm}
\end{figure}
\fi

%Once again, the empty location condition is subsumed under the match condition since we merely need to increment the counter with the number of packets carried in either case. However, we do need a conditional update to determine whether we need to overwrite the key in the location or not in the event of a mismatch, which is why our algorithm cannot be implemented on P4 supported hardware at the moment, but will be implementable in the near future.

\iffalse
\begin{figure}[h]
\lstinputlisting[language=c]{stage1.c}
\caption{First stage in our scheme where incoming flow is placed in the location it hashes to with either value 1 (key mismatch) or current count + 1 (key match)}
\label{fig:Stage1P4}
\end{figure}
\fi

\iffalse
\begin{figure*}[h]
 \includegraphics[width=\textwidth,height=12cm]{figures/Code.pdf}
 \caption{First stage in our scheme where incoming flow is placed in the location it hashes to with either value 1 (key mismatch) or current count + 1 (key match)}
\label{fig:P4}
\end{figure*}
\fi