%
% set up Oct 10th, 2013
% revision requirement:
% 1  this file finally will be the electrondynamics.tex
% 2  add more discussion to the Gauss's Law, potential etc.
% 3  add more discussion about electric field
% 4  for the part solving the Laplacian equation in spherical system,
%    we may finally separate it into the math part and add more details
%
\chapter{Coulomb Integrals}
%
%
In the two electron integrals, one of the term is the Coulomb integral which
is expressed as:
\begin{align}
\label{coulomb_int_eq:1}
 I &= \int dr \int dr^{'} \frac{\rho(r)\rho(r^{'})}{|r-r^{'}|} \nonumber \\
   &= \int dr \int dr^{'} P_{\mu\nu}P_{\lambda\eta}
   \frac{\phi_{\mu}(r)\phi_{\nu}(r)\phi_{\lambda}(r^{'})\phi_{\eta}(r^{'})}{|r-r^{'}|}
\end{align}
This expression is formed based on normal four center ERI integrals. In this
chapter, we will try to talk about how to simplify the \ref{coulomb_int_eq:1}
and make the Coulomb integral calculation more faster\footnote{Here we omit
the factor of $\dfrac{1}{2}$. $\dfrac{1}{2}$ is related to multiple change case, see
the Page of 46 in book of \cite{jackson_classic_electrodynamics}.}.

\section{Origin of Coulomb Interactions}
%
%
%
The Coulomb interactions in quantum chemistry is actually not a ``quantum''
phenomenon. It's more like to be a classic electrostatic potential term living
in the quantum world. In classic electrodynamics
\cite{jackson_classic_electrodynamics}, the electric potential for a point
charge could be as\footnote{In this chapter we omit a lot of background concepts
such as Coulomb force, electric field etc. They could be got from the above
referenced book about classic electrodynamics}:
\begin{equation}
 v(r) = \frac{1}{4\pi\varepsilon_{o}}\frac{q}{r}
\end{equation}
$q$ is the charge, and $r$ is the distance between the charge and a given point.
This is also called Coulomb potential.

The energy between this charge and a testing charge could be expressed as:
\begin{equation}
 E(r) = v(r)q^{'}
\end{equation}
this is the simplest case.

In quantum chemistry, if we express the $q$ and $q^{'}$ in terms of the electron
density, and replace the direct form with the integrand form;
then it's just the form of \ref{coulomb_int_eq:1}:
\begin{equation}
 E = \int dr \int dr^{'} \frac{\rho(r)\rho(r^{'})}{|r-r^{'}|}
\end{equation}
Such connection also indicates that we can draw some similarity between the
Coulomb interaction here with the simplest point charge case in classic
electrodynamics.

\section{Poisson Equation}
\label{laplace_spherical_electrondynamics:sec}
%
%
%
One of the important property for the classic electric field, is that for static
electric field(electrostatic field), the electric field is satisfying Gauss's Law:
\begin{equation}
 \nabla\bm{E} = 4\pi \rho
\end{equation}
$\bm{E}$ here denotes the static electric field. On the other hand, the electric
field is just the gradient of the electric potential:
\begin{equation}
 \bm{E} = -\nabla v(r)
\end{equation}
therefore for the static electric field, we can have:
\begin{equation}
 \nabla^{2} v(r) = -4\pi \rho
\end{equation}
This is the Poisson equation. For the point charge case, it could be expressed as:
\begin{equation}
\label{coulomb_int_eq:2}
 \nabla^{2} v(r) = 0
\end{equation}
Now this is the Laplace equation.

\section{Solving Laplace Equation in Sphere Coordinates}
%
%
%
One of the important application for Laplace equation is to solve it in
sphere coordinate system.

In the spherical coordinate system, it has three independent variables
which are corresponding to $x$, $y$ and $z$. Their relation is given as:
\begin{align}
 x &= r\sin \theta\cos \phi \nonumber \\
 y &= r\sin \theta\sin \phi \nonumber \\
 z &= r\cos \theta
\end{align}

On the other hand, it could be written as:
\begin{align}
 r &= \sqrt{x^{2} + y^{2} + z^{2}}  \nonumber \\
 \theta &= \arccos (z/r) \nonumber \\
 \phi   &= \arctan (y/x)
\end{align}

Based on the two expressions, we can derive the expression for $\nabla^{2}$
in terms of $r$, $\theta$ and $\phi$:
\begin{equation}
 \nabla^{2} = \frac{1}{r^{2}}\frac{\partial}{\partial r}(r^{2}
 \frac{\partial}{\partial r}) +
\frac{1}{r^{2}\sin \theta}\frac{\partial}{\partial \theta}
(\sin \theta \frac{\partial}{\partial \theta}) +
\frac{1}{r^{2}\sin^{2} \theta}\frac{\partial^{2}}{\partial \phi^{2}}
\end{equation}
Then the \ref{coulomb_int_eq:2} becomes:
\begin{align}
 &\frac{2}{r}\frac{\partial v(r,\theta,\phi)}{\partial r} +
 \frac{\partial^{2} v(r,\theta,\phi)}{\partial r^{2}} +
\frac{1}{r^{2}\sin \theta}\frac{\partial }{\partial \theta}
(\sin \theta \frac{\partial v(r,\theta,\phi)}{\partial \theta}) \nonumber \\
&+ \frac{1}{r^{2}\sin^{2} \theta}\frac{\partial^{2} v(r,\theta,\phi)}{\partial \phi^{2}} = 0
\end{align}

$v(r,\theta,\phi)$ could be divided into three independent component
functions:
\begin{equation}
 v(r,\theta,\phi) = \frac{R(r)}{r}P(\theta)Q(\phi)
\end{equation}
Then the above equation turns into:
\begin{equation}
 P(\theta)Q(\phi) \frac{d^{2} R(r)}{dr^{2}} +
 \frac{R(r)Q(\phi)}{r^{2}\sin \theta}\frac{d }{d \theta}
(\sin \theta \frac{d P(\theta)}{d \theta}) +
\frac{R(r)P(\theta)}{r^{2}\sin^{2} \theta}\frac{d^{2} Q(\phi)}{d \phi^{2}} = 0
\end{equation}

If we multiply both side with $\dfrac{r^{2}\sin^{2} \theta}{R(r)P(\theta)Q(\phi)}$,
then the above equation turns into:
\begin{equation}
\frac{r^{2}\sin^{2} \theta}{R(r)}\frac{d^{2} R(r)}{dr^{2}} +
\frac{\sin \theta}{P(\theta)}\frac{d }{d \theta}
(\sin \theta \frac{d P(\theta)}{d \theta}) +
\frac{1}{Q(\phi)}\frac{d^{2} Q(\phi)}{d \phi^{2}} = 0
\end{equation}

Obviously this function could be partitioned into two independent pieces:
\begin{align}
 \frac{1}{Q(\phi)}\frac{d^{2} Q(\phi)}{d \phi^{2}} &= -M \nonumber \\
\frac{r^{2}\sin^{2} \theta}{R(r)}\frac{d^{2} R(r)}{dr^{2}} +
\frac{\sin \theta}{P(\theta)}\frac{d }{d \theta}
(\sin \theta \frac{d P(\theta)}{d \theta}) &= M
\end{align}
Where $M$ is some constant since this satisfies all kind of variables
of $r, \theta, \phi$.

For the first equation, we can set $M$ to be $m^{2}$ then it goes:
\begin{equation}
 \frac{1}{Q(\phi)}\frac{d^{2} Q(\phi)}{d \phi^{2}} = -m^{2}
\end{equation}
It's solution is:
\begin{equation}
 Q(\phi) = e^{\pm im\phi}
\end{equation}

Therefore the second equation goes to:
\begin{equation}
 \frac{r^{2}\sin^{2} \theta}{R(r)}\frac{d^{2} R(r)}{dr^{2}} +
\frac{\sin \theta}{P(\theta)}\frac{d }{d \theta}
(\sin \theta \frac{d P(\theta)}{d \theta}) = m^{2}
\end{equation}
Where it could be written into:
\begin{equation}
 \frac{r^{2}}{R(r)}\frac{d^{2} R(r)}{dr^{2}} +
\frac{1}{P(\theta)\sin \theta}\frac{d }{d \theta}
(\sin \theta \frac{d P(\theta)}{d \theta}) = \frac{m^{2}}{\sin^{2} \theta}
\end{equation}

Similarly, in this equation the first part is only related to $r$,
and the second part (we should include the $\dfrac{m^{2}}{\sin^{2} \theta}$
into the second part) only related to $\theta$; we can separate the equation
into two equations:
\begin{align}
 \frac{r^{2}}{R(r)}\frac{d^{2} R(r)}{dr^{2}} &= l(l+1) \nonumber \\
 \frac{1}{P(\theta)\sin \theta}\frac{d }{d \theta}
(\sin \theta \frac{d P(\theta)}{d \theta}) + \frac{-m^{2}}{\sin^{2} \theta}
&= -l(l+1)
\end{align}
For the second equation, it's solution is actually based on $\cos \theta$
rather than $\theta$; therefore if we replace the $\theta$ with
$x = \cos \theta$, it would be:
\begin{equation}
\frac{d }{d x}(1-x^{2})\frac{d P}{d x} + [-\frac{m^{2}}{1-x^{2}}+l(l+1)]P = 0
\end{equation}
This is the associated Legendre equation. For $m=0$, this equation becomes
the Legendre differential equation, and it's solution is the Legendre polynomials:
\begin{equation}
 P_{l}(x) = \frac{1}{2^{n}n!}\frac{d^{l}}{dx^{l}}(x^{2}-1)^{l}
\end{equation}

The Legendre polynomials form an orthogonal functions set, which means:
\begin{equation}
 \int dx P_{l}(x) P_{m}(x) = 0
\end{equation}
if $l \neq m$.

For the radial part concerning the $R(r)$, it's able to see that it's solution
is like the form below:
\begin{equation}
 R(r) = Ar^{l+1} - Br^{-l}
\end{equation}
$A$ and $B$ are some constant, and $l$ is not fixed yet. Since the Legendre
polynomials is an orthogonal functions set, for $m=0$ case, the final solution for
equation of $\nabla^{2} v(r) = 0$ could be expressed as:
\begin{equation}\label{laplace_spherical_electrondynamics:2}
 v = \sum_{l=0}^{\infty}(Ar^{l+1} - Br^{-l})P_{l}(\cos \theta)
\end{equation}

The above solving process is for the case that $m=0$, for $m \neq 0$, we need to
solve this equation:
\begin{equation}
\frac{d }{d x}(1-x^{2})\frac{d P}{d x} + [-\frac{m^{2}}{1-x^{2}}+l(l+1)]P = 0
\end{equation}
This is the associated Legendre equation, and it's solution is the associated
Legendre polynomials:
\begin{equation}\label{}
 P^{m}_{l}(x) = (-1)^{m}\frac{(1-x^{2})^{\frac{m}{2}}}{2^{l}l!}
\frac{d^{l+m}}{dx^{l+m}}(x^{2}-1)^{l}
\end{equation}

By combing with the $Q(\phi) = e^{\pm im\phi}$, the angular part for the
$v(r)$ is:
\begin{equation}\label{}
P(\theta)Q(\phi) = (-1)^{m}\frac{(1-\cos^{2} \theta)^{\frac{m}{2}}}{2^{l}l!}
\frac{d^{l+m}}{d\cos^{l+m}\theta}(\cos^{2} \theta-1)^{l}e^{im\phi}
\end{equation}
Where $m$ could be vary from $-l$ to $+l$ for the fixed $l$.

We can further normalized the $P(\theta)Q(\phi)$, which finally turns it
into the spherical harmonic functions:
\begin{equation}\label{}
Y^{m}_{l}(\theta,\phi) = (-1)^{m}
\sqrt{\frac{2l+1}{4\pi}\frac{(l-m)!}{(l+m)!}}e^{im\phi} \frac{(1-\cos^{2}\theta)^{\frac{m}{2}}}{2^{l}l!}
\frac{d^{l+m}}{d\cos^{l+m}\theta}(\cos^{2}\theta-1)^{l}
\end{equation}

Therefore, similar with the expression of
\ref{laplace_spherical_electrondynamics:2}, the general solution
for the $\nabla^{2} v = 0$ will be:
\begin{align}\label{laplace_spherical_electrondynamics:3}
v(r,\theta,\phi) &= \sum_{l=0}^{l=\infty}\sum_{m=-l}^{m=+l}
(A_{lm}r^{l+1} - B_{lm}r^{-l})Y^{m}_{l}(\theta,\phi)
\end{align}
We note that the $A$ and $B$ could be dependent on $l$ and $m$. To get the
$A$ and $B$, we need more conditions of the potential of $v$ to fix
$A$ and $B$.

\section{Expansion of $\dfrac{1}{r_{12}}$}
\label{r12_electrondynamics:sec}
%
%
%
Now let's try to expand the $\frac{1}{r_{12}}$ based on the above
results in \ref{laplace_spherical_electrondynamics:sec}. Firstly,
for the $\frac{1}{r_{12}}$ the easiest case is that both of the two
points are lying on the same axis, for example; the Z axis:
\begin{equation}\label{}
\frac{1}{r_{12}} = \left| \frac{1}{\sqrt{r_{1}^{2}+r_{2}^{2}-2r_{1}r_{2}}}\right|
\end{equation}

Now let's introduce an variable $\alpha$ for expansion by writing the above
expression into:
\begin{align}\label{r12_electrondynamics:0}
\frac{1}{r_{12}} &= \lim_{\alpha\rightarrow 0} \frac{1}{r_{12}^{\alpha}} \nonumber \\
&=\lim_{\alpha\rightarrow 0}
\left| \frac{1}{\sqrt{r_{1}^{2}+r_{2}^{2}-2\cos \alpha r_{1}r_{2}}}\right| \nonumber \\
&= \lim_{\alpha\rightarrow 0}\frac{1}{r_{>}} \frac{1}{\sqrt{1+x^{2}-2x\cos \alpha }}
\end{align}
Where $x = \frac{r_{<}}{r_{>}}$, $r_{<}$ is the small value of $r_{1}$ and $r_{2}$,
$r_{>}$ is the larger one between $r_{1}$ and $r_{2}$. $\alpha$ is actually the
angle between the vector $\bm{r1-r2}$ and Z axis.

For expanding the bove expression, we know that it could be expressed as series
of Legendre polynomials:
\begin{equation}
 \frac{1}{\sqrt{1+x^{2}-2x\cos \alpha }} =
 \sum_{l}a_{l}P_{l}(\cos \alpha)
\end{equation}

Therefore we have:
\begin{align}
\frac{1}{\sqrt{1+x^{2}-2x\cos \alpha }} &=
 \sum_{l}a_{l}P_{l}(\cos \alpha) \Rightarrow \nonumber \\
\int_{-1}^{+1}\frac{d \cos \alpha}{1+x^{2}-2x\cos \alpha} &=
\sum_{l}a_{l}\sum_{l^{'}}a_{l^{'}}
\int^{+1}_{-1} P_{l}(\cos \alpha)P_{l^{'}}(\cos \alpha) d \cos \alpha
\end{align}
We perform it in this way is because $P_{l}(\cos \alpha)$ has a
complicated form, and through such treatment we can cancel
the $P_{l}(\cos \alpha)$.

The integration of above equation leads to:
\begin{equation}\label{r12_electrondynamics:1}
\int_{-1}^{+1}\frac{d \cos \alpha}{1+x^{2}-2x\cos \alpha} =
\sum_{l}\frac{2}{2l+1}a_{l}^{2}
\end{equation}
by using the orthogonality of Legendre polynomials.

The left hand side integration gives(remember that $x\leq 1$):
\begin{equation}
 \sum_{l}\frac{2}{2l+1}a_{l}^{2} = \frac{1}{x}\ln\left( \frac{1+x}{1-x}\right)
\end{equation}

To make the Talor expansion to the right hand side, it gives:
\begin{equation}
 \frac{1}{x}\ln\left( \frac{1+x}{1-x}\right) =
 2\sum_{l=0}^{\infty}\frac{x^{2l}}{2l+1}
\end{equation}
To compare this equation with the right hand side of \ref{r12_electrondynamics:1},
it's easy to see that:
\begin{equation}
 a_{l} = x^{l}
\end{equation}
therefore the final expansion for the \ref{r12_electrondynamics:0} is:
\begin{align}\label{r12_electrondynamics:2}
\frac{1}{r_{12}} &= \lim_{\alpha\rightarrow 0} \frac{1}{r_{12}^{\alpha}} \nonumber \\
&=\lim_{\alpha\rightarrow 0}
\left| \frac{1}{\sqrt{r_{1}^{2}+r_{2}^{2}-2\cos \alpha r_{1}r_{2}}}\right| \nonumber \\
&= \lim_{\alpha\rightarrow 0}\frac{1}{r_{>}} \frac{1}{\sqrt{1+x^{2}-2x\cos \alpha }}
\nonumber \\
&= \lim_{\alpha\rightarrow 0}\frac{1}{r_{>}}\sum_{l=0}^{\infty}
\left( \frac{r_{<}}{r_{>}}\right)^{l} P_{l}(\cos \alpha) \nonumber \\
&= \frac{1}{r_{>}}\sum_{l=0}^{\infty}
\left( \frac{r_{<}}{r_{>}}\right)^{l}
\end{align}
We also obtain the $\dfrac{1}{r_{12}}$ expansion for the $\bm{r_{12}}$
lies on the XZ plane (while the $\phi$ value is zero).

For the more general case, where the vector of $\bm{r_{1}}$ and $\bm{r_{2}}$
lie on arbitrary direction in the Cartesian coordinate system, we need to expand
the $\dfrac{1}{r_{12}}$ based on spherical harmonics rather than the Legendre
polynomials. For the spherical harmonics, it has a relation with the
Legendre polynomials(this is the addition theorem for spherical harmonics):
\begin{equation}
\label{r12_electrondynamics:3}
 P_{l}(\cos \alpha) = \sum_{m=-l}^{m=+l}
 Y_{lm}(\theta,\phi)Y_{l,-m}(\theta^{'},\phi^{'})
\end{equation}
Where the $\theta,\phi$ is related to the $\bm{r_{1}}$, and $\theta^{'},\phi^{'}$
is related to the $\bm{r_{2}}$. By inserting the \ref{r12_electrondynamics:3}
into the \ref{r12_electrondynamics:2}, we can get:
\begin{align}
\label{r12_electrondynamics:4}
|\frac{1}{r_{12}}| &= \frac{1}{r_{>}}\sum_{l=0}^{\infty}
\left( \frac{r_{<}}{r_{>}}\right)^{l} P_{l}(\cos \alpha) \nonumber \\
&=\frac{4\pi}{2l+1}\sum_{l=0}^{\infty}
\left( \frac{r_{<}^{l}}{r_{>}^{l+1}}\right)\sum_{m=-l}^{m=+l}
 Y_{lm}(\theta,\phi)Y_{l,-m}(\theta^{'},\phi^{'})
\end{align}

\subsection{Another Way to Expand the $\dfrac{1}{r_{12}}$}
%
%
%
Here we will follow Weitao's paper to rewrite the multipole expansion form.
The $\frac{1}{r_{12}}$ could be expressed as:
\begin{equation}
\frac{1}{r_{12}} = \frac{1}{r_{>}}\sum_{l=0}^{\infty}
\left( \frac{r_{<}}{r_{>}}\right)^{l} P_{l}(\cos \alpha)
\end{equation}
In the last section, our effort is trying to convert this expression into
the spherical harmonics. Here we will try to use another way to do it.

\section{Multipole Expansion}
%
%


\chapter{Conclusions and Future Work}~\label{conclusioni}
In this work, we have presented how adversarial machine learning is increasingly attracting researchers and privates due to the strong implications that it can have in real life. We have shown how in sophisticated domains, such as cyber-security, adversarial perturbations can bring to dangerous conclusions. We have in particular analyzed the impact of adversarial machine learning for the unsupervised paradigm.
After having shortly reviewed image segmentation in terms of clustering, we have noted how fooling an image segmentation algorithm can bring sophisticated systems to make dangerous decisions. \\
We have testified a lack of adversarial analysis in clustering algorithms and we have addressed this lack by performing extensive experimentation on three clustering algorithms, discovering a strong sensitivity to the adversarial perturbations. In particular, we have developed three methods for crafting adversarial examples against K-Means, Spectral and Dominant Sets clustering. The first two methods have been designed for fooling image segmentation algorithms, and we have discussed how they work along with the differences between them. The last one, instead, has been designed for fooling feature-based data clustering.
We have shown how the three clustering algorithms behave, for both applications, in presence of adversarial noise. In particular, we have seen how Spectral Clustering seems to be strongly sensitive to small perturbations with respect to the other two clustering algorithms. Moreover, we have seen how K-Means and Dominant Sets preserve a similar behavior against adversarial noise, but the latter has the advantage of working better in absence of adversarial noise.\\
During the development of this work we have realized some ideas that could be interesting to address in the future. The first one is related to the optimization of the adversarial algorithms. At the moment, the major component that results to be computationally costly is the noise evaluation, which requires multiple iterations of the clustering algorithms. A possible solution could be to develop the proposed clustering algorithms in order to work with GPUs, to speed up the computations. In our implementation the designed code is strongly scalable, meaning that it is possible to run the entire algorithm over parallel architectures without much effort. Right now, due to the absence of GPU-supported implementations of clustering algorithms, we can not run the adversarial algorithms on GPUs. Another idea for speeding up the adversarial target algorithm \ref{alg:target_clustering}, is to introduce a new heuristic that avoids the injection of noise if the target samples are locally close to the desired cluster. Indeed, at the moment target samples are always moved towards the destination cluster, meaning that the algorithm injects small perturbations even if samples are already locally close. From multiple observations, we have seen that the optimizer leaves local features more or less unchanged if samples are locally close. This consideration brings us to the conclusion that executing the optimization for those features can lead to waste computational resources, since only negligible perturbations are crafted.\\
The second topic of interest for future work is the connection between adversarial examples crafted against clustering and supervised classification models. A clustering algorithm can be seen as a way for estimating probability distributions of samples. If samples belong to the same group, then they are probably sampled from the same distribution. We believe that fooling clustering is tightly related to change the classes probability distributions. Supervised models are built with the goal of discriminating samples coming from different classes, therefore we think that adversarial examples crafted to fool clustering can even fool supervised algorithms. If we could verify the correctness of this idea then we might think to use the adversarial masks, like in Fig. \ref{noiseMaskOptimal}, generated offline against clustering algorithms, for fooling online classifiers. This strategy could be interesting for drastically reducing the computational time required for crafting adversarial examples.
%To the best of our knowledge, nowadays we require to optimize each sample --e.g. an image-- independently, in order to craft adversarial samples against classifiers. This strategy can be adopted against offline applications, or time invariant inputs. Conversely, for videos data, given that consecutive frames come from the same distribution, we think that crafting a generic adversarial mask can be sufficient for fooling multiple consecutive frames, strongly reducing the computational costs.\\
The latest idea is related to the design of the target clustering algorithm \ref{alg:target_clustering}. Indeed, it works moving samples from one cluster towards another one. We can imagine to generalize this framework allowing the attacker to move samples from a cluster towards multiple ones.\\
%We hope that with our contributions can invoke attentions from related researchers and practitioners, who
%would include security analysis in the application or development of clustering algorithms.


\documentclass[a4paper,man,natbib]{apa6}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}

% Common Packages - Delete Unused Ones %
\usepackage{setspace}
\usepackage{amsmath}
%\usepackage[cache=false]{minted}
\usepackage{graphicx}
%\usepackage{caption}
\graphicspath{ {./images/} }
\input{kvmacros}
\usepackage[dvipsnames]{xcolor}
% End Packages %

\title{Homework 5}
\shorttitle{HW5}
\author{Brandon Hosley}
\date{2018 10 30}
\affiliation{Mike Davis}

%\abstract{}

\begin{document}
\maketitle
\raggedbottom

\subsection{Problem 1}
\emph{(1 point each) Draw the non-abbreviated logic diagram. \\
	(1 point each) Construct the truth table for each.}
\subsubsection{a.}
\emph{$ ( (𝑎𝑏)′ (𝑏′𝑐)′ + 𝑎′𝑏′𝑐′ )′ $} \\
\includegraphics[width=0.7\linewidth]{1aDiagram.png}
\begin{tabular}{c c c | c}
	a & b & c & x \\
	\hline
	0 & 0 & 0 & 0 \\
	0 & 0 & 1 & 0 \\
	0 & 1 & 0 & 1 \\
	0 & 1 & 1 & 1 \\
	1 & 0 & 0 & 1 \\
	1 & 0 & 1 & 0 \\
	1 & 1 & 0 & 0 \\
	1 & 1 & 1 & 0 \\
\end{tabular}

\subsubsection{b.}
\emph{$  ( (𝑎𝑏𝑐)′ + (𝑎′𝑏′𝑐′) )′ $} \\
\includegraphics[width=0.7\linewidth]{1bDiagram.png}
\begin{tabular}{c c c | c}
	a & b & c & x \\
	\hline
	0 & 0 & 0 & 0 \\
	0 & 0 & 1 & 0 \\
	0 & 1 & 0 & 0 \\
	0 & 1 & 1 & 0 \\
	1 & 0 & 0 & 0 \\
	1 & 0 & 1 & 0 \\
	1 & 1 & 0 & 0 \\
	1 & 1 & 1 & 1 \\
\end{tabular}

\clearpage

\subsubsection{c.}
\emph{$	(𝑎 \bigoplus 𝑏) \bigoplus 𝑐 + 𝑎𝑏′𝑐 $} \\
\includegraphics[width=0.7\linewidth]{1cDiagram.png}
\begin{tabular}{c c c | c}
	a & b & c & x \\
	\hline
	0 & 0 & 0 & 0 \\
	0 & 0 & 1 & 1 \\
	0 & 1 & 0 & 1 \\
	0 & 1 & 1 & 0 \\
	1 & 0 & 0 & 1 \\
	1 & 0 & 1 & 1 \\
	1 & 1 & 0 & 0 \\
	1 & 1 & 1 & 1 \\
\end{tabular}

\subsubsection{d.}
\emph{$ ( ( (𝑎 + 𝑏)′ + 𝑐)′ + 𝑑)′ $} \\
\includegraphics[width=0.6\linewidth]{1dDiagram.png}
\begin{tabular}{c c c c | c}
	a & b & c & d & x \\
	\hline
	0 & 0 & 0 & 0 & 1 \\
	0 & 0 & 0 & 1 & 0 \\
	0 & 0 & 1 & 0 & 0 \\
	0 & 0 & 1 & 1 & 0 \\
	0 & 1 & 0 & 0 & 0 \\
	0 & 1 & 0 & 1 & 0 \\
	0 & 1 & 1 & 0 & 0 \\
	0 & 1 & 1 & 1 & 0 \\
	1 & 0 & 0 & 0 & 0 \\
	1 & 0 & 0 & 1 & 0 \\
	1 & 0 & 1 & 0 & 0 \\
	1 & 0 & 1 & 1 & 0 \\
	1 & 1 & 0 & 0 & 0 \\
	1 & 1 & 0 & 1 & 0 \\
	1 & 1 & 1 & 0 & 0 \\
	1 & 1 & 1 & 1 & 0 \\
\end{tabular}

\clearpage

\subsection{Problem 2}
\emph{(3 points each) Draw a Karnaugh map. \\
	(3 points each) Find the minimum AND-OR expression for .}
\kvnoindex
\subsubsection{a.}
\emph{$ \Sigma(2,4,5,11,13,15) $} \\
\karnaughmap{4}{$x:$}{abcd}{0010110000010101}
{
\textcolor{blue}{
	\put(2,1.5){\oval(1.9,0.9)}
}
\textcolor{red}{
	\put(2.4,0){\oval(0.9,1.9)[t]}
	\put(2.4,4){\oval(0.9,1.9)[b]}
}
	\put(0.4,2.5){\oval(0.9,0.9)}
	\put(3.5,3.5){\oval(0.9,0.9)}
} \\
$x(a,b,c,d) = $ \\
$\textcolor{blue}{acd}+
\textcolor{red}{bc'd}+
a'd'b'c+a'd'c'b$ \\
$ = d(bc'+ac)+a'd'(b'c+bc') $

\subsubsection{b.}
\emph{$\Sigma(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14) $} \\

\karnaughmap{4}{$x:$}{abcd}{1111111111111110}
{
\textcolor{blue}{
	\put(2,3){\oval(3.9,1.9)}}
\textcolor{red}{
	\put(1.8,2){\oval(1.9,3.9)}}
\textcolor{green}{
	\put(1.8,0.5){\oval(3.9,0.9)}}
\textcolor{orange}{
	\put(3,2){\oval(0.9,3.9)}}
} \\
$ x(a,b,c,d) $ \\
$ = \textcolor{blue}{a'}+
\textcolor{red}{b'}+
\textcolor{green}{ac'}+
\textcolor{orange}{bd'} $ \\
$ = (ab)'+ac'+bd' $

\clearpage

\subsection{Problem 3}
\emph{(3 points each) Draw a Karnaugh map. \\
	(3 points each) Find the minimum AND-OR expression for x(a,b,c,d) with don’t care conditions.}
\subsubsection{a.}
\emph{$ \Sigma(0,3,14) + d(2,4,7,8,10,11,13,15) $} \\

\karnaughmap{4}{$x:$}{abcd}{10x1x00xx0xx0x1x}
{
\textcolor{blue}{
	\put(2,2){\oval(1.9,1.9)}}
\textcolor{green}{
	\put(0.4,2){\oval(0.9,3.9)}}
\textcolor{red}{
	\put(1.8,1.5){\oval(3.9,0.9)}}
} \\
$ x(a,b,c,d) $ \\
$ = \textcolor{blue}{cd}+
\textcolor{green}{b'd'}+
\textcolor{red}{ac} $ \\
$ = ac+cd+b'd' $

\subsubsection{b.}
\emph{$ \Sigma(1,6,9,12) + d(0,2,3,4,5,7,14,15) $} \\

\karnaughmap{4}{$x:$}{abcd}{x1xxxx1x010010xx}
{
\textcolor{blue}{
	\put(3.5,2){\oval(0.9,3.9)}}
\textcolor{red}{
	\put(1.4,0){\oval(0.9,1.9)[t]}
	\put(1.4,4){\oval(0.9,1.9)[b]}}
} \\
$ x(a,b,c,d) $ \\
$ = \textcolor{blue}{bd'}+
\textcolor{red}{b'c'd} $

\clearpage
\subsection{Problem 4}
\singlespacing
\emph{For this diagram; } \\
\includegraphics[width=.6\linewidth]{Problem4Diagram.png}
\subsubsection{}
\emph{Draw the truth table.} \\

\begin{center}
	\begin{tabular}{r | c c | c c}
		$s$ & $a$ & $b$ & $x$ & $y$ \\
		\hline
		1 & 0 & 0 & 0 & 0 \\
		1 & 0 & 1 & 0 & 1 \\
		1 & 1 & 0 & 1 & 0 \\
		1 & 1 & 1 & 1 & 1 \\
		0 & 0 & 0 & 0 & 0 \\
		0 & 0 & 1 & 1 & 1 \\
		0 & 1 & 0 & 0 & 1 \\
		0 & 1 & 1 & 1 & 1 \\
	\end{tabular}
\end{center}

\subsubsection{}
\emph{Draw 2 K-Maps one for output of x and one of for output of y.} \\
\begin{center}

\begin{minipage}{2in}
	\karnaughmap{3}{$x:$}{asb}{01000111}{
		\textcolor{blue}{
			\put(2,1.5){\oval(1.9,0.9)}}
		\textcolor{red}{
			\put(2.8,0.5){\oval(1.9,0.9)}}}
\end{minipage}
\begin{minipage}{2in}
	\karnaughmap{3}{$y:$}{asb}{00011101}{
		\textcolor{blue}{
			\put(3,1.5){\oval(1.9,0.9)}}
		\textcolor{red}{
			\put(1.8,0.5){\oval(1.9,0.9)}}}
\end{minipage}
\end{center}

\subsubsection{}
\emph{Find \& show the minimum AND-OR expressions - one for f(x) and one for f(y)} \\

\begin{center}
	$f(x)=\textcolor{red}{sa}+\textcolor{blue}{s'b}$ \\
	$f(y)=\textcolor{red}{sb}+\textcolor{blue}{s'a}$ \\
\end{center}

\subsubsection{}
\emph{Construct one circuit using only AND, OR, and inverter gates.} \\

\begin{center}
	\includegraphics[width=0.45\linewidth]{4dDiagram.png}
\end{center}

\subsection{Problem 5}
\doublespacing
\includegraphics[width=.8\linewidth]{Figure10,57.png} \\
\emph{Implement the following logic units for the Pep/8 ALU: \\
Logic unit 6, $ \overline{ A \cdot B } $} \\
\includegraphics[width=\linewidth]{5diagram.png}

\nocite{warford10}
\bibliographystyle{apacite}
\bibliography{CS}
\end{document}


We tackle the same problem as is found in \cite{Zhang_2015_CVPR, guan2021understanding} of
subitization. However, there are a few differences between this implementation and each of those
implementations. In contrast to \cite{Zhang_2015_CVPR}, they work with a much wider definition of
subitization, in which the counter can count every kind of object; the domain is not restricted to
objects of the same type or roughly of the same type. We use a dataset that is extremely trivial
(uniform shapes in an image with a black backgroud) relative to their dataset. Though ambiguous
according to \cite{subitizingdefinition}, we believe that theirs is the correct interpretation,
especially from personal experience. Therefore, their problem is more difficult in this respect.
However, they stick with the common mindset of four objects being the maximum subitization
capability, and so compare their results to that limit (again, with a single category that pertains
to images with four or more objects). We do not believe this is a thorough test of the capabilities
of neural networks, and (though this fact was not a motivation for us) we take a stab at the neural
network learning to count an arbitrary number of objects. However, ``arbitrary'' does not mean
boundless as there can only be so many shapes within an image (a strong upper bound would be the
number of pixels in the image, but that is not a supremum). Both \cite{Zhang_2015_CVPR} and our work
attempt to detect objects using a classifier trained to count. However, our method performs the
localization as a byproduct of the second derivative of counting, which, although not exactly clear
due to time limits we had and ambiguity in the paper, differs from their methods; one of them uses
the output of the model as a guide for a separate counting method, for example.

% ^^^edit^^^: change "that" to "than"
With respect to \cite{guan2021understanding}, they make much stronger claims than this author feels
comfortable with. We aim to show that these networks can indeed subitize (up to a
object-dissimilarity limit), regardless of whether or not it is terribly accurate. Further, they
pose this problem as determining connected components, which allows them to make a claim that one
connecting pixel should be considered as merging two components into one. We think this is a dubious
argument, mostly because that for the example that they show~\cite{guan2021understanding}[figure
12], the vast majority of people would not likely be able to see the pixel-wide connection, and
therefore four separate components would have been the guess by most. Coincidentally, we also happen
to look at shapes, although we try to mix in different kinds and sizes of shapes into the same
image; they do try different sizes, but the sampling process is different (which we will use in our
implementation as a potential solution to poor saliency output).

The definition of our problem is as follows: given an image and a network, can we train the network
to successfully count shapes in a subitization fashion? The shapes were automatically generated with
random positioning; shape overlap detection was performed with the recommended\cite{viaforshapely}
Shapely\cite{shapely} package, and any overlap rejected that shape's location. Two possible shapes,
triangles and squares\footnote{This may be Professor David Crandall's idea} can be generated. Images
were drawn and saved with Pillow~\cite{imagesinpython}. Larger shapes resulted in proper learning;
we had no luck with smaller shapes. The network is a convolutional network, with no other layers
besides activation functions and a linear layer at the end to output a single
ReLU\cite{pmlr-v15-glorot11a}\footnote{This reference is commonly pointed to as the source of
ReLU}-filtered number. This is done because the network~\cite{szegedy2014going} they use in
\cite{10.1007/978-3-319-46487-9_48} does as well (except for the output layer). The loss function is
mean squared error, with the ground truth being the raw number of each kind of shape (this is in
contrast to \cite{Zhang_2015_CVPR}, which had separate classes that represented different counts).
Because the images are automatically generated, we are able to use extremely large datasets, which
may not be a reasonable expectation when training on non-artificial data. For now, we stick with
shapes as it is a simplified problem for which a proof-of-concept could lead to further research
into whether the concept can be applied in the real world (not just from a subitization standpoint,
but also from a detection one as well). We used Chainer~\cite{tokui2019chainer} to implement our
research in this section, as well as CuPy~\cite{cupy_learningsys2017}, NumPy~\cite{2020NumPy-Array},
and Python 3~\cite{language}. There was previous code that addressed this topic based on
PyTorch~\cite{NEURIPS2019_9015}; we did use it to some extent, but it was rewritten to use Chainer
later on. This code may have used Nesterov momentum instead.

\subsection{Detecting Shapes}
\label{detectingshapes}

To perform the detection step, a trained network\footnote{trained with small batch sizes as we found
this useful for some reason; it could be that small batch sizes increase variance, which results in
kind of a simulated annealing-like behavior} and an image are used to generate a saliency map via
the method described in \cite{simonyan2014deep}. However, instead of backpropagating from the
correct class's output (there is no concept of ``class'' in our network), we backpropagate from the
addition of all the outputs (which ideally would give us the total number of shapes), one output
squares and one for triangles. This addition occurs (most likely; thank the author's short memory)
because the aim is to detect \textit{all} shapes within the image, not just one type; however, it
would be good to see if saliency for a single shape type could be used (depending on the success of
the original method, of course).

The detection step comes in by exploiting the (yet unproven) property that the gradient of one pixel
depends on the value of another. Ideally, if the derivative of the saliency of the pixel w.r.t.
another pixel changes, then that implies that the changing value of the latter pixel (for this
example, it decreases to become more like the background) causes the former to take on more of a
representational burden in order to keep the object count up. However, it is possible that every
pixel in the image can change the second derivative of the target pixel. To see why, let's look at
the first derivative w.r.t. the image ($f$ is the sum over the estimated shape count, $x_i$ is
subpixel $i$ of image $x$, and $a_k$ is the output of layer $k$ for image $x$):
\[
    \frac{\partial f}{\partial x_i} = \frac{\partial f}{\partial a_k} \frac{\partial a_k}{\partial x_i}
\]
If we take the partial derivative of $\frac{\partial f}{\partial x_i}$ w.r.t. subpixel $j$, we see
that the product rule gives us non-zero values for some or all parts of the domain following what is
shown in section \ref{gradientmagnitudereduction}; the difference here is that we don't use a
non-linear loss function, so at least one activation function for this network \textit{must} be
non-linear (even if the function is piecewise, as described in \ref{gradientmagnitudereduction}) for
this to be true. We do not go over why not all layers have to have a non-zero second derivative in
that section (although work on the topic of \ref{gradientmagnitudereduction} likely preceded, and
therefore was the foundation of, this the idea of the type of activation causing second-order
issues), so we will do that here. Here is the analytical derivation of the second derivative:
\begin{multline*}
    \frac{\partial}{\partial x_j}     \frac{\partial a_4}{\partial a_3} \frac{\partial a_3}{\partial a_2} \frac{\partial a_2}{\partial a_1} \frac{\partial a_1}{\partial x_i} = \\[10pt]
    \frac{\partial f_3}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_4}{\partial a_3} \right)       +       \frac{\partial a_4}{\partial a_3} \left( \frac{\partial}{\partial x_j} \frac{\partial f_3}{\partial x_i} \right)\\[10pt]
    = \frac{\partial f_3}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_4}{\partial a_3} \right)       +       \frac{\partial a_4}{\partial a_3}         \left[
                \frac{\partial f_2}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_3}{\partial a_2} \right)       +       \frac{\partial a_3}{\partial a_2} \left( \frac{\partial}{\partial x_j} \frac{\partial f_2}{\partial x_i} \right)
      \right]\\[10pt]
    = \frac{\partial f_3}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_4}{\partial a_3} \right)       +       \frac{\partial a_4}{\partial a_3}         \left[
                \frac{\partial f_2}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_3}{\partial a_2} \right)       +       \frac{\partial a_3}{\partial a_2}          \left[
                        \frac{\partial f_1}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_2}{\partial a_1} \right)       +       \frac{\partial a_2}{\partial a_1} \left( \frac{\partial}{\partial x_j} \frac{\partial f_1}{\partial x_i} \right)
                \right]
      \right]\\[10pt]
    = \frac{\partial f_3}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_4}{\partial a_3} \right)       +       \frac{\partial a_4}{\partial a_3}         \left[
                \frac{\partial f_2}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_3}{\partial a_2} \right)       +       \frac{\partial a_3}{\partial a_2}          \left[
                        \frac{\partial f_1}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_2}{\partial a_1} \right)       +       \frac{\partial a_2}{\partial a_1} \left( \frac{\partial}{\partial x_j} \frac{\partial a_1}{\partial x_i} \right)
                \right]
      \right]
\end{multline*}
We can simplify this rather complex series of additions, and this looks like
\begin{multline*}
     \frac{\partial f_3}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_4}{\partial a_3} \right)       +       \frac{\partial a_4}{\partial a_3}         \left[
                \frac{\partial f_2}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_3}{\partial a_2} \right)       +       \frac{\partial a_3}{\partial a_2}          \left[
                        \frac{\partial f_1}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_2}{\partial a_1} \right)       +       \frac{\partial a_2}{\partial a_1} \left( \frac{\partial}{\partial x_j} \frac{\partial a_1}{\partial x_i} \right)
                \right]
      \right]\\[10pt]
     = \frac{\partial f_3}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_4}{\partial a_3} \right)       +       \frac{\partial a_4}{\partial a_3}         \left[
                \frac{\partial f_2}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_3}{\partial a_2} \right)       +
                         \frac{\partial a_3}{\partial a_2} \frac{\partial f_1}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_2}{\partial a_1} \right)       +        \frac{\partial a_3}{\partial a_2} \frac{\partial a_2}{\partial a_1} \left( \frac{\partial}{\partial x_j} \frac{\partial a_1}{\partial x_i} \right)
       \right]\\[10pt]
     = \frac{\partial f_3}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_4}{\partial a_3} \right)       +
                \frac{\partial a_4}{\partial a_3} \frac{\partial f_2}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_3}{\partial a_2} \right)       +
                         \frac{\partial a_4}{\partial a_3} \frac{\partial a_3}{\partial a_2} \frac{\partial f_1}{\partial x_i}  \left( \frac{\partial}{\partial x_j} \frac{\partial a_2}{\partial a_1} \right)       +
                                \frac{\partial a_4}{\partial a_3} \frac{\partial a_3}{\partial a_2} \frac{\partial a_2}{\partial a_1} \left( \frac{\partial}{\partial x_j} \frac{\partial a_1}{\partial x_i} \right)
\end{multline*}
We can expand this process to any number of layers. However, if each activation function has a
second derivative of $0$, the whole equation collapses to $0$; we discuss why this is relevant and a
problem shortly. If the last activation function's gradient has a gradient that is non-zero, then we
cannot guarantee the network's complete second derivative will end up being zero at some subpixel
$x_j$. This is essentially the same point that \ref{gradientmagnitudereduction} makes (and it may
have been based on it too). This conclusion requires that the derivatives of the derivatives of an
activation with respect to another evaluate (for example, $\left( \frac{\partial}{\partial x_j}
\frac{\partial a_4}{\partial a_3} \right)$) to zero. This happens to be the case because the second
derivative between two layers is zero, and the left-over derivative of the incoming set of
activations w.r.t. $x_j$ due to the chain rule application are nullified because it is multiplied by
the aforementioned second derivative. So, avoiding zero-valued second derivatives is necessary (one
non-zero second derivative will possibly result in a non-zero, end-to-end second derivative because
every addition in the above equation could give us something non-zero)\footnote{Stefan Lee confirmed
my math (at least for ReLU) as he also believed that $\frac{\partial^2 f}{\partial x_i}$ is required
to be non-zero}.

\subsection{Algorithm}
\label{algorithm}

Now that we have established the basic concepts and requirements for our localization procedure, we
can outline ways in which detection may happen. A way that we attempted (but were never able to
fully iron-out) and inspired by the thresholding used in \cite{reeves}[3:58] is that we take the
highest saliency~\cite{simonyan2014deep} value (which corresponds to a certain pixel $i$), and then
calculate the second derivative of that value w.r.t.\ each pixel within the image (forming a
saliency map in the same way that \cite{simonyan2014deep} does, but using the second derivative ---
this was done to ensure that second derivative values do not become negative when formulated as
saliency due to the absolute value used in \cite{simonyan2014deep}, and also to merge the three
channels of derivatives that would result under normal partial derivative calculation of the first
saliency map; this is why \cite{simonyan2014deep} takes these steps). We choose to backpropagate
from the most salient pixel as, intuitively, that is the pixel most likely to be on a shape. We then
threshold the second-derivative using some kind of intelligently chosen value, giving us a set of
pixels that hopefully are related enough to the original pixel. Using this set, it is possible to
draw a bounding-box around them, giving us detection. After this, we remove these pixels (including
the one from which we backpropagated) from the set of unassigned pixels. We do this for each $i$
(where $i$ is from the remaining pixels) until we no longer have no more shapes to find (based on
the count output by the network).

% Other papers^^^^^^ that do qualitative analysis look into results without it being in a dedicated
% results section, so I decided that it is OK for me to do that here (don't remember if I used those
% previous works for this reason before I started writing this, or as justification for keeping it
% the way I have it while I was writing this).
Unfortunately, we did not find this method reliable. For starters, the second derivatives only
covered, at most, about half of the shape, which would leave us with an incomplete bounding box.
This could be due to a poorly-chosen threshold value, but we did not have enough time to try other
values. However, we also noticed that a lot of the selected second-derivative pixels were between
two shapes, which obviously would cause poor localization. This is actually not that surprising;
remember, the first derivative was the derivative for the predicted count. If a pixel in-between is
chosen as $i$, then it likely influence the part of the total count that corresponds to the two
shapes; as a result, it would not be surprising that pixels local to $i$ would determine $i$'s first
derivative (say, if a new shape started to form using those children pixels). It is important to
note that the case before this could be because these shapes were further away than others. However,
as one can see in figure \ref{shapecorrelation}, the spatial breadth of the selected pixels is not
nearly the same, so we may be able to make the claim that we did anyway. Another issue is that, as
the loop continued, fewer shape-like structures formed by the second derivative were selected; many
of the points were extremely local. A more intelligent pixel selection method would likely improve
this method substantially. Regardless, we definitely see promising results (see figure
\ref{shapecorrelation}) that make it clear (barring any missed strange scenarios that allow these
images) that the network is probably learning some form of representation, especially because figure
\ref{inputs} show that the most saliency is being placed on the edges and the corners, what are
likely the only features that these shapes have. The original image and its saliency can be seen in
figure \ref{inputs}. Note that all experimental saliency pictures, including those for the
saliencies of the saliency, have slight tweaks to them: we have taken the 10th root of each saliency
output pixel so that the extrema are closer together, thus improving image readability, and they
were normalized for image output (this applies only to saliency maps, not the thresholded images).
Further, Pillow was used to transform this output to image files. This also applies to the saliency
maps generated for each saliency pixel. This is inspired by plots that use the log scale on the
y-axis.

\begin{figure}[th]
    \begin{center}
        \begin{tabular}{c c}
            \includegraphics[width=2in, height=2in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image1/touse/001.png} & \includegraphics[width=2in, height=2in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image1/touse/saliency.png} \\
            \includegraphics[width=2in, height=2in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image2/touse/007.png} & \includegraphics[width=2in, height=2in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image2/touse/saliency.png}
        \end{tabular}
    \end{center}
    \caption{The first image is the image that the network sees, while the second image is the
             saliency for that image}
    \label{inputs}
\end{figure}

\begin{figure}[t]
    \begin{center}
        \begin{tabular}{c c c}
            \includegraphics[width=1.5in, height=1.5in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image1/touse/8.png}          & \includegraphics[width=1.5in, height=1.5in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image1/touse/2.png}          & \includegraphics[width=1.5in, height=1.5in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image1/touse/17.png}          \\
            \includegraphics[width=1.5in, height=1.5in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image2/touse/1.png}          & \includegraphics[width=1.5in, height=1.5in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image2/touse/2.png}          & \includegraphics[width=1.5in, height=1.5in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image2/touse/3.png}           \\
            \includegraphics[width=1.5in, height=1.5in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image1/touse/8-saliency.png} & \includegraphics[width=1.5in, height=1.5in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image1/touse/2-saliency.png} & \includegraphics[width=1.5in, height=1.5in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image1/touse/17-saliency.png} \\
            \includegraphics[width=1.5in, height=1.5in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image2/touse/1-saliency.png} & \includegraphics[width=1.5in, height=1.5in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image2/touse/2-saliency.png} & \includegraphics[width=1.5in, height=1.5in]{Counting/LaTeX/figures/putasideall/limitscaleresamplingoptionnetworkputaside/image2/touse/3-saliency.png}
        \end{tabular}
    \end{center}
    \caption{Each of the first two row represents a different image. The first images for these
             clearly shows the partial outline of a shape, while the second depicts the situation of
             a pixel being associated with multiple shapes. The third is the case where saliency
             selection derails and the area selected is not, or partially not, meaningful. Their
             full maps before thresholding are in the third and fourth rows.}
    \label{shapecorrelation}
\end{figure}

\subsection{Tweaks}

Initially, our ReLU-activated network was trained on images of shapes that did not vary in size.
Prediction was extremely accurate, so much so that it was suggested\footnote{by the author's
advisor, David Crandall} that the network may be effectively adding up the number of black pixels
(non-shape pixels) and dividing it by the number of pixels within a shape, or that corners were
being counted instead (a graph of the network output against the ground truth created with
\cite{Hunter:2007} when classifying both shapes and squares confirmed this). To ameliorate this
issue, the network was trained on shapes of different sizes and was restructured to be
bigger\footnote{David Crandall implied that capacity might be a potential issue}. The ability of the
network to predict correctly was significantly reduced but was not bad, initially indicating that
the network had learned some kind of representation of the shapes. Further, it gave us saliency maps
that appeared to be what we were looking for, which was that the network learned the representation
of the shapes itself (see figure \ref{initialsaliency}). However, due to the problem of the second
derivative mentioned above, the second derivative did not give us anything meaningful. As a result,
SoftPlus~\cite{NIPS2000_44968aec} was tried, but this resulted in numerical issues that sill might
have squeaked some interesting detection pixels (see figure \ref{norenormalizationsoftplus}).

\begin{figure}
    \begin{center}
        \begin{tabular}{c c}
            \includegraphics[width = 3in, height = 3in]{Counting/LaTeX/figures/putasideall/nolimitscaleresamplingoptiondifferentactivation2networkputaside/image1/saliency.png} & \includegraphics[width = 3in, height = 3in]{Counting/LaTeX/figures/putasideall/nolimitscaleresamplingoptiondifferentactivation2networkputaside/image2/saliency.png}
        \end{tabular}
    \end{center}
    \caption{ReLU-based saliency.}
    \label{initialsaliency}
\end{figure}

\begin{figure}
    \begin{center}
        \begin{tabular}{c c}
            \includegraphics[width = 3in, height = 3in]{Counting/LaTeX/figures/putasideall/nolimitscaleresamplingoptiondifferentactivation3networkputaside/image1/saliency.png} & \includegraphics[width = 3in, height = 3in]{Counting/LaTeX/figures/putasideall/nolimitscaleresamplingoptiondifferentactivation3networkputaside/image1/1.png}
        \end{tabular}
    \end{center}
    \caption{Our first attempt at using SoftPlus~\cite{NIPS2000_44968aec}}
    \label{norenormalizationsoftplus}
\end{figure}

We moved to a sigmoid activation function (although we are not entirely sure why), with the network
trained with Batch Renormalization~\cite{ioffe2017batch} (to get the sigmoid network to actually
converge), but that only put the saliency in the blank space of the image. This is shown in figure
\ref{badsaliency}. This remained a frustrating issue until we found \cite{guan2021understanding},
which states ``[a]lthough sizes are random in a range, the average size...stabl[izes] [as] the
number of objects increases''~\cite{guan2021understanding}[page 3]. As a result, for two images that
have the same counts, the number of relevant pixels will remain the same, which makes the network's
job as easy as counting pixels. Therefore, we implemented the solution that they proposed, which was
to use randomly-sized shapes, with all the shapes in the image taking on that random size. Size
resampling happens after each image is generated. In \cite{guan2021understanding}, they allocated a
static number of pixels to the image, and thus the size of the shape depended on how many shapes
were to be put in that image. However, we made a slight tweak: we decoupled the number of shapes
from limit on the number of pixels, and just made sure to pick a range of scales that allowed all
the shapes to fit in a worst-case scenario (this was likely the problem they were trying to avoid by
imposing the aforementioned limit). We decided to go this way because it seemed less likely that the
neural network would find another non-optimal way to regress. The result from this method is
discussed in the previous section.

\begin{figure}
    \begin{center}
        \begin{tabular}{c c}
            \includegraphics[width = 2.3in, height = 2.3in]{Counting/LaTeX/figures/putasideall/nolimitscaleresamplingoptiondifferentactivationnetworkputaside/image1/saliency.png}   & \includegraphics[width = 2.3in, height = 2.3in]{Counting/LaTeX/figures/putasideall/nolimitscaleresamplingoptiondifferentactivationnetworkputaside/image2/saliency.png} \\
            \includegraphics[width = 2.3in, height = 2.3in]{Counting/LaTeX/figures/putasideall/nolimitscaleresamplingoptiondifferentactivationnetworkputaside/image1/1-saliency.png}   & \includegraphics[width = 2.3in, height = 2.3in]{Counting/LaTeX/figures/putasideall/nolimitscaleresamplingoptiondifferentactivationnetworkputaside/image2/1-saliency.png} \\
            \includegraphics[width = 2.3in, height = 2.3in]{Counting/LaTeX/figures/putasideall/nolimitscaleresamplingoptiondifferentactivationnetworkputaside/image1/1.png} & \includegraphics[width = 2.3in, height = 2.3in]{Counting/LaTeX/figures/putasideall/nolimitscaleresamplingoptiondifferentactivationnetworkputaside/image2/1.png}
        \end{tabular}
    \end{center}
    \caption{The first row shows saliency maps for two images, the second row shows the connection
             strength between the most salient pixel and others, and the third row are the pixels
             that ``qualify'' as being part of a shape}
    \label{badsaliency}
\end{figure}

Further tweaks need to address the problem discussed in section \ref{algorithm}. Regarding the most
salient pixels being between shapes, it may be necessary to modify the loss function from which to
backpropagate. Candidates would need to encode encouraging strong gradients that \textit{only}
relate to decreasing the count by one. Another option is to threshold the first derivative saliency
from above. As a result, errant pixels in the gap between shapes with large saliency would not be
considered. Further, as stated previously, automatic determination of both thresholds would be
substantially better than manual settings. This would become even more crucial when tackling
real-world issues. An alternative solution may be to use K-means to group low, medium and high
saliency pixels. The idea is that we would only stick with the medium-saliency pixels as the high
saliency group would have many pixels that may change the count too much; rejecting those with low
saliency values was justified previously. One may need to consider the distance metric to be used;
for example, high saliency pixels may be distributed in an exponential fashion, so normal Euclidean
distance would leave many undesired saliencies in the acceptable group.

Further, it is important to point out that real-world circumstances may actually provide
\textit{better, more reliable} saliency values. Counting shapes may have a significant flaw, which
is that ordinary, monocolor shapes really don't have many features outside of their edges and
corners\footnote{David Crandall reminded me about corners possibly being important.}. If there are
features that are internal to the object, it may result in cleaner saliency values that are focused
on the object itself. However, it is also possible that the network learns to identify one component
that many objects in the image share, and, as a result, its children pixels do not span the object
entirely, making bounding box prediction problematic.

% ^^^edit2^^^ said that the first quotation mark wasn't the correct kind, which made me realize that
% I didn't use the proper `` and '', so this was changed.
Our code and models can be found in the ``Counting'' folder at \cite{mycode}.


\providecommand{\main}{..}
\documentclass[\main/main.tex]{subfiles}
\begin{document}
\chapter{Metric distribution summary}
The metrics seem to follow these sample distributions:

\begin{table}
  \begin{tabular}{|l|l|}
    \hline
    \textbf{Metric}     & \textbf{Distribution} \\
    \hline
    CpGobsExp           & Beta                  \\
    \hline
    CpGperCpG           & Beta                  \\
    \hline
    CpGperGC            & Gaussian              \\
    \hline
    DGVCount            & Gamma                 \\
    \hline
    DnaseClusteredHyp   & Gamma                 \\
    \hline
    EncH3K27Ac          & Gamma                 \\
    \hline
    GCContent           & Gaussian              \\
    \hline
    EncH3K4Me3          & Gamma                 \\
    \hline
    ISCApath            & Gamma                 \\
    \hline
    DnaseClusteredScore & Beta                  \\
    \hline
    EncH3K4Me1          & Gamma                 \\
    \hline
    GerpRS              & Gamma                 \\
    \hline
    GerpRSpv            & Gamma                 \\
    \hline
    commonVar           & Exponential Weibull   \\
    \hline
    dbVARCount          & Gamma                 \\
    \hline
    fantom5Perm         & Gamma                 \\
    \hline
    fantom5Robust       & Gamma                 \\
    \hline
    mamPhastCons46way   & Gamma                 \\
    \hline
    priPhastCons46way   & Gamma                 \\
    \hline
    rareVar             & Beta                  \\
    \hline
    verPhastCons46way   & Gamma                 \\
    \hline
    numTFBSConserved    & Exponential           \\
    \hline
    fracRareCommon      & Beta                  \\
    \hline
    priPhyloP46way      & Beta                  \\
    \hline
    verPhyloP46way      & Gaussian              \\
    \hline
    mamPhyloP46way      & Gaussian              \\
    \hline
  \end{tabular}
  \caption{Metrics and their distribution}
\end{table}

\end{document}


\documentclass{memoir}
\usepackage{notestemplate}

%\logo{~/School-Work/Auxiliary-Files/resources/png/logo.png}
%\institute{Rice University}
%\faculty{Faculty of Whatever Sciences}
%\department{Department of Mathematics}
%\title{Class Notes}
%\subtitle{Based on MATH xxx}
%\author{\textit{Author}\\Gabriel \textsc{Gress}}
%\supervisor{Linus \textsc{Torvalds}}
%\context{Well, I was bored...}
%\date{\today}

%\makeindex

\begin{document}

% \maketitle

% Notes taken on 05/31/21

\subsection{Generators and Relations}
\label{sec:generators_and_relations}

First, we will give an initial perspective of groups via generators and relations, and then revisit the symmetric group under this light.
\begin{defn}[Generator]
	A subset \(S\) of elements of a group \(G\) is called a \textbf{generator} if every element can be written as a finite product of elements (and their inverses) of \(S\). We denote this by \(\langle S \rangle =G\) and when this holds say that \(G\) is \textbf{generated by} \(S\).
\end{defn}
Of course, we need to know exactly what happens to these products of elements in order to get a structure for \(G\).

\begin{defn}[Relations and Presentations]
	Let \(G = \langle S \rangle \) be a group generated by \(S\). Any equations \(R_i\) that elements in the generator satisfy are called \textbf{relations}. If there is some collection of relations \(R_1,\ldots,R_m\) such that any relation among elements of \(S\) can be deduced from, we call these generators and relations a \textbf{presentation} of \(G\), denoted by
	\begin{align*}
		G = \langle S \mid R_1,R_2,\ldots,R_m \rangle .
	\end{align*}
\end{defn}

\begin{exmp}[Dihedral Group]
	The dihedral group \(D_{2n}\) can be viewed as a presentation given by
	\begin{align*}
		D_{2n} = \langle r,s \mid r^{n}=^2=1, \; rs = sr^{-1} \rangle .
	\end{align*}
\end{exmp}
Showing that a presentation is equivalent to a group structure is non-trivial. Relations can often be tricky, in that there are often "hidden" relations that arise from combining two relations in different ways. As a result, often the best way to show that a presentation indeed corresponds to our group is to show bounds on the order of the presentation, and show that it has the same order as the group desired. Then provided your group satisfies the relations, it is likely that it is the only group (of that order) that does so.

% \printindex
\end{document}