\documentclass{article}
\setlength{\oddsidemargin}{0.25 in}
\setlength{\evensidemargin}{-0.25 in}
\setlength{\topmargin}{-0.6 in}
\setlength{\textwidth}{6.5 in}
\setlength{\textheight}{8.5 in}
\setlength{\headsep}{0.75 in}
\setlength{\parindent}{0 in}
\setlength{\parskip}{0.1 in}

\usepackage{amsmath,amsfonts,graphicx}
\usepackage{tikz}
\usepackage{epsfig}
\usepackage{filecontents}
\usepackage{pgfplots, pgfplotstable}
\usepackage{mathtools}
\usepackage{breqn}
\usepgfplotslibrary{statistics}

\newcounter{lecnum}
\renewcommand{\thepage}{\thelecnum-\arabic{page}}
\renewcommand{\thesection}{\thelecnum.\arabic{section}}
\renewcommand{\theequation}{\thelecnum.\arabic{equation}}
\renewcommand{\thefigure}{\thelecnum.\arabic{figure}}
\renewcommand{\thetable}{\thelecnum.\arabic{table}}

\newcommand{\lecture}[4]{
  \pagestyle{myheadings}
  \thispagestyle{plain}
  \setcounter{lecnum}{#1}
  \setcounter{page}{1}
  \noindent
  \begin{center}
    \framebox{
      \vbox{\vspace{2mm}
        \hbox to 6.28in { {\bf Analysis of Uncertainties
	    \hfill Fall 2014} }
        \vspace{4mm}
        \hbox to 6.28in { {\Large \hfill Lecture #1: #2  \hfill} }
        \vspace{2mm}
        \hbox to 6.28in { {\it Lecturer: #3 \hfill Notes by: #4} }
        \vspace{2mm}}
    }
  \end{center}
  \markboth{Lecture #1: #2}{Lecture #1: #2}
  \vspace*{4mm}
}

\renewcommand{\cite}[1]{[#1]}
\def\beginrefs{\begin{list}%
    {[\arabic{equation}]}{\usecounter{equation}
      \setlength{\leftmargin}{2.0truecm}\setlength{\labelsep}{0.4truecm}%
      \setlength{\labelwidth}{1.6truecm}}}
\def\endrefs{\end{list}}
\def\bibentry#1{\item[\hbox{[#1]}]}

\newtheorem{theorem}{Theorem}[lecnum]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}
\newenvironment{proof}{{\bf Proof:}}{\hfill\rule{2mm}{2mm}}

\newcommand\E{\mathbb{E}}

\begin{document}
\lecture{2}{24 October 2014}{Prof. Kate Scholberg}{Douglas Davis}
\section{Probability}
We define probability with
\begin{align}
  P = \frac{\text{number of occasions some particular result occurs}}{\text{total number of occurrences}}
\end{align}
The probability can only be between 0 and 1 (normalized). We write a discrete normalized distribution as:
\begin{align}
  \sum_i P_i = 1
\end{align}
An example would be a the probability of rolling a dice and getting a certain number. If the dice is fair, we have 6 total outcomes with each having a probability of 1/6
\begin{align*}
  \sum_{i=1}^6 P_i = 6\times\frac{1}{6} = 1
\end{align*}
An example of continuous probabilities would be the isotropic emission of say a photon (let's take this to be 2-dimensional for simplicity). The probability that the photon comes off at a set angle $\theta$ is just
\begin{align*}
  P(\theta) = \frac{1}{2\pi},
\end{align*}
it's just constant for any angle. The probability that the photon is emitted in some range of angles, $\Delta\theta$, would be $\Delta\theta/2\pi$. Integrating over all of $2\pi$ angles, we show:
\begin{align*}
  \int_0^{2\pi}P(\theta)d\theta = \frac{1}{2\pi}\int_0^{2\pi} d\theta = 2\pi/2\pi = 1.
\end{align*}
The familiar normalization condition for wave functions in quantum mechanics is just a property of probability. The probability that the state represented by the wave function $\psi$ exists from $-\infty$ to $\infty$ is 1.

\noindent Let's develop some definitions and notation. If $A$ and $B$ are possible outcomes, then:
\begin{align}
  P(A+B) \equiv \text{probability of }A\text{ or }B,
\end{align}
When $A$ and $B$ are independent (exclusive) the $P(A+B)$ is just equal to the sum of $P(A)$ and $P(B)$, but in general:
\begin{align*}
  P(A+B) \leq P(A) + P(B).
\end{align*}
Another definition:
\begin{align}
  P(AB) \equiv \text{probability of }A\text{ and } B = P(A|B)P(B).
  \label{eq:condi}
\end{align}
The new form we've introduced is the \emph{conditional probability}, $P(A|B)$, which is the probability of $A$ given $B$. Let's jump into a couple examples using the conditional probability. Let's say that $A$ represents that it's a Friday in October, and $B$ represents we have a 771 class day during this day in October. There are 4 class days for 771 in October, and there are 5 Fridays in the current October (2 are on Friday, 2 are not). First let's determine if the $A$ and $B$ are independent (if they are, $P(A)P(B)=P(AB)$).
\begin{align*}
  P(A)P(B) & = \frac{5}{31}\times\frac{4}{31} \approx .02 \\
  P(AB)    & = P(B|A)P(A) = \frac{2}{4}\times\frac{4}{31} = \frac{2}{31} \approx .065.
\end{align*}
Therefore, $A$ and $B$ are definitely not independent (as expected). We can also calculate $P(AB)$ using a different ordering of equation~\ref{eq:condi}:
\begin{align*}
  P(AB) = P(B|A)P(A) = \frac{2}{5}\times\frac{5}{31} = \frac{2}{31},
\end{align*}
as expected.

\noindent We've now reached a point where we can introduce Bayes' Theorem:
\begin{align}
  P(A|B)P(B) & = P(B|A)P(A)                                                               \\
  P(A|B)     & = \frac{P(B|A)P(A)}{P(B)}
\end{align}
Taking an example that works perfectly for current events, let $A$ be the probability that you have ebola and let $B$ be the probability that you test positive. Let's say a test has a 99\% detection rate and a 1\% false detection rate.
\begin{align*}
  P(B|A)     & = \text{testing positive if you have ebola }\, (99\%)                      \\
  P(A|B)     & = \text{probability of having ebola if you test positive }\, \text{(unknown)}
\end{align*}
We now need a value for $P(A)$, let's call the probability of having ebola 0.001. $P(B)$ is our false positive rate of 1\%. Now we can calculate:
\begin{align*}
  P(A|B) = \frac{P(B|A)P(A)}{P(B)} = \frac{0.99 \times 0.001}{0.01} \approx 10\%.
\end{align*}
With this we something a little counter intuitive -- if you test positive for ebola, there's really only a 10\% chance you have it under these circumstances. Let's look at a better physics example, proton decay. Let $A$ be the probability of proton decay, $B$ is the probability of any event passing selection cuts.
\begin{align*}
  P(B|A)     & = \text{effeciency (probability the event passes cuts given proton decay)} \\
  P(A|B)     & = \text{probability of proton decay given an event passing selection cuts}
\end{align*}
Using Bayes':
\begin{align}
  P(A|B) = \frac{P(B|A)P(A)}{P(B)},
\end{align}
where $P(B)$ is the probability of a background event -- therefore the experiment needs high efficiency and low background to make a serious measurement (increase the value of $P(A|B)$).

\noindent Let's now consider a parameter estimation scenario. Take $\frac{1}{2}(1+\alpha\cos\theta)$. Let $A$ be the experimental result probability and $B$ be the model parameterized by $\alpha$. $P(B|A) = P(A|B)P(B)/P(A)$ is the probability of $\alpha$ given the data. In this case $P(B)$ is very important, (this term is called the prior). If the experimenter does not know $P(B)$ well (if one does not have a reasonable distribution for it) then one cannot make much sense of $P(B|A)$ with much confidence. This is where Bayes' theorem has a weakness.

\section{Probability Distributions}
\subsection{Binomial}
Let's imagine we have three dice -- how often will we get 3 ones? This is pretty simple:
\begin{align*}
  (1/6)^3 \approx 0.0046,
\end{align*}
about half a percent. How about 2 ones? Now we have 3 different scenarios where this will happen, The first a second dice will be 1, the first and third dice will be 1, and the second and third dice will be 1. Therefore wehave:
\begin{align*}
  3\times(1/6)^2(5/6) \approx 6.9\%
\end{align*}
In this case -- a ``success'' is getting a 1. Now we define a probability distribution using the following parameters:
\begin{align}
  P(x;n,p)
\end{align}
where $x$ is the number of successes, $n$ is the number of trials, and $p$ is the probability of success in one trial. In the above case, our distribution would be $P(x;3,1/6)$, and it would be a {\bf Binomial Distribution}. The probability distribution function for a binomial distribution is:
\begin{align}
  P(x;n,p) = {n \choose x}p^xq^{n-x},
\end{align}
where
\begin{align*}
  {n \choose x} \equiv n\text{ ``choose'' }x = \frac{n!}{x!(n-x)!} \text{ and } q\equiv 1-p
\end{align*}
Now we define the mean and the variance of the binomial distribution:
\begin{align}
  \langle x \rangle              & = \mu = \sum_{x=0}^n xP(x;n,p) = np                     \\
  \sigma^2                       & = np(1-p)
\end{align}
\subsection{Poisson}
The limit of the binomial distribution for low rate processes ($\mu \ll n, p \ll 1$) yields the {\bf Poisson distribution}:
\begin{align}
  P(x;\mu) = \frac{\mu^x}{x!}e^{-\mu}.
\end{align}
Poisson is unique in that the expected value and variance are the same:
\begin{align}
  \langle x \rangle              & = \mu                                                   \\
  \sigma^2                       & = \mu
\end{align}
Poisson is continuous in $\mu$ and discrete in $x$.
\subsection{Gaussian}
Now we take $np \gg 1$ and arrive at the {\bf Gaussian distribution}:
\begin{align}
  P(x;\mu,\sigma) = \frac{1}{\sigma\sqrt{2\pi}}\exp\left[-\frac{1}{2}\left(\frac{x-\mu}{\sigma}\right)^2\right].
\end{align}
The Gaussian is defined for all $x$ and is continuous. Some properties of the distribution:
\begin{align*}
  1                              & = \int_{-\infty}^{\infty}dx\,P(x;\mu,\sigma)            \\
  \langle x \rangle              & = \int_{-\infty}^{\infty}dx\,x\,P(x;\mu,\sigma)         \\
  \langle (x-\mu)^2\rangle       & = \int_{-\infty}^{\infty}dx\,(x-\mu)^2\,P(x;\mu,\sigma) \\
  P(\mu\pm\sigma;\mu,\sigma)     & = \frac{1}{e}P(\mu;\mu,\sigma)
\end{align*}
The ``full width at half max'', $\Gamma$, is $2.354\sigma$. And finally:
\begin{align*}
  1\sigma \text{ out from mean } &\approx \text{68\% of area}                              \\
  2\sigma                        &\approx \text{95\% of area}                              \\
  3\sigma                        &\approx \text{99\% of area}
\end{align*}
\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Here is a citation, just for fun~\cite{CW87}.

\section*{References}
\beginrefs
\bibentry{CW87}{\sc D.~Coppersmith} and {\sc S.~Winograd},
``Matrix multiplication via arithmetic progressions,''
         {\it Proceedings of the 19th ACM Symposium on Theory of Computing},
         1987, pp.~1--6.
         \endrefs


\section{Evaluation}

The evaluation consists of two parts: one with computer-generated testing set, one with hand-drawn sketches.

\subsection{Computer-generated Testing Set}

\subsubsection{Result on Developing Set}

The confusion matrix for the evaluation on the developing set is in Table 1. The developing set contains 1000 figures with 200 figures from each category.

\begin{table}[ht!]
\centering
\begin{tabular}{|l|l|l|l|l|l|}
\hline
\backslashbox{Label}{Recognized} & Circle & Ellipse & Triangle & Square & Rectangle \\ \hline
Circle & \textbf{0.55} & 0.03 & 0.42 & 0.00 & 0.00 \\ \hline
Ellipse & 0.12 & \textbf{0.82} & 0.06 & 0.00 & 0.00 \\ \hline
Triangle & 0.00 & 0.00 & \textbf{0.99} & 0.00 & 0.01 \\ \hline
Square & 0.00 & 0.00 & 0.03 & \textbf{0.79} & 0.19 \\ \hline
Rectangle & 0.00 & 0.00 & 0.04 & 0.39 & \textbf{0.56} \\ \hline
\end{tabular}
\caption{Confusion Matrix on Developing Set}
\end{table}

\subsubsection{Error Analysis and Tuning}

First we see that nearly a half of circles are incorrectly recognized as triangles. Upon examination we find that these circles actually do not fall into any fuzzy sets because of their larger-than-expected $Thinness$ ratio. Sorting on the list with each shape's score = 0, a unexpected side effect happen that the letter ``T'' is alphabetically the largest. This problem can be fixed by making sure that \textbf{all fuzzy sets are interleaved and no blank area is left}, as what we do in this case of circles vs. squares.

Second we see that only 82\% ellipses are correctly recognized. The issue here is similar to the first one, but slightly different with the solution. The $Extent$ ratio for triangles and rectangles are quite centralized around 0.5 and 1.0. Therefore we can \textbf{safely expand the confidence range} of ellipses.

Finally we see that squares and rectangles are sometimes mixed up. This makes sense because \textbf{some of rectangle images in our data do look like squares}. If we are to deal with this type of error, we may consider using new features, such as identifying and comparing all the sides in the shape.

Besides, there are about 5\% figures showing a $Extent$ ratio of 1 due to image processing errors. Then when these figures happend to be non-rectangles, they will be recognized as triangles as explained above. The reason for the errors are currently unknown.

\subsubsection{Result on Testing Set}

After applying the necessary tweaks to the ``parameters'' (boundaries of fuzzy sets), we evaluate our system on the testing set, which contains 1000 figures with 200 figures from each category. The confusion matrix is in Table 2.

\begin{table}[ht!]
\centering
\begin{tabular}{|l|l|l|l|l|l|}
\hline
\backslashbox{Label}{Recognized} & Circle & Ellipse & Triangle & Square & Rectangle \\ \hline
Circle & \textbf{0.96} & 0.01 & 0.03 & 0.00 & 0.00 \\ \hline
Ellipse & 0.08 & \textbf{0.90} & 0.02 & 0.00 & 0.00 \\ \hline
Triangle & 0.00 & 0.00 & \textbf{0.99} & 0.00 & 0.01 \\ \hline
Square & 0.00 & 0.00 & 0.00 & \textbf{0.90} & 0.10 \\ \hline
Rectangle & 0.00 & 0.01 & 0.03 & 0.39 & \textbf{0.58} \\ \hline
\end{tabular}
\caption{Confusion Matrix on Testing Set}
\end{table}

Apart from the squares and rectangles mixing up, we notice that circles and ellipses also mix up due to similar reasons: some of ellipse images in our data do look like circles. But as this is largely due to the \textbf{inherent ambiguity in the images we use}, it would not be a serious issue when testing against hand-drawn sketches. Because \textbf{sketches are usually exaggerated in some ways to avoid multiple interpretations}, unless the person who draws them intentionally make them very ambiguous or such a distinction is not necessary.

\subsection{Hand-drawn Sketches}

As the final evaluation of our system, we feed about 55 sketches drawn by two people to the recognizer. The sketches include 1 $\sim$ 3 figures each, and contain in total 20 figures for every category. The confusion matrix is in Table 3.

\begin{table}[ht!]
\centering
\begin{tabular}{|l|l|l|l|l|l|}
\hline
\backslashbox{Label}{Recognized} & Circle & Ellipse & Triangle & Square & Rectangle \\ \hline
Circle & \textbf{20} & 0 & 0 & 0 & 0 \\ \hline
Ellipse & 1 & \textbf{19} & 0 & 0 & 0 \\ \hline
Triangle & 0 & 0 & \textbf{20} & 0 & 0 \\ \hline
Square & 0 & 0 & 0 & \textbf{18} & 2 \\ \hline
Rectangle & 0 & 0 & 0 & 5 & \textbf{15} \\ \hline
\end{tabular}
\caption{Confusion Matrix on Sketches}
\end{table}

We can see that performance is pretty good. There's only one problem left: sometimes squares are recognized as rectangles. The reason seems to be that value of $Thinness$ ratio is somewhat very sensitive to the input image.


\chapter{Protostar Formation}
\label{ch:protostar_form}

\marginnote{
\textbf{Suggested background reading:}
\begin{itemize}
\item \href{http://adsabs.harvard.edu/abs/2014prpl.conf..173L}{Dunham, M.~M., et al. 2014, in "Protostars and Planets VI", ed.~H.~Beuther et al., pp.~195-218}, sections 1-4 \nocite{dunham14a}
\end{itemize}
\textbf{Suggested literature:}
\begin{itemize}
\item \href{http://adsabs.harvard.edu/abs/2013ApJ...763....6T}{Tomida, K., et al., 2013, ApJ, 763, 6} \nocite{tomida13a}
\end{itemize}
}

The next two chapters focus on the structure and evolution of protostars. Our goal will be to understand when and why collapse stops, leading to formation of a pressure-supported object, and how those objects subsequently evolve into main sequence stars. This chapter focuses on the dynamics and thermal behavior of the material at the center of a collapsing core as it settles into something we can describe as a star, and on the structure of the envelope around this protostar. Chapter \ref{ch:protostar_evol} is focused on the evolution of this object, both internally and in its appearance on the HR diagram.

\section{Thermodynamics of a Collapsing Core}

We will begin by considering what happens at the center of a collapsing core where the density is rising rapidly as material collapses.

\subsection{The Isothermal-Adiabatic Transition}
\label{ssec:iso_adiabat}

Thus far we have treated the gas in star-forming regions as approximately isothermal, but this assumption must break down at some point. At low density there are minor deviations from isothermality that result from the density dependence of various heating and cooling processes, but these are fairly minor, in the sense that they are unable to significantly impede collapse. For example, the proposed \citet{larson05a} EOS discussed in chapter \ref{ch:imf_th} only gets as stiff as $T\propto \rho^{0.07}$ at high density, corresponding to a polytrope $P\propto \rho^{\gamma}$ with $\gamma=1.07$. Spherical objects can only be stable if $\gamma>4/3$, so gas with $\gamma=1.07$ is still in the unstable regime. In contrast, if the gas is not able to radiate at all, it will behave adiabatically. This means it will approach a polytrope with $\gamma=7/5$ or $5/3$, depending on whether the gas temperature is high enough to excite the rotational and vibrational levels of H$_2$ or not.\footnote{In actuality the value of $\gamma$ for H$_2$ is more complicated than that, but this detail is unimportant for our purposes.} Either of these values is $>4/3$, and thus sufficient to halt collapse.

Let us make some estimates of when deviations from isothermality that are significant enough to slow collapse will occur. Since we are dealing with the collapse of the first region to fall in, we can probably safely assume that this material has very low angular momentum and treat the collapse as spherical -- higher angular momentum material will only fall in later, since removal of angular momentum by the disk takes a while. The behavior of this material has been studied by a number of authors, going all the way back to \citet{larson69a}, but the treatment here follows that of \citet{masunaga98a} and \citet{masunaga00a}.

At high densities inside a core immediately before a central star forms and begins to radiate, the dominant source of energy is adiabatic compression of the gas. Let $e$ be the thermal energy per unit mass of a particular gas parcel, and let $\Gamma$ and $\Lambda$ be the rates of change in $e$ due to heating and cooling processes, i.e.,
\begin{equation}
\frac{de}{dt} = \Gamma - \Lambda.
\end{equation}
As the gas collapses it will heat up due to adiabatic compression. The first law of thermodynamics tells us that the heating rate due to this process is
\begin{equation}
\label{eq:gamma_ad}
\Gamma = -p \frac{d}{dt}\left(\frac{1}{\rho}\right),
\end{equation}
where $\rho$ and $p=\rho c_s^2$ are the gas density and pressure, and $c_s$ is the isothermal sound speed. Since $1/\rho$ is the specific volume, meaning the volume per unit mass occupied by the gas, this term is just $p\,dV$, the work done on the gas in compressing it. If the gas is collapsing in free-fall, the compression time scale is about the free-fall timescale $t_{\rm ff} = \sqrt{3\pi/32G\rho}$, so we expect
\begin{equation}
\Gamma = C_1 c_s^2 \sqrt{4\pi G\rho},
\end{equation}
where $C_1$ is a constant of order unity that will depend on the exact collapse solution, and the factor of $\sqrt{4\pi}$ has been inserted for future convenience.

The main cooling source is thermal emission by dust grains, which at the high densities with which we are concerned are thermally very well coupled to the gas. Let us first consider the case where the gas is optically thin to this thermal radiation, so the cooling rate per unit mass is simply given by the rate of thermal emission,
\begin{equation}
\Lambda_{\rm thin} = 4\kappa_{\rm P} \sigma_{\rm SB} T^4.
\end{equation}
Here $\sigma_{\rm SB}$ is the Stefan-Boltzmann constant and $\kappa_{\rm P}$ is the Planck mean specific opacity of the gas-dust mixture. As long as $\Lambda \gtrsim \Gamma$, the gas will remain isothermal. (Strictly speaking if $\Lambda > \Gamma$ the gas will cool, but that is because we have left out other sources of heating, such as cosmic rays and the fact that the gas and dust are bathed in a background IR radiation field from other stars.) If we equate the heating and cooling rates, using for $T$ the temperature in the isothermal gas, we therefore will obtain a characteristic density beyond which the gas can no longer remain isothermal. Doing so gives
\begin{eqnarray}
\rho_{\rm thin} & = & \frac{4}{\pi} \frac{\kappa_{\rm P}^2 \sigma_{\rm SB}^2 \mu^2 m_{\rm H}^2 T^6}{C_1^2 G k_B^2} \\
& = & 5\times 10^{-15} \mbox{ g cm}^{-3}\, C_1^{-2} \kappa_{\rm P,-2}^2 T_1^6
\end{eqnarray}
where $\mu$ is the mean mass per particle in units of $m_{\rm H}$ ($\mu=2.3$ for fully molecular gas), and we have set $c_s = \sqrt{k_B T/\mu m_{\rm H}}$. In the second line, $T_1 = T/10$ K and $\kappa_{\rm P,-2} = \kappa_{\rm P}/0.01$ cm$^2$ g$^{-1}$, a typical value for thermal radiation at a temperature of $\approx 10$ K and Milky Way dust grains. Thus we find that compressional heating and optically thin cooling to balance at about $10^{-14}$ g cm$^{-3}$.

A second important density is the one at which the gas starts to become optically thick to its own re-emitted infrared radiation. Suppose that the optically thick region at the center of our core has some mean density $\rho$ and radius $R$. The condition that the optical depth across it be unity then reduces to
\begin{equation}
\label{eq:thick_thin}
2 \kappa_{\rm P} \rho R \approx 1.
\end{equation}
If this central region corresponds to the size of the region that is no longer in free-fall collapse and is instead thermally supported, then its size must be comparable to the Jeans length at its lowest temperature, i.e., $R\sim \lambda_J = \sqrt{\pi c_s^2/(G\rho)}$. Thus we set
\begin{equation}
R = C_2 \frac{2\pi c_s}{\sqrt{4\pi G \rho}},
\end{equation}
where $C_2$ is again a constant of order unity, and Masunaga et al.\ find based on numerical results that $C_2\approx 0.75$. Plugging this value of $R$ into equation (\ref{eq:thick_thin}), we obtain the characteristic density at which the gas transitions from optically thin to optically thick,
\begin{eqnarray}
\rho_{\tau\sim 1} & = & \frac{1}{4\pi} C_2^{-2} \frac{\mu m_{\rm H} G}{\kappa_{\rm P}^2 k_B T} \\
& = &
1.5\times 10^{-13}\mbox{ g cm}^{-3}\,  C_2^{-2} \kappa_{\rm P,-2}^{-2} T_1^{-1}
\end{eqnarray}
This is not very different from the value for $\rho_{\rm thin}$, so in general for reasonable collapse conditions we expect that cores transition from isothermal to close to adiabatic at a density of $\sim 10^{-13}-10^{-14}$ g cm$^{-3}$.

It is worth noting that ratio of $\rho_{\rm thin}$ to $\rho_{\tau\sim 1}$ depends extremely strongly on both $\kappa_{\rm P}$ (to the 4th power) and $T$ (to the 7th), so any small change in either can render them very different. For example, if the metallicity is super-solar then $\kappa_{\rm P}$ will be larger, which will increase $\rho_{\rm thin}$ and decrease $\rho_{\tau\sim 1}$.
Similarly, if the region is somewhat warmer, for example due to the presence of nearby massive stars, then $\rho_{\rm thin}$ will increase and $\rho_{\tau\sim 1}$ will decrease.

If $\rho_{\tau\sim 1} < \rho_{\rm thin}$, the collapsing gas will become optically thick before heating becomes faster than optically thin cooling. In this case we must compare the heating rate due to compression with the cooling rate due to optically thick cooling instead of optically thin cooling. The cooling rate for an optically thick region is determined by how quickly radiation can diffuse out. If we have a central region of optical depth $\tau\gg 1$, the effective speed of the radiation moving through it is $c/\tau$, so the time required for the radiation to diffuse out is
\begin{equation}
t_{\rm diff} = \frac{l\tau}{c} = \frac{\kappa_{\rm P} \rho l^2}{c}
\end{equation}
where $l$ is the characteristic size of the core. Inside the optically thick region matter and radiation are in thermal balance, so the radiation energy density approaches the blackbody value $a_R T^4$. The radiation energy per unit mass is therefore $a_R T^4/\rho$. Putting all this together, and taking $l=2 R$ as we did before in computing $\rho_{\tau\sim 1}$, the optically thick cooling rate per unit mass is
\begin{equation}
\Lambda_{\rm thick} = \frac{a_R T^4/\rho}{t_{\rm diff}} = \frac{\sigma_{\rm SB} T^4}{\kappa_{\rm P} \rho^2 R^2},
\end{equation}
where $\sigma_{\rm SB} =ca_R /4$. If we equate $\Lambda_{\rm thick}$ and $\Gamma$, we get the characteristic density where the gas becomes non-isothermal in the optically thick regime
\begin{eqnarray}
\rho_{\rm thick} & = & \left(\frac{C_1^2 G \sigma_{\rm SB}^2 \mu^4 m_{\rm H}^4 T^4}{4\pi^3 C_2^4 k_B^4 \kappa_{\rm P}^2}\right)^{1/3} \\
& = & 5\times 10^{-14}\mbox{ g cm}^{-3}\, \frac{C_1^{2/3}}{C_2^{4/3}} \kappa_{\rm P,-2}^{-2/3} T_1^{4/3}.
\end{eqnarray}
This is much more weakly dependent on $\kappa_{\rm P}$ and $T$, so we can now make the somewhat more general statement that, even for supersolar metallicity or warmer regions, we expect a transition from isothermal to adiabatic behavior somewhere in the vicinity of $10^{-14}-10^{-13}$ g cm$^{-3}$.

\subsection{The First Core}

The transition to an adiabatic equation of state, with $\gamma>4/3$, means that the collapse must at least temporarily halt. The result will be a hydrostatic object that is supported by its own internal pressure. This object is known as the first core, or sometimes a Larson's first core, after Richard Larson, who first predicted this phenomenon.

We can model the first core reasonably well as a simple polytrope, with index $n$ defined by $n=1/(\gamma-1)$. When the temperature in the first core is low, $\gamma\approx 5/3$ and $n\approx 3/2$, and for a more massive, warmer core $\gamma \approx 7/5$ ($n\approx 5/2$). The theory of polytropes can be found in many standard stellar structure textbooks \citep[e.g.,][]{chandrasekhar39a, kippenhahn94a}, and so we will not rehearse the topic here, and will simply quote the result. For a polytrope of central density $\rho_c$, the radius and mass are
\begin{eqnarray}
R & = & a \xi_1\\
M & = & -4\pi a^3 \rho_c \left(\xi^2\frac{d\theta}{d\xi}\right)_1,
\end{eqnarray}
where $\xi=r/a$ is the dimensionless radius, $\theta = (\rho/\rho_c)^{1/n}$ is the dimensionless density, the subscript $1$ refers to the value at the edge of the sphere (where $\theta=0$), the factors $\xi_1$ and $(\xi\, d\theta/d\xi)_1$ can be determined by integrating the Lane-Emden equation, and the scale factor $a$ is defined by
\begin{equation}
a^2 = \frac{(n+1) K}{4\pi G} \rho_c^{\frac{1-n}{n}}.
\end{equation}
The factor $K = p/\rho^{\gamma}$ is the polytropic constant, which is determined by the specific entropy of the gas.

For our first core, the specific entropy will just be determined by the density at which the gas transitions from isothermal to adiabatic. If we let $\rho_{\rm ad}$ be the density at which the gas becomes adiabatic, then the pressure at this density is $p = \rho_{\rm ad} c_{s0}^2$, where $c_{s0}$ is the sound speed in the isothermal phase, and $K = c_{s0}^2 \rho_{\rm ad}^{1-\gamma}$. For $\gamma=5/3$ ($n=1.5$) we have $\xi_1=3.65$ and $(\xi^2\, d\theta/d\xi)_1=-2.71$, and plugging in we get
\begin{eqnarray}
R & = & 2.2\mbox{ AU} \; T_1^{1/2} \rho_{c,-10}^{1/6} \rho_{\rm ad,-13}^{-1/3} \\
M & = & 0.059\,\msun\; T_1^{1/2} \rho_{c,-10}^{7/6} \rho_{\rm ad,-13}^{-1/3},
\end{eqnarray}
where $\rho_{c,-10} = \rho_c / 10^{-10}$ g cm$^{-3}$ and $\rho_{\rm ad,-13} = \rho_{\rm ad}/10^{-13}$ g cm$^{-3}$. Our decision to scale $\rho_c$ to $10^{-10}$ g cm$^{-3}$ will be justified in a moment. Repeating the exercise for $\gamma=7/5$ ($n=2.5$) gives almost identical results, with slightly different leading constants. We therefore conclude that the first core is an object a few AU in size, with a mass of a few hundredths of a Solar mass.

\subsection{Second Collapse}

The first core is a very short-lived phase in the evolution of the protostar. To see why, let us estimate its temperature. The temperature inside the sphere rises as $T\propto \rho^{\gamma-1}$, so the central temperature is
\begin{equation}
T_c = T_0 \left(\frac{\rho_c}{\rho_{\rm ad}}\right)^{\gamma-1},
\end{equation}
where $T_0$ is the temperature in the isothermal phase. Thus the central temperature will be higher than the boundary temperature by a factor that is determined by how high the central density has risen, which in turn will be determined by the amount of mass that has accumulated on the core.

In general we have $M\propto \rho_c^{(3+n)/(2n)}$, or $M\propto \rho_c^{(3\gamma-2)/2}$. We also have $T_c\propto \rho_c^{\gamma-1}$. Combining these results, we have
\begin{equation}
T_c \propto M^{(2\gamma-2)/(3\gamma-2)}.
\end{equation}
The exponent is $0.44$ for $\gamma=5/3$ and $0.36$ for $\gamma=7/5$. Plugging in some numbers, $M = 0.06\msun$, $\rho_{\rm ad}=10^{-13}$ g cm$^{-3}$, and $\gamma=5/3$ gives $\rho_c = 10^{-10}$ g cm$^{-3}$ and $T_c=1000$ K. Thus we see that by the time anything like $0.1$ $\msun$ of material has accumulated on the first core, compression will have caused its central temperature to rise to $1000$ K or more.

This causes yet another change in the thermodynamics of the gas, because all the hydrogen is still molecular, and molecular hydrogen has a binding energy of $4.5$ eV. In comparison, the kinetic energy per molecule for molecular hydrogen at a temperature $T$ is $(3/2) k_B T = 0.13 T_3$ eV, where $T_3=T/(1000\mbox{ K})$. At 1000 K this means that the mean molecule still has only a few percent of the kinetic energy that would be required to dissociate it. However, there is a non-negligible tail of the Maxwellian distribution that is moving fast enough for collisions to produce dissociation. Each of these dissociative collisions removes $4.5$ eV from the kinetic energy budget of the gas and puts it into chemical energy instead. Since dissociations are occurring on the tail of the Maxwellian, any slight increase in the temperature dramatically increases the dissociation rate, moving even more kinetic energy into chemical energy.

This effectively acts as a thermostat for the gas, in much the same way that a boiling pot of water stays near the boiling temperature of water even when energy is added, because all the extra energy that is provided goes into changing the chemical phase of the water rather than raising its temperature. Detailed numerical calculations of this effect show that at temperatures above $1000-2000$ K, the equation of state becomes closer to $T\propto \rho^{0.1}$, or $\gamma=1.1$. This is again below the critical value of $\gamma=4/3$ required to have a hydrostatic object, and as a result the center of the first core again goes into something like free-fall collapse.

This is called the second collapse. The time required for it is set by the free-fall time at the central density of the first core, which is only a few years. This collapse continues until all the hydrogen dissociates. The hydrogen also ionizes during this collapse, since the ionization potential of $13.6$ eV is not very different from the dissociation potential of $4.5$ eV. Only once all the hydrogen is dissociated and ionized can a new hydrostatic object form. At this point the gas is warmer than $\sim 10^4$ K, is fully ionized, and the new hydrostatic object is a true protostar. It is supported by degeneracy pressure at first when its mass is low, and then as more mass arrives it heats up and becomes supported by thermal pressure.

An important point to make here is that this discussion implies that brown dwarfs, at least those of sufficiently low mass, do not undergo a prompt second collapse. Instead, their first cores never accumulate enough mass to dissociate the molecules at their center. This is not to say that dissociation never happens in them, and that second collapse never occurs. A brown dwarf-mass first core will still radiate from its surface and, lacking any internal energy source, this energy loss will have to be balanced by compression. As the gas compresses the temperature and entropy will rise, and, if the object does not become supported by degeneracy pressure first, the central temperature will eventually rise enough to produce second collapse. The difference for a brown dwarf is that this will only occur once slow radiative losses cause a temperature rise, which may take a very long time compared to formation. For stars, in contrast, there is enough mass to reach the critical temperature by compression during formation.

\section{The Protostellar Envelope}

Once a protostar is born at the center of a collapsing cloud, we can ask both about the structure immediately around it and about its internal structure. We defer the latter to Chapter \ref{ch:protostar_evol}, and focus here on the envelope around the newborn protostar.

\subsection{Accretion Luminosity}

The temperature of the gas around the newborn protostar is determined by the radiation that the central star emits. At early times the star has not reached the main sequence or ignited any nuclear burning, so gravity is the only important energy source in the problem. Even if nuclear burning does start, we will see that it is negligible for low mass stars. The protostar is a hydrostatic object, although it undergoes secular contraction, so that gas striking its surface comes to a halt in an accretion shock. In this shock its kinetic energy is converted to heat, which is then radiated away.

The detailed structure of the accretion shock was first worked out by \citet{stahler80a, stahler80b}. The summary is that the energy radiated away at the shock is roughly
\begin{equation}
L_{\rm acc} = \frac{G M_* \dot{M}_*}{R_*},
\end{equation}
where $M_*$, $\dot{M}_*$, and $R_*$ are the mass, accretion rate, and radius for the protostar. We will see in Chapter \ref{ch:protostar_evol} that $R_*$ is typically a few $\rsun$ (and indeed this is consistent with the observed radii of T Tauri stars). We have previously calculated typical accretion rates of $\dot{M}_*\sim 10^{-5}$ $\msun$ yr$^{-1}$ for low mass stars.
Plugging in these numbers, we find
\begin{equation}
L_{\rm acc} = 30\lsun\, \dot{M}_{*,-5} M_{*,0} R_{*,1}^{-1},
\end{equation}
where $\dot{M}_{*,-5}=\dot{M}_*/(10^{-5}\msun\mbox{ yr}^{-1})$, $M_{*,0}=M_*/\msun$, and $R_{*,1}=R_*/(10\rsun)$.
Thus a typical low mass protostar can easily put out many tens of $\lsun$ in accretion power, far greater than what it would produce from nuclear burning on the main sequence.

We can also estimate the effective temperature of the stellar surface due to accretion. The infalling gas arrives in free-fall at a velocity
\begin{equation}
v_{\rm ff}=\sqrt{\frac{2GM_*}{R_*}} = 200\mbox{ km s}^{-1} \, M_{*,0}^{1/2} R_{*,1}^{-1/2}.
\end{equation}
The vastly exceeds the sound speed of a few km s$^{-1}$ in gas at a temperature of $\sim 10^3-10^4$ K, so the gas must decelerate in a strong shock with a Mach number of order 100. For a strong shock, one where the Mach number $\mathcal{M} \gg 1$, the Rankine-Hugoniot jump conditions tell us that the post-shock temperature is
\begin{equation}
T_2 = \frac{2\gamma(\gamma-1)}{(\gamma+1)^2} \mathcal{M}^2 T_1
= \frac{2\gamma(\gamma-1)}{(\gamma+1)^2} \frac{v_{\rm shock}^2}{c_1^2} T_1
= \frac{2(\gamma-1)}{(\gamma+1)^2} \frac{\mu m_{\rm H}}{k_B} v_{\rm shock}^2,
\end{equation}
where $c_1$ is the adiabatic sound speed in the pre-shock gas.

Taking $v_{\rm shock}=v_{\rm ff}$, $\gamma=5/3$ for a monatomic gas, and $\mu=1.4$ for the pre-shock gas (assuming it to be neutral hydrogen), and plugging in we get
\begin{equation}
T_2 = 1.2\times 10^6 \, M_{*,0} R_{*,1}^{-1} \mbox{ K}.
\end{equation}
In other words, the post-shock gas is heated to temperatures such that it emits in UV and x-rays. The incoming gas will be extremely opaque to this radiation due to the opacity provided by both free electrons and numerous lines of multiply ionized metal atoms such as iron. As a result all the radiation emitted by the post-shock gas will be absorbed in a small region immediately outside the shock and reprocessed until it becomes blackbody emission. The stellar surface therefore emits as a blackbody, whose temperature we can calculate in the standard way:
\begin{eqnarray}
L_{\rm acc} & = & 4\pi R_*^2 \sigma_{\rm SB} T_*^4 \\
T_* & = & 4300 \dot{M}_{*,-5}^{1/4} M_{*,0}^{1/4} R_{*,1}^{-3/4} \mbox{ K}.
\end{eqnarray}
Thus the star is effectively a blackbody at a surface temperature comparable to that of a main sequence star.

\subsection{The Dust Destruction Front}

Now let us consider the effect of this luminosity on the gas around the protostar. Consider a spherical black dust grain of radius $a$ some distance $r$ from the star. It absorbs radiation at a rate
\begin{equation}
\Gamma = \frac{L_{\rm acc}}{4\pi r^2} \pi a^2 = \pi a^2 \sigma_{\rm SB} T_*^4 \left(\frac{R_*}{r}\right)^2
\end{equation}
and radiates it at a rate\footnote{This expression is only valid if the wavelengths characteristic of the peak of the blackbody curve at temperature $T_d$ are small compared to the circumference of the grain. For the dust temperature of $\approx 1000$ K we will insert below, this implies that the result is valid for grains with characteristic sizes $\gtrsim 1$ $\mu$m. Smaller grains will have lower values of $\Lambda$ and thus higher equilibrium temperatures.}
\begin{equation}
\Lambda = 4\pi a^2 \sigma_{\rm SB} T_d^4,
\end{equation}
where $T_d$ is the dust grain's temperature. Equating these two, the temperature of the grain is
\begin{equation}
T_d = \left(\frac{R_*}{2r}\right)^{1/2} T_*
\end{equation}

Even the most refractory materials out of which interstellar dust is made, such as graphite and silicate, will vaporize at temperatures larger than $\sim 1000-1500$ K. The exact temperature depends on the chemical composition of the grains. Thus when $r/R_*$ is too small grains cannot survive. They are vaporized. We therefore expect the protostar to be surrounded by dust-free region.

Since the ionizing radiation produced at the shock at the stellar surface all gets absorbed close to the shock, and the star is shining into this dust-free region as a blackbody at a temperature of only a few thousand K, the gas in this region is primarily neutral. Neutral atomic gas with no dust in it is essentially transparent to visible radiation, so in this region the opacity is tiny, and stellar radiation is able to free-stream outward. The dust-free neutral region is called the opacity gap.

As one moves away from the star the equilibrium grain temperature drops, and eventually one reaches a surface where dust grains can exist. This is called the dust destruction radius, since incoming gas that reaches this radius has its grains destroyed. If we plug the grain destruction temperature into our equation for $T_d$, we can solve for the dust destruction radius:
\begin{equation}
r_d = \frac{R_*}{2} \left(\frac{T_*}{T_d}\right)^2 = 0.4 \,  T_{d,3}^{-2} \dot{M}_{*,-5}^{1/2} M_{*,0}^{1/2} R_{*,1}^{-1/2} \mbox{ AU},
\end{equation}
where $T_{d,3}=T_d/(1000\mbox{ K})$ is the dust destruction temperature in units of 1000 K. Thus the dust-free region extends to $\sim 1$ AU around an accreting protostar.

\subsection{Temperature Structure and Observable Properties}

Now let us consider the material beyond the dust destruction front. At the front the gas density is given roughly by the condition
\begin{eqnarray}
\dot{M}_* & = & 4\pi r_d^2 \rho v_{\rm ff} \\
\rho & = & \frac{\dot{M}_*}{\sqrt{8 \pi^2 G M_* r_d^3}} \\
& = & 4\times 10^{-13} \, \dot{M}_{*,-5}^{1/4} M_{*,0}^{-7/4} R_{*,1}^{3/4} T_{d,3}^3\mbox{ g cm}^{-3}.
\end{eqnarray}
Just inside the front, the stellar spectrum is nearly a blackbody at a temperature of a few thousand Kelvin, so the peak wavelength is
\begin{equation}
\lambda \approx \frac{hc}{4k_BT} = 440 \, \dot{M}_{*,-5}^{-1/4} M_{*,0}^{-1/4} R_{*,1}^{3/4}\mbox{ nm},
\end{equation}
placing it in the visible.

The opacity of gas with Milky Way dust composition at 440 nm is roughly $\kappa=8000$ cm$^2$ g$^{-1}$, so the mean free-path of a stellar photon moving through the dust destruction front is $(\kappa\rho)^{-1} \approx 3\times 10^8$ cm. This is a tiny length scale compared to any other scale in the problem, such as the size of the core, the size of the opacity gap, or even the radius of the protostar. Thus all the starlight that strikes the dust destruction front will immediately be absorbed by the dust grains. They will re-emit it as thermal radiation with a peak wavelength determined by their blackbody temperature, which will be a factor of $\sim 4$ lower than the stellar surface temperature. At around 1.8 $\mu$m, a factor of 4 longer wavelength than the 440 nm we started with, the opacity is drops to around 1000 cm$^2$ g$^{-1}$, so the mean free path is a factor of 8 larger. Nonetheless, this is still tiny, so all the re-emitted radiation will also be absorbed.

Since we are in a situation where all the radiation is absorbed and re-emitted many times, it is reasonable to treat this as a diffusion problem. Protostellar radiation free-streams from the surface, through the opacity gap, and is absorbed and thermalized at the dust destruction front. Then it must diffuse out through the dust envelope. This is essentially the same calculation that is made for radiation diffusing outward through a star, and the equation describing it is the same:
\begin{equation}
F = -\frac{c}{3\rho \kappa_R} \nabla E,
\end{equation}
where $F$ is the radiation flux, $E$ is the radiation energy density, and $\kappa_R$ here is the Rosseland mean opacity, meaning the mean of the frequency-dependent opacity using a weighting function that is equal to the temperature derivative of the Planck function. Note here that $\kappa_R$ is a function of $T$.

The repeated absorption and re-emission of radiation forces it into thermal equilibrium with the gas, so $E$ is simply the energy density of a thermal radiation field at the gas temperature: $E=a_R T^4$. Since no energy is added or removed from the radiation field as it diffuses outward through the envelope, $F=L_{\rm acc}/(4\pi r^2)$. Putting this together, we have
\begin{equation}
L_{\rm acc}=-\frac{16\pi ca_R r^2}{3\rho\kappa_R} T^3 \frac{dT}{dr}
\end{equation}

For a given density structure and a model of dust grains that specifies $\kappa_R(T)$, this equation allows us to estimate the temperature structure in the protostellar envelope. For reasonable grain models we expect $\kappa_R\propto T^\alpha$ with $\alpha\approx 0.8$ in the temperature range of a few hundred K. Let us suppose that the density distribution in the envelope looks something like a powerlaw, so $\rho\propto r^{-k_{\rho}}$. Finally, let us also suppose that the temperature also behaves like a powerlaw in radius, $T\propto r^{-k_T}$. The left hand side of the equation is a constant, and we have now worked out how the right hand side varies with $r$. Plugging in all the radial dependences on the RHS, and knowing that they must sum to zero since the LHS is a constant, we get
\begin{equation}
k_T = \frac{k_{\rho} + 1}{4-\alpha}.
\end{equation}

Thus in the freely-falling part of the envelope, where $k_{\rho}\approx 3/2$, we have $k_T\approx 0.8$. In our fiducial example, where the temperature is 1000 K at 0.4 AU, we would expect the temperature to drop to 300 K at around 2 AU, to 100 K at around 8 AU, and back to the background temperature of 10 K at around 150 AU. In the outer part of the envelope the falloff in temperature can be either steeper or shallower depending on how the density falls off -- sharper density falloffs (larger $k_{\rho}$) lead to sharper temperature falls (larger $k_T$) as well.

Of course this approximation only applies as long as the radiation is trapped by the dust, and the dust opacity is highest for high frequency radiation. Once the dust temperature falls off to less than $\sim 100$ K, depending on the size of the core, the radiation is free to escape instead. Even further in, where the dust temperature is higher, long wavelength radiation can escape freely.

As a result the spectrum inside the core is never truly a blackbody, since radiation at long wavelengths never reaches thermal equilibrium. The emitted spectrum is also complicated by this behavior. We can think of this as follows: for a star, there is something close to a single well-defined photosphere at all frequencies because the density drops off sharply. For a dust cloud, on the other hand, the density drop is not sharp, and so the photosphere, the surface of optical depth unity (or 2/3 if you prefer) is in different places at different frequencies. At high frequencies it is near the core surface because the opacity is high, and at low frequencies the low opacity allows it to be much farther in. For this reason, centrally-heated cores do not emit as blackbodies.

In order to truly determine the temperature distribution within a core it is necessary to either use a more sophisticated analytic treatment (for example one is given in \citealt{chakrabarti05a}) or to proceed numerically. If one wants a more sophisticated density structure that is not spherical, numerical methods are also required. Of course all of this only applies as long as a great deal of mass remains in the envelope, so that it is optically thick to both the star's direct radiation and to the re-radiated thermal radiation from the dust destruction front. In terms of our evolutionary classes, all of this applies to class 0 and class I sources.


%----------------------------------------------------------------------------------------
%----------------------------------------------------------------------------------------

% =====================================================================================================
%
%  EDA 	- 	Exploratory Data Analysis
%
% =====================================================================================================
\section{Missing \& Duplicate Observations}
\label{sec:EDA}

We observe an initial 97 samples in the \textit{crime\_v2.csv} file, as well as all 25 columns listed in the code book above.  An initial pass through the data reveals two obvious data-collection errors: (\textbf{a}) 6 empty rows at the tail of the file (see \ref{fig:Empty Rows}), and (\textbf{b}) one row that has been duplicated for county 193 (see \ref{fig:Duplicate Row}): \\

\begin{figure}[!ht]
	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\caption{6 rows with missing values at tail of file}
		\includegraphics[width=\linewidth]{images/EDA_empty_rows.jpg}
		\label{fig:Empty Rows}
	\end{subfigure}\vspace{3mm}% or \hspace{0.3\textwidth}
	\hfill

	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\caption{Row for county 193 duplicated}
		\includegraphics[width=\linewidth]{images/EDA_duplicate_rows.jpg}
		\label{fig:Duplicate Row}
	\end{subfigure}
	\label{fig:EDA Duplicate and Missing Rows}
	\caption{EDA : Duplicated and Missing Rows}
\end{figure}

\pagebreak

\section{Descriptive Statistics}
\label{sec:Descriptive Statistics}
%\textbf{\textcolor{OrangeRed}{EXPLORATORY DATA ANALYSIS - CONTD.}}\\

Following removal of six empty rows and one of the duplicate rows, we are left with 90 observations useful for analysis.  The descriptive statistics for the variables of interest were captured:\\

\begin{table}[!htbp]
	\centering
	\small
	\caption{EDA : Descriptive Statistics}
	\label{EDA - Descriptive Statistics}
	\begin{tabular}{@{\extracolsep{5pt}}lccccccc}
		\\[-1.8ex]\hline
		\hline \\[-1.8ex]
		Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Pctl(25)} & \multicolumn{1}{c}{Pctl(75)} & \multicolumn{1}{c}{Max} \\
		\hline \\[-1.8ex]
		county & 90 & 100.60 & 58.32 & 1 & 51.5 & 150.5 & 197 \\
		year & 90 & 87.00 & 0.00 & 87 & 87 & 87 & 87 \\
		crmrte & 90 & 0.03 & 0.02 & 0.01 & 0.02 & 0.04 & 0.10 \\
		prbarr & 90 & 0.30 & 0.14 & 0.09 & 0.20 & 0.34 & 1.09 \\
		prbconv & 90 & 0.55 & 0.35 & 0.07 & 0.34 & 0.59 & 2.12 \\
		prbpris & 90 & 0.41 & 0.08 & 0.15 & 0.36 & 0.46 & 0.60 \\
		avgsen & 90 & 9.69 & 2.83 & 5.38 & 7.38 & 11.47 & 20.70 \\
		polpc & 90 & 0.002 & 0.001 & 0.001 & 0.001 & 0.002 & 0.01 \\
		density & 90 & 1.44 & 1.52 & 0.0000 & 0.55 & 1.57 & 8.83 \\
		taxpc & 90 & 38.16 & 13.11 & 25.69 & 30.73 & 41.01 & 119.76 \\
		west & 90 & 0.24 & 0.43 & 0 & 0 & 0 & 1 \\
		central & 90 & 0.38 & 0.49 & 0 & 0 & 1 & 1 \\
		urban & 90 & 0.09 & 0.29 & 0 & 0 & 0 & 1 \\
		pctmin80 & 90 & 25.71 & 16.98 & 1.28 & 10.02 & 38.18 & 64.35 \\
		wcon & 90 & 285.35 & 47.75 & 193.64 & 250.75 & 314.98 & 436.77 \\
		wtuc & 90 & 410.91 & 77.36 & 187.62 & 374.33 & 440.68 & 613.23 \\
		wtrd & 90 & 210.92 & 33.87 & 154.21 & 190.71 & 224.28 & 354.68 \\
		wfir & 90 & 321.62 & 54.00 & 170.94 & 285.56 & 342.63 & 509.47 \\
		wser & 90 & 275.34 & 207.40 & 133.04 & 229.34 & 277.65 & 2,177.07 \\
		wmfg & 90 & 336.03 & 88.23 & 157.41 & 288.60 & 359.89 & 646.85 \\
		wfed & 90 & 442.62 & 59.95 & 326.10 & 398.78 & 478.26 & 597.95 \\
		wsta & 90 & 357.74 & 43.29 & 258.33 & 329.27 & 383.15 & 499.59 \\
		wloc & 90 & 312.28 & 28.13 & 239.17 & 297.23 & 328.78 & 388.09 \\
		mix & 90 & 0.13 & 0.08 & 0.02 & 0.08 & 0.15 & 0.47 \\
		pctymle & 90 & 0.08 & 0.02 & 0.06 & 0.07 & 0.08 & 0.25 \\
		\hline \\[-1.8ex]
	\end{tabular}
\end{table}

From the descriptive statistics, we note several potential areas of concern and interest.  First, the $\textcolor{Blue}{county}$ variable appears to be the EPA FIPS code for \href{https://en.wikipedia.org/wiki/List_of_counties_in_North_Carolina}{North Carolina counties}.  The values are odd numbered only and from Figure \ref{fig:LocationCorrectedMap} (below) we can see that the Central/West/East indicators provided in the data geographically aligns using these values as FIPS codes.\\

Additionally, the variables $\textcolor{Blue}{wser}$,  $\textcolor{Blue}{density}$, $\textcolor{Blue}{polpc}$, $\textcolor{Blue}{taxpc}$, and $\textcolor{Blue}{pctymle}$ all appear to have a distribution that suggest potential outliers.  We will explore these variables to see if there may be more issues in the data collection that we can address.

\pagebreak
\section{Outlier Analysis}
\label{sec:Outliers}

\subsection{Weekly Wage, Service Industry [WSER]}

We start with $\textcolor{Blue}{wser}$, which appears to be the \textit{average weekly income for service industry workers}.  There exists a single large maximum value of $2177.07$ which appears to be well outside the distribution of the other values (see \ref{fig:EDA WSER variable uncorrected}).  The remaining values appear to be in the range of 133-348, so it seems very unlikely that only one county has a value in the 2,000+ weekly range (\$104,000 / year) for the service industry.  The county tied to this record is 185, which is the FIPS code for \href{https://en.wikipedia.org/wiki/Warren_County,_North_Carolina}{Warren County, North Carolina}.\\

This value appears to be the result of a decimal placement issue, where the likely real value is $217.7068$, based on a survey of the counties surrounding Warren County: Vance County ($347.6609$), Franklin County ($239.2233$), Nash County ($305.7612$), Halifax County ($172.6281$), and Northampton County ($213.5822$).  Given these surrounding county wages for service industry professionals, we come to a regional mean average of $\$255.7711$:\\

\textmathbf{
\begin{equation*}
\begin{aligned}
\mu_{regional\_wser} &= \frac{Vance + Franklin + Nash + Halifax + Northampton}{n}\\
&= \frac{\textcolor{Purple}{347.6609 + 239.2233 + 305.7612 + 172.6281 + 213.5822}}{5} = \frac{1278.856}{5}\\
\therefore &= \textcolor{OrangeRed}{255.7711}
\end{aligned}
\end{equation*}
}

Given these results, we elect to remediate the large outlier in $\textcolor{Blue}{wser}$ by multiplying the value by $0.1$.  The impact to distribution of values is depicted in \ref{fig:EDA WSER variable corrected} below:\\

\begin{figure}[!ht]
	\begin{subfigure}[t]{0.5\textwidth}
		\centering
		\includegraphics[width=\linewidth,height=3in]{images/EDA_wser_uncorrected.jpg}
		\caption{WSER with uncorrected, large outlier}
		\label{fig:EDA WSER variable uncorrected}
	\end{subfigure}
	\hfill
	\begin{subfigure}[t]{0.5\textwidth}
		\centering
		\includegraphics[width=\linewidth,height=3in]{images/EDA_wser_corrected.jpg}
		\caption{WSER with large outlier corrected}
		\label{fig:EDA WSER variable corrected}
	\end{subfigure}
	\caption{Outliers : Weekly Wage, Service Industry (WSER)}
	\label{fig:EDA WSER Outlier Treatment}
\end{figure}

\pagebreak

\subsection{People per Square Mile [DENSITY]}

Observation 79 (county = 173, \href{http://www.swaincountync.gov/}{Swain County}) is currently listed with a $\textcolor{Blue}{density}$ of of 0.0000203422 people per square mile.  By a wide-margin, this is the lowest value in the dataset (see \ref{fig:EDA DENSITY variable uncorrected}) and appears to be a potential mistake.  According to Wikipedia, \href{https://en.wikipedia.org/wiki/Swain_County,_North_Carolina}{Swain County} has a landmass of 541 square miles, which would equal 0.011 people living in the entire county - an impossibility.  \\

According to \href{https://www.google.com/publicdata/explore?ds=kf7tgg1uo9ude_&met_y=population&idim=county:37173&hl=en&dl=en}{U.S. Census Bureau records}, Swain County North Carolina had a population of 10,932 in 1987.  Upon reviewing $\textcolor{Blue}{density}$ more closely along with the Census Bureau records for population and the square mile landmass reported on Wikipedia, it appears that \textcolor{OrangeRed}{\textit{this variable is actually in units of 100 people per square mile}}.  With that adjustment, the data for Swain County would still equal only 1.1 person for the entire county; which is still clearly incorrect.\\

Based on the adjusted amount of 109.32 persons (in units of 100), the correct $\textcolor{Blue}{density}$ value for Swain County in 1987 should be $0.202070$.  We adjust accordingly (see \ref{fig:EDA DENSITY variable corrected}):\\

\vspace*{0.5in}
\begin{figure}[!ht]
	\begin{subfigure}[t]{0.5\textwidth}
		\centering
		\includegraphics[width=\linewidth,height=3.5in]{images/EDA_density_uncorrected.jpg}
		\caption{log(density) with uncorrected, small outlier}
		\label{fig:EDA DENSITY variable uncorrected}
	\end{subfigure}
	\hfill
	\begin{subfigure}[t]{0.5\textwidth}
		\centering
		\includegraphics[width=\linewidth,height=3.5in]{images/EDA_density_corrected.jpg}
		\caption{log(density) with small outlier, corrected}
		\label{fig:EDA DENSITY variable corrected}
	\end{subfigure}
	\label{fig:EDA DENSITY Outlier Untreaded and Treated}
	\caption{Outliers : People per Square Mile (DENSITY)}
\end{figure}

\pagebreak

\subsection{Police per Capita [POLPC]}

There are a total of five data points in the $\textcolor{Blue}{polpc}$ variable that qualify as anomalous (\href{https://en.wikipedia.org/wiki/Outlier}{IQR Rule}), but one stands well above the others and warrants additional scrutiny.  The entry for county 115 (\href{https://www.madisoncountync.gov/}{Madison County}) has a value of $0.00905433$ (see \ref{fig:EDA POLPC variable uncorrected}), significantly higher than the other values in all other counties.  According to the \href{https://www.google.com/publicdata/explore?ds=kf7tgg1uo9ude_&met_y=population&idim=county:37173&hl=en&dl=en#!ctype=l&strail=false&bcs=d&nselm=h&met_y=population&scale_y=lin&ind_y=false&rdim=country&idim=county:37115&ifdim=country&hl=en_US&dl=en&ind=false}{U.S. Census}, Madison County, NC had a population size of only 17,051 residents in 1987 making it one of the smaller counties in the state overall.  Madison County covers only 452 square miles of geography and is located in the Northwest portion of the state, directly bordering Tennessee.\\

At this per capita level, Madison County would have $154.38538$ officers covering just 17,051 people.  The mean of the $\textcolor{Blue}{polpc}$ variable is $0.00162543$ (excluding Madison County); with this value substituted for Madison, we would have a more realistic level of $\approx 27.715$ law enforcement officers, which is in-line with other counties in the 20k and below population range.  We'll substitute with the mean for Madison County to address this apparent mistake; \ref{fig:EDA POLPC variable corrected} reflects the data distribution following the adjustment:\\

\vspace*{0.5in}
\begin{figure}[!ht]
	\begin{subfigure}[b]{0.5\textwidth}
		\centering
		\includegraphics[width=\linewidth]{images/EDA_polpc_uncorrected.jpg}
		\caption{POLPC with uncorrected, large outlier}
		\label{fig:EDA POLPC variable uncorrected}
	\end{subfigure}
	\hfill
	\begin{subfigure}[b]{0.5\textwidth}
		\centering
		\includegraphics[width=\linewidth]{images/EDA_polpc_corrected.jpg}
		\caption{POLPC with large outlier corrected}
		\label{fig:EDA POLPC variable corrected}
	\end{subfigure}
	\label{fig:EDA POLPC Outlier Treatment}
	\caption{Outliers : Police per Capita (POLPC)}
\end{figure}

\pagebreak

\subsection{Tax Revenue per Capita [TAXPC]}

Next, we analyze a single large outlier found in the $\textcolor{Blue}{taxpc}$ variable.  According to the code book (ref: \ref{fig:Code Book}), $\textcolor{Blue}{taxpc}$ is the tax revenue per capita and while the typical range is from 25 - 75, county 55 (\href{https://www.darenc.com/}{Dare County}) has a large value of $119.76$ per person.  In 1987, Dare County had a population of 19,580 according to \href{https://www.google.com/publicdata/explore?ds=kf7tgg1uo9ude_&met_y=population&idim=county:37055:37053&hl=en&dl=en}{U.S. Census records}.  The tax rate in Dare County is roughly the same as other counties at 2\% with a total state + county combined rate of 6.75\%.\\

Based on the historical tax rates and the increasing burden we see in NC taxes from 1981-1987 \href{https://www.ncleg.gov/DocumentSites/committees/FiscalModernization/Comission\%20Meetings/Nov\%2028\%20and\%2029/Nov\%2028\%20Presentations/History\%20of\%20State\%20and\%20Local\%20Taxes\%20in\%20NC\%20Paper.pdf}{(reference)}, it is not clear if the value reported in the data is incorrect.  As such, we elect not to treat this value and leave it as-is for the purposes of our analysis.\\

\vspace*{0.5in}
\begin{figure}[!ht]
\centering
\includegraphics{images/EDA_taxpc_uncorrected.jpg}
\label{fig:EDA TAXPC variable uncorrected}
\caption{Outliers : Tax Revenue per Capita (TAXPC)}
\end{figure}

\pagebreak

\subsection{Percentage of Demographic as Young Males [PCTYMLE]}

We analyze a single large outlier found in the $\textcolor{Blue}{pctymle}$ variable.  According to the code book (ref: \ref{fig:Code Book}), $\textcolor{Blue}{pctymle}$ is the percent of young males representing the county population.  County 133 (\href{https://www.onslowcountync.gov/}{Onslow County}) has a relatively large value of almost 25\%, warranting further investigation.  According to Wikipedia, \href{https://en.wikipedia.org/wiki/Onslow_County,_North_Carolina}{Onslow County} is home to the U.S. Marine Corps Base \href{https://www.lejeune.marines.mil/}{Camp Lejeune}.\\

Though women have been permitted to join the U.S. Marines since 1918, historically they have made up less than 10\% of all U.S. Marines roles \href{https://en.wikipedia.org/wiki/Women_in_the_United_States_Marines}{(reference)}. It was not until calendar year 2016 that women were allowed to serve in all roles.  In addition to this, contemporary demographics statistics report that the median age of Onslow County is 25 \href{https://en.wikipedia.org/wiki/Onslow_County,_North_Carolina}{(reference)}.  Given these data, \textcolor{OrangeRed}{\textit{we conclude that this large value is accurate}} and elect to leave it as-is for the purposes of this analysis.

\vspace*{0.5in}
\begin{figure}[!ht]
	\centering
	\includegraphics{images/EDA_pctymle_uncorrected.jpg}
	\label{fig:EDA PCTYMLE variable uncorrected}
	\caption{Outliers : Percentage of Demographic as Young Males (PCTYMLE)}
\end{figure}

\pagebreak

\section{Location Errata}

The use of one-hot encoding for location variables $\textcolor{Blue}{west}$ and $\textcolor{Blue}{central}$ is potentially problematic as it allows for the possibility of insert/update anomalies. That is, the form of the data allows for impossible assignments into more than one location.  The dataset we were provided with contains only one such anomaly for \href{http://www.gastongov.com/}{Gaston County} (FIPS code 71).  This variable has inadvertently been assigned to both the "Central" and "West" groups (see figures \ref{fig:EDA Location - Gaston County} and \ref{fig:EDA Location map - Gaston County}).\\

\begin{figure}[!ht]
	\begin{subfigure}[b]{0.5\textwidth}
		\centering
		\includegraphics[width=\linewidth]{images/EDA_location_incorrect_category.jpg}
		\caption{Gaston County assigned to two location codes}
		\label{fig:EDA Location - Gaston County}
	\end{subfigure}
	\hfill
	\begin{subfigure}[b]{0.5\textwidth}
		\centering
		\includegraphics[width=\linewidth]{images/EDA_location_map.jpg}
		\caption{Gaston and surrounding counties}
		\label{fig:EDA Location map - Gaston County}
	\end{subfigure}
	\caption{EDA : Location Category of Gaston County}
	\label{fig:Local Errata}
\end{figure}

\href{http://www.gastongov.com/}{Gaston County} is surrounded by only three North Carolina counties:  \href{https://www.clevelandcounty.com/main/}{Cleveland County} to the West, \href{https://www.lincolncounty.org/}{Lincoln County} to the North, and \href{https://www.mecknc.gov/Pages/Home.aspx}{Mecklenburg County} to the East.  In this case, all of the surrounding counties are labeled as members of the "Central" category, so \textcolor{OrangeRed}{we correct the value for Gaston by removing it from the "West" category, leaving it assigned to "Central"}.  Following this correction, all counties appear to be distributed uniformly (see \ref{fig:LocationCorrectedMap})\\

\begin{figure}[!ht]
	\centering
	\includegraphics[scale=0.9]{images/EDA_location_map_correct.jpg}
	\caption{EDA : North Carolina Geographic Boundaries (West, Central, East)}
	\label{fig:LocationCorrectedMap}
\end{figure}

\pagebreak

\section{Crime Rate by County}

Earlier, we identified the $\textcolor{Blue}{county}$ variable as the FIPS code for North Carolina counties (ref \ref{sec:Descriptive Statistics}).  We can use this information to identify counties missing from our dataset as well as plot crime rates at a county level to see if there are any overt geographical signals of crime rate.\\

We received data for only 90 of the 100 counties in North Carolina; the missing counties are shown in Figure \ref{fig:MissingCountiesList}, and are identified geographically in Figure \ref{fig:MissingCountiesGraph} [in grey].

\begin{figure}[!ht]
	\small
	\begin{minipage}[t]{0.3\textwidth}
		\caption{EDA : Missing Counties}
		\begin{tabular}[t]{{p{1.0cm}p{3.0cm}}}
			\toprule
			\textbf{FIPS} & \textbf{County} \\
			\midrule
			29  &  Camden \\
			31  &  Carteret \\
			43  &  Clay \\
			73  &  Gates \\
			75  &  Graham \\
			95  &  Hyde \\
			103  &  Jones \\
			121  &  Mitchell \\
			177  &  Tyrrell \\
			199  &  Yancey \\
			\bottomrule
		\end{tabular}
		\label{fig:MissingCountiesList}
	\end{minipage} \hfill
	\begin{minipage}[t]{0.7\textwidth}
		\centering
		\caption{EDA : North Carolina Crime by County, 1987}
		\begin{subfigure}[t]{1.0\textwidth}
			\centering
			\includegraphics[width=\linewidth]{images/EDA_crmrte_by_county.jpg}
		\end{subfigure}
		\label{fig:MissingCountiesGraph}
	\end{minipage}
\end{figure}

No apparent strong crime rate patterns exist from a purely visual geographic positioning perspective; however, it is noteworthy that counties with high crime rate per West/Central/East grouping \textit{in general} tends to increase moving West to East. \\

\begin{figure}[!ht]
	\label{fig:EDA : County Top and Bottom 10 Crime Rates}
	\begin{minipage}[t]{0.5\textwidth}
	\centering
	\caption{EDA : Top 10 Counties by Crime Rate}
	\begin{tabular}[t]{{p{1.0cm}p{3.0cm}p{2.5cm}}}
		\toprule
		\textbf{FIPS} & \textbf{County} & \textbf{Crime Rate} \\
		\midrule
		119 & Mecklenburg & $9.897 \%$ \\
		51 & Cumberland & $8.838 \%$ \\
		129 & New Hanover & $8.350 \%$ \\
		55 & Dare & $7.902 \%$ \\
		181 & Vance & $7.295 \%$ \\
		63 & Durham & $7.066 \%$ \\
		65 & Edgecombe & $6.588 \%$ \\
		135 & Orange & $6.290 \%$ \\
		67 & Forsyth & $6.142 \%$ \\
		81 & Guilford & $6.045 \%$ \\
		\bottomrule
	\end{tabular}
	\end{minipage} \hfill
	\begin{minipage}[t]{0.5\textwidth}
	\centering
	\caption{EDA : Bottom 10 Counties by Crime Rate}
	\begin{tabular}[t]{{p{1.0cm}p{3.0cm}p{2.5cm}}}
		\toprule
		\textbf{FIPS} & \textbf{County} & \textbf{Crime Rate} \\
		\midrule
		117 & Martin & $0.553 \%$ \\
		9 & Ashe & $1.062 \%$ \\
		185 & Warren & $1.087 \%$ \\
		39 & Cherokee & $1.192 \%$ \\
		169 & Stokes & $1.210 \%$ \\
		137 & Pamlico & $1.267 \%$ \\
		5 & Alleghany & $1.296 \%$ \\
		173 & Swain & $1.399 \%$ \\
		53 & Currituck & $1.407 \%$ \\
		197 & Yadkin & $1.419 \%$ \\
		\bottomrule
	\end{tabular}
	\end{minipage}
\end{figure}

\pagebreak

\section{Frequency Distribution (Natural \& Log)}
%\textbf{\textcolor{OrangeRed}{EXPLORATORY DATA ANALYSIS - CONTD.}}\\

After identifying and, when appropriate, treating outliers, we move to consider the distribution of our data.  Here, we provide a Histogram view for all raw and log transformed data only for variables that are non-binary or of no regression value (i.e.  $\textcolor{Blue}{west}$, $\textcolor{Blue}{central}$, $\textcolor{Blue}{urban}$, $\textcolor{Blue}{county}$, and $\textcolor{Blue}{year}$).  We evaluate log transformations for their common utility in improving explanatory power and natural tendency to normalize distribution:\\

\begin{figure}[!ht]
	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_crmrte.jpg}
		\caption{EDA : Histogram of CRMRTE and log(CRMRTE)}
		\label{fig:EDA Histogram CRMRTE}
	\end{subfigure}\vspace{3mm}% or \hspace{0.3\textwidth}

	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_avgsen.jpg}
		\caption{EDA : Histogram of AVGSEN and log(AVGSEN)}
		\label{fig:EDA Histogram AVGSEN}
	\end{subfigure}
	\label{fig:CRMRTE and AVGSEN Histogram}
	\caption{EDA : Distribution of Variables CRMRTE and AVGSEN}
\end{figure}

\pagebreak

\textbf{\textcolor{OrangeRed}{EXPLORATORY DATA ANALYSIS - CONTD.}}\\

Histograms Continued.\\

\begin{figure}[!ht]
	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_density.jpg}
		\caption{EDA : Histogram of DENSITY and log(DENSITY)}
		\label{fig:EDA Histogram DENSITY}
	\end{subfigure}\vspace{3mm}% or \hspace{0.3\textwidth}

	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_mix.jpg}
		\caption{EDA : Histogram of MIX and log(MIX)}
		\label{fig:EDA Histogram MIX}
	\end{subfigure}
	\label{fig:DENSITY and MIX Histogram}
	\caption{EDA : Distribution of Variables DENSITY and MIX}
\end{figure}

\pagebreak

\textbf{\textcolor{OrangeRed}{EXPLORATORY DATA ANALYSIS - CONTD.}}\\

Histograms Continued.\\

\begin{figure}[!ht]
	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_pctmin80.jpg}
		\caption{EDA : Histogram of PCTMIN80 and log(PCTMIN80)}
		\label{fig:EDA Histogram PCTMIN80}
	\end{subfigure}\vspace{3mm}% or \hspace{0.3\textwidth}

	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_pctymle.jpg}
		\caption{EDA : Histogram of PCTYMLE and log(PCTYMLE)}
		\label{fig:EDA Histogram PCTYMLE}
	\end{subfigure}
	\label{fig:PCTMIN80 and PCTYMLE Histogram}
	\caption{EDA : Distribution of Variables PCTMIN80 and PCTYMLE}
\end{figure}

\pagebreak

\textbf{\textcolor{OrangeRed}{EXPLORATORY DATA ANALYSIS - CONTD.}}\\

Histograms Continued.\\

\begin{figure}[!ht]
	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_polpc.jpg}
		\caption{EDA : Histogram of POLPC and log(POLPC)}
		\label{fig:EDA Histogram POLPC}
	\end{subfigure}\vspace{3mm}% or \hspace{0.3\textwidth}

	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_prbarr.jpg}
		\caption{EDA : Histogram of PRBARR and log(PRBARR)}
		\label{fig:EDA Histogram PRBARR}
	\end{subfigure}
	\label{fig:POLPC and PRBARR Histogram}
	\caption{EDA : Distribution of Variables POLPC and PRBARR}
\end{figure}

\pagebreak

\textbf{\textcolor{OrangeRed}{EXPLORATORY DATA ANALYSIS - CONTD.}}\\

Histograms Continued.\\

\begin{figure}[!ht]
	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_prbconv.jpg}
		\caption{EDA : Histogram of PRBCONV and log(PRBCONV)}
		\label{fig:EDA Histogram PRBCONV}
	\end{subfigure}\vspace{3mm}% or \hspace{0.3\textwidth}

	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_prbpris.jpg}
		\caption{EDA : Histogram of PRBPRIS and log(PRBPRIS)}
		\label{fig:EDA Histogram PRBPRIS}
	\end{subfigure}
	\label{fig:PRBCONV and PRBPRIS Histogram}
	\caption{EDA : Distribution of Variables PRBCONV and PRBPRIS}
\end{figure}

\pagebreak

\textbf{\textcolor{OrangeRed}{EXPLORATORY DATA ANALYSIS - CONTD.}}\\

Histograms Continued.\\

\begin{figure}[!ht]
	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_taxpc.jpg}
		\caption{EDA : Histogram of TAXPC and log(TAXPC)}
		\label{fig:EDA Histogram TAXPC}
	\end{subfigure}\vspace{3mm}% or \hspace{0.3\textwidth}

	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_wcon.jpg}
		\caption{EDA : Histogram of WCON and log(WCON)}
		\label{fig:EDA Histogram WCON}
	\end{subfigure}
	\label{fig:TAXPC and WCON Histogram}
	\caption{EDA : Distribution of Variables TAXPC and WCON}
\end{figure}

\pagebreak

\textbf{\textcolor{OrangeRed}{EXPLORATORY DATA ANALYSIS - CONTD.}}\\

Histograms Continued.\\

\begin{figure}[!ht]
	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_wfed.jpg}
		\label{fig:EDA Histogram WFED}
		\caption{Histogram of WFED}
	\end{subfigure}\vspace{3mm}% or \hspace{0.3\textwidth}

	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_wfir.jpg}
		\label{fig:EDA Histogram WFIR}
		\caption{Histogram of WFIR}
	\end{subfigure}
	\label{fig:WFED and WFIR Histogram}
	\caption{EDA : Distribution of Variables WFED and WFIR}
\end{figure}

\pagebreak

\textbf{\textcolor{OrangeRed}{EXPLORATORY DATA ANALYSIS - CONTD.}}\\

Histograms Continued.\\

\begin{figure}[!ht]
	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_wloc.jpg}
		\label{fig:EDA Histogram WLOC}
		\caption{Histogram of WLOC}
	\end{subfigure}\vspace{3mm}% or \hspace{0.3\textwidth}

	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_wmfg.jpg}
		\label{fig:EDA Histogram WMFG}
		\caption{Histogram of WMFG}
	\end{subfigure}
	\label{fig:WLOC and WMFG Histogram}
	\caption{EDA : Distribution of Variables WLOC and WMFG}
\end{figure}

\pagebreak

\textbf{\textcolor{OrangeRed}{EXPLORATORY DATA ANALYSIS - CONTD.}}\\

Histograms Continued.\\

\begin{figure}[!ht]
	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_wser.jpg}
		\label{fig:EDA Histogram WSER}
		\caption{Histogram of WSER}
	\end{subfigure}\vspace{3mm}% or \hspace{0.3\textwidth}

	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_wsta.jpg}
		\label{fig:EDA Histogram WSTA}
		\caption{Histogram of WSTA}
	\end{subfigure}
	\label{fig:WSER and WSTA Histogram}
	\caption{EDA : Distribution of Variables WSER and WSTA}
\end{figure}

\pagebreak

\textbf{\textcolor{OrangeRed}{EXPLORATORY DATA ANALYSIS - CONTD.}}\\

Histograms Continued.\\

\begin{figure}[!ht]
	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_wtrd.jpg}
		\label{fig:EDA Histogram WTRD}
		\caption{Histogram of WTRD}
	\end{subfigure}\vspace{3mm}% or \hspace{0.3\textwidth}

	\begin{subfigure}[b]{1.0\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth,height=0.30\textheight]{images/EDA_histograms_wtuc.jpg}
		\label{fig:EDA Histogram WTUC}
		\caption{Histogram of WTUC}
	\end{subfigure}
	\label{fig:WTRD and WTUC Histogram}
	\caption{EDA : Distribution of Variables WTRD and WTUC}
\end{figure}

\pagebreak

%\textbf{\textcolor{OrangeRed}{EXPLORATORY DATA ANALYSIS - CONTD.}}\\
\section{Correlation}

We assess the correlation between dependent and independent variables, excluding all binary and identifier attributes.  Intersections where there exists a low statistical significance are removed from the plot to improve visibility of significant relationships.  There appears to be the strongest Pearson r correlation of the dependent variable $\textcolor{Blue}{crmrte}$ with potential regressors $\textcolor{Blue}{density}$ (0.73), $\textcolor{Blue}{wfed}$ (0.49), and $\textcolor{Blue}{polpc}$ (0.48).\\

Superficially, the relationship between $\textcolor{Blue}{polpc}$ and $\textcolor{Blue}{crmrte}$ seems as though it might be causal in the opposite direction - that is, the more crime present, the more police the county hires.  In this sense, $\textcolor{Blue}{polpc}$ might be better thought of as a dependent variable.\\

\begin{figure}[!ht]
	\centering
	\includegraphics[width=0.9\textwidth]{images/EDA_correlation.jpg}
	\label{fig:EDA Correlation Matrix1}
	\caption{EDA : Correlation of Independent and Dependent Variables}
\end{figure}

\pagebreak

\textbf{\textcolor{OrangeRed}{EXPLORATORY DATA ANALYSIS - CONTD.}}\\

We also assess the correlation between log transforms of the variables of interest to assess the impact.  Feature intersections where there exists a low statistical significance are also removed from the plot for better visibility.  Generally, the impact is minimal to correlation between log and non-log transformed variables.\\

\begin{figure}[!ht]
	\centering
	\includegraphics[width=0.9\textwidth]{images/EDA_log_correlation.jpg}
	\label{fig:EDA Correlation Matrix2}
	\caption{EDA : Correlation of Independent and Dependent Variables}
\end{figure}


\documentclass[10pt,a4paper,onecolumn]{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{color}
\usepackage{amsmath}
\usepackage[table]{xcolor}

\begin{document}
	\title{Logic Gates}
	\author{Nkechi Grace Okoacha}
	\maketitle
\tableofcontents

\newpage
\section{Introduction}
\label{intro}
	\begin{itemize}
		\item A logic gate is a building block of a digital circuit which is at the heart of any computer operation. \\

\includegraphics{1.jpg}

		\item Behind every digital system is a logic gate. \\

		\includegraphics{2.jpg}

		\item Logic gates perform logical operations that take binary input (0s and 1s) and produce  a single binary output. They are used in most electronic device including: \\
			\begin{figure}[h!]
				\centering
				\begin{subfigure}[b]{0.35\linewidth}
				\includegraphics[width=\linewidth]{phone.jpg}
				\caption{Smartphones}
				\end{subfigure}
			\begin{subfigure}[b]{0.35\linewidth}
				\includegraphics[width=\linewidth]{tablet.jpg}
				\caption{Tablets}
			\end{subfigure}
		\begin{subfigure}[b]{0.35\linewidth}
			\includegraphics[width=\linewidth]{sdcard.jpg}
			\caption{Memory device}
		\end{subfigure}
			\end{figure}

		\item Now think of a logic gate like a light switch, it is either in an ON or OFF position. Similarly, the input output terminals are always in one of two binary positions false(0) and true(1). Each gate has its own logic or set of rules that determines how it acts based on multiple inputs outlined in a truth table. \\

		\item Combining 10s, 1000s or millions of logic gates makes it possible for a computer to perform highly complex operations and tasks at ever increasing speeds. \\

		\item A gate is a basic electronic circuit which operates on one or more signals to produce an output signal.
		Logic gates are digital circuits constructed from diodes, transistors, and resistors connected in such a way that the circuit output is the result of a basic logic operation (OR, AND, NOT) performed on the inputs. \\

		\item Fundamental gates are \color{red}AND, OR \color{black}and \color{red}NOT \\
		\includegraphics{3.jpg}

		\color{black}Derived Gates are \color{red}NAND, NOR, XOR \color{black}and \color{red}XNOR \color{black}(derived from the fundamental gates)

		Universal Gates are \color{red}NAND \color{black} and \color{red}NOR \color{black}gates (the fundamental logic gates can be realized through them).

	\end{itemize}
\section{Logic Gates}

\subsection{AND Gate}
The expression C = A X B reads as “C equals A AND B“
The multiplication sign (X) stands for the AND operation, same for ordinary multiplication of 1s and 0s.\\
\includegraphics{4.jpg}

The AND operation produces a true output (result of 1) only for the single case when all of the input variables are 1 and a false output (result of 0) where one or more inputs are 0. \\
\begin{table}[h!]
	\begin{center}
		\begin{tabular}{c|c|c}
			\textbf{A} & \textbf{B} &
			\textbf{C = A x B}\\
			\hline
			1 & 1 & 1\\
			\hline
			1 & 0 & 0\\
			\hline
			0 & 1 & 0\\
			\hline
			0 & 0 & 0\\
			\hline
		\end{tabular}
	\end{center}
\end{table} \\
\includegraphics{6.jpg}

\subsection{OR Gate}
The expression C = A + B reads as “C equals A OR B". It is the inclusive “OR”
The Addition (+) sign stands for the OR operation. \\
\includegraphics{7.jpg}

The OR operation produces a true output (result of 1) when any of the input variable is 1 and a false output (result of 0) only when all the input variables are 0. \\
\begin{table}[h!]
	\begin{center}
		\begin{tabular}{c|c|c}
			\textbf{A} & \textbf{B} &
			\textbf{C = A + B}\\
			\hline
			1 & 1 & 1\\
			\hline
			1 & 0 & 1\\
			\hline
			0 & 1 & 1\\
			\hline
			0 & 0 & 0\\
			\hline
		\end{tabular}
	\end{center}
\end{table} \\
\includegraphics{9.jpg}

\subsection{NOT Gate}
The NOT gate is called a logical inverter. \\
It has only one input. It reverses the original input (A) to give an inverted output C. \\

\color{red}C = NOT A or C = \\ \color{black}

\includegraphics{10.jpg}

\begin{table}[h!]
	\begin{center}
		\begin{tabular}{c|c}
			\textbf{A} &
			\textbf{C = $\overline{A}$}\\
			\hline
			1 & 0 \\
			\hline
			0 & 1 \\
			\hline
		\end{tabular}
	\end{center}
\end{table}
\includegraphics{12.jpg}

\subsection{NOR Gate}
The NOR (NOT OR) gate circuit is an inverter OR gate. \\

\color{red}Reads as C = NOT of A or B \\ \color{black}

C = \includegraphics{13.jpg}

The NOR Gate gives a true output (result of 1) only when both inputs are false (0) \\
\begin{table}[h!]
	\begin{center}
		\begin{tabular}{c|c|c|c}
			\textbf{A} & \textbf{B} &
			\textbf{A + B} & \textbf{C = $\overline{A + B}$}\\
			\hline
			1 & 1 & 1 & 0 \\
			\hline
			1 & 0 & 1 & 0 \\
			\hline
			0 & 1 & 1 & 0\\
			\hline
			0 & 0 & 0 & 1\\
			\hline
		\end{tabular}
	\end{center}
\end{table} \\

\color{red}The NOR Gate is a universal gate because it can be used to form any other kind of gate. \\ \color{black}
\includegraphics{15.jpg}

\subsection{NAND Gate}
The NAND (NOT AND) Gate is an inverted AND Gate \\
C = \includegraphics{16.jpg}
\color{red}Reads as C = NOT of A AND B \\ \color{black}

The NAND Gate gives a false output (result of 0) only when both inputs are true (1) \\

\begin{table}[h!]
	\begin{center}
		\begin{tabular}{c|c|c|c}
			\textbf{A} & \textbf{B} &
			\textbf{A . B} & \textbf{C = $\overline{A . B}$}\\
			\hline
			1 & 1 & 1 & 0\\
			\hline
			1 & 0 & 0 & 1\\
			\hline
			0 & 1 & 0 & 1\\
			\hline
			0 & 0 & 0 & 1\\
			\hline
		\end{tabular}
	\end{center}
\end{table}

\color{red}The NAND Gate is a universal gate because it can be used to form any other kind of gate. \\ \color{black}
\includegraphics{18.jpg}

\subsection{XOR Gate}
An XOR (exclusive OR) gate acts in the same way as the exclusive OR logical connector. \\
It gives a true output (result of 1) if one, and only one, of the inputs to the gate is true (1), i.e either or but not both \\
\color{red}$\\ c = \overline{A}.B + \overline{B}.A$ \\ \color{black}
\includegraphics{19.jpg}
\begin{table}[h!]
	\begin{center}
		\begin{tabular}{c|c|c|c|c|c|c}
			\textbf{A} & \textbf{B} & \textbf{$\overline{A}$} & \textbf{$\overline{B}$} & \textbf{$\overline{A}$ . B} & \textbf{$\overline{B}$ . A} & \textbf{$\overline{A}$ . B} + \textbf{$\overline{B}$ . A}\\
			\hline
			1 & 1 & 0 & 0 & 0 & 0 & 0\\
			\hline
			1 & 0 & 0 & 1 & 0 & 1 & 1\\
			\hline
			0 & 1 & 1 & 0 & 1 & 0 & 1\\
			\hline
			0 & 0 & 1 & 1 & 0 & 0 & 0\\
			\hline
		\end{tabular}
	\end{center}
\end{table}
\color{red}It uses a combination of three basic gates – AND, OR and NOT. \\ \color{black}

\subsection{XNOR Gate}
The XNOR (exclusive - NOR) gate is a combination XOR gate followed by an inverter. \\
 It is represented by the \color{red} c = $\overline{A.B} + \overline{B.A}$  \\ \color{black} \\
\includegraphics{21.jpg}
Its gives a  true output (1), if the inputs are the same, and a false output (0) if the inputs are different. \\
\begin{table}[h!]
	\begin{center}
		\begin{tabular}{c|c|c|c|c|c|c|c}
			\textbf{A} & \textbf{B} & \textbf{$\overline{A}$} & \textbf{$\overline{B}$} & \textbf{$\overline{A}$ . B} & \textbf{$\overline{B}$ . A} & \textbf{A} + \textbf{B} & \textbf{$\overline{A + B}$}\\
			\hline
			1 & 1 & 0 & 0 & 0 & 0 & 0 & 1\\
			\hline
			1 & 0 & 0 & 1 & 0 & 1 & 1 & 0\\
			\hline
			0 & 1 & 1 & 0 & 1 & 0 & 1 & 0\\
			\hline
			0 & 0 & 1 & 1 & 0 & 0 & 0 & 1\\
			\hline
		\end{tabular}
	\end{center}
\end{table} \\

\subsection{Logic Gates and their Truth Tables}
\includegraphics{23.jpg}

\section{Summary}
\begin{itemize}
	\item Using different combination of logic gates, complex operations can be performed.
	\item With the Universal logic gates - NAND and NOR, any other gate can be built
	\item There is no limit to the number of gates that can be arranged together in a single device.
	\item However, in practice, there is a limit to the number of gates that can be packed into a given physical space.
	\item Arrays of logic gates are found in digital integrated circuits.
	\item The logic gates are abstract representations of real electronic circuits
	\item In computers, Logic gates are built using transistors combined with other electrical components like resistors and diodes.
	\item These electrical components are wired together in order to transform a particular input to give a desired output. \cite{mygst108}
\end{itemize}

\section{Quiz}
\begin{itemize}
	\item What is the output of an AND gate if the inputs are 1 and 0?
	\item Explain the difference between the AND gate and the OR gate.
	\item What is the output of a NOT gate if the inputs is 0?
	\item Which logic gate is this?
	\item Which gate is also known
	a logical converter?
\end{itemize}

\includegraphics{24.jpg}

\newpage
\bibliographystyle{ieeetr}
\bibliography{gst}
\end{document}


The motivation for this project is to explore the implementation of multi-threading
capabilities within a working compiler and assess the benefits and trade-offs it brings
to a real-world application with a large, actively-developed body of code.

\section{REDUCE}

REDUCE \cite{reduce} is a portable general-purpose Computer Algebra System (CAS). It enables symbolic
manipulation of mathematical expressions and provides a wide range of algorithms
to solve problems spanning many fields.
It has a friendly user interface and can display maths and generate graphics.

REDUCE is one of a few open-source general-purpose CAS programs, alongside Maxima and Axiom.
The three projects are all built on top of different Lisp kernels. At the time of this writing,
none of these projects have any multi-threading capabilities. My aim is to remove this limitation
for REDUCE. The project is written in a language called RLISP, which is a specialised
Lisp dialect with an Algol-like syntax.

\section{VSL}

There are multiple implementations of the Lisp backend REDUCE uses: PSL, CSL and VSL.
Visual Standard Lisp (VSL) is an interpreted implementation written
in \texttt{C}. It is capable of building the entirety of REDUCE, supports all the major
platforms and architectures, and despite being slower than CSL or PSL it is capable of
running realistic calculations including the full REDUCE test suite.
It exists to provide a test-bed for ideas that may later move to the much larger,
compiled CSL version.

\section{Benefits of multithreading}
The idea of using parallel computing to speed up computer algebra has come
up in research papers for many years \cite{algebra-parallelism},
but much of the activity
pre-dates the now ubiquitous multi-core CPUs used in modern computers and the amount of memory
which they now provide. Moreover, advancements in single-core CPU performance have slowed down
significantly, as clock speeds have stagnated and even gone down in recent years. The biggest
area of improvement in these new CPUs is their core count and number of hardware threads.
Therefore, binding the performance of REDUCE to single-threaded performance limits the speed gains
brought by new hardware. This project involves building the infrastructure
REDUCE needs to take full advantage of today's hardware.

\section{Achievements}
\label{sec:achievements}

My project involved modifications to several thousand lines of C/C++ code, upgrading it to
make better idiomatic use of C++ as well as adding concurrency support. It has also used raw
Lisp code in bracket notation, along with the rebuilding of REDUCE, which starts off as Lisp,
but is almost entirely written in its own language. REDUCE as a whole is around half a million
lines of code and my system fully supports it. I have also coded demonstration programs to
show how it can take advantage of modern multi-core processors to improve performance,
given the thread support I now provide it with. In some cases the runtime speed more than doubled,
proving that CAS programs can benefit from multi-threading support.
The existing set of REDUCE test scripts have provided me
with significant examples to demonstrate correctness and analyse the overheads of
concurrency support on all the major platforms (Linux, Windows and MacOS), with some surprising
differences between them.