%• Problem definition: What is demanded from the solution? What is the aim of the study?
%Useful simplifications?
In this section we describe what is required of the solution and what this thesis aims at achieving as well as some useful simplifications made for this thesis.

Kotler et. al. \cite{DDSC} train the DDSC algorithm with weeks sampled across two years of data as to generalize the training. This thesis aims at reimplementing the algorithm and investigating the possibility of training with less data but taking the advantage of the temporal correlation between years as to further extend the algorithm by pre-processing the data better, by training the algorithm for the same timeperiod across two years instead of randomly.

\subsection{Solution}
%• Solution/Design: How is it to be done? Will it give the expected performance? What
%limitations can be foreseen from theory?

\begin{enumerate}
	\item{Retrieve similar data}
	\item{Pre-process}
	\item{Implementation}
	\item{Tweak algorithm using temporal difference}
\end{enumerate}

The first problem to address is to retrieve valuable and similar data mostly found via githubs \href{https://github.com/caesar0301/awesome-public-datasets}{Awesome-public-datasets} \cite{awesome}. Once the data has been decided on we pre-process and implement the algorithm, where the algorithm itself could pose a challenge as there is no explicit formulation stated in the paper \cite{DDSC}, nor any source code available. This thesis aims at reproducing the results, by focusing on exploiting the data at hand. The method relies substansually on the data, which could prove to produce very different results. The implementation is limited by the amount of computational power that is available as it run by standard student-laptop. This is reflected on the choice of training set and as well as the choice of number of basis for the algorithms (this is preferably higher in dimension than the dimensionality of the data).


\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[left=2cm,right=2cm,top=3cm,bottom=4cm]{geometry}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{cases}

\author{Ari-Pekka Honkanen}
\title{PyTTE: The Technical Document\\Version 1.0}
\begin{document}
\maketitle
\section{Introduction}
PyTTE (pronounced \emph{pie-tee-tee-ee}) is a Python package for solving X-ray diffraction curves of bent crystals in reflection and transmission geometries. The computation of the diffraction curves is based on the numerical integration of 1D Takagi-Taupin equation (TTE) which is derived from a more general Takagi-Taupin theory describing the propagation of electromagnetic waves in a (quasi)periodic medium. Both energy and angle scans are supported.
This document describes the theoretical basis behind PyTTE.

\section{Takagi-Taupin theory}
\subsection{1D Takagi-Taupin equation}
In the typical two-beam case where the incident wave is written as $\mathbf{D}_0(\mathbf{r}) \exp(i \mathbf{k}_0 \cdot \mathbf{r})$ and the diffracted wave as $\mathbf{D}_h(\mathbf{r}) \exp(i \mathbf{k}_h \cdot \mathbf{r} - i \mathbf{h} \cdot \mathbf{u})$, the Takagi-Taupin equations are can be written as
\begin{subnumcases}{}
\frac{\partial D_0}{\partial s_0} =  i c_0 D_0 + i c_{\bar{h}} D_h \label{eq:TT_typicala} \\
\frac{\partial D_h}{\partial s_h} =  i \left(c_0 + \beta + \frac{\partial (\mathbf{h}\cdot\mathbf{u}) }{\partial s_h}  \right) D_h
+ ic_h D_0, \label{eq:TT_typicalb}
\end{subnumcases}
where $D_0$ and $D_h$ are the pseudoamplitudes of the incident and diffracted waves, and $s_0$ and $s_h$ coordinates along their direction of propagation, respectively. The deformation of the crystal is contained in $\mathbf{h}\cdot\mathbf{u}$ which will be considered in detail later. The coefficients $c_{0,h,\bar{h}}$ are given by
\begin{equation}
c_0 = \frac{k \chi_0}{2} \qquad c_{h,\bar{h}} = \frac{k C \chi_{h,\bar{h}}}{2},
\end{equation}
where $k=2 \pi/\lambda$ and $C = 1$ for $\sigma$-polarization and $\cos 2 \theta_B$ for $\pi$-polarization. The deviation parameter $\beta = (k_h^2 - k_0^2)/2k_h$ is quite often approximated by $\beta \approx k \Delta \theta \sin 2 \theta_B$, where $\Delta \theta$ is the deviation from the Bragg angle. However, since this approximation ceases to be valid near the backscattering condition, PyTTE uses a more general form
\begin{equation}
\beta = \frac{2 \pi}{d_h}\left(\sin \theta - \frac{\lambda}{2 d_h}\right) = h \left(\sin \theta - \frac{\lambda}{2 d_h}\right),
\label{eq:beta}
\end{equation}
where $d_h$ is the interplanar separation of the diffractive planes corresponding to the reciprocal vector $\mathbf{h}$ and $\theta$ is the incidence angle relative to the aforementioned planes. To avoid the possibility of catastrophic cancellation, the subtraction is performed explicitly with 64 bit floating point numbers.

%THIS PARAGRAPH NEEDS A FIGURE
The partial derivatives with respect to $s_0$ and $s_h$ can be written in Cartesian coordinates as
\begin{equation}
\frac{\partial}{\partial s_0} = \cos \alpha_0 \frac{\partial}{\partial x} - \sin \alpha_0 \frac{\partial}{\partial z} \qquad \frac{\partial}{\partial s_h} = \cos \alpha_h \frac{\partial}{\partial x} + \sin \alpha_h \frac{\partial}{\partial z}.
\end{equation}
The incidence and exit angles $\alpha_0$ and $\alpha_h$ with respect to the crystal surface are related to $\theta$ by $\alpha_0 = \theta + \varphi$ and $\alpha_h = \theta - \varphi$, where $\varphi$ is the asymmetry angle (positive clockwise). When seeking a solely depth-dependent solution for $D_0$ and $D_h$, we may drop the $x$-derivatives and thus obtain
\begin{subnumcases}{}
\frac{d D_0}{d z} =  - i \gamma_0 c_0 D_0 - i \gamma_0 c_{\bar{h}} D_h \label{eq:TT_b} \\
\frac{d D_h}{d z} =  i \gamma_h \left(c_0 + \beta + \frac{\partial (\mathbf{h}\cdot\mathbf{u}) }{\partial s_h}  \right) D_h + i \gamma_h c_h D_0,
\end{subnumcases}
where $\gamma_0 = 1/\sin \alpha_0$ and $\gamma_h = 1/\sin \alpha_h$. By defining $\xi = D_h/D_0$, the equations can be written as a single ordinary differential equation
\begin{equation}
\frac{d \xi}{d z} = i \gamma_0 c_{\bar{h}} \xi^2 + i \left[ (\gamma_0+\gamma_h)c_0 + \gamma_h \beta + \gamma_h \frac{\partial (\mathbf{h}\cdot\mathbf{u}) }{\partial s_h} \right] \xi + i \gamma_h c_h
\label{eq:xi}
\end{equation}
When $\xi$ is known, the incident wave can be then solved from Eq.~\eqref{eq:TT_b} as follows
\begin{equation}
\frac{d D_0}{d z} =  - i \left( \gamma_0 c_0  + \gamma_0 c_{\bar{h}} \xi \right) D_0.
\label{eq:D0}
\end{equation}

\subsection{Solving the TT-equation in the reflection and transmission geometries}

In the transmission geometry (Laue case), Eqs.~\eqref{eq:xi} and \eqref{eq:D0} are solved simultaneously by integrating them from the top of the crystal $z=0$ to the bottom $z=-t$. The initial conditions are $\xi(0) = 0$ and $D_0(0)=1$. In the reflection geometry (Bragg case), $\xi$ is solved by integrating from the bottom of the crystal $z = -t$ to the top $z = 0$ with the initial condition $\xi(-t) = 0$. Like in the Laue case, the transmitted beam would have to be integrated from top to bottom, which would require a separate run after $\xi$ is solved and increase the total solving time. Since $D_0$ is rarely needed in the Bragg case, its calculation is not implemented in the version 1.0.

The reflectivity $R$ in the Bragg case is then obtained by $R=|\xi(0)|^2$. However, it should be noted that this definition takes only account the intensities of the beam. From an experimental viewpoint, detectors often record the photon flux which also proportional to the cross-sectional area of the beam. In terms of the photon flux, the reflectivity is $R_\Phi = |\xi(0)|^2 \gamma_0/\gamma_h$. For a symmetric reflection $R=R_\Phi$. (For transmission $T = T_\Phi = |D_0(-t)/D_0(0)|^2$ always.) Similarly in the Laue case the transmission (or forward-diffractivity) $T$ and the diffractivity $R$ in terms of intensities are given by $T = |D_0(-t)/D_0(0)|^2$ and $R = |D_h(-t)/D_0(0)|^2 = |\xi(-t)D_0(-t)/D_0(0)|^2$ and in terms of photon fluxes $T_\Phi = T = |D_0(-t)/D_0(0)|^2$ and $R_\Phi = |\xi(-t)D_0(-t)/D_0(0)|^2  \gamma_0/|\gamma_h|$. The keyword \texttt{output\_type} of \texttt{TTscan} controls whether the solution is given in terms of intensities or photon fluxes.

Eqs.~\eqref{eq:xi} and \eqref{eq:D0} are solved numerically using the variable-coeffient ordinary differential equation solver (VODE) with backward differential formula (BDF) method \cite{Brown_1989} as implemented in \textsc{SciPy}. Analytically calculated Jacobians are provided for the solver.

\subsection{Susceptibilities and structure factors}
In linear media, the susceptibility $\chi$ is related to the dielectric constant $\epsilon$ by $\epsilon = \epsilon_0 (1 + \chi)$ where $\epsilon_0$ is the vacuum permittivity  \cite{del_Coso_2004}. Since $\chi$ is small, the complex refractive index is thus $n = \sqrt{\epsilon} \approx 1 + \chi/2$. The connection between the refractive index and the atomic form factor is \cite{Chantler_1995}
\begin{equation}
n = 1 - \frac{r_0 \lambda^2}{2 \pi} \sum_j n_j f_j
\end{equation}
where $r_0$ is the classical electron radius, $n_j$ and $f_j$ are the number density and the form factor of atomic species $j$, respectively. For crystalline matter, the phase factor and the Debye-Waller factors are included in the sum
\begin{equation}
\chi(\mathbf{q}) =  - \frac{r_0 \lambda^2}{\pi V} \sum_{i} e^{i \mathbf{q} \cdot \mathbf{R}_i}  \sum_j f_j(\mathbf{q})  e^{i \mathbf{q} \cdot \mathbf{r}_j}  e^{-\tfrac{1}{2}q^2 \langle u_j^2 \rangle}
\end{equation}
where $V$ is the volume of the crystal. The first sum goes over all the lattice points $i$, and the second one the atoms in the unit cell. The Fourier coefficients of the series $\chi(\mathbf{r}) = \sum_{\mathbf{h}} \chi_{\mathbf{h}} e^{i\mathbf{h} \cdot \mathbf{r}}$ are thus
\begin{equation}
\chi_\mathbf{h} =  - \frac{r_0 \lambda^2}{\pi v}  F_{\mathbf{h}}
\end{equation}
where $v$ is the volume of the unit cell, and the crystal structure factor is
\begin{equation}
F_{\mathbf{h}} = \sum_j f_j(\mathbf{h})  e^{i \mathbf{h} \cdot \mathbf{r}_j}  e^{-\tfrac{1}{2}h^2 \langle u_j^2 \rangle}.
\end{equation}

\textsc{PyTTE} uses \texttt{Crystal\_F\_H\_StructureFactor} of \textsc{xraylib} to calculate the structure factors $F_h$. In this case the user given Debye-Waller factor is assumed to be $\exp(-\tfrac{1}{2}h^2 \langle u^2 \rangle)$ which is passed to calculation of $F_h$ and $F_{\bar{h}}$; the Debye-Waller factor is always 1 for $F_0$. Although not explicitely stated, \textsc{xraylib} apparently assumes the form of the Fourier expansion to be $\sum_{\mathbf{h}} \chi_{\mathbf{h}} e^{-i\mathbf{h} \cdot \mathbf{r}}$ due to which the structure factors are complex conjugated in \textsc{PyTTE} before calculating $\chi_{\mathbf{h}}$. According to the \textsc{xraylib} source code and the example files (e.g. \texttt{example/xrlexample1.c}) the input parameter \texttt{rel\_angle} is set to 1.

\subsection{Scan vector and refraction correction}
The scan vector, whether in the energy or angle domain, is given to \textsc{PyTTE} relative to the kinematical diffraction condition $\lambda = 2 d_h \sin \theta$, or equivalently $\beta = 0$.
However, it is well-known \cite{Ewald_1986} that due to the refraction of X-rays at the crystal-vacuum interface, the diffraction is not exactly at where the kinematical condition suggests it to be. From Eq.~\eqref{eq:xi} we see, that the true center of the diffraction takes place at $\beta = -(1 + \gamma_0/\gamma_h)\mathrm{Re}[c_0]$. Compared to the kinematical condition, the energy of the centre of the diffraction is changed by
\begin{equation}
\frac{\Delta E}{E} = -\left(1 + \frac{\gamma_0}{\gamma_h} \right)\frac{\mathrm{Re}[\chi_0]}{4 \sin^2 \theta}
\end{equation}
and the angle by
\begin{equation}
\Delta \theta = -\left(1 + \frac{\gamma_0}{\gamma_h} \right)\frac{\mathrm{Re}[\chi_0]}{4 \sin \theta  \cos \theta}.
\end{equation}
The refraction corrections can be applied to the scan vector if needed.

\subsection{Automatic scan limit calculation}
Locally, the diffraction takes place most efficiently in the crystal when
\begin{equation}
\left(1 + \frac{\gamma_0}{\gamma_h}\right) \mathrm{Re} [c_0]  + \beta + \frac{\partial (\mathbf{h}\cdot\mathbf{u}) }{\partial s_h} = 0
\end{equation}
in Eq.~\eqref{eq:xi}, which is effectively Bragg's law corrected for the refraction and influence of deformation. The scan limits can be thus be calculated by finding the maximum and minimum values for the deformation term inside the crystal and calculating the corresponding $\beta$-range. In addition we have to take into account that every reflection has a finite width and extend the scan range accordingly. According to \cite{stepanov_server}, the Darwin width of a perfect thick crystal in the case of symmetric Bragg reflection is
\begin{equation}
\Delta \theta_D = \frac{2 \sqrt{|\chi_h \chi_{\bar{h}}|}}{\sin 2 \theta_B}
\end{equation}
except near $\theta_B = \pi/2$ when
\begin{equation}
\Delta \theta_D = \left(2 \sqrt{|\chi_h \chi_{\bar{h}}|} \right)^{1/2}.
\end{equation}
is more appropriate. For scan limit calculation purposes we combine the two expressions continuously in the following way:
\begin{equation}
\Delta \theta_D (\theta_B)  = \begin{dcases}
\left(2 \sqrt{|\chi_h \chi_{\bar{h}}|} \right)^{1/2} & \mathrm{when} \quad \sin 2\theta_B \leq \left(2 \sqrt{|\chi_h \chi_{\bar{h}}|} \right)^{1/2}\\
\frac{2 \sqrt{|\chi_h \chi_{\bar{h}}|}}{\sin 2 \theta_B} & \mathrm{when} \quad \sin 2\theta_B > \left(2 \sqrt{|\chi_h \chi_{\bar{h}}|} \right)^{1/2}
\end{dcases}
\end{equation}
Substituting this in Eq.~\eqref{eq:beta} and expanding up to the first order, we get
\begin{equation}
|\Delta \beta| = \sigma h \Delta \theta_D (\theta_B) \cos \theta_B,
\end{equation}
where $\sigma = 2$ is a scaling factor which makes the scan range look nicer especially in the absence of a deformation field. Therefore the scan limits are
\begin{align}
\beta_{\mathrm{min}} &= - \frac{k}{2} \left( 1 + \frac{\gamma_0}{\gamma_h} \right) \mathrm{Re}[\chi_0] - \max \left[ \frac{\partial (\mathbf{h}\cdot\mathbf{u}) }{\partial s_h} \right] - \sigma h \Delta \theta_D (\theta_B) \cos \theta_B \\
\beta_{\mathrm{max}} &= -\frac{k}{2} \left( 1 + \frac{\gamma_0}{\gamma_h} \right) \mathrm{Re}[\chi_0] - \min \left[  \frac{\partial (\mathbf{h}\cdot\mathbf{u}) }{\partial s_h} \right] +  \sigma h \Delta \theta_D (\theta_B) \cos \theta_B
\end{align}
It should be noted, that the limits above do not aim to be perfect but act more like as a suggestion. For example, the Darwin width term used may fall short if the crystal is strongly bent or very thin. Also, the first order expansion of $\beta$ is not accurate in the back-scattering.

\section{Deformation}
As stated in the previous section, the deformation is introduced through $\partial_h(\mathbf{h}\cdot \mathbf{u})$ term where $\mathbf{u}$ is the displacement vector field. Taking the asymmetry into account, the reciprocal vector is given by $\mathbf{h} = h \sin \varphi \hat{\mathbf{x}} + h \cos \varphi \hat{\mathbf{z}}$. Thus
\begin{equation}
\frac{\partial (\mathbf{h}\cdot \mathbf{u})}{\partial s_h} = h \sin \varphi \frac{\partial u_x}{\partial s_h} + h \cos \varphi \frac{\partial u_z}{\partial s_h}.
\end{equation}
Again we write the partial derivatives in terms of $x$ and $z$. In this case, however, neither $x$- or $z$-derivatives can be dropped as they both contain physical information about the rotation and the separation of the diffractive planes. Since the beam propagates also in the $x$-direction, the situation is not strictly speaking one dimensional. However, since the $x$-coordinate is geometrically related to $z$, the problem can be treated as such. Therefore the deformation term becomes
\begin{equation}
\frac{\partial (\mathbf{h}\cdot \mathbf{u})}{\partial s_h} = h \left(
\sin \varphi \cos \alpha_h \frac{\partial u_x}{\partial x}
+\sin \varphi \sin \alpha_h \frac{\partial u_x}{\partial z}
+\cos \varphi \cos \alpha_h \frac{\partial u_z}{\partial x}
+\cos \varphi \sin \alpha_h \frac{\partial u_z}{\partial z}
 \right),
\end{equation}
where the derivatives, that are functions of $x$ and $z$, are made only $z$-dependent with $x(z)=-z \cot \alpha_0$. PyTTE computes the strain term from the Jacobian of $\mathbf{u}$.

\subsection{Anisotropic plate, bending due to applied torques}
According to \cite{Chukhovskii_1994}, the components of the displacement field for an anisotropic plate bent by two (scaled) torques $m_1$ and $m_2$ acting about $y$- and $x$-axes, respectively, are
\begin{align}
u_x &= (S_{11} m_1 + S_{12} m_2) x z + (S_{51} m_1 + S_{52} m_2)\frac{z^2}{2} + (S_{61} m_1 +S_{62} m_2) \frac{y z}{2} \\
u_y &= (S_{21} m_1 + S_{22} m_2) y z + (S_{41} m_1 + S_{42} m_2)\frac{z^2}{2} + (S_{61} m_1 +S_{62} m_2) \frac{x z}{2} \\
u_z &= -(S_{11} m_1 + S_{12} m_2)\frac{x^2}{2} -(S_{21} m_1 + S_{22} m_2)\frac{y^2}{2} -(S_{61} m_1 +S_{62} m_2) \frac{x y}{2} +(S_{31} m_1 + S_{32} m_2)\frac{z^2}{2},
\end{align}
where $S_{ij}$ are the components of the compliance matrix. Thus we find the partial derivatives:
\begin{align}
\frac{\partial u_x}{\partial x} &= (S_{11} m_1 + S_{12} m_2) z \\
\frac{\partial u_x}{\partial z} &= (S_{11} m_1 + S_{12} m_2) x + (S_{51} m_1 + S_{52} m_2) z
+ (S_{61} m_1 + S_{62} m_2) \frac{y}{2}\\
\frac{\partial u_z}{\partial x} &= -(S_{11} m_1 + S_{12} m_2) x -(S_{61} m_1 + S_{62} m_2) \frac{y}{2} \\
\frac{\partial u_z}{\partial z} &= (S_{31} m_1 + S_{32} m_2) z
\end{align}
The torques are related to the bending radii $R_i$ by\footnote{In this work the signs of $R_i$ is the opposite to that of \cite{Chukhovskii_1994}}
\begin{equation}
\frac{1}{R_1} = -S_{11} m_1 - S_{12} m_2, \qquad
\frac{1}{R_2} = -S_{21} m_1 - S_{22} m_2.
\end{equation}
Thus
\begin{equation}
m_1 = \frac{1}{S_{11}S_{22}-S_{12}S_{21}}\left(\frac{S_{12}}{R_2}-\frac{S_{22}}{R_1} \right), \qquad
m_2 = \frac{1}{S_{11}S_{22}-S_{12}S_{21}}\left(\frac{S_{21}}{R_1}-\frac{S_{11}}{R_2} \right).
\label{eq:ms}
\end{equation}
However, it should be noted $R_1$ and $R_2$ due to $m_1$ and $m_2$ may not be the main axes of curvature of now toroidally bent crystal, as the non-diagonal components $S_{61}$ and $S_{62}$ may cause the rotation with respect to the torques. Therefore the equations presented here apply to the case where the crystal wafer is allowed to adopt the shape freely as an reaction to the orthogonal torques \emph{e.g.} when a thin slab is bent by its edges.

This deformation is implemented as \texttt{deformation.anisotropic\_plate\_fixed\_torques}. As an input, the user gives the bending radii $R_{1,2}$ from which the torques are calculated using Eq.~$\eqref{eq:ms}$. User may also give only the other of the $R_i$:s, when it is assumed that the torque acting in the orthogonal direction is zero, in which case the crystal adopts the corresponding $R_j, j \neq i$ via the anticlastic bending.

\subsection{Anisotropic plate, fixed toroidal shape}
When the shape of the bending is fixed \emph{e.g.} by bonding the crystal on a substrate, more complicated procedure than described before is needed. In the case of toroidal bending with the meridional bending radius $R_1$ (in the $x$-direction) and the sagittal radius $R_2$ (in the $y$-direction) are set the main axes of curvature, the relevant partial derivatives of $\mathbf{u}$, are \cite{Honkanen_2020}
\begin{align}
\frac{\partial u_x}{\partial x} &= - \frac{z}{R_1} \qquad
\frac{\partial u_z}{\partial x} = \frac{x}{R_1} \qquad
\frac{\partial u_z}{\partial z} = \left(S_{31}' \mu_x + S_{32}' \mu_y \right) z \nonumber \\
\frac{\partial u_x}{\partial z} &= -\frac{x}{R_1} + \left[
\left(S_{51}' \mu_x + S_{52}' \mu_y \right) \cos \alpha
- \left(S_{41}' \mu_x + S_{42}' \mu_y \right) \sin \alpha
\right]
\end{align}
where
\begin{align}
\mu_x = \frac{(S_{12}' - S_{22}')(R_1 + R_2) + (S_{12}' + S_{22}')(R_1 - R_2)\cos 2 \alpha}{2(S_{11}'S_{22}'  - S_{12}'S_{12}')R_1 R_2}\\
\mu_y = \frac{(S_{12}' - S_{11}')(R_1 + R_2) - (S_{12}' + S_{11}')(R_1 - R_2)\cos 2 \alpha}{2(S_{11}'S_{22}'  - S_{12}'S_{12}')R_1 R_2}.
\end{align}
$S_{ij}'$ are related to the input compliance matrix $S_{ij}$ by a rotation $\alpha$ in the $xy$-plane given by
\begin{equation}
\alpha = \frac{1}{2} \arctan \left[ \frac{D_\alpha(R_1 + R_2) - B_\alpha (R_1 - R_2)}{ A_\alpha (R_1 - R_2) - C_\alpha (R_1 + R_2) } \right]
\end{equation}
where
\begin{align}
A_\alpha &= S_{66} (S_{11} + S_{22} + 2 S_{12}) - (S_{61} + S_{62})^2 \\
B_\alpha &=  2\left[S_{62} (S_{12} + S_{11}) - S_{61} (S_{12} + S_{22}) \right]   \\
C_\alpha &= S_{66} (S_{22} - S_{11}) + S_{61}^2 - S_{62}^2  \\
D_\alpha &= 2\left[S_{62} (S_{12} - S_{11}) + S_{61} (S_{12} - S_{22}) \right].
\end{align}
\emph{unless} $S_{61} = S_{62} = 0$, $S_{11} = S_{22}$, and $S_{11} + S_{22} - 2 S_{12} - S_{66} = 0$ when $\alpha = 0$.

The rotation is performed to the compliance tensor by
\begin{equation}
s'_{ijkl} = \sum_{p,q,r,s} Q_{ip}Q_{jq}Q_{kr}Q_{ls} s_{pqrs}
\end{equation}
where $Q$ is
\begin{equation}
Q = \left[\begin{matrix}
\cos \alpha & -\sin \alpha & 0 \\
\sin \alpha & \cos \alpha & 0 \\
0 & 0 & 1
\end{matrix}\right].
\end{equation}
The Voigt notation\footnote{From \cite{Honkanen_2020}: "In the Voigt notation, a pair of indices $ij$ is replaced with a single index $m$ as follows: $11 \rightarrow 1$; $22 \rightarrow 2$; $33 \rightarrow 3$; $23,32 \rightarrow 4$; $13, 31 \rightarrow 5$ and $12, 21 \rightarrow 6$. The compliance matrix $S$ in the Voigt notation is given in terms of the compliance tensor $s$ so that $S_{mn} = (2 - \delta_{ij})(2 - \delta_{kl})s_{ijkl}$, where $ij$ and $kl$ are any pairs of indices corresponding to $m$ and $n$, respectively, and $\delta$ is the Kronecker delta."} is used to connect the compliance tensors and matrices.

The fixed shape bending is implemented as \texttt{deformation.anisotropic\_plate\_fixed\_shape}.

\subsection{Isotropic plate}
The general anisotropic equations for fixed torques and fixed shape simplify to the same solution when the plate is assumed to be isotropic. The isotropic compliance matrix is given by
\begin{equation}
S = \frac{1}{E}\left[\begin{matrix}
1 & -\nu & -\nu & 0 & 0 & 0 \\
-\nu & 1 & -\nu & 0 & 0 & 0 \\
-\nu & -\nu & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 2(1+\nu) & 0 & 0 \\
0 & 0 & 0 & 0 &2(1+\nu)  & 0 \\
0 & 0 & 0 & 0 & 0 & 2(1+\nu) \\
\end{matrix}\right],
\end{equation}
where $E$ is Young's modulus and $\nu$ is the Poisson ratio.
Plugging these into \eqref{eq:ms}, we obtain
\begin{equation}
m_x = -\frac{E}{1-\nu^2}\left(\frac{1}{R_x}+\frac{\nu}{R_y} \right), \qquad
m_y = -\frac{E}{1-\nu^2}\left(\frac{1}{R_y}+\frac{\nu}{R_x} \right)
\end{equation}
and thus
\begin{equation}
\frac{\partial u_x}{\partial x} = -\frac{z}{R_x}, \qquad
\frac{\partial u_x}{\partial z} = -\frac{x}{R_x}, \qquad
\frac{\partial u_z}{\partial x} = \frac{x}{R_x}, \qquad
\frac{\partial u_z}{\partial z} = \frac{\nu}{1-\nu}\left(\frac{1}{R_x}+\frac{1}{R_y}\right)z.
\end{equation}
Finally, since PyTTE assumes the top surface is at $z=0$, we need to shift the $z$-axis $z \rightarrow z + t/2 $
\section{Crystallography and elastic constants}
\subsection{Crystallographic vectors}
For crystallographic data, \textsc{pyTTE} relies on the internal library of \textsc{xraylib}\cite{Schoonjans_2011}. The direct primitive vectors $\mathbf{a}_1$, $\mathbf{a}_2$, and $\mathbf{a}_3$ given in a Cartesian system are calculated from the lattice parameters $a$,$b$,$c$, $\alpha$, $\beta$, and $\gamma$ as follows
\begin{equation}
\mathbf{a}_1 = a \left[\begin{matrix} 1 \\ 0 \\ 0 \end{matrix}\right] \qquad
\mathbf{a}_2 = b \left[\begin{matrix} \cos \gamma \\ \sin \gamma \\ 0 \end{matrix}\right] \qquad
\mathbf{a}_3 = \frac{c}{\sin \gamma} \left[\begin{matrix} \cos \beta \sin \gamma \\ \cos \alpha - \cos\beta \cos\gamma \\
\sqrt{\sin^2 \gamma - \cos^2 \alpha - \cos^2 \beta + 2 \cos \alpha \cos \beta \cos \gamma} \end{matrix}\right]
\end{equation}
The reciprocal primitive vectors are calculated according to
\begin{equation}
\mathbf{b}_1 = 2\pi \frac{\mathbf{a}_2 \times \mathbf{a}_3}{|\mathbf{a}_1 \times \mathbf{a}_2 \cdot \mathbf{a}_3|} \qquad
\mathbf{b}_2 = 2\pi \frac{\mathbf{a}_3 \times \mathbf{a}_1}{|\mathbf{a}_1 \times \mathbf{a}_2 \cdot \mathbf{a}_3|} \qquad
\mathbf{b}_3 = 2\pi \frac{\mathbf{a}_1 \times \mathbf{a}_2}{|\mathbf{a}_1 \times \mathbf{a}_2 \cdot \mathbf{a}_3|}.
\end{equation}
The reciprocal vector $\mathbf{h}$ corresponding and normal to the Bragg planes with the Miller indices $(h,k,l)$ is thus
\begin{equation}
\mathbf{h} = h \mathbf{b}_1 + k \mathbf{b}_2 + l \mathbf{b}_3.
\end{equation}
Crystal directions $[n_1 n_2 n_3]$ are converted to Cartesian vectors $(x,y,z)$ followingly
\begin{equation}
\left[\begin{matrix} x \\ y \\ z \end{matrix}\right] = \left[\begin{matrix} \mathbf{a}_1 & \mathbf{a}_2 & \mathbf{a}_3  \end{matrix}\right] \left[\begin{matrix} n_1 \\ n_2 \\ n_3 \end{matrix}\right]
\end{equation}
and \emph{vice versa} by inverting $[\mathbf{a}_1 \ \mathbf{a}_2 \ \mathbf{a}_3]$.

\subsection{Vector and tensor rotation}
A general counterclockwise rotation by $\theta$ about axis $\mathbf{u} = (u_1, u_2, u_3)$, with $|\mathbf{u}| = 1$, is given by the matrix
\begin{equation}
Q(\mathbf{u},\theta) = \left[\begin{matrix}
\cos \theta + u_1^2 (1 - \cos \theta) & u_1 u_2 (1 -\cos \theta) - u_3 \sin \theta &  u_1 u_3 (1 -\cos \theta) + u_2 \sin \theta \\
u_2 u_1 (1 -\cos \theta) + u_3 \sin \theta & \cos \theta + u_2^2 (1 - \cos \theta) & u_2 u_3 (1 -\cos \theta) - u_1 \sin \theta \\
u_3 u_1 (1 -\cos \theta) - u_2 \sin \theta &  u_3 u_2 (1 -\cos \theta) + u_1 \sin \theta & \cos \theta + u_3^2 (1 - \cos \theta)
\end{matrix} \right],
\end{equation}
also known as Rodrigues' rotation formula. Rotation is applied to vector $\mathbf{v}$ by the ordinary matrix multiplication $Q\mathbf{v}$. For a 4th order tensor $t$, the rotated components are
\begin{equation}
t'_{ijkl} = \sum_{p,q,r,s} Q_{ip}Q_{jq}Q_{kr}Q_{ls} t_{pqrs}.
\end{equation}

In \textsc{pyTTE}, it is taken that $\mathbf{h} \parallel \hat{\mathbf{z}}$, \emph{i.e.} the symmetric Bragg case, corresponds to the asymmetry angle $\phi=0$. Thus in the most general case the elastic tensors go through the following three rotations:
\begin{enumerate}
\item Rotate elastic tensors and direction vectors so that $\mathbf{h}$ is parallel to $z$-axis
\item Apply a rotation about $z$-axis to align the crystal directions in $xy$-plane
\item Apply the asymmetry by performing the rotation of $\phi$ about $y$-axis.
\end{enumerate}
Assuming that at least either of $h$ an $k$ is non-zero, the rotation of $\mathbf{h}= (h_1,h_2,h_3)$ (step 1) is performed with the following axis and angle
\begin{equation}
\mathbf{u} = \frac{1}{\sqrt{h_1^2 + h_2^2}} \left[\begin{matrix} h_2 \\ -h_1 \\ 0 \end{matrix}\right] \qquad
\theta = \arccos \left( \frac{h_3}{\sqrt{h_1^2 + h_2^2 + h_3^2}} \right).
\end{equation}
If $h=k=0$, a rotation of $\theta = \pi$ about $\mathbf{u} = -\hat{\mathbf{y}}$ is applied when $l<0$; no rotation is needed for $l>0$. For the in-plane rotation (step 2), the axis is $\mathbf{u} = [0,0,1]^{\mathrm{T}}$ and for the asymmetry rotation (step 3) $\mathbf{u} = [0,1,0]^{\mathrm{T}}$ and $\theta = \phi$.\footnote{Note that $\phi$ is defined clockwise-positive but about $-\hat{\mathbf{y}}$, not $\hat{\mathbf{y}}$}

The crystal directions $[n_1' n_2' n_3']$ after a rotation $Q$ are calculated as follows
\begin{equation}
 \left[\begin{matrix} n_1' \\ n_2' \\ n_3' \end{matrix}\right] =
 (Q \left[\begin{matrix} \mathbf{a}_1 & \mathbf{a}_2 & \mathbf{a}_3 \end{matrix} \right])^{-1} \mathbf{r}
\end{equation}
where $\mathbf{r}$ is an arbitrary direction in terms of Cartesian coordinates. (Although not clear from the notation, $Q \left[\begin{matrix} \mathbf{a}_1 & \mathbf{a}_2 & \mathbf{a}_3 \end{matrix} \right]$ and it's inverse are square matrices.)

\subsection{Elastic constants}
PyTTE v 1.0 has built-in elastic tensors for a handful of most commonly encountered crystals taken from CRC Handbook of Chemistry and Physics, 82nd edition.

\bibliographystyle{unsrt}
\bibliography{documentation}
\end{document}


% This file is part of the AbundanceSelfCal project
% Copyright 2019, 2020 the authors.

\documentclass[12pt, letterpaper]{article}

%% text macros
\newcommand{\project}[1]{\textsl{#1}}
\newcommand{\acronym}[1]{{\small{#1}}}
\newcommand{\apogee}{\project{\acronym{APOGEE}}}
\newcommand{\sdssiv}{\project{\acronym{SDSS-IV}}}
\newcommand{\dr}{\acronym{DR17}}

%% math macros
\newcommand{\teff}{{T_{\mathrm{eff}}}}
\newcommand{\logg}{\log g}

\begin{document}\sloppy\sloppypar\raggedbottom\frenchspacing

\section*{\raggedright
  A data-driven causal model to recalibrate element-abundance measurements,
  and to infer original birth abundances}
\noindent
ACE, DWH, MKN, HWR, and others

\paragraph{Abstract:}
There are multiple large-scale spectroscopic surveys of stars in the
Milky Way, currently comprising a global total of millions of stars with
detailed element-abundance information.
Many millions more are expected in the coming decade.
Element-abundance measurements are of great scientific importance because
surface abundances are expected to be (almost) invariant over a stellar
lifetime and thus provide information about the relationships between
the detailed history of star formation and the current configuration of the Galaxy.
This scientific program is fraught, however:
The element-abundance inferences are strongly model-dependent, being
affected by the treatment of computationally challenging physics, such
as non-eqilibrium and stochastic time-dependent effects.
And the surface abundances can truly change over cosmic time, because
of dredge-up, accretion, or other stellar-evolution effects.
That is, for both model mis-specification and stellar-evolution
reasons, the empirical element abundances in stellar parameter
catalogs show strong variations with stellar evolutionary phase, even
conditioning on position and velocity in the Galaxy.
Here we present a self-calibration of the stellar element abundances for
luminous red-giant stars in the \sdssiv--\apogee\ \dr\ Catalog [correct?].
This self-calibration is based on a particular hierarchical model
structure, or particular set of assumptions about the possible
existence (and enforced non-existence) of causal relationships between
birth abundances and properties of the stars, including position,
velocity, surface gravity, and observing details (such as which instrument
or spectroscopic fiber was employed).
Up to some overall degeneracies, the model produces a re-calibrated
set of element abundances for each star, which constitute an inference
of what the element abundances \emph{would have been at the time of
  the star's birth}.
[Statements about performance and validation.]

\section{Introduction}

We don't know how consistent our abundance measurements are as we scan
around the Milky Way...

And now there aren't just abundance measurements.
There are ages and...
All of these are uncertain, and have complex calibration issues...

The best current tests make use of globular and open clusters.
We ourselves are guilty of using such tests...

Importantly, abundances are only expected or permitted to depend on certain
things.
That is, one can take a \emph{causal} approach to this problem...

We can't distinguish between systematic errors and incorrectness of
our assumptions. But we don't need to!

Relatedly, the best calibration systems currently operating on astronomical
data are self-calibrations.
These systems make use of causal structure (and large data sets) to
separate real from spurious trends in, say, photometry of stars or
temperatures of cosmic background pixels.
The general idea is of very wide applicability...

\section{Method}

Imagine that we have a catalog of $N$ stars.
Each star $n$ has abundance measurements $y_n$.
That is, for each star $n$, we have assembled a set of abundance ratio
measurements into a data vector (or blob) $y_n$.
We believe that the true abundance ratios $z_n$ of the star are
closely related to, but not identical to, the measured abundance
ratios $y_n$.
We are going to use things we know about the causal relationships
between the abundances and other data to infer the true abundances
$z_n$ from the observed abundances $y_n$.

For each star $n$ we have, in addition to the abundance measurements
$y_n$ two other pieces of information.
The first is the position $X_n$ of the star in phase space; that is,
the position and velocity of the star in the Galaxy.
The second is meta-data about the star.
This can be thought of as a vector or blob $x_n$ of things we know
about the star like its apparent magnitude $J_n$, temperature
$\teff_n$, and surface gravity $\logg_n$.
The meta-data $x_n$ also includes things about how the star was
observed, like which spectrograph was used to observe it, which fiber
within that spectrograph, what time of year, the airmass of the
observation, and so on.

The causal argument here is that the true abundances $z_n$ of the star
will depend only on the phase-space position of the star $X_n$, but not at
all on the meta-data $x_n$.
That is...
...

In what sense are these assumptions wrong...?

\paragraph{Acknowledgements:}
Thanks to Jo Bovy (Toronto) for valuable input.

\end{document}


\chapter{Axiom schema of specification}


\section{Nomenclature}

\begin{table}[htb!]
\centering
\begin{tabular}{|c|l|}
\hline
$x_i$ & Position of the center of mass of the differential element in the\\
& current configuration\\
\hline
$X_I$ & Position of the center of mass of the differential element in the\\
& reference configuration\\
\hline
$\xi_I$ & Position of the center of mass of the micro element in the\\
& current configuration w.r.t. the center of mass of the differential element\\
\hline
$\Xi_I$ & Position of the center of mass of the micro element in the\\
& reference configuration w.r.t. the center of mass of the differential element\\
\hline
$\sigma_{ij}$ & Unsymmetric Cauchy stress\\
\hline
$s_{ij}$ & Symmetric micro stress\\
\hline
$m_{ijk}$ & Higher order couple stress\\
\hline
$f_{i}$ & Body force density\\
\hline
$a_{i}$ & Acceleration\\
\hline
$l_{ij}$ & Body force couple\\
\hline
$\omega_{ij}$ & Micro-spin inertia\\
\hline
$\tilde{\mathcal{B}}^h$ & The free micromorphic finite element overlap with ghost DNS domain\\
\hline
$\overline{\mathcal{B}}^h$ & The pure micromorphic domain\\
\hline
$\hat{\mathcal{B}}^h$ & The ghost micromorphic finite element overlap with free DNS domain\\
\hline
$\overline{\mathcal{B}}^{DNS}$ & The pure DNS domain\\
\hline
\GDNSDOF & The generalized DNS DOF vector\\
\hline
\GMMCDOF & The generalized micromorphic DOF vector\\
\hline
$\left\{\hat{Q}\right\}$ & The DNS DOF prescribed by micromorphic fields $\left(\alpha \in \hat{\mathcal{A}} \in \tilde{\mathcal{B}}^h\right)$\\
\hline
$\left\{\hat{D}\right\}$ & The nodes of the micromorphic continuum overlapping the DNS $\left(a \in \hat{\mathcal{N}}\ f \in \hat{\mathcal{M}}\quad \hat{\mathcal{N}},\hat{\mathcal{M}} \in \tilde{\mathcal{B}}^h \cup \hat{\mathcal{B}}^h\right)$\\
\hline
$\left\{D\right\}$ & The free DNS nodes $\left(m \in \mathcal{N}\ n \in \mathcal{M}\quad \mathcal{N},\mathcal{M} \in \tilde{\mathcal{B}}^h \cup \overline{\mathcal{B}}^h\right)$\\
\hline
$\VEC{q}_{\alpha}$  & The positional DOF vector for DNS  node $\alpha$ $\left(\alpha,\ \beta,\ldots \in \breve{\mathcal{A}}\right)$\\
\hline
$\VEC{d}_a$ & The macro-position vector for micromorphic node $a$ $\left(a,b,\ldots \in \breve{\mathcal{N}}\right)$\\
\hline
$\left\{\phi\right\}_f$ & The micro-dof vector for micromorphic node $f$ $\left(f,g,\ldots \in \breve{\mathcal{M}}\right)$\\
\hline
\end{tabular}
\end{table}

\FloatBarrier


\section{\texorpdfstring{Introduction}{Introduction}}
\vspace{5mm}
\large

\subsection{Course overview}

\begin{itemize}
	\item Finite graphs
	\item Existence theorems
	\item Algorithms, NP-completeness
	\item Graph drawing
\end{itemize}

How much information do we need to store the drawing?

Upward drawing: each edge directed upwards.

Most of the time we talk about \textbf{Intersection graphs}.

\subsection{Intersection graphs}

\begin{definition}[Intersection graph]
	Let $\A$ be a family of sets.
	Then \textbf{the} intersection graph is
	\[ IG(\A) = (\A, \{ ab: a\ne b, a \cap b \ne \emptyset, a, b \in \A \}) \]

	Let $\M$ be a large family of sets, then G is \textbf{an} intersection graph of $\M$ if
	\[ \exists A \subseteq \M: G \simeq IG(A) \]

	Note that in a family an element can be repeated several times.
\end{definition}

\begin{observation}
	IF $\M$ contains nonempty set, then $\forall$ complete graphs is in $\IG(\M)$.
\end{observation}
\begin{proof}
	\begin{gather*}
		A \in \M, A \ne \emptyset \\
		V(K_n) = \{ u_1, u_2, \ldots, u_m \} \\
	\end{gather*}
	Every vertex $u$ is represented by $A$.
\end{proof}

\begin{observation}
	\[ G \in \IG(\M) \iff \exists f:V(G) \to \M: \forall u \ne v \in V(G): uv \in E(G) \iff f(n) \cap f(v) \ne \emptyset \]
\end{observation}

\begin{observation}
	$\forall \M: \IG(M)$ is \textbf{hereditary} if
	\[ \forall G \in \IG(\M) \ \forall H \leq G: H \in IG(\M) \]

	Induced subgraph is just deleting some edges, which in sets case means forgetting edges that represent sets.
\end{observation}

\begin{definition}[Interval graph]
	% TODO Picture
	Are intersection graphs of intervals on connected subsets of 1 dimensional Euclidian space.
\end{definition}

We are interested in \emph{arc connected} sets of the plain.
\begin{definition}[Arc connected]
	% TODO

	Is different from topological connected.
\end{definition}

\begin{definition}[Circle graphs (CA)]
	Arcs on a circle.
\end{definition}

\begin{definition}[Circular arc graphs (CIR)]
	Chords on a circle.
\end{definition}

\begin{definition}[Polygon circle graphs (PC)]
	Polygons that can be inscribed in a circle.
\end{definition}

\begin{definition}[Permutation graphs (PER)]
	Segments connecting two parallel lines.

	Formally:
	\begin{gather*}
		V(G) = \{ u_1, u_2, \ldots, u_m \} \\
		\exists \pi \in Sym(m): u,v \in E \iff i < j \land \pi(i) > \pi (j)
	\end{gather*}
	% TODO check
\end{definition}

\begin{definition}[Function graphs (FUN)]
	Curves connecting two parallel lines.
\end{definition}

\begin{definition}[Segments graphs (SEG)]
	Straight-line segments in the plane.
\end{definition}

\begin{definition}[String graphs (STRING)]
	Curves in the plane.
\end{definition}

% TODO finish, statement
For each 2 sets, take a point that lies in the intersection of these sets.
Then connect unused dots by branching curve.

Problems we want to solve:
\begin{enumerate}
	\item Given a graph, does it belong to the class.
	\item How can we describe a representation. What size?
	\item Given a graph and a representation, can we find max independent set, clique and so on.
	Such questions that are NP-complete in general.
\end{enumerate}

Q: TODO is graph class recognition decidable?\\
A: Yes, but not polynomial in all cases.

INT, CA, CIR, PC, PER, FUN can be polynomially recognized.
SEG, CONN are considered NP-hard.
STRING is NP-complete.

\[ \forall n \exists G_N \in SEG\]
but in $\forall SEG$ segment representation there is a coordinate that is at least double exponential $2^{2^n}$, so even in bits is exponential.

Representation of STRING graph: make each intersection as a vertex.
All curves between intersection are edges.
Then graph becomes planar.
Planarity can be checked in Polynomial time.
But also $\forall n \exists G_n \in $ STRING $\forall$ representation requires $\geq 2^{cn}$ crossing points.


\section{Background}
\label{sec:background}

We investigated into the use of multi-layer perceptron. This is a
Neural Network regression classifier that includes a hidden layer
where the input is transformed into a more seperable layer. Many
hidden layers can be added to the model and we used two different
transformations to create the hidden data. The first is the identity
which is a no-operation activation. It just returns the same out put
as was inputed or $f(x)=x$. The second transformation we used was
described in the paper tilte,
and transformed the input into a rectified linear unit function.\cite{milgram} This
transformation returns $f(x)=max(0,x)$ and was used in the paper as a
baseline but we had not fully understood their further studys and so
this became one of our better classifiers. \\


\section{Conclusion}
\label{sec:conclusion}
%The contributions and organization of this letter are as follows: Sec.~\ref{sec:system_model} introduces the system model commonly used in the literature, which takes into account Rayleigh fading, shadowing and capture effect in wireless channel. Sec.~\ref{sec:trans_succ_p_pair} synthesizes some stochastic geometry research results useful for the subsequent analysis, and proposes an upper bound for maximum interference analysis. Sec.~\ref{sec:op_over_infinite_plane} presents our analysis for pure (i.e. non-slotted) and slotted ALOHA. It gives closed-form expressions, which are simple but accurate enough to quantify the macro reception diversity gain for a given packet loss rate objective. Sec.~\ref{sec:simulation} presents simulation results and analysis. Sec.~\ref{sec:conclusion} concludes this letter.
In this letter, we derive closed-form expressions for the network packet loss rate and macro diversity gain in pure and slotted ALOHA wireless networks taking into account Rayleigh fading, shadowing and capture effect. We find that systems with macro diversity benefit from shadowing effect and provide an important gain in all cases.
%In addition, we observe that macro diversity gain depends on path-loss exponent, shadowing standard deviation and packet loss rate constraint, and does not depend on capture ratio and ALOHA types.


\subsection{Analysis of Problem}
To work out the four problems, our solutions will be proceeded as follows.
\begin{itemize}
  \item[$\circledcirc$] \textbf{Problem 1:} In the nature, the process of fungi decomposing lignin or cellulose involves complex biochemical reactions. Hence, to simplify the problem, we are going to divide the decomposition situations into two types: ideal cylinder and plane. Based on that, we could conduct a symmetrization operation on decomposition environment of the fungi to facilitate the connection of this process with the \textbf{Gauss theorem} and Gauss surface in electromagnetic. Meanwhile, \textbf{fungal activity factor} (ACT) will be added to the model, which is determined by the suitable living concentration of specific fungal types, moisture tolerance and the influence between different fungal species.
  \item[$\circledcirc$] \textbf{Problem 2:} Based on Figure 1 and Figure 2 given in problem sheet, we plan to perform a function fitting derivation, and then carry out the fungi selection operation, which simplifies the overall model building process, and obtains more practical data. When considering two fungal populations living together, due to competition for habitat and food, the interaction between them would hinder each other's growth and reproduction. Therefore, we are going to introduce the \textbf{Relative Growth Blocking Index} (RGB) on the basis of Single-group Logistic Model, and establish \textbf{Multi-groups Logistic Model} to predict trends of fungal populations in short term and long term.
  \item[$\circledcirc$] \textbf{Problem 3:} To analyze different influences on each isolate and fungal combinations caused by different environments. We will conduct two predictions for single fungal species and combinations of fungal species, respectively. \textbf{Logistic Model} and \textbf{Gray Prediction} will be used in the prediction process. Meanwhile, five environmental conditions, including arid, semi-arid, temperate, arboreal, and tropical rain forests, will be candidates for the optimal environmental condition.
  \item[$\circledcirc$] \textbf{Problem 4:} We will carry out an ecologically significant analysis of the impact of fungal population biodiversity on the \textbf{carbon cycle} in authentic nature from the perspective of the ecosystem, and write the important conclusions in the \textbf{\textit{article for college level biology textbook}}.
\end{itemize}
\par
Above is a sketch of the analysis process on the four problems.


\section{Main Questions in Neural Network Theory}
\label{sec:Question}
Neural Networks have unfolded a striking power processing human like
work. However, the mechanism underneath such success is beyond our
comprehension. Center for Brains, Minds and Machines (CMBB) has done
plentiful work on giving a satisfying characterization of the deep
neural networks and completing our understanding of deep neural networks.
In this section, we attend to three main questions put forward
in Poggio et al. \parencite{poggio2016theory,poggio2017theory,
banburski2019theory}: (1) Why deep neural networks avoid the
exponentially increasing computation
as the dimension increases comparing to shallow networks?
(2) How does the landscape of the empirical risk looks like in
the deep neural networks?

\subsection{Representation Power of Deep Neural Networks}
The main conclusion that Poggio et al. \parencite{poggio2016theory}
draw is that for all compositional functions with binary tree
architecture deep neural networks eliminate the dependency on
variable dimensionality in complexity.

\subsubsection{Definition and Notation}
\textbf{Degree of approximation} Let $ V_N $ be a set of all networks
with complexity $ N $\footnote{The complexity we mean here is the
total number of units in neural networks}, $ f $ be the target
function and $ P $ be the approximation given by networks.
Then the degree of approximation is:
\begin{equation}
    \mathop{\text{dist}}(f,\ V_N) = \mathop{\inf}_{P\in V_N}||f-P||
\end{equation}
If $ \mathop{\text{dist}}(f,\ V_N) = O(N^{\gamma}) $, then the complexity
$ N = O(\epsilon^{-\frac{1}{\gamma}}) $ can guarantee a approximation
with accuracy at least $ \epsilon $.

\textbf{Function set} Let $ m,\ n \geq 1,\ m \in Z $, then $ W_m^n $
is the set of all functions of $ n $ variables with continuous partial
derivatives of orders up to $ m $.
 $ W_m^{n,\ 2} \subseteq W_m^n $ is
a set of all compositional functions of $ n $ variables with a binary
tree architecture i.e. using functions $ h \in W_m^2 $.
Let $ k \in R^+ $ is the degree of a polynomial, then $ P_k^n $ is
the set of all polynomial functions of degree $ k $ in $ n $ variables.
$ T_k^n $ is the set of all composition polynomials functions of degree
$ k $ in $ n $ variables with a binary tree structure.

\subsubsection{Shallow Networks}
A theorem w.r.t. complexity of shallow network is stated in
Mhaskar \parencite{mhaskar1996neural}.
\begin{thm}
    \label{thm:Shallow}
    Let activation $ \sigma $ be infinitely differentiable and not
    a polynomial. For $ f \in W_m^n $, the complexity of shallow networks
    that provide accuracy at least $ \epsilon $ is:
    \begin{equation}
        N = O(\epsilon^{-\frac{n}{m}})
    \end{equation}
\end{thm}
The term $ \epsilon^{-\frac{n}{m}} $ shows the exponentially increasing
of neural network units in shallow networks.

\subsubsection{Deep Hierarchy Networks}
The second theorem is formulated in the binary tree structure see
\autoref{fig:BT}. In CNN such structure corresponds to the $ 2\times 2 $
kernel.
\begin{thm}
    Let activation $ \sigma $ be infinitely differentiable and not
    a polynomial. For $ f \in W_m^{n,\ 2} $, the complexity of shallow networks
    that provide accuracy at least $ \epsilon $ is:
    \begin{equation}
        N = O((n-1)\epsilon^{-\frac{2}{m}})
    \end{equation}
\end{thm}

\begin{prf}
    We apply \autoref{thm:Shallow} to $ h \in W_m^2 $, which means the
    approximation provides accuracy $ \epsilon = c_1N^{-\frac{m}{2}},\ c_1 \in R $.
    We illustrate the proof using a example of $ f(h_1,\ h_2),\ P(P_1,\ P_2) $.
    Since
    \begin{equation}
        \begin{split}
            ||f-P|| & \leq \epsilon \\
            ||h_1-P_1|| & \leq \epsilon \\
            ||h_2-P_2|| & \leq \epsilon \\
        \end{split}
    \end{equation}
    Then we can derive:
    \begin{align}
        ||f(h_1,\ h_2) - P(P_1,\ P_2)|| & = ||f(h_1,\ h_2) - f(P_1,\ P_2) + f(P_1,\ P_2) - P(P_1,\ P_2)|| \\
        & \leq ||f(h_1,\ h_2) - f(P_1,\ P_2)|| + ||f(P_1,\ P_2) - P(P_1,\ P_2)|| \\
        & \leq c_2N^{-\frac{m}{2}}
    \end{align}
    Here we obtain the complexity of a single node in architecture,
    despite the output node, we come to the conclusion of
    $ N = O((n-1)\epsilon^{-\frac{2}{m}}) $. \\
    \textbf{Q.E.D.}
\end{prf}

\begin{figure}[H]
    \centering
    \includegraphics[width=8cm]{BT}
    \caption{\label{fig:BT}The binary tree structure}
\end{figure}

\subsection{The Landscape of Empirical Risk}
\label{ssec:empirical}
The term empirical risk is in contrast of the true risk, the average
loss on the true distribution over all input and output. The true
distribution is unknown, otherwise there is no need for neural
networks. Using data set, subset of the whole distribution, as
substitution is the origin of empirical. Poggio et al.
\parencite{poggio2017theory} explore the landscape of the empirical
risk, i.e. cost function $ J $, under the framework of convolutional
and overparameterized neural networks and the activation functions
$ g^{[l]}(z) $ are polynomial-like ReLU\footnote{The ReLU is
approximated by polynomials whose degree is $ d^{[l]}(\epsilon) $ at
the accuracy of $ \epsilon $. }. Moreover, a landscape model satisfying
the experimental results is provided.

\par First, we summarize the experimental observations in deep neural
networks.
\begin{enumerate}
    \item There is a large number of zero-error global minimums
    that are degenerate.\footnote{See Appendix 3 for
    theoretical analysis}
    \item Perturbation will lead to different convergence path,
    the larger or earlier in training process the perturbation is,
    the more different the path and the final minimum will be.
    \item Interpolation between two close convergence path to the
    same minimum will have similar or even smaller error. On the
    other hand, interpolation between two minimums cause the
    rise of error.
    \item No local minimum is observed.
\end{enumerate}

A simple model that is consistent with the observations is a collection
of rugged basins which is shown in \autoref{fig:Basin}.
The flat and wide global minimums in basins explain
a myriad of zero-error minimizers. A small perturbation will not make
a difference in a basin, while a lager one may cause a different path
to other basins, see \autoref{fig:basin}. Besides, the "walls" between
basins demonstrated in \autoref{fig:basin} may be the cause of
interpolation's different behaviors in the neighbor of minimum and a
distinct minimum.

\begin{figure}[H]
    \centering
    \subfigure[Profile view of the basin]{
        \begin{minipage}[t]{0.5\linewidth}
        \label{fig:Basin_1D}
        \centering
        \includegraphics[width=6cm]{Basin_1D}
        \end{minipage}%
    }%
    \subfigure[Top-down view of the basin]{
        \begin{minipage}[t]{0.5\linewidth}
        \label{fig:Basin_2D}
        \centering
        \includegraphics[width=6cm]{Basin_project}
        \end{minipage}%
    }%

    \subfigure[Example of perturbation]{
        \begin{minipage}[t]{0.5\linewidth}
        \label{fig:Basin_perturbation}
        \centering
        \includegraphics[width=6cm]{Basin_perturbation}
        \end{minipage}%
    }%
    \subfigure[Example of interpolation]{
        \begin{minipage}[t]{0.5\linewidth}
        \label{fig:Basin_interpolation}
        \centering
        \includegraphics[width=6cm]{Basin_interpolation}
        \end{minipage}%
    }%
    \centering
    \caption{\label{fig:Basin}The basin model}
\end{figure}

Another interesting model is a variant of basin: the basin-fractal
\autoref{fig:Fractal}.
The key difference between simple basins and basin-fractal is that
there are more than one global minimum in the same low loss area in
the latter model. Though in most cases the "walls" between these
global minimums are too flat and smooth to notice.

\begin{figure}[H]
    \centering
    \subfigure[2D view of basin-fractal]{
        \begin{minipage}[t]{0.5\linewidth}
        \centering
        \includegraphics[width=6cm]{Fractal_project}
        \end{minipage}%
    }%
    \subfigure[The landscape of basin-fractal]{
        \begin{minipage}[t]{0.5\linewidth}
        \centering
        \includegraphics[width=6cm]{Fractal_landscape}
        \end{minipage}%
    }%
    \centering
    \caption{\label{fig:Fractal}The basin-fractal model}
\end{figure}

\subsection{Generalization of Neural Networks}
There is no use for neural networks only fit the training data
well. The character of a neural network is measured by how well
it performs on other data, which is how well it generalizes.
Due to the obscurity of mathematical analysis in Banburski et al.
\parencite{banburski2019theory}, we only give a summary on
the whole work.
\begin{enumerate}
    \item Using the exponential loss\footnote{The exponential loss
    is defined as $ l(y f)=e^{-y f} $, then the cost function is
    $J(f)=\sum_{n=1}^{N} l\left(y_{n} f\left(x_{n}\right)\right)$}
    , minimization of $ J $ with a vanishing regularization term in
    weights leads to the maximization of the margin of $f$.
    \item The critical points are hyperbolic equilibrium points\footnote{
    A hyperbolic equilibrium point is a point at which the Jacobian Matrix
    has no eigenvalue with zero real part.\parencite{hyperbolic}} if the
    data are separable.

\end{enumerate}


\section{OLS predictions with many parameters}


\documentclass[11pt,a4paper,dvipsnames,twosided]{article}

\usepackage{amsmath}
\usepackage[unicode=true,pdftex,pdfa,colorlinks=true]{hyperref}
\usepackage{xcolor}
\usepackage{todonotes}

\newcommand\pbar{\overline{p}}

\begin{document}

\title{Stake Pool Ranking in Cardano}

\author{Alexander Byaly  \\ {\small \texttt{alexander.byaly@iohk.io}} \\
   \and Jared Corduan  \\ {\small \texttt{jared.corduan@iohk.io}}}

%\date{}

\hypersetup{
  pdftitle={Stake Pool Ranking in Cardano},
  breaklinks=true,
  bookmarks=true,
  colorlinks=false,
  linkcolor={blue},
  citecolor={blue},
  urlcolor={blue},
  linkbordercolor={white},
  citebordercolor={white},
  urlbordercolor={white}
}

\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt plus 3pt minus 2pt}

\maketitle

\section{Introduction}

The purpose of the stake pool ranking algorithm is to provide a systematic and unique ordering for stake pools,
based on the expected long-term rewards that each stake pool will produce.
The pool ranking is provided to users (wallets, people who own ADA, etc.), and can be used as a single
metric to guide delegation decisions.
The ranking is based upon past performance but should be a useful predictor of future performance.

An obvious, but na\"{i}ve, approach to the ranking problem would order pools based on the rewards that are
currently being paid out to their delegators.  There are, however, a number of problems with this approach.

\begin{enumerate}
  \item
    The na\"{i}ve approach is \emph{short-sighted}, in the sense that it does not take into
    account the rewards that a newly formed stake pool would yield when it reaches saturation (\cite{bkks2018} describes this in detail).
    The specific relationship to the Cardano design is explained in the IOHK delegation design document \cite[Section 5.6]{delegation_design}.
  \item
    A stake pool will sometimes have the opportunity to produce blocks,
    but fails to do so due to issues such as a poor network connection or untimely downtime. The rate at
    which a pool uses their opportunities to make blocks, which we will call its \emph{hit rate}, affects rewards.
    It needs to be taken into account.
\end{enumerate}

Our aim with the pool ranking algorithm is to address all these concerns.

\section{Hit Rate}

As described above, the \emph{hit rate} for some time period $T$ is the ratio of expected to actual blocks
that the pool produces during that time period.

$$
\begin{array}{l}
  \begin{array}{lclp{3in}}
    Hit~Rate_T &=& B_{Produced,T} / B_{Leader,T} \\
  ~~ \textit{where} \\
  \end{array}
\\
~~~~
  \begin{array}{lcp{3in}}
      B_{Produced,T} &=& \text{The actual number of blocks that a pool}\\
      && \text{has produced in time T}\\
      B_{Leader,T} &=& \text{The number of blocks during time T}\\
      && \text{in a pool's private leader schedule}
  \end{array}
\end{array}
$$

Note that the pool operator is the only one who knows $B_{Leader,T}$,
since only they have access to their internal VRF calculation.
Other actors can only estimate it using public knowledge of the
pool's relative stake and the number of blocks that it has produced.

\subsection{Hit Rate Estimation}

Each slot, a stake pool with relative (active) stake $\sigma_a$ has probability
\[ 1 - (1-f)^{\sigma_a} \]
of producing a block, where $f$ is the active slot coefficient.
We can use this to estimate the hit rate.
%
We represent such an estimate as a probability distribution on the interval $[0,1]$.

After each epoch, we refine our estimate into a more accurate one as follows.
%
Assume that we can
observe all the blocks that a stake pool produces during an epoch, that we have a previous estimate of the blocks that
we expected to produce during this epoch, $w_e$; we know that the
epoch $e$ has a total of $E$ slots; the pool produces $n_e$ blocks; and we calculate that on a given slot
the chance that the pool is allowed to produce a block is $t_e$.
%
The \emph{likelihood function}, $L_e$, is then shown below, where $L_e(x)$ is the probability of producing exactly $n_e$ blocks,
and $S_e(x)$ is the probability that the pool produces a block at a given slot, under the assumption that the
\emph{hit rate}, $p$, is equal to $x$.

\[ L_e(x) = \left( E \atop n_e \right) S_e(x)^{n_e} (1-S_e(x))^{E - n_e}, \]

\[
\begin{array}{rcl}
  S_e(x) &=& P( \text{made block} | p = x) \\
         &=& t_e \cdot P( \text{made block} | p = x,~b) + (1-t_e) \cdot P( \text{made block} | p = x,~\neg~b) \\
         &=& t_ex                              + (1-t_e) \cdot 0 \\
         &=& t_ex \\
         \\
  b    &=& \text{can make a block}
\end{array}
\]

Our refined hit rate estimate is then $w_{e+1}(x) =w_e(x)L_e(x)$.

This formula will generally not produce a proper proability distribution. The associated probability distribution is
$$q_e(x)=\frac{w_e(x)}{\int w_e(x)},$$
which is the function used to construct rankings for epoch $e$.

The data we store is the product
$$\mathcal{L}_e(x) = \prod_{i=1}^e L_i(x),$$
with the initial prior distribution $w_0$ included at the time a ranking is produced.

We have

\begin{equation}
  \label{post}
  q_e(x) = \frac{w_0(x)\mathcal{L}_e(x)}{\int w_0(x)\mathcal{L}_e(x)}.
\end{equation}

\subsection{Implementation}

We approximate a \emph{probability density function}, $g$, using a sequence of sample points,

\[ A(g) = \big(\ln(g(0.005)),~ \ln(g(0.015)),~ \ldots,~ \ln(g(0.995))\big). \]

This allows us to use multiplication rather than exponentiation for most of our calculations.

Because of the normalization step in Equation \eqref{post}, any scalar multiple of $g$
will ultimately yield the same result. It follows that any constant shift of $A(g)$ will also yield the same result.
In order to reduce the magnitude of the numbers that we are dealing with, we therefore use the logarithmic normal form.
\footnote{There may be tradeoffs, such as the computational cost of logs, that we have not yet explored.}

\[ A'(g) = \big(\ln(g(0.005)) - m,~ \ln(g(0.015)) - m,~ \ldots,~ \ln(g(0.995)) - m\big), \]
where $\ln$ is the \emph{natural logarithm} and $m$ is the minimal sample point. We use $g^i$ to denote the $i$'th term of $A'(g)$.
For each stake pool, we compute $A'(L_e)$, add it to $A'(\mathcal{L}_{e-1})$, and
normalize the result to approximate $A'(\mathcal{L}_e)$.

To calculate the final probability distribution function that we need for pool ranking, we approximate Equation \eqref{post}. We use

\[ q_e^i \approx \mathsf{exp}(w_0^i + \mathcal{L}_e^i) / S, \]
where
\[ S = \sum (0.01) \mathsf{exp}(w_0^i + \mathcal{L}_e^i). \]

In the ranking calculation, we use the $j$'th percentile of this distribution for some $j$.
We do so by computing the minimal $i$ such that the sum of $[q_e^0,~\ldots,q_e^i]$ is at least $j$.
Then $i/100$ is the $j$'th percentile.

Putting it all together, given some prior distribution, $w_0$, a percentile, $j$, and a cumulative likelihood approximation
$A'(\mathcal{L}_e)$, we estimate the hit rate to be $i/100$.

\subsection{Example}

Assume that Alice's pool has been active for two epochs,
there are 432,000 slots per epoch, and the active slot coefficient is 0.05
(these are the mainnet values at the time of writing).
\begin{itemize}
\item
  During the first epoch (epoch 1), the relative stake was $0.001$ and 10 blocks were produced.
\item
  During the second epoch (epoch 2), the relative stake was $0.01$ and 200 blocks were produced.
\end{itemize}
We calculate $\ln(L_1(x))$ for the first epoch as follows.
%
With relative stake $0.001$, the probability of being allowed to produce a block on
each slot is $t_1 = 1-(1-0.05)^{0.001},$ and $S_1(x)= t_1x$.
Since 10 blocks were produced, the real likelihood function is

\[ L_1(x) =  \left( 432,000 \atop 10 \right) (t_1x)^{10} (1-t_1x)^{431,990} \]

and we will use
\[
\begin{array}{rl}
  \ell_1(x) &= \ln\left( (t_1x)^{10} (t_1x)^{431,990} \right) \\
            &= 10 \ln(t_1 x) + 431,990 \ln(1 - t_1 x) \\
\end{array}
\]
to record information about Alice's pool's performance this epoch.
In particular, we record

\[ A'(L_1) = [\ell_1(0.005)-m_1,~\ell_1(0.015)-m_1,~\ldots,~\ell_1(.995)-m_1] \]
where $m_1=\min\{\ell_1(0.005),\ldots,\ell_1(0.995)\}$

For the second epoch,
\[
\begin{array}{rl}
  t_2 &= 1-(1-0.05)^{0.01} \\
  \ell_2(x) &= 200 \ln(t_2 x) + 431,800 \ln(1 - t_2 x).\\
\end{array}
\]
Then for the second epoch we store:
\[ A'(L_2) = [\ell_2(0.005)+\ell_1(0.005)-m_2,~\ldots,~\ell_2(.995)+\ell_1(.995)-m_2] \]
where $m_2=\min\{\ell_2(0.005)+\ell_1(0.005),\ldots,\ell_2(0.995)+\ell_1(0.995)\}$.

\section{Ranking and Saturation}

We now describe how the hit rate estimation can be used to calculate the stake pool ranking,
as described in \cite{bkks2018} and \cite[Section 5.6]{delegation_design}.
First we must turn the sampling of the likelihood functions into a concrete value.
Given a percentage, $z$, we will calculate the $z$'th percentile\footnote{At present we use the 10th percentile (i.e. $z=10\%$), but we ultimately aim for this to be user configurable.}.
For a given stake pool $P$, let $h_z$ denote the $z$'th percentile.
%
Following \cite[Section 5.6.1]{delegation_design},
we can then compute the stake pool's rewards when it reaches \emph{saturation} (it has the optimal level of stake) using:
\[
    \tilde{f}(s, \pbar) :=
    \hat{f}(s,z_0,\pbar)=
    \frac{\pbar R}{1 + a_0}
    \cdot
    \left(z_0 + \min(s,z_0)\cdot a_0\right).
\]

where $\bar{p}$ is the \textit{apparent performance} of the stake pool, as defined in
\cite[Section 5.5.2]{delegation_design}.
We will substitute our estimate of the hit rate, $h_z$, for the apparent performance, $\bar{p}$,
Given a pool, $P$ with pledged owner stake \(s\), costs \(c\) and margin \(m\),
the \emph{desirability function} of \cite[Section 5.6.1]{delegation_design} becomes:
\[
    d(c, m, s, h_z) :=
    \left\{
    \begin{array}{ll}
        \displaystyle 0 &
        \text{if $\tilde{f}(s,h_z)\leq c$,} \\
        \displaystyle\left(\tilde{f}(s,h_z) - c\right)\cdot(1-m) &
        \text{otherwise.}
    \end{array}
    \right.
\]
From here, we proceed exactly as in
\cite[Section 5.6.2]{delegation_design} and
\cite[Section 5.6.4]{delegation_design}.

The desirability function above can be used to provide an overall ranking over stake pools,
ordering the pools in terms of their \emph{non-myopic rewards} for some stake.
For a stake pool with pledged owner stake $s$, total stake $\sigma$, rank
$r$ and apparent performance $\pbar$, we define its \emph{non-myopic stake} $\sigma_\mathrm{nm}$ as:
\[
    \sigma_\mathrm{nm}(s,\sigma,r) :=
    \left\{
    \begin{array}{ll}
        \max(\sigma,z_0) &
        \text{if $r\leq k$,} \\
        s &
        \text{otherwise,}
    \end{array}
    \right.
\]
where $k$ is the parameter that is defined in \cite[Section 5.2]{delegation_design},
and which represents the desired number of stake pools in an equilibrium state.
%
The \emph{non-myopic pool member rewards}
% of a pool with costs $c$, margin $m$,
% pledged owner stake $s$, stake $\sigma$, rank $r$,
for a member that contributes member stake $t$, are then:
\[
    r_\mathrm{member, nm}(c, m, s, \sigma, t, r, \pbar) :=
    r_\mathrm{member}\Bigl(\hat{f}\bigl(s,\sigma_\mathrm{nm}(s,\sigma, r),
    \pbar\bigr),
    c, m, t, \sigma_\mathrm{nm}(s,\sigma,r)\Bigr),
\label{eq:non-myopic-member-rewards}
\]
where
\[
    r_\mathrm{member}(\hat{f}, c, m, t, \sigma) :=
    \left\{
    \begin{array}{ll}
        \displaystyle 0 &
        \text{if $\hat{f}\leq c$,} \\
        \displaystyle (\hat{f} - c)\cdot(1-m)\cdot\frac{t}{\sigma} &
        \text{otherwise.}
    \end{array}
    \right.
\]
Delegators can use $r_\mathrm{member, nm}$ to select a pool
that maximizes their rewards.

\addcontentsline{toc}{section}{References}
\bibliographystyle{habbrv}
\bibliography{references}

\end{document}