\chapter{Many-body dispersion method}\label{chap:mbd}

{\sffamily This chapter presents new developments within the many-body dispersion (MBD) method, namely the reciprocal-space formulation, the MBD dielectric constant, several analytical results for the MBD wave function, and the analysis of the MBD nuclear forces and self-consistency.
Some of these results are used in the following chapters.
All the presented results have been implemented in program `pymbd' \citep{HermannZ17}, which is a standalone Python program as well as a Fortran library included in electronic-structure programs FHI-aims and DFTB+.
}

\section{Reciprocal-space formulation}

In a crystal, the matrices involved in the multipole expansion of the polarizability are infinite, and the normal real-space formalism becomes intractable.
The most straightforward resolution is to cut a sufficiently large piece of the crystal consisting of multiple unit cells, a supercell, and apply periodic boundary conditions by summing the dipole operator over the periodic images.
As shown below, this formalism, while conceptually simple, is not very efficient.
The supercell approach is an unnecessary complication that introduces the issue of slow convergence with respect to the supercell size and makes the MBD calculation computationally as expensive as the corresponding KS-DFT calculation in some cases.
The formalism developed in this section resolves these problems.

A more natural formulation uses the discrete version of the Fourier transformation in~\eqref{eq:fourier-discrete}.
The trace over the infinite number of atoms in a crystal in the MBD version of the ACFD formula in~\eqref{eq:mbd-rpa} is then transformed into a trace over atoms in a single unit cell and the reciprocal-space vectors from the first Brillouin zone, $\mathbf q$,
\begin{gather}
\begin{aligned}
  E_\text{c,lr}^\text{MBD}
    &=\frac1{2\pi}\int_0^\infty\mathrm du
    \operatorname{Tr}_{\mathbf qp\mathbb R^3}\big(
      \ln(1+\boldsymbol\alpha_\text{eff}(\mathrm iu)\mathbf T_\text{lr}(\mathbf q))
    \!\big) \\
  &=\frac{(2\pi)^3}{\Omega_\text{UC}}\int\mathrm d\mathbf q\sum_{n=1}^{3N}\frac{\tilde\omega_n(\mathbf q)}2-\sum_{p=1}^N3\frac{\omega_p}2
\end{aligned} \\
\boldsymbol\alpha_{\text{eff},p}(\mathbf q,\mathrm iu)=\sum_{\mathbf R}\boldsymbol\alpha_{\text{eff},\mathbf R_p,\mathbf R+\mathbf R_p}(\mathrm iu)\mathrm e^{\mathrm i\mathbf q\cdot\mathbf R}=\boldsymbol\alpha_{\text{eff},p}(\mathrm iu) \\
\mathbf T_{\text{lr},pq}(\mathbf q)=\sum_{\mathbf R}\mathbf T_{\text{lr},\mathbf R_p,\mathbf R+\mathbf R_q}\mathrm e^{-\mathrm i\mathbf q\cdot(\mathbf R_p-\mathbf R-\mathbf R_q)}
\end{gather}
The diagonalization of $\mathbf Q(\mathbf q)$ that leads to $\tilde{\boldsymbol\omega}(\mathbf q)$ maps again exactly on the solution of the Fourier-transformed dipole-coupled Hamiltonian, and the diagonalizing vectors, $\mathbf V(\mathbf q)$, correspond to periodic collective electron oscillations with wavelength $2\pi/|\mathbf q|$, described by collective coupled coordinates $\boldsymbol\xi'(\mathbf q)$.
\citet{BuckoJPCM16} presented the reciprocal-space formulation of MBD without performing the analytic integration over the frequency.

\begin{figure}
\makebox[\textwidth][c]{
\begin{tikzpicture}
\node[below right, anchor=base] at (0,0) {{\bfseries a}};
\node[below right] at (-.5,.5) {\includegraphics{media/convergence-graphene.pdf}};
\node[below right, anchor=base] at (\linewidth/2,0) {{\bfseries b}};
\node[below right] at (\linewidth/2-.5,.5) {\includegraphics{media/convergence-argon.pdf}};
\end{tikzpicture}
}
\caption{\textbf{Convergence of energy in the supercell and reciprocal-space approach.}
Different convergence behavior for the 2D graphene layer (\textbf a) and the 3D argon crystal (\textbf b).
}\label{fig:mbd-convergence}
\end{figure}

The reciprocal-space formulation provides superior computational efficiency compared to the supercell approach for two reasons.
The only two computationally demanding tasks in calculating the MBD energy are the formation of the dipole operator, with complexity $O(N^2)$, $N$ being the number of atoms, and the diagonalization or inversion of matrices, with complexity $O(N^3)$.
Except for the smallest systems, the latter dominates.
The reciprocal-space integration over $\mathbf q$ is easily performed on an equidistant grid of $N_q$ vectors, and the calculation of the MBD energy then involves $N_q$ diagonalizations of the matrix $\mathbf Q(\mathbf q_n)$.
Each diagonalization has a computational complexity $O(N^3)$, $N$ being the number of atoms in the unit cell, and the total complexity is $O(N_q N^3)$.
In effective 1D and 2D systems (chains and layers), the rates of convergence of the energy with respect to the number of cells in the supercell, $N_\text c$, and to the number of points in the $\mathbf q$-grid are equal (Figure~\ref{fig:mbd-convergence}a), so for a given desired accuracy, $N_\text c=N_q$.
But the computational cost of the supercell calculation is $O\big((N_\text cN)^3\big)=O\big(N_\text c^3N^3)$, $N_\text c^2$ times larger than that of the reciprocal-space calculation.
The second reason for the better efficiency of the reciprocal-space formulation is that because the lattice sums of the dipole operator are not absolutely convergent in 3D systems, the energy converges slower with $N_\text{c}$ in the supercell approach than with $N_q$ in the reciprocal-space formulation for 3D systems (Figure~\ref{fig:mbd-convergence}b), so for a given required accuracy, $N_q<N_\text c$.

The lattice sum in the definition of $\mathbf T_\text{lr}(\mathbf q)$ can be efficiently computed using the Ewald summation in~\eqref{eq:ewald}.
The optimum balance between the computational cost of the real-space and reciprocal-space sum in the Ewald sum is reached by setting $\alpha=2.5/\sqrt[3]{\Omega_\text{UC}}$ (a.u.).
Using the real-space cutoff of $6/\alpha$ and reciprocal-space cutoff of $10\alpha$ then leads to MBD energies that are accurate up to 10 significant digits with respect to fully converged references, while the computational cost is typically by two or more orders of magnitude smaller compared to sufficiently converged calculations of MBD energies without Ewald summation.

\section{Dielectric function from MBD}

All approximate vdW methods based on the range-separated ACFD formula can be tested in two independent ways.
Testing against accurate reference polarizabilities gives information about $\boldsymbol\alpha_\text{eff}$ and $\mathbf T_\text{eff}$, but is independent of the range-separation mechanism expressed in $\mathbf T_\text{lr}$, whereas comparison against benchmark interaction energies tests all these three components combined.
For bulk material, there is no straightforward measurable equivalent of the total polarizability of a molecule.
(The total polarizability of a finite crystal sample depends on its shape.)
But an indirect measure of the bulk polarizability is provided by the macroscopic dielectric function.

Using the definitions in Section~\ref{sec:dielectric} and the Fourier transformation, $\mathcal F$, of the gradient operator, the dielectric function of the MBD model can be calculated straightforwardly,
\begin{gather}
\begin{aligned}
  \hat{\mathbf q}\cdot\boldsymbol\epsilon_\text{M}(u)\hat{\mathbf q}&=\lim_{\mathbf q\rightarrow0}\frac1{1+v(|\mathbf q|)\chi_{\mathbf 0\mathbf 0}(\mathbf q,u)} \\
  &=\lim_{\mathbf q\rightarrow0}\frac1{1+\frac{4\pi}{|\mathbf q|^2}\mathcal F[\boldsymbol\nabla\cdot\boldsymbol\nabla'\cdot\boldsymbol\alpha]_{\mathbf 0\mathbf 0}(\mathbf q,u)} \\
  &=\lim_{\mathbf q\rightarrow0}\frac1{1+\frac{4\pi}{|\mathbf q|^2}\mathbf q\cdot\boldsymbol\alpha_{\mathbf 0\mathbf 0}(\mathbf q,u)\mathbf q} \\
  &=\lim_{\mathbf q\rightarrow0}\frac1{1+4\pi\hat{\mathbf q}\cdot\boldsymbol\alpha_{\mathbf 0\mathbf 0}(\mathbf q,u)\hat{\mathbf q}} \\
  &\approx\lim_{\mathbf q\rightarrow0}\frac1{1+\frac{4\pi}{\Omega_\text{UC}}\hat{\mathbf q}\cdot\big(\sum_{pq}\boldsymbol\alpha_{pq}(\mathbf q,u)\!\big)\hat{\mathbf q}} \\
\end{aligned} \\
\boldsymbol\alpha(\mathbf q,u)=\big(\boldsymbol\alpha_\text{eff}^{-1}(u)+\mathbf T_\text{eff}(\mathbf q,u)\!\big)^{-1}
\end{gather}
The Unsöld approximation inherent in the MBD polarizability makes this approach of little use for the dynamic dielectric function, but the static dielectric constant should be represented as accurately as total polarizabilities of molecules.
Here, the use of the Ewald summation is crucial, since the required cutoff of the full real-space summation diverges as $\mathbf q\rightarrow0$.

In a simple cubic lattice, the bare dipole operator, $\mathbf T(\mathbf q)$, can be written in closed form for small $\mathbf q$,
\begin{equation}
  \mathbf T(\mathbf q)=\frac{4\pi}{\Omega_{\text{UC}}}(\hat{\mathbf k}\otimes\hat{\mathbf k}-\tfrac13\mathbf I)+O(|\mathbf q|)
\end{equation}
The expression for the dielectric function above then yields the Clausius--Mossotti equation,
\begin{equation}
  \frac{\epsilon_\text{M}(0)-1}{\epsilon_\text{M}(0)+2}=\frac{4\pi}3\frac{\alpha_\text{eff}(0)}{\Omega_\text{UC}}
\end{equation}
With more complex unit cells and the effective dipole operator from MBD, the resulting dielectric function is in general anisotropic.
Therefore, this approach can be interpreted as a generalization of the Clausius--Mossotti approximation.

\section{Properties of dipole-coupled wave function}

The diagonalization of the $\mathbf Q$ matrix of the MBD Hamiltonian in~\eqref{eq:dosc-hamil} results in the coupled resonance frequencies, $\tilde{\boldsymbol\omega}$, which give the MBD energy, as well as the eigenvectors, $\mathbf V=(\mathbf v_1\mathbf v_2\ldots)$, which define the coupled coordinates, $\hat{\boldsymbol\xi}=\mathbf V^\mathrm T\boldsymbol\xi$, in which the MBD Hamiltonian decouples into a noninteracting Hamiltonian.
The ground-state wave function is the product of harmonic-oscillator ground-state wave functions,
\begin{equation}
\psi_0(\{\tilde\xi_n\})=\prod_n\left(\frac{\tilde\omega_n}{\pi}\right)^\frac14\exp\left(-\tfrac12\tilde\omega_n\tilde\xi_n^2\right)
\label{eq:mbd-wave}
\end{equation}
This section presents several new analytical results for this correlated wave function, some of which are used in Chapter~\ref{chap:pi-pi}.

\subsection{Charge density}

When interpreted as an approximation to the full electronic Hamiltonian, the pseudo electrons in the MBD Hamiltonian effectively model the polarizable electrons in the valence shells of atoms.
One may then ask what is the charge density of these pseudo electrons, how is it different from the noninteracting system, and whether this change captures the true electron-density redistribution caused by long-range electron correlation.

The charge density of any system of $N$ charged particles is defined as an expectation value of the charge-density operator,
\begin{equation}
n(\mathbf r)=\langle\Psi|\sum_i q_i|\mathbf r_i=\mathbf r\rangle\langle\mathbf r_i=\mathbf r|\Psi\rangle=\idotsint\mathrm d\mathbf r_1\cdots\mathrm d\mathbf r_N\sum_i q_i\delta(\mathbf r-\mathbf r_i)\Psi(\{\mathbf r_j\})^2
\label{eq:density}
\end{equation}
To evaluate this expression for~\eqref{eq:mbd-wave}, we first transform the wave function back to $\boldsymbol\xi$ and gather the product of the exponentials,
\begin{equation}
\Psi(\{\xi_i\})=\left(\prod_i\left(\frac{\tilde\omega_i}{\pi}\right)^\frac14\right)\exp\Bigg(-\tfrac12\sum_{jk}\underbrace{\sum_i V_{ji}\tilde\omega_i V_{ki}}_{\Omega_{jk}}\xi_j\xi_k\Bigg)
\label{eq:wavefnc}
\end{equation}
In the following, we use $\sum_{i\notin A}$ for a sum that skips the $A$-th particle and $\sum_{i\in A}$ for a sum over the three Cartesian coordinates of the $A$-th particle.
For a given $A$, we divide the sum over $jk$ according to the order of $\xi_{i\in A}$,
\begin{equation}
\begin{aligned}
\sum_{jk}\Omega_{jk}\xi_j\xi_k&=\sum_{\substack{j\notin A\\k\notin A}}\Omega_{jk}\xi_j\xi_k+2\sum_{\substack{p\in A\\k\notin A}}\Omega_{pk}\xi_p\xi_k+2\sum_{\substack{p\in A\\q\in A}}\Omega_{pq}\xi_p\xi_q \\
&\equiv\boldsymbol\xi'^{\mathrm T}_A\boldsymbol\Omega''_A\boldsymbol\xi'_A+2\boldsymbol\xi_A'^{\mathrm T}\boldsymbol\Omega'_A\boldsymbol\xi_A+\boldsymbol\xi_A^{\mathrm T}\boldsymbol\Omega_A\boldsymbol\xi_A
\end{aligned}
\end{equation}
The linear term can be removed by completing the square with respect to $\boldsymbol\xi'_A$,
\begin{equation}
\sum_{jk}\Omega_{jk}\xi_j\xi_k=({\boldsymbol\xi'}^{\mathrm T}_A-\mathbf h_A^{\mathrm T})\boldsymbol\Omega''_A(\boldsymbol\xi'_A-\mathbf h_A)+\boldsymbol\xi_A^{\mathrm T}\boldsymbol\Omega_A\boldsymbol\xi_A-\boldsymbol\xi_A^{\mathrm T}\boldsymbol\Omega'^{\mathrm T}_A\boldsymbol\Omega_A''^{-1}\boldsymbol\Omega_A'\boldsymbol\xi_A
\label{eq:completesq}
\end{equation}
Here, $\mathbf h_A$ is some quantity that does not depend on $\boldsymbol\xi'_A$.
We can now factor out the exponential and the $3N$-dimensional integral,
\begin{equation}
n(\mathbf r)=\sum_A q_A\left(\idotsint\mathrm d\mathbf r_1\cdots\mathrm d\mathbf r_{A-1}\mathrm d\mathbf r_{A+1}\mathrm d\cdots\mathbf r_N\right)\int\mathrm d\mathbf r_A\delta(\mathbf r-\mathbf r_A)\ldots
\end{equation}

First, we evaluate the integrals in parentheses.
Because $\mathbf h_A$ is just a constant coordinate shift, and the integrals are over the whole space, $\mathbf h_A$ can be transformed away.
Furthermore, we can rotate $\boldsymbol\Omega''_A$ into a new basis where it becomes diagonal, which factors the $3(N-1)$-dimensional integral into a product of $3(N-1)$ 1-dimensional integrals over Gaussian functions of the form $\exp(-\bar\omega_{A,i}\bar\xi_{A,i}^2)$, where $\bar\omega_{A,i}$ are the eigenvalues of $\boldsymbol\Omega''_A$.
(The factor of $\frac12$ disappears due to the square of the wave function.)

Second, the integral over $\mathbf r_A$ picks the value of the following function at point $\mathbf r$ via the $\delta$-function,
\begin{equation}
\exp\big(-\boldsymbol\xi_A^\mathrm T(\underbrace{\boldsymbol\Omega_A-{\boldsymbol\Omega'}^\mathrm T_A\boldsymbol\Omega_A''^{-1}\boldsymbol\Omega_A'}_{\boldsymbol\Omega^{(A)}})\boldsymbol\xi_A\big)
\end{equation}
Combining~\eqref{eq:density},~\eqref{eq:wavefnc},~\eqref{eq:completesq}, and the previous two paragraphs, and transforming from $\boldsymbol\xi_A$ back to $\mathbf r_A$, we get
\begin{equation}
n(\mathbf r)=\sum_A q_A\left(\frac{m_A}\pi\right)^\frac32\sqrt{\frac{\prod_{i=1}^{3N}\tilde\omega_i}{\prod_{i=1}^{3(N-1)}\bar\omega_{A,i}}}\exp\big(-m_A(\mathbf r-\mathbf R_A)^\mathrm T\boldsymbol\Omega^{(A)}(\mathbf r-\mathbf R_A)\big)
\label{eq:mbd-density}
\end{equation}

\subsection{First-order perturbation correction}

The dipole-coupled wave function can serve as a zeroth-order Hamiltonian in a perturbation expansion with the perturbation equal to the difference between the full Coulomb interaction and the dipole interaction, $\hat V_{ee}-\hat V_\mathbf{pp}$.
The first-order correction does not capture any correlation energy from the higher multipoles (those start at second order), but it can serve as a measure of how effective is the Gaussian-screened dipole potential of MBD at mimicking the full Coulomb interaction at short range.

The first-order perturbation energy is just the expectation value of the perturbation Hamiltonian for the ground state,
\begin{equation}
E^{(1)}_\text{MBD}=\langle\psi_0|V_\text{ee}-V_{\mathbf{pp}}|\psi_0\rangle
\end{equation}
The expectation value of the Coulomb operator is a sum of two-particle terms,
\begin{equation}
\langle\psi_0|\tfrac12\sum_{AB}\frac{q_A q_B}{\lvert\mathbf r_A-\mathbf r_B\rvert}|\psi_0\rangle
\end{equation}
In analogy to the calculation of $n(\mathbf r)$, for each particle pair we rotate the $3(N-2)$ coordinates that are not in the Coulomb term such that the corresponding integrals become integrals over Gaussian functions, and then evaluate the remaining 6-dimensional integral over $\mathbf r_A$ and $\mathbf r_B$.

Introducing $\boldsymbol\xi_{AB}=(\boldsymbol\xi_A\boldsymbol\xi_B)$, a 6-dimensional vector, and $\boldsymbol\Omega^{(AB)}$ which is an equivalent of $\boldsymbol\Omega^{(A)}$ from the previous section, we can write the necessary integral as
\begin{equation}
I_1=\iint\mathrm d\boldsymbol\xi_A\mathrm d\boldsymbol\xi_B \frac{\exp\big(-\boldsymbol\xi_{AB}^\mathrm T\boldsymbol\Omega^{(AB)}\boldsymbol\xi_{AB}\big)}{\lvert\mathbf r_A-\mathbf r_B\rvert}
\label{eq:intcoulomb}
\end{equation}
We start by rewriting the Coulomb potential as an integral,
\begin{equation}
\frac1{\lvert\mathbf r_A-\mathbf r_B\rvert}=\frac2{\sqrt\pi}\int_0^\infty\mathrm du\exp(-\lvert\mathbf r_A-\mathbf r_B\rvert^2u^2)
\end{equation}
Inserting into $\eqref{eq:intcoulomb}$, and transforming to $\mathbf r_A$, we get a 7-dimensional integral over a Gaussian,
\begin{multline}
I_1=2\sqrt{\frac{m_A m_B}\pi}\iint\mathrm d\mathbf r_A\mathrm d\mathbf r_B\int_0^\infty\mathrm du \\
\times\exp\big[-(\mathbf r_{AB}-\mathbf R_{AB})^\mathrm T\boldsymbol\Omega_m'^{(AB)}(\mathbf r_{AB}-\mathbf R_{AB})-\mathbf r_{AB}^\mathrm T\mathbf U_2\mathbf r_{AB}\big]
\end{multline}
Here, $\boldsymbol\Omega'^{(AB)}$ absorbed the masses and $\mathbf U_2$ is defined as
\begin{equation}
\mathbf U_2=u^2\begin{pmatrix}
1&0&0&-1&0&0\\
0&1&0&0&-1&0\\
0&0&1&0&0&-1\\
-1&0&0&1&0&0\\
0&-1&0&0&1&0\\
0&0&-1&0&0&1
\end{pmatrix}
\end{equation}
Following with the integrand only, we rearrange terms and complete the square with respect to $\mathbf r_{AB}$,
\begin{multline}
\exp\big[-\mathbf r_{AB}^\mathrm T(\boldsymbol\Omega_m'^{(AB)}+\mathbf U_2)\mathbf r_{AB}+2\mathbf R_{AB}^\mathrm T\boldsymbol\Omega_m'^{(AB)}\mathbf r_{AB}-\mathbf R_{AB}^\mathrm T\boldsymbol\Omega_m'^{(AB)}\mathbf R_{AB}\big] \\
=\exp\big[-(\mathbf r_{AB}-\mathbf h_{AB})^\mathrm T(\boldsymbol\Omega_m'^{(AB)}+\mathbf U_2)(\mathbf r_{AB}-\mathbf h_{AB})\big] \\
\times\exp\big[-\mathbf R_{AB}^\mathrm T\big(\boldsymbol\Omega_m'^{(AB)}-\boldsymbol\Omega_m'^{(AB)}(\boldsymbol\Omega_m'^{(AB)}+\mathbf U_2)^{-1}\boldsymbol\Omega_m'^{(AB)}\big)\mathbf R_{AB}\big]
\end{multline}

As in the charge-density calculation, the first exponential can be shifted and rotated into a diagonal form, upon which the spatial integrals can be easily evaluated,
\begin{equation}
\iint\mathrm d\mathbf r_A\mathrm d\mathbf r_B\exp\big[-\mathbf r_{AB}^\mathrm T(\boldsymbol\Omega_m'^{(AB)}+\mathbf U_2)\mathbf r_{AB}\big]=\frac{\pi^3}{\sqrt{\prod_{i=1}^6\lambda_{AB,i}(u)}}
\end{equation}
Here, $\lambda_{AB,i}(u)$ are the eigenvalues of $(\boldsymbol\Omega_m'^{(AB)}+\mathbf U_2)$. The remaining 1-dimensional integral over $u$ from 0 to $\infty$ has a finite integrand that decays exponentially to zero, and can be quickly evaluated numerically.

Combining all parts together, we get
\begin{multline}
\langle\Psi|\tfrac12\sum_{AB}\frac{q_A q_B}{\lvert\mathbf r_A-\mathbf r_B\rvert}|\Psi\rangle
=\frac12\sum_{AB}q_A q_B\sqrt{\frac{\prod_{i=1}^{3N}\tilde\omega_i}{\prod_{i=1}^{3(N-2)}\bar\omega_{AB,i}}} \\
\times\int_0^\infty\mathrm du\frac{\exp\big[-\mathbf R_{AB}^\mathrm T\big(\boldsymbol\Omega_m'^{(AB)}-\boldsymbol\Omega_m'^{(AB)}(\boldsymbol\Omega_m'^{(AB)}+\mathbf U_2)^{-1}\boldsymbol\Omega_m'^{(AB)}\big)\mathbf R_{AB}\big]}{\sqrt{\prod_{i=1}^6\lambda_{AB,i}(u)}}
\label{eq:coulombrr}
\end{multline}

The calculation of the dipole term, $\langle\psi_0|V_\mathbf{pp}|\psi_0\rangle$, is straightforward.
First, we transform the dipole potential to the coupled basis and gather the prefactors,
\begin{equation}
  \tilde T_{ij}=\sum_{kl}C_{ki}C_{lj}\omega_k\omega_l\sqrt{\alpha_{k}(0)\alpha_{l(0)}}T_{kl}
\end{equation}
Then,
\begin{multline}
\langle\Psi|V_\mathbf{pp}|\Psi\rangle=\langle\Psi|\tfrac12\sum_{ij}\tilde\xi_i\tilde\xi_j\tilde T_{ij}|\Psi\rangle \\
=\frac12\sum_{i\neq j}\tilde T_{ij}\left(\frac{\tilde\omega_i\tilde\omega_j}{\pi^2}\right)^\frac14\int\mathrm d\tilde\xi_i\tilde\xi_i\exp\left(-\frac12\tilde\omega_i\tilde\xi_i^2\right)\int\mathrm d\tilde\xi_j\tilde\xi_j\exp\left(-\frac12\tilde\omega_j\tilde\xi_j^2\right) \\
+\frac12\sum_{i}\tilde T_{ii}\sqrt{\frac{\tilde\omega_i}{\pi}}\int\mathrm d\tilde\xi_i\tilde\xi_i^2\exp\left(-\tilde\omega_i\tilde\xi_i^2\right)=\sum_i\frac{\tilde T_{ii}}{4\tilde\omega_i}
\label{eq:dipoleterm}
\end{multline}
The $i\neq j$ terms vanished because the integrands are odd functions.

\subsection{Anisotropic Gaussian screening}

The technique used in the previous section can be also used to generalize the Gaussian screening of the Coulomb interaction, used in MBD to derive the effective dipole interaction, to anisotropic Gaussian charge densities.
This might be used to construct appropriate range separation for atomic fragments with anisotropic polarizabilities, which is investigated in Chapter~\ref{chap:polarizability}.
Integrals of the same kind are routinely evaluated in all quantum-chemistry algorithms based on Gaussian basis sets, but those are always with isotropic Gaussian functions.

The electrostatic energy of two Gaussian unit-charge densities located at $\mathbf R_A$ with anisotropic widths $\boldsymbol\sigma_A=1/\sqrt{\mathbf K_A}$ is expressed as an integral similar in form to~\eqref{eq:intcoulomb},
\begin{equation}
I_2(\mathbf K_1,\mathbf K_2)=\frac{\sqrt{\det(\mathbf K_1\mathbf K_2)}}{\pi^3}\iint\mathrm d\mathbf r_1\mathrm d\mathbf r_2\frac{\mathrm e^{-(\mathbf r_1-\mathbf R_1)\cdot\mathbf K_1(\mathbf r_1-\mathbf R_1)}\mathrm e^{-(\mathbf r_2-\mathbf R_2)\cdot\mathbf K_2(\mathbf r_2-\mathbf R_2)}}{\lvert\mathbf r_1-\mathbf r_2\rvert}
\end{equation}
The prefactor ensures proper normalization,
\begin{equation}
\lim_{a\rightarrow\infty} I_2(a\mathbf K_1,a\mathbf K_2)=\frac1{\lvert\mathbf R_1-\mathbf R_2\rvert}
\end{equation}
By identifying $m_A=1$ and $\boldsymbol\Omega^{(12)}\equiv\mathbf K=\mathbf K_1\oplus\mathbf K_2$, $I_2$ is mapped to $I_1$ of the previous section, and the final result is obtained by following the same procedure,
\begin{equation}
I_2(\mathbf K_1,\mathbf K_2)=\frac{2}{\sqrt\pi}\int_0^\infty\mathrm du\sqrt{\frac{\det\mathbf K}{\det(\mathbf K+\mathbf U_2)}}\exp\left[-\mathbf R^\mathrm T\left(\mathbf K-\mathbf K(\mathbf K+\mathbf U_2)^{-1}\mathbf K\right)\mathbf R\right]
\end{equation}
As before, the integrand is finite everywhere and decays exponentially to zero, so the integral can be efficiently evaluated by numerical quadrature.

For the isotropic case, $\mathbf K_A=\mathbf I/\sigma_A^2$, this reduces to~\eqref{eq:mayer},
\begin{equation}
\begin{aligned}
I_1(\sigma_1,\sigma_2)&=\frac2{\sqrt\pi}\int_0^\infty\mathrm du\left(1+u^2(\sigma_1^2+\sigma_2^2)\right)^{-\frac32}\exp\left[-\frac{u^2\lvert\mathbf R_1-\mathbf R_2\rvert^2}{1+u^2(\sigma_1^2+\sigma_2^2)}\right] \\
&=\frac2{\sqrt\pi}\int_0^{1/\sqrt{\sigma_1^2+\sigma_2^2}}\mathrm dv\exp\left(-v^2\lvert\mathbf R_1-\mathbf R_2\rvert^2\right) \\
&=\operatorname{erf}\left(\frac{\lvert\mathbf R_1-\mathbf R_2\rvert}{\sqrt{\sigma_1^2+\sigma_2^2}}\right)\frac1{\lvert\mathbf R_1-\mathbf R_2\rvert}
\end{aligned}
\end{equation}

The corresponding dipole operator is obtained by applying the tensor gradient,
\begin{gather}
\begin{aligned}
  \boldsymbol\nabla_{\mathbf R_1}\otimes\boldsymbol\nabla_{\mathbf R_2}I_2&\equiv
  \boldsymbol\nabla_{\mathbf R_1}\otimes\boldsymbol\nabla_{\mathbf R_2}\int_0^\infty\mathrm du i_2(u)=
  \int_0^\infty\mathrm du\boldsymbol\nabla_{\mathbf R_1}\otimes\boldsymbol\nabla_{\mathbf R_2} i_2(u) \\
  &=\int_0^\infty\mathrm du\big(-2\mathbf K_{12}+4(\mathbf K_{11}\mathbf R_1+\mathbf K_{12}\mathbf R_2)\otimes(\mathbf K_{12}\mathbf R_1+\mathbf K_{22}\mathbf R_2)\big)i_2(u)
\end{aligned} \\
  \begin{bmatrix}\mathbf K_{11}&\mathbf K_{12}\\\mathbf K_{12}&\mathbf K_{22}\end{bmatrix}\equiv\mathbf K-\mathbf K(\mathbf K+\mathbf U_2)^{-1}\mathbf K
\end{gather}

\subsection{Interaction energy decomposition}\label{sec:decom}

The interaction energy of two systems, $S_1$, $S_2$, is calculated with any total-energy method as the difference between the energy of the combined system and the subsystems,
\begin{equation}
  E^\text{(int)}(S_1,S_2)=E(S_1S_2)-E(S_1)-E(S_2)
\end{equation}
By construction, the pairwise vdW methods give a clear interpretation of the interaction energy in terms of pairs of atoms (fragments) in which the atoms are from different subsystems,
\begin{equation}
  E_\text{c,lr}^\text{(int)}(S_1,S_2)\approx-\sum_{\mathclap{A\in S_1,B\in S_2}}C_{6,{AB}}\frac{f(\mathbf R_A,\mathbf R_B)}{|\mathbf R_A-\mathbf R_B|^6}
\end{equation}
In the pairwise picture, the total collective oscillations in the system are decomposed into oscillations between individual pairs of atoms, and because this decomposition is identical in the total system and the individual subsystems, only the inter-system oscillations contribute to the interaction energy.
But in MBD, the total long-range correlation energy has the form of a sum of energies of the individual collective oscillations, which are fully delocalized and different in the total system and the subsystems.
Using the transformation between the uncoupled and coupled coordinates, however, the coupled oscillation energies of the subsystems can be projected into the coupled basis of the system and vice versa, which leads to a decomposition of the MBD interaction energy into the individual collective oscillations of the system.
This provides a clear physical picture of the binding that is utilized in Chapter~\ref{chap:pi-pi}.

The MBD interaction energy between two subsystems is expressed in terms of the coupled oscillation frequencies of the system, $\tilde{\boldsymbol\omega}$, and of the subsystems, $\tilde{\boldsymbol\omega}_1$, $\tilde{\boldsymbol\omega}_1$, and the uncoupled oscillation frequencies in the system, $\boldsymbol\omega$, and in the subsystems, $\boldsymbol\omega_1$, $\boldsymbol\omega_2$,
\begin{equation}
  E_\text{MBD}^\text{(int)}=\sum_{n=1}^{3N}\frac{(\tilde{\boldsymbol\omega})_n}2-\sum_{n'=1}^{3N}\frac{(\tilde{\boldsymbol\omega}_1\oplus\tilde{\boldsymbol\omega}_2)_{n'}}2
	-\sum_{n''=1}^{3N}\frac{({\boldsymbol\omega}-{\boldsymbol\omega}_1\oplus{\boldsymbol\omega_2})_{n''}}2
	\label{eq:mbd-int}
\end{equation}
Here, $n$ runs over the coupled coordinates of the system, $n'$ over coupled coordinates of the subsystems, and $n''$ over the uncoupled coordinates, and we wish to project the frequencies in such a way that the whole expression is a single sum either over $n$ or over $n'$.
In general, the effective noninteracting frequency of a given oscillator in the subsystem and in the total system are not equal in MBD, $\boldsymbol\omega\neq\boldsymbol\omega_1\oplus\boldsymbol\omega_2$, due to the slightly different Hirshfeld partitioning and short-range polarizability screening between the system and the subsystems.

Using the eigenvectors, $\mathbf V_1=(\mathbf v_1\mathbf v_2\ldots)$, $\mathbf V_2$, of the subsystem MBD matrices, $\mathbf Q_1$, $\mathbf Q_2$, and the eigenvectors, $\mathbf V$, of the total-system MBD matrix, $\mathbf Q$, we can construct a projector from the basis of the coupled subsystem coordinates, $\tilde{\boldsymbol\xi}_1\oplus\tilde{\boldsymbol\xi}_2$, to the basis of the coupled system coordinates, $\tilde{\boldsymbol\xi}$,
\begin{equation}
  \mathbf P=\mathbf V^\mathrm T(\mathbf V_1\oplus\mathbf V_2)
\end{equation}
This projector is orthonormal and retains the norm of a vector, but the total MBD energy is a 1-norm of the vector of oscillation energies, $E_\text{MBD}=|\boldsymbol\omega/2|_1$, which is retained by an elementwise (Hadamard) square of the projector,
\begin{equation}
  (\mathbf P^{\circ2})_{ij}=(\mathbf P)_{ij}^2
\end{equation}
Likewise, $(\mathbf V^{\circ2})^\mathrm T$ and $(\mathbf V_1^{\circ2}\oplus\mathbf V_2^{\circ2})^\mathrm T$ are projectors from the uncoupled basis of noninteracting oscillators to the coupled basis of the total system and the subsystems, respectively.
With these projectors at hand,~\eqref{eq:mbd-int} can be expressed as a single sum over the coupled coordinates of the system or the subsystems,
\begin{gather}
	E_\text{MBD}^\text{(int)}=\sum_{n=1}^{3N}\tfrac12\left(\tilde{\boldsymbol\omega}-\mathbf P^{\circ2}(\tilde{\boldsymbol\omega}_1\oplus\tilde{\boldsymbol\omega}_2)-(\mathbf V^{\circ2})^\mathrm T({\boldsymbol\omega}-{\boldsymbol\omega}_1\oplus{\boldsymbol\omega_2})\right)_n \label{eq:decom-1}\\
	E_\text{MBD}^\text{(int)}=\sum_{n'=1}^{3N}\tfrac12\left((\mathbf P^{\circ2})^\mathrm T\tilde{\boldsymbol\omega}-\tilde{\boldsymbol\omega}_1\oplus\tilde{\boldsymbol\omega}_2-(\mathbf V_1^{\circ2}+\mathbf V_2^{\circ2})^\mathrm T({\boldsymbol\omega}-{\boldsymbol\omega}_1\oplus{\boldsymbol\omega_2})\right)_{n'}\label{eq:decom-2}
\end{gather}
The vectors under the summation signs can now be interpreted as different decompositions of the MBD interaction energy into the coupled oscillations.

\section{Nuclear forces and self-consistency}

In this section, we analyze the problem of nuclear forces in a combined KS-DFT+MBD calculation.
Nuclear forces are the (negative of) total derivatives of the energy with respect to the positions of the nuclei, and are the necessary quantity for structure optimization, calculations of vibration spectra, and derived quantities.
As such, they are one of the cornerstones of computational chemistry and computational material physics.

In the following, we assume that the KS calculation is done in a finite one-electron basis, $\{|\mu\rangle\}$, which leads to the description of any particular KS state, $|\Psi\rangle$, in terms of the matrix elements, $P_{\mu\nu}$, of the density-matrix operator, $|\Psi\rangle\langle\Psi|$.
This enables expressing any measurable quantity, such as energy or the electron density, $n$, in terms of the density matrix,
\begin{equation}
\begin{aligned}
	n(\mathbf r)&=\langle\Psi|\hat n(\mathbf r)|\Psi\rangle=\langle\Psi|\sum_\mu|\mu\rangle\langle\mu|\hat n(\mathbf r)\sum_\nu|\nu\rangle\langle\nu|\Psi\rangle \\
	&=\sum_{\mu\nu}\langle\mu|\Psi\rangle\langle\Psi|\nu\rangle\langle\mu|\hat n(\mathbf r)|\nu\rangle
	=\sum_{\mu\nu}P_{\mu\nu}\varphi_\mu(\mathbf r)\varphi_\nu(\mathbf r)
\end{aligned}
\end{equation}

The total KS energy, $E_\text{KS}$, is a system-dependent (via the external potential) functional of the electron density, and hence of the density matrix and the one-electron basis.
In a standard KS calculation, the nuclear coordinates and the one-electron basis are fixed, and the KS ground state is found by minimizing the total energy (via the HK theorem) with respect to the density matrix, so that the partial derivatives are zero, $\partial E_\text{KS}/\partial P_{\mu\nu}=0$.
The total derivative of the KS energy consists of three terms via the chain rule ($\alpha=x,y,z$),
\begin{equation}
\frac{\mathrm dE_\text{KS}(\{R_{A\alpha}\},\{\varphi_\mu\},\mathbf P)}{\mathrm d R_{B\beta}}=\underbrace{\frac{\partial E_\text{KS}}{\partial R_{B\beta}}}_{\mathclap{\text{Feynman forces}}}+\underbrace{\sum_{\mu\nu}\frac{\partial E_\text{KS}}{\partial P_{\mu\nu}}\frac{\partial P_{\mu\nu}}{\partial R_{B\beta}}}_{=0}+\underbrace{\sum_\mu\int\mathrm d\mathbf r\frac{\delta E_\text{KS}}{\delta\varphi_\mu(\mathbf r)}\frac{\partial\varphi_\mu(\mathbf r)}{\partial R_{B\beta}}}_\text{Pulay forces}
\end{equation}
The first term is the explicit derivative, which is equal to the electrostatic force from the electron density on the nucleus $B$ \citep{FeynmanPR39}, the second term is zero because of the energy minimization, and the third term is nonzero only when the one-electron basis depends on the nuclear coordinates.

The MBD energy, $E_\text{MBD}$, is a function of the nuclear coordinates and of the Hirshfeld volumes (eq.~\ref{eq:hirshfeld-vol}), $V_A=\int\mathrm d\mathbf r\,n(\mathbf r)v_A(\mathbf r)$, which in turn are functionals of the electron density, and hence of the density matrix and the one-electron basis.
The total derivative is obtained via chain rules,
\begin{multline}
\frac{\mathrm dE_\text{MBD}(\{R_{A\alpha}\},\{V_A\})}{\mathrm dR_{B\beta}}=\frac{\partial E_\text{MBD}}{\partial R_{B\beta}}+\sum_A\frac{\partial E_\text{MBD}}{\partial V_A}\frac{\mathrm dV_A}{\mathrm dR_{B\beta}} \\
=\frac{\partial E_\text{MBD}}{\partial R_{B\beta}}+\sum_A\frac{\partial E_\text{MBD}}{\partial V_A}\left(\frac{\partial V_A}{\partial R_{B\beta}}+\int\mathrm d\mathbf r\frac{\delta V_A}{\delta n(\mathbf r)}\frac{\mathrm dn(\mathbf r)}{\mathrm dR_{B\beta}}\right) \\
=\frac{\partial E_\text{MBD}}{\partial R_{B\beta}}+\sum_A\frac{\partial E_\text{MBD}}{\partial V_A}\Bigg(\int\mathrm d\mathbf r\frac{\partial v_A(\mathbf r)}{\partial R_{B\beta}}n(\mathbf r)+\int\mathrm d\mathbf r\,v_A(\mathbf r)\Big(\sum_{\mu\nu}\frac{\partial n(\mathbf r)}{\partial P_{\mu\nu}}\frac{\partial P_{\mu\nu}}{\partial R_{B\beta}}+\sum_\mu\frac{\partial n(\mathbf r)}{\partial\varphi_\mu(\mathbf r)}\frac{\partial\varphi_\mu(\mathbf r)}{\partial R_{B\beta}}\Big)\!\Bigg) \\
=\frac{\partial E_\text{MBD}}{\partial R_{B\beta}}+\sum_A\frac{\partial E_\text{MBD}}{\partial V_A}\Bigg(\int\mathrm d\mathbf r\frac{\partial v_A(\mathbf r)}{\partial R_{B\beta}}n(\mathbf r)-2\int\mathrm d\mathbf r\,v_A(\mathbf r)\sum_{\mu\in B,\nu} P_{\mu\nu}\varphi_\nu(\mathbf r)\nabla_\beta\varphi_\mu(\mathbf r)\Bigg) \\
+\sum_{\mu\nu}\underbrace{\Bigg(\sum_A\frac{\partial E_\text{MBD}}{\partial V_A}\int\mathrm d\mathbf r\,v_A(\mathbf r)\varphi_\mu(\mathbf r)\varphi_\nu(\mathbf r)\!\Bigg)}_{\partial E_\text{MBD}/\partial P_{\mu\nu}}\frac{\partial P_{\mu\nu}}{\partial R_{B\beta}}
\end{multline}

Combining the KS and MBD forces together, the final expression consists of seven terms,
\begin{multline}
\frac{\mathrm d(E_\text{KS}+E_\text{MBD})}{\mathrm dR_{B\beta}}=\text{(KS Feynman forces)}+\text{(KS Pulay forces)}
+\underbrace{\frac{\partial E_\text{MBD}}{\partial R_{B\beta}}}_\text{I}\\
+\sum_A\frac{\partial E_\text{MBD}}{\partial V_A}\Bigg(\underbrace{\int\mathrm d\mathbf r\frac{\partial v_A(\mathbf r)}{\partial R_{B\beta}}n(\mathbf r)}_\text{IIa}-\underbrace{2\int\mathrm d\mathbf r\,v_A(\mathbf r)\sum_{\mu\in B,\nu} P_{\mu\nu}\varphi_\nu(\mathbf r)\nabla_\beta\varphi_\mu(\mathbf r)}_{\text{IIb}}\Bigg)\\
+\sum_{\mu\nu}\Bigg(\underbrace{\frac{\partial E_\text{KS}}{\partial P_{\mu\nu}}}_\text{IIIa}+\underbrace{\frac{\partial E_\text{MBD}}{\partial P_{\mu\nu}}}_\text{IIIb}\Bigg)\frac{\partial P_{\mu\nu}}{\partial R_{B\beta}}
\label{eq:mbd-forces}
\end{multline}
Term I is the direct force, computed with the Hirshfeld volumes fixed, and was given independently by \citet{Blood-ForsytheCS16} and \citet{BuckoJPCM16} as analytic expressions.
This is by far the dominant part of the MBD forces.
Calculation of terms IIa and IIb requires $\partial E_\text{MBD}/\partial V_A$, also given by \citet{Blood-ForsytheCS16}.
Term IIa is the force due to the dependence of the Hirshfeld-volume weight on the nuclear coordinates, and can be calculated straightforwardly from derivatives of the radial free-atom densities.
Using a plane-wave basis set, \citet{Blood-ForsytheCS16} found that the contribution of this term to the total forces is non-negligible in a test set of peptides.
Term IIb would be equal to zero in basis sets that do not depend on the nuclear coordinates (such as plane waves), and is the equivalent of the Pulay forces for the KS energy.

Terms IIIa and IIIb arise from the dependence of the density matrix on the nuclear positions.
When the MBD calculation is performed only after the KS-DFT calculation is converged (a posteriori), then IIIa is zero, and IIIb is nonzero.
On the other hand, when the MBD KS potential, $\delta E_\text{MBD}[n]/\delta n(\mathbf r)$, is calculated and included self-consistently in the KS calculation, then the total DFT+MBD energy is minimized with respect to the density matrix, and IIIa and IIIb together are zero.
The effect of self-consistency of the pairwise TS method on the resulting electron densities was investigated by \citet{FerriPRL15}.
The MBD KS potential can be calculated directly from the knowledge of $\partial E_\text{MBD}/\partial V_A$,
\begin{equation}
	v_\text{KS,MBD}(\mathbf r)=\frac{\delta E_\text{MBD}}{\delta n(\mathbf r)}=\sum_A\frac{\partial E_\text{MBD}}{\partial V_A}\frac{\delta V_A}{\delta n(\mathbf r)}=\sum_A\frac{\partial E_\text{MBD}}{\partial V_A}v_A(\mathbf r)
\end{equation}

We have implemented the evaluation of terms IIa, IIb, and of the MBD KS potential in the FHI-aims code \citep{BlumCPC09}, which uses an atom-centered basis set, to test the relative importance of the terms in~\eqref{eq:mbd-forces}.
For testing purposes, we used 10 dimers from the S22 benchmark set of small organic dimers at equilibrium geometries, and the black allotrope of phosphorus as an instance of a layered material with strong inter-layer vdW interactions.
As a benchmark, we used 5-point finite differencing to calculate the true forces.
In all cases, we found that the difference between the forces in a self-consistent and a posteriori MBD calculation, which can serve as an estimate of the magnitude of term IIIb, is below the inherent accuracy of the KS calculation.
The terms IIa and IIb were individually non-negligible, in line with the previous results, but surprisingly, the combined term fell again below the baseline accuracy in all cases.
This explains and solidifies the empirical observation that the derivatives of Hirshfeld volumes are non-negligible in a plane-wave basis, but can be neglected altogether in atom-centered basis sets in most circumstances.


\documentclass[10.5pt]{article}
\usepackage{amsmath,textcomp,amssymb,geometry,graphicx,enumerate}
\usepackage{listings}
\usepackage{color}
\usepackage{svg}
\def\dx{{\rm dx}}
\def\tr{{\rm tr}}
\def\spa{{\rm span}}
\def\T{{\mathbb{T}}}
\def\H{{\mathbb{H}}}
\def\K{{\mathbb{K}}}
\def\L{{\mathbb{L}}}
\def\M{{\mathbb{M}}}
\def\N{{\mathbb{N}}}
\def\P{{\mathbb{P}}}
\def\Q{{\mathbb{Q}}}
\def\R{{\mathbb{R}}}
\def\C{{\mathbb{C}}}
\def\Z{{\mathbb{Z}}}
\newcommand{\interior}[1]{%
  {\kern0pt#1}^{\mathrm{o}}%
}
\newcommand{\closure}{\overline}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{frame=tb,
  language=R,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  tabsize=3
}

\def\Name{Ameet Rahane}  % Your name
\def\Session{Spring 2019}

\title{ASD/MF Project Notes}

\author{Ameet Rahane}

\newenvironment{qparts}{\begin{enumerate}[{(}a{)}]}{\end{enumerate}}
\def\endproofmark{$\Box$}
\def\bigO{\mathcal{O}}
\newenvironment{proof}{\par{\bf Proof}:}{\endproofmark\smallskip}

\textheight=9in
\textwidth=6.5in
\topmargin=-.75in
\oddsidemargin=0.25in
\evensidemargin=0.25in

\begin{document}
\maketitle
\date{}
\section{Problem Set Up}

\subsection{What do we have?}
We start with data from Wholebrain. What this looks like for one mouse is a matrix in $\R^{2, n}$, where $n$ is the number of regions. This matrix consists of two vectors. They respectively stand for ipsilateral and contralateral hemispheres. Each vector contains cell counts for each region that we're looking at. Formally, we have
\begin{equation}
v \in \R^{2,n}
\end{equation}
\subsection{What do we want to find?}
We want to find whether or not this mouse is male or female or if it has autism or not. Generalized, we want to find how the region counts are related to a given experimental condition. Since the outputs of these are yes or no questions, we can have it be an output. Thus, in essence, according to my understanding of this, at least, we want to find:

\begin{equation}
Tv = w, v \in \R^{2,n}, v \in \{0,1\}
\end{equation}
and
\begin{equation}
T: \R^{2,m} \to \{0,1\}
\end{equation}
That is, we're trying to approximate a transformation from the space of relative region counts to a yes or no output. As in, a general binary classification problem. A strong question does still lie in whether we want to approximate this function directly or not, or rather, do we want to exactly build a classifier to do this (no harm in trying right?).

\section{Basic Exploratory Approaches}
There are some approaches that data scientists generally take to look at the space of data given. We can start by simply building a correlation or covariance matrix. This will tell us the correlation between regions and probably, we could use it to find the correlations between hemispheres, as well. \\

Alternatively (or in conjunction), we could take a look at the space of data by principal component analysis or singular value decomposition. Either of these methods manipulate orthogonality and eigenvalue decomposition in order to find where the most variation is. If we choose to do something like this, we could probably use it as a dimensionality reduction technique, as well as just telling us something about the data. We can also use canonical correlaiton analysis, but this is very similar and would serve the same purpose.

\section{More Advanced Approaches and Examples}
We can use methods like LDA, random forests, or other binary classification techniques in order to directly find this classification map. The Cell paper did this as well. \\

\subsection{Kim's (Cell) indirect, but more direct measure of which regions significantly matter}
Let's call a region $Y$. The assumption they made is the following:
\begin{equation}
Y\sim -Binom(\mu)
\end{equation}

$\mu$ here is the mean, but it's related to the experimental condition. Let's call this experimental condition $X$, in reality, this is the question we're trying to answer.
\begin{equation}
\mathbb{E}[Y] = \alpha + \beta X, \alpha, \beta \in \R
\end{equation}
With this, we know that if $\beta$ is statistically significant, then the region being tested is important to the experimental condition. We can use iterative linear least squares squares error to find the values of $\alpha, \beta$ with some confidence interval. They also use the Benjami-Hochberg procedure to reduce error, will need to look this up. Perhaps, if there are multiple regions here, we can find the joint distribution. Also, maybe this distribution becomes normal if it is significant? Not entirely sure about this.

\subsection{Using KNN clustering to approximate this function}

Changing distance function to be what we want.
\section{Questions}
I do still have a number of questions. In fact, I think this exercise has probably increased the number of questions that I have. \\

\begin{itemize}
  \item How much do we care about the relationship between ipsilateral and contralateral?\\

  I know that we generally care about the projections, but do we need to look for the experimental relationship between the hemispheres?
  \item If so, is it important to first find its relationship or its joint distribution?
  \item Are we looking at a certain cell type? If so, what is this?
  \item What kind of labelling are we using?
  \item In the cell paper, why are they using a negative binomial distribution for the conditional distributions? I'm sure there is a reason, but it's not clear.
\end{itemize}

\section{Takeaway and starting point}

Overall, it seems like the Cell paper actually uses a similar technique to the one I suggested, although I found it a bit circular. They did quite a bit of analysis on the data itself, before trying to find a mapping. This is actually very useful, density maps are nice and we should try to do the same. \\

I think a good starting point would be to start with PCA or a similar dimensionality reduction technique. Then, we can run LDA or some other linear classifier. After that, we can measure the effects pseudo-directly by the probabilistic model, they outlined. Although, I do still have a few questions about why they chose the distributions that they did. \\

Beyond that, we should do some region analytics too. That is, density maps and maybe trying to figure out the underlying probablity density distribution of the region data. \\

I'm not entirely sure how to incorporate ipsilateral vs. contralateral in this whole thing. Presumably, if we try to learn a map, we should see which matters more. Beyond that, the direct probabilistic modeling will give us a sense of which contributes more. We should treat ipsi-regions and contra-regions separately in the probabilistic sense, which would then give us the ability to compare how they look (lots of plots).
\end{document}


Nyx interfaces with two post-processing suites, Reeber and Gimlet.

\section{Reeber}

Reeber uses topological methods to construct merge trees of scalar fields.
These trees are effectively parameter-independent and contain a complete
description of the field topology. In the context of Nyx, the field of interest
is the dark matter density. Nyx then queries the merge tree with user-defined
runtime parameters in order to locate the volume-averaged center of dark matter
halos. The same tree can be queried with any number of such parameters to find
halos with different mass/density thresholds.

\section{Gimlet}

Gimlet computes a variety of quantities about the simulation, including optical
depths, Lyman-alpha fluxes, power spectra (both 1-D ``line-of-sight'' as well as
fully 3-D), and probability distribution functions. These suites are fully
MPI-parallel and can be run either ``in situ'' or ``in-transit,'' or with a
combination of both. A detailed description of their usage is provided in the
Nyx User Guide.

\section{Usage}

Nyx can post-process with Gimlet alone, with Reeber alone, or with both
simultaneously. To compile with Gimlet, add \texttt{GIMLET = TRUE} to the
\texttt{GNUmakefile}; to compile with Reeber, add \texttt{REEBER = TRUE}. Note
that these codes are in separate repositories and are not included with Nyx.

Nyx and AMReX provide the capability for the user to execute an arbitrary
post-processing workflow \textit{in situ}. An \textit{in
situ} workflow is one in which all MPI processes evolving the simulation stop
at specified time steps and perform the post-processing before continuing with
the simulation.


\documentclass[11pt,a4paper]{article}

% These are extra packages that you might need for writing the equations:
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{hyperref}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{subcaption}

\lstset {language=C++,
		 basicstyle=\ttfamily,
         keywordstyle=\color{blue}\ttfamily,
         stringstyle=\color{red}\ttfamily,
         commentstyle=\color{purple}\ttfamily,
         morecomment=[l][\color{magenta}]{\#},
       	 basicstyle=\tiny}

% You need the following package in order to include figures in your report:
\usepackage{graphicx}

% With this package you can set the size of the margins manually:
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\begin{document}

% Enter the exercise number, your name and date here:
\noindent\parbox{\linewidth}{
 \parbox{.25\linewidth}{ \large CSP, Exercise 03 }\hfill
 \parbox{.5\linewidth}{\begin{center} \large Beat Hubmann \end{center}}\hfill
 \parbox{.2\linewidth}{\begin{flushright} \large Mar 21, 2019 \end{flushright}}
}
\noindent\rule{\linewidth}{2pt}

\section{Introduction}

The Creutz algorithm~\cite{creutz} was implemented as another example of a Monte Carlo method to simulate
a microcanonical ('NVE') ensemble for the 3D Ising model. We focus our experiment on energy $E$ and calculate
temperature $T$ of the system from it in two different ways.

\section{Algorithm Description}
The implemented Creutz algorithm works as follows:
\begin{itemize}
	\item initialize 3d Ising grid with all spins aligned down.
	\item randomly pick a site: If flipping its spin increases total energy, do so;
	 repeat until system reaches target energy $E$
	\item release demon once system has reached target energy: Demon has energy $E_d=0$ with $E_{max}= 0.05\cdot E$.
	\item demon jumps to random site and calculates $\Delta E$ for a potential spin flip: Iff $E_{max} \geq E_d \geq 0$ keep flip.
	\item recording $E_d$ completes one Monte Carlo step; repeat demon jump until number of steps required
\end{itemize}
The temperature $T$ then is calculated using two different ways for comparison:\\
The probability distribution $P(E_d)$ of the demon energy $E_d$ is plotted in a semilog plot.
The slope of the linear fit to $P(E_d)$ then equals the inverse temperature $\beta$ as in equation~\ref{eqn:1}.\\

\begin{equation}
	P(E_d) \approx e^{-\frac{E_d}{k_BT}}
\label{eqn:1}
\end{equation}

For comparison, the temperature is calculated analytically according to equation~\ref{eqn:2}.
\begin{equation}
	\frac{k_BT}{J} = \frac{4}{\log(1+\frac{4J}{<E_d>})}
\label{eqn:2}
\end{equation}

\section{Results}

The program was implemented as described above and submitted with this report.
For all experiments, the coupling constant $J$ was fixed to the simplest ferromagnetic value of $J=1.0$.
Experiments where run for system side lengths $L \in \{10, 20\}$ and average site energies $E \in \{-2.9, -2.5, -2.0, -1.5, -1.0, -0.5\}$ (figures~\ref{fig:1} and~\ref{fig:2}).

\begin{figure}[b]
	\centering
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth]{E_d_L10_E2900.pdf}
	\end{subfigure}%
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth]{E_d_L10_E2500.pdf}
	\end{subfigure}
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth]{E_d_L10_E2000.pdf}
	\end{subfigure}%
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth]{E_d_L10_E1500.pdf}
	\end{subfigure}
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth]{E_d_L10_E1000.pdf}
	\end{subfigure}%
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=0.9\textwidth]{E_d_L10_E500.pdf}
	\end{subfigure}
	\caption[short]{$P(E_d)$ plots for $L=10$}
	\label{fig:1}
	\end{figure}

	\begin{figure}[b]
		\centering
		\begin{subfigure}{.5\textwidth}
			\centering
			\includegraphics[width=0.9\textwidth]{E_d_L20_E23200.pdf}
		\end{subfigure}%
		\begin{subfigure}{.5\textwidth}
			\centering
			\includegraphics[width=0.9\textwidth]{E_d_L20_E20000.pdf}
		\end{subfigure}
		\begin{subfigure}{.5\textwidth}
			\centering
			\includegraphics[width=0.9\textwidth]{E_d_L20_E16000.pdf}
		\end{subfigure}%
		\begin{subfigure}{.5\textwidth}
			\centering
			\includegraphics[width=0.9\textwidth]{E_d_L20_E12000.pdf}
		\end{subfigure}
		\begin{subfigure}{.5\textwidth}
			\centering
			\includegraphics[width=0.9\textwidth]{E_d_L20_E8000.pdf}
		\end{subfigure}%
		\begin{subfigure}{.5\textwidth}
			\centering
			\includegraphics[width=0.9\textwidth]{E_d_L20_E4000.pdf}
		\end{subfigure}
		\caption[short]{$P(E_d)$ plots for $L=20$}
		\label{fig:2}
		\end{figure}

Calculated temperatures and plotted temperatures then were plotted for all energies (figures~\ref{fig:3} and~\ref{fig:4}).

\begin{figure}
\includegraphics{T_vs_E_L10.pdf}
\caption{$T$ calculated and plotted versus $E$ for $L=10$.}
\label{fig:3}
\end{figure}

\begin{figure}
	\includegraphics{T_vs_E_L20.pdf}
	\caption{$T$ calculated and plotted versus $E$ for $L=20$.}
	\label{fig:4}
	\end{figure}

\section{Discussion}
The results for dimensionless temperature $T$ agree almost perfectly between the two calculation methods.\\
Also, plotting temperatures for several energies in a single plot manages to reproduce the behaviour simulated using the
Metropolis algorithm during a previous exercise (figures~\ref{fig:3} and~\ref{fig:4}).

\pagebreak
\begin{thebibliography}{99}

\bibitem{creutz}
	Creutz, M.\\
	\emph{Microcanonical Monte Carlo Simulation},\\
	Phys. Rev. Lett. American Physical Society. 50 (19): 1411–1414,\\
	1983.

% \bibitem{herrmann}
% 	Herrmann, H. J.,
% 	Singer, H. M.,
% 	Mueller L.,
% 	Buchmann, M.-A.,\\
% 	\emph{Introduction to Computational Physics - Lecture Notes},\\
% 	ETH Zurich,\\
% 	2017.

\bibitem{boettcher}
	Boettcher, L.,\\
	\emph{Computational Statistical Physics - Lecture Notes},\\
	ETH Zurich,\\
	2019.

\end{thebibliography}

\end{document}


\documentclass{article}

\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{placeins}

\usepackage[margin=1in]{geometry}
\usepackage{float}

\def\hwtitle{Computational Physics HW7}
\def\hwauthor{Ethan Rooney}
\def\hwdate{2020-04-01}

\usepackage{fancyhdr}
\lhead{\hwauthor}
\chead{\hwtitle}
\rhead{\hwdate}
\lfoot{\hwauthor}
\cfoot{}
\rfoot{\thepage}
\renewcommand{\footrulewidth}{0.4pt}
\pagestyle{fancy}

\author{\hwauthor}
\title{\hwtitle}
\date{\hwdate}

\begin{document}

\maketitle
\thispagestyle{fancy}

\section{Introduction}

 Bootstrapping is a powerful technique providing us with a way to get an understanding of the underlying distribution in a sample of data.

\section{Results}

\subsection{Question 1}

See below the distribution of \texttt{drand48} and \texttt{gausrand}. These methods produce a reasonably good approximate distributions. There is high agreement between the PDF and the Histogram.

\begin{figure}[!htb]
	\begin{center}
		\includegraphics[width=0.6\textwidth]{p1a.pdf}
	\end{center}
	\caption{The PDF for a random number between 0 and 1 being chosen VS the Distribution of numbers generated by \texttt{drand48}}
\label{fig:qual}
\end{figure}
\FloatBarrier

\begin{figure}[!htb]
	\begin{center}
		\includegraphics[width=0.6\textwidth]{p1b.pdf}
	\end{center}
	\caption{The PDF for a random number between 0 and 1 being chosen VS the Distribution of numbers generated by \texttt{gausrand}}
\label{fig:qual}
\end{figure}
\FloatBarrier

\subsection{Question 2}

When using the \texttt{gausrand} to generate 100,000 products of $x\times y$ with $\overline{x}=1,\sigma_x=2$ and $\overline{y}=4,\sigma_y=1$ we get the Histogram seen below. When compared to the PDF we see that the peak is higher than the naive approach.

\begin{figure}[!htb]
	\begin{center}
		\includegraphics[width=0.6\textwidth]{p2a.pdf}
	\end{center}
	\caption{The histogram of the result of $x\times y$ with $\overline{x}=1,\sigma_x=2$ and $\overline{y}=4,\sigma_y=1$ vs PDF}
\label{fig:qual}
\end{figure}
\FloatBarrier

\subsection{Question 3}

\begin{figure}[!htb]
	\begin{center}
		\includegraphics[width=0.6\textwidth]{p3a.pdf}
	\end{center}
	\caption{Results of 100000 bootstraps of cannonball.dat}
\label{fig:qual}
\end{figure}
\FloatBarrier

When using \texttt{gausrand} to generate 100000 values of $g$ we find  $g = 11 \pm 1.66 \frac{m}{s^2}$ to 1 standard deviation which to the accuracy of this dataset is a correct value of $g$ when compared to the canonical value of  $g=9.8 \frac{m}{s^2}$

\subsection{Question 4}

This question is confusingly worded and requests actions which cannot be performed in Mathematica. I petition it should be turned into a bonus question.

\subsubsection{Task 1}

\begin{center}
	\begin{tabular}{ |c|c|c| }
		\hline
		$t$ &  $y_t$ &  $\sigma_y$\\
		0.0 & 16381.3 & 101.903 \\
		0.5 & 16380.9 & 101.563 \\
		1.0 & 16377.6 & 102.517 \\
		1.5 & 16371.3 & 101.983 \\
		2.0 & 16364.3 & 101.296 \\
		2.5 & 16352.6 & 103.330 \\
		3.0 & 16340.3 & 102.216 \\
		3.5 & 16324.6 & 102.911 \\
		4.0 & 16306.0 & 101.821 \\
		4.5 & 16286.1 & 102.012 \\
		5.0 & 16263.0 & 101.756 \\
		5.5 & 16237.9 & 101.967 \\
		6.0 & 16210.1 & 102.882 \\
		\hline
	\end{tabular}
\end{center}

I did the first part, however \texttt{ErrorListPlot} does not exist as a function in Mathematica.

\subsubsection{Task 2}

Not sure what this section was asking for. So I made a histogram of what the distribution would look like if you generated Gaussian random values of $y_i$ and put it into a $\chi^2$ fitter 100000 times.

\begin{figure}[!htb]
	\begin{center}
		\includegraphics[width=0.6\textwidth]{p4t2a.pdf}
	\end{center}
	\caption{Results of 100000 gausrand of cannonball.dat}
\label{fig:qual}
\end{figure}
\FloatBarrier

We get a mean value of $g=9.83 \frac{m}{s^2}$ with a $\sigma_g = 17.6 \frac{m}{s^2}$

\subsubsection{Task 3}

I am not sure how this is different from Task 2, So instead I am just going to print the bootstrapped output of the $\chi^2$ fitters output for g.

\begin{figure}[!htb]
	\begin{center}
		\includegraphics[width=0.6\textwidth]{p4t3a.pdf}
	\end{center}
	\caption{Results of 100000 bootstraps of bootstrap.dat}
\label{fig:qual}
\end{figure}
\FloatBarrier

Here we get $ g= 9.7 \frac{m}{s^2}$ with a $\sigma_g = 18.1 \frac{m}{s^2}$

The values of g are consistent with each other, but you van see from the histogram bootstrapping provides a more consistent normal distribution.

\section{Conclusion}

The homework was very confusing especially the difference between the tasks\ldots I essentially just started guessing what was being asked of me. I would hope for some clarification to be added for future classes.

\end{document}


\documentclass{article}

\usepackage{arxiv}

\usepackage[utf8]{inputenc} % allow utf-8 input
\usepackage[T1]{fontenc}    % use 8-bit T1 fonts
\usepackage{hyperref}       % hyperlinks
\usepackage{url}            % simple URL typesetting
\usepackage{booktabs}       % professional-quality tables
\usepackage{amsfonts}       % blackboard math symbols
\usepackage{nicefrac}       % compact symbols for 1/2, etc.
\usepackage{microtype}      % microtypography
\usepackage{lipsum}

\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\title{Concrete Dropout: \\Experiments replication and Extensions}

\author{
  Valerii Likhosherstov \\
  Statistical Learning Theory Joint Master Program \\
  Skolkovo Institute of Science and Technology\\
  \texttt{Valerii.Likhosherstov@skoltech.ru} \\
  %% examples of more authors
   \And
 Alfredo de la Fuente \\
 Statistical Learning Theory Joint Master Program\\
 Skolkovo Institute of Science and Technology\\
  \texttt{Alfredo.Delafuente@skoltech.ru} \\
  %% \AND
  %% Coauthor \\
  %% Affiliation \\
  %% Address \\
  %% \texttt{email} \\
  %% \And
  %% Coauthor \\
  %% Affiliation \\
  %% Address \\
  %% \texttt{email} \\
  %% \And
  %% Coauthor \\
  %% Affiliation \\
  %% Address \\
  %% \texttt{email} \\
}

\begin{document}
\maketitle

\begin{abstract}
In this project we reproduce the results of the paper "Concrete Dropout" by Gal et al. (\cite{concrete}). We go further by extending the range of experiments and implementing the Concrete Dropout for Natural Language Processing tasks. Furthermore, we provide an efficient implementation of a fully connected, spatial convolution and LSTM Concrete Dropout layers.
\end{abstract}

% keywords can be removed
\keywords{bayesian deep learning, concrete dropout, model uncertainty}

\section{Background}

Imposing a prior over the weights of a neural network and adopting a fully Bayesian inference in this rich class of estimators provides multiple advantages. First, integrating model parameters out through the MC-estimate of the integral during prediction results in a better performance \cite{bconvnn} compared to using a point MAP estimate of weights, as it happens in vanilla-dropout \cite{dropout}. Second, MC-estimates of predictions' second moments give the information about model's uncertainty on the given example \cite{uncertainty}. Uncertainty gives a tool for human-guided model fitting, when the train set can be augmented with new examples of uncertain objects. One valuable area of application for uncertainty estimates (both epistemic and predictive) is Reinforcement Learning, where grid searching is clearly unfeasible and dropout has to be adapted dynamically, considering that the agent is expected to reduces its uncertainty as the data increases for a good model calibration. In addition, a remarkable feature of dropout's Bayesian interpretation is that with certain priors and variational approximation family, it results in sparse weight matrices \cite{sparse}, enabling more flexible and regularized models. \\

Originally, the Bayesian interpretation was only introduced for Gaussian dropout \cite{welling}, where the re-parametrization trick (or pathwise derivative) allows to obtain unbiased gradient estimates with low variance. Unfortunately, pathwise derivative is not available for discrete random variables - a case of Bernoulli dropout. As an alternative solution, the log-derivative trick and REINFORCE scheme \cite{Williams1992} suffers from high variance in stochastic gradients. For these reasons, a continuous relaxation of discrete random variables was elaborated to solve this problem - using the Gumbel-Softmax distribution \cite{gumbel}, which converges to discrete distribution at high temperatures and is compatible with the reparametrization trick. In \cite{gumbel}, authors exclusively employ Gumbel-Softmax to model discrete hidden states. In \cite{concrete} they use a special case of Gumbel-Softmax with two possible states (Concrete distribution) to approximate Bernoulli dropout during training. Also, a correct choice of prior results in a tractable KL-divergence between prior and variational approximation, which simplifies computations.

\section{Concrete Dropout}
\label{sec:headings}
In order to overcome the computationally intensive task of grid searching over the dropout probability space, specially in scenarios of dealing with complex models with large datasets and under continuous learning settings where the epistemic uncertainty should decrease as more data is collected; the authors suggest to incorporate the dropout rate in the loss function and thus optimize directly it using gradient methods. \\

\subsection{Derivation of the Loss function}
Following the variational interpretation of dropout \cite{Gal2016Uncertainty}, we can see it as an approximating distribution $q_\theta(\omega)$ to the posterior in a Bayesian neural network with a set of random weight matrices $ \omega = \left[ W_l \right]_{l=1}^L$  with $L$ layers and $\theta$ being the set of variational parameters. Then, the optimization objective can be written as follows,

\begin{equation}\label{eq1}
    \hat{\mathcal{L}}_{MC} (\theta) = -\frac{1}{M} \sum_{i\in S} \log p\left( y_i\vert f^{\omega} ( x_i ) \right) + \frac{1}{N} \mathbb{KL} \left( q_\theta(\omega) \Vert p(\omega) \right)
\end{equation}

where $N$ is the number of data points, $S$ a random set of $M$ data points, $f^\omega(x_i)$ the neural network's output on input $x_i$ with parameters $\omega$ and $p(y_i\vert f^\omega (x_i) $ the model's likelihood (e.g. Gaussian with mean $f^\omega (x_i) $). The regularization term ensures that the approximate posterior $q_\theta(\omega)$ does not deviate too far from the prior distribution $p(\omega)$. The prior was chosen to be a discrete quantised Gaussian as described in the paper \cite{Gal2016Uncertainty}. We can assume that the set of variational parameters for t he dropout

\begin{equation}\label{eq2}
    \mathbb{KL}\left( q_\theta(\omega) \Vert p(\omega) \right) = \sum_{l=1}^L \mathbb{KL}\left( q_{M_l} ( W_l \Vert p(W_l) \right) \propto \frac{l^2(1-p)}{2} \|M\|^2 - K \mathcal{H}(p).
\end{equation}

where $K$ is the constant to balance the regularization term with the predictive term. The entropy term $\mathcal{H}(p)$ can be seen as the \textit{dropout regularization term}, which pushes the dropout probability towards $0.5$ which is the highest value it can attain; meanwhile the first term is considered as the \textit{weight regularization term } which limits the norm of the weights used in the concrete dropout layers.

\subsubsection{Concrete Distribution}

One of the main restrictions, as previously mentioned,  relies on the evaluation of the derivative of the objective function with respected to the dropout rate $p$ for the loss optimization step.  The preferred estimator in the literature is  pathwise estimator, however we need to be able to express the random variable as a function of two parameters $\theta$ and $\epsilon$, the latter one being a random variable which does on depend on $\theta$. Unfortunately, the binary random variable does not admit such expression form.

In order to solve the above issue, the paper proposes a continuous relaxation of the binary discrete random variable by using a

\begin{equation}\label{eq3}
    \bar{z} =  \textit{sigmoid} \left( \frac{1}{t} \dot \left( \log \frac{p}{1-p}  + \log \frac{u}{1-u}    \right)  \right)
\end{equation}

where $u\sim \text{Unif}(0,1)$ and $t$ is the temperature variable which makes the distribution closer to the discrete version.

\subsection{Concrete Dropout for LSTM Layer}

We give a simple extension to Concrete dropout for the case of recurrent layer - LSTM. Let's revise the definition of LSTM\footnote{https://pytorch.org/docs/stable/nn.html#torch.nn.LSTM}:
\[
\begin{split}\begin{array}{ll}
i_t = \sigma(W_{ii} x_t + b_{ii} + W_{hi} h_{(t-1)} + b_{hi}) \\
f_t = \sigma(W_{if} x_t + b_{if} + W_{hf} h_{(t-1)} + b_{hf}) \\
g_t = \tanh(W_{ig} x_t + b_{ig} + W_{hg} h_{(t-1)} + b_{hg}) \\
o_t = \sigma(W_{io} x_t + b_{io} + W_{ho} h_{(t-1)} + b_{ho}) \\
c_t = f_t c_{(t-1)} + i_t g_t \\
h_t = o_t \tanh(c_t)
\end{array}\end{split}
\]

When using dropout with LSTM, we usually put it before the layer (at least we did that in experiments). From LSTM's definition it's clear, that this is equivalent to zeroing out columns of $W_{ii}, W_{if} W_{ig}, W_{io}$. So we only induce prior for $W_{ii}, W_{if} W_{ig}, W_{io}$ and consequently, only these matrices should be used in weight regularizer of our ELBO objective. This concludes our derivation of Concrete dropout for LSTM.

\section{Experiments}
\label{sec:experiments}

We analyze and validate the performance of Concrete Dropout in a wide variety of tasks.

\subsection{Regression Task - UCI Datasets}

In this experiment we employ Concrete dropout to solve a regression task for 3 datasets from UCI base\footnote{https://archive.ics.uci.edu/ml/datasets.html}: Boston Housing Dataset, KIN8NM robotic arm dinamics dataset and Wine Quality Dataset.

We utilize a neural network of 3 fully-connected layers, each with 50 hidden units and concrete dropout. This network predicts a mean value of normally distributed output for regression. We also train a single value of log-precision parameter $\log \tau$ of output's distribution, for which we impose a prior distribution $\text{Gamma}(0.1, 0.01)$ (consequently, we add prior's logarithm to our objective function). We use weight and dropout regularizer of $10^{-2}$ and $10^2$ respectively.

In \cite{concrete} they alternate between tuning $\tau$ and variational parameters - a so-called variational (MAP)-EM algorithm. When we replicated this setting, we have found out that dropout probabilities are hardly changing from their initial random values. Hence, we have added third pass through the data to this alternating scheme, where we only tune dropout probabilities.

In our experiments, we try to replicate a pattern of converged dropout probabilities, which is invariant to cross-validation splits. See Figure \ref{fig:uci} for results. We observe a well-distinguished dropout probabilities between first two and the last layer (Wine dataset). For KIN8NM, first two layers converge to low dropout probabilities with small variance, while the last layer exposes a higher variability over cross-validation splits. For Boston, we do not observe any stable pattern.

\subsection{MNIST}
We used the standard classification dataset MNIST \cite{lecun-mnisthandwrittendigit-2010} to assess the accuracy of Concrete dropout and it's relation with the training-set size, by applying it in a Multi-Layer Perceptron (MLP) arquitecture with $3$ hidden layers (with $512$ units) and ReLU activations.

After trained for $100$ epochs, our Concrete dropout achieves MNIST accuracy of $~98\%$  matching that of hand-tuned dropout. Figure \ref{fig:mnist_frac} shows a decreasing converged dropout probabilities as the size of data increases for each one of the MLP layers. Furthermore, we observe in \ref{fig:mnist_convergence} that the convergence in dropout probability in first layers was achieved in significantly less number of epochs compared to the deeper ones. In addition, it validates our intuition that shallower layers in a neural network should have smaller dropout rates.

\subsection{Computer Vision}

FC-DenseNet model \cite{densenet} shows state-of-the-art results in image segmentation task. We try to further improve the model by substituting each dropout layer in it with its concrete version.

In our experiments we use \textit{FC-DenseNet103} topology with 103 convolution layers inside. For it we use a spatial version of Concrete dropout, when the whole channels are "zeroed-out". We opt for weight regularizer of $10^{-8}$ and dropout regularizer of $10^0$. The model is trained for 100 epochs with RMSprop (learning rate - $10^{-4}$). We figured out, that starting from small random dropout probabilities ($0.01-0.05$) results in a better performance of the model.

We compare Concrete dropout with grid-searched dropout rate of $0.2$ (reported in \cite{densenet}). Figure \ref{fig:segcurve} reports average Intersection-over-Union score over 12 segmentation classes on training and validation set. Concrete dropout performed better on a validation set, even though training takes more time for it. If to encounter that dropout baseline required grid search, Concrete dropout appears to be more advantageous. On testing set, concrete dropout reached IoU of $0.414$ and $0.418$ with MC predictions against $0.401$ for dropout.

Figure \ref{fig:calib_ex} (a) shows calibration plots for each segmentation class. Concrete dropout with MC predictions is the closest to a diagonal. Strangely, if don't use MC for predicting, it results in worse-calibrated predictions then dropout in most cases. Figure \ref{fig:calib_ex} (b) illustrates predictions and uncertainties.

\subsection{Reinforcement Learning Task}

As part of the RL setting, we tested Concrete Dropout layers under two conditions: a model-based approached which learns the dynamics of the a cartpole environment and a model-free policy gradient for learning an agent to solve the simple OpenAI 'CartPole-v0' environment. We observe how using concrete dropout improves the learning curve \ref{fig:rl_cd} with respect to a fix dropout rate\ref{fig:rl_fix}. In general, we can show that the dropout rate decreases as more epochs we take to train the model, therefore reducing the epistemic uncertainty of predicting the next state or action for our models. For more implementation details, please refer to the github repository of the project.

\subsection{Natural Language Processing}

In this subsection we go beyond the scope of \cite{concrete} and apply Concrete dropout to solve real-life tasks in Natural Language Processing. We comment the results from a user standpoint, i.e. like if a data scientist was trying to add Concrete dropout feature into his model.

\subsubsection{Grapheme to Phoneme}

We tackle the problem a grapheme-to-phoneme \footnote{https://www.kaggle.com/c/grapheme-to-phoneme}, where we have to predict English word's transcription. We applied the following architecture for our model: an encoder that consists of embedding size 100, then 3 LSTM layers with 100 hidden units and batch-norm and dropout before each. Next, we used average-pooling over encoder outputs, repeated it and put as an input to decoder - two layers of LSTM blocks same as in encoder, followed by linear layer and softmax. We trained our model for 100 epochs with RMSprop (learning rate - $10^{-3}$).

For dropout, we check performance of different probabilities on a validation set. For concrete dropout, we use weight regularizer of $10^{-4}$ and try different values of dropout regularizer. As a metric, we use average Hamming distance between ground truth and predicted word.

Figure \ref{fig:nlpcurves} presents learning curves for dropout and Concrete dropout. We find, that Concrete dropout performs slightly worse than dropout. We also see that Concrete dropout overfits - that happens because dropout probabilities converge to zero (Figure \ref{fig:nlpprobs}). All in all, we didn't manage to glue Concrete dropout with LSTM to obtain good results in this task.

\subsubsection{Sentiment Classification Task - SST dataset }

For this task we used the well-known Stanford Sentiment Treebank dataset  \cite{socher2013}\footnote{https://nlp.stanford.edu/sentiment/treebank.html} in its binary form. This dataset contains movie reviews which are annotated by positive or negative sentiment labels. Our proposed model is composed by one embedding layer of size $100$, one  LSTM layer with $256$ hidden units and followed by a fully connected layer to the binary output.

We run the model with a fixed dropout rate of $0.5$ to compare it against the implemented ConcreteDropout version of the LSTM layer. We used batches of $64$ observations, weight regularizer $10^{-6}$ and dropout regularizer $2\times 10^{-5}$.

The results after training for $20$ epochs with Adam optimizer we obtained are shown at $\ref{fig:sentiment}$. We can observe that our ConcreteDropout LSTM model was able to surpass the baseline model accuracy for the validation set by taking only a few more iterations to converge. This suggests that our model is able to tune dropout rate faster, while not risking predictive accuracy.

\section{Conclusions and Remarks}

 In this research project, we were able to validate and demonstrate how tuning the dropout rate via concrete dropout can provide us an speed up in comparison with grid-searching. One drawback of this model reflects on the need to tune hyperparameters such as weight regularizer and dropout regularizer which can dramatically affect the model predictions. Although the original paper suggests some rule of thumbs, it is still unclear how to tune the values without using a grid-search approach. We should also mention as insight, that the dropout probabilities obtained for different layers follow the general knowledge about using smaller dropout for shallow layers in a neural network. Finally, based on our reproducibility results, we can conclude that the performance of the concrete dropout layer model is comparable with the one of the model with optimal dropout probability fixed, making it much faster than grid-search with exponential number of dropout combinations.

\bibliographystyle{unsrt}

\newpage
\bibliography{references}

\newpage
\section{Appendix}

In this section we display all relevant plots of results referenced in the experimental section.
\begin{figure}[!h]
\centering
\begin{subfigure}{.33\textwidth}
  \centering
  \includegraphics[width=\linewidth]{boston.png}
  \caption{Boston}
\end{subfigure}%
\begin{subfigure}{.33\textwidth}
  \centering
  \includegraphics[width=\linewidth]{kin8nm.png}
  \caption{KIN8NM}
\end{subfigure}%
%\vskip\baselineskip
\begin{subfigure}{.33\textwidth}
  \centering
  \includegraphics[width=\linewidth]{wine.png}
  \caption{Wine}
\end{subfigure}
\caption{UCI experiments. Best viewed on a computer screen.}
\label{fig:uci}
\end{figure}

\begin{figure}[!h]
\centering
\centering
\includegraphics[width=0.5\linewidth]{dropout_convergence_100.png}
\caption{Convergence of Dropout Probabilities per Layer with respect to training epochs.}
\label{fig:mnist_convergence}
\end{figure}

\begin{figure}[!h]
\centering
\centering
\includegraphics[width=0.5\linewidth]{dropout_fractions.png}
\caption{Convergence of Dropout Probabilities per Layer given different fractions of training set.}
\label{fig:mnist_frac}
\end{figure}

\begin{figure}[!h]
\centering
\centering
\includegraphics[width=0.7\linewidth]{time_iou_comparison.png}
\caption{Segmentation: learning curves.}
\label{fig:segcurve}
\end{figure}

\begin{figure}[!h]
\centering
\centering
\includegraphics[width=\linewidth]{dropout_rate_convergence.png}
\caption{Segmentation: dropout rate convergence over layers and several data fits.}
\label{fig:segconv}
\end{figure}

\begin{figure}[!h]
\centering
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=\linewidth]{calibration_plots.png}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=0.7\linewidth]{preview_results.png}
\end{subfigure}
\caption{Calibration plots for 12 classes (a) and example of segmentation and uncertainty (b).}
\label{fig:calib_ex}
\end{figure}

 \begin{figure}[!h]
      \centering
      \includegraphics[scale = 0.28]{model_free_1.png}
      \caption{Learning Curve with Concrete Dropout for CartPole environment.}
      \label{fig:rl_cd}
  \end{figure}
  \begin{figure}[!h]
      \centering
      \includegraphics[scale = 0.35]{model_free_2.png}
      \caption{Learning Curve with Fixed dropout (0.5) for CartPole environment.}
      \label{fig:rl_fix}
  \end{figure}

\begin{figure}[!h]
\centering
\centering
\includegraphics[width=\linewidth]{nlp_probs.png}
\caption{Grapheme-to-Phoneme: dropout rate convergence.}
\label{fig:nlpprobs}
\end{figure}

\begin{figure}[!h]
\centering
\centering
\includegraphics[width=\linewidth]{nlp_curves.png}
\caption{Grapheme-to-Phoneme: learning curves.}
\label{fig:nlpcurves}
\end{figure}

\begin{figure}[!h]
\centering
\begin{subfigure}{.7\textwidth}
  \centering
  \includegraphics[width=\linewidth]{NLP2_Accuracy_2.png}
  \caption{}
\end{subfigure}%

\begin{subfigure}{.7\textwidth}
  \centering
  \includegraphics[width=\linewidth]{NLP2_Accuracy_3.png}
  \caption{}
\end{subfigure}%
\caption{(a) Sentiment Classification learning curve for constant dropout (0.5). (b) Sentiment Classification learning curve for concrete dropout.}
\label{fig:sentiment}
\end{figure}

\end{document}


\documentclass{tufte-handout}

\title{A Note on Run Times and Scaling}

\author{David Dobor}

\date{January 29, 2016} % without \date command, current date is supplied

%\geometry{showframe} % display margins for debugging page layout

\usepackage{graphicx} % allow embedded images
  \setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio}
  \graphicspath{{graphics/}} % set of paths to search for images
\usepackage{amsmath}  % extended mathematics
\usepackage{booktabs} % book-quality tables
\usepackage{units}    % non-stacked fractions and better unit spacing
\usepackage{multicol} % multiple column layout facilities
\usepackage{lipsum}   % filler text
\usepackage{fancyvrb} % extended verbatim environments
  \fvset{fontsize=\normalsize}% default font size for fancy-verbatim environments

% Standardize command font styles and environments
\newcommand{\doccmd}[1]{\texttt{\textbackslash#1}}% command name -- adds backslash automatically
\newcommand{\docopt}[1]{\ensuremath{\langle}\textrm{\textit{#1}}\ensuremath{\rangle}}% optional command argument
\newcommand{\docarg}[1]{\textrm{\textit{#1}}}% (required) command argument
\newcommand{\docenv}[1]{\textsf{#1}}% environment name
\newcommand{\docpkg}[1]{\texttt{#1}}% package name
\newcommand{\doccls}[1]{\texttt{#1}}% document class name
\newcommand{\docclsopt}[1]{\texttt{#1}}% document class option name
\newenvironment{docspec}{\begin{quote}\noindent}{\end{quote}}% command specification environment

\usepackage{listings}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{frame=tb,
  language=matlab,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  tabsize=3
}

\begin{document}

\maketitle% this prints the handout title, author, and date

\begin{abstract}
\noindent We argue why a quadratic run-time of an algorithm is much too slow. The reason for this is that
$O(n^2)$ algorithms do not sclale: as computers get faster and bigger, quadratic time
algorithms actually get slower. We explain here what that means.
\end{abstract}

\section{What's wrong with $O(n^2)$?}

Many of the algrotims we considered so far, like insertion sort or selection sort, had $O(n^2)$
worst case running time. Large problems simply can not be solved by procedures
that are this slow.

\bigskip
A rough standard for now is that people have computers that run billions of operations per second and
have billions of entries in main memory.  For example, I'm typing this on a 2.2 GHz device with 8 GBytes
of main memory.

\begin{marginfigure}
  \includegraphics{processor}
  \caption{A modern processor.}
\end{marginfigure}

\bigskip
This means that you can touch everything in main memory on the order of about a second.

\bigskip
It is kind of an amazing fact that this rough stadard has held for longer than over past half-a-century. The
computers get bigger but they also get faster. To touch everything in memory is going to take a few seconds.
This was true when computers had a few thousand words of memory, and it is true now when they have billions
or more. So let's accept that for a moment as what computers are like.

\bigskip
What that means is that with that huge memory we can address huge problems. So we can have billions of
objects and hope to sort them using bubble-sort, for example.

\bigskip
But there is a problem here. A $O(n^2)$ algoritm taking as input $n = 10^9$  entries will perform about
$(10^9)^2 = 10^{18}$  operations. This, on a computer that processes $10^9$ entries per second, will
take $10^{18} / 10^9 = 10^9$ seconds.  Well, this works out to be over \emph{30 years of computing time.}
Obviously, it is not practical to address such a problem on today's computer.

\newthought{Now consider} a computer that is 10 times as fast on which you can address a problem that is 10 times as big and
which you will probably get to play with in not so distant future.

\begin{marginfigure}
  \includegraphics{graph}
  \caption{A $O(n^2)$ algoritm scales horribly.}
\end{marginfigure}

\bigskip
The same algortimg will take (10 billion)$^{2} = (10^{10})^2 = 10^{20}$ operations on a device with with
$10^{10}$ memory entries, all of which can be accessed in about a second. How long would that take?
$10^{20} / 10^{10} = 10^{10}$ seconds. Well, this works out to be over \emph{300 years of computing time.}

This is exactly the kind of situation you would want to try to avoid by developing algoritms that perform better.

\end{document}

Computer & Information Science Core courses/2166/3-Jan29/WhyNsqrdBad.tex


\chapter{Conclusion}
\label{sec:conclusion}

We have proposed two new models, FLDC and FFLDC, that extend the capabilities of a novel submodular probabilistic model, namely FLID. We have shown how the FLDC model can capture coherence in addition to diversity, and how FFLDC allows generalization through the use of features. Synthetic experiments show the performance of noise constrastive estimation for learning these models from data and the practical considerations that must be addressed such as how to avoid local maxima and the effect of various hyperparameters.

This type of models has been commonly used for document and image summarization, but we show how it can also be applied for recommending touristic locations using information extracted from an online image collection, namely Flickr. A complex probabilistic model such as FLDC captures higher order information resulting in a better approximation of the underlying data distribution.

Existing techniques for landmark identification allowed us to extract information and useful datasets from geo-tagged photos taken in the city of Zürich. Around 160,000 photos were collected representing perspectives of thousands of users, these were then translated into popular locations and user trips from which tourist behavior and routes were learned. For the large dataset, our best model was able to outperform the baselines that only model membership of elements in a set. However the score was lower than for models that include information about the order of the elements, i.e. those that can model sequences.

Devising a model that naturally incorporates information about order of the elements is an interesting direction for future work. However, this could significantly increase the complexity of models which in its current form already make computations intractable due to the combinatorial nature of the set domains.

Spatial features of the photos were mainly used for the identification of landmarks and modeling the user's behavior, however more study is required to identify other features that can be used with the FFLDC model to generalize what can be learned from one city to another. Some experiments were performed in this direction but no conclusive results were obtained.

Despite the limitations, we believe that the proposed models can be applied to a wide range of problems because they can model complex distributions and identify characteristics about the data, such as item similarity.


\documentclass{article}

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

\usepackage{listings} % Required for inserting code snippets
\usepackage{geometry}
\geometry{margin=0.5in}
\usepackage[usenames,dvipsnames]{color} % Required for specifying custom colors and referring to colors by name
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{tikz}
\usepackage{enumerate}
\usepackage{environ}

\NewEnviron{myequation}{%
    \begin{equation}
    \scalebox{1.5}{$\BODY$}
    \end{equation}
}

\definecolor{DarkGreen}{rgb}{0.0,0.4,0.0} % Comment color
\definecolor{highlight}{RGB}{255,251,204} % Code highlight color

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

\begin{document}

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

\section*{Problem 5}
\begin{flushleft}
Let's consider all the numbers that are the sum of a rational and a rational mulitple of $\sqrt{2}$. In other words, let's define
\begin{center}
\begin{equation*}
\mathbb{Q}[\sqrt{2}] = \{ r + s \sqrt{2} : r, s \in \mathbb{Q} \}
\end{equation*}
\end{center}
\end{flushleft}
\begin{flushleft}
In this quesiton you'll prove that this is a field (using the usual notions of addition and multiplication). You may assume that $\mathbb{R}$ is a field (as will be our standard assumption from now on).
\begin{enumerate}[a)]
\item Check that addition and multiplication of elements of $\mathbb{Q}[\sqrt{2}]$ results in other elements of $\mathbb{Q}[\sqrt{2}]$. This tells us that we can do arithmetic with things of this form and always end up with things of this form. \\
\begin{flushleft}
\qquad Let's assume that there exists some elements $p$ and $q \in \mathbb{Q}[\sqrt{2}]$. If we prove that both $p + q \in \mathbb{Q}[\sqrt{2}]$ and $pq \in \mathbb{Q}[\sqrt{2}]$, \\
\qquad then we know $\mathbb{Q}[\sqrt{2}]$ is closed under both addition and multiplication.
\begin{center}
\begin{tabular}{r c c l}
(1) & $(r_p + s_p \sqrt{2}) + (r_q + s_q \sqrt{2})$ & $(r_p + s_p \sqrt{2})(r_q + s_q \sqrt{2})$ & (2)
\end{tabular}
\end{center}
\qquad Let's first take a look at addition, denoted by equation (1): \\
\begin{center}
$(r_p + s_p \sqrt{2} + r_q + s_q \sqrt{2})$ \\
\vspace{0.25cm}
$(r_p + r_q + s_p \sqrt{2} + s_q \sqrt{2})$ \\
\vspace{0.25cm}
$(r_p + r_q) + (s_p \sqrt{2} + s_q \sqrt{2})$ \\
\vspace{0.25cm}
$(r_p + r_q) + ((s_p + s_q)\sqrt{2})$ \\
\end{center}
\qquad Now let's say there exists another element $t \in \mathbb{Q}[\sqrt{2}]$. We can redefine $(r_p + r_q)$ to equal $r_t$ because according to the \\
\qquad rules of addition in $\mathbb{Q}$, when $p \in \mathbb{Q}$ and $q \in \mathbb{Q}$, then $(p + q) \in \mathbb{Q}$. By the same notion, $(s_p + s_q)$ to equal $t_s$. Therefore, \\
\qquad  $\mathbb{Q}[\sqrt{2}]$ is closed under addition.

\vspace{.5cm}

\qquad Next let's look at multiplication, denoted by equation (2): \\
\begin{center}
$(r_p + s_p \sqrt{2})(r_q + s_q \sqrt{2})$ \\
\vspace{0.25cm}
$(r_p)(r_q) + (r_q)(s_p \sqrt{2}) + (r_p)(s_q \sqrt{2}) + 2(s_q)(s_p)$ \\
\vspace{0.25cm}
$(r_p r_q) + ((r_q s_p) \sqrt{2}) + ((r_p s_q) \sqrt{2}) + (2s_q s_p)$ \\
\vspace{0.25cm}
$(r_p r_q) + (((r_q s_p) + (r_p s_q)) \sqrt{2}) + (2s_q s_p)$ \\
\vspace{0.25cm}
$(r_p r_q) + (((r_q s_p) + (r_p s_q)) \sqrt{2}) \sqrt{2})$ \\
\vspace{0.25cm}
$(r_p r_q + 2s_q s_p) + (((r_q s_p) + (r_p s_q)) \sqrt{2})$ \\
\end{center}
\qquad Just as we saw with addition, we can redefine $(r_p r_q + 2s_q s_p)$ and $((r_q s_p) + (r_p s_q))$ which will both still be in $\mathbb{Q}$. \\
\qquad Therefore, $\mathbb{Q}[\sqrt{2}]$ is closed under multiplication. \\
\end{flushleft}

\item Check that negatives and reciprocals of elements of $\mathbb{Q}[\sqrt{2}]$ are in $\mathbb{Q}[\sqrt{2}]$. \\

\begin{flushleft}
\qquad Let's assume that there exists some element $p \in \mathbb{Q}[\sqrt{2}]$. If we prove that both $-p \in \mathbb{Q}[\sqrt{2}]$ and $p^{-1} \in \mathbb{Q}[\sqrt{2}]$, \\
\qquad then we know $\mathbb{Q}[\sqrt{2}]$ is closed to both the negative and inverse of elements in $\mathbb{Q}[\sqrt{2}]$.
\begin{center}
\begin{tabular}{r c c l}
(1) & $-(r_p + s_p \sqrt{2})$ & $(r_p + s_p \sqrt{2})^{-1}$ & (2)
\end{tabular}
\end{center}
\qquad Let's first take a look at negation, denoted by equation (1): \\
\begin{center}
$(-1)(r_p + s_p \sqrt{2})$ \\
\vspace{0.25cm}
$(-1)(r_p) + (-1)(s_p \sqrt{2})$ \\
\vspace{0.25cm}
$(-r_p) + ((-s_p) \sqrt{2})$\\
\end{center}
\qquad Now let's say there exists another element $q \in \mathbb{Q}[\sqrt{2}]$. We can redefine $(-r_p)$ to equal $r_q$. By the same notion, $(-s_p)$ \\
\qquad can be redefined to $q_s$. $r_q + s_q \sqrt{2} \in \mathbb{Q}[\sqrt{2}]$.

\vspace{.5cm}

\qquad Next let's look at reciprocal, denoted by equation (2). Note, $p^{-1} = 1/p$. Additionally, we can multiply by the \\
\qquad opposite reciprocal in order to split the numerator with a common denominator.\\

\begin{center}
$(r_p + s_p \sqrt{2})^{-1}$ \\
\vspace{0.25cm}
$\frac{1}{(r_p + s_p \sqrt{2})}$ \\
\vspace{0.25cm}
$\frac{1}{(r_p + s_p \sqrt{2})} \cdot \frac{r_p-s_p\sqrt{2}}{r_p-s_p\sqrt{2}}$ \\
\vspace{0.25cm}
$\frac{r_p-s_p\sqrt{2}}{r_p^2 - 2s_p^2}$ \\
\vspace{0.25cm}
$\frac{r_p}{r_p^2 - 2s_p^2} - \frac{s_p\sqrt{2}}{r_p^2 - 2s_p^2}$ \\
\vspace{0.25cm}
$\frac{r_p}{r_p^2 - 2s_p^2} + \frac{s_p}{2s_p^2 - r_p^2}\sqrt{2}$ \\
\end{center}
\qquad Like with each of the situations before, we can redefine $\frac{r_p}{r_p^2 - 2s_p^2}$ and $\frac{s_p}{2s_p^2 - r_p^2}$ to be $r_q$ and $s_q$ respectively. Both will \\
\qquad still be in $\mathbb{Q}[\sqrt{2}]$. Therefore, the reciprocal is closed in $\mathbb{Q}[\sqrt{2}]$. \\
\end{flushleft}

\item Explain briefly why axioms, such as A1, whose quantifiers are purely "$\forall$" are automaticlly true for  $\mathbb{Q}[\sqrt{2}]$ since they are true for $\mathbb{R}$. Pick out which axioms this argument works for.

\vspace{.5cm}

\qquad For $\mathbb{Q}[\sqrt{2}]$ to be a field, it must be a set together with two binary operations called \emph{addition} and \emph{multiplication} that \\
\qquad satisfies the 11 axioms as previously defined. The axioms containing "$\forall x$"as defined in $\mathbb{R}$ automatically hold "$\forall$" in \\
\qquad $\mathbb{Q}[\sqrt{2}]$ because any subset of $\mathbb{Q}$ is also a subset of $\mathbb{R}$ since $\mathbb{Q} \subset \mathbb{R}$. However, some of the axioms contain "$\exists x$" in \\
\qquad them, which do not automatically extend to $\mathbb{Q}[\sqrt{2}]$ because although $\mathbb{Q} \subset \mathbb{R}$, $\mathbb{R} \not \subset \mathbb{Q}$. Such axioms are A2, A3, A7, \\
\qquad A8, A11. Therefore, there will be some elements of $\mathbb{R}$ that do not exist in $\mathbb{Q}$. Those axioms must therefore be \\ \qquad proved. Such axioms are A1, A4, A5, A6, A9, and A10.

\item Prove that $\mathbb{Q}[\sqrt{2}]$ is a field, using your results from earlier parts.

\vspace{.5cm}

\qquad As stated in part (c), the axioms that do not automatically hold for $\mathbb{Q}[\sqrt{2}]$ are A1, A4, A5, A6, A9, and A10. In \\
\qquad  part (a), we proved that there was closure under addition and multiplication, satisfying axioms A1 and A6. In part \\
\qquad (b), we proved the existence of both additive and multiplicative inverses, satisfying axioms A5 and A10. The only \\
\qquad ones left to prove are A4 and A9.

\vspace{.5cm}

\qquad To prove A4, we need to show there exists an additive identity such that $\forall a \in \mathbb{F}$, $a+0=a$ In this case, we can \\
\qquad redefine $r + s\sqrt{2}$ as $a$.

\begin{center}
$(r + s \sqrt{2}) + 0 = (r + s \sqrt{2})$\\
$((r + s \sqrt{2}) + (-(r + s \sqrt{2}))) + 0 = (r + s \sqrt{2}) + (-(r + s \sqrt{2})))$
\end{center}

\qquad From here, we can use the A5 (since we proved it in part (b)), which states the existance of an additive inverse such \\
\qquad that $a + (-a)=0$. We redefined $(r + s \sqrt{2})$ as $a$, so we know the above equation simplifies to $0=0$. Thus, Axiom A4\\
\qquad holds.

\vspace{.5cm}

\qquad To prove A9, we need to show there exists an multiplicative identity such that $\forall a \in \mathbb{F}$, with $a \neq 0$, $a\cdot 1=a$. Again, \\
\qquad we can redefine $r + s\sqrt{2}$ as $a$.

\begin{center}
$1 \cdot (r + s \sqrt{2}) = (r + s \sqrt{2})$\\
\end{center}

\qquad From here, we can use the A10 (since we proved it in part (b)), which states the existance of an multiplicative \\
\qquad inverse. We redefined $(r + s \sqrt{2})$ as $a$, so we know the above equation implifies to $1=1$. Thus, Axiom A9 holds.

\vspace{.5cm}

\qquad We have now proved that all 11 axioms hold for $\mathbb{Q}[\sqrt{2}]$ under the binary operations of \emph{addition} and \emph{multiplication}. \\
\qquad Thus, $\mathbb{Q}[\sqrt{2}]$ is a field.
\end{enumerate}
\end{flushleft}

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

\end{document}


% !TEX root = ../main.tex
\newpage
\section*{Abstract}
\addcontentsline{toc}{subsection}{Abstract}
The synchronisation of networks of oscillators, network topology and network plasticity can only be understood from a holistic approach, and each domain is investigated in relation to the other. The Theta neuron model is analysed to understand feedback mechanisms between the frequency and phase response through the electrical current. Different network topologies are then described in terms of their degree distribution. Networks of Theta neurons are studied using the synchronisation of the mean-field. Inspired by the process of synaptic plasticity, learning rules are then established to observe emergent network topologies.