\documentclass[11pt]{amsart}
\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.
\usepackage{pseudocode}
\geometry{letterpaper}                   % ... or a4paper or a5paper or ... 
%\geometry{landscape}                % Activate for for rotated page geometry
%\usepackage[parfill]{parskip}    % Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{epstopdf}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}

\title{IDEA}
%\author{The Author}
%\date{}                                           % Activate to display a given date or no date

\begin{document}
\maketitle
%\section{}
%\subsection{}

\section{IDEA Algorithm}

\begin{pseudocode}{IDEA}{data}

instances \gets \{\} \\
east, west \gets \CALL{findpoles}{data} \\

\FOREACH datum \in data \DO
\BEGIN
a \gets \CALL{distance}{west, datum} \\
b \gets \CALL{distance}{east, datum} \\
c \gets \CALL {distance}{east, west} \\
x \gets (b^2 - c^2 - a^2) / (-2 * c) \\
y \gets \sqrt{a^2 - x^2} \\
instances.append(\CALL{INSTANCE}{x, y, datum}) \\
\END
\\
\FOREACH instance \in instances \DO
\BEGIN
instance.x \gets log(instance.x)
instance.y \gets log(instance.y)
\END
\\
quadrants \gets \CALL{QuadrantTree}{instances}.leaves() \\
clusters \gets \CALL{GRIDCLUS}{quadrants} \\
\COMMENT{
clusters can then be used for training Naive Bayes to make a classification. }\\
\COMMENT{With IDEA, we train on the synthesized attributes x \& y. } \\
\end{pseudocode}

\begin{pseudocode}{findpoles}{data}
east \gets \CALL{randomelement}{data} \\
west \gets \CALL{farthestfrom}{east, data} \\
east \gets \CALL{farthestfrom}{west, data} \\
\RETURN{east, west}
\end{pseudocode}

\begin{pseudocode}{QuadrantTree}{instances}
\COMMENT{Root node contains all instances and covers all bounds.} \\
root \gets Quadrant{minx, maxx, miny, maxy, instances} \\
minsize \gets \sqrt{| instances |} \\
\CALL{grow}{root} \\
\end{pseudocode}

\begin{pseudocode}{grow}{quadrant}
\IF | quadrant.instances | > minsize
\THEN quadrant.children \gets quadrant.split() \\
\FOREACH child \in children \DO
\CALL{grow}{child}
\end{pseudocode}


\begin{pseudocode}{quadrant.split}{self}
\COMMENT{Create four new quadrants based on equal frequency split.} \\
x_split \gets \CALL{equal\_frequency\_x\_cut}{quadrant.instances} \\
y_split \gets \CALL{equal\_frequency\_y\_cut}{quadrant.instances} \\
q1 \gets \CALL{Quadrant}{self.xmin, x_split, self.ymin, y_split, self.instances} \\
q2 \gets \CALL{Quadrant}{x_split, self.xmax, self.ymin, y_split, self.instances} \\
q3 \gets \CALL{Quadrant}{self.xmin, x_split, y_split, self.ymax, self.instances} \\
q4 \gets \CALL{Quadrant}{x_split, self.xmax, y_split, self.ymax, self.instances} \\
\RETURN{\{q1, q2, q3, q4\}}
\end{pseudocode}

\begin{pseudocode}{GRIDCLUS}{quadrants}
\COMMENT{Sort quadrants by increasing density.} \\
clusters \gets \{\} \\
\FOREACH quadrant \in quadrants \DO
\BEGIN
\COMMENT{Always compare with the root quadrant chosen for comparison.} \\
neighbors \gets \CALL{similarneighbors}{quadrant, 50\%} \\
\FOREACH neighbor \in neighbors \DO
\CALL{neighbors.append}{\CALL{similarneighbors}{quadrant, 50\%}} \\
cluster \gets \CALL{cluster}{quadrant, neighbors} \\
clusters.append(cluster) \\
\END
\\
\COMMENT{Continue to search for neighbors until no new neighbors are found.} \\
\RETURN{clusters}
\end{pseudocode}

\end{document}  