\section{Implementation}
\label{section:implementation}
A Naive Bayes classifier was implemented in Node.js \cite{node}, as a simple module with the ability to \texttt{train}
and \texttt{classify} on text, as well as some debugging interfaces such as \texttt{dump} and \texttt{restore}. This
core logic is exposed via a convenient CLI tool, which can be run locally from this project or downloaded from the
public node package manager (NPM) \cite{rdn-naive-bayes}. This CLI tool simply wraps the core Naive Bayes Classifier
with some scripting logic to process downloaded datasets of varying formats, described in
section \ref{subsection:datasets}.

\subsection{Training the Classifier}
\label{subsection:training}
Much of the work for Naive Bayes Classification takes place when training, rather than when classifying. True to this,
most of the business logic in this project resides in the \texttt{train} method, where a custom data structure is used,
making it easy to keep track of counters for (1) the total number of tokens seen, (2) the number of tokens seen for each
class, (3) the number of each token seen, and (4) the number of each token seen for each class. Using these counts,
the math is simple to find our prior and conditional probabilities when classifying.

\subsection{Classifying}
\label{subsection:classifying}
Classifying for Naive Bayes is simply a comparison of the Naive Bayes probability that a text blob belongs in each of
the known classes. The Naive Bayes simplification is that the presence of a token in a class is independent of any
other tokens found in the text blob. The formula for finding the probability a text blob belongs to a given class is
shown below. The derivation of this formula is well-known, for example see Leung's slides \cite{naive-bayes-slides}.

\begin{equation}
P(class)*\prod_{i=1}^{numTokens} P(token_i | class)
\end{equation}

One complexity with the formula is the matter of how to handle tokens you've never seen for the given
class (\begin{math}P(token_i | class)\end{math}). Algorithmically, the probability is 0, but this results in a
probability of 0 for every class when a document has a never-before-seen token. A simplification used in the
implementation presented here is to apply a \texttt{fudgeFactor} probability to these unknown tokens, such as 0.1.
This prevents new tokens from destroying our probabilities, without letting them influence a particular class too much
in the case where it has been seen in other classes.

\subsection{Tokenizing}
\label{subsection:tokenizing}
As with most Machine Learning techniques, the success of a Naive Bayes Classifier on text largely depends on what steps
are taken to normalize and slim the data before learning on it. In the case of Naive Bayes applied to learning text
blobs, the normalization and slimming step is determined by how the text blob is tokenized. By default, the classifier
implemented in this project simply splits the text by spaces, however the classifier can take an arbitrary tokenizer
function. This allows consumers to do application-specific tokenizing, such as lemmatization, or bi/tri-gramming, and
top-K word selection. Specific techniques attempted are described in section \ref{subsection:advancedResults}.

\subsection{CLI Tool}
\label{subsection:cliTool}

\begin{table}
    \begin{tabular}{lll}
        \hline
        \textbf{Option} & \textbf{Value} & \textbf{Description} \\ [0.5ex]
        \hline\hline
        --help & [bool] & Print usage \\
        --verbose & [bool] & Print debug messages \\
        --csv & [bool] & Results in CSV format \\
        --tsv & [bool] & Results in TSV (Tabs) \\
              &        & format for pasting in GDrive \\
        --inline & [bool] & Indicates --in is a file where \\
                 &        & each line is ``[class]\t[text]" \\
        --in & dir/file & Location to read text from \\
        --ratio & 1-100 & What percentage of dataset to \\
                &       & use as Training data \\
        --number & number & How many iterations to run \\
                 &        & at the given options \\
        --precision & decimals & How many decimal places to \\
                    &          & include on performance results \\
        \hline
    \end{tabular}
    \caption{Parameters available in the Naive Bayes Classifier CLI Tool at the time of this paper}
    \label{table:cliParams}
\end{table}

To simplify interactions with the Naive Bayes Classifier, a CLI tool was developed for the purpose of easily tweaking
parameters on the classifier, evaluating arbitrary datasets, and calculating \& formatting performance results.

As with the classifier, the CLI tool was developed in Node.js for rapid prototyping and ease of interfacing with the
classifier. It parses user-specified parameters in order to evaluate the Naive Bayes Classifier on arbitrary datasets.
The CLI parameters are described in table \ref{table:cliParams}.


\section{Part 7. QuadTree}

The file of the functions used for this exercise is:

\lstinputlisting{part_seven.py}

My script produces the following result, see Fig. \ref{fig:bhtree}. As can be seen, the BHTree does seem to mostly work.
In fact, while the plot seems to suggest that the BHTree did not correctly partition the space down to less than 12 particles
per node, from checking all the leaf nodes in the tree, I confirmed that there is no leaf nodes with more than 12 particles, as they would be
printed with \ref{fig:list} if so. So something seems to be wrong with the plotting, but I was unable to fix that at this time.

\begin{figure}[h!]
  \centering
  \includegraphics[width=0.9\linewidth]{./plots/bhtree.png}
  \caption{BHTree Space Separation and Points.}
  \label{fig:bhtree}
\end{figure}

The n = 0 multipole moment for the leaf node containg the particle with index i = 100 and that of
all its parent nodes up to the root node is shown here, along with the center of the box and width of the box that that
node represents:

\lstinputlisting{7.txt}\label{fig:list}


\documentclass[letterpaper]{article}

\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage[utf8]{luainputenc}
\usepackage{aeguill}
\usepackage{setspace}

\tikzstyle{edge} = [fill,opacity=.5,fill opacity=.5,line cap=round, line join=round, line width=50pt]
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{trees}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{2 mars, 2015}
\maketitle
\section*{edge ideals}
consider $\mathbb{R}$ and polynomials in $X$ with coefficients in $\mathbb{R}$.

\subsection*{example}
\begin{align*}
  x^2+1\\
  x-2\\
  \pi\\
  3x^3-5x+7
\end{align*}

we denote the set of all of these as $\mathbb{R}[x]$.

some polynomials ``do fun things''

\begin{enumerate}
\item
factor
\begin{align*}
  x^2-1&=(x+1)(x-1)\\
  x^2-2x+1&=(x-1)^2\\
  x^3-x^2+4x-4\\
  etc
\end{align*}
we say all plynomials in $\mathbb{R}[x]$ with  the property that $x-1$ divides it, this entire set is an ideal.

this is denoted $\langle x-1\rangle\subseteq \mathbb{R}[x]$

if we want all polynomials divisable by several things, then $\langle x-1,x^2+1,x^4-2\rangle$. This is ``or'' or union. the ``and'' or intersection would be formed by just multiplying the divisors.

in general $\langle f_1,\dots,f_r\rangle=\{\sum\limits_{i=1}^r{p_if_i}|p_i\in \mathbb{R}[x]\}$

we can do this in many variables like $\mathbb{R}[x,y,z]$ or $\mathbb{R}[x_1,\dots,x_n]$ or even $\mathbb{R}[x_1,\dots]$

all ideals have many invariants, eg, dimesnion, projective dimension, injective dimension, height, resolutions, betti numbers, etc.

\end{enumerate}

let $G$ be a graph and label the vertices $x_1,\dots,x_n$. then create an ideal in $\mathbb{R}[x_1,\dots,x_n]$. $I=\langle x_ix_j|x_j$

\subsubsection*{example}
\begin{tikzpicture}[main_node/.style={node distance=1cm,circle,draw,text=black,inner sep=1pt,outer sep=0pt]}]
  \node[main_node] (1)  {1};
  \node[main_node] (2) [below left of=1] {1};
\end{tikzpicture}
these ideals create a dictionary between graph theory properties and algebraic properties
\end{document}